Change sprites of articulated RV on refit

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

Change sprites of articulated RV on refit

Post by andythenorth »

I have an interesting question about articulated road vehicles. What would be the best way to provide a cargo-dependent livery override of the lead vehicle, if that vehicle has a cargo capacity of zero?

i.e. Vehicle is built, then user refits and first vehicle uses different sets of real sprites depending on cargo type. (this a tractor / trailer combination, where first vehicle carries no cargo).

I have been talking to Zephyris about it, the simplest way appeared to be to have the action 3 target different action 2 chains dependent on cargo. This creates some redundant code, but seemed to be conceptually simple. However it doesn't work when the cargo capacity of the lead vehicle is zero. Based on Pikka's comment in a previous thread, this is possibly expected.

Subject: Problems with coding refit cycle
PikkaBird wrote:You cannot create or destroy articulated parts on the fly; the articulation callback is run only once when the vehicle is bought.
I've copied my code below in case the cause is coder error. I think the nfo is valid because if I give the lead vehicle a capacity of 1, livery override works as expected on refit (although the vehicle's capacity is then horribly incorrect - does not seem to include the capacity of trailing vehicles).

Is there a way to achieve what I want with a reasonable amount of effort and code (possibly using variable 42)? NB this is different to the issue I had in a previous thread where I wanted to change the number of vehicles in an articulated vehicle on refit.

Code: Select all

  582 * 9	 02 01 A1 01 01 00 00 00 00  // set of real sprites
  583 * 9	 02 01 A2 01 01 01 00 01 00 // set of real spries
  584 * 4	 01 01 01 01 // will be used for buy menu sprites (unfinished)
  585 Y:\Documents\OTTD graphics\HEQS_build\Full HEQS\sprites\tractors/fourtrac_1CC.pcx 242 9 01 16 36 -18 -8
  586 * 9	 02 01 A0 01 01 00 00 00 00 // will be used for buy menu sprites (unfinished)
// the variation action 2 is thanks to Zephyris who supplied the original nfo for this grf
  587 * 14	 02 01 B0
               81 10 00 FF //check byte value of variable 10 (no bit shift, FF andmask)
               01 //check one range(s)
                00 80 01 01 //give callback result of 00 for value 01*
               FF FF //otherwise end the callback chain
  588 * 14	 02 01 B1
               81 0C 00 FF //check byte value of variable 81 (no bit shift, FF andmask)
               01 //check one range
                B0 00 16 16 //go to ID B0 for value 16 (ie. go to the articulated vehicle building instructions)
               A2 00 //otherwise go to ID A1 (ie. apply vehicle graphics)
  589 * 14	 02 01 C0
               81 10 00 FF //check byte value of variable 10 (no bit shift, FF andmask)
               01 //check one range(s)
               00 80 01 01 //give callback result of 00 for value 01*
               FF FF //otherwise end the callback chain
  590 * 14	 02 01 C1 
               81 0C 00 FF //check byte value of variable 81 (no bit shift, FF andmask)
               01 //check one range
                B0 00 16 16 //go to ID B0 for value 16 (ie. go to the articulated vehicle building instructions)
               A1 00 //otherwise go to ID A1 (ie. apply vehicle graphics)
  591 * 10	 03   // Action 3
    01  // RV 
    01  // Number of vehicles this action associate graphics with 
    80  // Vehicle ID
    01  // Number of different cargo types to support
    07 // wood
    C1 00
    B1 00   // default Action 2 ID 
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Change sprites of articulated RV on refit

Post by andythenorth »

I think I've found a solution for this using variable 42 (cargo transported by consist). It works so far in OpenTTD, I can't comment on Patch (sorry)

I'm posting here in case it's useful to others. If the solution is correct, I would like to contribute it to the wiki, but one thing at a time...

I've commented my nfo as best I understand it - if anyone can correct any mistakes, that would be great.

cheers,

Andy

Code: Select all

  // I've already created the vehicle with ID 80 in an action 0.  
    // NB That ID is valid in current Open TTD nightly as of Nov 2008, but may not be valid in Patch
    // This is an articulated vehicle. 
    // Lead vehicle is a tractor that hauls a trailer.  Tractor has cargo capacity of 0.  
    // Trailer carries cargo and is refittable.  Trailer (ID 00) is defined separately with its own action chain.
    // I want to use different tractor sprites depending on trailer cargo.
    // Refitting by cargo requires an action 2 to find the most common cargo in the consist using variable 42 
  
  // I've already created two real sprite sets with an action 1. These are the basic action 2s for them.
  25 * 9	 02 01 A1 01 01 00 00 00 00  // action 2 with ID A1.  Use with wood.
  26 * 9	 02 01 A2 01 01 01 00 01 00  // action 2 with ID A2.  Use with other cargoes.
  
  // the next action 2 is called from B0, and builds a trailer using vehicle ID 00 (the trailer)
  27 * 14	 02 01 B1
               81 10 00 FF //check byte value of variable 10 (no bit shift, FF andmask)
               01 //check one range(s)
                00 80 01 01 //give callback result of 00 for value 01*
               FF FF //otherwise end the callback chain
  // the next action 2 is called from B0 and chooses whether to use A1 or A2 to apply the real sprites.               
  28 * 14	 02 01 B2
               81 // starting from current vehicle...
               42 // variable 42 - consist cargo, returns in format 'uuiicctt' (look in wiki for details)
               08 // ???? I want the 'cc' bytes above, so use 08 to shift bytes right  
               FF // ???? FF andmask - I don't know what this does, I copied and pasted it from Zephyris's code
               01 //check one range(s)
                A1 00 07 07 //goto ID A1 for value 07 (wood)
               A2 00 //otherwise goto ID A2
  29 * 14	 02 01 B0
               81 0C 00 FF //check byte value of variable 81 (no bit shift, FF andmask)
               01 //check one range(s)
                B0 00 16 16 //go to ID B0 for value 16 (ie. go to the articulated vehicle building instructions)
               B2 00 //otherwise go to ID B2
  30 * 7	 03   // Action 3
    01  // RV 
    01  // Number of vehicles this action associate graphics with 
    80  // Vehicle ID
    00  // Number of different cargo types to support
    B0 00   // default Action 2 ID 
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Change sprites of articulated RV on refit

Post by DaleStan »

andythenorth wrote:

Code: Select all

  FF // ???? FF andmask - I don't know what this does, I copied and pasted it from Zephyris's code
I recommend you figure it out; it does exactly what the documentation says it does.

That aside, you're using cc, which is always the untranslated bit. This may or may not have any relation to the tables given in the TTDPatch wiki for the default cargos, and has no more than incidental relation to your cargo translation table.
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
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Change sprites of articulated RV on refit

Post by michael blunck »

andythenorth wrote:I think I've found a solution for this using variable 42 (cargo transported by consist). It works so far in OpenTTD, I can't comment on Patch (sorry)
Sorry, that sounds strange. O/c "it works" for TTDPatch. The newgrf system had been developed for TTDPatch in the first place. So everything from the specs (should) work(s) for TTDPatch. OTOH, quite a couple of features do not work in OTTD from my own experience.
I'm posting here in case it's useful to others. If the solution is correct, I would like to contribute it to the wiki, but one thing at a time...
I've commented my nfo as best I understand it - if anyone can correct any mistakes, that would be great.
I have problems with the excessive "documentation" here and I wouldn´t like to see it in exactly the same way in the Wiki. It´s not useful to "document" every byte at least not in that repetitive way. In addition, your code isn´t correct:

Code: Select all

  29 * 14	 02 01 B0
               81 0C 00 FF //check byte value of variable 81 (no bit shift, FF andmask)
               01 //check one range(s)
               B0 00 16 16 //go to ID B0 for value 16 (ie. go to the articulated vehicle building instructions)
               B2 00 //otherwise go to ID B2
Must be

Code: Select all

  29 * 14	 02 01 B0
               81 0C 00 FF //check byte value of variable 81 (no bit shift, FF andmask)
               01 //check one range(s)
               B1 00 16 16 //go to ID B1 for value 16 (ie. go to the articulated vehicle building instructions)
               B2 00 //otherwise go to ID B2
otherwise you´ll get an indefinite loop but no reference to the actual building instructions of your articulated vehicle.

regards
Michael
Image
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1794
Joined: 30 Mar 2005 09:43

Re: Change sprites of articulated RV on refit

Post by peter1138 »

michael blunck wrote:Sorry, that sounds strange. O/c "it works" for TTDPatch. The newgrf system had been developed for TTDPatch in the first place. So everything from the specs (should) work(s) for TTDPatch. OTOH, quite a couple of features do not work in OTTD from my own experience.
Not necessarily. There could be a bug in both OpenTTD and in a GRF that causes it to 'work'.
michael blunck wrote:otherwise you´ll get an indefinite loop but no reference to the actual building instructions of your articulated vehicle.
The comment is still wrong; it's variable 0C, not 81. You can't create an indefinite loop like that as the B0 will reference the previous definition (or cause an error if there isn't one), never the current definition.
He's like, some kind of OpenTTD developer.
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Change sprites of articulated RV on refit

Post by michael blunck »

peter1138 wrote:
mb wrote:otherwise you´ll get an indefinite loop but no reference to the actual building instructions of your articulated vehicle.
You can't create an indefinite loop like that as the B0 will reference the previous definition (or cause an error if there isn't one), never the current definition.
Yes, you´re right. IIRC, I´ve been using var "re-useing" myself years ago, confusing even DaleStan. 8)
peter1138 wrote: The comment is still wrong; it's variable 0C, not 81.
Right again. And it´s a strong hint that excessive documentation doesn´t guarantee for being read. A structure like this one would do better:

Code: Select all

// check for CBs
29 * 14    02 01 B0 81 0C 00 FF 01
               B1 00 16 16 // articulated
               B2 00       // graphics
regards
Michael
Image
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Change sprites of articulated RV on refit

Post by andythenorth »

Thanks for the replies so far.
michael blunck wrote:Sorry, that sounds strange. O/c "it works" for TTDPatch. The newgrf system had been developed for TTDPatch in the first place. So everything from the specs (should) work(s) for TTDPatch. OTOH, quite a couple of features do not work in OTTD from my own experience.

On that issue - sorry if it sounded strange - there was no implied criticism of TTDPatch, I simply meant exactly that I can't comment on TTDPatch: I don't have TTDPatch, therefore rather than making assumptions about it, I'll restrict my comments to the domain I am qualified to comment on. Hope that makes sense.
DaleStan wrote:
andythenorth wrote:

Code: Select all

  FF // ???? FF andmask - I don't know what this does, I copied and pasted it from Zephyris's code
I recommend you figure it out; it does exactly what the documentation says it does.
Yep - will do.
peter1138 wrote: You can't create an indefinite loop like that as the B0 will reference the previous definition (or cause an error if there isn't one), never the current definition.
Oops. That's just a mistake. This does work in-game. Based on the above, is the only reason this works because the previous Action 2 definition happened to be the one I should have referenced? Either way, I'll correct it.

@ Michael: I agree, that code is excessively commented. However it does let you guys pick apart my understanding of nfo, which helps me learn, which hopefully gets the community some more newgrfs ;)

My preferred format is the following: I find it helps me spot Action 2 IDs easily. For my own purposes I would also be inclined to document the variational element.

Code: Select all

// check for CBs
29 * 14    02 01 B0
               81 0C 00 FF 01
               B1 00 16 16 // articulated
               B2 00       // graphics
Something I would like to discuss with you guys:

I found learning nfo from the newgrf specs wiki a little challenging. This could be due to my rather flakey coding ability and knowledge, but I would have found a few more examples useful: good solutions to common problems, with explicit (but not excessive documentation). I am confident with languages such as Python, but have never had a need to use elements such as bytes, words, and bitmasks, and they present a relatively steep learning curve.

Perhaps that is good - it keeps newgrf quality higher by making it hard for people without solid coding skills to create them - however I reached a point yesterday where I felt like abandoning my set due to my own inability to understand how I should implement something correctly in nfo. Happily I've got past that. Others might not?

Let me be clear - lest I put noses out of joint and get flamed - the wiki is absolutely useful as documentation, but I needed Zephyris's newGRF examples guide and a lot of help from Zephyris on IM to get started on variational action 2. I've also had some very useful help on these forums. Finally Pikka's wiki also has a couple of really useful pages that demystified a few things for me.

In short, I'd like to help improve that if possible by contributing to the wiki - when I have time - and in a way that meets the approval of those of you who do know what you're talking about with nfo.

Perhaps a collaborative effort to prepare some standard solutions to common problems would be a good starting point?

cheers,

Andy
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: Change sprites of articulated RV on refit

Post by michael blunck »

andythenorth wrote: sorry if it sounded strange - there was no implied criticism of TTDPatch, I simply meant exactly that I can't comment on TTDPatch: I don't have TTDPatch, therefore rather than making assumptions about it, I'll restrict my comments to the domain I am qualified to comment on. Hope that makes sense.
Well, yes. However, by definition, all newgrf features as specifed in "the Wiki" are working under TTDPatch, but not all are usable under OTTD at the time being. And, as peter1138 wrote, by coincidence, there "could be a bug in both OpenTTD and in a GRF that causes it to 'work'". I.e., the reference is still TTDPatch, not OTTD.
@ Michael: I agree, that code is excessively commented. However it does let you guys pick apart my understanding of nfo, which helps me learn, which hopefully gets the community some more newgrfs
I do understand. I just wanted to avoid the (specification part of the) Wiki being flooded with excessive "documentation", which may be useful for an absolute beginner, in private usage or in a tutorial, though.
I found learning nfo from the newgrf specs wiki a little challenging. This could be due to my rather flakey coding ability and knowledge, but I would have found a few more examples useful: good solutions to common problems, with explicit (but not excessive documentation).
First of all, you seem to reference to the specification section of "the Wiki" all the time. However, there´s also a tutorial section.
Finally Pikka's wiki also has a couple of really useful pages that demystified a few things for me.
Mmh, does it include more basic things than the tutorial mentioned above, especially in
http://wiki.ttdpatch.net/tiki-index.php ... rstVehicle?
Perhaps a collaborative effort to prepare some standard solutions to common problems would be a good starting point?
Well, the aforementioned tutorial contains some chapters still awaiting input. 8)

regards
Michael
Image
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Change sprites of articulated RV on refit

Post by andythenorth »

michael blunck wrote: I do understand. I just wanted to avoid the (specification part of the) Wiki being flooded with excessive "documentation", which may be useful for an absolute beginner, in private usage or in a tutorial, though.
Agreed on all points.
michael blunck wrote: First of all, you seem to reference to the specification section of "the Wiki" all the time. However, there´s also a tutorial section.
Yes those are helpful and well written, I've read those several times - I just found that Pikka's page was a useful companion to them, and perhaps it could be linked from the TTDPatch Wiki? I guess what I found beneficial was that I already have lots of conceptual undersanding from coding many games and web apps over the years - I just needed a crash course to translate that into the basics of nfo, which Pikka does in entertaining style :)

On the other hand I then got rather quickly out of my depth trying to do variational action 2 chains and needed more of a clue stick for newbies than the nfo documentation provides...
Well, the aforementioned tutorial contains some chapters still awaiting input. 8)
...exactly :) Once I know more I'll have a go at some of those - but I'll need holding to account on my understanding of nfo.

In the short term, it would be useful to add some links to the TTDPatch Wiki - Pikka's page, Zephryis's PDF, Purno's drawing tutorials, and grf2HTML have all been invaluable for me in learning to create newgrfs, as has being sent a correct palette file for photoshop, and example sprite layouts. I've also figured out how to use grfcodec and grf2html on a mac without recompiling them.

I think those would be useful tips. I could get a wiki login and add some notes about them soon - however I haven't really had the time yet to understand if there is any specific person maintaining the wiki and looking after style, consistency etc. Is there someone wiki gardening who I should talk to, or do I just get on with it? :lol:

cheers,

Andy
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Change sprites of articulated RV on refit

Post by DaleStan »

As a general rule, pages with the word "Action" in their name or title are specifications, and should read like man pages. Examples there should be minimal to non-existent. Personally, I consider the regex man pages to set good examples.

The tutorial section, on the other hand, is wide open for examples, explanations, hand-holding, and just about anything else you want. If you want to write a tutorial that doesn't have a page yet, feel free to create a new page.
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
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: No registered users and 8 guests