22using ColossalFramework . Math ;
33using System ;
44using System . Collections . Generic ;
5- using System . Linq ;
65using System . Text ;
76using TrafficManager . Custom . PathFinding ;
87using TrafficManager . State ;
@@ -19,14 +18,14 @@ internal enum TransportMode {
1918 Taxi
2019 }
2120
22- public static readonly int [ ] FREE_TRANSPORT_USAGE_PROBABILITY = { 90 , 80 , 50 } ;
21+ public static readonly int [ ] FREE_TRANSPORT_USAGE_PROBABILITY = { 95 , 80 , 50 } ;
2322 public static readonly int [ ] TRANSPORT_USAGE_PROBABILITY = { 50 , 40 , 30 } ;
24- public static readonly int [ ] DAY_TAXI_USAGE_PROBABILITY = { 5 , 10 , 50 } ;
25- public static readonly int [ ] NIGHT_TAXI_USAGE_PROBABILITY = { 10 , 40 , 70 } ;
23+ public static readonly int [ ] DAY_TAXI_USAGE_PROBABILITY = { 5 , 25 , 50 } ; // if a taxi is available and assigned to this citizen, this probability kicks in
24+ public static readonly int [ ] NIGHT_TAXI_USAGE_PROBABILITY = { 25 , 75 , 100 } ; // if a taxi is available and assigned to this citizen, this probability kicks in
2625
2726 internal static TransportMode [ ] currentTransportMode = new TransportMode [ CitizenManager . MAX_INSTANCE_COUNT ] ;
2827
29- internal void OnLevelUnloading ( ) {
28+ internal static void OnBeforeLoadData ( ) {
3029 for ( int i = 0 ; i < currentTransportMode . Length ; ++ i )
3130 currentTransportMode [ i ] = TransportMode . None ;
3231 }
@@ -39,6 +38,7 @@ public bool CustomStartPathFind(ushort instanceID, ref CitizenInstance citizenDa
3938
4039 SimulationManager simManager = Singleton < SimulationManager > . instance ;
4140 Citizen . Wealth wealthLevel = citMan . m_citizens . m_buffer [ citizenData . m_citizen ] . WealthLevel ;
41+
4242 bool couldUseTaxi = false ; // could cim use a taxi if it was not forbidden because of randomization?
4343 bool couldUseCar = false ;
4444 bool couldUseBike = false ;
@@ -51,9 +51,14 @@ public bool CustomStartPathFind(ushort instanceID, ref CitizenInstance citizenDa
5151 Singleton < DistrictManager > . instance . m_districts . m_buffer [ 0 ] . m_productionData . m_finalTaxiCapacity != 0u ) {
5252 couldUseTaxi = true ;
5353
54- if ( currentTransportMode [ instanceID ] == TransportMode . Taxi || ( currentTransportMode [ instanceID ] == TransportMode . None &&
55- ( ( simManager . m_isNightTime && simManager . m_randomizer . Int32 ( 100 ) < NIGHT_TAXI_USAGE_PROBABILITY [ ( int ) wealthLevel ] ) ||
56- ( ! simManager . m_isNightTime && simManager . m_randomizer . Int32 ( 100 ) < DAY_TAXI_USAGE_PROBABILITY [ ( int ) wealthLevel ] ) ) ) ) {
54+ if ( currentTransportMode [ instanceID ] == TransportMode . Taxi ||
55+ ( currentTransportMode [ instanceID ] == TransportMode . None &&
56+ (
57+ ( ! Options . realisticMassTransitUsage && simManager . m_isNightTime && simManager . m_randomizer . Int32 ( 2 ) == 0 ) ||
58+ ( Options . realisticMassTransitUsage &&
59+ ( ( simManager . m_isNightTime && simManager . m_randomizer . Int32 ( 100 ) < NIGHT_TAXI_USAGE_PROBABILITY [ ( int ) wealthLevel ] ) ||
60+ ( ! simManager . m_isNightTime && simManager . m_randomizer . Int32 ( 100 ) < DAY_TAXI_USAGE_PROBABILITY [ ( int ) wealthLevel ] ) ) )
61+ ) ) ) {
5762 wouldAffordTaxiVoluntarily = true ; // NON-STOCK CODE
5863 }
5964 }
@@ -72,18 +77,22 @@ public bool CustomStartPathFind(ushort instanceID, ref CitizenInstance citizenDa
7277 }
7378 }
7479
75- byte districtId = Singleton < DistrictManager > . instance . GetDistrict ( startPos ) ;
76- DistrictPolicies . Services servicePolicies = Singleton < DistrictManager > . instance . m_districts . m_buffer [ ( int ) districtId ] . m_servicePolicies ;
77- int transportUsageProb = ( servicePolicies & DistrictPolicies . Services . FreeTransport ) != DistrictPolicies . Services . None ? FREE_TRANSPORT_USAGE_PROBABILITY [ ( int ) wealthLevel ] : TRANSPORT_USAGE_PROBABILITY [ ( int ) wealthLevel ] ;
78-
7980 bool useTaxi = false ;
8081 bool useBike = false ;
8182 bool useCar = false ;
8283 bool usePublicTransport = false ;
8384
8485 if ( ( citizenData . m_flags & CitizenInstance . Flags . CannotUseTransport ) == CitizenInstance . Flags . None ) { // STOCK CODE
86+ int transportUsageProb = 0 ;
87+ if ( Options . realisticMassTransitUsage ) {
88+ byte districtId = Singleton < DistrictManager > . instance . GetDistrict ( startPos ) ;
89+ DistrictPolicies . Services servicePolicies = Singleton < DistrictManager > . instance . m_districts . m_buffer [ ( int ) districtId ] . m_servicePolicies ;
90+ transportUsageProb = ( servicePolicies & DistrictPolicies . Services . FreeTransport ) != DistrictPolicies . Services . None ? FREE_TRANSPORT_USAGE_PROBABILITY [ ( int ) wealthLevel ] : TRANSPORT_USAGE_PROBABILITY [ ( int ) wealthLevel ] ;
91+ }
92+
8593 if ( currentTransportMode [ instanceID ] == TransportMode . PublicTransport || useTaxi ||
86- ( currentTransportMode [ instanceID ] == TransportMode . None && simManager . m_randomizer . Int32 ( 100 ) < transportUsageProb ) ) {
94+ ! Options . realisticMassTransitUsage ||
95+ ( Options . realisticMassTransitUsage && currentTransportMode [ instanceID ] == TransportMode . None && simManager . m_randomizer . Int32 ( 100 ) < transportUsageProb ) ) {
8796 usePublicTransport = true ;
8897 }
8998 }
0 commit comments