Game.SpecializationBonus
Assembly:
Namespace: Game.City
Type: struct
Base: System.ValueType, Unity.Entities.IBufferElementData, Colossal.Serialization.Entities.IDefaultSerializable, Colossal.Serialization.Entities.ISerializable
Summary:
Represents a specialization bonus value stored as a buffer element in the ECS (Unity.Entities). Provides simple serialization/deserialization hooks for the Colossal.Serialization system, a defaulting method, and a helper to compute a scaled bonus using a coefficient. Typical use is to store per-entity or per-component specialization bonuses in a DynamicBuffer
Fields
public int m_Value
Holds the integer value of the specialization bonus. Affects the computed bonus returned by GetBonus. Default is 0 when SetDefaults is called.
Properties
- (none)
Constructors
- (implicit)
public SpecializationBonus()
No explicit constructors are defined in the source; the default parameterless struct constructor is used. Fields will be zero-initialized unless SetDefaults is called.
Methods
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the stored m_Value from the provided reader. Used by the Colossal.Serialization.Entities deserialization pipeline. -
public float GetBonus(float maxBonus, int coefficient)
Computes and returns a scaled bonus using the formula: maxBonus * m_Value / (m_Value + coefficient) This uses floating-point arithmetic (casts to float) to avoid integer division. When m_Value is 0 the result is 0. The coefficient controls the curve/saturation of the bonus (larger coefficient reduces the effect of small m_Value). -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Value to the provided writer. Used by the Colossal.Serialization.Entities serialization pipeline. -
public void SetDefaults(Context context)
Sets default values for the struct. Implementation sets m_Value = 0. Intended to be called by the defaulting logic in the Colossal serialization framework.
Usage Example
// Create and compute a bonus directly
var bonus = new SpecializationBonus { m_Value = 10 };
float maxBonus = 100f;
int coefficient = 5;
float effectiveBonus = bonus.GetBonus(maxBonus, coefficient); // e.g. 100 * 10 / (10 + 5) = 66.666...
// Using as a buffer element on an entity (Unity ECS)
var entity = entityManager.CreateEntity();
entityManager.AddBuffer<SpecializationBonus>(entity);
var buffer = entityManager.GetBuffer<SpecializationBonus>(entity);
buffer.Add(new SpecializationBonus { m_Value = 3 });
// Serialization / Deserialization (conceptual)
// During save/load the Colossal serialization system will call Serialize/Deserialize
// and SetDefaults when needed. You generally don't call these directly unless
// integrating with the serialization pipeline.