Skip to content

Game.Areas.Extractor

Assembly:
Assembly-CSharp

Namespace:
Game.Areas

Type:
struct

Base:
IComponentData, IQueryTypeParameter, ISerializable

Summary:
Extractor is an ECS component used to represent a resource extractor area in the game. It stores runtime state about the resource deposit and extraction progress (amounts, concentrations, work/harvest metrics and the vehicle work type). The component implements ISerializable to support versioned save/load behavior and IQueryTypeParameter so it can be used in entity queries.


Fields

  • public float m_ResourceAmount
    Holds the current available amount of resource in the extractor area. Serialized/unserialized in all supported save versions (first value written/read by Serialize/Deserialize).

  • public float m_MaxConcentration
    Maximum concentration of the resource at this extractor. This field is read/written starting from save Version.resourceConcentration; older saves will not contain this value. Used to cap or describe extraction concentration.

  • public float m_ExtractedAmount
    Amount extracted (accumulated) by the extractor. Present starting from save Version.extractedResources. Used to track extraction progress separate from harvested/work amounts.

  • public float m_WorkAmount
    Work amount metric used for harvesting/extraction calculations. Introduced at Version.harvestedResources. Typically reflects work done by vehicles/workers associated with the extractor.

  • public float m_HarvestedAmount
    Amount that has been harvested (distinct from extractedAmount/total). Present from Version.harvestedResources. Tracks what has been collected for game statistics or resource depletion.

  • public float m_TotalExtracted
    Total ever extracted from this area across its lifetime. Introduced at Version.totalExtractedResources. Useful for long-term stats or thresholds.

  • public VehicleWorkType m_WorkType
    Type of vehicle work used by this extractor (enum VehicleWorkType). Serialized as an int and deserialized by reading an unsigned integer and casting to VehicleWorkType. This field is present starting with Version.harvestedResources.

Properties

  • None.
    This struct exposes fields directly; no C# properties are defined.

Constructors

  • implicit default struct constructor
    No explicit constructor is declared. The default parameterless struct constructor initializes all float fields to 0 and the enum to its zero value. Create and populate an instance manually when adding to an Entity or when reading from storage.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component state to a writer in a defined order:
  • m_ResourceAmount (float)
  • m_MaxConcentration (float)
  • m_ExtractedAmount (float)
  • m_WorkAmount (float)
  • m_HarvestedAmount (float)
  • m_WorkType (written as int)
  • m_TotalExtracted (float)

The ordering must be preserved because Deserialize reads in the same sequence. m_WorkType is cast to int when written.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component state from a reader while handling save format versioning via reader.context.version:
  • Always reads m_ResourceAmount.
  • If reader.context.version >= Version.resourceConcentration: reads m_MaxConcentration.
  • If reader.context.version >= Version.extractedResources: reads m_ExtractedAmount.
  • If reader.context.version >= Version.harvestedResources: reads m_WorkAmount, m_HarvestedAmount and then reads an unsigned integer which is cast to VehicleWorkType and assigned to m_WorkType.
  • If reader.context.version >= Version.totalExtractedResources: reads m_TotalExtracted.

Notes: - The method uses ref locals into the struct fields to read directly into them. - The method expects the save data to match the versioning checks; older save files simply skip fields not present in those versions. - Ensure Version.* identifiers correspond to the same enum/values used by the game's save system.

Usage Example

// Create and add an Extractor component to an entity (EntityManager usage example)
var extractor = new Game.Areas.Extractor
{
    m_ResourceAmount = 10000f,
    m_MaxConcentration = 1.0f,
    m_ExtractedAmount = 0f,
    m_WorkAmount = 0f,
    m_HarvestedAmount = 0f,
    m_TotalExtracted = 0f,
    m_WorkType = VehicleWorkType.Digging // example enum value
};

entityManager.AddComponentData(entity, extractor);

// To update values later:
var e = entityManager.GetComponentData<Game.Areas.Extractor>(entity);
e.m_ExtractedAmount += 250f;
e.m_ResourceAmount -= 250f;
entityManager.SetComponentData(entity, e);

// Serialization / deserialization is handled by the game's serializer which will call
// Serialize/Deserialize with appropriate writer/reader implementations that provide
// reader.context.version to support backward compatibility.

{{ Additional notes: - The component is designed for ECS-style usage (Unity.Entities). Avoid boxing; use AddComponentData/GetComponentData/SetComponentData to manipulate it. - Respect versioning when extending the struct: append new fields at the end of serialization order and update Deserialize with appropriate version checks to maintain save compatibility. - VehicleWorkType must be kept synchronized with how other systems interpret the enum values to avoid mismatches when casting from the saved integer. }}