Civilization 7 Behavior Tree System Architecture

notque

Artificially Intelligent
Joined
Nov 13, 2005
Messages
2,165
Civilization 7 Behavior Tree System Architecture

Core database tables handle tree definition, node configuration, and data management. Direct and clean reference system.

Base Structure​

BehaviorTree​


Essential starting point. No tree exists without this.
  • TreeName: Primary key
  • Must exist before any node references
  • Handles trigger connections

Key Point: Always register tree first.

BehaviorTreeNode​


Main tree structure. Heavy integration with NodeDefinition and TreeData.
  • TreeName: Links to base tree
  • NodeId: Sequential ordering
  • JumpTo: Flow control, defaults 0
  • NodeType: Links to definition
  • PrimaryKey: Unique identifier

Flow Rule: JumpTo values must align with existing NodeIds.

TreeData​


Node configuration layer. Highly flexible, deeply integrated.
  • DefnId: Links to NodeDataDefinition
  • NodeId: References BehaviorTreeNode
  • Tag/DefaultData: Core configuration
  • ParentTag: Data flow control
  • UniqueId: System tracking

Critical: Every node needs matching TreeData entries.

Supporting Architecture​


DataType System​


Foundational type management.
  • TypeName: String identifier
  • DataId: Internal reference

Rule: Type mismatches break nodes silently.

NodeDataDefinition​


Configuration requirements manager.
  • Links NodeType to DataType
  • Controls required fields
  • Manages data flow direction
  • Handles editor behavior

Key Point: Check Required and RequiredGroup flags.

ShapeDefinition​


Node structure control.
  • Sets child limits
  • Enforces tree shape
  • Controls node relationships

Core Rule: Respect MinChildren/MaxChildren.

NodeDefinition​


Behavior definition center.
  • NodeType primary key
  • Links to ShapeDefinition
  • Provides base description

Critical: New nodes need NodeDefinition entries.

Practical Implementation​


Tree Building Steps​

  1. Register in BehaviorTree
  2. Create node structure
  3. Add required TreeData
  4. Validate references

Error Prevention​

  • Check TreeName consistency
  • Verify NodeId sequence
  • Validate all references
  • Test data flow

Performance Notes​

  • Minimize JumpTo usage
  • Keep trees shallow
  • Clean up unused nodes
  • Monitor data chains

Real Talk: Complex trees need rigorous testing. Small changes ripple hard.


End Point: System's robust but unforgiving. Test thoroughly.
 
Last edited:
Diagram of Simple City Assault (civs attacking cities)
 

Attachments

  • 1739662342977.png
    1739662342977.png
    399.9 KB · Views: 68
Last edited:
Diagram of Civ attacking an independent
 

Attachments

  • 1739662390799.png
    1739662390799.png
    232.4 KB · Views: 63
Last edited:
Diagram of Civ City Defense
1739662425483.png
 
Last edited:
for that example diagram, did you skip the JumpTos from 4, 9 and 16 to 27, and the 13-> 16 one for brevity? or is there something about the db configuration that means those JumpTos aren't valid? I also notice its missing 11-15, which seems to be a branch off of 10.

it seems like the flow is index based using the ShapeId right? so for a given node x without a JumpTo, it walks back to be parented by the closest node with a suitable shapeID, i.e not 1 or 2 as they have no children.

I also am struggling to see what specifies some connections, like what is defining 20 -> 25 as opposed to 21->25? 0->4 as opposed to 1-> 4, and 4->9 as opposed to 5->9. These appear to be cases where an earlier node parents, even tho there was a closer node that could parent.
 
The thing is, this is an internal implementation. We don't know of an external reference architecture. So it's all trying to recreate documentation from very little actual information.

For example, the jump to's after the node number at the end. That is not an implementation I am aware of, but we know because they consistently do it, that it means end the run for this turn. And the only way to sort each one out is to try it, view the outcome, and hope to make a logical conclusion.

So I don't have the answers a lot of times. I'm just sort of shaping out what I understand of it. For me, most of the early work is documenting all the variables available for each part of the tree data, because we don't have any linker. So I have to put massive levels of documentation around each tree so that all of that is known when editing.

From there, I determine if what I'm editing is possible to change. For example, Number of Turns to run is an easy one, and I often change it because waiting for things to happen for 20 turns or whatever in civ, is a lot.

However, the one to find the best plot to settle, or the best place to dig for an artifact, that's handed off to the db, and we're basically left to guess.

In the case of plot to settle, we know the inputs in general across flavors for plot settle conditions. For artifacts, we have literally no idea.

So for each question, I would have to attempt variations, and see what the outcomes are, and hope that I can clearly understand the impact. Hope this is making sense.
 
 
Back
Top Bottom