Skip to content

TacticsUnit

A unit in a tactics game, with no code: on its team’s turn you pick it, see the cells it can walk to (and the cells it can hit from them), then click one to walk there and click an enemy in reach to attack it. Each turn it moves up to Move cells, around walls and other units, then attacks something MinRange to Range steps away for Damage, or waits. Give it a TurnTaker with 1 action naming its team: attacking or waiting uses the action, so once every unit on a team has had its go, the turn passes. A TacticsControls in the scene does the picking and draws the ranges. On a team the computer plays (the turn order’s Computer Teams), the computer takes each unit’s go in turn, the way its Stance says: the best attack it can make (a foe it can finish off first, then the weakest), or a walk toward the nearest foe.

Part of the Tactics module: Turn-based tactics: units on a grid, picked and sent to a cell in reach or set on a foe, side by side in turns (TacticsUnit, TacticsControls), the computer playing a team, the Tactics template, and Create Tactics Unit in the Entity menu.

Its enemies are the units on other teams (with no teams, every other unit) and anything else with a Health on another team (see Teams), or whatever with Health is on its Layers. Ranges are counted in steps and reach over walls. Units block each other, friend or foe. In a network game the host moves the units: a player’s clicks are sent to it.

Requires: GridMovement

Works with: TurnTaker (its side, with 1 action: a go each turn); Health (hit points, so it can be beaten); TacticsControls (picks units and draws their ranges, one per scene)

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • move: a whole number = 4. How many cells it can walk in a turn, around walls and other units. (Field: a number.)
  • range: a whole number = 1. How many steps away it can hit: 1 is next to it, more for an archer or a mage. (Field: a number.)
  • minRange: a whole number = 1. How close something has to be at least for it to hit it: 2 for an archer that can’t hit what’s next to it. (Field: a number.)
  • damage: a number = 1. Hit points each attack takes away. (Field: a number.)
  • damageRoll: text = null. Dice rolled for each hit’s damage in place of Damage, e.g. “1d8+2”; empty hits for Damage every time. Table Values sets it from a dice column given for Damage. (Dice: how many, “d”, their sides, then anything added or taken away, e.g. “2d6+3”, “d20”, “1d8+1d6-1” or a plain number; empty for none. The Inspector builds them and shows the lowest, highest and average roll.) (Field: its own editor: Dice.)
  • layers: text = null. The collision layers it attacks, e.g. “Enemy”. Empty attacks the units on other teams (see TurnTaker). (Names collision layers: their names, separated by commas.) (Field: a name.)
  • attackSound: text = null. A sound played with each attack, e.g. “Sounds/hit.wav”. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • hitEffect: text = null. A prefab spawned on what it hits, e.g. “Sparkle”: a burst of particles, a damage number. (Names a prefab.) (Field: a name.)
  • hitStop: a number = 0.06. Freezes the game for this many seconds when an attack lands, so it hits hard. 0 for none. (Field: a number.)
  • stance: one of Charge, Guard, Hold = “Charge”. How it plays when the computer plays its team (see TurnOrder.ComputerTeams): Charge goes after the nearest foe, Guard stays put until a foe comes within a walk and a hit, Hold never walks and only attacks from where it stands. (Field: one of its values.)
  • hasMoved: true or false = false. True once it has walked this go and has yet to attack or wait. The game clears it as its go ends and as each of its team’s turns starts. (Field: on or off.)

What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).

  • Wait. Ends its go where it stands, without attacking, at the start of the next frame.
  • UndoMove. Takes back the walk it took this go, if it hasn’t attacked or waited yet, putting it back where it was.

What anything can read with no code: a Counter’s, Bar’s or Text’s output, a Contraptions Wire’s output as its signal; Text shows names too, the rest read numbers, true as 1.

  • Moved (true or false). True once it has walked this go and has yet to attack or wait. The game clears it as its go ends and as each of its team’s turns starts.
  • CanAct (true or false). True while it can take its go: it’s its team’s turn (if it takes turns) and it hasn’t used its action.
  • Done (true or false). True on its team’s turn once it has had its go: drawn dimmed until its team’s next turn.

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • canAct: true or false. True while it can take its go: it’s its team’s turn (if it takes turns) and it hasn’t used its action.
  • isDone: true or false. True on its team’s turn once it has had its go: drawn dimmed until its team’s next turn.
  • isWalking: true or false. True while it’s walking to where it was sent.

Scripts use it as TacticsUnit: its methods, events and values that aren’t saved with the scene.