Refit orders patch

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Siggie
Engineer
Engineer
Posts: 3
Joined: 28 Aug 2014 08:11

Refit orders patch

Post by Siggie »

Hello,
When I was playing with newGRFs FIRS and openGFX+trains I noticed that refit at station 'didn't work properly'. I tried out other train GRFs and noticed that some even do not allow refit at stations. So I decided to dive into openTTD development to fix this 'bug'. After some hours of reading code I understood the game mechanic behind the refit at station orders and noticed that the behavior I saw is not a bug but is intended. But I was still unhappy with it. So I decided to create this patch to get my desired behavior. What I basically did is:
- introduced a setting to allow refit at station orders even if the GRF set does not
- introduced a setting that allows refitting at station even if it causes costs
- incorporated some logic that only refits as many trucks as needed.

My intension was that in my opinion a cargo truck does not need to go to a depot for refitting to all other cargos. For example a truck carrying some goods (lets say computers) can be used for carrying alcohol (lets say beer or bottles of spirits) without any refitting as everything is packaged in boxes. This ability is provided by the refit at station orders in openTTD. But these orders are currently only allowed if the GRF set allows it and if the refitting does not cause any costs. With my patch the player can decide by himself if he wants to use refitting orders for all vehicles/cargos or if he plays like it was intended by the GRF developer.

The patch file attached is be applied against release 1.4.2.

As these changes are my first steps in openTTD development I am happy about all of your comments especially I didn't know which flags I should use for the new settings.

Thanks!

Edit: I uploaded the wrong patch file. Sorry for that! Here is the correct one.
Attachments
refit_vs_1.4.2.patch
new version 16. September 2014
(9.27 KiB) Downloaded 119 times
Last edited by Siggie on 16 Sep 2014 15:02, edited 1 time in total.
User avatar
kamnet
Moderator
Moderator
Posts: 8586
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: Refit orders patch

Post by kamnet »

Having automatic refits at stations even if they cost is a good way for a payer's route to quickly become unprofitable.
Eddy Arfik
Transport Coordinator
Transport Coordinator
Posts: 260
Joined: 09 Apr 2014 11:10

Re: Refit orders patch

Post by Eddy Arfik »

I'm not sure a source code patch against a specific release which will (most likely) break savegame compatability with trunk is the best approach to this problem, it's like putting a new engine in your car just because the oil needs changing. The betterer solution would be to modify the refit properties of the OpenGFX+ vehicle sets, it will give the same gameplay but with much less nasty side-effects. Also many of the newGRF's released recently have already set the refits to behave in this way, I'm not sure why you say most sets do not allow station refit
aantono
Traffic Manager
Traffic Manager
Posts: 211
Joined: 15 Apr 2010 21:01
Location: Midwest, US

Re: Refit orders patch

Post by aantono »

What do you do about the old sets that are no longer being maintained, the authors are gone and the source code is not available?
Eddy Arfik
Transport Coordinator
Transport Coordinator
Posts: 260
Joined: 09 Apr 2014 11:10

Re: Refit orders patch

Post by Eddy Arfik »

Source code is easily obtained for any newGRF if you understand grfcodec and nfo code, assuming the license allows it even old, unmaintained sets can be edited in this way. If not, no-one is forcing any particular grf to be used, you could always use one of the newer sets. My point was the place to fix grf issues is in the grf, hacking the core game code to achieve this creates too many unwanted side effects. Even a patch against latest trunk would be better than patching against an almost outdated stable release.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Refit orders patch

Post by planetmaker »

Siggie wrote:Hello,
When I was playing with newGRFs FIRS and openGFX+trains I noticed that refit at station 'didn't work properly'.
If you have anything in specific which needs improvement with OpenGFX+Trains, please say so. I made a bit of an effort so that the wagons there allow station refit when the refit seems reasonable to me (with or without cost, if memory serves me well). However refits which require "realistically" some modification to the wagon are only allowed in depots. Maybe the station refit rules could and should be relaxed more - but then I need to know what needs to get better where. Patches in the form of source code patches for that NewGRF would be especially welcome. If we want to discuss it further, we should use its own thread or its issue tracker (especially for patches).
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Refit orders patch

Post by PikkaBird »

Siggie wrote:But these orders are currently only allowed if the GRF set allows it and if the refitting does not cause any costs.
This isn't actually true; station refits can absolutely cost money with the current spec (using callback 15e or refit_cost). If every newgrf author who has implemented station refits has had the sense to make them free, perhaps that tells us something. ;)
planetmaker wrote:However refits which require "realistically" some modification to the wagon are only allowed in depots. Maybe the station refit rules could and should be relaxed more
"Realism" is a bad feature. :)

Limiting station refits by what was "realistic" was how I did it for UKRS2, too, but for Pineapple Trains I decided it was better for gameplay if every refit which could be done in the depot could also be done at a station. It's simply less confusing for players - and those players who don't like the "unrealism" of reusing an oil tanker for beer can just not do it!
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Refit orders patch

Post by planetmaker »

PikkaBird wrote:
Siggie wrote:But these orders are currently only allowed if the GRF set allows it and if the refitting does not cause any costs.
This isn't actually true; station refits can absolutely cost money with the current spec (using callback 15e or refit_cost). If every newgrf author who has implemented station refits has had the sense to make them free, perhaps that tells us something. ;)
planetmaker wrote:However refits which require "realistically" some modification to the wagon are only allowed in depots. Maybe the station refit rules could and should be relaxed more
"Realism" is a bad feature. :)

Limiting station refits by what was "realistic" was how I did it for UKRS2, too, but for Pineapple Trains I decided it was better for gameplay if every refit which could be done in the depot could also be done at a station. It's simply less confusing for players - and those players who don't like the "unrealism" of reusing an oil tanker for beer can just not do it!
Well, OpenGFX+Trains does not make (all) station refits free-of-charge. But that probably doesn't matter much. One example:

Code: Select all

switch (FEAT_CURRENT, SELF, bulk_refit_from_clean_switch, extra_callback_info1 & 0xFF) {
    // The vehicle is clean, but we want to transport something else. Allow to
    // clean it quickly in the station with a broom and some water at a cost.
    CERE: return 20 | CB_RESULT_AUTOREFIT;
    CTCD: return 20 | CB_RESULT_AUTOREFIT;
    FICR: return 20 | CB_RESULT_AUTOREFIT;
    FRUT: return 20 | CB_RESULT_AUTOREFIT;
    FRVG: return 20 | CB_RESULT_AUTOREFIT;
    GRAI: return 20 | CB_RESULT_AUTOREFIT;
    MAIZ: return 20 | CB_RESULT_AUTOREFIT;
    RSGR: return 20 | CB_RESULT_AUTOREFIT;
    SGCN: return 20 | CB_RESULT_AUTOREFIT;
    SGBT: return 20 | CB_RESULT_AUTOREFIT;
    TOFF: return 20 | CB_RESULT_AUTOREFIT;
    WHEA: return 20 | CB_RESULT_AUTOREFIT;
    // The vehicle is clean and we want to transport dirty stuff. Just do so
    // without costs:
    return 0 | CB_RESULT_AUTOREFIT;
}
But when I com back to that set, I'll remove the refit restrictions, too. I agree with the reasoning "just don't do it, if you don't like it".
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Refit orders patch

Post by andythenorth »

The cb should be removed in next version of grf spec, or limited to specify the cost only. Station refit should be 1:1 identical to depot refit.

Not only are limited refits it weird and annoying, they also make it easy for a player to set orders which are broken, and these fail silently. :)
Siggie
Engineer
Engineer
Posts: 3
Joined: 28 Aug 2014 08:11

Re: Refit orders patch

Post by Siggie »

kamnet wrote:Having automatic refits at stations even if they cost is a good way for a payer's route to quickly become unprofitable.
This should not be a Problem, as only as many trucks as needed are refitted.
kamnet wrote:I'm not sure why you say most sets do not allow station refit
I didn't say that. But examples are the 2cc set (original version, don't know about the recoded), the DB-XL set or the ECS&FIRS original vehicle set.
kamnet wrote:The betterer solution would be to modify the refit properties of the OpenGFX+ vehicle sets
Eddy Arfik wrote:If you have anything in specific which needs improvement with OpenGFX+Trains, please say so...
I agree that a change request for an GRF would be a easier solution but the advantage of this patch is that I don't need to do this for every GRF I want to play. Also the community behind the a specific set may refuse my request. Using this patch I can just switch the options on and it works.
planetmaker wrote:
Siggie wrote: But these orders are currently only allowed if the GRF set allows it and if the refitting does not cause any costs.
This isn't actually true; station refits can absolutely cost money with the current spec (using callback 15e or refit_cost)...
I'm quite sure it is: Try out the following savegame.
Nedwood Transport, 7th Sep 1970.sav
(11.66 KiB) Downloaded 72 times
Some general Questions: Why is it bad to create a patch against a release instead of the trunk? Isn't it some kind of part of the trunk? I just used SVN and checked out Tag 1.4.2. And what about the savegame incompatibilities. I currently can load the same savegames with my patched version and the release.


Regards
User avatar
kamnet
Moderator
Moderator
Posts: 8586
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: Refit orders patch

Post by kamnet »

Siggie wrote:
kamnet wrote:Having automatic refits at stations even if they cost is a good way for a payer's route to quickly become unprofitable.
This should not be a Problem, as only as many trucks as needed are refitted.
If a single truck makes a $100 profit delivering one type of good, but the refit at the station costs more than $100, then the route has become unprofitable. If a player using your patch is unaware of the refit cost because they never see it because they didn't set it up in a depot, then they're going to be left confused.
Siggie wrote:Some general Questions: Why is it bad to create a patch against a release instead of the trunk? Isn't it some kind of part of the trunk? I just used SVN and checked out Tag 1.4.2. And what about the savegame incompatibilities. I currently can load the same savegames with my patched version and the release.
The first reason is because once you apply your patch to an official release, that official release can no longer be considered stable, and it is not savegame-compatible with unpatched versions. A person playing with unpatched 1.4.2 will not be able to load your game. The second reason is that trunk releases contain newer, updated code and features, where the stable release had its development frozen months ago. Basing your patch on a nightly trunk puts your development ahead of the curve.
Hafting
Engineer
Engineer
Posts: 106
Joined: 13 Feb 2014 11:22

Re: Refit orders patch

Post by Hafting »

andythenorth wrote:The cb should be removed in next version of grf spec, or limited to specify the cost only. Station refit should be 1:1 identical to depot refit.

Not only are limited refits it weird and annoying, they also make it easy for a player to set orders which are broken, and these fail silently. :)
There is another solution to that: Make the game complain when an order fails. We already get notifications about "train with invalid order" when a depot/station is deleted. We could also have "train 15 attempted invalid refit from oil to beer at station X - only doable in depot". A clear warning, and soone enought he player knows what won't work.

Ideally, the player should not be able to specify an invalid refit in the first place; but conditional orders means that some invalid refits are impossible to guard against. Still, many don't use conditional orders much, so most cases could get the warning immediately. I.e. whenever an order window without conditionals have an impossible sequence - highlight with red or something. But don't disallow completely, as the player may intend to produce a valid order by adding a depot refit in a later step.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Refit orders patch

Post by Alberth »

Hafting wrote:
andythenorth wrote:The cb should be removed in next version of grf spec, or limited to specify the cost only. Station refit should be 1:1 identical to depot refit.

Not only are limited refits it weird and annoying, they also make it easy for a player to set orders which are broken, and these fail silently. :)
There is another solution to that: Make the game complain when an order fails. We already get notifications about "train with invalid order" when a depot/station is deleted. We could also have "train 15 attempted invalid refit from oil to beer at station X - only doable in depot". A clear warning, and soone enought he player knows what won't work.
Except when you play with cargo-dist, which needws to know whether you can refit to a certain cargo, in a reliable way.
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
fonso
President
President
Posts: 945
Joined: 13 Oct 2007 08:28

Re: Refit orders patch

Post by fonso »

Cargodist will just assume that the refit works when calculating the distribution. So if you create bad refit orders you may get some misrouted cargo, but we can just say "that's your problem" again. That said, I also consider this feature as something between useless and harmful, and I'd be happy if we removed the extra restrictions to station-refit.
The guy on the picture is not me, it's Alonso.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 17 guests