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: Towns can build tunnels #8473

Merged
merged 1 commit into from Jan 8, 2021

Conversation

2TallTyler
Copy link
Member

@2TallTyler 2TallTyler commented Jan 1, 2021

Motivation / Problem

In mountainous terrain, OpenTTD towns build roads up and over tall mountains, which often looks silly. Tunneling looks better while still allowing the town to grow.

Also, building a rail line on a raised embankment when Towns can build level crossings is off blocks town growth since it cannot bridge over the tracks. Now, towns can also tunnel under these and other obstructions.

Description

A town can build a tunnel through a mountain if the uphill slope is 4 or more tiles, and the length of the tunnel is within the limit. This limit begins at 8 tiles, the minimum for tunneling through a mountain which has 4 uphill tiles on each side, and increases by 1 for every 1,000 population, as in #8439.

When building under obstructions, the length limit is 5, enough to tunnel under a four-track railway.

I have created a test savegame to check most scenarios I could think of: Town_Tunnel_Test_1.zip

Limitations

  • Towns will not terraform the start tile of the tunnel like they will the end tile, so it needs to be a standard inclined slope to attempt building a tunnel — no steep slopes or half slopes.
  • Although my code closely mirrors GrowTownWithBridge() and checks the next tile after the tunnel as I added in Change: Towns don't build dead-end road bridges #8401, it doesn't recognize road stations as a valid next tile. But bridges are fine, even when constructed by a player company. I'm not sure what's going on here and would appreciate some help. This is a bug in Change: Towns don't build dead-end road bridges #8401 and will be fixed in a separate PR.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@michicc michicc added candidate: needs considering This Pull Request needs more opinions preview This PR is receiving preview builds size: small This Pull Request is small, and should be relative easy to process labels Jan 1, 2021
@DorpsGek DorpsGek temporarily deployed to preview-pr-8473 January 1, 2021 11:01 Inactive
@TrueBrain TrueBrain added candidate: yes This Pull Request is a candidate for being merged work: minor details This Pull Request has some minor details left to do and removed candidate: needs considering This Pull Request needs more opinions labels Jan 5, 2021
@TrueBrain TrueBrain added this to the 1.11.0 milestone Jan 5, 2021
Copy link
Member

@TrueBrain TrueBrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall code looks good; haven't tested the PR yet, will do that after the fixes :)

src/town_cmd.cpp Outdated Show resolved Hide resolved
src/town_cmd.cpp Show resolved Hide resolved
src/town_cmd.cpp Outdated Show resolved Hide resolved
src/town_cmd.cpp Show resolved Hide resolved
src/town_cmd.cpp Show resolved Hide resolved
src/town_cmd.cpp Outdated Show resolved Hide resolved
@TrueBrain
Copy link
Member

Owh, would you mind checking if deleting towns works as expected? I remember vaguely there is code for bridges to make sure that towns that grew beyond bridges also clean up correctly. This is needed for map generation, if I remember correctly :) Tnx!

@2TallTyler
Copy link
Member Author

Sure, I can take a look in scenario editor. I'll also have to check the Migrations GS, which shrinks towns and leaves bridges behind (on purpose). Need to make sure that won't crash the game.

@DorpsGek DorpsGek temporarily deployed to preview-pr-8473 January 8, 2021 15:53 Inactive
@DorpsGek DorpsGek temporarily deployed to preview-pr-8473 January 8, 2021 15:54 Inactive
@2TallTyler
Copy link
Member Author

Owh, would you mind checking if deleting towns works as expected?

I have tested and can confirm that deleting towns in Scenario Editor works fine. GameScripts which delete roads during gameplay, such as Migrations, also work properly when deleting tunnels constructed by a town.

@2TallTyler 2TallTyler marked this pull request as draft January 8, 2021 16:34
@2TallTyler 2TallTyler marked this pull request as ready for review January 8, 2021 16:57
Copy link
Member

@TrueBrain TrueBrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks absolutely amazing! Well done :)

@TrueBrain TrueBrain merged commit 9c0da68 into OpenTTD:master Jan 8, 2021
@2TallTyler 2TallTyler deleted the grow_town_with_tunnel branch January 8, 2021 17:42
@2TallTyler 2TallTyler restored the grow_town_with_tunnel branch February 24, 2021 21:44
@2TallTyler 2TallTyler deleted the grow_town_with_tunnel branch February 27, 2021 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
candidate: yes This Pull Request is a candidate for being merged preview This PR is receiving preview builds size: small This Pull Request is small, and should be relative easy to process work: minor details This Pull Request has some minor details left to do
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants