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
Merged

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 #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 #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')
Copy link
Member

@TrueBrain TrueBrain left a comment

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
src/town_cmd.cpp Show resolved Hide resolved
@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Jan 6, 2021

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

@2TallTyler 2TallTyler commented Jan 6, 2021

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.

@2TallTyler 2TallTyler force-pushed the 2TallTyler:grow_town_with_tunnel branch from e6829c0 to 8729b64 Jan 8, 2021
@DorpsGek DorpsGek temporarily deployed to preview-pr-8473 Jan 8, 2021 Inactive
@2TallTyler 2TallTyler force-pushed the 2TallTyler:grow_town_with_tunnel branch from 8729b64 to 7f333df Jan 8, 2021
@2TallTyler
Copy link
Member Author

@2TallTyler 2TallTyler commented Jan 8, 2021

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 Jan 8, 2021
@2TallTyler 2TallTyler marked this pull request as ready for review Jan 8, 2021
Copy link
Member

@TrueBrain TrueBrain left a comment

It looks absolutely amazing! Well done :)

@TrueBrain TrueBrain merged commit 9c0da68 into OpenTTD:master Jan 8, 2021
8 checks passed
8 checks passed
Emscripten
Details
Commit checker
Details
Check preview needs update Check preview needs update
Details
Linux (clang, clang++)
Details
Linux (gcc, g++)
Details
Mac OS (x64, x86_64)
Details
Windows (x86)
Details
Windows (x64)
Details
@2TallTyler 2TallTyler deleted the 2TallTyler:grow_town_with_tunnel branch Jan 8, 2021
@2TallTyler 2TallTyler restored the 2TallTyler:grow_town_with_tunnel branch Feb 24, 2021
@2TallTyler 2TallTyler deleted the 2TallTyler:grow_town_with_tunnel branch Feb 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants