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

Feature: [GS] Goal destination can be updated #10817

Merged
merged 1 commit into from Jun 8, 2023

Conversation

mrmbernardi
Copy link
Contributor

@mrmbernardi mrmbernardi commented May 13, 2023

Motivation / Problem

See #10503

The destination of an existing goal object cannot be updated.

Description

I have added the relevant method to the GS.

I refactored the way validity of the goal destination is checked since it's now checked both on creation of goals and on updating the destination.

E.g.

GSGoal.SetDestination(gid, GSGoal.GT_TOWN, 2)

Limitations

The company of an existing goal object still cannot be updated. I'm not sure of the full implications of doing this.

I'm also not sure what CMD_STR_CTRL does regarding the other goal update methods (e.g. set completed), but since they use it, I used it too.

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')

src/goal.cpp Outdated Show resolved Hide resolved
src/script/api/script_goal.hpp Show resolved Hide resolved
Comment on lines +37 to +42
return (type == GT_NONE && destination == 0) ||
(type == GT_TILE && ScriptMap::IsValidTile(destination)) ||
(type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) ||
(type == GT_TOWN && ScriptTown::IsValidTown(destination)) ||
(type == GT_COMPANY && ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)destination) != ScriptCompany::COMPANY_INVALID) ||
(type == GT_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c)));
(type == GT_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c));

Check notice

Code scanning / CodeQL

Complex condition Note

Complex condition: too many logical operations in this expression.
Copy link
Member

Choose a reason for hiding this comment

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

Could this use the new IsValidGoalDestination function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's something I considered. The original author had this code written twice like this. Without understanding the original intention I followed suit.

If I had to guess, the intention seems to be to use functions like ScriptMap::IsValidTile instead of ::IsValidTile, but these functions in ScriptMap mostly just call the global functions anyway. Maybe the intention is to try and make sure the checks obey the logic exposed to the script api.

If you agree this isn't a concern I can replace this with a call to Goal::IsValidGoalDestination

@PeterN PeterN merged commit 35ef6c1 into OpenTTD:master Jun 8, 2023
19 checks passed
mrmbernardi added a commit to mrmbernardi/OpenTTD that referenced this pull request Jul 2, 2023
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

3 participants