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
Fix: Inconsistent error message when overbuilding canal on a lock/ship depot tile #9410
Fix: Inconsistent error message when overbuilding canal on a lock/ship depot tile #9410
Conversation
Apparently, this also fixes inconsistent error messages when overbuilding on dock-water-parts and buoys on sea/canal. |
Wow. This PR is really hard to read .. "rambling by a madman" .. "a day in the life of Samu" .. please do not do this to us. It makes it really hard to understand what you are trying to fix. Additionally, this PR is basically: I fiddled till it worked. And that brings me to: a broken clock is even right twice a day. So let's dive in, see what happened, and what this change actually does. Regarding Those two commits kinda contradict each other. Given the second negates the use for As for the But, that said, when we dive a bit deeper in what that if-statement does, we notice the function has changed so drastically, it no longer really means what it used to. Take this change for example, a12c748, here it was added that using CTRL when placing canals meant placing sea. For that this check is useful, to prevent water being made to water, to nudge the player in the right direction.
Finally, this PR really should be two commits: one removing the @SamuXarick : Are you up for that? Or are you like: way over my head, please take care of it? Edit: I suggest two commits with messages something like this:
Changing to
|
It is not like we will drain the sea first, to put water back in it after. Besides, the cost for draining the sea isn't calculated for all other cases either.
IsTileType() also considers ship depots and locks water. IsWaterTile() does the right thing.
128cbcd
to
4c37d36
Compare
Motivation / Problem
This is a delicate issue.
It originated when my AI was overbuilding a canal on the entry/exit of a lock tile. If the waterclass was canal, I would get a 'Can't build canals here... ... already built' error message, but if the waterclass was sea, I would get 'Can't build canals here... Building must be demolished first'.
OpenTTD/src/water_cmd.cpp
Lines 478 to 485 in d38ad7d
First I discovered that
IsTileType(current_tile, MP_WATER)
can't be used here, due to Ship Depots and Locks also being tiles of the same typeMP_WATER
as Canals. I changed toIsWaterTile(current_tile)
and I thought that would be enough to fix the problem, but it wasn't.Now I was getting 'Can't build canals here... Must demolish canal first'.
I found that
DC_FORCE_CLEAR_TILE
was in the way. It would end up doing these checks:OpenTTD/src/landscape.cpp
Lines 696 to 702 in d38ad7d
I still tried adding some extra checks to line 698, to exclude locks and ship depots, but that would mean I was going against the purpose of
DC_FORCE_CLEAR_TILE
.Went back to the origin of this flag, at line 482 of water_cmd.cpp. Decided to remove the flag, and that finally solved the issue.
Now, the error message is consistent, regardless of waterclass: 'Can't build canals here... Building must be demolished first'. They reach
ClearTile_Water
to get the error string.There is however, behaviour changes when experimenting with tiles of type
MP_OBJECT
. I Loaded NewGRF 'OpenGFX+ Landscape 1.1.2'. When we have a canal, and a rocky land on the canal, overbuilding the canal no longer comes up with an error message saying 'Can't build canals here... ... Must demolish canal first'. Now it overbuilds with no error. Also, if we build a canal on top of a rocky land on sea, the price is also different. It doesn't include the price of clearing sea.Description
Limitations
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.