(Dead thread) unexpected problems coding articulated RVs

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

(Dead thread) unexpected problems coding articulated RVs

Post by andythenorth »

Hi all,

I am trying to code an articulated road vehicle that will obey the following logic:

first vehicle: no cargo
(add trailers)
if cargo type is coal:
build 4 trailers
else:
build 2 trailers

The vehicle will only carry one cargo type, there is no requirement for mixed cargoes.

The following code fails. I think it's valid code, but the wrong implementation for what I am trying to achieve. My guess is that because the first vehicle has no cargo, variable 47 will never return 01, so action C2 will always be used.

What would be a better implementation?

thanks,

Andy

Code: Select all

  806 * 26	 02 01 C3  // Action 2
    81 10 00 FF //check byte value of variable 10 (no bit shift, FF andmask)
    04 //check four ranges
      03 80 01 01  //give callback result of 03 for value 01
      01 80 02 02  //give callback result of 00 for value 02
      03 80 03 03  //give callback result of 03 for value 03
      01 80 04 04  //give callback result of 00 for value 04
    FF FF // end the callback chain
  807 * 26	 02 01 C2  // Action 2
    81 10 00 FF //check byte value of variable 10 (no bit shift, FF andmask)
    02 //check four ranges
      03 80 01 01  //give callback result of 03 for value 01
      00 80 02 02  //give callback result of 00 for value 02
    FF FF // end the callback chain

  808 * 14	 02 01 C1  // Action 2
    81 47 00 FF //check byte value of variable 47 (no bit shift, FF andmask) 
    01 //check one range
      C3 00 01 01  // go to ID C3 for value 01 - cargo is coal
    C2 00 // go to ID C2 for default

  809 * 14	 02 01 C0 // Action 2
    81 0C 00 FF //check byte value of variable 81 (no bit shift, FF andmask)
    01 //check one range
      C1 00 16 16 //go to ID C1 for value 16 (ie. go to the articulated vehicle building instructions)
    A0 00 //otherwise go to ID A0 (ie. apply vehicle graphics)

  810 * 7	 03 // Action 3
    01 // RV
    01 // Number of vehicles this action associate graphics with 
    06 // Vehicle ID
    00 // only use default cargo
    C0 00      // Action 2 ID for default cargo   
Last edited by andythenorth on 08 Nov 2008 18:13, edited 2 times in total.
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: Variational Action 2 chains for articulated RVs

Post by DJ Nekkid »

well, im talking just in general here, but looking at your action3 it only have one cargo. And the way i understand your question, can the vehicle (for example) take all bulk cargo, but only the coal version should have 4 "wagons", and all others should have two, so to me would the code be in the folling pattern

action1 for the engine
action1 for defalt cargo trailer
action1 for coal trailer

action2's

ArticulationVar2s that apply only 2 wagons (lets call it C0), pointing at the default cargo trailer
ArticulationVar2s that apply 4 wagons (lets call it B0), pointing at the coal trailer

Action3 in the folloing matter:

Code: Select all

  810 * 7    03 // Action 3
    01 // RV
    01 // Number of vehicles this action associate graphics with 
    06 // Vehicle ID
    01 // two different cargoes
    B0 00 01  // use cID B0 for cargotype 01 (coal)
    C0 00      // Action 2 ID for default cargo
btw, the 01 there (B0 00 01) is your statement, that it's the "id" for coal.

Hope that made sense, and helped. If you need me to can i probably dig up some "real" code, but i can't do that until tomorrow. Im about to go to a footballmatch and some beer-duty ;)
Member of the
ImageImage
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Variational Action 2 chains for articulated RVs

Post by andythenorth »

DJ Nekkid wrote: Action3 in the folloing matter:

Code: Select all

  810 * 7    03 // Action 3
    01 // RV
    01 // Number of vehicles this action associate graphics with 
    06 // Vehicle ID
    01 // two different cargoes
    B0 00 01  // use cID B0 for cargotype 01 (coal)
    C0 00      // Action 2 ID for default cargo
<glum>Thanks for the tip - I tried using action 3 to choose different Action 2 IDs depending on cargo already. The Action 3 simply uses the default Action 2 ID in all cases.</glum>

It could be something wrong with the Action 0:

Code: Select all

18 * 67	 00 01 19 01 06 
    00 00 00
    02 20
    03 11
    04 23
    06 0F
    07 05
    08 80
    09 1E 0A 48 4C 00 00 13 14 14 18 
    0E FF
    0F 01
    10 FF
    11 34
    12 17
    15 20
    16 00 00 00 00
    17 10
    1A 00
    1B 00
    1C 02
    1D FF 03
    1E 01 00
    1F 60 B3 0A 00
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: (Dead thread) unexpected problems coding articulated RVs

Post by andythenorth »

I've tried a lot of different solutions, and I'd like to declare this thread dead unless anyone knows that the following is NOT true:

- The number of vehicles in an articulated road vehicle cannot be changed once the vehicle has been constructed.
Last edited by andythenorth on 08 Nov 2008 18:12, edited 1 time in total.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Variational Action 2 chains for articulated RVs

Post by frosch »

andythenorth wrote:first vehicle: no cargo
NewGrfSpecs callback 16 wrote:In OpenTTD the cargo class of the first road vehicles is used to determine whether the vehicle can stop at bus or truck stops regardless of the capacity of the first vehicle. If the cargo class bit for passengers is set it can go to bus stops when the is not set it can go to truck stops.
You can set the capacity to 0 though. Don't know about TTDP.
andythenorth wrote:if cargo type is coal:
build 4 trailers
else:
build 2 trailers
Callback 16 is called when the vehicle is build. Not when it is refitted.
So it is impossible to add different articulated parts depending on cargo type.
You can only draw empty sprites for the third and fourth part, and use callback 11 (don't know whether TTDP supports it for road vehicles) to make them shorter.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Variational Action 2 chains for articulated RVs

Post by andythenorth »

frosch wrote: You can only draw empty sprites for the third and fourth part, and use callback 11 (don't know whether TTDP supports it for road vehicles) to make them shorter.
Thanks Frosch, I'll stop banging my head on this. I did think of using empty sprites, but it seems like a monster hack, and I'd still have to deal with changing cargo capacity and a whole lot of other trouble.

I've come up with a much simpler solution, but it will involve having more vehicles in the buy menu, so is far from ideal :shock:
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: (Dead thread) unexpected problems coding articulated RVs

Post by DaleStan »

:evil:

Kindly explain to me what in all the burning hells makes you think that "Ask in public only" means "PM DaleStan a link to the thread"?

DaleStan will read the thread when he's good and ready to, and usually before he reads his PMs.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: (Dead thread) unexpected problems coding articulated RVs

Post by andythenorth »

DaleStan wrote::evil:

Kindly explain to me what in all the burning hells makes you think that "Ask in public only" means "PM DaleStan a link to the thread"?

DaleStan will read the thread when he's good and ready to, and usually before he reads his PMs.
Burning hells noted. Please may I offer you my apologies.
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: No registered users and 14 guests