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

Missing in GSRail::RemoveRailTrack's documentation #5853

Closed
DorpsGek opened this issue Jan 7, 2014 · 6 comments
Closed

Missing in GSRail::RemoveRailTrack's documentation #5853

DorpsGek opened this issue Jan 7, 2014 · 6 comments
Labels
component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)

Comments

@DorpsGek
Copy link
Member

DorpsGek commented Jan 7, 2014

idioty opened the ticket and wrote:

I found a missing thing in script documentation:
IsRailTypeAvailable(GetCurrentRailType()) in the GSRail::RemoveRailTrack()'s precondition.
I did not understand why it does not work.
If I set any railtype with GSRail.SetCurrentRailType() function, RemoveRailTrack() works.

Reported version: Version?
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/5853
@DorpsGek
Copy link
Member Author

DorpsGek commented Jan 7, 2014

idioty wrote:

I tried with 1.2.0, 1.3.3 and 1.4.0-beta1 version of OpenTTD in Mac OSx 10.9.


This comment was imported from FlySpray: https://bugs.openttd.org/task/5853#comment12904

@DorpsGek
Copy link
Member Author

krinn wrote:

I think the doc is fine.
But the DoCommand need a valid railtype pass.

This is how it is fix in RemoveRail :
if (!IsRailTypeAvailable(GetCurrentRailType())) SetCurrentRailType(GetRailType(tile));

So this part is missing in RemoveRailTrack and if someone didn't set a railtype the docommand will fail.

But you should note the doc help for SetCurrentRailType : http://nogo.openttd.org/api/trunk/classGSRail.html# 32966cfb53f523d9bbed7f6b3f281854
"Set the RailType for all further GSRail functions. "
This kinda imply a default precondition for any rail functions, so you should always set a railtype before using any other rail functions, including after loading a game (i suppose this is how you find the bug).


This comment was imported from FlySpray: https://bugs.openttd.org/task/5853#comment12908

@DorpsGek
Copy link
Member Author

idioty wrote:

Ok, thx!
But I saw in other documentation of function, example: GSRail::BuildRailDepot.
I think this is necessary in documentation.
I can't use any rail function before this, so I could not!
I searched for about an hour, that does not work....
no matter... :)


This comment was imported from FlySpray: https://bugs.openttd.org/task/5853#comment12910

@DorpsGek
Copy link
Member Author

krinn wrote:

It's documented in build functions, as prior to build something you must know what kind of railtype to use.
While this function is to remove something that exists, so it imply you have create it first (so set a railtype before to create the rail)...

That's why i suppose you got that bug because you are loading a savegame, where you could have rails built already, while still never have set any railtype. I'm not sure if any newGRF can invalidate a railtype itself by date or other usage, and i don't think right now any AI can brought another company.
You might fall into this if you AI have its randomai setting enable, and the ai is use intead of another one and seeing rails built by other ais. But again, that will happen when loading too.
Notice the dead end : if a newGRF add a railtype, you create rails with it, but when loading the savegame without the newGRF, no railtype is avaiable now because of the missing newGRF : so this function will always fail, even rails exists on the map. This is that kind of awkard situation that made devs change openttd to not allow missing newGRF savegame to be loaded without a trick.

So in order to build, you must know the railtype to use, but in order to remove, you need any railtype set to let the docommand works (well, this is how i understand its need, i might be wrong, but i don't think you need the same railtype as the rail to remove, as you pass the railbit to remove, no need to know really the railtype of the rail), and this is why RemoveRailTrack just try to pass the current railtype to the docommand, as you need one, but any.
I don't think the doc need a change, just adding the missing <if (!IsRailTypeAvailable(GetCurrentRailType())) SetCurrentRailType(GetRailType(tile));> will do the job fine.

You should make a better handling at using SetCurrentRailType, maybe the SetCurrentRailType doc could be change to emphasis even more it's really a precondition to any rails functions, anyway, you'll get into trouble at not taking enough care about this one when new railtype appears in game, you'll see how easy you'll be end with mixed railtype in your constructions.


This comment was imported from FlySpray: https://bugs.openttd.org/task/5853#comment12912

@DorpsGek
Copy link
Member Author

idioty wrote:

Yeah, I did not find the GSRail description that is a prerequisite.
I've never made ​​AI, never even brought up rails, so I did not know about it.
I just want to remove rails due to suction. :)

... sorry my bad english, I don't speak english! :)


This comment was imported from FlySpray: https://bugs.openttd.org/task/5853#comment12915

@DorpsGek
Copy link
Member Author

frosch closed the ticket.

Reason for closing: Fixed

in r26279. Setting railtype is no longer required for removing rail. It will remove any railtype anyway.


This comment was imported from FlySpray: https://bugs.openttd.org/task/5853

@DorpsGek DorpsGek added flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) Goal/Game script labels Apr 7, 2018
@frosch123 frosch123 added the component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) label Apr 14, 2018
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) flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)
Projects
None yet
Development

No branches or pull requests

2 participants