Modding:Agent Component Overview
Modding Getting Started |
Agent Component Overview |
Editing existing files |
Adding new assets |
Writing new code |
Starmancer is designed around an agent-component-event system. (This is not a unique system, it has other names, like Entity-Component System (ECS))
Understanding this system will make it much easier to create mods.
Agents
Everything in Starmancer is a GameObjectAgent. Colonists, Doors, Items, Buttons--literally everything.
Agents are comprised of Components and components communicate via Events.
You could think of everything in the game as a sum of its components. There's no class in the game named "Colonist". Instead, a colonist is comprised of components like HitPointComponent, PathfindingComponent, MoraleComponent, SkillComponent, etc.
For example, here are some components that make up Colonists and Doors. Both the Colonists and the Door use the same HitpointComponent and AnimationComponent, but only the Colonist has a MoraleComponent and only the Door has a BreakableComponent (because Colonists can't "break")
Colonist Agent | Door Agent |
---|---|
HitPointComponent | HitPointComponent |
AnimationComponent | AnimationComponent |
PathfindingComponent | BreakableComponent |
MoraleComponent |
Components
Components store data and perform some sort of logic. The HitpointComponent for example, stores an object's current health, and is responsible for adjusting current health when an Agent takes damage.
Each component is responsible for saving its own data and preventing invalid operations from occurring. The HitPointComponent ensures that currentHealth never becomes negative.
Events
Components communicate with each other using Events. An event like OnDamaged is invoked when a Colonist takes damage. The HitPointComponent subscribes to this event and does whatever it wants with the provided information (specifically, the HitPointComponent would subtract amountOfDamage from currentHealth, and invoke the event OnDied if health reaches 0)
Events can be subscribed to with different priorities. This allows components to listen to modify or stop events before any other components have a chance to act on the event.
Imagine a NeverTakeDamageComponent. It could subscribe to OnDamaged with a very high priority and either set the amountOfDamage to 0, or stop the event completely.
Parameters
Events contain data, like amountOfDamage and DamageType. These are passed between components using Parameters. A parameter might look like this:
public class OnDamagedParameter { public int amountOfDamage; public DamageType damageType; }
And then the Component that actually uses it:
void OnDamaged(OnDamagedParameter parameter) { currentHealth -= parameter.amountOfDamage; }
Summary
This was a very brief overview of the Agent-Component-Event system. If you're only creating Asset Bundles (art), this is about all the information you'll need.