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

GS method to control engine availability for a specific company #7791

Merged
merged 2 commits into from Jan 15, 2020

Conversation

ldpl
Copy link
Contributor

@ldpl ldpl commented Oct 21, 2019

Just a simple method that uses existing Engine::company_avail mask and allows GS to do tech trees and such.

GS for testing: techstump.zip

@James103
Copy link
Contributor

Could you also make it so Game Scripts can remove engines from the purchase menu of a company? This should allow for things like "researching teck X obsoletes engine Y", events like "This engine is only available for purchase in December", and more.

@nielsmh
Copy link
Contributor

nielsmh commented Oct 22, 2019

+1 to @James103 idea, there should be plenty of space in p2 to add a flag for enable, disable, or perhaps even "reset to default".

@andythenorth
Copy link
Contributor

andythenorth commented Oct 22, 2019

Idea with a different scope, but related: actual tech tree in newgrf, that GS could query.

Could be done as:

  • property with arbitrary strings or labels for things like engine 'role' (a schema shared between newgrf and GS authors)
  • or a 'vehicle replaced by' property, so that a DAG of vehicles can be built, and exposed to GS
    • this could then also be used by OpenTTD to automate the fiddly model life / reliability period calculation which newgrfs have to do currently to handle buy menu expiry
    • this could then also be used (by GS?) to adjust model life, keeping vehicles around for many game years, which seems to be a big chunk of what daylength advocates want
    • this could be used to draw a tech tree in game
    • one gotcha, tech tree branches may be merged and forked, so 'replaced by' might need to be a list, which introduces a lot more faff in every layer (API, consumers)
  • or combination of both ideas, so that branches of tech tree can be given a label, for e.g. 'role' and a GS could 'award a new freight engine' or whatever

If there's any interest, I can copy this to a new issue.

I've been experimenting with rendering tech trees in different formats:

@ldpl
Copy link
Contributor Author

ldpl commented Oct 22, 2019

@James103, @nielsmh I refrained from doing remove method since I was concerned it may have some undesirable side-effects and I don't rly like an idea of anything becoming obsolete anyway. But I checked and it seems it should be ok as existing mechanics already uses that mask for making vehicles obsolete so I guess I'll try adding the method.

@andythenorth IMO GameScripts shouldn't work with unknown newgrfs and for known ones it's better to have tech tree on a website like you do rather than hidden behind some api so it's easier for gs developer to read. Some GUI for GS to show tech tree would be nice (like any other GS GUI) but it's unclear to me how should it look/work. Tbh I'm mostly thinking of making linear tech progressions atm, and have no ideas for any meaningful "tree" thing as there is always the best engine in OpenTTD.

@nielsmh
Copy link
Contributor

nielsmh commented Oct 22, 2019

What happens reliability-wise when a vehicle is introduced long before its planned introduction date?

@ldpl
Copy link
Contributor Author

ldpl commented Oct 22, 2019

@nielsmh AFAICT reliability calculations don't rely on company_avail mask at all, so it should be just using it's initial reliability (same as it works with preview).

@nielsmh
Copy link
Contributor

nielsmh commented Oct 22, 2019

So if you get a vehicle 10 years before its regular introduction, it'd be stuck at 50% or so max reliability for the first 9 years? I guess that makes sense.

@ldpl
Copy link
Contributor Author

ldpl commented Oct 22, 2019

@nielsmh Yep. Though I have no idea why would anyone want to use this method with breakdowns enabled (or, well, enable them at all :p).

@James103
Copy link
Contributor

How would you handle a Game Script removing an engine from the purchase menu of a company despite having "vehicles never expire" set to true? Would the engine still be removed from the purchase menu?

@nielsmh
Copy link
Contributor

nielsmh commented Oct 23, 2019

The general concept of GS is that it overrides all other rules. If the GS says you can't build a certain vehicle model, then you can't build it, regardless of the general expiry rules. (It could be the GS has a concept of being in good/bad standing with a vehicle manufacturer, so depending on player actions you will be permitted/refused to purchase certain models.)

@James103
Copy link
Contributor

Another way that this feature can be helpful for is if you wanted to use the in-game date as some sort of timer (like how OpenRCT2 does it). A Game Script that enables all engines for all companies at the start of the game would be helpful in this situation.

@ldpl ldpl changed the title GS method to allow company to use an engine before its intro date GS method to control engine availability for a specific company Oct 29, 2019
@ldpl
Copy link
Contributor Author

ldpl commented Oct 29, 2019

Added a method to retire vehicles.
GS for testing: techtroll.zip

@James103
Copy link
Contributor

James103 commented Oct 29, 2019

It's been over 11 days since the checks have triggered and passed. Why haven't the "OpenTTD CI (Windows Win32)" check passed yet on GitHub's side even though it passed on Azure's side?

I feel like that because of this error in OpenTTD CI system, this PR may not be able to be merged unless committed to again, or maybe even at all.

@James103
Copy link
Contributor

James103 commented Nov 2, 2019

Is it possible to have a Game Script repeatedly enable and disable an engine for some company? (enable, disable, re-enable, ...)? If so or if you can make it so, then that would allow for engines available only under certain conditions not tied to the date, such as "Only purchasable in December", or "Must have 500+ performance rating", or "Must have 100+ road vehicles", or "Must maintain consistent 100t oil/month supply", or other such conditions as defined and implemented by the game script?

@ldpl
Copy link
Contributor Author

ldpl commented Nov 2, 2019

@James103 Sure, if you check techtroll GS I attached all it does is constantly enabling and disabling engines.

Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

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

Missing script changelog entry as well

src/engine.cpp Show resolved Hide resolved
src/script/api/script_engine.hpp Outdated Show resolved Hide resolved
@ldpl ldpl force-pushed the enable-vehicle-for-company branch 3 times, most recently from 3d86f34 to 40fec79 Compare December 1, 2019 11:56
src/engine.cpp Outdated Show resolved Hide resolved
@ldpl ldpl force-pushed the enable-vehicle-for-company branch from 40fec79 to f7d9b68 Compare December 2, 2019 10:50
@ldpl ldpl requested a review from LordAro January 11, 2020 00:06
@nielsmh nielsmh added the component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) label Jan 15, 2020
@nielsmh nielsmh merged commit d7a928a into OpenTTD:master Jan 15, 2020
douiwby pushed a commit to douiwby/OpenTTD that referenced this pull request Apr 16, 2020
…any (OpenTTD#7791)

* Feature: GS method to allow company to use an engine before its introduction date

* Feature: GS method to retire an engine early for a specific company
@ldpl ldpl deleted the enable-vehicle-for-company branch September 4, 2020 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants