Tactics RPG Devlog

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:

Criteria