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

Fix: Incorrect error messages on placing water on scenario editor #9560

Conversation

SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Sep 18, 2021

Motivation / Problem

I found some issues when placing sea/canal/river on scenario, the error messages don't always make sense and the behaviour is a little inconsistent when compared with each other. Listed below is the behaviour tested on 12.0-beta2.

On the scenario editor...
Building sea on sea: "Can't build canals here... already built"
Building sea on canal (owner none): "Can't build canals here... already built"
Building sea on canal (company owned): "Can't build canals here... already built"
Building sea on river: "Can't build canals here... already built"

Building canal on sea: builds with no error
Building canal on canal (owner none): "Can't build canals here... already built"
Building canal on canal (company owned): "Can't build canals here... already built"
Building canal on river: builds with no error

Building river on sea: builds with no error
Building river on canal (owner none): "Can't place rivers here... already built"
Building river on canal (company owned): "Can't place rivers here... already built"
Building river on river: overbuilds with no error

On a game...
Building canal on sea: builds with no error, cost £3,750
Building canal on canal (owner none): "Can't build canals here... already built"
Building canal on canal (self-owned): "Can't build canals here... already built"
Building canal on canal (other company): "Can't build canals here... already built"
Building canal on river: builds with no error, cost £3,750

Description

Below is the behaviour after the PR, which seem a bit better.

On the scenario editor...
Building sea on sea: overbuilds with no error
Building sea on canal (owner none): builds with no error
Building sea on canal (company owned): "Can't build canals here... owned by 'company'"
Building sea on river: builds with no error

Building canal on sea: builds with no error
Building canal on canal (owner none): overbuilds with no error
Building canal on canal (company owned): "Can't build canals here... owned by 'company'"
Building canal on river: builds with no error

Building river on sea: builds with no error
Building river on canal (owner none): builds with no error
Building river on canal (company owned): "Can't place rivers here... owned by 'company'"
Building river on river: overbuilds with no error

On a game...
Building canal on sea: builds with no error, cost £3,750
Building canal on canal (owner none): "Can't build canals here... already built"
Building canal on canal (self-owned): "Can't build canals here... already built"
Building canal on canal (other company): "Can't build canals here... owned by 'company'"
Building canal on river: builds with no error, cost £3,750

Limitations

Still incorrect error message for 'Building sea on canal (company owned)'

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 touches english.txt or translations? Check the guidelines
  • 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')

@SamuXarick SamuXarick force-pushed the Fix-Incorrect-error-messages-on-placing-water-on-scenario-editor branch 2 times, most recently from ac07e44 to ca082ad Compare September 18, 2021 14:58
@SamuXarick
Copy link
Contributor Author

It is ready to review now.

src/water_cmd.cpp Outdated Show resolved Hide resolved
@SamuXarick SamuXarick force-pushed the Fix-Incorrect-error-messages-on-placing-water-on-scenario-editor branch from ca082ad to 008e9ac Compare September 18, 2021 20:59
/* can't make water of water! */
if (water && (!IsTileOwner(current_tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue;
/* Allow to make water of water, except in these specific situations.
* The checks done via CMD_LANDSCAPE_CLEAR can provide better error messages if any. */
Copy link
Member

Choose a reason for hiding this comment

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

This comment doesn't really help the reader. "These specific situations" is what is important. As the code is not obvious in what those situations are.
Also, the "make water of water" doesn't make sense anymore.

You have to look at it this way: if you read this in 1 year, would you still understand what this code does? And if not, will the comment help you understanding?

So what are those specific situations? Well, if I understood you correctly, your intentions are:

  • Building a canal on your own canal should be skipped.
  • Building a canal on a OWNER_NONE owned canal should be skipped.

So the comment should at least mention that.

Basically, what you made this if do now, is something like:
Prevent building a canal over your own or OWNER_NONE owned canal.

if (water && (!IsTileOwner(current_tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue;
/* Allow to make water of water, except in these specific situations.
* The checks done via CMD_LANDSCAPE_CLEAR can provide better error messages if any. */
if (water && IsCanal(current_tile) && Company::IsValidID(_current_company) && (IsTileOwner(current_tile, _current_company) || GetTileOwner(current_tile) == OWNER_NONE)) continue;
Copy link
Member

Choose a reason for hiding this comment

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

There are two things in this line that are weird to me.

  • The IsValidID is not obvious why it is there. So either you have to put it in the comment why, but a few lines above they use a more verbose way: _game_mode != GM_EDITOR.
  • For one check you use IsTileOwner, for the next GetTileOwner. Why? Is there something wrong with using IsTileOwner twice? (hint: there isn't, as IsTileOwner executes GetTileOwner)

Additionally changes the behaviour of placing sea on sea/river/canal and placing canal/river on canal to (over)build, instead of disallowing it
@SamuXarick SamuXarick force-pushed the Fix-Incorrect-error-messages-on-placing-water-on-scenario-editor branch from 008e9ac to c42f328 Compare September 19, 2021 10:10
@TrueBrain TrueBrain merged commit 45edd9f into OpenTTD:master Sep 19, 2021
@SamuXarick SamuXarick deleted the Fix-Incorrect-error-messages-on-placing-water-on-scenario-editor branch June 3, 2022 21:13
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.

None yet

2 participants