Callback 36 query (RV cargo capacity)

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Callback 36 query (RV cargo capacity)

Post by andythenorth »

I have a case where it would be useful to modify a road vehicle's capacity depending on the date built.

Using callback 36 to modify vehicle prop 0F would seem to be a good solution here. I have code that appears to work to some extent. This produces the expected capacity, but only on refit, not when the vehicle is built. When built, the vehicle uses the capacity from the action 0 (90t). A screenshot may show this better:
callback_36.png
callback_36.png (78.65 KiB) Viewed 2129 times
I suspect the answer is going to be related to this comment in the documentation:
Wiki wrote:"Most properties will only change when the vehicle is bought, serviced (enters a depot), visits a station or on loading of a saved game. Other ones such as TE are called every time a TE calculation is run."
(EDIT) Just thought of something that might be relevant: the vehicle in question is part of an articulated RV chain. I wondered if that's a factor?
(EDIT 2) Capacities are coming out wrong: 19t instead of 78t, 21t instead of 87t etc. Probably I've misunderstood the correct way to return a value for this callback?
(EDIT 3) Current workaround is to define multiple vehicles IDs using multiple action 0s with different capacities. This works, but leaves me with a lot of redundant code, and uses a lot of IDs! A better solution would be nice to have.

Any help on this much appreciated.
cheers,

Andy

Code: Select all

 1357 * 22	 02 01 CC // refitted capacity
           81 C4 00  FF // check date vehicle built
           03 // range
             4E 80 \b00 \b59 // before 1980 (78t)
             57 80 \b60 \b70 // before 1991 (87t)
             60 80 \b71 \b84 // before 2005 (96t)
           68 80 // default (104t)
 1358 * 14	 02 01 CE //
           81 10 00  FF // check which vehicle property to change
           01 // range
             CC 00 0F 0F // vehicle cargo capacity (as set in Action 0)
           FF FF // default 
 1359 * 14	 02 01 CA
               81 0C 00 FF // handle callbacks
               01 //check one range
                CE 00 36 36 // change vehicle properties CB
               CD 00 // go to ID A1
 1360 * 7	 03 01 01 0A // Action 3
      00  // Number of different cargo types to support  
      CA 00 // default
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: Callback 36 query (RV cargo capacity)

Post by DJ Nekkid »

the way i would do it is:
CB36 for the 1st year cID A5
CB36 for the 2nd year cID B5
CB36 for the 3rd year cID C5
var-2-what-year with 3 ranges, A5 00 <year low> <year high> B5 00 <year low><year high> C5 <year low><year high> <default>

.

i can provide "real" code if u need me to.
Member of the
ImageImage
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Callback 36 query (RV cargo capacity)

Post by andythenorth »

DJ Nekkid wrote:i can provide "real" code if u need me to.
That would be useful, thanks.

I have an alternative solution working avoiding CB 36, but it uses six vehicle IDs just to change the capacity over time!
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: Callback 36 query (RV cargo capacity)

Post by DJ Nekkid »

now, if your var2 regarding the year is working as intended, it should be something like this:

Code: Select all

-1 * 0  02 01 A0 81 10 00 FF 01  \b78 80  14 14 FF FF // 78 tons new capacity
-1 * 0  02 01 A1 81 0C 00 FF 01 A0 00  36 36 <grapical cID to attach>

-1 * 0  02 01 B0 81 10 00 FF 01  \b87 80  14 14 FF FF // 87 tons new capacity
-1 * 0  02 01 B1 81 0C 00 FF 01 B0 00  36 36 <grapical cID to attach>

-1 * 0  02 01 C0 81 10 00 FF 01  \b96 80  14 14 FF FF // 96 tons new capacity
-1 * 0  02 01 C1 81 0C 00 FF 01 C0 00  36 36 <grapical cID to attach>

-1 * 0	02 01 CC // refitted capacity
		81 C4 00  FF 	// check date vehicle built
		03		// range
		4E 80 \b00 \b59 // before 1980 (78t)
		57 80 \b60 \b70 // before 1991 (87t)
		60 80 \b71 \b84 // before 2005 (96t)
		68 80 		// default (104t)

<action 3>
Please note that this chain also needs to be run via the purchase list sprite (if it's another one) to get the proper values there.
Member of the
ImageImage
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: Callback 36 query (RV cargo capacity)

Post by DJ Nekkid »

did u get it to work?
Member of the
ImageImage
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Callback 36 query (RV cargo capacity)

Post by andythenorth »

DJ Nekkid wrote:did u get it to work?
Not yet. I'm happy with the solution of using lots of vehicle IDs for now. If I get short on IDs I'll try CB 36 again. :P

Looking at your code, I see you're changing prop 14 - I figure your code is train code? Anyway if I changed that to 0F for RVs, I think it would do the same thing as mine, just different wrapper. ;) My code worked, but I need the callback to be called when a vehicle is built; it appears to only be called on refit - think it's a specific issue for articulated RV trailers, but I haven't tested enough to prove it.

cheers,

Andy
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: Callback 36 query (RV cargo capacity)

Post by DJ Nekkid »

andythenorth wrote: Looking at your code, I see you're changing prop 14 - I figure your code is train code?
Yup, some copy/paste from the 2cc-set, but you got the drift...
andythenorth wrote:My code worked, but I need the callback to be called when a vehicle is built; it appears to only be called on refit - think it's a specific issue for articulated RV trailers, but I haven't tested enough to prove it.
I guess it's a bit dependant on how you make the articulation. If it's an "engine" with "wagons" (different vehicleID in both) i think the CB36 wont work, but if it is the same i think it will, but you might need to use it in the purchaselist sprite (if that is different) and not the "vehicle"-sprite...
Member of the
ImageImage
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Callback 36 query (RV cargo capacity)

Post by andythenorth »

DJ Nekkid wrote:I guess it's a bit dependant on how you make the articulation. If it's an "engine" with "wagons" (different vehicleID in both) i think the CB36 wont work
Yup, it's a tractor-trailer-trailer-trailer kind of thing, with different IDs. Thanks anyway though.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Callback 36 query (RV cargo capacity)

Post by frosch »

fixed in r14903 ;)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: Amazon [Bot], Google [Bot] and 6 guests