Skip to content

Faction

namespace Griff.Modules.Strategy;
public sealed class Faction : Component, ITeamMember, IHoldsItems

A team in a strategy game: its name (the Team and Team of everything it owns, the same teams every genre shares, see Teams), its color, and the resources it has to spend. Teams with different names are enemies. A team is beaten when it has no buildings left.

Resources are items, the one idea every genre shares (see Items), kept a row each, “Gold 200”, as an Inventory keeps its items, so they show (and can be changed) in the Inspector while the game runs, and rewind with everything else. They’re the team’s items: anything else on its team without items of its own (a platformer hero, a card hand) collects into them and pays from them. Any name works for a resource: whatever a Resource’s Kind or a pickup’s Item says.

This is a component: its saved properties are on its component page.

public int Buildings { get; }

How many buildings its team has left in the scene, built or going up.

public Color Color { get; set; }

The team’s color: selection rings, its dots on the minimap.

public string? DefeatMessage { get; set; }

Sent (with the team’s name) when it loses its last building.

public bool IsDefeated { get; }

True once it has no buildings left.

public IReadOnlyList<string> Resources { get; set; }

What it has to spend, a row each, e.g. “Gold 250” and “Wood 100”. Starts as what it starts with.

public IReadOnlyList<ValueTuple<string, int>> Stock { get; }

Its resources and how much of each, in the order it first had them.

public int SupplyLimit { get; set; }

The most supply it can ever have, however many farms it builds.

public string? Team { get; set; }

The team’s name, e.g. “Player” or “Enemy”. Units and buildings with this Team belong to it.

public int Units { get; }

How many units its team has left in the scene.

public void Add(string kind, int amount)

Adds amount of kind, e.g. gold brought back to a town hall (never below 0).

public int Amount(string kind)

How much of kind (e.g. “Gold”) it has. Read as “Amount:Gold”.

public bool CanAfford(string? cost)

True if it has everything a cost like “150 Gold, 50 Wood” asks for.

public string? Lacking(string? cost)

What it’s short of to pay cost, e.g. “Wood”, or null if it can pay.

public void Refund(string? cost)

Gives back a cost it paid, e.g. when training is cancelled.

public bool Spend(string? cost)

Pays a cost like “150 Gold, 50 Wood” if it can afford it; returns whether it did.

public event Action<Faction>? Defeated

Raised when it loses its last building.