Tribe Design
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): Jul 18, 2025 8:48:18 PM java.util.prefs.FileSystemPreferences$1 run WARNING: Couldn't create user preferences directory. User preferences are unusable. Jul 18, 2025 8:48:18 PM java.util.prefs.FileSystemPreferences$1 run WARNING: java.io.IOException: No such file or directory Error line 8 in file: /tmp/diagrams_in20eda7c0ccfb.plantuml Some diagram description contains errors Jul 18, 2025 8:48:20 PM java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode WARNING: Could not lock User prefs. Unix error code 2. Jul 18, 2025 8:48:20 PM java.util.prefs.FileSystemPreferences syncWorld WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
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.