Table of Contents

Struct UnitState

Namespace
Core.Units
Assembly
Core.dll

8-byte hot data for a single military unit.

DESIGN:

  • Fixed size (8 bytes) for cache efficiency and network transmission
  • No visual data (positions, sprites) - presentation layer responsibility
  • provinceID instead of coordinates - simulation layer doesn't know positions
  • RISK-style: Simple unit count instead of percentage-based strength/morale

MULTIPLAYER:

  • Deterministic layout (explicit struct layout)
  • No managed references (NativeArray compatible)
  • Serializable for network sync
public struct UnitState

Fields

countryID

Owning country (0-65535 countries)

public ushort countryID

Field Value

ushort

provinceID

Current province location (0-65535 provinces)

public ushort provinceID

Field Value

ushort

unitCount

Number of troops in this unit

public ushort unitCount

Field Value

ushort

unitTypeID

Unit type ID (infantry, cavalry, artillery, etc.)

public ushort unitTypeID

Field Value

ushort

Properties

HasTroops

Does this unit have troops?

public bool HasTroops { get; }

Property Value

bool

IsDestroyed

Is this unit destroyed (unitCount = 0)?

public bool IsDestroyed { get; }

Property Value

bool

Methods

Create(ushort, ushort, ushort, ushort)

Create a new unit with specified troop count

public static UnitState Create(ushort provinceID, ushort countryID, ushort unitTypeID, ushort unitCount = 1)

Parameters

provinceID ushort
countryID ushort
unitTypeID ushort
unitCount ushort

Returns

UnitState

CreateWithStats(ushort, ushort, ushort, ushort)

Create a unit with custom stats (for loading saves, reinforcements, etc.)

public static UnitState CreateWithStats(ushort provinceID, ushort countryID, ushort unitTypeID, ushort unitCount)

Parameters

provinceID ushort
countryID ushort
unitTypeID ushort
unitCount ushort

Returns

UnitState

Equals(UnitState)

public bool Equals(UnitState other)

Parameters

other UnitState

Returns

bool

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

FromBytes(byte[])

Deserialize from 8 bytes

public static UnitState FromBytes(byte[] bytes)

Parameters

bytes byte[]

Returns

UnitState

GetHashCode()

public override int GetHashCode()

Returns

int

ToBytes()

Serialize to 8 bytes for network transmission or save files

public byte[] ToBytes()

Returns

byte[]

ToString()

public override string ToString()

Returns

string

Operators

operator ==(UnitState, UnitState)

public static bool operator ==(UnitState left, UnitState right)

Parameters

left UnitState
right UnitState

Returns

bool

operator !=(UnitState, UnitState)

public static bool operator !=(UnitState left, UnitState right)

Parameters

left UnitState
right UnitState

Returns

bool