25 #include <csutil/array.h> 26 #include <csutil/list.h> 27 #include <csutil/priorityqueue.h> 28 #include <csutil/weakref.h> 29 #include <csutil/parray.h> 31 #include <csgeom/vector3.h> 32 #include <iengine/sector.h> 60 #define TRIBE_UNLIMITED_SIZE 100 118 iSector* GetSector();
136 iSector* GetSector();
165 bool Load(iResultRow &row);
180 bool AddMember(PID pid,
const char* tribeMemberType);
233 return name.GetDataSafe();
237 return membersId.GetSize();
241 return members.GetSize();
249 return resources.GetSize();
257 csList<Memory*>::Iterator it(memories);
262 return npcIdleBehavior;
271 return homeSectorName;
288 void GetHome(csVector3 &pos,
float &radius, iSector* §or);
293 void SetHome(
const csVector3 &pos,
float radius, iSector* sector);
308 bool GetResource(
NPC* npc, csVector3 startPos, iSector* startSector,
309 csVector3 &pos, iSector* §or,
float range,
bool random);
386 Memory*
FindMemory(csString name,
const csVector3 &pos, iSector* sector,
float radius);
396 void AddMemory(csString name,
const csVector3 &pos, iSector* sector,
float radius,
NPC* npc);
421 Memory*
FindNearestMemory(
const char* name,
const csVector3 &pos,
const iSector* sector,
float range = -1.0,
float* foundRange = NULL);
426 Memory*
FindRandomMemory(
const char* name,
const csVector3 &pos,
const iSector* sector,
float range = -1.0,
float* foundRange = NULL);
442 csVector3* basePos=NULL, iSector* baseSector=NULL);
479 bool includeInvisible,
bool includeInvincible,
float* hate=NULL);
558 knowledge.Push(knowHow);
621 void Build(
NPC* npc,
bool pickupable);
636 csArray<NPC*>
SelectNPCs(
const csString &type,
const char* number);
646 csString
GetBuffer(
const csString &bufferName);
654 void SetBuffer(
const csString &bufferName,
const csString &value);
777 virtual void LocalDebugReport(
const csString &debugString);
782 virtual void RemoteDebugReport(uint32_t clientNum,
const csString &debugString);
787 void UpdateDeathRate();
792 void UpdateResourceRate(
int amount);
796 csArray<MemberID> membersId;
797 csArray<NPC*> members;
798 csArray<NPC*> deadMembers;
799 csArray<Resource> resources;
800 csArray<csString> knowledge;
801 csPDelArray<Asset> assets;
802 csArray<CyclicRecipe> cyclicRecipes;
809 csString homeSectorName;
814 BufferHash tribeBuffer;
815 csString wealthResourceName;
816 csString wealthResourceNick;
817 csString wealthResourceArea;
818 float wealthResourceGrowth;
819 float wealthResourceGrowthActive;
820 int wealthResourceGrowthActiveLimit;
821 float accWealthGrowth;
822 int reproductionCost;
823 csString npcIdleBehavior;
824 csString wealthGatherNeed;
825 csList<Memory*> memories;
834 csTicks lastResource;
csString GetNPCIdleBehavior()
int quantity
Quantity of items of this type.
void DumpBuffers()
Dump Buffers.
void HandlePerception(NPC *npc, Perception *perception)
Handled a perception given to this tribe.
This embodies any perception an NPC might have, or any game event of interest.
const char * GetNeededResourceAreaType()
Get a area for the most needed resource for this tribe.
size_t AssetQuantity(Tribe::AssetType type, csString name)
Return the quanitity of the given asset type matching the name.
Memory * FindPrivMemory(csString name, const csVector3 &pos, iSector *sector, float radius, NPC *npc)
Find a privat memory.
Check how long time it take to process a scope.
void SaveResource(Resource *resource, bool newResource)
Save or update an resource in database.
bool CheckKnowledge(csString knowHow)
Check if knowledge is known.
void DumpAssets()
Dump Assets.
virtual ~Tribe()
Destruct a tribe object.
bool LoadMember(iResultRow &row)
Load and add a new member to the tribe.
bool Load(iResultRow &row)
Load the tribe object.
void SaveMemory(Memory *memory)
Save a memory to the db.
void AddKnowledge(csString knowHow)
Add a knowledge token.
bool CheckAsset(Tribe::AssetType type, csString name, int number)
Check to see if enough assets are available.
Callback function for ScopedTimers.
void ModifyWait(Recipe *recipe, int delta)
Modify Wait Time for a recipe.
csHash< csString, csString > BufferHash
void SetRecipeManager(RecipeManager *rm)
Sets the tribe's recipe manager.
gemNPCActor * GetMostHated(NPC *npc, float range, bool includeOutsideRegion, bool includeInvisible, bool includeInvincible, float *hate=NULL)
Find the most hated entity for tribe within range.
int timeTotal
Total number of ticks to cycle.
bool AttachMember(NPC *npc, const char *tribeMemberType)
Attach a new member to the tribe.
csString sectorName
Name of the sector.
void SetHome(const csVector3 &pos, float radius, iSector *sector)
Set home position for the tribe.
AssetType type
Type of this asset.
void AddResource(csString resource, int amount, csString nick="")
Add a new resource to the tribe resource table.
csArray< NPC * > SelectNPCs(const csString &type, const char *number)
Returns pointers to required npcs for a task.
int CountResource(csString resource) const
Return the amount of a given resource.
bool CheckAttach(NPC *npc)
Attach a new member to the tribe if the NPC is a member.
void DumpKnowledge()
Dump knowledge to console.
csString sectorName
Keep the sector name until sector is loaded.
bool CheckWithinBoundsTribeHome(NPC *npc, const csVector3 &pos, const iSector *sector)
Check if the position is within the bounds of the tribe home.
void DeleteCyclicRecipe(Recipe *recipe)
Delete a cyclic recipe.
bool AddMember(PID pid, const char *tribeMemberType)
Adds a new member to the tribe.
csWeakRef< gemNPCItem > item
Item representing the asset.
bool CheckMembers(const csString &type, int number)
Check to see if enough members are idle.
csString GetHomeSectorName()
void SaveKnowledge(csString knowHow)
Save a knowledge piece in the database.
void ForgetMemories(NPC *npc)
Forget privat memories.
void SetBuffer(const csString &bufferName, const csString &value)
Set/Update the value of a named buffer.
csList< Memory * >::Iterator GetMemoryIterator()
Asset * GetRandomAsset(Tribe::AssetType type, Tribe::AssetStatus status, csVector3 pos, iSector *sector, float range)
Get a random asset.
const char * GetNeededResourceNick()
Get the nick for the most needed resource for this tribe.
iSector * sector
The Sector.
bool LoadNPCMemoryBuffer(const char *name, csArray< NPC * > npcs)
Set npcs memory buffers.
Memory * FindMemory(csString name, const csVector3 &pos, iSector *sector, float radius)
Find a memory.
bool ShouldGrow() const
Check if the tribe should grow by checking number of members against max size.
void HandlePersistItem(gemNPCItem *item)
Handle persist items that should be assets.
int timeLeft
Number of ticks left before re-execution.
size_t GetMemberIDCount()
void TriggerEvent(Perception *pcpt, float maxRange=-1.0, csVector3 *basePos=NULL, iSector *baseSector=NULL)
Send a perception to all members of the tribe.
Class that represents the Recipe Manager of the game.
Tribe(EventManager *eventmngr, RecipeManager *rm)
Construct a new tribe object.
bool CanGrow() const
Check if the tribe can grow by checking the tribes wealth.
static const char * AssetStatusStr[]
int GetWealthResourceGrowthActiveLimit() const
Get wealth resource growth active limit.
bool LoadMemory(iResultRow &row)
Load all stored memories from db.
void ReplaceBuffers(csString &result)
Replace $TBUFFER[x] with values from the NPC buffer.
void AddAsset(Tribe::AssetType type, csString name, gemNPCItem *item, int quantity, int id=-1)
Add an item asset.
static const char * AssetTypeStr[]
AssetStatus status
Status of this asset. Used for buildings.
int AliveCount() const
Count number of alive members.
Asset * GetNearestAsset(Tribe::AssetType type, Tribe::AssetStatus status, csVector3 pos, iSector *sector, float range, float *locatedRange=NULL)
Get nearest asset.
float GetResourceRate()
Retrive resource rate average value from tribe.
csString tribeMemberType
Used to select needSet by index.
csVector3 pos
Position // Used only for reservations.
void AddRecipe(Recipe *recipe, Recipe *parentRecipe, bool reqType=false)
Add a recipe.
int GetReproductionCost() const
Return the reproduction cost for this tribe.
int GetMaxSize() const
Calculate the maximum number of members for the tribe.
uint32_t itemUID
The UID of the item, 0 if no item.
float GetWealthResourceGrowth() const
Get wealth resource growth rate.
Recipe * recipe
Link to recipe.
This object represents each NPC managed by this superclient.
void DumpRecipesToConsole()
Dumps all information about recipes to console.
void LoadAsset(iResultRow &row)
Load an asset from an iResultRow.
bool CheckResource(csString resource, int number)
Check to see if enough resources are available.
void SaveAsset(Tribe::Asset *asset, bool deletion=false)
Save an asset to the db - responsable for deleting assets to.
const Resource & GetResource(size_t n)
csString name
Name. Especially used for buildings.
csString GetBuffer(const csString &bufferName)
Return a named buffer from the NPC.
void ProspectMine(NPC *npc, csString resource, csString nick)
Assigned a resource to a prospect Mine.
float GetWealthResourceGrowthActive() const
Get wealth resource growth rate active.
void Unbuild(NPC *npc, gemNPCItem *building)
Tear down a building.
void UpdateRecipeData(int delta)
Updates recipe wait times.
float GetDeathRate()
Retrive death rate average value from tribe.
iSector * GetHomeSector()
void Build(NPC *npc, bool pickupable)
Build a building on the current NPC building spot.
NPC * GetMember(size_t i)
void RemoveAsset(Tribe::Asset *asset)
Remove an asset.
Keep track of remote debugging.
void GetHome(csVector3 &pos, float &radius, iSector *§or)
Get home position for the tribe.
Memory * FindNearestMemory(const char *name, const csVector3 &pos, const iSector *sector, float range=-1.0, float *foundRange=NULL)
Find nearest memory to a position.
void ShareMemories(NPC *npc)
Share privat memories with the other npcs.
const char * GetNeededResource()
Get the most needed resource for this tribe.
bool HandleDeath(NPC *npc)
Remove members that die.
csVector3 GetHomePosition()
virtual void ScopedTimerCallback(const ScopedTimer *timer)
Callback for debug of long time used in scopes.
size_t GetResourceCount()
NPC * npc
Privat memory if NPC is set.
void AddCyclicRecipe(Recipe *recipe, int time)
Add a cyclic recipe.
Asset * GetAsset(Tribe::AssetType type, csString name)
Get asset.
This class represents a leaf in a recipe tree.
This object represents recipes for the tribe AI.
This class handles all queueing and invoking of timed events, such as combat, spells, NPC dialog responses, range weapons, or NPC respawning.
void Advance(csTicks when, EventManager *eventmgr)
Advance the tribe.
void AddMemory(csString name, const csVector3 &pos, iSector *sector, float radius, NPC *npc)
Add a new memory to the tribe.
Recipe * GetTribalRecipe()
Get the main recipe.
Memory * FindRandomMemory(const char *name, const csVector3 &pos, const iSector *sector, float range=-1.0, float *foundRange=NULL)
Find a random memory within range to a position.
void SendPerception(const char *pcpt, csArray< NPC * > npcs)
Sends the given perception to the given list of npcs.
void DeleteAsset(csString name, int quantity)
Delete item assets.
bool LoadResource(iResultRow &row)
Load and add a new resource to the tribe.
void Memorize(NPC *npc, Perception *perception)
Memorize a perception.
Holds list of tribe members, position of tribe home Keeps resources and handles tribe perceptions...