TurnOrder
namespace Griff.Scenes;
public sealed class TurnOrder : ComponentTurn-based play with no code: teams take turns, each acting on its own turn while the others wait. List its Teams in order (“Player, Enemy”, or “Blue, Red” for two people at one keyboard) and give whatever acts a TurnTaker naming its team. Teams are the one idea every genre shares (see Teams). Off its team’s turn a turn taker takes no input and its patrols, chases, attacks and shooters hold still; everything else (physics, animations, things with no turn taker) runs in real time as ever, so a turn can be a stretch of real-time play, as in Worms. A turn ends when its team presses End Turn (Tab, the gamepad’s Back, or a button whose Action is End Turn), when its time runs out, or once every turn taker on it has used its actions. With a Text beside it, it shows whose turn it is. For a roguelike, where everything moves when the player moves, give the grid player and the grid enemies turn takers with 1 action and set Between to 0: each step is a turn, and an enemy with nowhere to go passes.
It covers the whole scene, or with Within only part of it: a turn-based arena in a real-time game, or two boards each taking their own turns. A turn taker takes turns in the turn order whose Within covers it (inside that entity, or standing in its area), else in one over the whole scene; one covered by none acts freely. In a network game the host runs it, and with Teams each player’s character is on its player’s team: the same “Blue, Red” teams.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”Between
Section titled “Between”public float Between { get; set; }Seconds between one turn and the next, while nobody acts: a last shot lands, a swing finishes.
ComputerTeams
Section titled “ComputerTeams”public string? ComputerTeams { get; set; }The teams the computer plays, e.g. “Enemy”. End Turn doesn’t end their turns: they end once their turn takers have used their actions or ComputerTurnTime runs out, or when a script ends them.
ComputerTurnTime
Section titled “ComputerTurnTime”public float ComputerTurnTime { get; set; }Seconds a computer team’s turn lasts at most: how long its patrols, chases and shooters get to act. 0 lasts until its turn takers have used their actions.
Current
Section titled “Current”public string? Current { get; set; }The team whose turn it is. Empty starts with the first team; set it to start with another, or from a script to hand the turn straight to a team (its turn starts afresh).
DefeatMessage
Section titled “DefeatMessage”public string? DefeatMessage { get; set; }A message sent once a team that had turn takers has none left (beaten: its units all destroyed), with the team’s name as its data. {0} in it is the team’s name: “{0}Defeated” sends “RedDefeated”, for a Victory panel to open on.
EndAction
Section titled “EndAction”public string? EndAction { get; set; }The input action that ends a person’s turn: “EndTurn” is Tab or the gamepad’s Back. Empty ends turns only with an End Turn button or a script.
Format
Section titled “Format”public string? Format { get; set; }What its Text says: {0} is the team whose turn it is, {1} the round and {2} the seconds left of a timed turn, e.g. “{0}’s turn ({2})”.
IsBetweenTurns
Section titled “IsBetweenTurns”public bool IsBetweenTurns { get; }True between turns, while nobody acts.
Message
Section titled “Message”public string? Message { get; set; }A message sent with Game.Send as each turn starts, with the team’s name as its data. {0} in it is the team’s name: “{0}Turn” sends “PlayerTurn”, then “EnemyTurn”.
public int Round { get; set; }How many times the turns have come round, from 1. The game counts it; it’s 0 until the game starts.
SideList
Section titled “SideList”public IReadOnlyList<string> SideList { get; }What TeamList was called before every genre’s teams were one idea. Kept for scripts.
public string? Sides { get; set; }What Teams was called before every genre’s teams were one idea. Kept for scripts.
public string? Sound { get; set; }A sound played as each turn starts, e.g. “Sounds/turn.wav”.
StartsIn
Section titled “StartsIn”public float StartsIn { get; set; }Seconds until the Current team’s turn starts, between turns. The game counts it down.
TeamList
Section titled “TeamList”public IReadOnlyList<string> TeamList { get; }The teams in order, from Teams.
public string? Teams { get; set; }The teams in the order they take turns, separated by commas, e.g. “Player, Enemy”. A team with no turn takers left is skipped (unless no team has any, for a game whose scripts take the turns). They’re the teams every genre shares: a strategy faction’s, a network game’s, a Team’s.
TimeLeft
Section titled “TimeLeft”public float TimeLeft { get; set; }Seconds left of a timed turn. The game counts it down.
TurnTime
Section titled “TurnTime”public float TurnTime { get; set; }Seconds a person’s turn lasts before it passes by itself, e.g. 30 for a timer as in Worms. 0 lasts until they end it.
Within
Section titled “Within”public string? Within { get; set; }The part of the scene it runs the turns of, by an entity’s name: the turn takers inside that entity or standing in its area (a Room’s, a tilemap’s, a collider’s), e.g. “Arena”. Something that walks in joins the turns, and walks out of them as it leaves. Empty covers the whole scene (but what another turn order’s Within covers).
Methods
Section titled “Methods”Covering
Section titled “Covering”public Scope Covering()The part of the scene it covers (see Within).
EndTurn
Section titled “EndTurn”public void EndTurn()Ends the current turn at the start of the next frame, whoever’s it is (a script’s own End Turn, or a computer team whose script has finished its moves). Between turns it does nothing.
IsComputer
Section titled “IsComputer”public bool IsComputer(string? team)True if the computer plays team (see ComputerTeams).
IsTurn
Section titled “IsTurn”public bool IsTurn(string? team)True while it’s team’s turn (not between turns).
public int Left(string team)How many turn takers team has left in the scene, e.g. “Enemy”: units left in tactics, monsters left in a roguelike. Read as “Left:Enemy”.
ReadsAs
Section titled “ReadsAs”public string ReadsAs(string? format)What its Text says with format as its Format: the team whose turn it is (the first before the game starts), the round (1 before it starts) and the seconds left of a timed turn.
SameSide
Section titled “SameSide”public static bool SameSide(string? a, string? b)The same as Same: true if two team names are the same team. Kept for scripts.
Events
Section titled “Events”TurnEnded
Section titled “TurnEnded”public event Action<string>? TurnEndedRaised as each team’s turn ends, with the team’s name.
TurnStarted
Section titled “TurnStarted”public event Action<string>? TurnStartedRaised as each team’s turn starts, with the team’s name.