Game.UI.InGame.BuildingHappiness
Assembly: Game (approx.)
Namespace: Game.UI.InGame
Type: static class
Base: System.Object
Summary:
Utility class used by the game to compute happiness / well‑being factors for buildings. It contains methods to gather and aggregate the various happiness contributions for residential buildings and company buildings (commercial/industrial/service), updating a supplied factors buffer (NativeArray
Fields
None
This static class contains no instance or static fields in the provided source.
Properties
None
No properties are declared.
Constructors
None (static class)
Being a static class, there are no constructors. All members are static methods.
Methods
public static void GetResidentialBuildingHappinessFactors(Entity city, NativeArray<int> taxRates, Entity property, NativeArray<int2> factors, ref ComponentLookup<PrefabRef> prefabs, ref ComponentLookup<SpawnableBuildingData> spawnableBuildings, ref ComponentLookup<BuildingPropertyData> buildingPropertyDatas, ref BufferLookup<CityModifier> cityModifiers, ref ComponentLookup<Building> buildings, ref ComponentLookup<ElectricityConsumer> electricityConsumers, ref ComponentLookup<WaterConsumer> waterConsumers, ref BufferLookup<Game.Net.ServiceCoverage> serviceCoverages, ref ComponentLookup<Locked> locked, ref ComponentLookup<Game.Objects.Transform> transforms, ref ComponentLookup<GarbageProducer> garbageProducers, ref ComponentLookup<CrimeProducer> crimeProducers, ref ComponentLookup<MailProducer> mailProducers, ref BufferLookup<Renter> renters, ref ComponentLookup<Citizen> citizenDatas, ref BufferLookup<HouseholdCitizen> householdCitizens, ref ComponentLookup<BuildingData> buildingDatas, CitizenHappinessParameterData citizenHappinessParameters, GarbageParameterData garbageParameters, HealthcareParameterData healthcareParameters, ParkParameterData parkParameters, EducationParameterData educationParameters, TelecomParameterData telecomParameters, DynamicBuffer<HappinessFactorParameterData> happinessFactorParameters, NativeArray<GroundPollution> pollutionMap, NativeArray<NoisePollution> noisePollutionMap, NativeArray<AirPollution> airPollutionMap, CellMapData<TelecomCoverage> telecomCoverage, float relativeElectricityFee, float relativeWaterFee) : System.Void
This is the primary function for computing residential building happiness contributions. It:- Validates the provided property entity and its prefab presence.
- Reads building/lot data to calculate per-apartment space.
- Iterates renters/households (if any) to derive averages such as current citizen happiness, leisure counters and education distribution, which affect internal weighting.
- Calls a number of helper functions (CitizenHappinessSystem.*) to obtain bonuses for electricity/water supply & fees, pollution (ground/air/noise), sewage, garbage, crime, telecom, mail, healthcare, parks/entertainment, education, welfare, leisure, taxes, and apartment wellbeing.
- For each factor, it increments the corresponding entry in the provided factors array (int2): the method increments .x (count) and adds (computed_bonus - parameterBaseLevel) to .y, using happinessFactorParameters to determine base levels and locked to skip locked modifiers.
- Uses service coverage buffers (serviceCoverages) attached to the property's road edge to compute several service-based bonuses (healthcare, entertainment, education, welfare).
- Takes into account per‑citizen averages and modifiers (e.g., child fraction) to scale some bonuses.
- Note: the factors array is modified in place and expected to be properly sized by the caller.
Important behavior notes and dependencies: - This method assumes it runs inside an ECS system where ComponentLookup and BufferLookup are valid and have been updated (and that their HasComponent/HasBuffer semantics are used correctly). - Many checks skip computation for locked happiness factors using locked.HasEnabledComponent(...) and happinessFactorParameters entries. - CitizenHappinessSystem provides the core per-factor computations; this method aggregates their results and applies building-specific scaling and base-level adjustments. - The method reads many parameter data structs (CitizenHappinessParameterData, GarbageParameterData, etc.) and uses them to call the helper functions. - The indexing of the factors array is important — callers must provide an array with the same expected index mapping (see Index mapping below).
public static void GetCompanyHappinessFactors(Entity property, NativeArray<int2> factors, ref ComponentLookup<PrefabRef> prefabs, ref ComponentLookup<SpawnableBuildingData> spawnableBuildings, ref ComponentLookup<BuildingPropertyData> buildingPropertyDatas, ref ComponentLookup<Building> buildings, ref ComponentLookup<OfficeBuilding> officeBuildings, ref ComponentLookup<WorkProvider> workProviders, ref BufferLookup<Renter> renters, ref ComponentLookup<BuildingData> buildingDatas, ref ComponentLookup<CompanyData> companies, ref ComponentLookup<IndustrialProcessData> industrialProcessDatas, ref ComponentLookup<WorkplaceData> workplaceDatas, ref ComponentLookup<Citizen> citizens, ref ComponentLookup<HealthProblem> healthProblems, ref ComponentLookup<ServiceAvailable> serviceAvailables, ref ComponentLookup<ResourceData> resourceDatas, ref ComponentLookup<ZonePropertiesData> zonePropertiesDatas, ref BufferLookup<Efficiency> efficiencies, ref ComponentLookup<ServiceCompanyData> serviceCompanyDatas, ref BufferLookup<ResourceAvailability> availabilities, ref BufferLookup<TradeCost> tradeCosts, EconomyParameterData economyParameters, NativeArray<int> taxRates, NativeArray<Entity> processes, ResourcePrefabs resourcePrefabs) : System.Void
Computes happiness-related factors for company buildings (industrial/commercial/service). Behavior summary:- Validates prefab and spawnable data for the property.
- Determines allowed resources (manufactured/sold) from BuildingPropertyData. If none, returns early.
- If the building has renters that are companies, the method inspects renter company prefabs for industrialProcessDatas / serviceCompanyDatas to find the process/service driving the company at this property.
- If a renter company with a process is found, it selects that process and calls AddCompanyHappinessFactors to add the contributions.
- Otherwise it iterates the provided processes list (NativeArray
processes) and for each process whose output resource matches the building's allowed resources it calls AddCompanyHappinessFactors. - AddCompanyHappinessFactors does the detailed factor accumulation (see below).
-
Note: this method relies heavily on components relating to workplaces, employees, available services, resource availabilities and trade costs to compute company-specific happiness. It aggregates and forwards relevant context to AddCompanyHappinessFactors.
-
private static void AddCompanyHappinessFactors(NativeArray<int2> factors, Entity property, Entity prefab, Entity renter, Entity renterPrefab, IndustrialProcessData processData, ServiceCompanyData serviceCompanyData, bool commercial, int level, ref ComponentLookup<OfficeBuilding> officeBuildings, ref ComponentLookup<WorkProvider> workProviders, ref BufferLookup<Employee> employees, ref ComponentLookup<WorkplaceData> workplaceDatas, ref ComponentLookup<Citizen> citizens, ref ComponentLookup<HealthProblem> healthProblems, ref ComponentLookup<ServiceAvailable> serviceAvailables, ref ComponentLookup<BuildingPropertyData> buildingPropertyDatas, ref ComponentLookup<ResourceData> resourceDatas, ref ComponentLookup<ServiceCompanyData> serviceCompanyDatas, ref BufferLookup<Efficiency> efficiencies, ref BufferLookup<ResourceAvailability> availabilities, ref BufferLookup<TradeCost> tradeCosts, NativeArray<int> taxRates, Building building, SpawnableBuildingData spawnableData, BuildingData buildingData, ResourcePrefabs resourcePrefabs, ref EconomyParameterData economyParameters) : System.Void
Intended to add the detailed company-side happiness contributions to the factors buffer. In the provided source this method has an empty body (no-op). In a full implementation it would: - Use processData/serviceCompanyData and workplace/employee information to compute work-related happiness, resource availability/efficiency effects, health problems, and service availability impacts for company employees and the company itself.
- Adjust relevant factor indices in factors (similar to the residential method) for pollution, services, taxes, welfare, employee leisure, and other company-specific happiness drivers.
- Note: Because the method body is currently empty in the provided code, GetCompanyHappinessFactors will end up making no changes unless AddCompanyHappinessFactors is implemented elsewhere or modified.
Index mapping (factors array): The GetResidentialBuildingHappinessFactors method updates many indices of the factors array. The mapping inferred from the code is: - factors[0] = Telecom - factors[1] = Crime - factors[2] = Air pollution - factors[3] = Electricity supply - factors[4] = Healthcare - factors[5] = Ground pollution - factors[6] = Noise - factors[7] = Water supply - factors[8] = Water pollution - factors[9] = Sewage - factors[10] = Garbage - factors[11] = Entertainment / Parks - factors[12] = Education - factors[13] = Mail - factors[14] = Welfare - factors[15] = Leisure - factors[16] = Tax effects (combined by education fractions) - factors[21] = Apartment wellbeing (space-based) - factors[26] = Electricity fee - factors[27] = Water fee
Implementation detail: each updated factors[i] is an int2 where: - .x is used as a counter (# of contributions aggregated) - .y is a cumulative adjusted value (sum of computed bonuses minus parameter base-levels). Callers are expected to compute final averages/normalization from these aggregates afterwards.
Notes, constraints and typical usage:
- This code is tied to the game's ECS and service/parameter data models. It should be invoked only when the required ComponentLookup/BufferLookup objects are valid and up-to-date.
- Many checks use locked.HasEnabledComponent(...) and happinessFactorParameters entries to determine whether a particular factor should be computed or skipped (locked modifiers).
- The residential method expects the factors NativeArray
Usage Example
// Example: from within a SystemBase or a method where ComponentLookup/BufferLookup are available
NativeArray<int2> factors = new NativeArray<int2>(32, Allocator.Temp); // sized to cover indices used above
for (int i = 0; i < factors.Length; i++) factors[i] = new int2(0,0);
// Suppose you have prepared/refreshed all required lookups and parameter buffers:
// ref ComponentLookup<PrefabRef> prefabs = ...; ref BufferLookup<Renter> renters = ...; etc.
// Residential example call:
BuildingHappiness.GetResidentialBuildingHappinessFactors(
cityEntity,
taxRatesArray,
propertyEntity,
factors,
ref prefabs,
ref spawnableBuildings,
ref buildingPropertyDatas,
ref cityModifiers,
ref buildings,
ref electricityConsumers,
ref waterConsumers,
ref serviceCoverages,
ref locked,
ref transforms,
ref garbageProducers,
ref crimeProducers,
ref mailProducers,
ref renters,
ref citizenDatas,
ref householdCitizens,
ref buildingDatas,
citizenHappinessParameters,
garbageParameters,
healthcareParameters,
parkParameters,
educationParameters,
telecomParameters,
happinessFactorParametersBuffer,
groundPollutionMap,
noisePollutionMap,
airPollutionMap,
telecomCoverage,
relativeElectricityFee,
relativeWaterFee
);
// Company example call (AddCompanyHappinessFactors is a no-op in provided source):
BuildingHappiness.GetCompanyHappinessFactors(
propertyEntity,
factors,
ref prefabs,
ref spawnableBuildings,
ref buildingPropertyDatas,
ref buildings,
ref officeBuildings,
ref workProviders,
ref renters,
ref buildingDatas,
ref companies,
ref industrialProcessDatas,
ref workplaceDatas,
ref citizens,
ref healthProblems,
ref serviceAvailables,
ref resourceDatas,
ref zonePropertiesDatas,
ref efficiencies,
ref serviceCompanyDatas,
ref availabilities,
ref tradeCosts,
economyParameters,
taxRatesArray,
processesArray,
resourcePrefabs
);
// After calling, inspect/normalize factors as needed to compute final happiness indicators.
// Remember to dispose of NativeArray<int2> when done.