Game.TourismSystem
Assembly:
Assembly-CSharp (game code)
Namespace:
Game.Simulation
Type:
public class TourismSystem
Base:
GameSystemBase
Summary:
Manages tourism-related simulation for the city. The system aggregates lodging capacity and current tourist counts, computes city-wide attractiveness from AttractivenessProvider components, applies city modifiers, and writes a Tourism component on the city entity with current tourists, lodging, attractiveness and average tourists. It runs its work inside a Burst-compiled IJob (TourismJob) that reads attractiveness providers, lodging providers and renter buffers, and uses data from CitySystem, ClimateSystem and CountHouseholdDataSystem to compute weather-adjusted tourist probability. The class also exposes several static helper methods for computing raw tourist probability and weather effects.
Fields
-
private int2 m_CachedLodging
Cached integer pair used internally to accumulate lodging counts (occupied, total/available). Used to avoid repeated allocations when computing lodging totals. -
private CitySystem m_CitySystem
Reference to the CitySystem instance in the world. Used to get the city entity to write the Tourism component. -
private ClimateSystem m_ClimateSystem
Reference to the ClimateSystem instance in the world. Used to obtain current weather state (temperature, precipitation, rain/snow flags, classification). -
private CountHouseholdDataSystem m_CountHouseholdDataSystem
Reference to the household counting system used to obtain the current number of tourist citizens. -
private EntityQuery m_AttractivenessProviderGroup
EntityQuery selecting AttractivenessProvider components (excludes Temp and Deleted). Used to gather archetype chunks for all attractiveness providers in the city. -
private EntityQuery m_HotelGroup
EntityQuery selecting LodgingProvider and PropertyRenter components (excludes Temp and Deleted). Used to gather lodging (hotel) archetype chunks. -
private EntityQuery m_ParameterQuery
EntityQuery used to read the AttractivenessParameterData singleton which contains parameters controlling the attractiveness/weather math. -
private TypeHandle __TypeHandle
Internal struct containing ComponentTypeHandle/BufferLookup/ComponentLookup handles. Assigned at OnCreateForCompiler to allow fast access inside jobs and OnUpdate. -
private struct TourismJob
(nested, private)
Burst-compiled IJob that performs the main tourism calculations. It: - Reads hotel chunks and attractiveness provider chunks (NativeArray
). - Aggregates lodging occupancy and free rooms from LodgingProvider buffers and Renter dynamic buffers.
- Sums squared attractiveness values from all AttractivenessProvider components, converts that sum into a city attractiveness score with a logistic-like mapping.
- Applies CityModifiers of type Attractiveness to the computed attractiveness.
- Computes average tourists using GetTouristProbability and writes a Tourism component to the city entity.
Notes: - The job uses DeallocateOnJobCompletion for the chunk arrays. - It reads data from climate and household systems passed in as read-only fields.
Properties
- None (no public properties are defined on TourismSystem).
Constructors
public TourismSystem()
Default constructor. The system is created by the ECS world. OnCreate does the actual setup (retrieves other systems and entity queries).
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the update interval for this system. This system returns a hard-coded interval value (32768). The value is used by the game scheduling to control how often the system updates. -
public static int GetTouristRandomStay()
Returns a constant used for tourist random stay calculation (262144). Primarily an internal constant used by game logic. -
public static float GetRawTouristProbability(int attractiveness)
Converts an integer attractiveness value into a raw tourist probability multiplier: attractiveness / 1000f. -
public static float GetTouristProbability(AttractivenessParameterData parameterData, int attractiveness, ClimateSystem.WeatherClassification weatherClassification, float temperature, float precipitation, bool isRaining, bool isSnowing)
Computes the final tourist probability by combining the raw tourist probability (from attractiveness) with weather effects computed by GetWeatherEffect. Use this to get the probability that influences average tourist counts. -
public static float GetWeatherEffect(AttractivenessParameterData parameterData, ClimateSystem.WeatherClassification weatherClassification, float temperature, float precipitation, bool isRaining, bool isSnowing)
Calculates a weather multiplier in the range [0.5, 1.5] based on: - Attractive and extreme temperature ranges and temperature affect parameters from AttractivenessParameterData.
- Rain and snow precipitation effect ranges and associated modifiers.
-
Stormy classification adds an extra factor. This method returns a clamped multiplier which is multiplied with raw tourist probability to obtain the weather-adjusted tourist probability.
-
[Preserve] protected override void OnCreate()
System initialization: - Calls base.OnCreate().
- Retrieves references to CitySystem, ClimateSystem, CountHouseholdDataSystem.
-
Creates entity queries for attractiveness providers, hotels (lodging providers + property renters), and the attractiveness parameter singleton.
-
[Preserve] protected override void OnUpdate()
Main update: constructs and schedules the Burst TourismJob with: - Archetype chunk arrays for attractiveness providers and hotels (ToArchetypeChunkArray with Allocator.TempJob).
- Component/Buffer/Lookup handles obtained via InternalCompilerInterface.GetComponentTypeHandle / GetBufferTypeHandle / GetBufferLookup / GetComponentLookup using the internal __TypeHandle.
- The AttractivenessParameterData singleton.
-
City/Climate/Household data (city entity, isRaining, isSnowing, temperature, precipitation, tourist citizen count, weather classification). The job is scheduled and appended to the system dependency.
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Compiler-generated helper (empty in practice) used during IL2CPP/compilation. Not intended for direct use. -
protected override void OnCreateForCompiler()
Compiler support: calls __AssignQueries and assigns the type handles in __TypeHandle by calling __AssignHandles. Used by generated code to ensure proper setup for the job code paths. -
private struct TypeHandle
(nested)
Contains ComponentTypeHandle/BufferTypeHandle/BufferLookup/ComponentLookup fields used inside OnUpdate and job setup. It exposes a method __AssignHandles(ref SystemState state) that assigns the appropriate handles from the provided SystemState: - LodgingProvider component type handle (read-only)
- Renter buffer type handle (read-only)
- CityModifier buffer lookup (read-only)
- Tourism component lookup (read/write)
- AttractivenessProvider component type handle (read-only)
Remarks about threading and Burst:
- The TourismJob is Burst-compiled and scheduled as an IJob. Data passed into the job uses the Unity.Entities low-level handles and NativeArray
Usage Example
// Example: compute weather-adjusted tourist probability from outside the system
AttractivenessParameterData parameters = /* obtain singleton or construct with game defaults */;
int cityAttractiveness = 120; // example attractiveness value
ClimateSystem.WeatherClassification classification = ClimateSystem.WeatherClassification.Clear;
float temperature = 22f;
float precipitation = 0f;
bool isRaining = false;
bool isSnowing = false;
float probability = TourismSystem.GetTouristProbability(
parameters,
cityAttractiveness,
classification,
temperature,
precipitation,
isRaining,
isSnowing);
// Use probability to influence custom logic or debugging
Debug.Log($"Tourist probability: {probability}");
Notes for modders: - TourismSystem expects game-managed singletons (AttractivenessParameterData) and other systems (CitySystem, ClimateSystem, CountHouseholdDataSystem) to be present. Typically you don't instantiate this system manually — extend or query the Tourism component or use the provided static helpers for compatibility with the game's tourism math. - If you need to change how attractiveness aggregates or how weather affects tourists, consider creating a system that runs at the appropriate phase and modifies the AttractivenessProvider components or the AttractivenessParameterData singleton before TourismSystem executes.