Game.Simulation.ZoneEvaluationUtils
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: class
Base: System.Object
Summary:
Utility class containing helpers to evaluate zoning desirability and to compute per-factor zoning scores used by the simulation to decide which zone type (residential, commercial, industrial/office, storage, etc.) is appropriate for a location. It exposes a set of static scoring functions and internal helpers that combine resource availability (DynamicBuffer
This class also defines: - enum ZoningEvaluationFactor — list of factors that influence zoning evaluations (Services, Workplaces, Competitors, Customers, Inputs, Pollution, LandValue, Employees, ...). - struct ZoningEvaluationResult — a simple (factor, score) pair implementing IComparable to allow sorting factor entries by importance (sorts by absolute value descending; ties broken by sign — positive preferred).
The methods are intended for use from simulation systems and expect Unity collections (NativeList, NativeArray) and ECS buffers/lookups (DynamicBuffer, ComponentLookup). Avoid allocating these per-frame; allocate and reuse collections where possible.
Fields
This class has no persistent instance fields; it is composed of nested types and static methods.
Properties
This class does not expose properties.
Constructors
public ZoneEvaluationUtils()
Default parameterless constructor (type is used as a static-style utility; methods are static — you typically do not need to construct this type).
Methods
-
private static float GetFactor(DynamicBuffer<ResourceAvailability> availabilities, float curvePos, AvailableResource resource)
Returns a normalized factor based on availability for the provided AvailableResource at curvePos. Internally clamps result with math.min(20f, 0.2f / availability). Used as a small helper for converting an availability value to a factor used in several score calculations. -
public static void GetFactors(AreaType areaType, bool office, DynamicBuffer<ResourceAvailability> availabilities, float curvePos, ref ZonePreferenceData preferences, NativeList<ZoningEvaluationResult> results, NativeArray<int> resourceDemands, float pollution, float landvalue, DynamicBuffer<ProcessEstimate> estimates, NativeList<IndustrialProcessData> processes, ResourcePrefabs resourcePrefabs, ComponentLookup<ResourceData> resourceDatas)
Populates the provided results list with ZoningEvaluationResult entries representing individual factor contributions for the given areaType (Residential, Commercial, Industrial). Behavior summary: - Residential: adds Services, Workplaces, Pollution and LandValue factor entries computed from preferences, availability and local pollution/land value.
- Commercial: computes Customers (combining uneducated/educated citizens or workplaces), Competitors (service availability), and LandValue entries.
-
Industrial: for production (office == false) adds Inputs and LandValue. For office (office == true) adds Employees and Services entries. This method does not return a total score — it returns the factor breakdown so a caller can inspect or sort components.
-
private static float GetStorageScore(Resource resource, float price, DynamicBuffer<ResourceAvailability> availabilities, float curvePos)
Internal helper used when evaluating storage suitability. It examines available upstream supplies (via ResourceIterator and EconomyUtils.IsProducedFrom) and computes a combined score that favors resources with more reliable/cheaper upstream availability. Used by the industrial storage branch of GetScore. -
private static float GetTransportScore(Resource allowedManufactured, NativeList<IndustrialProcessData> processes, DynamicBuffer<ResourceAvailability> availabilities, NativeArray<int> resourceDemands, float curvePos, ResourcePrefabs resourcePrefabs, ref ComponentLookup<ResourceData> resourceDatas)
Internal helper for industrial production evaluation. Iterates manufactured resources and their inputs, compares required input amounts vs availability and market prices, and computes a normalized transport/input pressure score. Returns a value used to penalize industries with poor input availability or expensive transport. Uses EconomyUtils, ResourceIterator and market price lookup. -
public static float GetResidentialScore(DynamicBuffer<ResourceAvailability> availabilities, float curvePos, ref ZonePreferenceData preferences, float landValue, float pollution)
Computes and returns a single float score for residential zoning desirability. Combines service/workplace availability penalties (inverted via GetAvailability), pollution penalty, and land value preference. The method returns a base offset (555f) plus the combined preference-driven modifiers (same baseline convention used by the other Get*Score methods in this class). -
public static float GetCommercialScore(DynamicBuffer<ResourceAvailability> availabilities, float curvePos, ref ZonePreferenceData preferences, float landValue, bool lodging)
Computes a commercial zoning score for either normal commercial (lodging == false) or lodging commercial (lodging == true). Considers consumer availability (educated/uneducated citizens), workplaces, service competitors and land value. Returns base (555f) + combined modifiers. -
public static float GetScore(AreaType areaType, bool office, DynamicBuffer<ResourceAvailability> availabilities, float curvePos, ref ZonePreferenceData preferences, bool storage, NativeArray<int> resourceDemands, BuildingPropertyData propertyData, float pollution, float landValue, DynamicBuffer<ProcessEstimate> estimates, NativeList<IndustrialProcessData> processes, ResourcePrefabs resourcePrefabs, ref ComponentLookup<ResourceData> resourceDatas)
Top-level scoring function. Depending on areaType and flags it dispatches to the appropriate specialized scoring logic: - Residential -> GetResidentialScore
- Commercial -> weighted combination of commercial vs lodging commercial (90%/10%)
-
Industrial:
- storage == true -> evaluates storage suitability by iterating allowedStored resources in propertyData, calling GetStorageScore and returning a value derived from the minimum storage score found (returns a value in the same baseline style; clamps to >= 0).
- office == true -> office-specific score based on educated citizen availability and services.
- production -> combines industrial input/transport score (GetTransportScore), industrial land value preference, and a small penalty based on landValue. Returns a float representing overall desirability (higher = more desirable). Note: the numeric baseline 555f and other magic constants are internal to the game balancing and should be preserved if using or comparing scores to game internals.
-
public struct ZoningEvaluationResult : IComparable<ZoningEvaluationResult>
- Fields:
public ZoningEvaluationFactor m_Factor;
public float m_Score;
-
public int CompareTo(ZoningEvaluationResult other)
Comparison used to sort factor entries: it orders by absolute score descending (largest magnitude first). When absolute values are equal, the tie-breaker prefers positive scores over negative ones. -
public enum ZoningEvaluationFactor
Enum listing factors used by the utils: None, Workplaces, Services, Competitors, Customers, OutsideConnections, Inputs, Pollution, LandValue, Employees, Count
Usage Example
// Example inside a simulation system where you already have access to:
// - DynamicBuffer<ResourceAvailability> availabilities
// - ZonePreferenceData preferences
// - NativeList<ZoneEvaluationUtils.ZoningEvaluationResult> factorResults (allocated and cleared by caller)
// - NativeArray<int> resourceDemands
// - other required inputs (processes, estimates, resourcePrefabs, etc.)
// 1) Get a total score for a residential tile:
float resScore = ZoneEvaluationUtils.GetScore(
AreaType.Residential,
office: false,
availabilities: availabilities,
curvePos: someCurvePos,
ref preferences,
storage: false,
resourceDemands: resourceDemands,
propertyData: default, // only needed for industrial/storage paths
pollution: localPollution,
landValue: localLandValue,
estimates: estimatesBuffer,
processes: processesList,
resourcePrefabs: resourcePrefabs,
ref resourceDatas
);
// 2) Get a factor breakdown for an industrial (production) tile:
factorResults.Clear();
ZoneEvaluationUtils.GetFactors(
AreaType.Industrial,
office: false,
availabilities: availabilities,
curvePos: someCurvePos,
ref preferences,
results: factorResults,
resourceDemands: resourceDemands,
pollution: localPollution,
landvalue: localLandValue,
estimates: estimatesBuffer,
processes: processesList,
resourcePrefabs: resourcePrefabs,
resourceDatas: resourceDatas
);
// Sort factors by importance (ZoningEvaluationResult implements IComparable)
factorResults.Sort();
Notes and caveats:
- Many parameters use Unity Collections and ECS types. Allocate NativeList/NativeArray and reuse them to avoid per-frame GC/allocations.
- Methods depend on other game systems (NetUtils, EconomyUtils, ResourceIterator, ResourcePrefabs, ComponentLookup