Tips Useful Concepts - CBornholdt/RimWorld-AI-Tutorial GitHub Wiki

Useful Concepts

When designing AI logic, one will normally interact with numerous different system aspects, and doing so consistently can rise to a challenge. Herein are a cursory description of the high level concepts in RimWorld, along with examples/guidelines on how vanilla handles them.

Danger

Danger is an easy concept to grasp, and it is normally used as a Threshold to determine whether a Pawn/Lord will attempt to perform some task (for pawns this is the NormalMaxDanger() extension method) . In vanilla, it can take on one of the following values

  • Unspecified
  • None
  • Some
  • Deadly

Danger is considered to a property of Regions, and is calculated per cell via that cell's region. Dangerous effects are cached by the Region (see Region.DangerFor) and returned when requested. Some of the dangers with their danger values are listed below ... the highest level of applicable Danger is the one that applies.

Dangerous Entity Danger Value
Temperature within comfortable range Danger.None
Temperature less than 80 degrees outside of comfortable Danger.Some
Temperature more than 80 degrees outside of comfortable Danger.Deadly

Story Danger

A close cousin to Danger, this is merely an extension of the same idea to the map level. StoryDanger can take the following values

  • None
  • Low
  • High

StoryDanger is a map level property, is driven primarily by the StoryTeller, and interacts with numerous Lords and Jobs. In particular, the following states influence the StoryDanger. As with Danger, the highest applicable StoryDanger value applies.

Dangerous Event StoryDanger
No targets hostile to colony StoryDanger.None
Some hostile targets totaling less than half of the free, spawned colonists StoryDanger.Low
As above, but colonist was harmed in the last 900 ticks StoryDanger.High
Any AI lord that is presently in LordToil_AssaultColony StoryDanger.High

Note, that if you wish to have the presence of a Lord to influence the StoryDanger, they must possess either the LordToil_AssaultColony or the DangerWatcher.DangerRating property will need to be patched.

Stances

Certain pawn state that occurs on the tick-level is captured by stances, specifically whether that pawn is actively performing something (Busy), whether they are moving (Mobile), whether they are preparing to do something (WarmUp), and whether they are recovering from doing something (Cooldown). This can influence how pawns respond to immediate actions or events.

Effecters

Effecters represent an effect, some external pawn action accompanied with visuals/sound. In some manner it can be considered a Toil enhancement, as the extension methods toil.WithEffect add adjustments to that toil's PreTickAction and FinishActions such that the Effecter is created, then ticks with the Toil, and finally is removed when that Toil ends.

Terrain Affordances and Properties

Terrain affordances specify what can done on any particular terrain cell. The current list of affordances is

Affordance Property
Light TODO
Medium Capable of moderate structures
Heavy TODO
GrowSoil Whether plants can be grown
Diggable Whether that terrain is diggable
SmoothableStone Whether that terrain can be smoothed
MovingFluid River or other

To check whether a particular Terrain is wet, check TerrainDef.driesTo != null