Skip to content

Game.City.ServiceFee

Assembly: Game
Namespace: Game.City

Type: struct

Base: IBufferElementData, ISerializable

Summary:
Represents a per-service fee entry used by the city/player resource systems. Each ServiceFee holds which PlayerResource it applies to and the current fee value. Implements custom serialization/deserialization to support save/load and new-game initialization; when creating a new game the saved fee value is ignored and a default fee is assigned via GetDefaultFee. The type is intended to be stored in an ECS DynamicBuffer (IBufferElementData) on entities that track service fees.


Fields

  • public PlayerResource m_Resource
    Represents which player resource/service this fee entry refers to (e.g., Water, Electricity, Education levels, Healthcare, Garbage). Serialized as an int.

  • public float m_Fee
    The fee/value for the associated resource. Serialized as a float. On NewGame deserialization this value is replaced by the result of GetDefaultFee(m_Resource).

Properties

  • (none)
    This struct exposes public fields and implements required interfaces; it does not declare properties.

Constructors

  • public ServiceFee()
    Implicit default value-type constructor. There is no explicit constructor in the source; instances will typically be created when adding elements to an ECS DynamicBuffer or by default-initializing the struct.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the data for this element in the following order: the PlayerResource as an int, then the fee (float). This is used by the game's custom serializer.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data in the same order as Serialize. Behavior details:

  • If reader.context.purpose == Purpose.NewGame: reads the resource (int) and ignores the stored fee value, then sets m_Fee = GetDefaultFee(m_Resource). This ensures new games start with canonical defaults rather than any saved values.
  • Otherwise: reads the resource and the fee into m_Fee.
  • After reading, if reader.context.version < Version.waterFeeReset and the resource is PlayerResource.Water, the fee is overridden to 0.3f. This maintains backward compatibility with older save versions that need the water fee adjusted.

  • public float GetDefaultFee(PlayerResource resource)
    Returns the default fee for a given PlayerResource. Mapped defaults in the source:

  • BasicEducation => 100f
  • SecondaryEducation => 200f
  • HigherEducation => 300f
  • Healthcare => 100f
  • Garbage => 0.1f
  • Electricity => 0.2f
  • Water => 0.1f
  • default/others => 0f

Usage Example

// Example: adding service fees to an entity with an EntityManager and DynamicBuffer<ServiceFee>
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity feesEntity = em.CreateEntity(typeof(ServiceFee)); // or create a dedicated entity for fees

DynamicBuffer<ServiceFee> buffer = em.AddBuffer<ServiceFee>(feesEntity);

// Add a water fee entry
buffer.Add(new ServiceFee {
    m_Resource = PlayerResource.Water,
    m_Fee = 0.1f // or use GetDefaultFee(PlayerResource.Water)
});

// Add electricity
buffer.Add(new ServiceFee {
    m_Resource = PlayerResource.Electricity,
    m_Fee = 0.2f
});

// When saving/loading the game's serialization system will call Serialize/Deserialize
// For new games, Deserialize will assign defaults via GetDefaultFee regardless of saved values.

{{ Additional notes: - The struct depends on the PlayerResource enum and the serialization context types (IWriter/IReader, Purpose, Version) defined elsewhere in the codebase. - Be cautious when changing serialized ordering or field types: the custom Serialize/Deserialize must remain compatible with save versions. - The special-case for water fee and Version.waterFeeReset indicates a historic change to how water fees were handled; consult the project's versioning constants when modifying deserialization logic. }}