Planeshift
|
Class used to define a Tribal Object. More...
#include <tribe.h>
Classes | |
struct | Asset |
struct | CyclicRecipe |
struct | MemberID |
struct | Memory |
struct | Resource |
Public Types | |
enum | AssetStatus { ASSET_STATUS_NOT_APPLICABLE, ASSET_STATUS_NOT_USED, ASSET_STATUS_INCONSTRUCTION, ASSET_STATUS_CONSTRUCTED } |
enum | AssetType { ASSET_TYPE_ITEM, ASSET_TYPE_BUILDING, ASSET_TYPE_BUILDINGSPOT } |
typedef csHash< csString, csString > | BufferHash |
Public Member Functions | |
void | AddAsset (Tribe::AssetType type, csString name, gemNPCItem *item, int quantity, int id=-1) |
Add an item asset. | |
Tribe::Asset * | AddAsset (Tribe::AssetType type, csString name, csVector3 position, iSector *sector, Tribe::AssetStatus status) |
Add an asset to the tribe. | |
void | AddCyclicRecipe (Recipe *recipe, int time) |
Add a cyclic recipe. | |
void | AddKnowledge (csString knowHow) |
Add a knowledge token. | |
bool | AddMember (PID pid, const char *tribeMemberType) |
Adds a new member to the tribe. | |
void | AddMemory (csString name, const csVector3 &pos, iSector *sector, float radius, NPC *npc) |
Add a new memory to the tribe. | |
void | AddRecipe (Recipe *recipe, Recipe *parentRecipe, bool reqType=false) |
Add a recipe. | |
void | AddResource (csString resource, int amount, csString nick="") |
Add a new resource to the tribe resource table. | |
void | Advance (csTicks when, EventManager *eventmgr) |
Advance the tribe. | |
int | AliveCount () const |
Count number of alive members. | |
size_t | AssetQuantity (Tribe::AssetType type, csString name) |
Return the quanitity of the given asset type matching the name. | |
bool | AttachMember (NPC *npc, const char *tribeMemberType) |
Attach a new member to the tribe. | |
void | Build (NPC *npc, bool pickupable) |
Build a building on the current NPC building spot. | |
bool | CanGrow () const |
Check if the tribe can grow by checking the tribes wealth. | |
bool | CheckAsset (Tribe::AssetType type, csString name, int number) |
Check to see if enough assets are available. | |
bool | CheckAttach (NPC *npc) |
Attach a new member to the tribe if the NPC is a member. | |
bool | CheckKnowledge (csString knowHow) |
Check if knowledge is known. | |
bool | CheckMembers (const csString &type, int number) |
Check to see if enough members are idle. | |
bool | CheckResource (csString resource, int number) |
Check to see if enough resources are available. | |
bool | CheckWithinBoundsTribeHome (NPC *npc, const csVector3 &pos, const iSector *sector) |
Check if the position is within the bounds of the tribe home. | |
int | CountResource (csString resource) const |
Return the amount of a given resource. | |
void | DeleteAsset (csString name, int quantity) |
Delete item assets. | |
void | DeleteAsset (csString name, csVector3 pos) |
Delete a building asset. | |
void | DeleteCyclicRecipe (Recipe *recipe) |
Delete a cyclic recipe. | |
void | DumpAssets () |
Dump Assets. | |
void | DumpBuffers () |
Dump Buffers. | |
void | DumpKnowledge () |
Dump knowledge to console. | |
void | DumpRecipesToConsole () |
Dumps all information about recipes to console. | |
Memory * | FindMemory (csString name, const csVector3 &pos, iSector *sector, float radius) |
Find a memory. | |
Memory * | FindMemory (csString name) |
Find a memory. | |
Memory * | FindNearestMemory (const char *name, const csVector3 &pos, const iSector *sector, float range=-1.0, float *foundRange=NULL) |
Find nearest memory to a position. | |
Memory * | FindPrivMemory (csString name, const csVector3 &pos, iSector *sector, float radius, NPC *npc) |
Find a privat memory. | |
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 | ForgetMemories (NPC *npc) |
Forget privat memories. | |
Asset * | GetAsset (uint32_t itemUID) |
Get asset. | |
Asset * | GetAsset (Tribe::AssetType type, csString name) |
Get asset. | |
Asset * | GetAsset (Tribe::AssetType type, csString name, csVector3 where, iSector *sector) |
Get an asset based on name and position. | |
Asset * | GetAsset (Tribe::AssetType type, csString name, Tribe::AssetStatus status) |
Get asset. | |
Asset * | GetAsset (gemNPCItem *item) |
Get asset. | |
csString | GetBuffer (const csString &bufferName) |
Return a named buffer from the NPC. | |
float | GetDeathRate () |
Retrive death rate average value from tribe. | |
void | GetHome (csVector3 &pos, float &radius, iSector *§or) |
Get home position for the tribe. | |
csVector3 | GetHomePosition () |
iSector * | GetHomeSector () |
csString | GetHomeSectorName () |
int | GetID () |
int | GetMaxSize () const |
Calculate the maximum number of members for the tribe. | |
NPC * | GetMember (size_t i) |
size_t | GetMemberCount () |
size_t | GetMemberIDCount () |
csList< Memory * >::Iterator | GetMemoryIterator () |
gemNPCActor * | GetMostHated (NPC *npc, float range, bool includeOutsideRegion, bool includeInvisible, bool includeInvincible, float *hate=NULL) |
Find the most hated entity for tribe within range. | |
const char * | GetName () |
Asset * | GetNearestAsset (Tribe::AssetType type, Tribe::AssetStatus status, csVector3 pos, iSector *sector, float range, float *locatedRange=NULL) |
Get nearest asset. | |
Asset * | GetNearestAsset (Tribe::AssetType type, csString name, Tribe::AssetStatus status, csVector3 pos, iSector *sector, float range, float *locatedRange=NULL) |
Get an asset. | |
const char * | GetNeededResource () |
Get the most needed resource for this tribe. | |
const char * | GetNeededResourceAreaType () |
Get a area for the most needed resource for this tribe. | |
const char * | GetNeededResourceNick () |
Get the nick for the most needed resource for this tribe. | |
csString | GetNPCIdleBehavior () |
Asset * | GetRandomAsset (Tribe::AssetType type, csString name, Tribe::AssetStatus status, csVector3 pos, iSector *sector, float range) |
Get an asset. | |
Asset * | GetRandomAsset (Tribe::AssetType type, Tribe::AssetStatus status, csVector3 pos, iSector *sector, float range) |
Get a random asset. | |
int | GetReproductionCost () const |
Return the reproduction cost for this tribe. | |
bool | GetResource (NPC *npc, csVector3 startPos, iSector *startSector, csVector3 &pos, iSector *§or, float range, bool random) |
Get a memorized location for resources. | |
Tribe::Memory * | GetResource (csString resourceName, NPC *npc) |
Get the closest Memory regarding a resource or the closest non-prospected mine. | |
const Resource & | GetResource (size_t n) |
size_t | GetResourceCount () |
float | GetResourceRate () |
Retrive resource rate average value from tribe. | |
Recipe * | GetTribalRecipe () |
Get the main recipe. | |
float | GetWealthResourceGrowth () const |
Get wealth resource growth rate. | |
float | GetWealthResourceGrowthActive () const |
Get wealth resource growth rate active. | |
int | GetWealthResourceGrowthActiveLimit () const |
Get wealth resource growth active limit. | |
bool | HandleDeath (NPC *npc) |
Remove members that die. | |
void | HandlePerception (NPC *npc, Perception *perception) |
Handled a perception given to this tribe. | |
void | HandlePersistItem (gemNPCItem *item) |
Handle persist items that should be assets. | |
bool | Load (iResultRow &row) |
Load the tribe object. | |
void | LoadAsset (iResultRow &row) |
Load an asset from an iResultRow. | |
bool | LoadMember (iResultRow &row) |
Load and add a new member to the tribe. | |
bool | LoadMemory (iResultRow &row) |
Load all stored memories from db. | |
void | LoadNPCMemoryBuffer (Tribe::Memory *memory, csArray< NPC * > npcs) |
Set npcs memory buffers - Using a memory. | |
bool | LoadNPCMemoryBuffer (const char *name, csArray< NPC * > npcs) |
Set npcs memory buffers. | |
bool | LoadResource (iResultRow &row) |
Load and add a new resource to the tribe. | |
void | Memorize (NPC *npc, Perception *perception) |
Memorize a perception. | |
void | ModifyWait (Recipe *recipe, int delta) |
Modify Wait Time for a recipe. | |
void | ProspectMine (NPC *npc, csString resource, csString nick) |
Assigned a resource to a prospect Mine. | |
void | RemoveAsset (Tribe::Asset *asset) |
Remove an asset. | |
void | ReplaceBuffers (csString &result) |
Replace $TBUFFER[x] with values from the NPC buffer. | |
void | SaveAsset (Tribe::Asset *asset, bool deletion=false) |
Save an asset to the db - responsable for deleting assets to. | |
void | SaveKnowledge (csString knowHow) |
Save a knowledge piece in the database. | |
void | SaveMemory (Memory *memory) |
Save a memory to the db. | |
void | SaveResource (Resource *resource, bool newResource) |
Save or update an resource in database. | |
virtual void | ScopedTimerCallback (const ScopedTimer *timer) |
Callback for debug of long time used in scopes. | |
csArray< NPC * > | SelectNPCs (const csString &type, const char *number) |
Returns pointers to required npcs for a task. | |
void | SendPerception (const char *pcpt, csArray< NPC * > npcs) |
Sends the given perception to the given list of npcs. | |
void | SendPerception (const char *pcpt) |
Sends the given perception to the tribe. | |
void | SetBuffer (const csString &bufferName, const csString &value) |
Set/Update the value of a named buffer. | |
void | SetHome (const csVector3 &pos, float radius, iSector *sector) |
Set home position for the tribe. | |
void | SetRecipeManager (RecipeManager *rm) |
Sets the tribe's recipe manager. | |
void | ShareMemories (NPC *npc) |
Share privat memories with the other npcs. | |
bool | ShouldGrow () const |
Check if the tribe should grow by checking number of members against max size. | |
Tribe (EventManager *eventmngr, RecipeManager *rm) | |
Construct a new tribe object. | |
void | TriggerEvent (Perception *pcpt, float maxRange=-1.0, csVector3 *basePos=NULL, iSector *baseSector=NULL) |
Send a perception to all members of the tribe. | |
void | Unbuild (NPC *npc, gemNPCItem *building) |
Tear down a building. | |
void | UpdateRecipeData (int delta) |
Updates recipe wait times. | |
virtual | ~Tribe () |
Destruct a tribe object. | |
Static Public Attributes | |
static const char * | AssetStatusStr [] |
static const char * | AssetTypeStr [] |
typedef csHash<csString,csString> Tribe::BufferHash |
enum Tribe::AssetStatus |
enum Tribe::AssetType |
Tribe::Tribe | ( | EventManager * | eventmngr, |
RecipeManager * | rm | ||
) |
Construct a new tribe object.
virtual Tribe::~Tribe | ( | ) | [virtual] |
Destruct a tribe object.
void Tribe::AddAsset | ( | Tribe::AssetType | type, |
csString | name, | ||
gemNPCItem * | item, | ||
int | quantity, | ||
int | id = -1 |
||
) |
Add an item asset.
Tribe::Asset* Tribe::AddAsset | ( | Tribe::AssetType | type, |
csString | name, | ||
csVector3 | position, | ||
iSector * | sector, | ||
Tribe::AssetStatus | status | ||
) |
Add an asset to the tribe.
void Tribe::AddKnowledge | ( | csString | knowHow | ) | [inline] |
bool Tribe::AddMember | ( | PID | pid, |
const char * | tribeMemberType | ||
) |
Adds a new member to the tribe.
void Tribe::AddMemory | ( | csString | name, |
const csVector3 & | pos, | ||
iSector * | sector, | ||
float | radius, | ||
NPC * | npc | ||
) |
Add a new memory to the tribe.
void Tribe::AddResource | ( | csString | resource, |
int | amount, | ||
csString | nick = "" |
||
) |
Add a new resource to the tribe resource table.
void Tribe::Advance | ( | csTicks | when, |
EventManager * | eventmgr | ||
) |
Advance the tribe.
int Tribe::AliveCount | ( | ) | const |
Count number of alive members.
size_t Tribe::AssetQuantity | ( | Tribe::AssetType | type, |
csString | name | ||
) |
Return the quanitity of the given asset type matching the name.
bool Tribe::AttachMember | ( | NPC * | npc, |
const char * | tribeMemberType | ||
) |
Attach a new member to the tribe.
bool Tribe::CanGrow | ( | ) | const |
Check if the tribe can grow by checking the tribes wealth.
bool Tribe::CheckAsset | ( | Tribe::AssetType | type, |
csString | name, | ||
int | number | ||
) |
Check to see if enough assets are available.
bool Tribe::CheckKnowledge | ( | csString | knowHow | ) |
Check if knowledge is known.
bool Tribe::CheckMembers | ( | const csString & | type, |
int | number | ||
) |
Check to see if enough members are idle.
bool Tribe::CheckResource | ( | csString | resource, |
int | number | ||
) |
Check to see if enough resources are available.
bool Tribe::CheckWithinBoundsTribeHome | ( | NPC * | npc, |
const csVector3 & | pos, | ||
const iSector * | sector | ||
) |
Check if the position is within the bounds of the tribe home.
npc | The npc responsible for this checking |
pos | The position to check |
sector | The sector to check |
int Tribe::CountResource | ( | csString | resource | ) | const |
Return the amount of a given resource.
void Tribe::DeleteAsset | ( | csString | name, |
int | quantity | ||
) |
Delete item assets.
void Tribe::DeleteAsset | ( | csString | name, |
csVector3 | pos | ||
) |
Delete a building asset.
void Tribe::DeleteCyclicRecipe | ( | Recipe * | recipe | ) |
Delete a cyclic recipe.
void Tribe::DumpAssets | ( | ) |
Dump Assets.
void Tribe::DumpBuffers | ( | ) |
Dump Buffers.
void Tribe::DumpKnowledge | ( | ) |
Dump knowledge to console.
void Tribe::DumpRecipesToConsole | ( | ) |
Dumps all information about recipes to console.
Find a memory.
Memory* Tribe::FindMemory | ( | csString | name | ) |
Find a memory.
Memory* Tribe::FindNearestMemory | ( | const char * | name, |
const csVector3 & | pos, | ||
const iSector * | sector, | ||
float | range = -1.0 , |
||
float * | foundRange = NULL |
||
) |
Find nearest memory to a position.
Memory* Tribe::FindPrivMemory | ( | csString | name, |
const csVector3 & | pos, | ||
iSector * | sector, | ||
float | radius, | ||
NPC * | npc | ||
) |
Find a privat memory.
Memory* Tribe::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 Tribe::ForgetMemories | ( | NPC * | npc | ) |
Forget privat memories.
Should be called when npc die.
Asset* Tribe::GetAsset | ( | Tribe::AssetType | type, |
csString | name, | ||
csVector3 | where, | ||
iSector * | sector | ||
) |
Get an asset based on name and position.
Asset* Tribe::GetAsset | ( | Tribe::AssetType | type, |
csString | name | ||
) |
Get asset.
Asset* Tribe::GetAsset | ( | Tribe::AssetType | type, |
csString | name, | ||
Tribe::AssetStatus | status | ||
) |
Get asset.
Asset* Tribe::GetAsset | ( | gemNPCItem * | item | ) |
Get asset.
Asset* Tribe::GetAsset | ( | uint32_t | itemUID | ) |
Get asset.
csString Tribe::GetBuffer | ( | const csString & | bufferName | ) |
Return a named buffer from the NPC.
Function used to get data from buffers containing information.
bufferName | The name of the buffer to retrive. |
float Tribe::GetDeathRate | ( | ) | [inline] |
void Tribe::GetHome | ( | csVector3 & | pos, |
float & | radius, | ||
iSector *& | sector | ||
) |
Get home position for the tribe.
iSector* Tribe::GetHomeSector | ( | ) |
int Tribe::GetMaxSize | ( | ) | const |
Calculate the maximum number of members for the tribe.
csList<Memory*>::Iterator Tribe::GetMemoryIterator | ( | ) | [inline] |
gemNPCActor* Tribe::GetMostHated | ( | NPC * | npc, |
float | range, | ||
bool | includeOutsideRegion, | ||
bool | includeInvisible, | ||
bool | includeInvincible, | ||
float * | hate = NULL |
||
) |
Find the most hated entity for tribe within range.
Check the hate list and retrive most hated entity within range of the given NPC.
npc | The senter of the search. |
range | The range to search for hated entities. |
includeOutsideRegion | Include outside region entities in the search. |
includeInvisible | Include invisible entities in the search. |
includeInvincible | Include invincible entities in the search. |
hate | If diffrent from NULL, set upon return to the hate of the hated. |
Asset* Tribe::GetNearestAsset | ( | Tribe::AssetType | type, |
Tribe::AssetStatus | status, | ||
csVector3 | pos, | ||
iSector * | sector, | ||
float | range, | ||
float * | locatedRange = NULL |
||
) |
Get nearest asset.
Asset* Tribe::GetNearestAsset | ( | Tribe::AssetType | type, |
csString | name, | ||
Tribe::AssetStatus | status, | ||
csVector3 | pos, | ||
iSector * | sector, | ||
float | range, | ||
float * | locatedRange = NULL |
||
) |
Get an asset.
const char* Tribe::GetNeededResource | ( | ) |
Get the most needed resource for this tribe.
const char* Tribe::GetNeededResourceAreaType | ( | ) |
Get a area for the most needed resource for this tribe.
const char* Tribe::GetNeededResourceNick | ( | ) |
Get the nick for the most needed resource for this tribe.
Asset* Tribe::GetRandomAsset | ( | Tribe::AssetType | type, |
Tribe::AssetStatus | status, | ||
csVector3 | pos, | ||
iSector * | sector, | ||
float | range | ||
) |
Get a random asset.
Asset* Tribe::GetRandomAsset | ( | Tribe::AssetType | type, |
csString | name, | ||
Tribe::AssetStatus | status, | ||
csVector3 | pos, | ||
iSector * | sector, | ||
float | range | ||
) |
Get an asset.
int Tribe::GetReproductionCost | ( | ) | const |
Return the reproduction cost for this tribe.
Tribe::Memory* Tribe::GetResource | ( | csString | resourceName, |
NPC * | npc | ||
) |
Get the closest Memory regarding a resource or the closest non-prospected mine.
bool Tribe::GetResource | ( | NPC * | npc, |
csVector3 | startPos, | ||
iSector * | startSector, | ||
csVector3 & | pos, | ||
iSector *& | sector, | ||
float | range, | ||
bool | random | ||
) |
Get a memorized location for resources.
float Tribe::GetResourceRate | ( | ) | [inline] |
Recipe* Tribe::GetTribalRecipe | ( | ) |
Get the main recipe.
float Tribe::GetWealthResourceGrowth | ( | ) | const |
Get wealth resource growth rate.
Get the rate that the wealth will grow when all members are dead.
float Tribe::GetWealthResourceGrowthActive | ( | ) | const |
Get wealth resource growth rate active.
Get the rate that the wealth will grow when there are alive members.
int Tribe::GetWealthResourceGrowthActiveLimit | ( | ) | const |
Get wealth resource growth active limit.
Get the limit that the wealth will be capped at when there are alive members.
bool Tribe::HandleDeath | ( | NPC * | npc | ) |
Remove members that die.
void Tribe::HandlePerception | ( | NPC * | npc, |
Perception * | perception | ||
) |
Handled a perception given to this tribe.
void Tribe::HandlePersistItem | ( | gemNPCItem * | item | ) |
Handle persist items that should be assets.
bool Tribe::Load | ( | iResultRow & | row | ) |
Load the tribe object.
void Tribe::LoadAsset | ( | iResultRow & | row | ) |
Load an asset from an iResultRow.
bool Tribe::LoadMember | ( | iResultRow & | row | ) |
Load and add a new member to the tribe.
bool Tribe::LoadMemory | ( | iResultRow & | row | ) |
Load all stored memories from db.
void Tribe::LoadNPCMemoryBuffer | ( | Tribe::Memory * | memory, |
csArray< NPC * > | npcs | ||
) |
Set npcs memory buffers - Using a memory.
Set npcs memory buffers.
Loads locations into the Memory buffers of the npcs. Useful when assigning tasks to them.
name | Name of the memory/resource to load. |
npcs | Link to the npcs on which to load. |
bool Tribe::LoadResource | ( | iResultRow & | row | ) |
Load and add a new resource to the tribe.
void Tribe::Memorize | ( | NPC * | npc, |
Perception * | perception | ||
) |
void Tribe::ProspectMine | ( | NPC * | npc, |
csString | resource, | ||
csString | nick | ||
) |
Assigned a resource to a prospect Mine.
Upon 'Explore' behavior, tribe members may find locations named 'mine'. After mining from an unkown deposit, the npcclient will receive a psWorkDoneMessage telling it what his npc just mined. This function renames the former 'mine' Memory with it's real deposit name.
npc | The npc who prospected it to access his memoryBuffer. |
resource | The resulted resource received from psServer. |
nick | The nick name of the resource for this mine. |
void Tribe::RemoveAsset | ( | Tribe::Asset * | asset | ) |
Remove an asset.
void Tribe::ReplaceBuffers | ( | csString & | result | ) |
Replace $TBUFFER[x] with values from the NPC buffer.
result | String to replace buffers in. |
void Tribe::SaveAsset | ( | Tribe::Asset * | asset, |
bool | deletion = false |
||
) |
Save an asset to the db - responsable for deleting assets to.
void Tribe::SaveKnowledge | ( | csString | knowHow | ) |
Save a knowledge piece in the database.
void Tribe::SaveMemory | ( | Memory * | memory | ) |
Save a memory to the db.
void Tribe::SaveResource | ( | Resource * | resource, |
bool | newResource | ||
) |
Save or update an resource in database.
virtual void Tribe::ScopedTimerCallback | ( | const ScopedTimer * | timer | ) | [virtual] |
Callback for debug of long time used in scopes.
Implements ScopedTimerCB.
Returns pointers to required npcs for a task.
void Tribe::SendPerception | ( | const char * | pcpt | ) |
Sends the given perception to the tribe.
Used to send perceptions to all tribe members.
pcpt | The perception name to be sent |
Sends the given perception to the given list of npcs.
Used by the recipe manager to send perceptions to tribe members selected by the active recipe.
pcpt | The perception name to be sent |
npcs | The list of npcs to send perception to. |
void Tribe::SetBuffer | ( | const csString & | bufferName, |
const csString & | value | ||
) |
Set/Update the value of a named buffer.
bufferName | The buffer name. |
value | The value to put in the buffer. |
void Tribe::SetHome | ( | const csVector3 & | pos, |
float | radius, | ||
iSector * | sector | ||
) |
Set home position for the tribe.
void Tribe::SetRecipeManager | ( | RecipeManager * | rm | ) | [inline] |
void Tribe::ShareMemories | ( | NPC * | npc | ) |
Share privat memories with the other npcs.
Should be called when npc return to home.
bool Tribe::ShouldGrow | ( | ) | const |
Check if the tribe should grow by checking number of members against max size.
void Tribe::TriggerEvent | ( | Perception * | pcpt, |
float | maxRange = -1.0 , |
||
csVector3 * | basePos = NULL , |
||
iSector * | baseSector = NULL |
||
) |
Send a perception to all members of the tribe.
This will send the perception to all the members of the tribe. If the maxRange has been set to something greater than 0.0 a range check will be applied. Only members within the range from the base position and sector will be triggered.
pcpt | Perception to be sent. |
maxRange | If greater then 0.0 then max range apply |
basePos | The base position for range checks. |
baseSector | The base sector for range checks. |
void Tribe::Unbuild | ( | NPC * | npc, |
gemNPCItem * | building | ||
) |
Tear down a building.
void Tribe::UpdateRecipeData | ( | int | delta | ) |
Updates recipe wait times.
const char* Tribe::AssetStatusStr[] [static] |
const char* Tribe::AssetTypeStr[] [static] |