Game.Simulation.ITradeSystem
Assembly:
Namespace: Game.Simulation
Type: interface
Base:
Summary:
Interface that defines how to compute the trade price for a given resource when interacting with outside connections. Implementations are expected to combine the resource's base price with modifiers coming from the connection type, whether the transaction is an import or an export, and any city-specific modifiers provided in the DynamicBuffer
Fields
- None
No fields are declared on the interface itself.
Properties
- None
The interface does not expose properties.
Constructors
- None
Interfaces do not declare constructors.
Methods
-
float GetTradePrice(Resource resource, OutsideConnectionTransferType type, bool import, DynamicBuffer<CityModifier> cityEffects)
Calculates and returns the trade price for the specified resource. Implementations should consider: -
resource (Game.Economy.Resource): the commodity being traded (e.g., goods, raw materials).
- type (Game.Prefabs.OutsideConnectionTransferType): the transfer/connection type which may influence handling (e.g., cargo, passenger, special-case transfers).
- import (bool): true when the city is importing (buying) the resource, false when exporting (selling). Imports often have different price modifiers than exports.
- cityEffects (Unity.Entities.DynamicBuffer
): a buffer containing city-specific modifiers such as taxes, subsidies, special policies, demand/supply adjustments. Implementations should iterate this buffer to adjust final price.
Return value: a floating-point price value (typically currency per unit) that the trade system will use for the transaction.
Implementation notes:
- Consider applying a base resource price, then modifying by connection-type multipliers, import/export premiums, and city modifiers.
- Be mindful of precision, rounding, and clamping (e.g., ensure price >= 0).
- If called frequently, consider caching computations or precomputing aggregated modifier values to avoid iterating the DynamicBuffer every frame.
- Watch threading/context: DynamicBuffer
Usage Example
using Game.Simulation;
using Game.Economy;
using Game.Prefabs;
using Game.City;
using Unity.Entities;
public class SimpleTradeSystem : ITradeSystem
{
public float GetTradePrice(Resource resource, OutsideConnectionTransferType type, bool import, DynamicBuffer<CityModifier> cityEffects)
{
// Example base price lookup (pseudo-call; replace with actual economy API)
float basePrice = EconomyAPI.GetBasePrice(resource);
// Apply connection-type adjustment
float typeMultiplier = 1.0f;
if (type == OutsideConnectionTransferType.Cargo) typeMultiplier = 0.95f;
else if (type == OutsideConnectionTransferType.Ship) typeMultiplier = 1.05f;
// Import/export premium
float importPremium = import ? 1.10f : 0.95f;
// Aggregate city modifiers (example: multiply all modifiers)
float cityModifier = 1.0f;
for (int i = 0; i < cityEffects.Length; i++)
{
cityModifier *= cityEffects[i].Value; // CityModifier assumed to have a Value float field
}
float price = basePrice * typeMultiplier * importPremium * cityModifier;
// Clamp to a sensible range
return MathF.Max(0f, price);
}
}