Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add behavior to prevent AI from entering intersections when they are blocked. #628

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martin509
Copy link

In reference to #627 .
Currently, if a road convoy sees an intersection on its route, it will enter that intersection regardless of whether it can actually leave that intersection - if the next spot after the intersection is occupied, this frequently leads to gridlock that can only be stopped by very careful route design. This is not only aggravating but also contrary to the rules of the road in most countries.
For instance, this route where a bus goes A->B->C->D->A is crippled by a single bus entering the intersection:

image
The rule added here checks for if:

  • At the first non-intersection tile after an intersection,
  • There is a road vehicle already in place

If there is, the convoy will wait for that tile to be clear.

image

As far as I can tell, it works fine, but in cases where a tile becomes occupied in between a convoy entering an intersection and it reaching the end, there is still a possibility of a convoy ending up blocked in an intersection. Other than that, this should solve most cases of gridlock from arising.

@MatthewForrester
Copy link

MatthewForrester commented Dec 10, 2023

Thank you so much for this contribution to Simutrans-Extended, Martin! It's always exciting to see a new contributor; identifying a problem and fixing it straight away is a really great way to introduce yourself to the community. Thank you! 👏

James Petts is the project lead and he may be happy to incorporate this patch right away. If so, that's all well and good. But FYI, he usually prefers PRs to be accompanied by a post in the relevant part of the International Simutrans Forum, rather than here.

If that seems annoying or surprising, that's understandable. On 99% of projects what you have done would be perfect. There's an explanation below if you want one.

Or you can head straight over to the forum to focus on your contribution. You might be especially interested in this thread discussing intersections. At that time, it seems like private cars and player vehicles behaved differently at intersections. I am a baby programmer and not at all familiar with vehicle/road_vehicle.cc, so I might have totally misunderstood things, but have you tested your changes with private cars present as well as player vehicles?

There's also a new contributor welcome thread on the forum, though it's totally optional (if you prefer to focus on code, that's fine! ).

Why not discuss PRs on GitHub?
We're not trying to be awkward! It is unusual, since posting on GitHub threads is pretty much standard in the West, and we use GitHub extensively for other things. There would definitely be advantages to a switch.

There are two reasons we don't. Firstly, Simutrans has been in development since the 1990s, long before GitHub or even Git existed, so it's helpful to keep all of the development information in one place, and avoid breaking the existing workflows of project leaders. In particular, the Standard version uses Subversion rather than Git, so we can't fully commit to the GitHub way™ anyway. Secondly, GitHub blocks itself in several countries due to US export control laws. That might be right for them, but we are a harmless transport simulation and our very international community wants to welcome contributors and players from every country.

@martin509
Copy link
Author

Thanks for the reply, Matthew! I can see why the issue of private cars being treated preferentially - which is apparently what would happen at intersections when there used to be a rule in the AI about this - could really interfere with the game. If I'm able to figure out a solution I'll commit that (and general cleaning-up of the code) but if not I might close this PR as I wasn't aware the community had been over this before and removed this rule for a reason. If I do get that done though, I'll make a thread on the forums for discussion.

@jamespetts
Copy link
Owner

Thank you both for your input on this, and apologies for the delay in responding: I have been very busy this week.

Looking at this, I think that I agree with Matthew - you have modified road_vehicle.cc, which only applies to player vehicles, which would have the effect of applying this rule only to player vehicles, not private cars, thus giving private cars precedence over player vehicles at intersections.

What you need to do is add an equivalent rule in simroadtraffic.cc, which is the part of the code that deals with private cars in the game. If you are able to do this, then we should have a system that prevents deadlocks without giving private cars precedence over player vehicles.

Thank you very much for your work on this - it is much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants