Game.Simulation.TerrainAttractiveness
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: struct
Base: IStrideSerializable, ISerializable
Summary:
Represents small attractiveness bonuses applied to terrain tiles from natural features. This struct stores two float bonuses (shore and forest) and implements the game's serialization interfaces so it can be written to and read from save/stream data. The struct reports a fixed stride of 8 bytes (two 4-byte floats), which is important for binary layout and stride-based serialization used by the engine.
Fields
-
public float m_ShoreBonus
Bonus applied to terrain attractiveness when near shore/water. Serialized as a 4-byte float. -
public float m_ForestBonus
Bonus applied to terrain attractiveness when near/inside forest. Serialized as a 4-byte float.
Properties
- None.
This struct exposes its data via public fields rather than properties for compactness and direct binary serialization.
Constructors
public TerrainAttractiveness()
There is no explicit constructor in the source — the default parameterless constructor for the struct is used. Initialize the fields directly after creation, for example:
TerrainAttractiveness ta = new TerrainAttractiveness();
ta.m_ShoreBonus = 0.5f;
ta.m_ForestBonus = 0.25f;
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the two float fields to the provided writer in order: m_ShoreBonus then m_ForestBonus. Uses writer.Write(float). Keep the order the same when deserializing to preserve data integrity. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the two float fields from the provided reader in the same order they were written. The method reads into the struct fields by reference (ref float) and calls reader.Read(out float). Ensure the reader supplies values in the same ordering as Serialize. -
public int GetStride(Context context)
Returns the fixed byte size used by stride/packed serialization for this struct. Returns 8, reflecting two 4-byte floats. This value is used by stride-aware serializers to allocate and interpret contiguous memory for arrays or streams of this struct.
Usage Example
// Example: create, serialize and deserialize a TerrainAttractiveness instance.
// IWriter/IReader are placeholders for the engine's concrete writer/reader implementations.
TerrainAttractiveness ta = new TerrainAttractiveness();
ta.m_ShoreBonus = 0.75f;
ta.m_ForestBonus = 0.5f;
// Serialize
SomeConcreteWriter writer = new SomeConcreteWriter(...);
ta.Serialize(writer);
// Later / elsewhere: Deserialize
SomeConcreteReader reader = new SomeConcreteReader(...);
TerrainAttractiveness loaded = new TerrainAttractiveness();
loaded.Deserialize(reader);
// Verify stride (optional)
int stride = loaded.GetStride(default(Context)); // expected 8
Notes and tips: - The struct is designed for compact, predictable binary layout; do not add non-serialized fields or change order without updating serialization and stride. - When writing custom save/stream code, always match Serialize and Deserialize ordering and types exactly. - The GetStride method receives a Context parameter (not used here) to allow stride calculation that might depend on serialization context for other types; for this struct it always returns 8.