CitiesSkylinesMods / TMPE

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

Car accidents / breakdowns #61

Open originalfoo opened 5 years ago

originalfoo commented 5 years ago

On Steam, you mentioned this should be separate mod, and I agree.

However, IMO, it will need tight integration with TM:PE so just jotting down some thoughts here....

Choosing accident sites:

Making the accident happen:

Additional visualisation:

Things to consider:

krzychu124 commented 5 years ago

Many thanks for your thoughts. I would like to see that in game in the future. I agree with you that would need tight integration but it's still possible to call TM:PE functions from outside from any other mod if we set that functions to public scope. In this case any data we are collecting about road usage and actual traffic lights state would be easily accessible.

In my opinion some of your ideas could greatly help with development of this epic feature (#14 , #26 ). In addition i've been thinking about making cars to pull over if emergency vehicle is coming from behind to decrease time needed to reach their destination.

As far as I know we could also use built-in Transfer Manager to create offers for emergency services. That would solve problems with managing paths to accident location.

Traffic Manager 2.0 :smile:

pcfantasy commented 5 years ago

Nice idea,I also think about those ideas, let us make this happen in the future

originalfoo commented 5 years ago

The desire for accidents and breakdowns has been around since the game was launched, and people regularly mention it in respect to traffic mods, but also more generally in discussion forums, reddit, etc.

Vehicle breakdowns would be nice too. I see there's already a mod that makes vehicles require fuel; maybe they could break down if they run out before being able to refuel/recharge. It would likely need a new 'vehicle recovery' service (tow trucks, etc). There are some vehicle assets in the workshop that would suit such a service, they would need updating to have flashing lights when "on call", but building assets for the services would also be required. Towing vehicles would treat the broken down vehicle as a trailer to the towtruck. My assumption is that any vehicle can be towed by any other vehicle as far as the code is concerned.

Speaking of flashing "on call" lights, it's always bugged me how emergency vehicles turn their lights out as soon as they reach destination, rather than waiting until the emergency is fixed. This would be particularly problematic in the case of accident response; if there's a crash the emergency services keep their flashing lights on to warn drivers of the crash.

For making vehicles move out of the way for emergency vehicles, jfarias was experimenting with that back in T++ days. He mentioned having a basic implementation working, so there might be something lurking in a branch or tag of the old T++ repo. Vehicles could take advantage of parking lanes, bike lanes, bus lanes, etc. However, even with vehicles trying to move out of the way, there might still be some roads that don't facilitate such actions (like small 1u alley road from NeXT2).

At some point it might be worth doing some docs to help people integrate their mods with T++. Not API docs, maybe just pointers to where to look in the code and summaries of some useful functions with a few Do's and Don'ts? TMPE could possibly provide some helper functions for common things, like "is this junction dangerous" or "does this road have emergency lanes" and so on.

pcfantasy commented 5 years ago

@aubergine10

The mod you mentioned that makes vehicles require fuel is written by me. I tried to make vehicles break down if they run out before being able to refuel/recharge, but It is hard for me to implement items like you said such as "other vehicles try and route around it" or "Visual effect: fire / smoke / steam (depending on severity of crash)"

Strdate commented 5 years ago

@pcfantasy Visual effect can be seen in this mod https://steamcommunity.com/sharedfiles/filedetails/?id=780720853 I learned about it today

originalfoo commented 5 years ago

@AdamDri That mod adds the effect to all instances of a vehicle though? For car crashes I think it would be easier to just use the steam/smoke/fire/etc spawn points that come with the base game. Benefit is that they would automatically be included in save game (they are just props) and it would be easy to clear up after the crash (just remove those props within small radius of the accident).

krzychu124 commented 5 years ago

There should be a way to spawn that effect on demand, I think

originalfoo commented 5 years ago

The smoke/steam/fire? Yes, just place the props, User can already spawn those props using "Find It" mod (search "steam" or "smoke" etc and you will find the props, you can just plop them on the map and they work instantly).

pcfantasy commented 5 years ago

Guys, Let me remind you something.

The key point for whatever car breakdown or car crash function is , we need to let cars change lanes not only in nodes.

In current game, cars can change lanes only inside nodes, so if a car breakdown, the other car behinds it can not change lanes to continue their trips.

originalfoo commented 5 years ago

Isn't that kind of what we want anyway? That breakdowns and accidents cause traffic jams?

As mentioned in OP, we could even mark road segments as blocked. (Note: I suspect that marking a segment as blocked will cause cars within that segment to do an in-road u-turn and leave the segment)

pcfantasy commented 5 years ago

@aubergine10

Ok, I understand your idea. I may try to write a mod first to test this.

originalfoo commented 5 years ago

Yes, it should definitely start as some small test mods just to try out different aspects of what would be required.

For example:

Each of these little mods would be useful for other devs to look at as they can see in a small package how to achieve a certain thing. So sources should be in github.

pcfantasy commented 5 years ago

@aubergine10

So I quickly check the codes, blocked flag can add on segments, but if there is a car accident in 8-way road, we have to block the whole road?

That seems not real.

originalfoo commented 5 years ago

Yes, that is somewhat excessive. Ideally we only want to block on single side of road (and maybe reduce speed on other side of road as drivers will slow down to look at accident lol).

But if you can determine how the 'blocked' flag works, I mean, how it makes vehicles avoid that route and (I don't know if this happens, you'd need to test) if it makes cars already on the blocked segment turn around and find new route, then we could perhaps create a custom version of "blocked" that only affects one side of segment.

Note: "One side of a road" actually means "a set of adjacent road vehicle lanes going in same direction". (there are some roads that sort of split in multiple sections like this)

pcfantasy commented 5 years ago

@aubergine10
Do you know how do create a prop?

Is there any mod I can use as a reference?

originalfoo commented 5 years ago

Find It mod places props.

pcfantasy commented 5 years ago

@aubergine10 No I mean how to use code to spawn a prop on the road. There is a method to CreateProp, but I do not know how to get a PropInfo of a certain prop public bool CreateProp(out ushort prop, ref Randomizer randomizer, PropInfo info, Vector3 position, float angle, bool single)

originalfoo commented 5 years ago

I don't know, sorry. Find It mod obviously has to get prop info to list props and allow user to place them on the map, so digging through source of that mod should help: https://github.com/SamsamTS/CS-FindIt

Strdate commented 5 years ago

You can disable pathfinding on the affected lanes and force recalculation when vehicles approach. What regards the visual part of this, when you check the Vehicle Effects mod you should find out how to spawn these visuals on selected vehicles only.

When you delete a road in vanilla game, the vehicles fly to other nearby road as was mentioned. Maybe in case of an accident if you removed lanes on one part of the road, vehicles would move to the other and it wouldn't even look like flying but be realistic enuf. But I don't know.

originalfoo commented 5 years ago

Car crashes could be implemented using custom simulation step in the CarAI, similar to how blown or flood vehicles are handled (branched off at the start of the main simulation step).

originalfoo commented 5 years ago

Related idea from @kvakvs : Vehicle breakdowns

a friend of mine had an idea, not sure if he ever begins doing that. Make cars break sometimes, make car collisions and crashes. And not just general breakdown, but one of car parts can break producing different effects which you can observe (slow down, smoke, stop and block the lane, etc)

r59andrey commented 4 years ago

make it so that at crossroads without a traffic light, the transport was stupid (driving slowly).

richaell commented 4 years ago

It's been a while since this was mentioned. Any updates on ideas or new ways to implement these? @pcfantasy @krzychu124