Page 1 of 1

(Dead thread) unexpected problems coding articulated RVs

Posted: 08 Nov 2008 14:15
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   

Re: Variational Action 2 chains for articulated RVs

Posted: 08 Nov 2008 16:37
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 ;)

Re: Variational Action 2 chains for articulated RVs

Posted: 08 Nov 2008 17:26
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

Re: (Dead thread) unexpected problems coding articulated RVs

Posted: 08 Nov 2008 18:11
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.

Re: Variational Action 2 chains for articulated RVs

Posted: 08 Nov 2008 18:11
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.

Re: Variational Action 2 chains for articulated RVs

Posted: 08 Nov 2008 18:16
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:

Re: (Dead thread) unexpected problems coding articulated RVs

Posted: 08 Nov 2008 18:32
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.

Re: (Dead thread) unexpected problems coding articulated RVs

Posted: 08 Nov 2008 18:55
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.