New refit_cost callback for vehicles

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

New refit_cost callback for vehicles

Post by planetmaker »

Yesterday michi_cc submitted a new misc_flag and callback for all vehicle types, the "allow autorefit" flag (nfo, nml) and callback 15E (nfo, nml) which controls refit costs.

The idea is such that a refit between, say, coal and ore doesn't need any work in a depot and refit can be done at the station, just loading the other cargo type (either automatically what is available or explicitly chosen via the order). This becomes possible when both, the misc_flag is set and refit costs are 0 (either via property or callback) or when the refit_cost callback returns a value with bit 14 set which allows refit at a station with arbitrary costs.

The current cargo classes, cargo types and cargo subtypes are accessible by the usual variables, the new cargo classess (cccc), cargo subtype (ss) and cargo type (tt) are available via extra_callback_info1 (var 0x10) in the form of ccccsstt.

As such vehicle set authors probably want to update their sets and make use of this new misc_flag and the related callback.

Example code from OpenGFX+Trains looks like this:

Code: Select all

// Carrying vehicles needs special equipment. Changing from that to other transport types
// needs a depot visit. Different vehicle types need no change and are fine to be changed
// in a station w/o cost and trouble. Mask only the cargo type and mask out cargo classes and subtypes
switch (FEAT_TRAINS, SELF, flatbed_wagon_refit_from_vehicles, extra_callback_info1 & 0xFF) {
	FMSP: return 0 | CB_RESULT_AUTOREFIT;
	ENSP: return 0 | CB_RESULT_AUTOREFIT;
	VEHI: return 0 | CB_RESULT_AUTOREFIT;
	return CB_FAILED;
}
// Carrying containers requires stakes to be removed. This needs a depot visit. Changing
// one container for the other incurs no cost nor needs a depot visit.
switch (FEAT_TRAINS, SELF, flatbed_wagon_refit_from_flat, extra_callback_info1 & 0xFF) {
	GOOD: return 0 | CB_RESULT_AUTOREFIT;
	return CB_FAILED;
}
// Being a stake wagon is default. Allow refit without trouble and cost. Other versions
// need a depot visit
switch (FEAT_TRAINS, SELF, flatbed_wagon_refit_from_stakes, extra_callback_info1 & 0xFF) {
	FMSP: return CB_FAILED;
	ENSP: return CB_FAILED;
	VEHI: return CB_FAILED;
	GOOD: return CB_FAILED;
	return 0 | CB_RESULT_AUTOREFIT;
}
switch (FEAT_TRAINS, SELF, flatbed_wagon_refit_cost_switch, cargo_type_in_veh) {
	FMSP: flatbed_wagon_refit_from_vehicles;
	ENSP: flatbed_wagon_refit_from_vehicles;
	VEHI: flatbed_wagon_refit_from_vehicles;
	GOOD: flatbed_wagon_refit_from_flat;
	flatbed_wagon_refit_from_stakes;
}

item(FEAT_TRAINS, flatbed_wagon) {
    property {
(...)
        refit_cost:         40; // default value;
    }
    graphics {
(...)
        refit_cost:         flatbed_wagon_refit_cost_switch;
(...)
}
Attachments
auto-refit.png
auto-refit.png (163.86 KiB) Viewed 1494 times
Last edited by planetmaker on 04 Nov 2011 14:36, edited 1 time in total.
User avatar
ISA
Tycoon
Tycoon
Posts: 3384
Joined: 17 Oct 2005 20:56
Location: Estonia

Re: New refit_cost callback for vehicles

Post by ISA »

That's cool! That means when I unload some cargo and load it another supported cargo near by and deliver it to the start location, it compensate going back empty to destination where I came from?!?! More cargo means more profit!
ZxBiohazardZx
Tycoon
Tycoon
Posts: 1534
Joined: 14 Mar 2006 12:46
Location: Netherlands

Re: New refit_cost callback for vehicles

Post by ZxBiohazardZx »

will this finally make "multi-cargo" trains more viable (aka auto-adjust to available supply or do i misunderstand now)
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: New refit_cost callback for vehicles

Post by planetmaker »

ZxBiohazardZx wrote:will this finally make "multi-cargo" trains more viable (aka auto-adjust to available supply or do i misunderstand now)
Yes. Exactly that works when the NewGRF (or rather the wagons) support automatic refit. You could give it a shot jointly with the upcoming nightlies of both OpenTTD and OpenGFX+Trains.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: New refit_cost callback for vehicles

Post by PikkaBird »

This sounds great, but for autorefit to become the norm (a la locomotion) we'll also need a way to specify which cargo a train should pick up (a la locomotion). Otherwise my petrol tankers are going to get filled randomly with plastic, and my lumber trains with goods.

I will incorporate this onto my sets, but will make auto a refittable option rather than the default for now, I think.
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: New refit_cost callback for vehicles

Post by Michi_cc »

PikkaBird wrote:This sounds great, but for autorefit to become the norm (a la locomotion) we'll also need a way to specify which cargo a train should pick up (a la locomotion).
Thankfully, you can specify either a fixed cargo type or what is available for each order.

-- Michael Lutz
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: New refit_cost callback for vehicles

Post by planetmaker »

PikkaBird wrote:I will incorporate this onto my sets, but will make auto a refittable option rather than the default for now, I think.
Why that? The player has to select autorefit explicitly via the order anyway...?
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: New refit_cost callback for vehicles

Post by Terkhen »

Thank you for the nice explanation, this will make implementing this in OpenGFX+ Road Vehicles simpler :D
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: New refit_cost callback for vehicles

Post by PikkaBird »

Thanks Michael, i hadnt tried it yet so I did not realise you had already modified the orders system too. This will be fantastic!
Supercheese
Tycoon
Tycoon
Posts: 1660
Joined: 16 Dec 2007 22:24
Location: Idaho, USA

Re: New refit_cost callback for vehicles

Post by Supercheese »

PikkaBird wrote:Thanks Michael, i hadnt tried it yet so I did not realise you had already modified the orders system too. This will be fantastic!
Yes. Yes it will. :mrgreen:
Eyecandy Road Vehicles | Fake Subways | Supercheese's NewObjects

"Fashions and cultures change, but steam trains shall always be majestic."
-Professor Hershel Layton
ZxBiohazardZx
Tycoon
Tycoon
Posts: 1534
Joined: 14 Mar 2006 12:46
Location: Netherlands

Re: New refit_cost callback for vehicles

Post by ZxBiohazardZx »

planetmaker wrote:
ZxBiohazardZx wrote:will this finally make "multi-cargo" trains more viable (aka auto-adjust to available supply or do i misunderstand now)
Yes. Exactly that works when the NewGRF (or rather the wagons) support automatic refit. You could give it a shot jointly with the upcoming nightlies of both OpenTTD and OpenGFX+Trains.

then maybe we can implement the "repair" stations as well now? (the other depot feature other then refit) (to me that addition sounds similar in approach )
User avatar
Emperor Jake
Tycoon
Tycoon
Posts: 3443
Joined: 24 Apr 2007 09:37
Skype: Discord: Emperor Jake #4106
Location: Not Actually Japan
Contact:

Re: New refit_cost callback for vehicles

Post by Emperor Jake »

I've just tried out this new feature, and it's awesome. But there is one thing bugging me: I tried to autorefit a flatbed wagon from lumber to engineering supplies, but it didn't work (the train didn't refit) because the cargos aren't "compatible" with each other. However, the option to refit to that cargo is still there. In addition, when I had first built the train, it was refitted to Goods by default, and it can't autorefit from goods to lumber or engineering supplies, so it was stuck at the station. (I had assumed it would autorefit from Goods to Lumber). It's also hard to determine which cargos are actually compatible with each other, as you have to go to the train's depot refit window and see which cargos cost to refit to, or something like that.

I imagine this would be very disorientating and confusing for a novice player, and will result in a lot of questions, reports and complaints such as "why isn't my train autorefitting?" etc...

Another thing: When a certain order is set to auto-refit, it should be removable in the same way as a load/unload order, ie the autorefit button should be depressed if autorefit is active, and one click resets it. It is currently difficult to remove autorefit from an order (one must select "no loading" in order to remove it.)
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: New refit_cost callback for vehicles

Post by Michi_cc »

Emperor Jake wrote:I've just tried out this new feature, and it's awesome. But there is one thing bugging me: I tried to autorefit a flatbed wagon from lumber to engineering supplies, but it didn't work (the train didn't refit) because the cargos aren't "compatible" with each other. However, the option to refit to that cargo is still there.
Yes, that's is definitely not a good UI, but unfortunately not really avoidable as OpenTTD only knows the cargo type the vehicles have right now, while for auto-refitting the cargo type the vehicle will have in the future upon arriving at the destination is the deciding one. Predicting the future is... problematic.
Emperor Jake wrote:Another thing: When a certain order is set to auto-refit, it should be removable in the same way as a load/unload order, ie the autorefit button should be depressed if autorefit is active, and one click resets it. It is currently difficult to remove autorefit from an order (one must select "no loading" in order to remove it.)
The auto-refit order is removed exactly like the existing depot refit order which is by Ctrl-Click as the tooltip will tell you.

-- Michael Lutz
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: New refit_cost callback for vehicles

Post by Michi_cc »

Sorry for the double post.

From OpenTTD r23124 on the value returned in bits 0-13 is now treated as a signed integer to allow refit income (for example if refit is used to change the number of articulated parts). As I don't think any of the few already changed NewGRFs returns a refit cost factor >= 8192, no action is needed for the existing NewGRFs.

-- Michael Lutz
User avatar
Emperor Jake
Tycoon
Tycoon
Posts: 3443
Joined: 24 Apr 2007 09:37
Skype: Discord: Emperor Jake #4106
Location: Not Actually Japan
Contact:

Re: New refit_cost callback for vehicles

Post by Emperor Jake »

Michi_cc wrote: The auto-refit order is removed exactly like the existing depot refit order which is by Ctrl-Click as the tooltip will tell you.

-- Michael Lutz
Actually, that scrolls to the destination as it does with any other order. Or are you referring to clicking somewhere else?

Also, if you remove the wagons of a train that has autorefit orders and replace them with non-auto-refittable wagons (or simply copy orders from a train that has autorefit) then it is also impossible to remove the autorefit orders because the button is greyed out. In fact they shouldn't be there if the wagons don't support it - either automatically removed or the order copy refused.
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: New refit_cost callback for vehicles

Post by Michi_cc »

Emperor Jake wrote: Actually, that scrolls to the destination as it does with any other order. Or are you referring to clicking somewhere else?
<snip snip> ... either automatically removed or the order copy refused.
I'm referring to Ctrl-clicking the refit button. This is exactly the same behaviour as for the pre-existing depot refit orders, which aren't removed either on copying orders as far as I remember.

-- Michael Lutz
User avatar
Snail
Tycoon
Tycoon
Posts: 1287
Joined: 28 Apr 2003 18:52
Contact:

Re: New refit_cost callback for vehicles

Post by Snail »

Very interesting feature!

I'd like to talk a little bit about refitting to different subtypes of the same cargo.
Right now, if I refit from cargo type A to cargo type B, and cargo type B has subtypes X and Y with different refitting costs, refitting to cargo B (subtype X) will have a different cost than refitting to cargo B (subtype Y).
OTOH, it seems that if I refit to another subtype of the same current cargo, the refitting costs are always 0, no matter how much I set the costs for each single subtype.

Is this intended?

I can see a couple of drawbacks here. First of all, let's say cargo B's subtype X has higher refitting costs than subtype Y. So:

* if I refit from cargo A to cargo B (subtype X) it will cost a certain amount;
* if I refit from cargo A to cargo B (subtype Y), and then to cargo B (subtype X), it will cost less (and the final effect will be the same!).

Also, in my set, I'm creating passenger classes as subtypes of PASS. My original idea was to have the passenger wagons to show up as 2nd class by default, and then have a certain refit cost (> 0) if I refitted from "passengers (2nd class)" to "passengers (1st class)". Why this? Well, because refurbishing a 2nd class coach to a 1st class coach costs money, due to labor and the more luxurious interiors. OTOH, refitting back from 1st class to 2nd class would cost something as well, but less (just the labor needed to refurbish the wagon using cheaper interiors).

For this reasons, I set up refit_costs to a certain amount for passengers (2nd class), and to a higher amount for passengers (1st class).
However, since refitting to a different subtype of the same cargo costs nothing, this has no effect.

I could also code different classes' wagons as separate IDs, but I'd prefer to do it the way I just described, to save IDs and to make the set leaner.

Perhaps we could add a feature that can make the refit costs > 0 when switching between subtypes of the same cargo, if needed?
The French Narrow Gauge Train Set is now released! Get it here
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: New refit_cost callback for vehicles

Post by michael blunck »

Snail wrote: [refitting to different subtypes of the same cargo]

Right now, if I refit from cargo type A to cargo type B, and cargo type B has subtypes X and Y with different refitting costs, refitting to cargo B (subtype X) will have a different cost than refitting to cargo B (subtype Y).
OTOH, it seems that if I refit to another subtype of the same current cargo, the refitting costs are always 0, no matter how much I set the costs for each single subtype.

Is this intended?
In general, there´s no refitting cost incurred for refitting to the same cargo, even if a refitting cost value specified in the vehicle´s action0.

OTOH, the documentation of CB15E (refit cost factor) explicitly mentions "cargo subtype" being part of variable 10, which might be checked when in that callback.

So, it´s either a bug or a misleading documentation, and word from a developer would be indeed helpful, IMO.

[edit]thanks[/edit]

regards
Michael
Image
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: New refit_cost callback for vehicles

Post by Michi_cc »

michael blunck wrote:So, it´s either a bug or a misleading documentation, and word from a developer would be indeed helpful, IMO.
It's a bug that was just fixed in r23518.

By default, refitting only the subtype was always free so the cost callback was skipped. I've changed it now that a subtype-only refit is still free by default, but the refit cost callback can override it now.

-- Michael Lutz
User avatar
Snail
Tycoon
Tycoon
Posts: 1287
Joined: 28 Apr 2003 18:52
Contact:

Re: New refit_cost callback for vehicles

Post by Snail »

Thanks! :D Now it works great!
The French Narrow Gauge Train Set is now released! Get it here
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 2 guests