Struct UnitState
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
provinceIDushortcountryIDushortunitTypeIDushortunitCountushort
Returns
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
provinceIDushortcountryIDushortunitTypeIDushortunitCountushort
Returns
Equals(UnitState)
public bool Equals(UnitState other)
Parameters
otherUnitState
Returns
- bool
Equals(object)
public override bool Equals(object obj)
Parameters
objobject
Returns
- bool
FromBytes(byte[])
Deserialize from 8 bytes
public static UnitState FromBytes(byte[] bytes)
Parameters
bytesbyte[]
Returns
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
Returns
- bool
operator !=(UnitState, UnitState)
public static bool operator !=(UnitState left, UnitState right)
Parameters
Returns
- bool