Refit of two different capacities of the same cargo

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
MarkyParky
Engineer
Engineer
Posts: 89
Joined: 20 Nov 2003 15:20

Refit of two different capacities of the same cargo

Post by MarkyParky »

Hello,

George is using for some of his busses ability to change look/capacity of vehicle by refitting. I am trying to do simmilar thing (two trams, one version with and the other without attached towed wagon), but the Game keeps offering me only one version to refit. Any idea what did I forgot in my code? Thank you very much for help..

Code: Select all

2 * 9    02 01 AA 01 01 00 00 00 00 //Engine
   23 * 9    02 01 BB 01 01 01 00 01 00 //Attached vagon

   24 * 16    02 01 11 81 40 80 FF 00 03 01 //Checking the position in consist
                       AA 00 00 00 //First
                       BB 00       //Other

   25 * 14    02 01 10 81 10 00 FF 01 //Callback for articulated
                       44 80 01 01               //Add one car
                       FF 80                        //And come back

   26 * 14    02 01 09 81 10 00 FF 01 //Callback for sound
                       49 80 01 01         //Set up the sound
                       11 00                 //And go for graphics

   27 * 30    02 01 08 81 0C 00 FF 05  //Testing callback for 2 cars version
                    09 00 33 33    //For sound go to 09
                    10 00 16 16   // For articulated go to 10
                    08 FF 12 12   // Set loading speed
                    2E FF 15 15   // Set capacity
                    02 FF 19 19   // Set text to display for refit
                    11 00

   28 * 26       02 01 07 81 0C 00 FF 04 //Testing callback for 1 car version
                    09 00 03 33  //For sound go to 09
                    04 FF 12 12   // Set loading speed
                    30 FF 15 15   // Set capacity
                    01 FF 19 19   //Set text to display for refit
                    11 00

   29 * 18    02 01 EF 81 F2 00 FF 02 //Testing refit versions (George is using F2 variable so I am doing it based on his files, but I havent found exact documentation?)
                    07 00 01 01   //For version 01 go to 07
                    08 00 00 00  //For version 00 go to 08
                    FF FF


   30 * 7    03 01 01 44 00 EF 00 //Start at EF

   31 * 28    04 01 0F 01 44 "Ringhoffer/Krizik 1915" 00  //Name
   32 * 20    00 01 07 01 44

             0E FF     // New graphics
             00 00 00  // Year 1920
             02 16     // Deteriorating
             03 32     // Life span
             04 1C     // Model aviability
             06 07     // Where aviable
             07 04     // Loading speed
   33 * 15    00 01 05 01 44
             08 32     // Speed in  kmph * 2
             13 0A     // Horse power
             14 08     // Weight in quarter tons
             15 0C     // Speed in kmph / 2 for real. accel.
             12 49     // Use sound 49
   34 * 22    00 01 07 01 44
             0F 2E     // Capacity
             10 00     // Cargo type (passengers)
             09 29     // Running cost
             11 9B     // Price
             1C 01     // Its a tram
             17 BC     // Sound
             16 01 00 00 00    // Refitable to passengers

// Names to display at refit table
   
   35 * 24    04 01 FF 01 01 D0 " (with towed car)" 00 
   36 * 27    04 01 FF 01 02 D0 " (without towed car)" 00
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Post by PikkaBird »

A couple of things stand out... firstly, I'd normally put all the texts at the top of the nfo, before any references to them. I'm not sure it makes a difference with D0xx texts, but I know it does with DCxx texts. It also makes it easier to keep track of which IDs you've already used if they're all in one block. :)

The main problem seems to be with the way you're using the callback, and variable F2. Variable F2 is only changed after running callback 19, but you're trying to make a decision based on F2 before you've checked the callback. Consequently, F2 is never changed.

The way I'd normally do a livery refit is to check for cb 19, and then check F2 to return the texts if we're checking the callback, or check F2 to choose a varational branch if we're not checking the callback, like this:

Code: Select all

1*1	 02 00 01 81 ... variation 1
1*1	 02 00 02 81 ... variation 2
1*1	 02 00 AA 81 F2 00 FF 02 01 00 01 01 02 00 02 02 AA 00 // variations
1*1	 02 00 BB 81 F2 00 FF 02 01 80 01 01 02 80 02 02 FF FF // texts
1*1	 02 00 AA 81 0C 00 FF 01 BB 00 19 19 AA 00 // BB if callback 19, AA otherwise.
Edit: It occurs to me: you also seem to be trying to build and destroy articulated locomotives on the fly. You can't do that; callback 16 is only ever run when the vehicle is built, not at any other time.
MarkyParky
Engineer
Engineer
Posts: 89
Joined: 20 Nov 2003 15:20

Post by MarkyParky »

A couple of things stand out... firstly, I'd normally put all the texts at the top of the nfo, before any references to them. I'm not sure it makes a difference with D0xx texts, but I know it does with DCxx texts. It also makes it easier to keep track of which IDs you've already used if they're all in one block.
This doesnt seem to be a problem, texts are displayed ok.
The main problem seems to be with the way you're using the callback, and variable F2. Variable F2 is only changed after running callback 19, but you're trying to make a decision based on F2 before you've checked the callback. Consequently, F2 is never changed.
That is what I have from George's grfs. He also checks F2 first, and then use callback 19 only to setup the text. But to fill in F2 variable with some data first makes sence, so I will take a closer look at your approach.

Here is part of his code where he makes decision and this works:

Code: Select all

  ...
  8699 * 22	 02 01 E8 81 0C 00 FF 03 28 FF 12 12 73 FF 15 15 B7 FF 19 19 E0 00
 ...
 8739 * 22	 02 01 E9 81 0C 00 FF 03 1E FF 12 12 4B FF 15 15 B6 FF 19 19 E1 00
 8740 * 18	 02 01 EF 81 F2 00 FF 02 E8 00 01 01 E9 00 00 00 FF FF
 8741 * 7	 03 01 01 11 00 EF 00
 ...
Edit: It occurs to me: you also seem to be trying to build and destroy articulated locomotives on the fly. You can't do that; callback 16 is only ever run when the vehicle is built, not at any other time.
That might be true, I am trying to build/destroy articulated locomotive with refit. It would be sad if this is not possible, because this is AFAIK the only way how to make two different versions of one bus/tram (short and long articulated) use only one ID. But still there is a workaround in my mind, simply with short version, the "second" vehicle can be invisible...

Thank you for advices, I am going deeper into testing.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Post by PikkaBird »

Hmm, okay, it may work George's way. Your problem then will just be with the articulation code.
MarkyParky
Engineer
Engineer
Posts: 89
Joined: 20 Nov 2003 15:20

Post by MarkyParky »

Problem is probably still somewhere else. You have been right, that it is not possible to build articulated vehicle "on the fly" - if I force georges vehicles to be articulated, they simply do not become articulated as callback is not called during refit as you say. But there is still a chance to chose between two variants. I keep searching... :?

Edit: I have finaly found it. Problem was with testing sound callback, probably is called during refit too, causing game to skip the other options.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Post by PikkaBird »

Damn, yes, you have a typo in sprite 28 ("03 33" instead of "33 33").

Are you using Dalestan's NFORenum tool? It should have picked that up...
MarkyParky
Engineer
Engineer
Posts: 89
Joined: 20 Nov 2003 15:20

Post by MarkyParky »

Yes I am using it and I was all the time wondering what the hell is this warning and why does it show on otherwise correct code. :oops:

Finaly I managed it and I have refitable articulated vehicle now. It is not possible (as you said) to attach or detach the articulated car on refit, so I choose workaround - use "invisible" second car for shorter version. But another problem occures - the repainting stops working :cry:

Code: Select all

   30 * 9	 02 01 AA 01 01 00 00 00 00 //First car
   31 * 9	 02 01 BB 01 01 01 00 01 00 //Towed car
   32 * 9	 02 01 CC 01 01 02 00 02 00 //Invisible car

   33 * 16	 02 01 11 81 40 //CID 11 - 2cars consist
                    80 FF 00 03 01  //Testing car position in consist
                       AA 00 00 00  //First car draws AA
                       BB 00           //Other cars draw BB

   34 * 14	 02 01 13 81 0C 00 FF 01  //CID 13 - shortening of invisible car
                       07 80 11 11 //Shorten by 7/8
                       CC 00        //Draw CC

   35 * 16	 02 01 12 81 40 //CID 12 - 1 car only
                    80 FF 00 03 01 //Testing the position in consist
                       AA 00 00 00 //First car draws AA
                       13 00          //Other cars jumps to 13 

   36 * 14	 02 01 10 81 10 00 FF 01 //CID 10 - Callback for articulated
                       44 80 01 01       //Add one car and return
                       FF 80

   37 * 14	 02 01 A9 81 10 00 FF 01 //CID A9 - Sound callback for long
                       49 80 01 01       //Setup sound 49
                       11 00               //Or draw 11

   38 * 14	 02 01 A8 81 10 00 FF 01 //CID A8 - Sound callback for short
                       49 80 01 01       //Setup sound 49
                       12 00                //Or draw 12


   39 * 26	 02 01 08 81 0C 00 FF 04  //Testing callbacks of long                     versions 
                    08 FF 12 12 //Loading speed
                    2E FF 15 15 //Capacity
                    02 FF 19 19 //Text displayed 
                    A9 00 33 33 //For sound goto A9
                    11 00          //Else goto 11


   40 * 26	 02 01 07 81 0C 00 FF 04 //Testing callbacks of short                     versions  
                    04 FF 12 12 //Loading speed
                    17 FF 15 15 //Capacity
                    01 FF 19 19  //Text displayed
                    A8 00 33 33 //For sound goto A8
                    12 00         //Else goto 12


   41 * 18	 02 01 EF 81 F2 00 FF 02 //Testing refit posibilities
                    07 00 01 01   //For 01 goto 07
                    08 00 00 00   //For 00 goto 08
                    FF FF


   42 * 14	 02 01 EE 81 0C 00 FF 01  //Testing articulated vehicle callback
                    10 00 16 16 //For building articulated goto 10
                    EF 00          //Else goto EF

   43 * 7	 03 01 01 44 00 EE 00
The problem seems to be somewhere at sprites 39 or 40 - all the refit callbacks works fine (eg. long vehicle has capacity of 2*46 and short has capacity of 2*23,etc..), but when it comes to graphics, somehow value 11 from sprite 39 is used regardles the verison. Any idea why this happens?


Edit: It now seems to me that I understand why did you check if callback 19 have been called and why George do not need this. I will report my results, but it seems that this is the problem.
MarkyParky
Engineer
Engineer
Posts: 89
Joined: 20 Nov 2003 15:20

Post by MarkyParky »

I have finaly found the problem, and it is probalby code - related. I am also not sure if it isnt only OpenTTD problem (as I am testing my vehicle under OpenTTD) and if TTDPatch do or does not behave differently.

I have discovered, that if you change graphics based on refit, the change affects only first vehicle in the consist, all other vehicles remain unchanged.


So until this is somehow fixed/figured out, it is not possible to build refitable articulated trams/trucks with custom graphics using single ID :cry: .
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1794
Joined: 30 Mar 2005 09:43

Post by peter1138 »

It is. Use the 'related' varaction2 type, i.e. 82 instead of 81.
He's like, some kind of OpenTTD developer.
MarkyParky
Engineer
Engineer
Posts: 89
Joined: 20 Nov 2003 15:20

Post by MarkyParky »

Okay, somethig new to learn. But first to find some info to have at least some clue how this should work ;)... Let's wiki.... :shock:
MarkyParky
Engineer
Engineer
Posts: 89
Joined: 20 Nov 2003 15:20

Post by MarkyParky »

So finaly done ;), picture bellow shows recoded Ringhofer tram from CSTramSet both with and without attached tow van.


Thank to everyone for ideas, learning is (partialy) finished, lets go to work, lets code some stuff.
Attachments
Vehicle 4 is without towed van<br />Vehicle 7 is with towed van<br />Vehicle 10 shows refit options (in english it means &amp;quot;with towed van&amp;quot; and &amp;quot;without towed van&amp;quot; )<br />and finaly in right bottom corner you can see them in action
Vehicle 4 is without towed van
Vehicle 7 is with towed van
Vehicle 10 shows refit options (in english it means &quot;with towed van&quot; and &quot;without towed van&quot; )
and finaly in right bottom corner you can see them in action
Great Wardingham Transport, 28. b&#345;e 2009.png (75.43 KiB) Viewed 2477 times
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

MarkyParky wrote:Yes I am using it and I was all the time wondering what the hell is this warning and why does it show on otherwise correct code. :oops:
Unless you know what the message means, please do not simply ignore it. NFORenum usually knows what it's talking about. Of course, that doesn't mean that it makes it *clear* what it's talking about -- like NFO, it can be cryptic at times. Read SANITY.txt, and, failing that, ask. Once you do understand it, feel free to recommend a different error message, and/or updates to SANITY.txt.
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
MarkyParky
Engineer
Engineer
Posts: 89
Joined: 20 Nov 2003 15:20

Post by MarkyParky »

Yep, next time I will be more careful. Now from different part - I would like to use variable 45 to use different sprite in turn for second (third, etc...) part (as you recieve some glitches in turns now), but NFOrenum keeps telling me warning that such a variable does not exist. I will investigate this more in evening, meanwhile I wanted to ask if variable 45 isnt restricted to trains only?
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Post by PikkaBird »

MarkyParky wrote:meanwhile I wanted to ask if variable 45 isnt restricted to trains only?
I wouldn't be surprised. Renum obviously thinks it is.

Bear in mind you're never going to get an articulated vehicle to look perfect in turns. If you do want different sprites when turning though, you might want to look at testing the movement state, variable E2.
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

MarkyParky wrote:I wanted to ask if variable 45 isnt restricted to trains only?
It was so restricted. Or, more precisely, it had no useful definition for road vehicles, since road vehicles couldn't be articulated. By the broadest possible definition, all listed 40+x vars are available for all vehicles; NFORenum is stricter than that, defining as nonexistent all variables that wouldn't be meaningful.

(It would work like this. I tell you to pay attention when NFORenum complains, and NFORenum rewards me for my trouble by complaining when it shouldn't.)

EDIT: Fixed. New datafiles in the NFORenum thread.
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: belgi and 19 guests