CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
574 stars 85 forks source link

Parking AI ignores `ElectricCars` district policy and also prevent spawning electric cars at outside connection #1543

Closed krzychu124 closed 2 years ago

krzychu124 commented 2 years ago

Fixes #1527

Update:

Something I found while debugging ParkingAI:

originalfoo commented 2 years ago

Will this affect Vehicle Wealthizer mod by @klyte45

krzychu124 commented 2 years ago

Will this affect Vehicle Wealthizer mod by @klyte45

@aubergine10 if source in github repo is not outdated then it's broken since the release date of Harmony migration.

originalfoo commented 2 years ago

Can this go in to 11.6.5.2? If so pls add milestone in sidebar.

krzychu124 commented 2 years ago

Can this go in to 11.6.5.2? If so pls add milestone in sidebar.

yup, just review and test. I did a lot of tests and debugging. Looks good when running alone.


I also noticed few weird issues while running it and experimenting with bike lanes (cim walked to the intersection closest to position where he parked vehicle and started spamming pathfinding looking for CarPathToParkedVehicle literally 10m away) - need recheck (99.9999% because of shared Car/Bike lane - he thought he is in vehicle while standing on Car/Bike lane 😂)

originalfoo commented 2 years ago

Tourists can spawn electric cars same as in vanilla.

Were tourists able to spawn electric cars prior to this PR?

krzychu124 commented 2 years ago

Tourists can spawn electric cars same as in vanilla.

Were tourists able to spawn electric cars prior to this PR?

Hmm, they couldn't if ParkingAI was active and was not a DummyTourist. Citizens moving-in also couldn't spawn electric car at outside connection, so probably only when student grew up and moved out to ElectricCars district from family house...

krzychu124 commented 2 years ago

One more review @kvakvs, @chameleon-tbn, @kianzarrin?

krzychu124 commented 2 years ago

I improved detection of wrong parked vehicle type in some edge cases. Now they should always use electric car if forced by district policy.

krzychu124 commented 2 years ago

Heh, I thought about possible null vehicle info and slightly refactored behavior for swapping vehicle to eliminate chance of throwing away currently parked vehicle even if it couldn't swap it because of no vehicle info or no free parked vehicle units. The user will still see parked cars in areas where district has forced electric cars - I hope they will figure out quickly that electric car assets are required to make the policy work 😅 (better than despawning "wrong" cars or returning null info even if cim had parked vehicle - could cause other weird issues)

You can test again if you want. I'll merge it later in the evening (it's ~4am here xD).

originalfoo commented 2 years ago

Is it possible to use colour of existing parked vehicle for the swapped vehicle? Sudden colour changes are going to be much more noticeable than shape changes (eg. if white car turns red, vs. red car changes shape).

krzychu124 commented 2 years ago

Is it possible to use colour of existing parked vehicle for the swapped vehicle? Sudden colour changes are going to be much more noticeable than shape changes (eg. if white car turns red, vs. red car changes shape).

How? What's the probability of generating vehicle with the same/similar color? I think that each vanilla electric car has completely different color variants, you can change it in AVO and we are talking only about swapping cars when you drawn district or added policy and cim already has some parked car assigned.

originalfoo commented 2 years ago

How?

Ah, I just checked the code and it's doing GetColor() every frame; I had assumed that would happen once and be stored per [parked] vehicle. The color index is based on pseudo-random value based on vehicleId to ensure color remains same per instance.

At which point my mind starts going way off track... So now I'm wondering how parked vehicle gets the colour of the driving vehicle that just parked? Parked vehicles also get color every frame in the same way - pseudo-random based on parked vehicle id. It's same vehicle prefab - so same colour choices... how on earth does it ensure the id of parked vehicle results in same color _index_ as the id of driving vehicle does? It can't just use the same id between both states, otherwise slots would never free up for other parked/driving vehicles... can it? Have vehicles always been changing color when transitioning between parked/driving and I've just not noticed?
krzychu124 commented 2 years ago

Heh, no idea how those colors are selected and somehow retained on switches between parked and moving. Might be some magic in randomizer but... it uses SimulationManager randomizer so results are pseudo random compared to initializing Randomizer seed with vehicle ID and taking first value(will return always the same).

Anyways... merging :)