<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://planeshift.top-ix.org//pswiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Zee</id>
	<title>PSwiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://planeshift.top-ix.org//pswiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Zee"/>
	<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php/Special:Contributions/Zee"/>
	<updated>2026-04-06T08:26:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Scripting&amp;diff=9143</id>
		<title>Tribe Scripting</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Scripting&amp;diff=9143"/>
		<updated>2011-09-22T15:03:59Z</updated>

		<summary type="html">&lt;p&gt;Zee: Added info about recipe logic&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Recipe Logic =&lt;br /&gt;
&lt;br /&gt;
== Recipes ==&lt;br /&gt;
&#039;&#039;&#039;A recipe database entry&#039;&#039;&#039;&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!name&lt;br /&gt;
!requirements&lt;br /&gt;
!algorithm&lt;br /&gt;
!persistent&lt;br /&gt;
|-&lt;br /&gt;
|used for db storing&lt;br /&gt;
|Name of the recipe&lt;br /&gt;
|requirement string containing all requirements&lt;br /&gt;
|algorithm string containing all algorithm steps&lt;br /&gt;
|If this flag is on, the recipe won&#039;t ever be deleted from the recipe tree. After parsing it, if no other recipe has a higher priority... it will be reparsed.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Usage of Recipes ==&lt;br /&gt;
&lt;br /&gt;
On tribe initialization, a tribal recipe is first loaded in respect of the information indicated by the &#039;tribal_recipe&#039; field. (see tribes.sql). The tribal recipe is formed from &#039;Tribe Info&#039; functions. (see below)&lt;br /&gt;
&lt;br /&gt;
Based on those functions the npctype for each tribe is created and initial recipes are loaded.&lt;br /&gt;
&lt;br /&gt;
Further on, each Recipe has two important sections: requirements and algorithm. Each of those two is represented by a long string (the maximum is set in the database to 1000 characters) of functions separated by a semi-colon &#039;;&#039;. Upon parsing the long string is split in respect of the semicolons (;) and the recipe manager analyzes each resulting function.&lt;br /&gt;
&lt;br /&gt;
== Recipe-Tree Nodes ==&lt;br /&gt;
&lt;br /&gt;
Inside a tribe object, recipes are stored as Recipe Tree Nodes. This class was created to facilitate the management of recipes and the way recipes are selected to be parsed.&lt;br /&gt;
&lt;br /&gt;
All recipes are stored as leaves in a tree. This way we can always know their hierarchy and precedence.&lt;br /&gt;
&lt;br /&gt;
Besides the obvious usage as a tree, recipe tree nodes also hold vital data for recipe parsing: last requirement parsed, last algorithm step parsed, remaining waiting time.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s consider an example of a tribe which has some building spots available and the task to build on those spots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
TribalRecipe *-- BuildingSpots&lt;br /&gt;
TribalRecipe *-- ThreeBuildings&lt;br /&gt;
ThreeBuildings *-- Breed : Not enough members&lt;br /&gt;
Breed *-- GatherFood : Not enough food&lt;br /&gt;
ThreeBuildings *-- GatherWood: Not enough wood&lt;br /&gt;
ThreeBuildings *-- GatherStone: Not enough stone&lt;br /&gt;
ThreeBuildings *-- LearnMasonry : knowledge masonry needed&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Having the tree above, it&#039;s easy to select the actions required to complete the task. We first get some more food. After that we get the required members, search for wood and stone, and finally build the buildings.&lt;br /&gt;
&lt;br /&gt;
= Tribe Info =&lt;br /&gt;
&lt;br /&gt;
== Brain ==&lt;br /&gt;
&lt;br /&gt;
Syntax: brain(x);&lt;br /&gt;
&lt;br /&gt;
Known Arguments: x in { civilised, savage, inhuman }&lt;br /&gt;
&lt;br /&gt;
Effect: Decides the advancement of this tribe. At the moment it acts only as a token. An expression with the same syntax (e.g. &amp;quot;brain(civilised);&amp;quot;) can be placed as a requirement.&lt;br /&gt;
&lt;br /&gt;
== Aggressivity ==&lt;br /&gt;
&lt;br /&gt;
Syntax: aggressivity(x);&lt;br /&gt;
&lt;br /&gt;
Known Arguments: x in { warlike, neutral, peaceful }&lt;br /&gt;
&lt;br /&gt;
Effect: Decides the way the tribe reacts to other entities around it&#039;s members:&lt;br /&gt;
* Warlike  -- Attack anything on sight.&lt;br /&gt;
* Neutral  -- Attack only if members are attacked.&lt;br /&gt;
* Peaceful -- If tribe members are attack they flee, trying to escape.&lt;br /&gt;
&lt;br /&gt;
Mechanics: Upon parsing this function, an extra reaction is added to the tribal npctype in respect of this function&#039;s argument.&lt;br /&gt;
&lt;br /&gt;
== LoadRecipe ==&lt;br /&gt;
&lt;br /&gt;
Syntax: loadRecipe(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is a Recipe Name&lt;br /&gt;
&lt;br /&gt;
Effect: Loads a recipe into the recipe tree. The new recipe&#039;s priority will be the current recipe&#039;s priority + 1.&lt;br /&gt;
&lt;br /&gt;
== LoadCyclicRecipe ==&lt;br /&gt;
&lt;br /&gt;
Syntax: loadCyclicRecipe(x,t);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is a Recipe Name&lt;br /&gt;
* &#039;t&#039; is an int, representing the number of ticks between recipe executions&lt;br /&gt;
&lt;br /&gt;
Effect: Loads a recipe into the recipe tree once every &#039;t&#039; ticks, with highest priority.&lt;br /&gt;
&lt;br /&gt;
== SleepPeriod ==&lt;br /&gt;
&lt;br /&gt;
Syntax: sleepPeriod(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: x in { diurnal, nocturnal, nosleep }&lt;br /&gt;
&lt;br /&gt;
Effect: Makes the tribe members sleep at the given period of day.&lt;br /&gt;
&lt;br /&gt;
Mechanics: Upon parsing this function, an extra reaction is added to the tribal npctype. The reaction should react to timeofday perceptions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Requirements =&lt;br /&gt;
&lt;br /&gt;
== Tribesman ==&lt;br /&gt;
&lt;br /&gt;
Syntax: tribesman(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* x is a tribesman type (types are not well-defined at the moment). Keyword &#039;any&#039; is accepted too in order to define any member.&lt;br /&gt;
* y is an int defining the number of tribesmen needed&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: The tribal object checks for a number &#039;y&#039; of tribesman typed &#039;x&#039; with the current behavior equal to the tribe&#039;s idle behavior. (e.g. &amp;quot;do nothing&amp;quot; behavior) If &#039;y&#039; members are found idle, the requirement is considered met.&lt;br /&gt;
&lt;br /&gt;
== Resource ==&lt;br /&gt;
&lt;br /&gt;
Syntax: resource(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* x is the resource name &lt;br /&gt;
* y is the resource quantity required&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: The tribal object checks for a &#039;y&#039; quantity of &#039;x&#039; resource. If this quantity is found then the resource is considered complete.&lt;br /&gt;
&lt;br /&gt;
Judging by the way natural resources are defined, any string declared in natural_resources.sql as a resource can be parsed and mined by the tribe. By default, any new mine found by the tribesmen is stored as a memory named &#039;mine&#039;. Upon it&#039;s first mining action done on the &#039;mine&#039; memory, a reward is granted to the npc. When the NPC gets home and gives that to the tribal object, the memory &#039;mine&#039; is renamed after the reward. In conclusion, having a resource named &#039;Space Shuttle&#039; is valid and works.&lt;br /&gt;
&lt;br /&gt;
Note: The resource requirement just checks if enough resources are available. Use &#039;alterResource&#039; function in your recipes in order to actually substract resource from the tribe bank.&lt;br /&gt;
&lt;br /&gt;
== Knowledge ==&lt;br /&gt;
&lt;br /&gt;
Syntax: knowledge(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; can be any string.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: As described in the [[Tribes]] document, knowledge are tokens that keep track on technologies developed by the tribe. It&#039;s valid to request any string as long as it would be possible for the tribe to develop the knowledge. Otherwise the requirement will never be met.&lt;br /&gt;
&lt;br /&gt;
== Item ==&lt;br /&gt;
&lt;br /&gt;
Syntax: item(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is an item/building name.&lt;br /&gt;
* &#039;y&#039; is an int defining the quantity of items needed.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: At the moment, items are &#039;magically&#039; stored inside the tribal object. This object keeps track on items and buildings with the &#039;Asset&#039; structure. &#039;x&#039; can be any string with the condition that the tribe can actually gain the requested asset. Otherwise the requirement will never be met. Upon parsing this requirement, the tribal object checks it&#039;s asset arrays for the item &#039;x&#039; of quantity &#039;y&#039;.&lt;br /&gt;
&lt;br /&gt;
== Recipe ==&lt;br /&gt;
&lt;br /&gt;
Syntax: recipe(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is a recipe name.&lt;br /&gt;
* &#039;y&#039; is an int defining the quantity of recipes needed.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: Upon parsing this requirement, the parser just adds an &#039;y&#039; number of &#039;x&#039; recipes to the recipe tree.&lt;br /&gt;
&lt;br /&gt;
This requirement isn&#039;t quite practical and should be avoided.&lt;br /&gt;
&lt;br /&gt;
== Trader (Not available) ==&lt;br /&gt;
&lt;br /&gt;
Syntax: trader(x);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is an item name&lt;br /&gt;
&lt;br /&gt;
Effect: This requirement should check the traders array for a nearby trader giving item &#039;x&#039;.&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
Syntax: memory(x);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is a memory name&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: Upon parsing this requirement, the parser checks the memory array for a memory called &#039;x&#039;. If it is found, requirement is considered met.&lt;br /&gt;
&lt;br /&gt;
= Algorithm Steps =&lt;br /&gt;
&lt;br /&gt;
== AlterResource ==&lt;br /&gt;
&lt;br /&gt;
Syntax: alterResource(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is a resource name&lt;br /&gt;
* &#039;y&#039; is an int describing quantity&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: Upon parsing this function, the parser modifies the quantity of resources available in the tribe.&lt;br /&gt;
&lt;br /&gt;
Note: The &#039;y&#039; value will be added to the current value in the tribe&#039;s bank. Use negative value to represent costs. (e.g. alterResource(gold,-20); in order to pay for a building)&lt;br /&gt;
&lt;br /&gt;
== AddKnowledge ==&lt;br /&gt;
&lt;br /&gt;
Syntax: addKnowledge(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; can be any string.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: Adds the &#039;x&#039; token as a piece of knowledge in the knowledge array.&lt;br /&gt;
&lt;br /&gt;
== Select ==&lt;br /&gt;
&lt;br /&gt;
Syntax: select(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments: &lt;br /&gt;
* &#039;x&#039; is a tribe member type.&lt;br /&gt;
* &#039;y&#039; is an int defining the number of members to be selected.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: The &#039;select&#039; function is probably the most important algorithm step. It selects the members passed as arguments and keeps them in a temporary npc array so they can accept orders from the next algorithm steps. It actually works like selecting units and commanding them in a strategy game. After a &#039;select&#039; function, all next algorithm steps apply to selected members only, until another &#039;select&#039; command is issued or the recipe is completed.&lt;br /&gt;
&lt;br /&gt;
  Example:&lt;br /&gt;
     // Will send 3 miners to mine for gold.&lt;br /&gt;
     select(miner,3);&lt;br /&gt;
     locate(gold);&lt;br /&gt;
     mine();&lt;br /&gt;
&lt;br /&gt;
== Locate ==&lt;br /&gt;
&lt;br /&gt;
Syntax: locate(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is a memory name.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This function works like the &#039;locate operation&#039; from the NPC Scripting. It looks in the tribe&#039;s memory array for the memory called &#039;x&#039; and loads it into the previous selected npc&#039;s buffers. It is vital to use it before basic functions like mine,gather,guard,attack that use the npc buffers to execute.&lt;br /&gt;
&lt;br /&gt;
== LocateResource ==&lt;br /&gt;
&lt;br /&gt;
Syntax: locateResource(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is a resource name.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This function works like the above-mentioned &#039;locate&#039; function. The sole difference is that this function tries to locate resource &#039;x&#039;, and it case it fails it tries to locate memories &#039;mine&#039; or &#039;field&#039;. (which are the standard names of unprospected/undiscovered resource zones). In case nor &#039;mine&#039; or &#039;field&#039; are found, it sends the previous selected npcs to explore for them.&lt;br /&gt;
&lt;br /&gt;
== LocateBuildingSpot ==&lt;br /&gt;
&lt;br /&gt;
Syntax: locateBuildingSpot(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is a building name.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This functions locates a building spot previously reserved via &#039;reserveBuildingSpot&#039; function. It searches for in the asset array and uploads it&#039;s position in the npc&#039;s memory buffers.&lt;br /&gt;
&lt;br /&gt;
== ReserveSpot ==&lt;br /&gt;
&lt;br /&gt;
Syntax: reserveSpot(x,y,z,bname);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039;, &#039;y&#039; and &#039;z&#039; are coordinates in the same sector as the tribe&lt;br /&gt;
* &#039;bname&#039; is the building name we want to reserve the spot for&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This function is used so the scripter (you) can arrange the future village of the tribe. When creating a tribe, a recipe containing building spots should be wrote in order to pinpoint where building should be constructed in the future.&lt;br /&gt;
&lt;br /&gt;
== GoWork ==&lt;br /&gt;
&lt;br /&gt;
Syntax: goWork(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is an int defining the number of seconds the npcs should work for.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: The &#039;goWork&#039; function sends previously selected npcs to a previously selected location and activates their &#039;work&#039; behavior on that location for &#039;x&#039; number of seconds.&lt;br /&gt;
&lt;br /&gt;
== Wait ==&lt;br /&gt;
&lt;br /&gt;
Syntax: wait(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is an int defining number of ticks to halt recipe for.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This function sets the wait time for a recipe. By default, no recipes with a wait time bigger than 0 are reparsed. As a consequence, applying wait time to a recipe will make the parser halt the current recipe at the current algorithm step and parse other recipes that wait in line.&lt;br /&gt;
&lt;br /&gt;
== Mine ==&lt;br /&gt;
&lt;br /&gt;
Syntax: mine();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to a previously selected mine and fires their &#039;mine&#039; behavior.&lt;br /&gt;
&lt;br /&gt;
== Gather == &lt;br /&gt;
&lt;br /&gt;
Syntax: gather();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to a previously selected field and fires their &#039;gather&#039; behavior.&lt;br /&gt;
&lt;br /&gt;
== Mate ==&lt;br /&gt;
&lt;br /&gt;
Syntax: mate();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to their home and fires their &#039;breed&#039; behavior.&lt;br /&gt;
&lt;br /&gt;
Note: By default, the &#039;mate&#039; functions requires no resources and has no checks. Use it in a recipe that checks that enough resources for breeding are available.&lt;br /&gt;
&lt;br /&gt;
== Attack ==&lt;br /&gt;
&lt;br /&gt;
Syntax: attack();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to attack a previously selected location. If the selected location is not an attackable entity they will simply move there and attack whatever is near.&lt;br /&gt;
&lt;br /&gt;
== Guard ==&lt;br /&gt;
&lt;br /&gt;
Syntax: guard();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to guard the selected location. Members will just patrol the area and attack whatever poses a threat.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9142</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9142"/>
		<updated>2011-09-22T14:19:50Z</updated>

		<summary type="html">&lt;p&gt;Zee: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Scripting&amp;diff=9141</id>
		<title>Tribe Scripting</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Scripting&amp;diff=9141"/>
		<updated>2011-09-22T13:52:00Z</updated>

		<summary type="html">&lt;p&gt;Zee: Created page with the function list and short explanations.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Info =&lt;br /&gt;
&lt;br /&gt;
== Brain ==&lt;br /&gt;
&lt;br /&gt;
Syntax: brain(x);&lt;br /&gt;
&lt;br /&gt;
Known Arguments: x in { civilised, savage, inhuman }&lt;br /&gt;
&lt;br /&gt;
Effect: Decides the advancement of this tribe. At the moment it acts only as a token. An expression with the same syntax (e.g. &amp;quot;brain(civilised);&amp;quot;) can be placed as a requirement.&lt;br /&gt;
&lt;br /&gt;
== Aggressivity ==&lt;br /&gt;
&lt;br /&gt;
Syntax: aggressivity(x);&lt;br /&gt;
&lt;br /&gt;
Known Arguments: x in { warlike, neutral, peaceful }&lt;br /&gt;
&lt;br /&gt;
Effect: Decides the way the tribe reacts to other entities around it&#039;s members:&lt;br /&gt;
* Warlike  -- Attack anything on sight.&lt;br /&gt;
* Neutral  -- Attack only if members are attacked.&lt;br /&gt;
* Peaceful -- If tribe members are attack they flee, trying to escape.&lt;br /&gt;
&lt;br /&gt;
Mechanics: Upon parsing this function, an extra reaction is added to the tribal npctype in respect of this function&#039;s argument.&lt;br /&gt;
&lt;br /&gt;
== LoadRecipe ==&lt;br /&gt;
&lt;br /&gt;
Syntax: loadRecipe(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is a Recipe Name&lt;br /&gt;
&lt;br /&gt;
Effect: Loads a recipe into the recipe tree. The new recipe&#039;s priority will be the current recipe&#039;s priority + 1.&lt;br /&gt;
&lt;br /&gt;
== LoadCyclicRecipe ==&lt;br /&gt;
&lt;br /&gt;
Syntax: loadCyclicRecipe(x,t);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is a Recipe Name&lt;br /&gt;
* &#039;t&#039; is an int, representing the number of ticks between recipe executions&lt;br /&gt;
&lt;br /&gt;
Effect: Loads a recipe into the recipe tree once every &#039;t&#039; ticks, with highest priority.&lt;br /&gt;
&lt;br /&gt;
== SleepPeriod ==&lt;br /&gt;
&lt;br /&gt;
Syntax: sleepPeriod(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: x in { diurnal, nocturnal, nosleep }&lt;br /&gt;
&lt;br /&gt;
Effect: Makes the tribe members sleep at the given period of day.&lt;br /&gt;
&lt;br /&gt;
Mechanics: Upon parsing this function, an extra reaction is added to the tribal npctype. The reaction should react to timeofday perceptions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Requirements =&lt;br /&gt;
&lt;br /&gt;
== Tribesman ==&lt;br /&gt;
&lt;br /&gt;
Syntax: tribesman(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* x is a tribesman type (types are not well-defined at the moment). Keyword &#039;any&#039; is accepted too in order to define any member.&lt;br /&gt;
* y is an int defining the number of tribesmen needed&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: The tribal object checks for a number &#039;y&#039; of tribesman typed &#039;x&#039; with the current behavior equal to the tribe&#039;s idle behavior. (e.g. &amp;quot;do nothing&amp;quot; behavior) If &#039;y&#039; members are found idle, the requirement is considered met.&lt;br /&gt;
&lt;br /&gt;
== Resource ==&lt;br /&gt;
&lt;br /&gt;
Syntax: resource(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* x is the resource name &lt;br /&gt;
* y is the resource quantity required&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: The tribal object checks for a &#039;y&#039; quantity of &#039;x&#039; resource. If this quantity is found then the resource is considered complete.&lt;br /&gt;
&lt;br /&gt;
Judging by the way natural resources are defined, any string declared in natural_resources.sql as a resource can be parsed and mined by the tribe. By default, any new mine found by the tribesmen is stored as a memory named &#039;mine&#039;. Upon it&#039;s first mining action done on the &#039;mine&#039; memory, a reward is granted to the npc. When the NPC gets home and gives that to the tribal object, the memory &#039;mine&#039; is renamed after the reward. In conclusion, having a resource named &#039;Space Shuttle&#039; is valid and works.&lt;br /&gt;
&lt;br /&gt;
Note: The resource requirement just checks if enough resources are available. Use &#039;alterResource&#039; function in your recipes in order to actually substract resource from the tribe bank.&lt;br /&gt;
&lt;br /&gt;
== Knowledge ==&lt;br /&gt;
&lt;br /&gt;
Syntax: knowledge(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; can be any string.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: As described in the [[Tribes]] document, knowledge are tokens that keep track on technologies developed by the tribe. It&#039;s valid to request any string as long as it would be possible for the tribe to develop the knowledge. Otherwise the requirement will never be met.&lt;br /&gt;
&lt;br /&gt;
== Item ==&lt;br /&gt;
&lt;br /&gt;
Syntax: item(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is an item/building name.&lt;br /&gt;
* &#039;y&#039; is an int defining the quantity of items needed.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: At the moment, items are &#039;magically&#039; stored inside the tribal object. This object keeps track on items and buildings with the &#039;Asset&#039; structure. &#039;x&#039; can be any string with the condition that the tribe can actually gain the requested asset. Otherwise the requirement will never be met. Upon parsing this requirement, the tribal object checks it&#039;s asset arrays for the item &#039;x&#039; of quantity &#039;y&#039;.&lt;br /&gt;
&lt;br /&gt;
== Recipe ==&lt;br /&gt;
&lt;br /&gt;
Syntax: recipe(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is a recipe name.&lt;br /&gt;
* &#039;y&#039; is an int defining the quantity of recipes needed.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: Upon parsing this requirement, the parser just adds an &#039;y&#039; number of &#039;x&#039; recipes to the recipe tree.&lt;br /&gt;
&lt;br /&gt;
This requirement isn&#039;t quite practical and should be avoided.&lt;br /&gt;
&lt;br /&gt;
== Trader (Not available) ==&lt;br /&gt;
&lt;br /&gt;
Syntax: trader(x);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is an item name&lt;br /&gt;
&lt;br /&gt;
Effect: This requirement should check the traders array for a nearby trader giving item &#039;x&#039;.&lt;br /&gt;
&lt;br /&gt;
== Memory ==&lt;br /&gt;
&lt;br /&gt;
Syntax: memory(x);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is a memory name&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: Upon parsing this requirement, the parser checks the memory array for a memory called &#039;x&#039;. If it is found, requirement is considered met.&lt;br /&gt;
&lt;br /&gt;
= Algorithm Steps =&lt;br /&gt;
&lt;br /&gt;
== AlterResource ==&lt;br /&gt;
&lt;br /&gt;
Syntax: alterResource(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039; is a resource name&lt;br /&gt;
* &#039;y&#039; is an int describing quantity&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: Upon parsing this function, the parser modifies the quantity of resources available in the tribe.&lt;br /&gt;
&lt;br /&gt;
Note: The &#039;y&#039; value will be added to the current value in the tribe&#039;s bank. Use negative value to represent costs. (e.g. alterResource(gold,-20); in order to pay for a building)&lt;br /&gt;
&lt;br /&gt;
== AddKnowledge ==&lt;br /&gt;
&lt;br /&gt;
Syntax: addKnowledge(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; can be any string.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: Adds the &#039;x&#039; token as a piece of knowledge in the knowledge array.&lt;br /&gt;
&lt;br /&gt;
== Select ==&lt;br /&gt;
&lt;br /&gt;
Syntax: select(x,y);&lt;br /&gt;
&lt;br /&gt;
Arguments: &lt;br /&gt;
* &#039;x&#039; is a tribe member type.&lt;br /&gt;
* &#039;y&#039; is an int defining the number of members to be selected.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: The &#039;select&#039; function is probably the most important algorithm step. It selects the members passed as arguments and keeps them in a temporary npc array so they can accept orders from the next algorithm steps. It actually works like selecting units and commanding them in a strategy game. After a &#039;select&#039; function, all next algorithm steps apply to selected members only, until another &#039;select&#039; command is issued or the recipe is completed.&lt;br /&gt;
&lt;br /&gt;
  Example:&lt;br /&gt;
     // Will send 3 miners to mine for gold.&lt;br /&gt;
     select(miner,3);&lt;br /&gt;
     locate(gold);&lt;br /&gt;
     mine();&lt;br /&gt;
&lt;br /&gt;
== Locate ==&lt;br /&gt;
&lt;br /&gt;
Syntax: locate(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is a memory name.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This function works like the &#039;locate operation&#039; from the NPC Scripting. It looks in the tribe&#039;s memory array for the memory called &#039;x&#039; and loads it into the previous selected npc&#039;s buffers. It is vital to use it before basic functions like mine,gather,guard,attack that use the npc buffers to execute.&lt;br /&gt;
&lt;br /&gt;
== LocateResource ==&lt;br /&gt;
&lt;br /&gt;
Syntax: locateResource(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is a resource name.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This function works like the above-mentioned &#039;locate&#039; function. The sole difference is that this function tries to locate resource &#039;x&#039;, and it case it fails it tries to locate memories &#039;mine&#039; or &#039;field&#039;. (which are the standard names of unprospected/undiscovered resource zones). In case nor &#039;mine&#039; or &#039;field&#039; are found, it sends the previous selected npcs to explore for them.&lt;br /&gt;
&lt;br /&gt;
== LocateBuildingSpot ==&lt;br /&gt;
&lt;br /&gt;
Syntax: locateBuildingSpot(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is a building name.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This functions locates a building spot previously reserved via &#039;reserveBuildingSpot&#039; function. It searches for in the asset array and uploads it&#039;s position in the npc&#039;s memory buffers.&lt;br /&gt;
&lt;br /&gt;
== ReserveSpot ==&lt;br /&gt;
&lt;br /&gt;
Syntax: reserveSpot(x,y,z,bname);&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;x&#039;, &#039;y&#039; and &#039;z&#039; are coordinates in the same sector as the tribe&lt;br /&gt;
* &#039;bname&#039; is the building name we want to reserve the spot for&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This function is used so the scripter (you) can arrange the future village of the tribe. When creating a tribe, a recipe containing building spots should be wrote in order to pinpoint where building should be constructed in the future.&lt;br /&gt;
&lt;br /&gt;
== GoWork ==&lt;br /&gt;
&lt;br /&gt;
Syntax: goWork(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is an int defining the number of seconds the npcs should work for.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: The &#039;goWork&#039; function sends previously selected npcs to a previously selected location and activates their &#039;work&#039; behavior on that location for &#039;x&#039; number of seconds.&lt;br /&gt;
&lt;br /&gt;
== Wait ==&lt;br /&gt;
&lt;br /&gt;
Syntax: wait(x);&lt;br /&gt;
&lt;br /&gt;
Arguments: &#039;x&#039; is an int defining number of ticks to halt recipe for.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: This function sets the wait time for a recipe. By default, no recipes with a wait time bigger than 0 are reparsed. As a consequence, applying wait time to a recipe will make the parser halt the current recipe at the current algorithm step and parse other recipes that wait in line.&lt;br /&gt;
&lt;br /&gt;
== Mine ==&lt;br /&gt;
&lt;br /&gt;
Syntax: mine();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to a previously selected mine and fires their &#039;mine&#039; behavior.&lt;br /&gt;
&lt;br /&gt;
== Gather == &lt;br /&gt;
&lt;br /&gt;
Syntax: gather();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to a previously selected field and fires their &#039;gather&#039; behavior.&lt;br /&gt;
&lt;br /&gt;
== Mate ==&lt;br /&gt;
&lt;br /&gt;
Syntax: mate();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to their home and fires their &#039;breed&#039; behavior.&lt;br /&gt;
&lt;br /&gt;
Note: By default, the &#039;mate&#039; functions requires no resources and has no checks. Use it in a recipe that checks that enough resources for breeding are available.&lt;br /&gt;
&lt;br /&gt;
== Attack ==&lt;br /&gt;
&lt;br /&gt;
Syntax: attack();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to attack a previously selected location. If the selected location is not an attackable entity they will simply move there and attack whatever is near.&lt;br /&gt;
&lt;br /&gt;
== Guard ==&lt;br /&gt;
&lt;br /&gt;
Syntax: guard();&lt;br /&gt;
&lt;br /&gt;
Arguments: None.&lt;br /&gt;
&lt;br /&gt;
Effect &amp;amp; Mechanics: It sends previously selected members to guard the selected location. Members will just patrol the area and attack whatever poses a threat.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9140</id>
		<title>Tribe Design</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9140"/>
		<updated>2011-09-18T21:47:59Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Runtime */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Design =&lt;br /&gt;
&lt;br /&gt;
The tribe design is done using NPC Behaviors and Recipes. Tribe members are assigned tasks based on what the recipes dictates the tribe to achieve. This system uses a Recipe Manager which takes care of parsing recipes, breaking the initial recipe into subtasks and telling the npcs which action to take.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : members&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : deadMembers&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Resource : resources&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Memory : memories&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Asset : assets&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Knowledge : knowledge&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;1..1&amp;quot; RecipeTreeNode : recipes&lt;br /&gt;
RecipeTreeNode *-- Recipe&lt;br /&gt;
RecipeManager &amp;quot;1&amp;quot; *-- &amp;quot;N..1&amp;quot; Recipe : all recipes&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Members &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Tribe members (both dead &amp;amp; alive) are kept in an array in the Tribe Class. They are all represented by the NPC class. The tribal class only has methods to attach a tribe member. For spawning new members the server (gemSupervisor &amp;amp; entityManager classes) and the npcclient class are responsable.&lt;br /&gt;
&lt;br /&gt;
Tribe members can have different types. (Discussion needed about tribe types)&lt;br /&gt;
&lt;br /&gt;
Tribe members are being kept in the &#039;tribe_members&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Resources &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A resource is kept in a data structure (&#039;&#039;Tribe::Resource&#039;&#039;) containing it&#039;s name, nick and quantity. The tribe class has methods for adding, modifying, storing and completely deleting resources.&lt;br /&gt;
&lt;br /&gt;
Resources are being kept in the &#039;sc_tribe_resources&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Memories &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A memory is a location of some importance to the tribe. (E.g. a mine, a field, an enemy, etc)&lt;br /&gt;
&lt;br /&gt;
A memory is kept in a data structure (&#039;&#039;Tribe::Memory&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name and a link to an NPC (which is NULL if the memory is public to all tribe members, or != NULL if it&#039;s private to a tribe member). The tribe object has methods to add, store, modify and search memories.&lt;br /&gt;
&lt;br /&gt;
Tribe members also have a memory slot for keeping it&#039;s current task location. (see bufferMemory attribute of NPC class).&lt;br /&gt;
&lt;br /&gt;
Tribe memories are being kept in the &#039;sc_tribe_memories&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Assets &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Assets are belongings of the tribe. They can represent buildings, items or spots to be built in the future.&lt;br /&gt;
&lt;br /&gt;
An asset is represented by a data structure (&#039;&#039;Tribe::Asset&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name, it&#039;s quantity (relevant just for items) and it&#039;s type (Building Spot, Building or Item). The tribe class has methods for adding, editing and deleting assets. It also has methods for managing buildings. (e.g. Replace a building spot with the actual building after the workers built it)&lt;br /&gt;
&lt;br /&gt;
Tribe assets are being kept in the &#039;sc_tribe_assets&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Knowledge &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Knowledge represents the information the tribe has gathered and the technologies they can use. (E.g. Ironworks, pottery, horseback riding, alphabet, math, etc)&lt;br /&gt;
&lt;br /&gt;
Technically, they are just strings used as tokens to prove the tribe has acquired knowledge or not.&lt;br /&gt;
&lt;br /&gt;
Knowledge is kept in an array of strings.&lt;br /&gt;
&lt;br /&gt;
Tribe knowledge is being kept in the &#039;sc_tribe_knowledge&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe Tree Node &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This class represents a node of the recipe tree describing the tribe current tasks. Each recipe tree node contains a link to it&#039;s recipe, waiting times, current requirement, current algorithm step and relationship information regarding other recipes. (just as a standard Tree, it may have parents and descendants).&lt;br /&gt;
&lt;br /&gt;
RecipeTreeNodes are not being stored in any database. They are just used during runtime as an AI for tribes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A recipe is a set of requirements and algorithm steps regarding a task that needs to be done. Recipes can vary from simple (Gather a resource) to very complex (Build an entire civilization).&lt;br /&gt;
&lt;br /&gt;
Recipes are being stored in the &#039;tribe_recipes&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
=== Advance Sequence ===&lt;br /&gt;
&lt;br /&gt;
Advance sequence is the heart of the Tribe system. The NPCClient will advance the brain 4 times a second. On each loop, this sequence takes care of special cases (e.g.: 0 npcs alive in tribe) and assigns tasks to idle members.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
-&amp;gt; NPCClient : Advance&lt;br /&gt;
activate NPCClient&lt;br /&gt;
loop For each tribe&lt;br /&gt;
  NPCClient -&amp;gt; Tribe : Advance&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AdvanceResources&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AddCyclicRecipes&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  loop For each member&lt;br /&gt;
     alt For NPC&#039;s that have the tribe&#039;s idle behavior&lt;br /&gt;
        activate Tribe&lt;br /&gt;
        Tribe -&amp;gt; Tribe : Get highest priority recipe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
        &lt;br /&gt;
        Tribe -&amp;gt; RecipeManager : Apply Recipe&lt;br /&gt;
        activate RecipeManager&lt;br /&gt;
        Tribe &amp;lt;- RecipeManager&lt;br /&gt;
        deactivate RecipeManager&lt;br /&gt;
        &lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
  NPCClient &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;-- NPCClient&lt;br /&gt;
deactivate NPCClient&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up tribes ==&lt;br /&gt;
There are 3 main database tables that need to be populated.&lt;br /&gt;
&lt;br /&gt;
* [[TribesTable|tribes]]&lt;br /&gt;
** Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.&lt;br /&gt;
** max_size sets the maximum number of members.&lt;br /&gt;
** wealth_resource sets the different types of resource that a tribe can mine in order to grow and/or sustain itself. This needs more work however the most important one is wealth_resource_growth which is the default rate at which a resource will grow without any work per second.&lt;br /&gt;
** reproduction_cost is the amount of resources required to reproduce.&lt;br /&gt;
** tribal_recipe loads the initial recipe that sets tribe traits and loads tribe goals (recipes)&lt;br /&gt;
&lt;br /&gt;
* tribe_members&lt;br /&gt;
** Each row is an association between a PID (on the server side) and a tribe.&lt;br /&gt;
&lt;br /&gt;
* tribe_recipes&lt;br /&gt;
** Each row represents a recipe (name,requirements,algorithm). This table needs to be loaded in order to order tribe members what to do. Not having recipes, or requesting a recipe that does not exist will result in a termination of the npcclient.&lt;br /&gt;
&lt;br /&gt;
Additionally, tables for extra tribe info need to be created:&lt;br /&gt;
*sc_tribe_assets&lt;br /&gt;
*sc_tribe_knowledge&lt;br /&gt;
*sc_tribe_memories&lt;br /&gt;
*sc_tribe_resources&lt;br /&gt;
&lt;br /&gt;
== Tribe day-to-day life ==&lt;br /&gt;
&lt;br /&gt;
Tribe members are normal NPCs. They all expand a base NPCType called &#039;AbstractTribesman&#039;, on which each tribe adds it&#039;s own particularities (e.g. when to go to sleep, what to do when they meet a stranger, etc). [[NPC_Behavior_scripting|Read more on NPCTypes]]. The &#039;AbstractTribesman&#039; contains behaviors that describe generic actions: breeding, gathering, mining, fighting, exploring and working. (trading to be added soon). These generic behaviors use some data buffers to read data from during runtime in order to execute the same behavior on different data. (different mines, different fields, different building places, etc)&lt;br /&gt;
&lt;br /&gt;
Upon parsing recipes, different perceptions are fired on the tribesmen. This process simulates a working society on which a superior entity assigns tasks to the population.&lt;br /&gt;
&lt;br /&gt;
== Tribe death ==&lt;br /&gt;
When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.&lt;br /&gt;
&lt;br /&gt;
= Runtime =&lt;br /&gt;
&lt;br /&gt;
==Step #1 (Loading)==&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*assets from mysql:&#039;sc_tribe_assets&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
==Step #2 (RunTime)==&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top-priority recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
It checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes which achieves the requirement on top of the tribe&#039;s recipe list.&lt;br /&gt;
Requirement parsing can be done two ways:&lt;br /&gt;
* Distributed Parsing : The parser takes the first requirement and checks it + tries to achieve it. When the same recipe gets parsed again, the parser takes the second requirement (even if the first is still not met) and tries to achieve it. This way, the parser loops through requirements and tries to achieve all in parallel.&lt;br /&gt;
* Concentrated Parsing : The parser tries to achieve the first requirement on each recipe parse until it is met. After that it picks the second requirement and applies the same principle.&lt;br /&gt;
&lt;br /&gt;
E.G.: We want our tribe to gain 150 of Coal, Silver, Gold and Platinum.&lt;br /&gt;
&lt;br /&gt;
Using Distributed Parsing:&lt;br /&gt;
*Step 1: Assign miner to Coal.&lt;br /&gt;
*Step 2: Assign miner to Silver.&lt;br /&gt;
*Step 3: Assign miner to Gold.&lt;br /&gt;
*Step 4: Assign miner to Platinum.&lt;br /&gt;
*Step 5: Assign miner to Coal.&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
Using Concentrated Parsing: (in this example we consider each step gets the tribe 1 quantity of resource)&lt;br /&gt;
*Step 1: Assign miner to Coal.&lt;br /&gt;
...&lt;br /&gt;
*Step 150: Assign miner to Coal.&lt;br /&gt;
*Step 151: Assign miner to Silver.&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Step #3 (Recipe&#039;s Algorithm)==&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs. A complete set of algorithm and requirements functions can be found [[Tribe_Scripting|here]].&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]] [[Category:NPCClient Design]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9139</id>
		<title>Tribe Design</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9139"/>
		<updated>2011-09-18T21:46:35Z</updated>

		<summary type="html">&lt;p&gt;Zee: Added runtime description.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Design =&lt;br /&gt;
&lt;br /&gt;
The tribe design is done using NPC Behaviors and Recipes. Tribe members are assigned tasks based on what the recipes dictates the tribe to achieve. This system uses a Recipe Manager which takes care of parsing recipes, breaking the initial recipe into subtasks and telling the npcs which action to take.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : members&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : deadMembers&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Resource : resources&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Memory : memories&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Asset : assets&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Knowledge : knowledge&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;1..1&amp;quot; RecipeTreeNode : recipes&lt;br /&gt;
RecipeTreeNode *-- Recipe&lt;br /&gt;
RecipeManager &amp;quot;1&amp;quot; *-- &amp;quot;N..1&amp;quot; Recipe : all recipes&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Members &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Tribe members (both dead &amp;amp; alive) are kept in an array in the Tribe Class. They are all represented by the NPC class. The tribal class only has methods to attach a tribe member. For spawning new members the server (gemSupervisor &amp;amp; entityManager classes) and the npcclient class are responsable.&lt;br /&gt;
&lt;br /&gt;
Tribe members can have different types. (Discussion needed about tribe types)&lt;br /&gt;
&lt;br /&gt;
Tribe members are being kept in the &#039;tribe_members&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Resources &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A resource is kept in a data structure (&#039;&#039;Tribe::Resource&#039;&#039;) containing it&#039;s name, nick and quantity. The tribe class has methods for adding, modifying, storing and completely deleting resources.&lt;br /&gt;
&lt;br /&gt;
Resources are being kept in the &#039;sc_tribe_resources&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Memories &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A memory is a location of some importance to the tribe. (E.g. a mine, a field, an enemy, etc)&lt;br /&gt;
&lt;br /&gt;
A memory is kept in a data structure (&#039;&#039;Tribe::Memory&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name and a link to an NPC (which is NULL if the memory is public to all tribe members, or != NULL if it&#039;s private to a tribe member). The tribe object has methods to add, store, modify and search memories.&lt;br /&gt;
&lt;br /&gt;
Tribe members also have a memory slot for keeping it&#039;s current task location. (see bufferMemory attribute of NPC class).&lt;br /&gt;
&lt;br /&gt;
Tribe memories are being kept in the &#039;sc_tribe_memories&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Assets &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Assets are belongings of the tribe. They can represent buildings, items or spots to be built in the future.&lt;br /&gt;
&lt;br /&gt;
An asset is represented by a data structure (&#039;&#039;Tribe::Asset&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name, it&#039;s quantity (relevant just for items) and it&#039;s type (Building Spot, Building or Item). The tribe class has methods for adding, editing and deleting assets. It also has methods for managing buildings. (e.g. Replace a building spot with the actual building after the workers built it)&lt;br /&gt;
&lt;br /&gt;
Tribe assets are being kept in the &#039;sc_tribe_assets&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Knowledge &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Knowledge represents the information the tribe has gathered and the technologies they can use. (E.g. Ironworks, pottery, horseback riding, alphabet, math, etc)&lt;br /&gt;
&lt;br /&gt;
Technically, they are just strings used as tokens to prove the tribe has acquired knowledge or not.&lt;br /&gt;
&lt;br /&gt;
Knowledge is kept in an array of strings.&lt;br /&gt;
&lt;br /&gt;
Tribe knowledge is being kept in the &#039;sc_tribe_knowledge&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe Tree Node &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This class represents a node of the recipe tree describing the tribe current tasks. Each recipe tree node contains a link to it&#039;s recipe, waiting times, current requirement, current algorithm step and relationship information regarding other recipes. (just as a standard Tree, it may have parents and descendants).&lt;br /&gt;
&lt;br /&gt;
RecipeTreeNodes are not being stored in any database. They are just used during runtime as an AI for tribes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A recipe is a set of requirements and algorithm steps regarding a task that needs to be done. Recipes can vary from simple (Gather a resource) to very complex (Build an entire civilization).&lt;br /&gt;
&lt;br /&gt;
Recipes are being stored in the &#039;tribe_recipes&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
=== Advance Sequence ===&lt;br /&gt;
&lt;br /&gt;
Advance sequence is the heart of the Tribe system. The NPCClient will advance the brain 4 times a second. On each loop, this sequence takes care of special cases (e.g.: 0 npcs alive in tribe) and assigns tasks to idle members.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
-&amp;gt; NPCClient : Advance&lt;br /&gt;
activate NPCClient&lt;br /&gt;
loop For each tribe&lt;br /&gt;
  NPCClient -&amp;gt; Tribe : Advance&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AdvanceResources&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AddCyclicRecipes&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  loop For each member&lt;br /&gt;
     alt For NPC&#039;s that have the tribe&#039;s idle behavior&lt;br /&gt;
        activate Tribe&lt;br /&gt;
        Tribe -&amp;gt; Tribe : Get highest priority recipe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
        &lt;br /&gt;
        Tribe -&amp;gt; RecipeManager : Apply Recipe&lt;br /&gt;
        activate RecipeManager&lt;br /&gt;
        Tribe &amp;lt;- RecipeManager&lt;br /&gt;
        deactivate RecipeManager&lt;br /&gt;
        &lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
  NPCClient &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;-- NPCClient&lt;br /&gt;
deactivate NPCClient&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up tribes ==&lt;br /&gt;
There are 3 main database tables that need to be populated.&lt;br /&gt;
&lt;br /&gt;
* [[TribesTable|tribes]]&lt;br /&gt;
** Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.&lt;br /&gt;
** max_size sets the maximum number of members.&lt;br /&gt;
** wealth_resource sets the different types of resource that a tribe can mine in order to grow and/or sustain itself. This needs more work however the most important one is wealth_resource_growth which is the default rate at which a resource will grow without any work per second.&lt;br /&gt;
** reproduction_cost is the amount of resources required to reproduce.&lt;br /&gt;
** tribal_recipe loads the initial recipe that sets tribe traits and loads tribe goals (recipes)&lt;br /&gt;
&lt;br /&gt;
* tribe_members&lt;br /&gt;
** Each row is an association between a PID (on the server side) and a tribe.&lt;br /&gt;
&lt;br /&gt;
* tribe_recipes&lt;br /&gt;
** Each row represents a recipe (name,requirements,algorithm). This table needs to be loaded in order to order tribe members what to do. Not having recipes, or requesting a recipe that does not exist will result in a termination of the npcclient.&lt;br /&gt;
&lt;br /&gt;
Additionally, tables for extra tribe info need to be created:&lt;br /&gt;
*sc_tribe_assets&lt;br /&gt;
*sc_tribe_knowledge&lt;br /&gt;
*sc_tribe_memories&lt;br /&gt;
*sc_tribe_resources&lt;br /&gt;
&lt;br /&gt;
== Tribe day-to-day life ==&lt;br /&gt;
&lt;br /&gt;
Tribe members are normal NPCs. They all expand a base NPCType called &#039;AbstractTribesman&#039;, on which each tribe adds it&#039;s own particularities (e.g. when to go to sleep, what to do when they meet a stranger, etc). [[NPC_Behavior_scripting|Read more on NPCTypes]]. The &#039;AbstractTribesman&#039; contains behaviors that describe generic actions: breeding, gathering, mining, fighting, exploring and working. (trading to be added soon). These generic behaviors use some data buffers to read data from during runtime in order to execute the same behavior on different data. (different mines, different fields, different building places, etc)&lt;br /&gt;
&lt;br /&gt;
Upon parsing recipes, different perceptions are fired on the tribesmen. This process simulates a working society on which a superior entity assigns tasks to the population.&lt;br /&gt;
&lt;br /&gt;
== Tribe death ==&lt;br /&gt;
When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.&lt;br /&gt;
&lt;br /&gt;
= Runtime =&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*assets from mysql:&#039;sc_tribe_assets&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top-priority recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
It checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes which achieves the requirement on top of the tribe&#039;s recipe list.&lt;br /&gt;
Requirement parsing can be done two ways:&lt;br /&gt;
* Distributed Parsing : The parser takes the first requirement and checks it + tries to achieve it. When the same recipe gets parsed again, the parser takes the second requirement (even if the first is still not met) and tries to achieve it. This way, the parser loops through requirements and tries to achieve all in parallel.&lt;br /&gt;
* Concentrated Parsing : The parser tries to achieve the first requirement on each recipe parse until it is met. After that it picks the second requirement and applies the same principle.&lt;br /&gt;
&lt;br /&gt;
E.G.: We want our tribe to gain 150 of Coal, Silver, Gold and Platinum.&lt;br /&gt;
&lt;br /&gt;
Using Distributed Parsing:&lt;br /&gt;
*Step 1: Assign miner to Coal.&lt;br /&gt;
*Step 2: Assign miner to Silver.&lt;br /&gt;
*Step 3: Assign miner to Gold.&lt;br /&gt;
*Step 4: Assign miner to Platinum.&lt;br /&gt;
*Step 5: Assign miner to Coal.&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
Using Concentrated Parsing: (in this example we consider each step gets the tribe 1 quantity of resource)&lt;br /&gt;
*Step 1: Assign miner to Coal.&lt;br /&gt;
...&lt;br /&gt;
*Step 150: Assign miner to Coal.&lt;br /&gt;
*Step 151: Assign miner to Silver.&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs. A complete set of algorithm and requirements functions can be found [[Tribe_Scripting||here]].&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]] [[Category:NPCClient Design]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9138</id>
		<title>Tribe Design</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9138"/>
		<updated>2011-09-18T21:20:20Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Tribe day-to-day life */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Design =&lt;br /&gt;
&lt;br /&gt;
The tribe design is done using NPC Behaviors and Recipes. Tribe members are assigned tasks based on what the recipes dictates the tribe to achieve. This system uses a Recipe Manager which takes care of parsing recipes, breaking the initial recipe into subtasks and telling the npcs which action to take.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : members&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : deadMembers&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Resource : resources&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Memory : memories&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Asset : assets&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Knowledge : knowledge&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;1..1&amp;quot; RecipeTreeNode : recipes&lt;br /&gt;
RecipeTreeNode *-- Recipe&lt;br /&gt;
RecipeManager &amp;quot;1&amp;quot; *-- &amp;quot;N..1&amp;quot; Recipe : all recipes&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Members &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Tribe members (both dead &amp;amp; alive) are kept in an array in the Tribe Class. They are all represented by the NPC class. The tribal class only has methods to attach a tribe member. For spawning new members the server (gemSupervisor &amp;amp; entityManager classes) and the npcclient class are responsable.&lt;br /&gt;
&lt;br /&gt;
Tribe members can have different types. (Discussion needed about tribe types)&lt;br /&gt;
&lt;br /&gt;
Tribe members are being kept in the &#039;tribe_members&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Resources &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A resource is kept in a data structure (&#039;&#039;Tribe::Resource&#039;&#039;) containing it&#039;s name, nick and quantity. The tribe class has methods for adding, modifying, storing and completely deleting resources.&lt;br /&gt;
&lt;br /&gt;
Resources are being kept in the &#039;sc_tribe_resources&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Memories &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A memory is a location of some importance to the tribe. (E.g. a mine, a field, an enemy, etc)&lt;br /&gt;
&lt;br /&gt;
A memory is kept in a data structure (&#039;&#039;Tribe::Memory&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name and a link to an NPC (which is NULL if the memory is public to all tribe members, or != NULL if it&#039;s private to a tribe member). The tribe object has methods to add, store, modify and search memories.&lt;br /&gt;
&lt;br /&gt;
Tribe members also have a memory slot for keeping it&#039;s current task location. (see bufferMemory attribute of NPC class).&lt;br /&gt;
&lt;br /&gt;
Tribe memories are being kept in the &#039;sc_tribe_memories&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Assets &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Assets are belongings of the tribe. They can represent buildings, items or spots to be built in the future.&lt;br /&gt;
&lt;br /&gt;
An asset is represented by a data structure (&#039;&#039;Tribe::Asset&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name, it&#039;s quantity (relevant just for items) and it&#039;s type (Building Spot, Building or Item). The tribe class has methods for adding, editing and deleting assets. It also has methods for managing buildings. (e.g. Replace a building spot with the actual building after the workers built it)&lt;br /&gt;
&lt;br /&gt;
Tribe assets are being kept in the &#039;sc_tribe_assets&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Knowledge &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Knowledge represents the information the tribe has gathered and the technologies they can use. (E.g. Ironworks, pottery, horseback riding, alphabet, math, etc)&lt;br /&gt;
&lt;br /&gt;
Technically, they are just strings used as tokens to prove the tribe has acquired knowledge or not.&lt;br /&gt;
&lt;br /&gt;
Knowledge is kept in an array of strings.&lt;br /&gt;
&lt;br /&gt;
Tribe knowledge is being kept in the &#039;sc_tribe_knowledge&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe Tree Node &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This class represents a node of the recipe tree describing the tribe current tasks. Each recipe tree node contains a link to it&#039;s recipe, waiting times, current requirement, current algorithm step and relationship information regarding other recipes. (just as a standard Tree, it may have parents and descendants).&lt;br /&gt;
&lt;br /&gt;
RecipeTreeNodes are not being stored in any database. They are just used during runtime as an AI for tribes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A recipe is a set of requirements and algorithm steps regarding a task that needs to be done. Recipes can vary from simple (Gather a resource) to very complex (Build an entire civilization).&lt;br /&gt;
&lt;br /&gt;
Recipes are being stored in the &#039;tribe_recipes&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
=== Advance Sequence ===&lt;br /&gt;
&lt;br /&gt;
Advance sequence is the heart of the Tribe system. The NPCClient will advance the brain 4 times a second. On each loop, this sequence takes care of special cases (e.g.: 0 npcs alive in tribe) and assigns tasks to idle members.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
-&amp;gt; NPCClient : Advance&lt;br /&gt;
activate NPCClient&lt;br /&gt;
loop For each tribe&lt;br /&gt;
  NPCClient -&amp;gt; Tribe : Advance&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AdvanceResources&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AddCyclicRecipes&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  loop For each member&lt;br /&gt;
     alt For NPC&#039;s that have the tribe&#039;s idle behavior&lt;br /&gt;
        activate Tribe&lt;br /&gt;
        Tribe -&amp;gt; Tribe : Get highest priority recipe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
        &lt;br /&gt;
        Tribe -&amp;gt; RecipeManager : Apply Recipe&lt;br /&gt;
        activate RecipeManager&lt;br /&gt;
        Tribe &amp;lt;- RecipeManager&lt;br /&gt;
        deactivate RecipeManager&lt;br /&gt;
        &lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
  NPCClient &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;-- NPCClient&lt;br /&gt;
deactivate NPCClient&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up tribes ==&lt;br /&gt;
There are 3 main database tables that need to be populated.&lt;br /&gt;
&lt;br /&gt;
* [[TribesTable|tribes]]&lt;br /&gt;
** Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.&lt;br /&gt;
** max_size sets the maximum number of members.&lt;br /&gt;
** wealth_resource sets the different types of resource that a tribe can mine in order to grow and/or sustain itself. This needs more work however the most important one is wealth_resource_growth which is the default rate at which a resource will grow without any work per second.&lt;br /&gt;
** reproduction_cost is the amount of resources required to reproduce.&lt;br /&gt;
** tribal_recipe loads the initial recipe that sets tribe traits and loads tribe goals (recipes)&lt;br /&gt;
&lt;br /&gt;
* tribe_members&lt;br /&gt;
** Each row is an association between a PID (on the server side) and a tribe.&lt;br /&gt;
&lt;br /&gt;
* tribe_recipes&lt;br /&gt;
** Each row represents a recipe (name,requirements,algorithm). This table needs to be loaded in order to order tribe members what to do. Not having recipes, or requesting a recipe that does not exist will result in a termination of the npcclient.&lt;br /&gt;
&lt;br /&gt;
Additionally, tables for extra tribe info need to be created:&lt;br /&gt;
*sc_tribe_assets&lt;br /&gt;
*sc_tribe_knowledge&lt;br /&gt;
*sc_tribe_memories&lt;br /&gt;
*sc_tribe_resources&lt;br /&gt;
&lt;br /&gt;
== Tribe day-to-day life ==&lt;br /&gt;
&lt;br /&gt;
Tribe members are normal NPCs. They all expand a base NPCType called &#039;AbstractTribesman&#039;, on which each tribe adds it&#039;s own particularities (e.g. when to go to sleep, what to do when they meet a stranger, etc). [[NPC_Behavior_scripting|Read more on NPCTypes]]. The &#039;AbstractTribesman&#039; contains behaviors that describe generic actions: breeding, gathering, mining, fighting, exploring and working. (trading to be added soon). These generic behaviors use some data buffers to read data from during runtime in order to execute the same behavior on different data. (different mines, different fields, different building places, etc)&lt;br /&gt;
&lt;br /&gt;
Upon parsing recipes, different perceptions are fired on the tribesmen. This process simulates a working society on which a superior entity assigns tasks to the population.&lt;br /&gt;
&lt;br /&gt;
== Tribe death ==&lt;br /&gt;
When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]] [[Category:NPCClient Design]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9135</id>
		<title>Tribe Design</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9135"/>
		<updated>2011-09-18T12:45:58Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Setting up tribes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Design =&lt;br /&gt;
&lt;br /&gt;
The tribe design is done using NPC Behaviors and Recipes. Tribe members are assigned tasks based on what the recipes dictates the tribe to achieve. This system uses a Recipe Manager which takes care of parsing recipes, breaking the initial recipe into subtasks and telling the npcs which action to take.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : members&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : deadMembers&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Resource : resources&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Memory : memories&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Asset : assets&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Knowledge : knowledge&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;1..1&amp;quot; RecipeTreeNode : recipes&lt;br /&gt;
RecipeTreeNode *-- Recipe&lt;br /&gt;
RecipeManager &amp;quot;1&amp;quot; *-- &amp;quot;N..1&amp;quot; Recipe : all recipes&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Members &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Tribe members (both dead &amp;amp; alive) are kept in an array in the Tribe Class. They are all represented by the NPC class. The tribal class only has methods to attach a tribe member. For spawning new members the server (gemSupervisor &amp;amp; entityManager classes) and the npcclient class are responsable.&lt;br /&gt;
&lt;br /&gt;
Tribe members can have different types. (Discussion needed about tribe types)&lt;br /&gt;
&lt;br /&gt;
Tribe members are being kept in the &#039;tribe_members&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Resources &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A resource is kept in a data structure (&#039;&#039;Tribe::Resource&#039;&#039;) containing it&#039;s name, nick and quantity. The tribe class has methods for adding, modifying, storing and completely deleting resources.&lt;br /&gt;
&lt;br /&gt;
Resources are being kept in the &#039;sc_tribe_resources&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Memories &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A memory is a location of some importance to the tribe. (E.g. a mine, a field, an enemy, etc)&lt;br /&gt;
&lt;br /&gt;
A memory is kept in a data structure (&#039;&#039;Tribe::Memory&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name and a link to an NPC (which is NULL if the memory is public to all tribe members, or != NULL if it&#039;s private to a tribe member). The tribe object has methods to add, store, modify and search memories.&lt;br /&gt;
&lt;br /&gt;
Tribe members also have a memory slot for keeping it&#039;s current task location. (see bufferMemory attribute of NPC class).&lt;br /&gt;
&lt;br /&gt;
Tribe memories are being kept in the &#039;sc_tribe_memories&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Assets &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Assets are belongings of the tribe. They can represent buildings, items or spots to be built in the future.&lt;br /&gt;
&lt;br /&gt;
An asset is represented by a data structure (&#039;&#039;Tribe::Asset&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name, it&#039;s quantity (relevant just for items) and it&#039;s type (Building Spot, Building or Item). The tribe class has methods for adding, editing and deleting assets. It also has methods for managing buildings. (e.g. Replace a building spot with the actual building after the workers built it)&lt;br /&gt;
&lt;br /&gt;
Tribe assets are being kept in the &#039;sc_tribe_assets&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Knowledge &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Knowledge represents the information the tribe has gathered and the technologies they can use. (E.g. Ironworks, pottery, horseback riding, alphabet, math, etc)&lt;br /&gt;
&lt;br /&gt;
Technically, they are just strings used as tokens to prove the tribe has acquired knowledge or not.&lt;br /&gt;
&lt;br /&gt;
Knowledge is kept in an array of strings.&lt;br /&gt;
&lt;br /&gt;
Tribe knowledge is being kept in the &#039;sc_tribe_knowledge&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe Tree Node &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This class represents a node of the recipe tree describing the tribe current tasks. Each recipe tree node contains a link to it&#039;s recipe, waiting times, current requirement, current algorithm step and relationship information regarding other recipes. (just as a standard Tree, it may have parents and descendants).&lt;br /&gt;
&lt;br /&gt;
RecipeTreeNodes are not being stored in any database. They are just used during runtime as an AI for tribes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A recipe is a set of requirements and algorithm steps regarding a task that needs to be done. Recipes can vary from simple (Gather a resource) to very complex (Build an entire civilization).&lt;br /&gt;
&lt;br /&gt;
Recipes are being stored in the &#039;tribe_recipes&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
=== Advance Sequence ===&lt;br /&gt;
&lt;br /&gt;
Advance sequence is the heart of the Tribe system. The NPCClient will advance the brain 4 times a second. On each loop, this sequence takes care of special cases (e.g.: 0 npcs alive in tribe) and assigns tasks to idle members.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
-&amp;gt; NPCClient : Advance&lt;br /&gt;
activate NPCClient&lt;br /&gt;
loop For each tribe&lt;br /&gt;
  NPCClient -&amp;gt; Tribe : Advance&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AdvanceResources&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AddCyclicRecipes&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  loop For each member&lt;br /&gt;
     alt For NPC&#039;s that have the tribe&#039;s idle behavior&lt;br /&gt;
        activate Tribe&lt;br /&gt;
        Tribe -&amp;gt; Tribe : Get highest priority recipe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
        &lt;br /&gt;
        Tribe -&amp;gt; RecipeManager : Apply Recipe&lt;br /&gt;
        activate RecipeManager&lt;br /&gt;
        Tribe &amp;lt;- RecipeManager&lt;br /&gt;
        deactivate RecipeManager&lt;br /&gt;
        &lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
  NPCClient &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;-- NPCClient&lt;br /&gt;
deactivate NPCClient&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up tribes ==&lt;br /&gt;
There are 3 main database tables that need to be populated.&lt;br /&gt;
&lt;br /&gt;
* [[TribesTable|tribes]]&lt;br /&gt;
** Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.&lt;br /&gt;
** max_size sets the maximum number of members.&lt;br /&gt;
** wealth_resource sets the different types of resource that a tribe can mine in order to grow and/or sustain itself. This needs more work however the most important one is wealth_resource_growth which is the default rate at which a resource will grow without any work per second.&lt;br /&gt;
** reproduction_cost is the amount of resources required to reproduce.&lt;br /&gt;
** tribal_recipe loads the initial recipe that sets tribe traits and loads tribe goals (recipes)&lt;br /&gt;
&lt;br /&gt;
* tribe_members&lt;br /&gt;
** Each row is an association between a PID (on the server side) and a tribe.&lt;br /&gt;
&lt;br /&gt;
* tribe_recipes&lt;br /&gt;
** Each row represents a recipe (name,requirements,algorithm). This table needs to be loaded in order to order tribe members what to do. Not having recipes, or requesting a recipe that does not exist will result in a termination of the npcclient.&lt;br /&gt;
&lt;br /&gt;
Additionally, tables for extra tribe info need to be created:&lt;br /&gt;
*sc_tribe_assets&lt;br /&gt;
*sc_tribe_knowledge&lt;br /&gt;
*sc_tribe_memories&lt;br /&gt;
*sc_tribe_resources&lt;br /&gt;
&lt;br /&gt;
== Tribe day-to-day life ==&lt;br /&gt;
&lt;br /&gt;
=== Behaviour ===&lt;br /&gt;
A tribe has a set of needs, which are nothing, explore, dig, reproduce and walk. These needs are increased by a rate set in the code for now. When a need is activated, it may also trigger a perception for the next npc.&lt;br /&gt;
&lt;br /&gt;
Tribe members are ordinary [[NPC Types|NPCs]], with an additional set of [[Behavior Operations]] and perceptions to be used in [[Behaviors_and_Reactions|Reactions]]. These perceptions are defined by the needs defined in the tribe_needs table and might be:&lt;br /&gt;
&lt;br /&gt;
* tribe:explore&lt;br /&gt;
* tribe:dig&lt;br /&gt;
* tribe:reproduce (should result in a reproduce op).&lt;br /&gt;
* tribe:resurrect&lt;br /&gt;
* tribe:guard&lt;br /&gt;
* Or anything else&lt;br /&gt;
&lt;br /&gt;
=== Reproduction ===&lt;br /&gt;
The reproduction need will only increase if the number of tribe members is below the maximum. When reproduction is triggered, the tribe resources are decreased by reproduction_cost and the next NPC receives the tribe:reproduce perception. If the NPC then performs the reproduce op, it causes a server-side clone. Everything is cloned and the new cloned NPC will be a member of the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Resurrection ===&lt;br /&gt;
When a member dies, it will be resurrected according to the tribe need and will also take a reproduction_cost. However, no cloning will take place.&lt;br /&gt;
&lt;br /&gt;
=== Resources ===&lt;br /&gt;
A tribe member can be set to use the [[Behavior_Operations#Locate_Operation|Transfere Operation]] to locate the memory of a tribe resource and use the [[Behavior_Operations#Locate_Operation|Dig Operation]] or [[Behavior_Operations#Locate_Operation|Harvest Operation]] to get resources when for example a &#039;&#039;tribe:harvest&#039;&#039; perception is triggered. The [[Behavior_Operations#Locate_Operation|Transfere Operation]] needs to be used when the npc is back home to transfer it to the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Locations ===&lt;br /&gt;
The tribe:resource and tribe:home locations can be used with tribe members. For example in the [[Behavior_Operations#Locate_Operation|Locate Operation]].&lt;br /&gt;
&lt;br /&gt;
== Tribe death ==&lt;br /&gt;
When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]] [[Category:NPCClient Design]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=TribesTable&amp;diff=9134</id>
		<title>TribesTable</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=TribesTable&amp;diff=9134"/>
		<updated>2011-09-18T12:15:17Z</updated>

		<summary type="html">&lt;p&gt;Zee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! field&lt;br /&gt;
! type&lt;br /&gt;
! foreign key&lt;br /&gt;
! description&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| integer&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| name&lt;br /&gt;
| varchar&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| home_sector_id&lt;br /&gt;
| integer&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| home_x&lt;br /&gt;
| real&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| home_y&lt;br /&gt;
| real&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| home_z&lt;br /&gt;
| real&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| home_radius&lt;br /&gt;
| real&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| max_size&lt;br /&gt;
| integer&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| wealth_resource_name&lt;br /&gt;
| varchar&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| wealth_resource_nick&lt;br /&gt;
| varchar&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| wealth_resource_area&lt;br /&gt;
| varchar&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| reproduction_cost&lt;br /&gt;
| integer&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| tribal_recipe&lt;br /&gt;
| integer&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Field&lt;br /&gt;
!type&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|id&lt;br /&gt;
|int&lt;br /&gt;
|The ID of the tribe.&lt;br /&gt;
|-&lt;br /&gt;
|name&lt;br /&gt;
|string&lt;br /&gt;
|The name of the tribe.&lt;br /&gt;
|-&lt;br /&gt;
|home_sector_id&lt;br /&gt;
|int&lt;br /&gt;
|The ID of the sector where the tribe home is located&lt;br /&gt;
|-&lt;br /&gt;
|home_x&lt;br /&gt;
|float&lt;br /&gt;
|X-coordinate of the tribe home location&lt;br /&gt;
|-&lt;br /&gt;
|home_y&lt;br /&gt;
|float&lt;br /&gt;
|Y-coordinate of the tribe home location&lt;br /&gt;
|-&lt;br /&gt;
|home_z&lt;br /&gt;
|float&lt;br /&gt;
|Z-coordinate of the tribe home location&lt;br /&gt;
|-&lt;br /&gt;
|home_radius&lt;br /&gt;
|float&lt;br /&gt;
|The radius of the tribe home&lt;br /&gt;
|-&lt;br /&gt;
|max_size&lt;br /&gt;
|int&lt;br /&gt;
|The maximum number of tribe memers allowed for this tribe.&lt;br /&gt;
|-&lt;br /&gt;
|wealth_resource_name&lt;br /&gt;
|string&lt;br /&gt;
|Name of the resource this tribe treasures most. Collecting this will enable growth capability in the tribe.&lt;br /&gt;
|-&lt;br /&gt;
|wealth_resource_nick&lt;br /&gt;
|string&lt;br /&gt;
|Commands like dig use the nick of the resource instead of the name.&lt;br /&gt;
|-&lt;br /&gt;
|wealth_resource_area&lt;br /&gt;
|string&lt;br /&gt;
|The name of the Location Type that represents location where the wealth resource might be found.&lt;br /&gt;
|-&lt;br /&gt;
|wealth_gather_need&lt;br /&gt;
|string&lt;br /&gt;
|The name of the tribe need that will enable collection of wealth resources. Made the primary need when the tribe has dead members.&lt;br /&gt;
|-&lt;br /&gt;
|wealth_resource_growth&lt;br /&gt;
|float&lt;br /&gt;
|When there are no members of the tribe we need a push of resources at this rate to enable reproduction.&lt;br /&gt;
|-&lt;br /&gt;
|reproduction_cost&lt;br /&gt;
|int&lt;br /&gt;
|The cost to reproduce.&lt;br /&gt;
|-&lt;br /&gt;
|tribal_recipe&lt;br /&gt;
|int&lt;br /&gt;
|the id of the tribal recipe to load on each npcclient startup&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9133</id>
		<title>Tribe Design</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9133"/>
		<updated>2011-09-18T12:13:31Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Setting up tribes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Design =&lt;br /&gt;
&lt;br /&gt;
The tribe design is done using NPC Behaviors and Recipes. Tribe members are assigned tasks based on what the recipes dictates the tribe to achieve. This system uses a Recipe Manager which takes care of parsing recipes, breaking the initial recipe into subtasks and telling the npcs which action to take.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : members&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : deadMembers&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Resource : resources&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Memory : memories&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Asset : assets&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Knowledge : knowledge&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;1..1&amp;quot; RecipeTreeNode : recipes&lt;br /&gt;
RecipeTreeNode *-- Recipe&lt;br /&gt;
RecipeManager &amp;quot;1&amp;quot; *-- &amp;quot;N..1&amp;quot; Recipe : all recipes&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Members &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Tribe members (both dead &amp;amp; alive) are kept in an array in the Tribe Class. They are all represented by the NPC class. The tribal class only has methods to attach a tribe member. For spawning new members the server (gemSupervisor &amp;amp; entityManager classes) and the npcclient class are responsable.&lt;br /&gt;
&lt;br /&gt;
Tribe members can have different types. (Discussion needed about tribe types)&lt;br /&gt;
&lt;br /&gt;
Tribe members are being kept in the &#039;tribe_members&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Resources &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A resource is kept in a data structure (&#039;&#039;Tribe::Resource&#039;&#039;) containing it&#039;s name, nick and quantity. The tribe class has methods for adding, modifying, storing and completely deleting resources.&lt;br /&gt;
&lt;br /&gt;
Resources are being kept in the &#039;sc_tribe_resources&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Memories &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A memory is a location of some importance to the tribe. (E.g. a mine, a field, an enemy, etc)&lt;br /&gt;
&lt;br /&gt;
A memory is kept in a data structure (&#039;&#039;Tribe::Memory&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name and a link to an NPC (which is NULL if the memory is public to all tribe members, or != NULL if it&#039;s private to a tribe member). The tribe object has methods to add, store, modify and search memories.&lt;br /&gt;
&lt;br /&gt;
Tribe members also have a memory slot for keeping it&#039;s current task location. (see bufferMemory attribute of NPC class).&lt;br /&gt;
&lt;br /&gt;
Tribe memories are being kept in the &#039;sc_tribe_memories&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Assets &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Assets are belongings of the tribe. They can represent buildings, items or spots to be built in the future.&lt;br /&gt;
&lt;br /&gt;
An asset is represented by a data structure (&#039;&#039;Tribe::Asset&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name, it&#039;s quantity (relevant just for items) and it&#039;s type (Building Spot, Building or Item). The tribe class has methods for adding, editing and deleting assets. It also has methods for managing buildings. (e.g. Replace a building spot with the actual building after the workers built it)&lt;br /&gt;
&lt;br /&gt;
Tribe assets are being kept in the &#039;sc_tribe_assets&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Knowledge &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Knowledge represents the information the tribe has gathered and the technologies they can use. (E.g. Ironworks, pottery, horseback riding, alphabet, math, etc)&lt;br /&gt;
&lt;br /&gt;
Technically, they are just strings used as tokens to prove the tribe has acquired knowledge or not.&lt;br /&gt;
&lt;br /&gt;
Knowledge is kept in an array of strings.&lt;br /&gt;
&lt;br /&gt;
Tribe knowledge is being kept in the &#039;sc_tribe_knowledge&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe Tree Node &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This class represents a node of the recipe tree describing the tribe current tasks. Each recipe tree node contains a link to it&#039;s recipe, waiting times, current requirement, current algorithm step and relationship information regarding other recipes. (just as a standard Tree, it may have parents and descendants).&lt;br /&gt;
&lt;br /&gt;
RecipeTreeNodes are not being stored in any database. They are just used during runtime as an AI for tribes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A recipe is a set of requirements and algorithm steps regarding a task that needs to be done. Recipes can vary from simple (Gather a resource) to very complex (Build an entire civilization).&lt;br /&gt;
&lt;br /&gt;
Recipes are being stored in the &#039;tribe_recipes&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
=== Advance Sequence ===&lt;br /&gt;
&lt;br /&gt;
Advance sequence is the heart of the Tribe system. The NPCClient will advance the brain 4 times a second. On each loop, this sequence takes care of special cases (e.g.: 0 npcs alive in tribe) and assigns tasks to idle members.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
-&amp;gt; NPCClient : Advance&lt;br /&gt;
activate NPCClient&lt;br /&gt;
loop For each tribe&lt;br /&gt;
  NPCClient -&amp;gt; Tribe : Advance&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AdvanceResources&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AddCyclicRecipes&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  loop For each member&lt;br /&gt;
     alt For NPC&#039;s that have the tribe&#039;s idle behavior&lt;br /&gt;
        activate Tribe&lt;br /&gt;
        Tribe -&amp;gt; Tribe : Get highest priority recipe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
        &lt;br /&gt;
        Tribe -&amp;gt; RecipeManager : Apply Recipe&lt;br /&gt;
        activate RecipeManager&lt;br /&gt;
        Tribe &amp;lt;- RecipeManager&lt;br /&gt;
        deactivate RecipeManager&lt;br /&gt;
        &lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
  NPCClient &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;-- NPCClient&lt;br /&gt;
deactivate NPCClient&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up tribes ==&lt;br /&gt;
There are 3 main database tables that need to be populated.&lt;br /&gt;
&lt;br /&gt;
* [[TribesTable|tribes]]&lt;br /&gt;
** Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.&lt;br /&gt;
** max_size sets the maximum number of members.&lt;br /&gt;
** wealth_resource sets the different types of resource that a tribe can mine in order to grow and/or sustain itself. This needs more work however the most important one is wealth_resource_growth which is the default rate at which a resource will grow without any work per second.&lt;br /&gt;
** reproduction_cost is the amount of resources required to reproduce.&lt;br /&gt;
** tribal_recipe loads the initial recipe that sets tribe traits and loads tribe goals (recipes)&lt;br /&gt;
&lt;br /&gt;
* tribe_members&lt;br /&gt;
** Each row is an association between a PID (on the server side) and a tribe.&lt;br /&gt;
&lt;br /&gt;
* tribe_recipes&lt;br /&gt;
** Each row represents a recipe (name,requirements,algorithm). This table needs to be loaded in order to order tribe members what to do. Not having recipes, or requesting a recipe that does not exist will result in a termination of the npcclient.&lt;br /&gt;
&lt;br /&gt;
== Tribe day-to-day life ==&lt;br /&gt;
&lt;br /&gt;
=== Behaviour ===&lt;br /&gt;
A tribe has a set of needs, which are nothing, explore, dig, reproduce and walk. These needs are increased by a rate set in the code for now. When a need is activated, it may also trigger a perception for the next npc.&lt;br /&gt;
&lt;br /&gt;
Tribe members are ordinary [[NPC Types|NPCs]], with an additional set of [[Behavior Operations]] and perceptions to be used in [[Behaviors_and_Reactions|Reactions]]. These perceptions are defined by the needs defined in the tribe_needs table and might be:&lt;br /&gt;
&lt;br /&gt;
* tribe:explore&lt;br /&gt;
* tribe:dig&lt;br /&gt;
* tribe:reproduce (should result in a reproduce op).&lt;br /&gt;
* tribe:resurrect&lt;br /&gt;
* tribe:guard&lt;br /&gt;
* Or anything else&lt;br /&gt;
&lt;br /&gt;
=== Reproduction ===&lt;br /&gt;
The reproduction need will only increase if the number of tribe members is below the maximum. When reproduction is triggered, the tribe resources are decreased by reproduction_cost and the next NPC receives the tribe:reproduce perception. If the NPC then performs the reproduce op, it causes a server-side clone. Everything is cloned and the new cloned NPC will be a member of the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Resurrection ===&lt;br /&gt;
When a member dies, it will be resurrected according to the tribe need and will also take a reproduction_cost. However, no cloning will take place.&lt;br /&gt;
&lt;br /&gt;
=== Resources ===&lt;br /&gt;
A tribe member can be set to use the [[Behavior_Operations#Locate_Operation|Transfere Operation]] to locate the memory of a tribe resource and use the [[Behavior_Operations#Locate_Operation|Dig Operation]] or [[Behavior_Operations#Locate_Operation|Harvest Operation]] to get resources when for example a &#039;&#039;tribe:harvest&#039;&#039; perception is triggered. The [[Behavior_Operations#Locate_Operation|Transfere Operation]] needs to be used when the npc is back home to transfer it to the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Locations ===&lt;br /&gt;
The tribe:resource and tribe:home locations can be used with tribe members. For example in the [[Behavior_Operations#Locate_Operation|Locate Operation]].&lt;br /&gt;
&lt;br /&gt;
== Tribe death ==&lt;br /&gt;
When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]] [[Category:NPCClient Design]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9132</id>
		<title>Tribe Design</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9132"/>
		<updated>2011-09-18T12:02:32Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Advance Sequence */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Design =&lt;br /&gt;
&lt;br /&gt;
The tribe design is done using NPC Behaviors and Recipes. Tribe members are assigned tasks based on what the recipes dictates the tribe to achieve. This system uses a Recipe Manager which takes care of parsing recipes, breaking the initial recipe into subtasks and telling the npcs which action to take.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : members&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : deadMembers&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Resource : resources&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Memory : memories&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Asset : assets&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Knowledge : knowledge&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;1..1&amp;quot; RecipeTreeNode : recipes&lt;br /&gt;
RecipeTreeNode *-- Recipe&lt;br /&gt;
RecipeManager &amp;quot;1&amp;quot; *-- &amp;quot;N..1&amp;quot; Recipe : all recipes&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Members &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Tribe members (both dead &amp;amp; alive) are kept in an array in the Tribe Class. They are all represented by the NPC class. The tribal class only has methods to attach a tribe member. For spawning new members the server (gemSupervisor &amp;amp; entityManager classes) and the npcclient class are responsable.&lt;br /&gt;
&lt;br /&gt;
Tribe members can have different types. (Discussion needed about tribe types)&lt;br /&gt;
&lt;br /&gt;
Tribe members are being kept in the &#039;tribe_members&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Resources &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A resource is kept in a data structure (&#039;&#039;Tribe::Resource&#039;&#039;) containing it&#039;s name, nick and quantity. The tribe class has methods for adding, modifying, storing and completely deleting resources.&lt;br /&gt;
&lt;br /&gt;
Resources are being kept in the &#039;sc_tribe_resources&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Memories &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A memory is a location of some importance to the tribe. (E.g. a mine, a field, an enemy, etc)&lt;br /&gt;
&lt;br /&gt;
A memory is kept in a data structure (&#039;&#039;Tribe::Memory&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name and a link to an NPC (which is NULL if the memory is public to all tribe members, or != NULL if it&#039;s private to a tribe member). The tribe object has methods to add, store, modify and search memories.&lt;br /&gt;
&lt;br /&gt;
Tribe members also have a memory slot for keeping it&#039;s current task location. (see bufferMemory attribute of NPC class).&lt;br /&gt;
&lt;br /&gt;
Tribe memories are being kept in the &#039;sc_tribe_memories&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Assets &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Assets are belongings of the tribe. They can represent buildings, items or spots to be built in the future.&lt;br /&gt;
&lt;br /&gt;
An asset is represented by a data structure (&#039;&#039;Tribe::Asset&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name, it&#039;s quantity (relevant just for items) and it&#039;s type (Building Spot, Building or Item). The tribe class has methods for adding, editing and deleting assets. It also has methods for managing buildings. (e.g. Replace a building spot with the actual building after the workers built it)&lt;br /&gt;
&lt;br /&gt;
Tribe assets are being kept in the &#039;sc_tribe_assets&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Knowledge &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Knowledge represents the information the tribe has gathered and the technologies they can use. (E.g. Ironworks, pottery, horseback riding, alphabet, math, etc)&lt;br /&gt;
&lt;br /&gt;
Technically, they are just strings used as tokens to prove the tribe has acquired knowledge or not.&lt;br /&gt;
&lt;br /&gt;
Knowledge is kept in an array of strings.&lt;br /&gt;
&lt;br /&gt;
Tribe knowledge is being kept in the &#039;sc_tribe_knowledge&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe Tree Node &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This class represents a node of the recipe tree describing the tribe current tasks. Each recipe tree node contains a link to it&#039;s recipe, waiting times, current requirement, current algorithm step and relationship information regarding other recipes. (just as a standard Tree, it may have parents and descendants).&lt;br /&gt;
&lt;br /&gt;
RecipeTreeNodes are not being stored in any database. They are just used during runtime as an AI for tribes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A recipe is a set of requirements and algorithm steps regarding a task that needs to be done. Recipes can vary from simple (Gather a resource) to very complex (Build an entire civilization).&lt;br /&gt;
&lt;br /&gt;
Recipes are being stored in the &#039;tribe_recipes&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
=== Advance Sequence ===&lt;br /&gt;
&lt;br /&gt;
Advance sequence is the heart of the Tribe system. The NPCClient will advance the brain 4 times a second. On each loop, this sequence takes care of special cases (e.g.: 0 npcs alive in tribe) and assigns tasks to idle members.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
-&amp;gt; NPCClient : Advance&lt;br /&gt;
activate NPCClient&lt;br /&gt;
loop For each tribe&lt;br /&gt;
  NPCClient -&amp;gt; Tribe : Advance&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AdvanceResources&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AddCyclicRecipes&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  loop For each member&lt;br /&gt;
     alt For NPC&#039;s that have the tribe&#039;s idle behavior&lt;br /&gt;
        activate Tribe&lt;br /&gt;
        Tribe -&amp;gt; Tribe : Get highest priority recipe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
        &lt;br /&gt;
        Tribe -&amp;gt; RecipeManager : Apply Recipe&lt;br /&gt;
        activate RecipeManager&lt;br /&gt;
        Tribe &amp;lt;- RecipeManager&lt;br /&gt;
        deactivate RecipeManager&lt;br /&gt;
        &lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
  NPCClient &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;-- NPCClient&lt;br /&gt;
deactivate NPCClient&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up tribes ==&lt;br /&gt;
There are 2 main database tables that need to be populated.&lt;br /&gt;
&lt;br /&gt;
* [[TribesTable]]&lt;br /&gt;
** Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.&lt;br /&gt;
** max_size sets the maximum number of members.&lt;br /&gt;
** wealth_resource sets the different types of resource that a tribe can mine in order to grow and/or sustain itself. This needs more work however the most important one is wealth_resource_growth which is the default rate at which a resource will grow without any work per second.&lt;br /&gt;
** reproduction_cost is the amount of resources required to reproduce.&lt;br /&gt;
&lt;br /&gt;
* tribe_members&lt;br /&gt;
** Each row is an association between a PID (on the server side) and a tribe.&lt;br /&gt;
&lt;br /&gt;
* tribe_needs&lt;br /&gt;
** Each row is a need associated with a tribe&lt;br /&gt;
** Consists of: type, name, perception, depend, need_start_value,need_growth_value, arguments&lt;br /&gt;
&lt;br /&gt;
== Tribe day-to-day life ==&lt;br /&gt;
&lt;br /&gt;
=== Behaviour ===&lt;br /&gt;
A tribe has a set of needs, which are nothing, explore, dig, reproduce and walk. These needs are increased by a rate set in the code for now. When a need is activated, it may also trigger a perception for the next npc.&lt;br /&gt;
&lt;br /&gt;
Tribe members are ordinary [[NPC Types|NPCs]], with an additional set of [[Behavior Operations]] and perceptions to be used in [[Behaviors_and_Reactions|Reactions]]. These perceptions are defined by the needs defined in the tribe_needs table and might be:&lt;br /&gt;
&lt;br /&gt;
* tribe:explore&lt;br /&gt;
* tribe:dig&lt;br /&gt;
* tribe:reproduce (should result in a reproduce op).&lt;br /&gt;
* tribe:resurrect&lt;br /&gt;
* tribe:guard&lt;br /&gt;
* Or anything else&lt;br /&gt;
&lt;br /&gt;
=== Reproduction ===&lt;br /&gt;
The reproduction need will only increase if the number of tribe members is below the maximum. When reproduction is triggered, the tribe resources are decreased by reproduction_cost and the next NPC receives the tribe:reproduce perception. If the NPC then performs the reproduce op, it causes a server-side clone. Everything is cloned and the new cloned NPC will be a member of the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Resurrection ===&lt;br /&gt;
When a member dies, it will be resurrected according to the tribe need and will also take a reproduction_cost. However, no cloning will take place.&lt;br /&gt;
&lt;br /&gt;
=== Resources ===&lt;br /&gt;
A tribe member can be set to use the [[Behavior_Operations#Locate_Operation|Transfere Operation]] to locate the memory of a tribe resource and use the [[Behavior_Operations#Locate_Operation|Dig Operation]] or [[Behavior_Operations#Locate_Operation|Harvest Operation]] to get resources when for example a &#039;&#039;tribe:harvest&#039;&#039; perception is triggered. The [[Behavior_Operations#Locate_Operation|Transfere Operation]] needs to be used when the npc is back home to transfer it to the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Locations ===&lt;br /&gt;
The tribe:resource and tribe:home locations can be used with tribe members. For example in the [[Behavior_Operations#Locate_Operation|Locate Operation]].&lt;br /&gt;
&lt;br /&gt;
== Tribe death ==&lt;br /&gt;
When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]] [[Category:NPCClient Design]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9131</id>
		<title>Tribe Design</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9131"/>
		<updated>2011-09-16T14:21:23Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Design =&lt;br /&gt;
&lt;br /&gt;
The tribe design is done using NPC Behaviors and Recipes. Tribe members are assigned tasks based on what the recipes dictates the tribe to achieve. This system uses a Recipe Manager which takes care of parsing recipes, breaking the initial recipe into subtasks and telling the npcs which action to take.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : members&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : deadMembers&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Resource : resources&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Memory : memories&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Asset : assets&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Knowledge : knowledge&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;1..1&amp;quot; RecipeTreeNode : recipes&lt;br /&gt;
RecipeTreeNode *-- Recipe&lt;br /&gt;
RecipeManager &amp;quot;1&amp;quot; *-- &amp;quot;N..1&amp;quot; Recipe : all recipes&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Members &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Tribe members (both dead &amp;amp; alive) are kept in an array in the Tribe Class. They are all represented by the NPC class. The tribal class only has methods to attach a tribe member. For spawning new members the server (gemSupervisor &amp;amp; entityManager classes) and the npcclient class are responsable.&lt;br /&gt;
&lt;br /&gt;
Tribe members can have different types. (Discussion needed about tribe types)&lt;br /&gt;
&lt;br /&gt;
Tribe members are being kept in the &#039;tribe_members&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Resources &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A resource is kept in a data structure (&#039;&#039;Tribe::Resource&#039;&#039;) containing it&#039;s name, nick and quantity. The tribe class has methods for adding, modifying, storing and completely deleting resources.&lt;br /&gt;
&lt;br /&gt;
Resources are being kept in the &#039;sc_tribe_resources&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Memories &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A memory is a location of some importance to the tribe. (E.g. a mine, a field, an enemy, etc)&lt;br /&gt;
&lt;br /&gt;
A memory is kept in a data structure (&#039;&#039;Tribe::Memory&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name and a link to an NPC (which is NULL if the memory is public to all tribe members, or != NULL if it&#039;s private to a tribe member). The tribe object has methods to add, store, modify and search memories.&lt;br /&gt;
&lt;br /&gt;
Tribe members also have a memory slot for keeping it&#039;s current task location. (see bufferMemory attribute of NPC class).&lt;br /&gt;
&lt;br /&gt;
Tribe memories are being kept in the &#039;sc_tribe_memories&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Assets &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Assets are belongings of the tribe. They can represent buildings, items or spots to be built in the future.&lt;br /&gt;
&lt;br /&gt;
An asset is represented by a data structure (&#039;&#039;Tribe::Asset&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name, it&#039;s quantity (relevant just for items) and it&#039;s type (Building Spot, Building or Item). The tribe class has methods for adding, editing and deleting assets. It also has methods for managing buildings. (e.g. Replace a building spot with the actual building after the workers built it)&lt;br /&gt;
&lt;br /&gt;
Tribe assets are being kept in the &#039;sc_tribe_assets&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Knowledge &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Knowledge represents the information the tribe has gathered and the technologies they can use. (E.g. Ironworks, pottery, horseback riding, alphabet, math, etc)&lt;br /&gt;
&lt;br /&gt;
Technically, they are just strings used as tokens to prove the tribe has acquired knowledge or not.&lt;br /&gt;
&lt;br /&gt;
Knowledge is kept in an array of strings.&lt;br /&gt;
&lt;br /&gt;
Tribe knowledge is being kept in the &#039;sc_tribe_knowledge&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe Tree Node &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This class represents a node of the recipe tree describing the tribe current tasks. Each recipe tree node contains a link to it&#039;s recipe, waiting times, current requirement, current algorithm step and relationship information regarding other recipes. (just as a standard Tree, it may have parents and descendants).&lt;br /&gt;
&lt;br /&gt;
RecipeTreeNodes are not being stored in any database. They are just used during runtime as an AI for tribes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A recipe is a set of requirements and algorithm steps regarding a task that needs to be done. Recipes can vary from simple (Gather a resource) to very complex (Build an entire civilization).&lt;br /&gt;
&lt;br /&gt;
Recipes are being stored in the &#039;tribe_recipes&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
=== Advance Sequence ===&lt;br /&gt;
&lt;br /&gt;
Advance sequence is the hart of the Tribe system. The NPCClient will advance the brain 4 times a second. If some NPCs don&#039;t have task the Tribe will select a new task and Trigger a perception to start one of the NPCs behaviors.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
-&amp;gt; NPCClient : Advance&lt;br /&gt;
activate NPCClient&lt;br /&gt;
loop For each tribe&lt;br /&gt;
  NPCClient -&amp;gt; Tribe : Advance&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AdvanceResources&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  loop For each member&lt;br /&gt;
     alt For NPC&#039;s that &amp;quot;do nothing&amp;quot;&lt;br /&gt;
        Tribe -&amp;gt; Tribe : Brain&lt;br /&gt;
        activate Tribe&lt;br /&gt;
&lt;br /&gt;
        Tribe -&amp;gt; Tribe : GetNeedSet&lt;br /&gt;
        activate Tribe&lt;br /&gt;
        Tribe -&amp;gt; NPC : GetTribeMemberType&lt;br /&gt;
        activate NPC&lt;br /&gt;
        Tribe &amp;lt;-- NPC&lt;br /&gt;
        deactivate NPC&lt;br /&gt;
        Tribe &amp;lt;-- Tribe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
&lt;br /&gt;
        Tribe -&amp;gt; NeedSet : UpdateNeed&lt;br /&gt;
        activate NeedSet&lt;br /&gt;
        Tribe &amp;lt;-- NeedSet&lt;br /&gt;
        deactivate NeedSet&lt;br /&gt;
&lt;br /&gt;
        Tribe -&amp;gt; NeedSet : CalculateNeed&lt;br /&gt;
        activate NeedSet&lt;br /&gt;
        Tribe &amp;lt;-- NeedSet&lt;br /&gt;
        deactivate NeedSet&lt;br /&gt;
       &lt;br /&gt;
        Tribe -&amp;gt; TribeNeed : GetNeed&lt;br /&gt;
        activate TribeNeed&lt;br /&gt;
        Tribe &amp;lt;-- TribeNeed&lt;br /&gt;
        deactivate TribeNeed&lt;br /&gt;
&lt;br /&gt;
        Tribe &amp;lt;-- Tribe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
&lt;br /&gt;
        alt There is a perception&lt;br /&gt;
           Tribe -&amp;gt; NPC : TriggerEvent&lt;br /&gt;
           activate NPC&lt;br /&gt;
           Tribe &amp;lt;-- NPC&lt;br /&gt;
           deactivate NPC&lt;br /&gt;
        end&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
  NPCClient &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;-- NPCClient&lt;br /&gt;
deactivate NPCClient&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up tribes ==&lt;br /&gt;
There are 2 main database tables that need to be populated.&lt;br /&gt;
&lt;br /&gt;
* [[TribesTable]]&lt;br /&gt;
** Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.&lt;br /&gt;
** max_size sets the maximum number of members.&lt;br /&gt;
** wealth_resource sets the different types of resource that a tribe can mine in order to grow and/or sustain itself. This needs more work however the most important one is wealth_resource_growth which is the default rate at which a resource will grow without any work per second.&lt;br /&gt;
** reproduction_cost is the amount of resources required to reproduce.&lt;br /&gt;
&lt;br /&gt;
* tribe_members&lt;br /&gt;
** Each row is an association between a PID (on the server side) and a tribe.&lt;br /&gt;
&lt;br /&gt;
* tribe_needs&lt;br /&gt;
** Each row is a need associated with a tribe&lt;br /&gt;
** Consists of: type, name, perception, depend, need_start_value,need_growth_value, arguments&lt;br /&gt;
&lt;br /&gt;
== Tribe day-to-day life ==&lt;br /&gt;
&lt;br /&gt;
=== Behaviour ===&lt;br /&gt;
A tribe has a set of needs, which are nothing, explore, dig, reproduce and walk. These needs are increased by a rate set in the code for now. When a need is activated, it may also trigger a perception for the next npc.&lt;br /&gt;
&lt;br /&gt;
Tribe members are ordinary [[NPC Types|NPCs]], with an additional set of [[Behavior Operations]] and perceptions to be used in [[Behaviors_and_Reactions|Reactions]]. These perceptions are defined by the needs defined in the tribe_needs table and might be:&lt;br /&gt;
&lt;br /&gt;
* tribe:explore&lt;br /&gt;
* tribe:dig&lt;br /&gt;
* tribe:reproduce (should result in a reproduce op).&lt;br /&gt;
* tribe:resurrect&lt;br /&gt;
* tribe:guard&lt;br /&gt;
* Or anything else&lt;br /&gt;
&lt;br /&gt;
=== Reproduction ===&lt;br /&gt;
The reproduction need will only increase if the number of tribe members is below the maximum. When reproduction is triggered, the tribe resources are decreased by reproduction_cost and the next NPC receives the tribe:reproduce perception. If the NPC then performs the reproduce op, it causes a server-side clone. Everything is cloned and the new cloned NPC will be a member of the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Resurrection ===&lt;br /&gt;
When a member dies, it will be resurrected according to the tribe need and will also take a reproduction_cost. However, no cloning will take place.&lt;br /&gt;
&lt;br /&gt;
=== Resources ===&lt;br /&gt;
A tribe member can be set to use the [[Behavior_Operations#Locate_Operation|Transfere Operation]] to locate the memory of a tribe resource and use the [[Behavior_Operations#Locate_Operation|Dig Operation]] or [[Behavior_Operations#Locate_Operation|Harvest Operation]] to get resources when for example a &#039;&#039;tribe:harvest&#039;&#039; perception is triggered. The [[Behavior_Operations#Locate_Operation|Transfere Operation]] needs to be used when the npc is back home to transfer it to the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Locations ===&lt;br /&gt;
The tribe:resource and tribe:home locations can be used with tribe members. For example in the [[Behavior_Operations#Locate_Operation|Locate Operation]].&lt;br /&gt;
&lt;br /&gt;
== Tribe death ==&lt;br /&gt;
When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]] [[Category:NPCClient Design]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9130</id>
		<title>Tribe Design</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9130"/>
		<updated>2011-09-16T14:20:08Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Classes */  Added info for each.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Design =&lt;br /&gt;
&lt;br /&gt;
The tribe design is done using NPC Behaviors and Recipes. Tribe members are assigned tasks based on what the recipes dictates the tribe to achieve. This system uses a Recipe Manager which takes care of parsing recipes, breaking the initial recipe into subtasks and telling the npcs which action to take.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : members&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : deadMembers&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Resource : resources&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Memory : memories&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Asset : assets&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Knowledge : knowledge&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;1..1&amp;quot; RecipeTreeNode : recipes&lt;br /&gt;
RecipeTreeNode *-- Recipe&lt;br /&gt;
RecipeManager &amp;quot;1&amp;quot; *-- &amp;quot;N..1&amp;quot; Recipe : all recipes&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Members &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Tribe members (both dead &amp;amp; alive) are kept in an array in the Tribe Class. They are all represented by the NPC class. The tribal class only has methods to attach a tribe member. For spawning new members the server (gemSupervisor &amp;amp; entityManager classes) and the npcclient class are responsable.&lt;br /&gt;
&lt;br /&gt;
Tribe members can have different types. (Discussion needed about tribe types)&lt;br /&gt;
&lt;br /&gt;
Tribe members are being kept in the &#039;tribe_members&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Resources &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A resource is kept in a data structure (&#039;&#039;Tribe::Resource&#039;&#039;) containing it&#039;s name, nick and quantity. The tribe class has methods for adding, modifying, storing and completely deleting resources.&lt;br /&gt;
&lt;br /&gt;
Resources are being kept in the &#039;sc_tribe_resources&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Memories &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A memory is a location of some importance to the tribe. (E.g. a mine, a field, an enemy, etc)&lt;br /&gt;
&lt;br /&gt;
A memory is kept in a data structure (&#039;&#039;Tribe::Memory&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name and a link to an NPC (which is NULL if the memory is public to all tribe members, or != NULL if it&#039;s private to a tribe member). The tribe object has methods to add, store, modify and search memories.&lt;br /&gt;
&lt;br /&gt;
Tribe members also have a memory slot for keeping it&#039;s current task location. (see bufferMemory attribute of NPC class).&lt;br /&gt;
&lt;br /&gt;
Tribe memories are being kept in the &#039;sc_tribe_memories&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Assets &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Assets are belongings of the tribe. They can represent buildings, items or spots to be built in the future.&lt;br /&gt;
&lt;br /&gt;
An asset is represented by a data structure (&#039;&#039;Tribe::Asset&#039;&#039;) containing it&#039;s location (sector &amp;amp; coords), it&#039;s name, it&#039;s quantity (relevant just for items) and it&#039;s type (Building Spot, Building or Item). The tribe class has methods for adding, editing and deleting assets. It also has methods for managing buildings. (e.g. Replace a building spot with the actual building after the workers built it)&lt;br /&gt;
&lt;br /&gt;
Tribe assets are being kept in the &#039;sc_tribe_assets&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Knowledge &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Knowledge represents the information the tribe has gathered and the technologies they can use. (E.g. Ironworks, pottery, horseback riding, alphabet, math, etc)&lt;br /&gt;
&lt;br /&gt;
Technically, they are just strings used as tokens to prove the tribe has acquired knowledge or not.&lt;br /&gt;
&lt;br /&gt;
Knowledge is kept in an array of strings.&lt;br /&gt;
&lt;br /&gt;
Tribe knowledge is being kept in the &#039;sc_tribe_knowledge&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe Tree Node &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This class represents a node of the recipe tree describing the tribe current tasks. Each recipe tree node contains a link to it&#039;s recipe, waiting times, current requirement, current algorithm step and relationship information regarding other recipes. (just as a standard Tree, it may have parents and descendants).&lt;br /&gt;
&lt;br /&gt;
RecipeTreeNodes are not being stored in any database. They are just used during runtime to be used like an AI for the tribes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Recipe &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A recipe is a set of requirements and algorithm steps regarding a task that needs to be done. Recipes can vary from simple (Gather a resource) to very complex (Build an entire civilization).&lt;br /&gt;
&lt;br /&gt;
Recipes are being stored in the &#039;tribe_recipes&#039; mysql table.&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
=== Advance Sequence ===&lt;br /&gt;
&lt;br /&gt;
Advance sequence is the hart of the Tribe system. The NPCClient will advance the brain 4 times a second. If some NPCs don&#039;t have task the Tribe will select a new task and Trigger a perception to start one of the NPCs behaviors.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
-&amp;gt; NPCClient : Advance&lt;br /&gt;
activate NPCClient&lt;br /&gt;
loop For each tribe&lt;br /&gt;
  NPCClient -&amp;gt; Tribe : Advance&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AdvanceResources&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  loop For each member&lt;br /&gt;
     alt For NPC&#039;s that &amp;quot;do nothing&amp;quot;&lt;br /&gt;
        Tribe -&amp;gt; Tribe : Brain&lt;br /&gt;
        activate Tribe&lt;br /&gt;
&lt;br /&gt;
        Tribe -&amp;gt; Tribe : GetNeedSet&lt;br /&gt;
        activate Tribe&lt;br /&gt;
        Tribe -&amp;gt; NPC : GetTribeMemberType&lt;br /&gt;
        activate NPC&lt;br /&gt;
        Tribe &amp;lt;-- NPC&lt;br /&gt;
        deactivate NPC&lt;br /&gt;
        Tribe &amp;lt;-- Tribe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
&lt;br /&gt;
        Tribe -&amp;gt; NeedSet : UpdateNeed&lt;br /&gt;
        activate NeedSet&lt;br /&gt;
        Tribe &amp;lt;-- NeedSet&lt;br /&gt;
        deactivate NeedSet&lt;br /&gt;
&lt;br /&gt;
        Tribe -&amp;gt; NeedSet : CalculateNeed&lt;br /&gt;
        activate NeedSet&lt;br /&gt;
        Tribe &amp;lt;-- NeedSet&lt;br /&gt;
        deactivate NeedSet&lt;br /&gt;
       &lt;br /&gt;
        Tribe -&amp;gt; TribeNeed : GetNeed&lt;br /&gt;
        activate TribeNeed&lt;br /&gt;
        Tribe &amp;lt;-- TribeNeed&lt;br /&gt;
        deactivate TribeNeed&lt;br /&gt;
&lt;br /&gt;
        Tribe &amp;lt;-- Tribe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
&lt;br /&gt;
        alt There is a perception&lt;br /&gt;
           Tribe -&amp;gt; NPC : TriggerEvent&lt;br /&gt;
           activate NPC&lt;br /&gt;
           Tribe &amp;lt;-- NPC&lt;br /&gt;
           deactivate NPC&lt;br /&gt;
        end&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
  NPCClient &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;-- NPCClient&lt;br /&gt;
deactivate NPCClient&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up tribes ==&lt;br /&gt;
There are 2 main database tables that need to be populated.&lt;br /&gt;
&lt;br /&gt;
* [[TribesTable]]&lt;br /&gt;
** Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.&lt;br /&gt;
** max_size sets the maximum number of members.&lt;br /&gt;
** wealth_resource sets the different types of resource that a tribe can mine in order to grow and/or sustain itself. This needs more work however the most important one is wealth_resource_growth which is the default rate at which a resource will grow without any work per second.&lt;br /&gt;
** reproduction_cost is the amount of resources required to reproduce.&lt;br /&gt;
&lt;br /&gt;
* tribe_members&lt;br /&gt;
** Each row is an association between a PID (on the server side) and a tribe.&lt;br /&gt;
&lt;br /&gt;
* tribe_needs&lt;br /&gt;
** Each row is a need associated with a tribe&lt;br /&gt;
** Consists of: type, name, perception, depend, need_start_value,need_growth_value, arguments&lt;br /&gt;
&lt;br /&gt;
== Tribe day-to-day life ==&lt;br /&gt;
&lt;br /&gt;
=== Behaviour ===&lt;br /&gt;
A tribe has a set of needs, which are nothing, explore, dig, reproduce and walk. These needs are increased by a rate set in the code for now. When a need is activated, it may also trigger a perception for the next npc.&lt;br /&gt;
&lt;br /&gt;
Tribe members are ordinary [[NPC Types|NPCs]], with an additional set of [[Behavior Operations]] and perceptions to be used in [[Behaviors_and_Reactions|Reactions]]. These perceptions are defined by the needs defined in the tribe_needs table and might be:&lt;br /&gt;
&lt;br /&gt;
* tribe:explore&lt;br /&gt;
* tribe:dig&lt;br /&gt;
* tribe:reproduce (should result in a reproduce op).&lt;br /&gt;
* tribe:resurrect&lt;br /&gt;
* tribe:guard&lt;br /&gt;
* Or anything else&lt;br /&gt;
&lt;br /&gt;
=== Reproduction ===&lt;br /&gt;
The reproduction need will only increase if the number of tribe members is below the maximum. When reproduction is triggered, the tribe resources are decreased by reproduction_cost and the next NPC receives the tribe:reproduce perception. If the NPC then performs the reproduce op, it causes a server-side clone. Everything is cloned and the new cloned NPC will be a member of the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Resurrection ===&lt;br /&gt;
When a member dies, it will be resurrected according to the tribe need and will also take a reproduction_cost. However, no cloning will take place.&lt;br /&gt;
&lt;br /&gt;
=== Resources ===&lt;br /&gt;
A tribe member can be set to use the [[Behavior_Operations#Locate_Operation|Transfere Operation]] to locate the memory of a tribe resource and use the [[Behavior_Operations#Locate_Operation|Dig Operation]] or [[Behavior_Operations#Locate_Operation|Harvest Operation]] to get resources when for example a &#039;&#039;tribe:harvest&#039;&#039; perception is triggered. The [[Behavior_Operations#Locate_Operation|Transfere Operation]] needs to be used when the npc is back home to transfer it to the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Locations ===&lt;br /&gt;
The tribe:resource and tribe:home locations can be used with tribe members. For example in the [[Behavior_Operations#Locate_Operation|Locate Operation]].&lt;br /&gt;
&lt;br /&gt;
== Tribe death ==&lt;br /&gt;
When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]] [[Category:NPCClient Design]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9129</id>
		<title>Tribe Design</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Design&amp;diff=9129"/>
		<updated>2011-09-16T13:46:39Z</updated>

		<summary type="html">&lt;p&gt;Zee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tribe Design =&lt;br /&gt;
&lt;br /&gt;
The tribe design is done using NPC Behaviors and Recipes. Tribe members are assigned tasks based on what the recipes dictates the tribe to achieve. This system uses a Recipe Manager which takes care of parsing recipes, breaking the initial recipe into subtasks and telling the npcs which action to take.&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
scale 0.8&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : members&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; NPC : deadMembers&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Resource : resources&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Memory : memories&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Asset : assets&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;0..N&amp;quot; Knowledge : knowledge&lt;br /&gt;
Tribe &amp;quot;1&amp;quot; *-- &amp;quot;1..1&amp;quot; RecipeTreeNode : recipes&lt;br /&gt;
RecipeTreeNode *-- Recipe&lt;br /&gt;
RecipeManager &amp;quot;1&amp;quot; *-- &amp;quot;N..1&amp;quot; Recipe : all recipes&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
=== Advance Sequence ===&lt;br /&gt;
&lt;br /&gt;
Advance sequence is the hart of the Tribe system. The NPCClient will advance the brain 4 times a second. If some NPCs don&#039;t have task the Tribe will select a new task and Trigger a perception to start one of the NPCs behaviors.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;uml&amp;gt;&lt;br /&gt;
-&amp;gt; NPCClient : Advance&lt;br /&gt;
activate NPCClient&lt;br /&gt;
loop For each tribe&lt;br /&gt;
  NPCClient -&amp;gt; Tribe : Advance&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe -&amp;gt; Tribe : AdvanceResources&lt;br /&gt;
  activate Tribe&lt;br /&gt;
  Tribe &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
  loop For each member&lt;br /&gt;
     alt For NPC&#039;s that &amp;quot;do nothing&amp;quot;&lt;br /&gt;
        Tribe -&amp;gt; Tribe : Brain&lt;br /&gt;
        activate Tribe&lt;br /&gt;
&lt;br /&gt;
        Tribe -&amp;gt; Tribe : GetNeedSet&lt;br /&gt;
        activate Tribe&lt;br /&gt;
        Tribe -&amp;gt; NPC : GetTribeMemberType&lt;br /&gt;
        activate NPC&lt;br /&gt;
        Tribe &amp;lt;-- NPC&lt;br /&gt;
        deactivate NPC&lt;br /&gt;
        Tribe &amp;lt;-- Tribe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
&lt;br /&gt;
        Tribe -&amp;gt; NeedSet : UpdateNeed&lt;br /&gt;
        activate NeedSet&lt;br /&gt;
        Tribe &amp;lt;-- NeedSet&lt;br /&gt;
        deactivate NeedSet&lt;br /&gt;
&lt;br /&gt;
        Tribe -&amp;gt; NeedSet : CalculateNeed&lt;br /&gt;
        activate NeedSet&lt;br /&gt;
        Tribe &amp;lt;-- NeedSet&lt;br /&gt;
        deactivate NeedSet&lt;br /&gt;
       &lt;br /&gt;
        Tribe -&amp;gt; TribeNeed : GetNeed&lt;br /&gt;
        activate TribeNeed&lt;br /&gt;
        Tribe &amp;lt;-- TribeNeed&lt;br /&gt;
        deactivate TribeNeed&lt;br /&gt;
&lt;br /&gt;
        Tribe &amp;lt;-- Tribe&lt;br /&gt;
        deactivate Tribe&lt;br /&gt;
&lt;br /&gt;
        alt There is a perception&lt;br /&gt;
           Tribe -&amp;gt; NPC : TriggerEvent&lt;br /&gt;
           activate NPC&lt;br /&gt;
           Tribe &amp;lt;-- NPC&lt;br /&gt;
           deactivate NPC&lt;br /&gt;
        end&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
  NPCClient &amp;lt;-- Tribe&lt;br /&gt;
  deactivate Tribe&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;-- NPCClient&lt;br /&gt;
deactivate NPCClient&lt;br /&gt;
&amp;lt;/uml&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up tribes ==&lt;br /&gt;
There are 2 main database tables that need to be populated.&lt;br /&gt;
&lt;br /&gt;
* [[TribesTable]]&lt;br /&gt;
** Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.&lt;br /&gt;
** max_size sets the maximum number of members.&lt;br /&gt;
** wealth_resource sets the different types of resource that a tribe can mine in order to grow and/or sustain itself. This needs more work however the most important one is wealth_resource_growth which is the default rate at which a resource will grow without any work per second.&lt;br /&gt;
** reproduction_cost is the amount of resources required to reproduce.&lt;br /&gt;
&lt;br /&gt;
* tribe_members&lt;br /&gt;
** Each row is an association between a PID (on the server side) and a tribe.&lt;br /&gt;
&lt;br /&gt;
* tribe_needs&lt;br /&gt;
** Each row is a need associated with a tribe&lt;br /&gt;
** Consists of: type, name, perception, depend, need_start_value,need_growth_value, arguments&lt;br /&gt;
&lt;br /&gt;
== Tribe day-to-day life ==&lt;br /&gt;
&lt;br /&gt;
=== Behaviour ===&lt;br /&gt;
A tribe has a set of needs, which are nothing, explore, dig, reproduce and walk. These needs are increased by a rate set in the code for now. When a need is activated, it may also trigger a perception for the next npc.&lt;br /&gt;
&lt;br /&gt;
Tribe members are ordinary [[NPC Types|NPCs]], with an additional set of [[Behavior Operations]] and perceptions to be used in [[Behaviors_and_Reactions|Reactions]]. These perceptions are defined by the needs defined in the tribe_needs table and might be:&lt;br /&gt;
&lt;br /&gt;
* tribe:explore&lt;br /&gt;
* tribe:dig&lt;br /&gt;
* tribe:reproduce (should result in a reproduce op).&lt;br /&gt;
* tribe:resurrect&lt;br /&gt;
* tribe:guard&lt;br /&gt;
* Or anything else&lt;br /&gt;
&lt;br /&gt;
=== Reproduction ===&lt;br /&gt;
The reproduction need will only increase if the number of tribe members is below the maximum. When reproduction is triggered, the tribe resources are decreased by reproduction_cost and the next NPC receives the tribe:reproduce perception. If the NPC then performs the reproduce op, it causes a server-side clone. Everything is cloned and the new cloned NPC will be a member of the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Resurrection ===&lt;br /&gt;
When a member dies, it will be resurrected according to the tribe need and will also take a reproduction_cost. However, no cloning will take place.&lt;br /&gt;
&lt;br /&gt;
=== Resources ===&lt;br /&gt;
A tribe member can be set to use the [[Behavior_Operations#Locate_Operation|Transfere Operation]] to locate the memory of a tribe resource and use the [[Behavior_Operations#Locate_Operation|Dig Operation]] or [[Behavior_Operations#Locate_Operation|Harvest Operation]] to get resources when for example a &#039;&#039;tribe:harvest&#039;&#039; perception is triggered. The [[Behavior_Operations#Locate_Operation|Transfere Operation]] needs to be used when the npc is back home to transfer it to the tribe.&lt;br /&gt;
&lt;br /&gt;
=== Locations ===&lt;br /&gt;
The tribe:resource and tribe:home locations can be used with tribe members. For example in the [[Behavior_Operations#Locate_Operation|Locate Operation]].&lt;br /&gt;
&lt;br /&gt;
== Tribe death ==&lt;br /&gt;
When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]] [[Category:NPCClient Design]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Behaviors_and_Reactions&amp;diff=9118</id>
		<title>Behaviors and Reactions</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Behaviors_and_Reactions&amp;diff=9118"/>
		<updated>2011-08-28T20:17:37Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Behavior */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As discussed earlier in [[NPC_Behavior_scripting]], any [[NPC Types]] are really simply a collection of behaviors and reactions to events.  At the most meta level, all of us fit this definition. How we act and how we respond to stimuli determines everything about our activities over time.  Thus it seems sufficient and general to model npc behavior this way also.&lt;br /&gt;
&lt;br /&gt;
Each behavior gets a script made of [[Behavior_Operations]] as documented in the previous sections.  For now we will neglect those, however and just talk about the behaviors themselves.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Here is an example of an NPC Type’s behavior/reaction list:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;Wanderer&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;walk&amp;quot; decay=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; initial=&amp;quot;50&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;turn&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;fight&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;chase&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;BR&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;collision&amp;quot;           behavior=&amp;quot;turn&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;out of bounds&amp;quot;       behavior=&amp;quot;turn&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;attack&amp;quot;              behavior=&amp;quot;fight&amp;quot; delta=&amp;quot;150&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;damage&amp;quot;              behavior=&amp;quot;fight&amp;quot; delta=&amp;quot;20&amp;quot; weight=&amp;quot;1&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;chase&amp;quot; delta=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;death&amp;quot;               behavior=&amp;quot;fight&amp;quot; delta=&amp;quot;-1&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This collection of behaviors and reactions is sufficient to have a basic outdoor wandering monster who will avoid collisions, stay in his boundary region, fight back if attacked and stop attacking if he dies.&lt;br /&gt;
&lt;br /&gt;
=== List of priorities for NPCs ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Similar to the way the hate list maintains a prioritized list of enemies for each NPC, each NPC also maintains a set of priorities for the list of behaviors in its npctype.  The priority list starts out with 0 as the default score, unless an “initial” attribute is specified.  (One behavior should have this attribute so the npc has a place to start.)  Thus, any “Wanderer” NPC will start with the following priority list:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-0, chase-0&lt;br /&gt;
&lt;br /&gt;
Thus on startup the NPC will begin by walking and using the operations inside that behavior tag to do something until an event occurs which preempts the behavior by making something else higher priority.  For example, if he goes out of bounds, he will get an “out of bounds” perception, which he has a &amp;lt;react&amp;gt; tag for.  It says to add 100 points to the “turn” behavior priority, which results in:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-100, fight-0, chase-0&lt;br /&gt;
&lt;br /&gt;
So his “walk” behavior is interrupted and the “turn” behavior and script is activated.  This script starts running and the npc starts turning.  Turning to point back into the boundary region should only take a couple of seconds.  When the script complets for this behavior, the “completion_decay” of the behavior kicks in and affects the P-List again:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-0, chase-0&lt;br /&gt;
&lt;br /&gt;
There are many real-world examples of how “completion_decay” exists in humans.  Many actions are the top priority until they are completed, and then one simply doesn’t need to do them anymore.  “completion_decay” is modeling that change in priority when an action is performed.&lt;br /&gt;
&lt;br /&gt;
Now that the priority for turn has gone back to 0, “walk” again is the highest priority behavior and the npc starts walking again.&lt;br /&gt;
&lt;br /&gt;
So now the npc is attacked by a player in the forest.  “attack” is a perception sent by the server, as discussed in a previous section, and one for which this npctype has a &amp;lt;react&amp;gt; tag, telling him to add 150 to his “fight” priority, resulting in:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-150, chase-0&lt;br /&gt;
&lt;br /&gt;
So now the npc stops walking and starts his fight behavior, which probably has the &amp;lt;melee&amp;gt; operation in it, using the hate list to fight back against one or more attackers.  As the attack progresses, damage perceptions come in.  A damage perception of 10HP has a &amp;lt;react&amp;gt; script also, which adds 10 points to the fight priority and also has a “weight” attribute which affects the hate list instead of the behavior list:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-160, chase-0&lt;br /&gt;
&lt;br /&gt;
Since the fight behavior is already the highest, it might be redundant to keep increasing it like this, but personally I view it as the npc getting more enraged, which means it will take him longer to calm down when he runs out of enemies.  The weight=”1” attribute means that the attacker’s hate score will go up by 1*HP.&lt;br /&gt;
&lt;br /&gt;
Now imagine that the attacking player is losing the fight, and decides to run away.  Very quickly, the “target out of range” perception will fire, created by the melee operation when the most hated enemy is farther away than the melee_range but within the seek_range.  This NPC is scripted to chase after hated enemies if they run away with his &amp;lt;react event=”target out of range”&amp;gt; tag.  The “delta” specified of 0 is a special delta which means “Make the named behavior the highest no matter what.”  When reactions are coded with 0 deltas, NPCs are really acting like state machines again.&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-160, chase-185  (Highest means at least 25 higher than the next highest to cause a preemption and switch.)&lt;br /&gt;
&lt;br /&gt;
So now the NPC stops attacking and begins chasing the most hated enemy.  The &amp;lt;chase&amp;gt; tag has a range specified for the chase to be completed (probably 2m again), so when the npc has caught the player, the chase behavior completion decay hits.  The chase behavior has  a specified completion decay of 100, but since chase was escalated artificially high by the 0 react, it is restored intead back to its original value.&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-160, chase-0&lt;br /&gt;
&lt;br /&gt;
So the npc stops chasing and resumes fighting the player immediately when he catches him.  Now the npc finally kills the player and the fight is over.  The “fight” behavior is still the highest one, so the npc keeps looking around for other enemies to fight, such as group members.  If none are found, his fight behavior keeps decreasing by 10 points per iteration.&lt;br /&gt;
P-List: walk-50, turn-0, fight-160, chase-0&lt;br /&gt;
P-List: walk-50, turn-0, fight-150, chase-0&lt;br /&gt;
P-List: walk-50, turn-0, fight-140, chase-0&lt;br /&gt;
P-List: walk-50, turn-0, fight-130, chase-0&lt;br /&gt;
And so on…&lt;br /&gt;
&lt;br /&gt;
Eventually, “walk” behavior becomes the most active again and the npc resumes his wandering of the forest.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The key concepts here are that the NPC constantly maintains a priority list of behaviors and a priority of list of enemies to attack.  &amp;lt;react&amp;gt; tags can affect behavior priority, hatelist priority or both.&lt;br /&gt;
&lt;br /&gt;
The interactions of events, behaviors and reactions can become very complex.  The npc can be interrupted by an attack while moving, turning or even chasing another player.  This priority structure was designed to allow for rich behavior interruption and resumption while having realistic reactions to world events and activities.  Hopefully, with the right scripts we can create very life-like npcs that are also efficient on networking and CPU, with emergent behaviors that stay challenging and interesting to players for a long time to come.&lt;br /&gt;
&lt;br /&gt;
== Behavior ==&lt;br /&gt;
{|&lt;br /&gt;
!Parameter&lt;br /&gt;
!Type&lt;br /&gt;
!Default&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|name&lt;br /&gt;
|string&lt;br /&gt;
|Mandatory&lt;br /&gt;
|The name of this behavior&lt;br /&gt;
|-&lt;br /&gt;
|loop&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set to true if this behavior should loop&lt;br /&gt;
|-&lt;br /&gt;
|decay&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|The decay rate of this behavior to apply when the behavior is the active one.&lt;br /&gt;
|-&lt;br /&gt;
|completion_decay&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|The decay to be applied when this behavior is done. -1 will be all of the current need.&lt;br /&gt;
|-&lt;br /&gt;
|growth&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|The growth rate of this behavior to apply when the behavior isn&#039;t the active one.&lt;br /&gt;
|-&lt;br /&gt;
|initial&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|The initial need for this behavior&lt;br /&gt;
|-&lt;br /&gt;
|when_dead&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set this to true if this behavior should be possible while dead. [[Behavior Operations#Resurrect_Operation|Resurrect Operation]] will need this.&lt;br /&gt;
|-&lt;br /&gt;
|resume&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set to true if this behavior should resume after an interrupt.&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|float&lt;br /&gt;
|none&lt;br /&gt;
|Set this attribute if a min need limit should be applied to this behavior.&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|float&lt;br /&gt;
|none&lt;br /&gt;
|Set this attribute if a max need limit should be applied to this behavior.&lt;br /&gt;
|-&lt;br /&gt;
|auto_memorize&lt;br /&gt;
|string,[...,string]&lt;br /&gt;
|none&lt;br /&gt;
|If set this npc will memorize all perceptions types passed without changing behavior. (can pass keyword &#039;all&#039; as parameter to auto_memorize all)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
  Ex: &amp;lt;behavior name=&amp;quot;move&amp;quot; decay=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; initial=&amp;quot;80&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        ...&lt;br /&gt;
      &amp;lt;/behavior&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;chase&amp;quot; decay=&amp;quot;1&amp;quot; completion_decay=&amp;quot;-1&amp;quot; growth=&amp;quot;0&amp;quot; initial=&amp;quot;0&amp;quot; &amp;gt;&lt;br /&gt;
        ...&lt;br /&gt;
      &amp;lt;/behavior&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reaction ==&lt;br /&gt;
{|&lt;br /&gt;
!Parameter&lt;br /&gt;
!Type&lt;br /&gt;
!Default&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|string&lt;br /&gt;
|&lt;br /&gt;
|The event to react to.&lt;br /&gt;
|-&lt;br /&gt;
|behavior&lt;br /&gt;
|string[,...,string]&lt;br /&gt;
|&lt;br /&gt;
|The set of behavior to influence if this reaction is triggered.&lt;br /&gt;
|-&lt;br /&gt;
|delta&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|Apply a delta value to the need of the affected behavior.&lt;br /&gt;
|-&lt;br /&gt;
|absolute&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|Apply a absolute value to the need of the affected behavior.&lt;br /&gt;
|-&lt;br /&gt;
|range&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|weight&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|Passed to the perception when the reaction is accepted. Used to alter the HateList of the NPC.&lt;br /&gt;
|-&lt;br /&gt;
|faction_diff&lt;br /&gt;
|int&lt;br /&gt;
|0&lt;br /&gt;
|Used to match faction perceptions.&lt;br /&gt;
|-&lt;br /&gt;
|oper&lt;br /&gt;
|string&lt;br /&gt;
|&lt;br /&gt;
|The operator to use when comparing faction perceptions.&lt;br /&gt;
|-&lt;br /&gt;
|value&lt;br /&gt;
|string[,...,string]&lt;br /&gt;
|&lt;br /&gt;
|Used by some perceptions like time.&lt;br /&gt;
|-&lt;br /&gt;
|random&lt;br /&gt;
|integer[,...,integer]&lt;br /&gt;
|&lt;br /&gt;
|Used to add some random value to the value array.&lt;br /&gt;
|-&lt;br /&gt;
|type&lt;br /&gt;
|string&lt;br /&gt;
|&lt;br /&gt;
|The type is different for each perception. A &amp;quot;location sensed&amp;quot; will have the location type as the type.&lt;br /&gt;
|-&lt;br /&gt;
|active_only&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Only influence active behaviors&lt;br /&gt;
|-&lt;br /&gt;
|inactive_only&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Only influence inactive behaviors&lt;br /&gt;
|-&lt;br /&gt;
|when_dead&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Influence behaviors even if the npc is dead.&lt;br /&gt;
|-&lt;br /&gt;
|when_invisible&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set to true if an invisible NPC should accept this reaction.&lt;br /&gt;
|-&lt;br /&gt;
|when_invincible&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set to true if an invincible NPC should accept this reaction.&lt;br /&gt;
|-&lt;br /&gt;
|only_interrupt&lt;br /&gt;
|string,[...,string]&lt;br /&gt;
|&lt;br /&gt;
|If set this event will only be accepted if it can interrupt one and active behavior from this list.&lt;br /&gt;
|-&lt;br /&gt;
|do_not_interrupt&lt;br /&gt;
|string,[...,string]&lt;br /&gt;
|&lt;br /&gt;
|Set this if this reaction should not interrupt some active behaviors.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The reaction can influence on a behaviors need either as GUARANTIED to execute(no delta or absolute attribute set), DELTA (delta attribute set), or ABSOLUTE ( absolute attribute set).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  Ex:  &amp;lt;react event=&amp;quot;damage&amp;quot;                behavior=&amp;quot;Fight&amp;quot; delta=&amp;quot;20&amp;quot; weight=&amp;quot;1&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  Ex:  &amp;lt;react event=&amp;quot;time&amp;quot; value=&amp;quot;16,0,,,&amp;quot;  random=&amp;quot;,5,,,&amp;quot; behavior=&amp;quot;GoHome&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example show a reaction to a time event that will occur between 1600 and 1605. This is archived due to the random property. Each of the values in value represents &amp;quot;Hour,Minute,Year,Month,Day&amp;quot;. Any parameter not&lt;br /&gt;
set will match every possible combination.&lt;br /&gt;
&lt;br /&gt;
  Ex:  &amp;lt;react event=&amp;quot;location sensed&amp;quot;    behavior=&amp;quot;ExploreLoc&amp;quot;    type=&amp;quot;mine&amp;quot; only_interrupt=&amp;quot;Explore&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example show a reaction to the location sensed perception where location of type mine will interrupt explore operation with the ExploreLoc behavior.&lt;br /&gt;
&lt;br /&gt;
== Perceptions ==&lt;br /&gt;
&lt;br /&gt;
Perceptions it the invisible mechanism that makes reactions act. There are several situations where perceptions are fired. Some are hard coded into the NPCClient. Some are fired as responses to other script elements and the name might be configurable. An example on this is the [[Behavior_Operations#Chase_Operation|Chase Operation]] where the perception name is configured through the operation.&lt;br /&gt;
&lt;br /&gt;
This section try to summarize some of the perceptions available. Though they might as well be documented at all or only through the senders.&lt;br /&gt;
&lt;br /&gt;
=== Events to react to ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Perception&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|collision&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|out of bounds&lt;br /&gt;
|Checks if the NPC is out of bounds of a region defined in sc_npc_definitions and set up in sc_locations &lt;br /&gt;
|-&lt;br /&gt;
|in bounds&lt;br /&gt;
|Checks if the NPC is in bounds of a region defined in sc_npc_definitions and set up in sc_locations &lt;br /&gt;
|-&lt;br /&gt;
|damage&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|attack&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|nearby&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|target out of range&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|death&lt;br /&gt;
|description&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Faction Perceptions ===&lt;br /&gt;
&lt;br /&gt;
This is perception can be filtered on the faction standing between the NPC and the sender. By defining the oper in the&lt;br /&gt;
reaction the faction will be compared. Without the factions will not be compared.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute&lt;br /&gt;
!Values&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
|talk&lt;br /&gt;
|Talk preception fired when talked to&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|owner anyrange, owner sensed, owner nearby, owner adjacent&lt;br /&gt;
|Owner perceptions fired when owner is at different ranges(Will not get player perception if you are the owner).&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
|player anyrange, player sensed, player nearby, player adjacent&lt;br /&gt;
|Player perceptions fired when player is at different ranges.&lt;br /&gt;
|-&lt;br /&gt;
|faction_diff&lt;br /&gt;
|integer&lt;br /&gt;
|The faction value to compare&lt;br /&gt;
|-&lt;br /&gt;
|oper&lt;br /&gt;
|&amp;gt;,&amp;lt;&lt;br /&gt;
|React if grater than or react when less than. If no oper is defined, faction will not be compared.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Range&lt;br /&gt;
!Value&lt;br /&gt;
|-&lt;br /&gt;
|sensed&lt;br /&gt;
|&amp;lt;30&lt;br /&gt;
|-&lt;br /&gt;
|nearby&lt;br /&gt;
|&amp;lt;10&lt;br /&gt;
|-&lt;br /&gt;
|adjacent&lt;br /&gt;
|&amp;lt;4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
  Ex: &amp;lt;react event=&amp;quot;talk&amp;quot; faction_diff=&amp;quot;10&amp;quot; oper=&amp;quot;&amp;gt;&amp;quot; ... /&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
This example will only react to talk if the faction difference is more than +10 to the originator of the talk perception.&lt;br /&gt;
&lt;br /&gt;
  Ex: &amp;lt;react event=&amp;quot;player nearby&amp;quot; ... /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allways react when a player is nearby.&lt;br /&gt;
&lt;br /&gt;
=== Item Perceptions ===&lt;br /&gt;
&lt;br /&gt;
This perception is fired whenever a NPC moves into the nearby, adjacent, or sensed range from an item. In the nearby range the item is so close that it can be picked up.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute&lt;br /&gt;
!Values&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|item nearby, item adjacent, item sensed&lt;br /&gt;
|The different perception fired that nearby, adjacent, or sensed range.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Location Perception ===&lt;br /&gt;
&lt;br /&gt;
This perception is fired whenever a NPC moves into the sensed range of a location.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute&lt;br /&gt;
!Values&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|location perception&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|type&lt;br /&gt;
|&#039;&#039;string&#039;&#039;&lt;br /&gt;
|The location type name of the location sensed.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  Ex:  &amp;lt;react event=&amp;quot;location perception&amp;quot; type=&amp;quot;mine&amp;quot; ... /&amp;gt;&lt;br /&gt;
       &amp;lt;react event=&amp;quot;location perception&amp;quot; ... /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Time Perception ===&lt;br /&gt;
&lt;br /&gt;
This perception is fired every game minute. It allows react to trigger on any combination of game hours, minutes, years, month, days.&lt;br /&gt;
{|&lt;br /&gt;
!Attribute&lt;br /&gt;
!Values&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|time&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|value&lt;br /&gt;
|hours,minutes,years,months,days&lt;br /&gt;
|Match 1200 at the 2nd month like this &amp;quot;12,00,,2,&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
   Ex: &amp;lt;react event=&amp;quot;time&amp;quot; value=&amp;quot;12,00,,2,&amp;quot; ... /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Behaviors_and_Reactions&amp;diff=9117</id>
		<title>Behaviors and Reactions</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Behaviors_and_Reactions&amp;diff=9117"/>
		<updated>2011-08-28T16:46:23Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Behavior */ -- Added auto_memorize&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As discussed earlier in [[NPC_Behavior_scripting]], any [[NPC Types]] are really simply a collection of behaviors and reactions to events.  At the most meta level, all of us fit this definition. How we act and how we respond to stimuli determines everything about our activities over time.  Thus it seems sufficient and general to model npc behavior this way also.&lt;br /&gt;
&lt;br /&gt;
Each behavior gets a script made of [[Behavior_Operations]] as documented in the previous sections.  For now we will neglect those, however and just talk about the behaviors themselves.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Here is an example of an NPC Type’s behavior/reaction list:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;Wanderer&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;walk&amp;quot; decay=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; initial=&amp;quot;50&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;turn&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;fight&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;chase&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;BR&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;collision&amp;quot;           behavior=&amp;quot;turn&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;out of bounds&amp;quot;       behavior=&amp;quot;turn&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;attack&amp;quot;              behavior=&amp;quot;fight&amp;quot; delta=&amp;quot;150&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;damage&amp;quot;              behavior=&amp;quot;fight&amp;quot; delta=&amp;quot;20&amp;quot; weight=&amp;quot;1&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;chase&amp;quot; delta=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;react event=&amp;quot;death&amp;quot;               behavior=&amp;quot;fight&amp;quot; delta=&amp;quot;-1&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This collection of behaviors and reactions is sufficient to have a basic outdoor wandering monster who will avoid collisions, stay in his boundary region, fight back if attacked and stop attacking if he dies.&lt;br /&gt;
&lt;br /&gt;
=== List of priorities for NPCs ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Similar to the way the hate list maintains a prioritized list of enemies for each NPC, each NPC also maintains a set of priorities for the list of behaviors in its npctype.  The priority list starts out with 0 as the default score, unless an “initial” attribute is specified.  (One behavior should have this attribute so the npc has a place to start.)  Thus, any “Wanderer” NPC will start with the following priority list:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-0, chase-0&lt;br /&gt;
&lt;br /&gt;
Thus on startup the NPC will begin by walking and using the operations inside that behavior tag to do something until an event occurs which preempts the behavior by making something else higher priority.  For example, if he goes out of bounds, he will get an “out of bounds” perception, which he has a &amp;lt;react&amp;gt; tag for.  It says to add 100 points to the “turn” behavior priority, which results in:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-100, fight-0, chase-0&lt;br /&gt;
&lt;br /&gt;
So his “walk” behavior is interrupted and the “turn” behavior and script is activated.  This script starts running and the npc starts turning.  Turning to point back into the boundary region should only take a couple of seconds.  When the script complets for this behavior, the “completion_decay” of the behavior kicks in and affects the P-List again:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-0, chase-0&lt;br /&gt;
&lt;br /&gt;
There are many real-world examples of how “completion_decay” exists in humans.  Many actions are the top priority until they are completed, and then one simply doesn’t need to do them anymore.  “completion_decay” is modeling that change in priority when an action is performed.&lt;br /&gt;
&lt;br /&gt;
Now that the priority for turn has gone back to 0, “walk” again is the highest priority behavior and the npc starts walking again.&lt;br /&gt;
&lt;br /&gt;
So now the npc is attacked by a player in the forest.  “attack” is a perception sent by the server, as discussed in a previous section, and one for which this npctype has a &amp;lt;react&amp;gt; tag, telling him to add 150 to his “fight” priority, resulting in:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-150, chase-0&lt;br /&gt;
&lt;br /&gt;
So now the npc stops walking and starts his fight behavior, which probably has the &amp;lt;melee&amp;gt; operation in it, using the hate list to fight back against one or more attackers.  As the attack progresses, damage perceptions come in.  A damage perception of 10HP has a &amp;lt;react&amp;gt; script also, which adds 10 points to the fight priority and also has a “weight” attribute which affects the hate list instead of the behavior list:&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-160, chase-0&lt;br /&gt;
&lt;br /&gt;
Since the fight behavior is already the highest, it might be redundant to keep increasing it like this, but personally I view it as the npc getting more enraged, which means it will take him longer to calm down when he runs out of enemies.  The weight=”1” attribute means that the attacker’s hate score will go up by 1*HP.&lt;br /&gt;
&lt;br /&gt;
Now imagine that the attacking player is losing the fight, and decides to run away.  Very quickly, the “target out of range” perception will fire, created by the melee operation when the most hated enemy is farther away than the melee_range but within the seek_range.  This NPC is scripted to chase after hated enemies if they run away with his &amp;lt;react event=”target out of range”&amp;gt; tag.  The “delta” specified of 0 is a special delta which means “Make the named behavior the highest no matter what.”  When reactions are coded with 0 deltas, NPCs are really acting like state machines again.&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-160, chase-185  (Highest means at least 25 higher than the next highest to cause a preemption and switch.)&lt;br /&gt;
&lt;br /&gt;
So now the NPC stops attacking and begins chasing the most hated enemy.  The &amp;lt;chase&amp;gt; tag has a range specified for the chase to be completed (probably 2m again), so when the npc has caught the player, the chase behavior completion decay hits.  The chase behavior has  a specified completion decay of 100, but since chase was escalated artificially high by the 0 react, it is restored intead back to its original value.&lt;br /&gt;
&lt;br /&gt;
P-List: walk-50, turn-0, fight-160, chase-0&lt;br /&gt;
&lt;br /&gt;
So the npc stops chasing and resumes fighting the player immediately when he catches him.  Now the npc finally kills the player and the fight is over.  The “fight” behavior is still the highest one, so the npc keeps looking around for other enemies to fight, such as group members.  If none are found, his fight behavior keeps decreasing by 10 points per iteration.&lt;br /&gt;
P-List: walk-50, turn-0, fight-160, chase-0&lt;br /&gt;
P-List: walk-50, turn-0, fight-150, chase-0&lt;br /&gt;
P-List: walk-50, turn-0, fight-140, chase-0&lt;br /&gt;
P-List: walk-50, turn-0, fight-130, chase-0&lt;br /&gt;
And so on…&lt;br /&gt;
&lt;br /&gt;
Eventually, “walk” behavior becomes the most active again and the npc resumes his wandering of the forest.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The key concepts here are that the NPC constantly maintains a priority list of behaviors and a priority of list of enemies to attack.  &amp;lt;react&amp;gt; tags can affect behavior priority, hatelist priority or both.&lt;br /&gt;
&lt;br /&gt;
The interactions of events, behaviors and reactions can become very complex.  The npc can be interrupted by an attack while moving, turning or even chasing another player.  This priority structure was designed to allow for rich behavior interruption and resumption while having realistic reactions to world events and activities.  Hopefully, with the right scripts we can create very life-like npcs that are also efficient on networking and CPU, with emergent behaviors that stay challenging and interesting to players for a long time to come.&lt;br /&gt;
&lt;br /&gt;
== Behavior ==&lt;br /&gt;
{|&lt;br /&gt;
!Parameter&lt;br /&gt;
!Type&lt;br /&gt;
!Default&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|name&lt;br /&gt;
|string&lt;br /&gt;
|Mandatory&lt;br /&gt;
|The name of this behavior&lt;br /&gt;
|-&lt;br /&gt;
|loop&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set to true if this behavior should loop&lt;br /&gt;
|-&lt;br /&gt;
|decay&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|The decay rate of this behavior to apply when the behavior is the active one.&lt;br /&gt;
|-&lt;br /&gt;
|completion_decay&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|The decay to be applied when this behavior is done. -1 will be all of the current need.&lt;br /&gt;
|-&lt;br /&gt;
|growth&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|The growth rate of this behavior to apply when the behavior isn&#039;t the active one.&lt;br /&gt;
|-&lt;br /&gt;
|initial&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|The initial need for this behavior&lt;br /&gt;
|-&lt;br /&gt;
|when_dead&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set this to true if this behavior should be possible while dead. [[Behavior Operations#Resurrect_Operation|Resurrect Operation]] will need this.&lt;br /&gt;
|-&lt;br /&gt;
|resume&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set to true if this behavior should resume after an interrupt.&lt;br /&gt;
|-&lt;br /&gt;
|min&lt;br /&gt;
|float&lt;br /&gt;
|none&lt;br /&gt;
|Set this attribute if a min need limit should be applied to this behavior.&lt;br /&gt;
|-&lt;br /&gt;
|max&lt;br /&gt;
|float&lt;br /&gt;
|none&lt;br /&gt;
|Set this attribute if a max need limit should be applied to this behavior.&lt;br /&gt;
|-&lt;br /&gt;
|auto_memorize&lt;br /&gt;
|string,[...,string]&lt;br /&gt;
|none&lt;br /&gt;
|If set this npc will memorize all perceptions types passed without changing behavior.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
  Ex: &amp;lt;behavior name=&amp;quot;move&amp;quot; decay=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; initial=&amp;quot;80&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        ...&lt;br /&gt;
      &amp;lt;/behavior&amp;gt;&lt;br /&gt;
      &amp;lt;behavior name=&amp;quot;chase&amp;quot; decay=&amp;quot;1&amp;quot; completion_decay=&amp;quot;-1&amp;quot; growth=&amp;quot;0&amp;quot; initial=&amp;quot;0&amp;quot; &amp;gt;&lt;br /&gt;
        ...&lt;br /&gt;
      &amp;lt;/behavior&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reaction ==&lt;br /&gt;
{|&lt;br /&gt;
!Parameter&lt;br /&gt;
!Type&lt;br /&gt;
!Default&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|string&lt;br /&gt;
|&lt;br /&gt;
|The event to react to.&lt;br /&gt;
|-&lt;br /&gt;
|behavior&lt;br /&gt;
|string[,...,string]&lt;br /&gt;
|&lt;br /&gt;
|The set of behavior to influence if this reaction is triggered.&lt;br /&gt;
|-&lt;br /&gt;
|delta&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|Apply a delta value to the need of the affected behavior.&lt;br /&gt;
|-&lt;br /&gt;
|absolute&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|Apply a absolute value to the need of the affected behavior.&lt;br /&gt;
|-&lt;br /&gt;
|range&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|weight&lt;br /&gt;
|float&lt;br /&gt;
|0.0&lt;br /&gt;
|Passed to the perception when the reaction is accepted. Used to alter the HateList of the NPC.&lt;br /&gt;
|-&lt;br /&gt;
|faction_diff&lt;br /&gt;
|int&lt;br /&gt;
|0&lt;br /&gt;
|Used to match faction perceptions.&lt;br /&gt;
|-&lt;br /&gt;
|oper&lt;br /&gt;
|string&lt;br /&gt;
|&lt;br /&gt;
|The operator to use when comparing faction perceptions.&lt;br /&gt;
|-&lt;br /&gt;
|value&lt;br /&gt;
|string[,...,string]&lt;br /&gt;
|&lt;br /&gt;
|Used by some perceptions like time.&lt;br /&gt;
|-&lt;br /&gt;
|random&lt;br /&gt;
|integer[,...,integer]&lt;br /&gt;
|&lt;br /&gt;
|Used to add some random value to the value array.&lt;br /&gt;
|-&lt;br /&gt;
|type&lt;br /&gt;
|string&lt;br /&gt;
|&lt;br /&gt;
|The type is different for each perception. A &amp;quot;location sensed&amp;quot; will have the location type as the type.&lt;br /&gt;
|-&lt;br /&gt;
|active_only&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Only influence active behaviors&lt;br /&gt;
|-&lt;br /&gt;
|inactive_only&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Only influence inactive behaviors&lt;br /&gt;
|-&lt;br /&gt;
|when_dead&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Influence behaviors even if the npc is dead.&lt;br /&gt;
|-&lt;br /&gt;
|when_invisible&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set to true if an invisible NPC should accept this reaction.&lt;br /&gt;
|-&lt;br /&gt;
|when_invincible&lt;br /&gt;
|boolean&lt;br /&gt;
|false&lt;br /&gt;
|Set to true if an invincible NPC should accept this reaction.&lt;br /&gt;
|-&lt;br /&gt;
|only_interrupt&lt;br /&gt;
|string,[...,string]&lt;br /&gt;
|&lt;br /&gt;
|If set this event will only be accepted if it can interrupt one and active behavior from this list.&lt;br /&gt;
|-&lt;br /&gt;
|do_not_interrupt&lt;br /&gt;
|string,[...,string]&lt;br /&gt;
|&lt;br /&gt;
|Set this if this reaction should not interrupt some active behaviors.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The reaction can influence on a behaviors need either as GUARANTIED to execute(no delta or absolute attribute set), DELTA (delta attribute set), or ABSOLUTE ( absolute attribute set).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  Ex:  &amp;lt;react event=&amp;quot;damage&amp;quot;                behavior=&amp;quot;Fight&amp;quot; delta=&amp;quot;20&amp;quot; weight=&amp;quot;1&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  Ex:  &amp;lt;react event=&amp;quot;time&amp;quot; value=&amp;quot;16,0,,,&amp;quot;  random=&amp;quot;,5,,,&amp;quot; behavior=&amp;quot;GoHome&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example show a reaction to a time event that will occur between 1600 and 1605. This is archived due to the random property. Each of the values in value represents &amp;quot;Hour,Minute,Year,Month,Day&amp;quot;. Any parameter not&lt;br /&gt;
set will match every possible combination.&lt;br /&gt;
&lt;br /&gt;
  Ex:  &amp;lt;react event=&amp;quot;location sensed&amp;quot;    behavior=&amp;quot;ExploreLoc&amp;quot;    type=&amp;quot;mine&amp;quot; only_interrupt=&amp;quot;Explore&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example show a reaction to the location sensed perception where location of type mine will interrupt explore operation with the ExploreLoc behavior.&lt;br /&gt;
&lt;br /&gt;
== Perceptions ==&lt;br /&gt;
&lt;br /&gt;
Perceptions it the invisible mechanism that makes reactions act. There are several situations where perceptions are fired. Some are hard coded into the NPCClient. Some are fired as responses to other script elements and the name might be configurable. An example on this is the [[Behavior_Operations#Chase_Operation|Chase Operation]] where the perception name is configured through the operation.&lt;br /&gt;
&lt;br /&gt;
This section try to summarize some of the perceptions available. Though they might as well be documented at all or only through the senders.&lt;br /&gt;
&lt;br /&gt;
=== Events to react to ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Perception&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|collision&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|out of bounds&lt;br /&gt;
|Checks if the NPC is out of bounds of a region defined in sc_npc_definitions and set up in sc_locations &lt;br /&gt;
|-&lt;br /&gt;
|in bounds&lt;br /&gt;
|Checks if the NPC is in bounds of a region defined in sc_npc_definitions and set up in sc_locations &lt;br /&gt;
|-&lt;br /&gt;
|damage&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|attack&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|nearby&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|target out of range&lt;br /&gt;
|description&lt;br /&gt;
|-&lt;br /&gt;
|death&lt;br /&gt;
|description&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Faction Perceptions ===&lt;br /&gt;
&lt;br /&gt;
This is perception can be filtered on the faction standing between the NPC and the sender. By defining the oper in the&lt;br /&gt;
reaction the faction will be compared. Without the factions will not be compared.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute&lt;br /&gt;
!Values&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
|talk&lt;br /&gt;
|Talk preception fired when talked to&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|owner anyrange, owner sensed, owner nearby, owner adjacent&lt;br /&gt;
|Owner perceptions fired when owner is at different ranges(Will not get player perception if you are the owner).&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
|player anyrange, player sensed, player nearby, player adjacent&lt;br /&gt;
|Player perceptions fired when player is at different ranges.&lt;br /&gt;
|-&lt;br /&gt;
|faction_diff&lt;br /&gt;
|integer&lt;br /&gt;
|The faction value to compare&lt;br /&gt;
|-&lt;br /&gt;
|oper&lt;br /&gt;
|&amp;gt;,&amp;lt;&lt;br /&gt;
|React if grater than or react when less than. If no oper is defined, faction will not be compared.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Range&lt;br /&gt;
!Value&lt;br /&gt;
|-&lt;br /&gt;
|sensed&lt;br /&gt;
|&amp;lt;30&lt;br /&gt;
|-&lt;br /&gt;
|nearby&lt;br /&gt;
|&amp;lt;10&lt;br /&gt;
|-&lt;br /&gt;
|adjacent&lt;br /&gt;
|&amp;lt;4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
  Ex: &amp;lt;react event=&amp;quot;talk&amp;quot; faction_diff=&amp;quot;10&amp;quot; oper=&amp;quot;&amp;gt;&amp;quot; ... /&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
This example will only react to talk if the faction difference is more than +10 to the originator of the talk perception.&lt;br /&gt;
&lt;br /&gt;
  Ex: &amp;lt;react event=&amp;quot;player nearby&amp;quot; ... /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allways react when a player is nearby.&lt;br /&gt;
&lt;br /&gt;
=== Item Perceptions ===&lt;br /&gt;
&lt;br /&gt;
This perception is fired whenever a NPC moves into the nearby, adjacent, or sensed range from an item. In the nearby range the item is so close that it can be picked up.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute&lt;br /&gt;
!Values&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|item nearby, item adjacent, item sensed&lt;br /&gt;
|The different perception fired that nearby, adjacent, or sensed range.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Location Perception ===&lt;br /&gt;
&lt;br /&gt;
This perception is fired whenever a NPC moves into the sensed range of a location.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute&lt;br /&gt;
!Values&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|location perception&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|type&lt;br /&gt;
|&#039;&#039;string&#039;&#039;&lt;br /&gt;
|The location type name of the location sensed.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  Ex:  &amp;lt;react event=&amp;quot;location perception&amp;quot; type=&amp;quot;mine&amp;quot; ... /&amp;gt;&lt;br /&gt;
       &amp;lt;react event=&amp;quot;location perception&amp;quot; ... /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Time Perception ===&lt;br /&gt;
&lt;br /&gt;
This perception is fired every game minute. It allows react to trigger on any combination of game hours, minutes, years, month, days.&lt;br /&gt;
{|&lt;br /&gt;
!Attribute&lt;br /&gt;
!Values&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|event&lt;br /&gt;
|time&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|value&lt;br /&gt;
|hours,minutes,years,months,days&lt;br /&gt;
|Match 1200 at the 2nd month like this &amp;quot;12,00,,2,&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
   Ex: &amp;lt;react event=&amp;quot;time&amp;quot; value=&amp;quot;12,00,,2,&amp;quot; ... /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Engine documents]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_15-August_21&amp;diff=9110</id>
		<title>Zee August 15-August 21</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_15-August_21&amp;diff=9110"/>
		<updated>2011-08-22T00:47:00Z</updated>

		<summary type="html">&lt;p&gt;Zee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First days of this week I mostly read code regarding object spawning in the world. (due some family problems)&lt;br /&gt;
&lt;br /&gt;
At the end of the week I managed to get the building spawning on tribe request working. Also all standard behaviors are done, checked and should work.&lt;br /&gt;
&lt;br /&gt;
At the moment recipes manage all tribe movement and behavior and the tribe can achieve simple tasks. (it should easily achieve any task as long as the scripting functions are used correctly)&lt;br /&gt;
&lt;br /&gt;
This weekend I also changed the way recipes were managed by the tribe. Tribes now use a tree structure (RecipeTreeNode class) to store and prioritize their goals.&lt;br /&gt;
&lt;br /&gt;
Best wishes.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_15-August_21&amp;diff=9109</id>
		<title>Zee August 15-August 21</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_15-August_21&amp;diff=9109"/>
		<updated>2011-08-22T00:46:49Z</updated>

		<summary type="html">&lt;p&gt;Zee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First days of this week I mostly read code regarding object spawning in the world. (due some family problems)&lt;br /&gt;
&lt;br /&gt;
At the end of the week I managed to get the building spawning on tribe request working. Also all standard behaviors are done, checked and should work.&lt;br /&gt;
&lt;br /&gt;
At the moment recipes manage all tribe movement and behavior and the tribe can achieve simple tasks. (it should easily achieve any task as long as the scripting functions are used correctly)&lt;br /&gt;
&lt;br /&gt;
This weekend I also changed the way recipes were managed by the tribe. Tribes now use a tree structure (RecipeTreeNode class) to store and prioritize their goals.&lt;br /&gt;
&lt;br /&gt;
Best wishes.&lt;br /&gt;
&lt;br /&gt;
 :wq&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_15-August_21&amp;diff=9108</id>
		<title>Zee August 15-August 21</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_15-August_21&amp;diff=9108"/>
		<updated>2011-08-22T00:46:35Z</updated>

		<summary type="html">&lt;p&gt;Zee: Created page with &amp;#039;First days of this week I mostly read code regarding object spawning in the world. (due some family problems)  At the end of the week I managed to get the building spawning on tr…&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First days of this week I mostly read code regarding object spawning in the world. (due some family problems)&lt;br /&gt;
&lt;br /&gt;
At the end of the week I managed to get the building spawning on tribe request working. Also all standard behaviors are done, checked and should work.&lt;br /&gt;
&lt;br /&gt;
At the moment recipes manage all tribe movement and behavior and the tribe can achieve simple tasks. (it should easily achieve any task as long as the scripting functions are used correctly)&lt;br /&gt;
&lt;br /&gt;
This weekend I also changed the way recipes were managed by the tribe. Tribes now use a tree structure (RecipeTreeNode class) to store and prioritize their goals.&lt;br /&gt;
&lt;br /&gt;
Best wishes.&lt;br /&gt;
:wq&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9107</id>
		<title>GSoC weekly reports</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9107"/>
		<updated>2011-08-22T00:41:17Z</updated>

		<summary type="html">&lt;p&gt;Zee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
== May ==&lt;br /&gt;
&lt;br /&gt;
Request of weekly reports was sent out the 8th of June, anyway if you have any progress report for May, please post it here.&lt;br /&gt;
&lt;br /&gt;
[[Zhan 16-20]]&lt;br /&gt;
&lt;br /&gt;
== June 6-12 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 6-12]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 6-12]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== June 13-19 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 13-19]]&lt;br /&gt;
&lt;br /&gt;
== June 20-26 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 20-26]]&lt;br /&gt;
&lt;br /&gt;
== June 27-July 4 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
== July 5-11 ==&lt;br /&gt;
[[Landson July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 5-11]]&lt;br /&gt;
== July 12-18 ==&lt;br /&gt;
[[Landson July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 12-18]]&lt;br /&gt;
&lt;br /&gt;
== July 18-25 ==&lt;br /&gt;
[[Landson July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 18-25]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== July 25-31 ==&lt;br /&gt;
[[Zhan July 25-31]]&lt;br /&gt;
&lt;br /&gt;
[[Landson July 25-31]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 25-31]]&lt;br /&gt;
&lt;br /&gt;
Lucubro in vacation.&lt;br /&gt;
&lt;br /&gt;
== July 31-August 7 ==&lt;br /&gt;
[[Zee July 31-August 7]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 31-August 7]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 25-August 7]]&lt;br /&gt;
&lt;br /&gt;
Landson no report (see next week for summary).&lt;br /&gt;
&lt;br /&gt;
== August 8th - August 15 ==&lt;br /&gt;
[[Landson July 31-August 15]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro August 8-15]]&lt;br /&gt;
&lt;br /&gt;
[[Zee August 8-August 15]]&lt;br /&gt;
&lt;br /&gt;
== August 15 - August 21 ==&lt;br /&gt;
[[Zee August 15-August 21]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_8-August_15&amp;diff=9106</id>
		<title>Zee August 8-August 15</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_8-August_15&amp;diff=9106"/>
		<updated>2011-08-15T20:37:22Z</updated>

		<summary type="html">&lt;p&gt;Zee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Personally I think it was a good week. I&#039;ve studied the server - superclient connection a lot to see how actions are triggered.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve spent the time testing how the tribe behaves based on some simple target recipes (like... acquire 30 members... acquire 100 gold... etc)&lt;br /&gt;
&lt;br /&gt;
I noticed that the former system had the tribe dig automatically for it&#039;s wealth. I&#039;ve changed this and now the tribe explores for resources... and once it finds a mine it prospects it in order to see what&#039;s in it. (this is why I studied the network managers and added MSGTYPE_NPC_WORKDONE). Currently, the tribe explores and digs for whatever resource we signal in the recipes.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve made some tweaks in the NPC code and tribe code in order to attach buffers to each npc. I wanted npcs to have their own buffers in order to remember their targets while working. (E.G. : once they are sent mining, they store their mining place in the NPC class, so the tribe can use it&#039;s buffers to keep own data or assign other tasks to other npcs) For this I added some other attributes in npcOperations. I will signal them in the wiki when I update the documentation.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve added the CMD_SPAWN_BUILDING command. This will be used by the superclient to request a building from the server. I&#039;m working on it atm... probably a MSGTYPE_PERSIST_ITEM will be the response sent to all clients containing the new building. (item dropped on the ground).&lt;br /&gt;
As per the location of the buildings... I think I&#039;ll use the easy way for now... as in... pre-select the locations for buildings and signal them in recipes.&lt;br /&gt;
&lt;br /&gt;
PS: Various minor changes that I didn&#039;t note here can be found as comments on svn commits. They aren&#039;t as important on the long run though :)&lt;br /&gt;
&lt;br /&gt;
High regards,&lt;br /&gt;
Zee.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_8-August_15&amp;diff=9105</id>
		<title>Zee August 8-August 15</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Zee_August_8-August_15&amp;diff=9105"/>
		<updated>2011-08-15T20:36:16Z</updated>

		<summary type="html">&lt;p&gt;Zee: Created page with &amp;#039;Personally I think it was a good week. I&amp;#039;ve studied the server - superclient connection a lot to see how actions are triggered.  I&amp;#039;ve spent the time testing how the tribe behaves…&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Personally I think it was a good week. I&#039;ve studied the server - superclient connection a lot to see how actions are triggered.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve spent the time testing how the tribe behaves based on some simple target recipes (like... acquire 30 members... acquire 100 gold... etc)&lt;br /&gt;
&lt;br /&gt;
I noticed that the former system had the tribe dig automatically for it&#039;s wealth. I&#039;ve changed this and now the tribe explores for resources... and once it finds a mine it prospects it in order to see what&#039;s in it. (this is why I studied the network managers and added MSGTYPE_NPC_WORKDONE). Currently, the tribe explores and digs for whatever resource we signal in the recipes.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve made some tweaks in the NPC code and tribe code in order to attach buffers to each npc. I wanted npcs to have their own buffers in order to remember their targets while working. (E.G. : once they are sent mining, they store their mining place in the NPC class, so the tribe can use it&#039;s buffers to keep own data or assign other tasks to other npcs) For this I added some other attributes in npcOperations. I will signal them in the wiki when I update the documentation.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve added the CMD_SPAWN_BUILDING command. This will be used by the superclient to request a building from the server. I&#039;m working on it atm... probably a MSGTYPE_PERSIST_ITEM will be the response sent to all clients containing the new building. (item dropped on the ground).&lt;br /&gt;
As per the location of the buildings... I think I&#039;ll use the easy way for now... as in... pre-select the locations for buildings and signal them in recipes.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9104</id>
		<title>GSoC weekly reports</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9104"/>
		<updated>2011-08-15T20:27:28Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* August 8th - August 15 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
== May ==&lt;br /&gt;
&lt;br /&gt;
Request of weekly reports was sent out the 8th of June, anyway if you have any progress report for May, please post it here.&lt;br /&gt;
&lt;br /&gt;
[[Zhan 16-20]]&lt;br /&gt;
&lt;br /&gt;
== June 6-12 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 6-12]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 6-12]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== June 13-19 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 13-19]]&lt;br /&gt;
&lt;br /&gt;
== June 20-26 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 20-26]]&lt;br /&gt;
&lt;br /&gt;
== June 27-July 4 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
== July 5-11 ==&lt;br /&gt;
[[Landson July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 5-11]]&lt;br /&gt;
== July 12-18 ==&lt;br /&gt;
[[Landson July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 12-18]]&lt;br /&gt;
&lt;br /&gt;
== July 18-25 ==&lt;br /&gt;
[[Landson July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 18-25]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== July 25-31 ==&lt;br /&gt;
[[Zhan July 25-31]]&lt;br /&gt;
&lt;br /&gt;
[[Landson July 25-31]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 25-31]]&lt;br /&gt;
&lt;br /&gt;
Lucubro in vacation.&lt;br /&gt;
&lt;br /&gt;
== July 31-August 7 ==&lt;br /&gt;
[[Zee July 31-August 7]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 31-August 7]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 25-August 7]]&lt;br /&gt;
&lt;br /&gt;
Landson no report (see next week for summary).&lt;br /&gt;
&lt;br /&gt;
== August 8th - August 15 ==&lt;br /&gt;
[[Landson July 31-August 15]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro August 8-15]]&lt;br /&gt;
&lt;br /&gt;
[[Zee August 8-August 15]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9084</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9084"/>
		<updated>2011-08-10T12:00:15Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes which achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
*an array of Assets (see below)&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|sleepPeriod(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ diurnal, nocturnal, nosleep }&lt;br /&gt;
|decides when tribe members should go to sleep... if they should at all&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|trader(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item name&lt;br /&gt;
|requires a memory containing the position of another npc trading items of type x&lt;br /&gt;
|-&lt;br /&gt;
|memory(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a memory name&lt;br /&gt;
|requires a memory. Especially used when looking for resources... if no memory is available explore for it.&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mate()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members a &#039;tribe:breed&#039; perception&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|guard()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|Makes the previous selected NPCs guard the previous selected Location. (using select(x,y) and locateMemory(z))&lt;br /&gt;
|-&lt;br /&gt;
|trade(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the item/tria quantity given by the tribesman, y is the item/tria quantity given by the other npc&lt;br /&gt;
|Performs a trade between the tribesman and the npc.&lt;br /&gt;
|-&lt;br /&gt;
|wait(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a number of ticks&lt;br /&gt;
|sets the recipe on pause for the given csTicks. Useful when waiting for buildings to finish.&lt;br /&gt;
|-&lt;br /&gt;
|setBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe (string)recipeBuffer to the given value&lt;br /&gt;
|-&lt;br /&gt;
|setAmountBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe secondary buffer (recipeAmountBuffer) to the given value&lt;br /&gt;
|-&lt;br /&gt;
|addMember(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a member type&lt;br /&gt;
|adds a new member of type &#039;x&#039; to the tribe&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
More algorithm steps might be added.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Assets ==&lt;br /&gt;
&lt;br /&gt;
Assets are items and buildings that belong to the tribe. They are held in the &#039;assets&#039; array (which acts like a bank) in the tribal object.&lt;br /&gt;
&lt;br /&gt;
An Asset data structure contains the following:&lt;br /&gt;
*name&lt;br /&gt;
*item     - a gemNPCItem* that will hold how the item/building looks&lt;br /&gt;
*quantity - an int which will hold how many items of a kind the tribe has (used only for items)&lt;br /&gt;
*pos      - a csVector3 holding the position of the item (used only for buildings)&lt;br /&gt;
*building - a boolean value (flagged as true for building entries)&lt;br /&gt;
&lt;br /&gt;
I found that keeping positions &amp;amp; multiple entries for items would prove quite useless... and thought of a better practice to remove all tribal items from the world and keeping them as numbers.&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Zee_July_31-August_7&amp;diff=9079</id>
		<title>Zee July 31-August 7</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Zee_July_31-August_7&amp;diff=9079"/>
		<updated>2011-08-08T10:48:31Z</updated>

		<summary type="html">&lt;p&gt;Zee: Created page with &amp;#039;This week was pretty prolific.  I spent the time completing all the gaps left in the code, completing the function list for recipes and making them work. In detail: *coded all re…&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This week was pretty prolific.&lt;br /&gt;
&lt;br /&gt;
I spent the time completing all the gaps left in the code, completing the function list for recipes and making them work.&lt;br /&gt;
In detail:&lt;br /&gt;
*coded all requirements checks and added actions to do in case they are not met&lt;br /&gt;
*added tribe buffers and memory buffers to hold dynamic data between execution of functions, and dynamic data for the execution of behaviors&lt;br /&gt;
*added a preparser to allow the usage of buffers and certain variables (like REPRODUCTION_RESOURCE)&lt;br /&gt;
*added Assets (tribe buildings &amp;amp; items) and all the methods/mechanics to make it usable. (including sc_tribe_assets)&lt;br /&gt;
*added &#039;fireperc&#039; command in the npcclient for testing purposes.&lt;br /&gt;
*varios small changes and fixes :)&lt;br /&gt;
&lt;br /&gt;
Best wishes, Zee.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9078</id>
		<title>GSoC weekly reports</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9078"/>
		<updated>2011-08-08T10:38:52Z</updated>

		<summary type="html">&lt;p&gt;Zee: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
== May ==&lt;br /&gt;
&lt;br /&gt;
Request of weekly reports was sent out the 8th of June, anyway if you have any progress report for May, please post it here.&lt;br /&gt;
&lt;br /&gt;
[[Zhan 16-20]]&lt;br /&gt;
&lt;br /&gt;
== June 6-12 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 6-12]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 6-12]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== June 13-19 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 13-19]]&lt;br /&gt;
&lt;br /&gt;
== June 20-26 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 20-26]]&lt;br /&gt;
&lt;br /&gt;
== June 27-July 4 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
== July 5-11 ==&lt;br /&gt;
[[Landson July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 5-11]]&lt;br /&gt;
== July 12-18 ==&lt;br /&gt;
[[Landson July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 12-18]]&lt;br /&gt;
&lt;br /&gt;
== July 18-25 ==&lt;br /&gt;
[[Landson July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 18-25]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== July 25-31 ==&lt;br /&gt;
[[Zhan July 25-31]]&lt;br /&gt;
&lt;br /&gt;
[[Landson July 25-31]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 25-31]]&lt;br /&gt;
&lt;br /&gt;
== July 31-August 7 ==&lt;br /&gt;
[[Zee July 31-August 7]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9077</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9077"/>
		<updated>2011-08-07T14:40:08Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */ added mate() function&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes which achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
*an array of Assets (see below)&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|sleepPeriod(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ diurnal, nocturnal, nosleep }&lt;br /&gt;
|decides when tribe members should go to sleep... if they should at all&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|trader(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item name&lt;br /&gt;
|requires a memory containing the position of another npc trading items of type x&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mate()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members a &#039;tribe:breed&#039; perception&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|guard()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|Makes the previous selected NPCs guard the previous selected Location. (using select(x,y) and locateMemory(z))&lt;br /&gt;
|-&lt;br /&gt;
|trade(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the item/tria quantity given by the tribesman, y is the item/tria quantity given by the other npc&lt;br /&gt;
|Performs a trade between the tribesman and the npc.&lt;br /&gt;
|-&lt;br /&gt;
|wait(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a number of ticks&lt;br /&gt;
|sets the recipe on pause for the given csTicks. Useful when waiting for buildings to finish.&lt;br /&gt;
|-&lt;br /&gt;
|setBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe (string)recipeBuffer to the given value&lt;br /&gt;
|-&lt;br /&gt;
|setAmountBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe secondary buffer (recipeAmountBuffer) to the given value&lt;br /&gt;
|-&lt;br /&gt;
|addMember(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a member type&lt;br /&gt;
|adds a new member of type &#039;x&#039; to the tribe&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
More algorithm steps might be added.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Assets ==&lt;br /&gt;
&lt;br /&gt;
Assets are items and buildings that belong to the tribe. They are held in the &#039;assets&#039; array (which acts like a bank) in the tribal object.&lt;br /&gt;
&lt;br /&gt;
An Asset data structure contains the following:&lt;br /&gt;
*name&lt;br /&gt;
*item     - a gemNPCItem* that will hold how the item/building looks&lt;br /&gt;
*quantity - an int which will hold how many items of a kind the tribe has (used only for items)&lt;br /&gt;
*pos      - a csVector3 holding the position of the item (used only for buildings)&lt;br /&gt;
*building - a boolean value (flagged as true for building entries)&lt;br /&gt;
&lt;br /&gt;
I found that keeping positions &amp;amp; multiple entries for items would prove quite useless... and thought of a better practice to remove all tribal items from the world and keeping them as numbers.&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9074</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9074"/>
		<updated>2011-08-05T20:03:26Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes which achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
*an array of Assets (see below)&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|sleepPeriod(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ diurnal, nocturnal, nosleep }&lt;br /&gt;
|decides when tribe members should go to sleep... if they should at all&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|trader(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item name&lt;br /&gt;
|requires a memory containing the position of another npc trading items of type x&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|guard()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|Makes the previous selected NPCs guard the previous selected Location. (using select(x,y) and locateMemory(z))&lt;br /&gt;
|-&lt;br /&gt;
|trade(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the item/tria quantity given by the tribesman, y is the item/tria quantity given by the other npc&lt;br /&gt;
|Performs a trade between the tribesman and the npc.&lt;br /&gt;
|-&lt;br /&gt;
|wait(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a number of ticks&lt;br /&gt;
|sets the recipe on pause for the given csTicks. Useful when waiting for buildings to finish.&lt;br /&gt;
|-&lt;br /&gt;
|setBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe (string)recipeBuffer to the given value&lt;br /&gt;
|-&lt;br /&gt;
|setAmountBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe secondary buffer (recipeAmountBuffer) to the given value&lt;br /&gt;
|-&lt;br /&gt;
|addMember(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a member type&lt;br /&gt;
|adds a new member of type &#039;x&#039; to the tribe&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
More algorithm steps might be added.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Assets ==&lt;br /&gt;
&lt;br /&gt;
Assets are items and buildings that belong to the tribe. They are held in the &#039;assets&#039; array (which acts like a bank) in the tribal object.&lt;br /&gt;
&lt;br /&gt;
An Asset data structure contains the following:&lt;br /&gt;
*name&lt;br /&gt;
*item     - a gemNPCItem* that will hold how the item/building looks&lt;br /&gt;
*quantity - an int which will hold how many items of a kind the tribe has (used only for items)&lt;br /&gt;
*pos      - a csVector3 holding the position of the item (used only for buildings)&lt;br /&gt;
*building - a boolean value (flagged as true for building entries)&lt;br /&gt;
&lt;br /&gt;
I found that keeping positions &amp;amp; multiple entries for items would prove quite useless... and thought of a better practice to remove all tribal items from the world and keeping them as numbers.&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9073</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9073"/>
		<updated>2011-08-05T19:00:19Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes which achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
*an array of Assets (see below)&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|trader(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item name&lt;br /&gt;
|requires a memory containing the position of another npc trading items of type x&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|guard()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|Makes the previous selected NPCs guard the previous selected Location. (using select(x,y) and locateMemory(z))&lt;br /&gt;
|-&lt;br /&gt;
|trade(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the item/tria quantity given by the tribesman, y is the item/tria quantity given by the other npc&lt;br /&gt;
|Performs a trade between the tribesman and the npc.&lt;br /&gt;
|-&lt;br /&gt;
|wait(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a number of ticks&lt;br /&gt;
|sets the recipe on pause for the given csTicks. Useful when waiting for buildings to finish.&lt;br /&gt;
|-&lt;br /&gt;
|setBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe (string)recipeBuffer to the given value&lt;br /&gt;
|-&lt;br /&gt;
|setAmountBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe secondary buffer (recipeAmountBuffer) to the given value&lt;br /&gt;
|-&lt;br /&gt;
|addMember(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a member type&lt;br /&gt;
|adds a new member of type &#039;x&#039; to the tribe&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
More algorithm steps might be added.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Assets ==&lt;br /&gt;
&lt;br /&gt;
Assets are items and buildings that belong to the tribe. They are held in the &#039;assets&#039; array (which acts like a bank) in the tribal object.&lt;br /&gt;
&lt;br /&gt;
An Asset data structure contains the following:&lt;br /&gt;
*name&lt;br /&gt;
*item     - a gemNPCItem* that will hold how the item/building looks&lt;br /&gt;
*quantity - an int which will hold how many items of a kind the tribe has (used only for items)&lt;br /&gt;
*pos      - a csVector3 holding the position of the item (used only for buildings)&lt;br /&gt;
*building - a boolean value (flagged as true for building entries)&lt;br /&gt;
&lt;br /&gt;
I found that keeping positions &amp;amp; multiple entries for items would prove quite useless... and thought of a better practice to remove all tribal items from the world and keeping them as numbers.&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9071</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9071"/>
		<updated>2011-08-03T22:05:37Z</updated>

		<summary type="html">&lt;p&gt;Zee: added Assets information&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes which achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
*an array of Assets (see below)&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|trader(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item name&lt;br /&gt;
|requires a memory containing the position of another npc trading items of type x&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|guard()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|Makes the previous selected NPCs guard the previous selected Location. (using select(x,y) and locateMemory(z))&lt;br /&gt;
|-&lt;br /&gt;
|trade(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the item/tria quantity given by the tribesman, y is the item/tria quantity given by the other npc&lt;br /&gt;
|Performs a trade between the tribesman and the npc.&lt;br /&gt;
|-&lt;br /&gt;
|wait(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a number of ticks&lt;br /&gt;
|sets the recipe on pause for the given csTicks. Useful when waiting for buildings to finish.&lt;br /&gt;
|-&lt;br /&gt;
|setBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe (string)recipeBuffer to the given value&lt;br /&gt;
|-&lt;br /&gt;
|setAmountBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe secondary buffer (recipeAmountBuffer) to the given value&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
More algorithm steps might be added.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Assets ==&lt;br /&gt;
&lt;br /&gt;
Assets are items and buildings that belong to the tribe. They are held in the &#039;assets&#039; array (which acts like a bank) in the tribal object.&lt;br /&gt;
&lt;br /&gt;
An Asset data structure contains the following:&lt;br /&gt;
*name&lt;br /&gt;
*item     - a gemNPCItem* that will hold how the item/building looks&lt;br /&gt;
*quantity - an int which will hold how many items of a kind the tribe has (used only for items)&lt;br /&gt;
*pos      - a csVector3 holding the position of the item (used only for buildings)&lt;br /&gt;
*building - a boolean value (flagged as true for building entries)&lt;br /&gt;
&lt;br /&gt;
I found that keeping positions &amp;amp; multiple entries for items would prove quite useless... and thought of a better practice to remove all tribal items from the world and keeping them as numbers.&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9070</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9070"/>
		<updated>2011-08-03T21:57:37Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Tribal Object */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
*an array of Assets (see below)&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|trader(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item name&lt;br /&gt;
|requires a memory containing the position of another npc trading items of type x&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|guard()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|Makes the previous selected NPCs guard the previous selected Location. (using select(x,y) and locateMemory(z))&lt;br /&gt;
|-&lt;br /&gt;
|trade(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the item/tria quantity given by the tribesman, y is the item/tria quantity given by the other npc&lt;br /&gt;
|Performs a trade between the tribesman and the npc.&lt;br /&gt;
|-&lt;br /&gt;
|wait(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a number of ticks&lt;br /&gt;
|sets the recipe on pause for the given csTicks. Useful when waiting for buildings to finish.&lt;br /&gt;
|-&lt;br /&gt;
|setBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe (string)recipeBuffer to the given value&lt;br /&gt;
|-&lt;br /&gt;
|setAmountBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe secondary buffer (recipeAmountBuffer) to the given value&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
More algorithm steps might be added.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9066</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9066"/>
		<updated>2011-08-02T16:59:58Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|trader(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item name&lt;br /&gt;
|requires a memory containing the position of another npc trading items of type x&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|guard()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|Makes the previous selected NPCs guard the previous selected Location. (using select(x,y) and locateMemory(z))&lt;br /&gt;
|-&lt;br /&gt;
|trade(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the item/tria quantity given by the tribesman, y is the item/tria quantity given by the other npc&lt;br /&gt;
|Performs a trade between the tribesman and the npc.&lt;br /&gt;
|-&lt;br /&gt;
|wait(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a number of ticks&lt;br /&gt;
|sets the recipe on pause for the given csTicks. Useful when waiting for buildings to finish.&lt;br /&gt;
|-&lt;br /&gt;
|setBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe (string)recipeBuffer to the given value&lt;br /&gt;
|-&lt;br /&gt;
|setAmountBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe secondary buffer (recipeAmountBuffer) to the given value&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
More algorithm steps might be added.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9065</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9065"/>
		<updated>2011-08-02T16:59:16Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|trader(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item name&lt;br /&gt;
|requires a memory containing the position of another npc trading items of type x&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|guard()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|Makes the previous selected NPCs guard the previous selected Location. (using select(x,y) and locateMemory(z))&lt;br /&gt;
|-&lt;br /&gt;
|trade(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the item/tria quantity given by the tribesman, y is the item/tria quantity received by the other npc&lt;br /&gt;
|Performs a trade between the tribesman and the npc.&lt;br /&gt;
|-&lt;br /&gt;
|wait(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a number of ticks&lt;br /&gt;
|sets the recipe on pause for the given csTicks. Useful when waiting for buildings to finish.&lt;br /&gt;
|-&lt;br /&gt;
|setBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe (string)recipeBuffer to the given value&lt;br /&gt;
|-&lt;br /&gt;
|setAmountBuffer(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is any value&lt;br /&gt;
|sets the tribe secondary buffer (recipeAmountBuffer) to the given value&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
More algorithm steps might be added.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9064</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9064"/>
		<updated>2011-08-02T14:15:10Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|guard()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|Makes the previous selected NPCs guard the previous selected Location. (using select(x,y) and locateMemory(z))&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Much more algorithm steps will be added soon.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9062</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9062"/>
		<updated>2011-08-01T20:47:09Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* AbstractTribesman npctype */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Much more algorithm steps will be added soon.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds general behaviors and reactions.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9061</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9061"/>
		<updated>2011-08-01T20:45:26Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* AbstractTribesman npctype */ -- Added the npctype&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Much more algorithm steps will be added soon.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds behaviors only.&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;npctype name=&amp;quot;AbstractTribesman&amp;quot; vel=&amp;quot;2.5&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;do nothing&amp;quot; initial=&amp;quot;80&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;peace_meet&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/bow&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;aggressive_meet&amp;quot; completion_decay=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;coward_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;emote cmd=&amp;quot;/me flees in panic.&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;normal_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;target&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;united_attacked&amp;quot; decay=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;enemy&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;percept event=&amp;quot;tribesman attacked&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;melee seek_range=&amp;quot;20&amp;quot; melee_range=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Chase&amp;quot; initial=&amp;quot;0&amp;quot; growth=&amp;quot;0&amp;quot; decay=&amp;quot;1&amp;quot; complection_decay=&amp;quot;-1&amp;quot; &amp;gt;&lt;br /&gt;
      &amp;lt;chase type=&amp;quot;target&amp;quot; chase_range=&amp;quot;20&amp;quot; anim=&amp;quot;run&amp;quot; vel=&amp;quot;5&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToWork&amp;quot; loop=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeBuilding&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;moveto coords=&amp;quot;tribe:memory:activeLocation&amp;quot; anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Explore&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;waypoint&amp;quot; static=&amp;quot;no&amp;quot; random=&amp;quot;yes&amp;quot; range=&amp;quot;80&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;stand&amp;quot; duration=&amp;quot;3&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; static=&amp;quot;no&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;navigate anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GatherResource&amp;quot; completion_decay=&amp;quot;100&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:memory:activeResource&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;equip item=&amp;quot;Rock Pick&amp;quot; slot=&amp;quot;righthand&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;dig resource=&amp;quot;tribe:wealth&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;transfer item=&amp;quot;tribe:wealth&amp;quot; target=&amp;quot;tribe&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;share_memories /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;GoToSleep&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locate obj=&amp;quot;tribe:home&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Breed&amp;quot; completion_decay=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;invisible /&amp;gt;&lt;br /&gt;
      &amp;lt;wait anim=&amp;quot;sit&amp;quot; duration=&amp;quot;180&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;visible /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Resurrect&amp;quot; when_dead=&amp;quot;yes&amp;quot; completion_decay=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;resurrect /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;behavior name=&amp;quot;Guard&amp;quot; resume=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;locate obj=&amp;quot;tribe:memory:activeLocation&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;wander anim=&amp;quot;walk&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;circle anim=&amp;quot;walk&amp;quot; radius=&amp;quot;2&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/behavior&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:resurrect&amp;quot; behavior=&amp;quot;Resurrect&amp;quot; delta=&amp;quot;200&amp;quot; when_dead=&amp;quot;yes&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gotowork&amp;quot; behavior=&amp;quot;GoToWork&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:gather&amp;quot; behavior=&amp;quot;GatherResource&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:breed&amp;quot; behavior=&amp;quot;Breed&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;tribe:explore&amp;quot; behavior=&amp;quot;Explore&amp;quot; delta=&amp;quot;100&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of range&amp;quot; behavior=&amp;quot;Chase&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;react event=&amp;quot;target out of chase&amp;quot; behavior=&amp;quot;Chase&amp;quot; absolute=&amp;quot;0&amp;quot; only_interrupt=&amp;quot;chase&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/npctype&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Zee_July_25-31&amp;diff=9060</id>
		<title>Zee July 25-31</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Zee_July_25-31&amp;diff=9060"/>
		<updated>2011-08-01T20:43:31Z</updated>

		<summary type="html">&lt;p&gt;Zee: Created page with &amp;#039;I&amp;#039;ve been away for a week and I apologize for the delay on my arrival. Since I came back on friday I worked on making the Recipe Manager really work.  Now we have everything done…&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I&#039;ve been away for a week and I apologize for the delay on my arrival.&lt;br /&gt;
Since I came back on friday I worked on making the Recipe Manager really work.&lt;br /&gt;
&lt;br /&gt;
Now we have everything done on parsing requirements. (except the member types on which we have to agree... for now if we request 5 gatherers we&#039;ll get 5 npcs of any type)&lt;br /&gt;
&lt;br /&gt;
We also have all the functions working. The provisional list is posted on the wiki page... if you guys think we need extra functions or something please let me know.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve spent the last hours trying to populate the tribe_recipes database in order to have something to test on.&lt;br /&gt;
&lt;br /&gt;
I ask of you again... point me to someone who&#039;s good at making npctypes and behaviors... I didn&#039;t manage to have the npcs salute me on &amp;quot;player nearby&amp;quot; perception or retaliate on my attacks. (the examples in npcbehave.xml don&#039;t work ... ) -- I posted my work on &#039;AbstractTribesman&#039; on the wiki page [[Tribe Rework]].&lt;br /&gt;
&lt;br /&gt;
Best Wishes... Zee.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9059</id>
		<title>GSoC weekly reports</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9059"/>
		<updated>2011-08-01T20:37:42Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* July 25-31 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
== May ==&lt;br /&gt;
&lt;br /&gt;
Request of weekly reports was sent out the 8th of June, anyway if you have any progress report for May, please post it here.&lt;br /&gt;
&lt;br /&gt;
[[Zhan 16-20]]&lt;br /&gt;
&lt;br /&gt;
== June 6-12 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 6-12]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 6-12]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== June 13-19 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 13-19]]&lt;br /&gt;
&lt;br /&gt;
== June 20-26 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 20-26]]&lt;br /&gt;
&lt;br /&gt;
== June 27-July 4 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
== July 5-11 ==&lt;br /&gt;
[[Landson July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 5-11]]&lt;br /&gt;
== July 12-18 ==&lt;br /&gt;
[[Landson July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 12-18]]&lt;br /&gt;
&lt;br /&gt;
== July 18-25 ==&lt;br /&gt;
[[Landson July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 18-25]]&lt;br /&gt;
&lt;br /&gt;
== July 25-31 ==&lt;br /&gt;
[[Zhan July 25-31]]&lt;br /&gt;
&amp;lt;br&amp;gt;[[Landson July 25-31]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 25-31]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9058</id>
		<title>GSoC weekly reports</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9058"/>
		<updated>2011-08-01T20:37:29Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* July 25-31 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
== May ==&lt;br /&gt;
&lt;br /&gt;
Request of weekly reports was sent out the 8th of June, anyway if you have any progress report for May, please post it here.&lt;br /&gt;
&lt;br /&gt;
[[Zhan 16-20]]&lt;br /&gt;
&lt;br /&gt;
== June 6-12 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 6-12]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 6-12]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== June 13-19 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 13-19]]&lt;br /&gt;
&lt;br /&gt;
== June 20-26 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 20-26]]&lt;br /&gt;
&lt;br /&gt;
== June 27-July 4 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
== July 5-11 ==&lt;br /&gt;
[[Landson July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 5-11]]&lt;br /&gt;
== July 12-18 ==&lt;br /&gt;
[[Landson July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 12-18]]&lt;br /&gt;
&lt;br /&gt;
== July 18-25 ==&lt;br /&gt;
[[Landson July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 18-25]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 18-25]]&lt;br /&gt;
&lt;br /&gt;
== July 25-31 ==&lt;br /&gt;
[[Zhan July 25-31]]&lt;br /&gt;
&amp;lt;br&amp;gt;[[Landson July 25-31]]&lt;br /&gt;
[[Zee July 25-31]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9057</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9057"/>
		<updated>2011-08-01T20:13:15Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|select(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the type of npcs, y is the number&lt;br /&gt;
|Important: Selects the npcs on which to sends the following commands. It should always be used as a first command.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Much more algorithm steps will be added soon.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds behaviors only.&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9056</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9056"/>
		<updated>2011-08-01T17:44:20Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|loadRecipe(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|x is a recipe name&lt;br /&gt;
|loads a recipe at the initialization of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Much more algorithm steps will be added soon.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds behaviors only.&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9053</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9053"/>
		<updated>2011-08-01T17:11:59Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Provisional Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|addKnowledge(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a name of knowledge (e.g: Ironworks, Pottery)&lt;br /&gt;
|adds the knowledge in the tribe knowledge array&lt;br /&gt;
|-&lt;br /&gt;
|addBuilding(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the name of a building&lt;br /&gt;
|finds a good location for the building (in respect of it&#039;s size) and spawns it&lt;br /&gt;
|-&lt;br /&gt;
|attack()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to attack a previous selected location (to be used with locateMemory(enemy))&lt;br /&gt;
|-&lt;br /&gt;
|gather()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to gather a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|mine()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|sends all selected members to mine a previous selected resource&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Much more algorithm steps will be added soon.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds behaviors only.&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Zee_July_12-18&amp;diff=9033</id>
		<title>Zee July 12-18</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Zee_July_12-18&amp;diff=9033"/>
		<updated>2011-07-18T02:49:52Z</updated>

		<summary type="html">&lt;p&gt;Zee: Created page with &amp;#039;This week I took my time to work-out the way the tribal object manages the recipe priority list. By friday everything was done and I started working on parsing functions used in …&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This week I took my time to work-out the way the tribal object manages the recipe priority list. By friday everything was done and I started working on parsing functions used in recipes.&lt;br /&gt;
&lt;br /&gt;
I need some help from someone experienced in order to complete the &#039;AbstractTribesman&#039; npctype. The model I did seemed fine to me but it has some malfunctions :(.&lt;br /&gt;
&lt;br /&gt;
I would also like to know if you have any extra ideas on what the function list (available on [[Tribe Rework]]) should have to be a complete set of instructions.&lt;br /&gt;
&lt;br /&gt;
Next week I want plan to have a working recipe manager and tribe system in order to test basic things for a start.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9032</id>
		<title>GSoC weekly reports</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9032"/>
		<updated>2011-07-18T02:45:47Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* July 12-18 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
== May ==&lt;br /&gt;
&lt;br /&gt;
Request of weekly reports was sent out the 8th of June, anyway if you have any progress report for May, please post it here.&lt;br /&gt;
&lt;br /&gt;
[[Zhan 16-20]]&lt;br /&gt;
&lt;br /&gt;
== June 6-12 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 6-12]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 6-12]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== June 13-19 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 13-19]]&lt;br /&gt;
&lt;br /&gt;
== June 20-26 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 20-26]]&lt;br /&gt;
&lt;br /&gt;
== June 27-July 4 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
== July 5-11 ==&lt;br /&gt;
[[Landson July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 5-11]]&lt;br /&gt;
== July 12-18 ==&lt;br /&gt;
[[Landson July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan July 12-18]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 12-18]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9009</id>
		<title>GSoC weekly reports</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9009"/>
		<updated>2011-07-10T22:05:00Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* July 5-11 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
== May ==&lt;br /&gt;
&lt;br /&gt;
Request of weekly reports was sent out the 8th of June, anyway if you have any progress report for May, please post it here.&lt;br /&gt;
&lt;br /&gt;
[[Zhan 16-20]]&lt;br /&gt;
&lt;br /&gt;
== June 6-12 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 6-12]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 6-12]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== June 13-19 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 13-19]]&lt;br /&gt;
&lt;br /&gt;
== June 20-26 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 20-26]]&lt;br /&gt;
&lt;br /&gt;
== June 27-July 4 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
== July 5-11 ==&lt;br /&gt;
[[Landson July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zee July 5-11]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9008</id>
		<title>GSoC weekly reports</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9008"/>
		<updated>2011-07-10T22:04:43Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* July 5-11 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
== May ==&lt;br /&gt;
&lt;br /&gt;
Request of weekly reports was sent out the 8th of June, anyway if you have any progress report for May, please post it here.&lt;br /&gt;
&lt;br /&gt;
[[Zhan 16-20]]&lt;br /&gt;
&lt;br /&gt;
== June 6-12 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 6-12]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 6-12]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== June 13-19 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 13-19]]&lt;br /&gt;
&lt;br /&gt;
== June 20-26 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 20-26]]&lt;br /&gt;
&lt;br /&gt;
== June 27-July 4 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
== July 5-11 ==&lt;br /&gt;
[[Landson July 5-11]]&lt;br /&gt;
&lt;br /&gt;
[[Zee_July_5-11]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9007</id>
		<title>GSoC weekly reports</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=GSoC_weekly_reports&amp;diff=9007"/>
		<updated>2011-07-10T22:04:35Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* July 5-11 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
== May ==&lt;br /&gt;
&lt;br /&gt;
Request of weekly reports was sent out the 8th of June, anyway if you have any progress report for May, please post it here.&lt;br /&gt;
&lt;br /&gt;
[[Zhan 16-20]]&lt;br /&gt;
&lt;br /&gt;
== June 6-12 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 6-12]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 6-12]]&lt;br /&gt;
&lt;br /&gt;
Zee no report.&lt;br /&gt;
&lt;br /&gt;
== June 13-19 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 13-19]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 13-19]]&lt;br /&gt;
&lt;br /&gt;
== June 20-26 ==&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Landson June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 20-26]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 20-26]]&lt;br /&gt;
&lt;br /&gt;
== June 27-July 4 ==&lt;br /&gt;
&lt;br /&gt;
[[Landson June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Lucubro June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zee June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
[[Zhan June 27-July 4]]&lt;br /&gt;
&lt;br /&gt;
== July 5-11 ==&lt;br /&gt;
[[Landson July 5-11]]&lt;br /&gt;
[[Zee_July_5-11]]&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Zee_July_5-11&amp;diff=9006</id>
		<title>Zee July 5-11</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Zee_July_5-11&amp;diff=9006"/>
		<updated>2011-07-10T22:04:17Z</updated>

		<summary type="html">&lt;p&gt;Zee: Created page with &amp;#039;*This week I finished all the database work required. (built all dbs &amp;amp; methods for loading &amp;amp; saving data) *Designed the plan presented on wiki. I personally think it fits all the…&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*This week I finished all the database work required. (built all dbs &amp;amp; methods for loading &amp;amp; saving data)&lt;br /&gt;
*Designed the plan presented on wiki. I personally think it fits all the tribe requirements and it will be the final version of the implementation.&lt;br /&gt;
*Wrote the &#039;AbstractTribesman&#039; npctype&lt;br /&gt;
*Made the methods for parsing db information regarding scripting functions for recipes&lt;br /&gt;
*Made a provisional list of functions&lt;br /&gt;
*Most of the lesser things implemented in Recipe &amp;amp; RecipeManager are noted on svn commits &amp;amp; wiki page.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9005</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9005"/>
		<updated>2011-07-09T17:08:41Z</updated>

		<summary type="html">&lt;p&gt;Zee: updated&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
*Unique Recipe: recipe which can be executed only once. Like recipes to gain a knowledge, or build unique buildings.&lt;br /&gt;
*Persistent Recipe: recipe which never ends. Usually, these recipes will contain tribe information or goals which tribe will follow forever.&lt;br /&gt;
&lt;br /&gt;
A recipe object holds all details regarding the process of doing tasks.&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*flag to signal a unique recipe&lt;br /&gt;
*flag to signal a persistent recipe&lt;br /&gt;
*a requirement data structure which flags it&#039;s name, type and number of entitites required&lt;br /&gt;
*csStringArray for holding algorithm steps&lt;br /&gt;
*csArray for holding requirements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recipe Manager&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It holds:&lt;br /&gt;
*a list of enrolled tribes and a tribeData structure for each of them&lt;br /&gt;
*a list of recipes loaded&lt;br /&gt;
&lt;br /&gt;
Main operations the Recipe Manager does are explained above in the &#039;idea&#039; tab.&lt;br /&gt;
&lt;br /&gt;
It&#039;s in development how the recipe manager should track recipes. I&#039;ll add more details as soon as I got a good picture of it.&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Added a column to hold the tribal recipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_recipes table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
*Persistent&lt;br /&gt;
*Uniqueness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(hoilme);alterResource(coal,1)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sc_tribe_knowledge table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It keeps the knowledge gained by the tribe.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!tribe_id&lt;br /&gt;
!knowledge&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Leatherwork&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mineworks&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Provisional Functions ==&lt;br /&gt;
&lt;br /&gt;
Below is a list of functions which will be used to script recipes. Please note that this list is provisional. It will become final as soon as we have a solid list which allows us to do anything tribe-related.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!function&lt;br /&gt;
!type&lt;br /&gt;
!arguments&lt;br /&gt;
!effect&lt;br /&gt;
|-&lt;br /&gt;
|brain(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ civilised, savage, inhuman }&lt;br /&gt;
|decides the advancement of this tribe&lt;br /&gt;
|-&lt;br /&gt;
|aggressivity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ warlike, neutral, peaceful }&lt;br /&gt;
|decides how tribe members will react to entities coming near them&lt;br /&gt;
|-&lt;br /&gt;
|growth(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ expansionist, normal, conservatory }&lt;br /&gt;
|decides the expansion rate of the tribe&lt;br /&gt;
|-&lt;br /&gt;
|unity(x)&lt;br /&gt;
|tribe info&lt;br /&gt;
|{ organised, normal, cowards }&lt;br /&gt;
|decides how members will react if a fellow is attacked&lt;br /&gt;
|-&lt;br /&gt;
|tribesman(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a tribe member type, y is a number&lt;br /&gt;
|used by recipes to require able-to-work tribesman&lt;br /&gt;
|-&lt;br /&gt;
|resource(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a resource type, y is a number&lt;br /&gt;
|used by recipes to require an amount of resources&lt;br /&gt;
|-&lt;br /&gt;
|knowledge(x)&lt;br /&gt;
|requirement&lt;br /&gt;
|name of knowledge (knowledges discussed above)&lt;br /&gt;
|requires a knowledge&lt;br /&gt;
|-&lt;br /&gt;
|item(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is an item&#039;s name, y is the number of items&lt;br /&gt;
|requires items&lt;br /&gt;
|-&lt;br /&gt;
|recipe(x,y)&lt;br /&gt;
|requirement&lt;br /&gt;
|x is a recipe&#039;s name, y is the number of recipes&lt;br /&gt;
|require a recipe&lt;br /&gt;
|-&lt;br /&gt;
|alterResource(x,y)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is the resources name, y is the value to alter with&lt;br /&gt;
| Pretty self-explaining :D&lt;br /&gt;
|-&lt;br /&gt;
|loadLocation(x,y,z)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x,y,z are float numbers&lt;br /&gt;
|loads this location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|go()&lt;br /&gt;
|algorithm step&lt;br /&gt;
|none&lt;br /&gt;
|makes the npcs go to tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateMemory(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a memory&#039;s name&lt;br /&gt;
|loads the memory&#039;s location into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|locateResource(x)&lt;br /&gt;
|algorithm step&lt;br /&gt;
|x is a resource name&lt;br /&gt;
|loads the nearest resource of this type into tribe:memory:activeLocation&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Much more algorithm steps will be added soon.&lt;br /&gt;
&lt;br /&gt;
== AbstractTribesman npctype ==&lt;br /&gt;
&lt;br /&gt;
This npctype is a parent for all npctypes tribe members will have. It holds behaviors only.&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9004</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9004"/>
		<updated>2011-07-09T16:15:48Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Tribal Object */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
The tribal object will suffer some changes in order to support the above-mentioned capabilities:&lt;br /&gt;
*a knowledge array of strings: it contains only the name of the knowledge received by the tribe from completing recipes. They act more as tokens to prove completion. They are needed because recipes may require knowledge. (E.g.: if we want our tribe to build axes for it&#039;s warriors, we need the ironworks knowledge)&lt;br /&gt;
*an array of Recipe pointers which acts more as a priority queue for keeping recipes. Initially, only the tribal recipe will be there. After initialization, persistent recipes (which will never expire) will be pushed there and act as goals for the tribe. Based on the goals, normal recipes will be pushed there... and if requirements are not met... recipes to meet the requirements... and the list can go on forever.&lt;br /&gt;
*some memory entries which act as registers for sending data to tribe members. (E.g.: the memory named activeLocation, in which the tribal object will place location data for the tribe members to locateOp on them... as the place of the new building, or the place of a resource, or the place of a nearby tribe) Using this we can load data in the register, and fire a reaction to send members to work on &amp;quot;tribe:memory:activeLocation&amp;quot;, for example.&lt;br /&gt;
&lt;br /&gt;
==Parser Class==&lt;br /&gt;
&lt;br /&gt;
Will act only as a translator from basic csStrings to NPCTypes based on rules written in the database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Creating the NPCType&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Currently, the NPCs behave based on NPCTypes declared in &#039;&#039;data/npcbehave.xml&#039;&#039;. ( [[http://planeshift.ezpcusa.com/pswiki/index.php?title=NPC_Types]] )&lt;br /&gt;
&lt;br /&gt;
My idea was to dynamically generate these scripts (containing behaviors and reactions) on run-time, based on all information the parser class has on the tribe. (rules on generation can be added, deleted, altered at any-time without interfering with anything else but this class).&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
This class will hold links to all the tribes and recipes loaded in-game. Besides, it needs to keep track to all actions done by the tribe regarding the recipes.&lt;br /&gt;
&lt;br /&gt;
More info will be added.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_need table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain only the initial recipes id and the tribe id they are assigned to.&lt;br /&gt;
&lt;br /&gt;
Of course, on npcclient&#039;s shutdown... the current state can be written here.&lt;br /&gt;
&lt;br /&gt;
Much like:&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Counter&lt;br /&gt;
!tribe_id&lt;br /&gt;
!recipe_id&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 10&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 0&lt;br /&gt;
| 12&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| 1&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;recipe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(home);alterResource(coal,1)&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;correspondence table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The correspondence table should contain the matches between the basic algorithm functions and the operations needed to be done.&lt;br /&gt;
&lt;br /&gt;
The requirements will only check if certain npcs, items, recipes exist. They don&#039;t need a database.&lt;br /&gt;
&lt;br /&gt;
Functions in the algorithm section will be described by a succession of operations from [[Behavior Operations|here]].&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!function&lt;br /&gt;
!operation&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|equip&lt;br /&gt;
|EquipOp&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|dig&lt;br /&gt;
|DigOp&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|goTo&lt;br /&gt;
|MoveTo&lt;br /&gt;
|}&lt;br /&gt;
Note: Special tribe operations like &amp;quot;selectLocation, selectMemory, alterResource&amp;quot; might be hardcoded.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
	<entry>
		<id>https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9003</id>
		<title>Tribe Rework</title>
		<link rel="alternate" type="text/html" href="https://planeshift.top-ix.org//pswiki/index.php?title=Tribe_Rework&amp;diff=9003"/>
		<updated>2011-07-09T15:42:59Z</updated>

		<summary type="html">&lt;p&gt;Zee: /* Idea */  improved and updated&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Idea==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For this system to work, an npctype named &amp;quot;AbstractTribesman&amp;quot; needs to be declared in &#039;data/npcbehave.xml&#039;.&lt;br /&gt;
&lt;br /&gt;
The functioning of the tribe system is based on the following steps:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #1 (Loading Stuff)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed only once, on NPCClient&#039;s startup. No further interrogation on the database should be done)&lt;br /&gt;
&lt;br /&gt;
On NPCClient&#039;s startup everything is loaded into the classes.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager loads all available recipes from mysql:&#039;tribe_recipes&#039;.&lt;br /&gt;
&lt;br /&gt;
During load, the Recipe Manager parses the requirements and keeps them in the Recipe Class. (Recipe::requirements&amp;lt;Recipe::Requirement&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object receives all the information regarding the tribe:&lt;br /&gt;
*resources from mysql:&#039;sc_tribe_resources&#039;&lt;br /&gt;
*memories from mysql:&#039;sc_tribe_memories&#039;&lt;br /&gt;
*knowledge from mysql:&#039;sc_tribe_knowledge&#039;&lt;br /&gt;
*basic tribe information from mysql:&#039;tribes&#039; (including the ID of the tribal recipe, more details below)&lt;br /&gt;
*npc&#039;s are loaded by the psNPCClient and assigned to the tribe&lt;br /&gt;
&lt;br /&gt;
Further on, each Tribal Object is linked to in the Recipe Manager. (a pointer is sent and loaded into a csArray)&lt;br /&gt;
For each tribe loaded, the Recipe Manager does the following:&lt;br /&gt;
* assembles a data structure named &#039;TribeData&#039;&lt;br /&gt;
* links the tribal recipe belonging to this tribe to &#039;TribeData&#039;&lt;br /&gt;
* parses the information in the tribal recipe and assign the stats to csStrings in &#039;TribeData&#039;&lt;br /&gt;
* computes a tribal npctype having as parent the &#039;AbstractTribesman&#039; npctype. The difference is done by adding reactions to whatever the tribe reacts to. (attacking any player nearby or simply greeting them, sleeping at day or at night, etc)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #2 (RunTime)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed once on startup and each time a recipe is completed)&lt;br /&gt;
&lt;br /&gt;
The Tribal Object selects the top recipe which needs execution and sends it to the Recipe Manager.&lt;br /&gt;
&lt;br /&gt;
The Recipe Manager parses the contents of the recipe:&lt;br /&gt;
*checks for requirements. If requirements are met it proceeds with parsing the algorithm (see step #3). If requirements are not met, it pushes the Recipes with achieves the requirement on top of the tribe&#039;s recipe list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step #3 (Recipe&#039;s Algorithm)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
(executed for each step the algorithm has, each time a recipe needs execution)&lt;br /&gt;
&lt;br /&gt;
The Recipe has an algorithm stored as a csArray&amp;lt;csString&amp;gt;. When an algorithm needs an execution, the Recipe Manager takes each string and parses it. Depending on the rules we set, the Recipe Manager will tell the tribal object which perceptions to fire on their npcs.&lt;br /&gt;
&lt;br /&gt;
(E.g.: If the recipe&#039;s algorithm require us to send 10 workers to build a town hall, the tribal object will be told to fire a &amp;quot;go to work&amp;quot; perception on 10 worker tribesman)&lt;br /&gt;
&lt;br /&gt;
==Tribal Object==&lt;br /&gt;
&lt;br /&gt;
Much of the Tribe object needs re-done in order to apply this.&lt;br /&gt;
&lt;br /&gt;
* The NeedList needs to be a set of persistent Recipes (recipes that never end). These reflect the tribe unique attributes and targets.&lt;br /&gt;
&lt;br /&gt;
Note: It is different from the current concept of Needs. I consider the tribe needs should be uniquely assigned to Tribes only, not to individuals. Members should have no independent Needs, but instead be fully controlled by the Tribal Object by assigning different NPCTypes in respect of the tribe&#039;s targets.&lt;br /&gt;
&lt;br /&gt;
* Methods to communicate with the Parser Class and the Recipe Manager need to be added.&lt;br /&gt;
* A method to load tribe initial needs.&lt;br /&gt;
* Tribe needs can be held like an array of ints (representing the IDs of the recipes)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Parser Class==&lt;br /&gt;
&lt;br /&gt;
Will act only as a translator from basic csStrings to NPCTypes based on rules written in the database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Creating the NPCType&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Currently, the NPCs behave based on NPCTypes declared in &#039;&#039;data/npcbehave.xml&#039;&#039;. ( [[http://planeshift.ezpcusa.com/pswiki/index.php?title=NPC_Types]] )&lt;br /&gt;
&lt;br /&gt;
My idea was to dynamically generate these scripts (containing behaviors and reactions) on run-time, based on all information the parser class has on the tribe. (rules on generation can be added, deleted, altered at any-time without interfering with anything else but this class).&lt;br /&gt;
&lt;br /&gt;
==Recipe Manager==&lt;br /&gt;
&lt;br /&gt;
This class will hold links to all the tribes and recipes loaded in-game. Besides, it needs to keep track to all actions done by the tribe regarding the recipes.&lt;br /&gt;
&lt;br /&gt;
More info will be added.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
&lt;br /&gt;
The database needs to suffer some changes for this to work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;tribe_need table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain only the initial recipes id and the tribe id they are assigned to.&lt;br /&gt;
&lt;br /&gt;
Of course, on npcclient&#039;s shutdown... the current state can be written here.&lt;br /&gt;
&lt;br /&gt;
Much like:&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!Counter&lt;br /&gt;
!tribe_id&lt;br /&gt;
!recipe_id&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 0&lt;br /&gt;
| 10&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 0&lt;br /&gt;
| 12&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| 1&lt;br /&gt;
| 10&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;recipe table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It will contain all the recipes described by:&lt;br /&gt;
*ID&lt;br /&gt;
*Recipe Name&lt;br /&gt;
*Requirement Script&lt;br /&gt;
*Algorithm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!ID&lt;br /&gt;
!Name&lt;br /&gt;
!Requirement&lt;br /&gt;
!Algorithm&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| &amp;quot;Mine Coal&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(gatherer,1);item(pickaxe,1);&amp;quot;&lt;br /&gt;
| &amp;quot;goToMemory(coal);equip(pickaxe);dig;goTo(home);alterResource(coal,1)&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| &amp;quot;Build Well&amp;quot;&lt;br /&gt;
| &amp;quot;tribesman(builder,3);item(shovel,3);&amp;quot;&lt;br /&gt;
| &amp;quot;selectLocation(x,y,z);goTo(x,y,z);alterResource(food,-1);dig;alterResource(food,-2);addBuilding(well)&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;correspondence table&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The correspondence table should contain the matches between the basic algorithm functions and the operations needed to be done.&lt;br /&gt;
&lt;br /&gt;
The requirements will only check if certain npcs, items, recipes exist. They don&#039;t need a database.&lt;br /&gt;
&lt;br /&gt;
Functions in the algorithm section will be described by a succession of operations from [[Behavior Operations|here]].&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
!id&lt;br /&gt;
!function&lt;br /&gt;
!operation&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|equip&lt;br /&gt;
|EquipOp&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|dig&lt;br /&gt;
|DigOp&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|goTo&lt;br /&gt;
|MoveTo&lt;br /&gt;
|}&lt;br /&gt;
Note: Special tribe operations like &amp;quot;selectLocation, selectMemory, alterResource&amp;quot; might be hardcoded.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pros &amp;amp; Cons ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Pros &#039;&#039;&#039; &lt;br /&gt;
* It won&#039;t use any other data sources besides the sql database&lt;br /&gt;
* Independent pieces can be altered without the need to change the whole system. Adding moods will only affect the Parser Class that will slightly change the behavior before assembling and sending to the Tribal Object.&lt;br /&gt;
* There&#039;s no need to change the code in order to add or change tribes.&lt;br /&gt;
* The parser class can assemble NPCTypes for regular non-tribe npcs too.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Cons &#039;&#039;&#039;&lt;br /&gt;
* It will put a higher load on the NPCClient. I&#039;m not to good at predicting but... it shouldn&#039;t make it &amp;quot;a piece of 20tons rock&amp;quot; :).&lt;br /&gt;
* For the start... I might be needed to assembly the NPCType and send it as an xml IDocumentNode so I can use the already-made API there.&lt;br /&gt;
&lt;br /&gt;
== Notes == &lt;br /&gt;
&lt;br /&gt;
* It would be great if MathScript could be used for the tasks above. Please let me know if it&#039;s possible. I like to avoid reinventing the wheel.&lt;br /&gt;
* Awaiting the green light.&lt;/div&gt;</summary>
		<author><name>Zee</name></author>
	</entry>
</feed>