Tribe Design: Difference between revisions

From PSwiki
Jump to navigation Jump to search
Zee (talk | contribs)
Zee (talk | contribs)
Line 132: Line 132:
== Tribe day-to-day life ==
== Tribe day-to-day life ==


=== Behaviour ===
Tribe members are normal NPCs. They all expand a base NPCType called 'AbstractTribesman', on which each tribe adds it'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 'AbstractTribesman' 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)
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.


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:
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.
 
* tribe:explore
* tribe:dig
* tribe:reproduce (should result in a reproduce op).
* tribe:resurrect
* tribe:guard
* Or anything else
 
=== Reproduction ===
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.
 
=== Resurrection ===
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.
 
=== Resources ===
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 ''tribe:harvest'' 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.
 
=== Locations ===
The tribe:resource and tribe:home locations can be used with tribe members. For example in the [[Behavior_Operations#Locate_Operation|Locate Operation]].


== Tribe death ==
== Tribe death ==

Revision as of 21:20, 18 September 2011

Tribe Design

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.

Classes

Members

Tribe members (both dead & 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 & entityManager classes) and the npcclient class are responsable.

Tribe members can have different types. (Discussion needed about tribe types)

Tribe members are being kept in the 'tribe_members' mysql table.

Resources

A resource is kept in a data structure (Tribe::Resource) containing it's name, nick and quantity. The tribe class has methods for adding, modifying, storing and completely deleting resources.

Resources are being kept in the 'sc_tribe_resources' mysql table.

Memories

A memory is a location of some importance to the tribe. (E.g. a mine, a field, an enemy, etc)

A memory is kept in a data structure (Tribe::Memory) containing it's location (sector & coords), it's name and a link to an NPC (which is NULL if the memory is public to all tribe members, or != NULL if it's private to a tribe member). The tribe object has methods to add, store, modify and search memories.

Tribe members also have a memory slot for keeping it's current task location. (see bufferMemory attribute of NPC class).

Tribe memories are being kept in the 'sc_tribe_memories' mysql table.

Assets

Assets are belongings of the tribe. They can represent buildings, items or spots to be built in the future.

An asset is represented by a data structure (Tribe::Asset) containing it's location (sector & coords), it's name, it's quantity (relevant just for items) and it'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)

Tribe assets are being kept in the 'sc_tribe_assets' mysql table.

Knowledge

Knowledge represents the information the tribe has gathered and the technologies they can use. (E.g. Ironworks, pottery, horseback riding, alphabet, math, etc)

Technically, they are just strings used as tokens to prove the tribe has acquired knowledge or not.

Knowledge is kept in an array of strings.

Tribe knowledge is being kept in the 'sc_tribe_knowledge' mysql table.

Recipe Tree Node

This class represents a node of the recipe tree describing the tribe current tasks. Each recipe tree node contains a link to it'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).

RecipeTreeNodes are not being stored in any database. They are just used during runtime as an AI for tribes.

Recipe

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).

Recipes are being stored in the 'tribe_recipes' mysql table.

Sequences

Advance Sequence

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.

Diagrams error (with plantuml command): Error line 8 in file: /tmp/diagrams_inc2c3ccefa0e9.plantuml Some diagram description contains errors

Setting up tribes

There are 3 main database tables that need to be populated.

  • tribes
    • Each row represents one tribe, which must have a home position/sector and a radius in which to resurrect dead members.
    • max_size sets the maximum number of members.
    • 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.
    • reproduction_cost is the amount of resources required to reproduce.
    • tribal_recipe loads the initial recipe that sets tribe traits and loads tribe goals (recipes)
  • tribe_members
    • Each row is an association between a PID (on the server side) and a tribe.
  • tribe_recipes
    • 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.

Additionally, tables for extra tribe info need to be created:

  • sc_tribe_assets
  • sc_tribe_knowledge
  • sc_tribe_memories
  • sc_tribe_resources

Tribe day-to-day life

Tribe members are normal NPCs. They all expand a base NPCType called 'AbstractTribesman', on which each tribe adds it's own particularities (e.g. when to go to sleep, what to do when they meet a stranger, etc). Read more on NPCTypes. The 'AbstractTribesman' 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)

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.

Tribe death

When all the members die, then a member will be resurrected if there are 10*reproduction_cost resources available.