Namespace Core.Resources
Classes
- ResourceCostExtensions
Helper methods for working with ResourceCost arrays
- ResourceDefinition
ENGINE LAYER: Defines a single resource type (gold, manpower, prestige, etc.)
This is the data structure that represents a resource's properties. Resources are loaded from JSON5 files and registered in ResourceRegistry.
Architecture:
- Engine layer provides the mechanism (ResourceDefinition + ResourceSystem)
- Game layer provides the policy (which resources exist, their properties)
- Data files define specific resources (gold, manpower, etc.)
- ResourceSystem
ENGINE LAYER: Generic resource storage and management system.
Stores and manages multiple resource types (gold, manpower, prestige, etc.) for all countries. Uses deterministic fixed-point math for multiplayer compatibility.
Architecture:
- Dictionary storage: resourceId → array of country values
- Fixed-size arrays: countryId → resource amount
- Deterministic: FixedPoint64 only, no float operations
- Event-driven: Emits ResourceChangedEvent via EventBus
Usage:
- Initialize with country capacity and EventBus
- Register resource types with RegisterResource(resourceId, definition)
- Use AddResource/RemoveResource/GetResource for all operations
- Use CanAfford/TrySpend for cost validation
Performance:
- GetResource: O(1) dictionary lookup + O(1) array access
- Memory: sizeof(FixedPoint64) × resourceCount × countryCount
- Example: 10 resources × 200 countries × 8 bytes = 16 KB
Structs
- ResourceBatchCompletedEvent
ENGINE: Event fired when batch mode ends (single event instead of many individual changes). Contains summary information about what changed during the batch.
- ResourceChangedEvent
ENGINE: Event fired when a resource amount changes for a country. Subscribe via EventBus for reactive UI updates.
- 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); }
- ResourceRegisteredEvent
ENGINE: Event fired when a new resource type is registered.
- ResourceSystemInitializedEvent
ENGINE: Event fired when ResourceSystem is initialized.
- ResourceTransferredEvent
ENGINE: Event fired when resources are transferred between countries.
Interfaces
- IResourceProvider
ENGINE: Interface for resource management systems.
Allows GAME layer to provide custom implementations (e.g., modded resources, different storage strategies, or resource calculation overrides).
Default implementation: ResourceSystem