Skip to content

Game.Prefabs.BuildingPropertyData

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents how many properties (units/slots) a building prefab provides per zone type and which Resource types the building is allowed to trade/store/manufacture/accept as input. This data is used by the prefab system and gameplay code to determine the number of rentable/residential/commercial/industrial properties and to serialize/deserialize prefab data.


Fields

  • public int m_ResidentialProperties
    Number of residential properties provided by the building when placed in Residential area(s). CountProperties(AreaType.Residential) returns this value.

  • public Resource m_AllowedSold
    Resource type that this building is allowed to sell (used by commercial logic). If set to Resource.NoResource the building does not provide a commercial (sold) property.

  • public Resource m_AllowedInput
    Resource type that the building is allowed to accept as input. This field is read from serialized data only when the reader format includes the BpPrefabData tag (backward/forward compatibility).

  • public Resource m_AllowedManufactured
    Resource type that the building is allowed to manufacture. Used by industrial logic. If Resource.NoResource it contributes no manufactured property.

  • public Resource m_AllowedStored
    Resource type that the building is allowed to store. Used by industrial logic. If not Resource.NoResource this gives the building a stored property.

  • public float m_SpaceMultiplier
    A multiplier affecting space calculations for properties (applies to prefab/property space usage). The exact effect depends on other parts of the game that consume this multiplier.

Properties

  • None (this struct exposes fields directly; there are no C# properties declared in the source).

Constructors

  • public BuildingPropertyData()
    Structs have an implicit default constructor. Default-initialized values are: m_ResidentialProperties = 0, m_AllowedSold/AllowedInput/AllowedManufactured/AllowedStored = default(Resource) (typically Resource.NoResource), m_SpaceMultiplier = 0f. Use an object initializer to set specific values.

Methods

  • public int CountProperties(AreaType areaType)
    Returns the number of properties the building provides for the specified AreaType:
  • AreaType.Residential: returns m_ResidentialProperties.
  • AreaType.Commercial: returns 1 if m_AllowedSold != Resource.NoResource, otherwise 0.
  • AreaType.Industrial: returns 1 if m_AllowedStored != Resource.NoResource or m_AllowedManufactured != Resource.NoResource, otherwise 0.
  • Other area types: returns 0.

Note: The implementation checks m_AllowedStored first; if it has a resource it returns 1 immediately; otherwise it checks m_AllowedManufactured. Effectively industrial returns 1 if either stored or manufactured Resource is set.

  • public int CountProperties()
    Returns the total number of properties across Residential, Commercial and Industrial by summing CountProperties for each of those three AreaType values.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes data in the following order:

  • m_ResidentialProperties (int)
  • m_SpaceMultiplier (float)
  • m_AllowedSold (cast to ulong)
  • m_AllowedManufactured (cast to ulong)
  • m_AllowedStored (cast to ulong)
  • m_AllowedInput (cast to ulong)

Notes: Resources are written as numeric (ulong) values representing the Resource enum.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data in the same order as Serialize, but m_AllowedInput is only read if the reader context format includes FormatTags.BpPrefabData. This conditional read supports backward/forward compatibility with prefab data formats:
  • Reads m_ResidentialProperties (int)
  • Reads m_SpaceMultiplier (float)
  • Reads three ulongs and assigns them to m_AllowedSold, m_AllowedManufactured, m_AllowedStored
  • If reader.context.format.Has(FormatTags.BpPrefabData) then reads one more ulong and assigns it to m_AllowedInput

Be aware: if you write data with m_AllowedInput but read with an older format that does not contain BpPrefabData, the m_AllowedInput will remain its default value.

Usage Example

// Create and initialize BuildingPropertyData for a prefab
var propData = new BuildingPropertyData
{
    m_ResidentialProperties = 6,
    m_SpaceMultiplier = 1.2f,
    m_AllowedSold = Resource.Food,            // provides one commercial property (sells Food)
    m_AllowedManufactured = Resource.NoResource,
    m_AllowedStored = Resource.NoResource,
    m_AllowedInput = Resource.NoResource
};

// Query counts
int residential = propData.CountProperties(AreaType.Residential); // 6
int commercial = propData.CountProperties(AreaType.Commercial);   // 1 (since m_AllowedSold != NoResource)
int industrial = propData.CountProperties(AreaType.Industrial);   // 0

int total = propData.CountProperties(); // sums the three values

// Serialization example (writer is game-provided IWriter)
propData.Serialize(writer);

// Deserialization example (reader is game-provided IReader)
var readData = new BuildingPropertyData();
readData.Deserialize(reader);

Additional notes for modders: - Resource refers to Game.Economy.Resource enum; Resource.NoResource indicates "none". - AreaType refers to Game.Zones.AreaType enum (Residential, Commercial, Industrial, etc.). - The struct is used as a component-like data block for prefabs and is marked ISerializable for prefab persistence. When adding fields or changing serialization order for a mod, take care to maintain compatibility with FormatTags.BpPrefabData and existing save/prefab formats.