Struct ResourceCost
ENGINE: Represents a resource cost (resourceId + amount).
Used for cost validation and atomic spending operations. Zero-allocation struct for hot path usage.
Usage:
var costs = new[] {
ResourceCost.Create(goldId, 100),
ResourceCost.Create(manpowerId, 50)
};
if (resourceSystem.CanAfford(countryId, costs)) {
resourceSystem.TrySpend(countryId, costs);
}
public readonly struct ResourceCost
Constructors
ResourceCost(ushort, FixedPoint64)
Create a resource cost
public ResourceCost(ushort resourceId, FixedPoint64 amount)
Parameters
resourceIdushortamountFixedPoint64
Fields
Amount
The amount required (always positive)
public readonly FixedPoint64 Amount
Field Value
ResourceId
The resource type ID
public readonly ushort ResourceId
Field Value
- ushort
Properties
IsZero
Check if this cost is zero (free)
public bool IsZero { get; }
Property Value
- bool
Methods
Add(FixedPoint64)
Create a cost with added amount
public ResourceCost Add(FixedPoint64 additionalAmount)
Parameters
additionalAmountFixedPoint64
Returns
Create(ushort, FixedPoint64)
Factory method for cleaner syntax
public static ResourceCost Create(ushort resourceId, FixedPoint64 amount)
Parameters
resourceIdushortamountFixedPoint64
Returns
Create(ushort, int)
Factory method from integer amount
public static ResourceCost Create(ushort resourceId, int amount)
Parameters
resourceIdushortamountint
Returns
Equals(ResourceCost)
public bool Equals(ResourceCost other)
Parameters
otherResourceCost
Returns
- bool
Equals(object)
public override bool Equals(object obj)
Parameters
objobject
Returns
- bool
GetHashCode()
public override int GetHashCode()
Returns
- int
Scale(FixedPoint64)
Create a scaled version of this cost (e.g., for discounts)
public ResourceCost Scale(FixedPoint64 multiplier)
Parameters
multiplierFixedPoint64
Returns
ToString()
public override string ToString()
Returns
- string
Operators
operator ==(ResourceCost, ResourceCost)
public static bool operator ==(ResourceCost left, ResourceCost right)
Parameters
leftResourceCostrightResourceCost
Returns
- bool
operator !=(ResourceCost, ResourceCost)
public static bool operator !=(ResourceCost left, ResourceCost right)
Parameters
leftResourceCostrightResourceCost
Returns
- bool