Implementing NPCs
Data Model
Currently every unit is a player. To implement NPCs I need to add some fields to Unit
, as well as some new game states.
record Unit = {
...,
player: Boolean,
npc_behavior_opt: Option NpcBehavior
}
record NpcBehavior = {
move: Game => List Coord
}
sum GameState
...
| NpcSelectingMove
| NpcExecutingMove { path: List Coord }
The StartingTurn
state will transition to NpcSelectingMove
when the unit is not a player.
If there's a non-player unit that doesn't have NPC behavior, then StartingTurn
will transition directly to EndingTurn
.
This should be flexible enough. If NPCs end up needing their own special state then I have a few options:
- Make
NpcBehavior
a trait and encapsulate some special state. - Replace
NpcBehavior
with anNpcType
sum type that contains the necessary state. - Add some kind of generic resource like
special_points
that any NPC can use.
Criteria
- In addition to the 2 player units, there's a new "Goon" unit that path-finds to the nearest player and moves as far as it can each turn.