Interesting problems arising when coding industries....

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

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

Interesting problems arising when coding industries....

Post by andythenorth »

(For those who were helping me on irc - I gave up, my ADSL dies when it's raining, and it's currently raining grrr).

For those new to the show, I'm coding FIRS, and I'm using this thread and the #openttd irc for solving nfo problems (/me being slightly better at drawing than coding).

Problem #1.

Background:
- I am coding production boosting cargos (Engineering Supplies and Farm Supplies).
- Pretty much all FIRS industries use the production callback for gradual processing.
- I am using the monthly random production change to increase production multiplier if the correct supplies are waiting to be processed.

Problem:
My implementation works just fine when the production callback processes 0 units per month. When I start processing the cargo, often there is no cargo remaining by the time the production change callback runs, so no increase.
For various gameplay reasons, I cannot simply process the cargo very slowly, nor do I want to require that players deliver a lot of cargo :)

Question:
Could I store a flag in a register? This would be set by the production callback if cargo is present, then used (and cleared) by the monthly production change callback.
If that's a valid idea, how on earth might I do it? :shock:

Code: Select all

//Iron Ore Mine
-1 * 0 00 0A \b8 01 IND_IRONOREMINE //-1 * 0 00 0A <num-props> 01 <id>
	08 12 //substitute industry type
	09 12 //industry type override
	11 CARGO_ENGINEERINGSUPPLIES FF FF FF //acceptance cargo types (dword; fill unused with FFh)
	1C 00 00 00 00 //input cargo 1 multiplier (dword M1 M2; output_typen = X*Mn/256)
	17 \b5 //probability in random game
	18 \b2 //probability during gameplay
	21 B4 //callback flags 
	22 01  //callback flags
//To show cargo waiting to be processed at industry, ensure prop 21 is set to use production callback

//No action 1 for industries, as graphics are defined by the industry-tile feature.

-1 * 0 02 0A 00 //Production callback
	00 //version
	\w12 \w0 \w0 //<subtract-in-1..3>
	\w0 \w0 //<add-out-1..2>
	00 //don't repeat
	
-1 * 0 02 0A C2 //Random production increase if engineering supplies stockpiled...  
  81 18 00 03
  \b1 //range
    0E 80 00 00 //lookat cb 35 or 29 in wiki to see what the returned value means
  00 80 //else no change	
  
-1 * 0 02 0A C1 //Handle cb 35 monthly production change 
  85 40 00 FF FF //check cargo waiting
  \b1 // range
    C2 00  01 00  FF FF    
  00 80 //else do the standard random production change as if this industry was a primary one.
	
-1 * 0 02 0A C0 //Callback 38 display additional text in fund window
	85 0C //<type> <variable> word-access callback
	00 FF FF //no shift, no mask
	\b4 //number of ranges to check
	  00 80   29 00   29 00 //monthly production change cb 29
	  C1 00   35 00   35 00 //monthly production change cb 35
    STR_INFO_GENERIC 80   38 00   38 00 //return text-ID D0xx if cb 38 (fund window)
    STR_INFO_GENERIC 80   3A 00   3A 00 //return text-ID D0xx if cb 3A (industry window)
	\w0 //default

//Industry action 3 attach varaction2 chain to industry
-1 * 0 03 0A 01 IND_IRONOREMINE 00 \wxC0 //-1 * 0 03 09 <n-ids> <id> 00 <def-cid>	
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Interesting problems arising when coding industries....

Post by PikkaBird »

[06:47] <Pikka> I'd say set a flag during the production callback
[06:47] <Pikka> and then check/clear it in the monthly?
[06:47] <andythenorth_> using the grebs logs as my irc client sucks :P
[06:47] <andythenorth_> Pikka: yep
[06:48] <andythenorth_> exactly
[06:48] * andythenorth_ scared of registers
[06:48] <Belugas> me too...
[06:48] <Belugas> sales registers that is...
[06:48] <Pikka> there's nothing to 'em
[06:49] <Pikka> you write to them by calculating the value, then use an advanced 2 operator 10 and var 1A 00 <register #>
[06:49] <Pikka> and you read them just like any other action 2 variable
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Interesting problems arising when coding industries....

Post by andythenorth »

Solved by branching action 2 chain...changing the processing amount depending on amount waiting. This means that for any month, there will always be some cargo waiting around about the time the production change callback runs, but unless more is delivered, all cargo should be gone by the next time the production change cb runs.

This seems like a hack to me, and it presents inconsistent processing rate to the player!

Really I need to set a flag in a register when I check cargo waiting in action ID C1

Code: Select all

-1 * 0 02 0A 00 //Production callback high production
	00 //version
	\w16 \w0 \w0 //<subtract-in-1..3>
	\w0 \w0 //<add-out-1..2>
	00 //don't repeat

-1 * 0 02 0A 01 //Production callback low production
	00 //version
	\w8 \w0 \w0 //<subtract-in-1..3>
	\w0 \w0 //<add-out-1..2>
	00 //don't repeat

-1 * 0 02 0A 02 //Production callback low production
	00 //version
	\w1 \w0 \w0 //<subtract-in-1..3>
	\w0 \w0 //<add-out-1..2>
	00 //don't repeat
	
-1 * 0 02 0A C1 //branch production depending on cargo waiting 
  85 40 00 FF FF //check cargo waiting
  \b2 // range
    00 00  \w24  FF FF    
    01 00  \w16  \w23    
  02 00 // default
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Interesting problems arising when coding industries....

Post by andythenorth »

Attempting to code a stockpiling limit of 200t for Engineering Supplies. Apologies for huge amount of code!

I've setup CB 3D for industry and CB 2B for industry tiles. This looks about right to me, but I've never worked with industry tiles before.

EDIT: This now works :D

Couple of default values I'm not sure about below, otherwise what else might be wrong? cheers, Andy

Code: Select all

//Redefinition of original TTD industry
//Iron Ore Mine
-1 * 0 00 0A \b8 01 IND_IRONOREMINE //-1 * 0 00 0A <num-props> 01 <id>
	08 12 //substitute industry type
	09 12 //industry type override
	11 CARGO_ENGINEERINGSUPPLIES FF FF FF //acceptance cargo types (dword; fill unused with FFh)
	1C 00 00 00 00 //input cargo 1 multiplier (dword M1 M2; output_typen = X*Mn/256)
	17 \b5 //probability in random game
	18 \b2 //probability during gameplay
	21 B6 //callback flags 
	22 05  //callback flags
//To show cargo waiting to be processed at industry, ensure prop 21 is set to use production callback

//No action 1 for industries, as graphics are defined by the industry-tile feature.

-1 * 0 02 0A 00 //Production callback high production
	00 //version
	\w16 \w0 \w0 //<subtract-in-1..3>
	\w0 \w0 //<add-out-1..2>
	00 //don't repeat

-1 * 0 02 0A 01 //Production callback low production
	00 //version
	\w8 \w0 \w0 //<subtract-in-1..3>
	\w0 \w0 //<add-out-1..2>
	00 //don't repeat

-1 * 0 02 0A 02 //Production callback low production
	00 //version
	\w1 \w0 \w0 //<subtract-in-1..3>
	\w0 \w0 //<add-out-1..2>
	00 //don't repeat
	
-1 * 0 02 0A C1 //branch production depending on cargo waiting 
  85 40 00 FF FF //check cargo waiting
  \b2 // range
    00 00  \w24  FF FF    
    01 00  \w16  \w23    
  02 00 // default

-1 * 0 02 0A D2 //Random production increase if engineering supplies stockpiled...  
  81 18 00 03
  \b1 //range
    0E 80 00 00 //lookat cb 35 or 29 in wiki to see what the returned value means
  00 80 //else no change	
  
-1 * 0 02 0A D1 //Handle cb 35 monthly production change 
  85 40 00 FF FF //check cargo waiting
  \b1 //range
    D2 00  01 00  FF FF    
  00 80 //else no change
	
-1 * 0 02 0A A2//Return cargo acceptance (0 or 1) depending on amount of first cargo waiting
  85 40 00 FF FF
  \b1 //range 
    00 80 \w220 FF FF //I've set the industry limit slightly higher than the tile limit...otherwise the limit won't be reached for 'cargo waiting' 
  01 80

-1 * 0 02 0A A1//Handle cb 3D industry cargo acceptance
  81 18 00 FF 
  \b1
    A2 00 CARGO_ENGINEERINGSUPPLIES CARGO_ENGINEERINGSUPPLIES
  A2 00	 //what should the default be here?
	
-1 * 0 02 0A C0 //Handle callbacks
	85 0C //<type> <variable> word-access callback
	00 FF FF //no shift, no mask
	\b5 //number of ranges to check
	  04 80   29 00   29 00 //monthly production change cb 29
	  D1 00   35 00   35 00 //monthly production change cb 35
	  A1 00   3D 00   3D 00 //industry cargo acceptance
    STR_INFO_GENERIC 80   38 00   38 00 //return text-ID D0xx if cb 38 (fund window)
    STR_INFO_GENERIC 80   3A 00   3A 00 //return text-ID D0xx if cb 3A (industry window)
	C1 00 //default

//Industry action 3 attach varaction2 chain to industry
-1 * 0 03 0A 01 IND_IRONOREMINE 00 \wxC0 //-1 * 0 03 09 <n-ids> <id> 00 <def-cid>	

//Tiles 64..73
-1 * 0 00 09 \b6 01 64 // -1 * 0 00 09 <num-props> 01 <id>
	08 64 //subsitute tile type
	09 64 //industry tile override
	0E 04 //callback flags
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
-1 * 0 00 09 \b6 01 65 // -1 * 0 00 09 <num-props> 01 <id>
	08 65 //subsitute tile type
	09 65 //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 66 // -1 * 0 00 09 <num-props> 01 <id>
	08 66 //subsitute tile type
	09 66 //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 67 // -1 * 0 00 09 <num-props> 01 <id>
	08 67 //subsitute tile type
	09 67 //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 68 // -1 * 0 00 09 <num-props> 01 <id>
	08 68 //subsitute tile type
	09 68 //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 69 // -1 * 0 00 09 <num-props> 01 <id>
	08 69 //subsitute tile type
	09 69 //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 6A // -1 * 0 00 09 <num-props> 01 <id>
	08 6A //subsitute tile type
	09 6A //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 6B // -1 * 0 00 09 <num-props> 01 <id>
	08 6B //subsitute tile type
	09 6B //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 6C // -1 * 0 00 09 <num-props> 01 <id>
	08 6C //subsitute tile type
	09 6C //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 6D // -1 * 0 00 09 <num-props> 01 <id>
	08 6D //subsitute tile type
	09 6D //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 6E // -1 * 0 00 09 <num-props> 01 <id>
	08 6E //subsitute tile type
	09 6E //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 6F // -1 * 0 00 09 <num-props> 01 <id>
	08 6F //subsitute tile type
	09 6F //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 70 // -1 * 0 00 09 <num-props> 01 <id>
	08 70 //subsitute tile type
	09 70 //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 71 // -1 * 0 00 09 <num-props> 01 <id>
	08 71 //subsitute tile type
	09 71 //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 72 // -1 * 0 00 09 <num-props> 01 <id>
	08 72 //subsitute tile type
	09 72 //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
-1 * 0 00 09 \b6 01 73 // -1 * 0 00 09 <num-props> 01 <id>
	08 73 //subsitute tile type
	09 73 //industry tile override
	0A CARGO_ENGINEERINGSUPPLIES 08 //tile acceptance 1
	0B 00 00 //tile acceptance 2
	0C 00 00 //tile acceptance 3
	0E 04 //callback flags
	
-1 * 0 02 09 C1 //industry tile cargo acceptance depending on waiting cargo
    86 40 00 FF FF
    \b1 //range
     00 80 \w200 FF FF //lookup cb 2B in wiki for what the returned value means 
   01 80
-1 * 0 02 09 C0 //Handle callbacks
	81 0C 00 FF //no shift, no mask
	\b1 //range
    C1 00 2B 2B //cargo acceptance cb 2B
  FF 00 //what should the default be?
	
// action 3s for industry tiles 64-73	
-1 * 0 03 09 01 64
  00 C0 00
-1 * 0 03 09 01 65
  00 C0 00
-1 * 0 03 09 01 66
  00 C0 00
-1 * 0 03 09 01 67
  00 C0 00
-1 * 0 03 09 01 68
  00 C0 00
-1 * 0 03 09 01 69
  00 C0 00
-1 * 0 03 09 01 6A
  00 C0 00
-1 * 0 03 09 01 6B
  00 C0 00
-1 * 0 03 09 01 6C
  00 C0 00
-1 * 0 03 09 01 6D
  00 C0 00
-1 * 0 03 09 01 6E
  00 C0 00
-1 * 0 03 09 01 6F
  00 C0 00
-1 * 0 03 09 01 70
  00 C0 00
-1 * 0 03 09 01 71
  00 C0 00
-1 * 0 03 09 01 72
  00 C0 00
-1 * 0 03 09 01 73
  00 C0 00
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Interesting problems arising when coding industries....

Post by DaleStan »

andythenorth wrote:

Code: Select all

-1 * 0 02 0A A1//Handle cb 3D industry cargo acceptance
  81 18 00 FF 
  \b1
    A2 00 CARGO_ENGINEERINGSUPPLIES CARGO_ENGINEERINGSUPPLIES
  A2 00	 //what should the default be here?
	
<...>
	
-1 * 0 02 09 C1 //industry tile cargo acceptance depending on waiting cargo
    86 40 00 FF FF
    \b1 //range
     00 80 \w200 FF FF //lookup cb 2B in wiki for what the returned value means 
   01 80
-1 * 0 02 09 C0 //Handle callbacks
	81 0C 00 FF //no shift, no mask
	\b1 //range
    C1 00 2B 2B //cargo acceptance cb 2B
  FF 00 //what should the default be?
In both cases, an industry tile standard action 2. You may need to re-invent the built-in tile information, though you can evade this (albeit at the cost of making NFORenum unhappy) by checking for var0C == 0, returning a callback result there, and returning graphics for everything else.
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: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Interesting problems arising when coding industries....

Post by andythenorth »

Code: Select all

-1 * 0 02 0A A1//Handle cb 3D industry cargo acceptance
  81 18 00 FF 
  \b1
    A2 00 CARGO_ENGINEERINGSUPPLIES CARGO_ENGINEERINGSUPPLIES
  A2 00	 //what should the default be here?
DaleStan wrote:In both cases, an industry tile standard action 2.
That surprised me...in the case of an industry action 2 chain, it seems counter-intuitive to provide an industry tile action 2, rather than another industry action 2? Have I misunderstood.
DaleStan wrote:You may need to re-invent the built-in tile information, though you can evade this (albeit at the cost of making NFORenum unhappy) by checking for var0C == 0, returning a callback result there, and returning graphics for everything else.
Okay, I think I'll need to re-invent the original tile info. That means a lot more code to write, but I suspect the info is kicking around somewhere...this code will be needed to support snow tiles, so it's going to be useful in future anyway :)

EDIT: I'm still totally confused about default IDs in varaction 2s that provide a callback result :shock:

Example: check 1 range and return a text ID if in range, otherwise a default (but I really don't care about the result, I just don't want to crash the game, that would be rude). The examples from mb in the TTDPatch Wiki imply that I should return FF FF for such a default...is that wrong?
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Interesting problems arising when coding industries....

Post by PikkaBird »

andythenorth wrote: That surprised me...in the case of an industry action 2 chain, it seems counter-intuitive to provide an industry tile action 2, rather than another industry action 2? Have I misunderstood.
I think Dalestan was thinking of callback 2B rather than 3D. I have no idea what he means by "you may need to re-invent the built-in tile information".
EDIT: I'm still totally confused about default IDs in varaction 2s that provide a callback result :shock:
Generally, the default in a callback action 2 should be "where do I go if this isn't the callback I'm looking for". FF FF is a callback result (for historical reasons, FF in the high byte of the result means the same as 80), so you generally wouldn't return that unless that's what you want to return. :)

Remember, every time your grf goes through the action 2 chain, it should end up at either
a) a meaningful callback result, or
b) the graphics you want to display.

With respect to callback 3D, this is a 3D block from TaI:

Code: Select all

    // is a product waiting to be processed?  < x = accept cargo
  493 * 17	 02 0A 55 85 41 00 FF FF 01 01 80 00 00 \w800  00 80 // coal
  494 * 17	 02 0A 33 85 40 00 FF FF 01 01 80 00 00 \w1000 00 80 // ore
  495 * 14	 02 0A 30 81 18 00 FF 01 33 00 0E 0E 55 00
  496 * 14	 02 0A 11 81 0C 00 FF 01 30 00 3D 3D 31 00
As you can see stepping through it, the default in sprite 496 points to the next block of the chain (action 2 id 31). Otherwise, if we are checking 3D, this chain always ends in one of the four callback results in sprites 493 and 494.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Interesting problems arising when coding industries....

Post by andythenorth »

PikkaBird wrote:Remember, every time your grf goes through the action 2 chain, it should end up at either
a) a meaningful callback result, or
b) the graphics you want to display.
Thanks. I'm still confused by an example like this though (cb3D) :P If A1 returns an action 2 ID as the default, how does C1 ever get a result for cb 3D? Having tried different values for the default for A1, it seems to just work, no matter what the default... (and FF FF is not a meaningful result for this callback as far as I can see!). Still scratching my head and stroking my chin :)

Code: Select all

-1 * 0 02 0A A1//Handle cb 3D industry cargo acceptance
  81 18 00 FF 
  \b1
    A2 00 CARGO_ENGINEERINGSUPPLIES CARGO_ENGINEERINGSUPPLIES
  FF FF	 //default
	
	
-1 * 0 02 0A C0 //Handle callbacks
	85 0C //<type> <variable> word-access callback
	00 FF FF //no shift, no mask
	\b6 //number of ranges to check
	  04 80   29 00   29 00 //monthly production change cb 29
	  D1 00   35 00   35 00 //monthly production change cb 35
	  B1 00   37 00   37 00 //monthly production change cb 37
	  A1 00   3D 00   3D 00 //industry cargo acceptance
          STR_INFO_GENERIC 80   38 00   38 00 //return text-ID D0xx if cb 38 (fund window)
          STR_INFO_ES_PRIMARY_BOOST 80   3A 00   3A 00 //return text-ID D0xx if cb 3A (industry window)
	C1 00 //default
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Interesting problems arising when coding industries....

Post by PikkaBird »

If A1 returns an action 2 ID as the default, how does C1 ever get a result for cb 3D?
If a callback chain returns a real sprite, the callback fails, and does nothing / does the default behaviour.

In the case of callback 3D, if you wanted to return a callback ID as the default in A1, technically it should be 00 80. However, since your mine only accepts one cargo anyway, sprite A1 is superfluous; it's never going to reach the default, and you may as well take the sprite out altogether. :)
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Interesting problems arising when coding industries....

Post by andythenorth »

PikkaBird wrote:In the case of callback 3D, if you wanted to return a callback ID as the default in A1, technically it should be 00 80. However, since your mine only accepts one cargo anyway, sprite A1 is superfluous; it's never going to reach the default, and you may as well take the sprite out altogether. :)
Yay, some understanding. I've removed A1 and jump straight to A2 which checks var 40 (cargo waiting).

Could I also have kept A1, and returned either 00 80 (don't accept) or 01 80 (accept)? That wouldn't have done much in the real world, but would have a valid result for this cb as far as I can see?

What about this example with strings? I *do* need B1 to check the right cargo type. Should I create an empty string somewhere and return the ID for that as the default result?

Code: Select all

-1 * 0 02 0A B1//Handle cb 37 cargo subtexts (used here to provide max cargo limit information)
  81 18 00 FF 
  \b1
    STR_INFO_LIMIT_200 80 00 00
  FF FF	 //default
	
	
-1 * 0 02 0A C0 //Handle callbacks
	85 0C //<type> <variable> word-access callback
	00 FF FF //no shift, no mask
	\b6 //number of ranges to check
	  04 80   29 00   29 00 //monthly production change cb 29
	  D1 00   35 00   35 00 //monthly production change cb 35
	  B1 00   37 00   37 00 //cargo subtext industry window cb 37
	  A2 00   3D 00   3D 00 //industry cargo acceptance
    STR_INFO_GENERIC 80   38 00   38 00 //return text-ID D0xx if cb 38 (fund window)
    STR_INFO_ES_PRIMARY_BOOST 80   3A 00   3A 00 //return text-ID D0xx if cb 3A (industry window)
	C1 00 //default
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Interesting problems arising when coding industries....

Post by PikkaBird »

andythenorth wrote:What about this example with strings? I *do* need B1 to check the right cargo type. Should I create an empty string somewhere and return the ID for that as the default result?
The wiki says "Returning FFh causes no text to be displayed", so I guess you do that. ;)
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Interesting problems arising when coding industries....

Post by DaleStan »

andythenorth wrote:

Code: Select all

-1 * 0 02 0A A1//Handle cb 3D industry cargo acceptance
  81 18 00 FF 
  \b1
    A2 00 CARGO_ENGINEERINGSUPPLIES CARGO_ENGINEERINGSUPPLIES
  A2 00	 //what should the default be here?
DaleStan wrote:In both cases, an industry tile standard action 2.
That surprised me...in the case of an industry action 2 chain, it seems counter-intuitive to provide an industry tile action 2, rather than another industry action 2? Have I misunderstood.
AAUGH! Nope. I misunderstood. Somehow I thought that was an industry tile chain. For industries, fail conventional callbacks by returning a production callback result.
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 “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 20 guests