Table of Contents

Struct ResourceCost

Namespace
Core.Resources
Assembly
Core.dll

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

resourceId ushort
amount FixedPoint64

Fields

Amount

The amount required (always positive)

public readonly FixedPoint64 Amount

Field Value

FixedPoint64

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

additionalAmount FixedPoint64

Returns

ResourceCost

Create(ushort, FixedPoint64)

Factory method for cleaner syntax

public static ResourceCost Create(ushort resourceId, FixedPoint64 amount)

Parameters

resourceId ushort
amount FixedPoint64

Returns

ResourceCost

Create(ushort, int)

Factory method from integer amount

public static ResourceCost Create(ushort resourceId, int amount)

Parameters

resourceId ushort
amount int

Returns

ResourceCost

Equals(ResourceCost)

public bool Equals(ResourceCost other)

Parameters

other ResourceCost

Returns

bool

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

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

multiplier FixedPoint64

Returns

ResourceCost

ToString()

public override string ToString()

Returns

string

Operators

operator ==(ResourceCost, ResourceCost)

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

Parameters

left ResourceCost
right ResourceCost

Returns

bool

operator !=(ResourceCost, ResourceCost)

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

Parameters

left ResourceCost
right ResourceCost

Returns

bool