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

Open
wants to merge 2 commits into
base: master
from

Conversation

@ldpl
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

James103 commented Oct 22, 2019

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

nielsmh commented Oct 22, 2019

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

@ldpl

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

James103 commented Oct 23, 2019

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

James103 commented Oct 25, 2019

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

This comment has been minimized.

Copy link
Contributor Author

ldpl commented Oct 29, 2019

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

@James103

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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 left a comment

Missing script changelog entry as well

/* Update the toolbar. */
InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);

This comment has been minimized.

Copy link
@LordAro

LordAro Nov 14, 2019

Member

why only road & ship?

This comment has been minimized.

Copy link
@James103

James103 Nov 27, 2019

Contributor

Can you test this to see if it works?

Suggested change
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
if (e->type == VEH_TRAIN) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_RAIL);
if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);

This comment has been minimized.

Copy link
@ldpl

ldpl Dec 1, 2019

Author Contributor

Because only ship and road windows can be opened when no vehicles are available. Or so it was before NRT, now it's ship window only. I can remove update for the road window if you want but IMO it should be fixed on NRT side since building roads kind of makes sense even without road vehicles (for towns).

src/script/api/script_engine.hpp Outdated Show resolved Hide resolved
@ldpl ldpl force-pushed the ldpl:enable-vehicle-for-company branch 3 times, most recently from 3d86f34 to 40fec79 Dec 1, 2019
src/engine.cpp Outdated Show resolved Hide resolved
@ldpl ldpl force-pushed the ldpl:enable-vehicle-for-company branch from 40fec79 to f7d9b68 Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.