GridPatrol
namespace Griff.Scenes;
public sealed class GridPatrol : Component, IGridDriverWalks its GridMovement round a route of cells with no code: guards, villagers, a maze’s sentries, a block that slides back and forth. Points are steps from where it’s placed, e.g. “4 0” (four cells right and back) or “4 0; 4 -3; 0 -3” (round a square). It finds its way around walls between them, waits for whatever stands in its way, and pauses Wait seconds at each. With a GridChase too, it walks its route until it spots the target. The Scene view draws its route, with knobs to drag its points from cell to cell.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”public Vector2 Away { get; set; }How many cells from where it was placed it is (x right, y up), which its points are counted from. The game keeps it up to date as it steps or is moved, so one chased or pushed off its route finds its way back.
IsFinished
Section titled “IsFinished”public bool IsFinished { get; }True once a Once patrol has reached its last point.
LastCell
Section titled “LastCell”public ValueTuple<int, int>? LastCell { get; }The cell it was in last frame, to add how far it went to Away. Not saved: a restored game starts counting again from wherever it is.
public int Leg { get; set; }Which stretch of its route it’s walking, from 0 (the start to the first point). The game keeps it up to date; set it to start part of the way round, so a row of guards don’t all walk together.
public MoverMode Mode { get; set; }How it goes round its points: there and back, round in a loop, or once.
public IReadOnlyList<ValueTuple<int, int>> Path { get; }Its points in cells from where it was placed (x right, y up), starting with (0, 0).
Points
Section titled “Points”public string? Points { get; set; }Where to go, in cells from where it’s placed (x right, y up): “x y” pairs separated by semicolons, e.g. “4 0” or “4 0; 4 -3; 0 -3”. The start (0 0) is always the first point. On a hex map they’re columns and rows, so “0 2” is straight up the screen and “0 1” the row above, half a hexagon to one side.
Running
Section titled “Running”public bool Running { get; set; }Untick it to stop it where it is. Switches tick and untick it.
public float Wait { get; set; }Seconds to wait at each point. Taking turns (a TurnTaker with actions), it waits that many of its turns instead, rounded up.
WaitLeft
Section titled “WaitLeft”public float WaitLeft { get; }Seconds left waiting at a point.
Methods
Section titled “Methods”PointOf
Section titled “PointOf”public int PointOf(int leg)Which of its Path’s points stretch leg heads for.
Resume
Section titled “Resume”public void Resume(float waitLeft, ValueTuple<int, int>? lastCell)Picks up where it was (a puzzle’s undo): its seconds left waiting and the cell it was in last.
Events
Section titled “Events”Arrived
Section titled “Arrived”public event Action<GridPatrol, int>? ArrivedRaised on reaching each point, with which one (1 is the first after the start, 0 the start).