NFO - industry construction callback query...

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

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

NFO - industry construction callback query...

Post by andythenorth »

I have a case where it would be useful to have 'more complicated' conditions for industry construction.

Sample logic:

1. Attempt to build new industry.
2. Find nearest industry of type x to selected position
3. If nearest industry of type x is not within n tiles of selected position, new industry can't be built (return 0000-03ff), else...
4. If nearest industry of type x has not produced p units of cargo q within the last r months, new industry can't be built (return 0000-03ff), else...
5. Build industry.

That's not the only logic I might wish to use, but it will serve as a sufficient example.

I am a little jet-lagged, but I have been reading nfo documentation (specifically action 2 Callback 28), and my conclusion is that the above is not possible (which of course is fine if that's the case).

Is my conclusion correct, or have I missed something? :wink:

thanks,

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

Re: NFO - industry construction callback query...

Post by DaleStan »

3 is possible, 4 is not. The others are tasks for TTDPatch, or the user, not NFO.
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: NFO - industry construction callback query...

Post by andythenorth »

DaleStan wrote:3 is possible, 4 is not. The others are tasks for TTDPatch, or the user, not NFO.
Thanks, that helps.

As a theoretical question, would extending nfo to support 4 (above) be:
- impossible?
- possible but highly unlikely / undesirable?
- possible?
- none of the above?
(Assuming that the necessary support could be added in TTDPatch and OpenTTD)

cheers,

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

Re: NFO - industry construction callback query...

Post by DaleStan »

In terms of TTDPatch internals, that would actually be one of the simpler things to implement -- the feature doesn't change, as it would for, eg, providing access to vehicle and station data in CB 145.

A logical NFO[0] encoding for that object shift is difficult for me to imagine, though.

[0] Yes, I did just apply that adjective to that noun.
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: NFO - industry construction callback query...

Post by andythenorth »

DaleStan wrote:In terms of TTDPatch internals, that would actually be one of the simpler things to implement -- the feature doesn't change, as it would for, eg, providing access to vehicle and station data in CB 145.
Ok, well thanks for the info.

The back story here is that I think (expensive) industry construction by the player is one of the better solutions to the 'problem' of 'too much money' (I find it a problem, others see it as the point of the game). However simply constructing or prospecting for industries is not an interesting challenge - I am looking at ways to provide interesting conditions that would have to be met (such as building near a power station that is producing electricity), or for varying an industry's production based on the production of nearby industries (such as a power station that is producing electricity). There are more possibilities than the power station, but it's the simplest example.

I am aware that some may see this as a perversion of what is fundamentally a transport game, but I'll have to take my chances with that. The gameplay changes I envisage are entirely appropriate to a newgrf; adding them to the core game would be entirely inappropriate, therefore I am currently coding a test grf for an industry chain applying this philosophy. For now I can use distance to nearest industry of type n as a reasonable proxy for more interesting conditions.

If my thinking stands up ok in the test grf, it would be very useful to then be able to implement additional conditions such as described in the thread above; I am aware that this would rely on support from TTDPatch and OpenTTD developers and is not a small ask (if possible at all).
DaleStan wrote: A logical NFO[0] encoding for that object shift is difficult for me to imagine, though.

[0] Yes, I did just apply that adjective to that noun.
Well, I'm starting to find NFO strangely logical and elegant. This may be a bad sign for my well-being. I think coding nfo is now corrupting my Python abilities...I'm looking at dicts and finding them both too simple and too complicated...also objects with methods, easy-use strings as keys and variable names, ints, dicts, tuples, lists, square bracket access; all seems like high level craziness after 2 straight days of nfo.

cheers,

Andy
User avatar
AndersI
Tycoon
Tycoon
Posts: 1732
Joined: 19 Apr 2004 20:09
Location: Sweden
Contact:

Re: NFO - industry construction callback query...

Post by AndersI »

andythenorth wrote:I'm looking at dicts and finding them both too simple and too complicated...also objects with methods, easy-use strings as keys and variable names, ints, dicts, tuples, lists, square bracket access; all seems like high level craziness after 2 straight days of nfo.
That is a serious condition! I'd prescribe reading the threads about "High level NFO" as medicine :-)
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: NFO - industry construction callback query...

Post by DaleStan »

And that's supposed to be a *cure*? :p
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: NFO - industry construction callback query...

Post by andythenorth »

Okey dokey, so to learn how callback 28 works, I have created an action 2 chain that checks the town population and distance to town centre to determine if the industry can be built. This successfully returns 0400 to callback 28 to build the industry, or text string IDs for messages to the player.
catfood_location.png
catfood_location.png (61.61 KiB) Viewed 3379 times
However research shows that cat food miners are more interested in electricity supply than being in town, and I would like to use industry variational action 2 67 to check the distance to the nearest power station. My existing code for distance to town is below.

Code: Select all

   10 * 14	 02 0A 0E
      81 89 00 FF 01  // check distance to town 
          00 84 00 0F // returns 0400 (build) (due to the magic of 84) if distance is between 0 and 15
        04 80 // otherwise returns string D0 04
I am unsure of how to:
- set the parameters (grf ID, industry ID (01)) that action 67 requires
- make use of the results which are in the format rrccdddd, and the dddd element is what I want to check

Code: Select all

 // my starting guess
        81 67 ?? Parameters ?? 01
           00 84 00 00 00 0F // distance between 0 and 15
        04 80 // otherwise returns string D0 04
Documentation for action 67

Apologies for being dim about this, I can't seem to acquire any conceptual understanding of registers. :oops: Location is one of two stumbling blocks for my industry chain and the good news is that I nearly have it nailed :) . The bad news is that I have yet to tackle varying production levels :shock: .

Although I am having a great deal of fun with nfo, if anybody would like to spend dark winter evenings coding an industry chain, I would happily give up the glory and get on with drawing graphics. :wink:

cheers,

Andy
a.locritani
Engineer
Engineer
Posts: 111
Joined: 08 Feb 2007 11:59
Skype: a.locritani
Location: Italy

Re: NFO - industry construction callback query...

Post by a.locritani »

I'm quite new to GRF (so maybe i'm telling rubbish) but why don't use variable 64? it seems to obtain the same effect in a simpler way.

variable 67 takes a single parameter, the industry type id. for default industries, it can be found here.

on the other hand, to set the registry value you can use operator 0E of variational action 2, as written in variable 67 description (using 01 00 - i'm not sure here if is correct or endianness applies - as val2 and 00 00 00 00 - if checking default industres - or FF FF FF FF - if checking your own GRF - as val1)

and to use only a part of the result, I think the best way is using 81,85 or 89 as type (in this case i think you should use 85 - instead of 81)

Hope this helps (and hope i'm not telling nonsense :wink: )
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: NFO - industry construction callback query...

Post by andythenorth »

Thanks. So
- variational action 2 dealing with callback 28
- variable 67 (information about industries of type n)
- type 85 because I want the lowest word from the result rrccdddd
- use 0E to set parameters

As trying is often the best way to learn, I've tried the following code, which as you'll see produces a renum error...

Code: Select all

   
// excessive linebreaks to isolate elements here, not how I would usually format code
//!!Fatal Error (173): Offset 6: shift may not have both high bits set.
10 * 14	 02 0A 0E
      85 67 00 FF 
        0E 01 00 00 // industry ID 01; varadjust 0
        0E 00 00 00 00 00  // check the default industries; varadjust 0 
        01  
          00 84 00 00 00 0F // returns 0400 (build) (due to the magic of 84) if distance is between 0 and 15
        04 80 // otherwise returns string D0 04
I have probably made several odd mistakes here, any chance of a smack from the cluebat?

cheers,

Andy
PhilSophus
Chairman
Chairman
Posts: 776
Joined: 20 Jan 2007 12:08
Location: Germany

Re: NFO - industry construction callback query...

Post by PhilSophus »

andythenorth wrote:I have probably made several odd mistakes here, any chance of a smack from the cluebat?
I'm not an expert, either, but the problem it is complaining about, is the FF at the end of the second line. This is the shift-num field of the varadjust parameter and shouldn't have both bits 7 and 6 set (see the spec for variational action 2 for details). Probably you mis-counted the fields and thought it was something else (maybe you thought variable was a word?).
andythenorth wrote:

Code: Select all

   
// excessive linebreaks to isolate elements here, not how I would usually format code
//!!Fatal Error (173): Offset 6: shift may not have both high bits set.
10 * 14	 02 0A 0E
      85 67 00 FF // <--- HERE IS THE ERROR
      // rest snipped
"The bigger the island of our knowledge, the longer the shore of our ignorance" - John A. Wheeler, Physicist, 1911-2008
a.locritani
Engineer
Engineer
Posts: 111
Joined: 08 Feb 2007 11:59
Skype: a.locritani
Location: Italy

Re: NFO - industry construction callback query...

Post by a.locritani »

I'm quite sure you should use a word "and mask" here, because you're masking a word value (you're using 85 to extract a word, remember)

Code: Select all

 85 67 00 FF

should become

85 67 00 FF FF
------
edit:as PhilSophus said (while I was writing my post... :wink: )
------

further, you should consider that to use advanced varaction2 you should use this format:

variable1 varadjust1 (with bit 5 set in shift mask) operator variable2 varadjust2 (see here).

looking at your code it seems not respected (no bit 5 set in shift mask and maybe too much 0e operator?)

As I already said, I'm new to GRF so I can only speak reading from wiki. Nevertheless I hope this can help you. And I hope some GRF expert will come here to help us... :wink:
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: NFO - industry construction callback query...

Post by michael blunck »

For the mask part you´ll need a mask which is equally long as the value to be masked, i.e.

FF for a byte,
FF FF for a word, and
FF FF FF FF for a double word.

However, for the shift part, you´ll always use a byte value (because this would be sufficient to allow the max number of shifts).

Andy, I don´t know what you´re planning to do, but I´d second Angelo´s proposal to use var64 instead of 67.

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

Re: NFO - industry construction callback query...

Post by andythenorth »

michael blunck wrote: Andy, I don´t know what you´re planning to do, but I´d second Angelo´s proposal to use var64 instead of 67.
Appealing. Based on a note in the wiki, I'd come to the conclusion that var 64 was deprecated in favour of var67, however I guess var 64 is not going away?

It seems 'tidier' to look for an industry specifically in *my* grf, but are there any real issues if I don't do that?

thanks,

Andy
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 990
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NFO - industry construction callback query...

Post by frosch »

you are missing the parameter of variable 67. 60+x variables get an additional byte paramter, which directly follows the variable number.

Take a look at:

Code: Select all

    1 * 28	 02 0A 99 85
		      1A    20 \wx0 
		\2sto 1A    20 \wx100
		\2rst 67 00 00 \wxFFFF
		01
		\wx8401 \w0 \w30
		\wx8400
It loads the constant 0, stores it in register 0x100, reads variable 0x67 with paramter 0 and then returns 0x401 for values between 0 and 30, or 0x400 else.

Edit: corrected typo (0x74 -> 0x67)
Last edited by frosch on 05 Dec 2008 19:43, edited 1 time in total.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: NFO - industry construction callback query...

Post by michael blunck »

Yeah, using registers is real fun. 8)
andythenorth wrote:Based on a note in the wiki, I'd come to the conclusion that var 64 was deprecated in favour of var67
Wiki wrote: Variable 64 will stay for backward compatibility only. [emph. mb]
Well, I wouldn´t call that deprecated ...

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

Re: NFO - industry construction callback query...

Post by andythenorth »

frosch wrote:It loads the constant 0, stores it in register 0x100, reads variable 0x74 with paramter 0 and then returns 0x401 for values between 0 and 30, or 0x400 else.
Ow. ?(

I just showed that to a programmer who sits next to me at work. His comment: "so you're programming in assembly? That's insane!" Sadly he's a Simutrans contributor, and is now feeling smug. But lets not talk about that here. The main thing is that he's a good judge of my programming skills (I'm his boss) and he wasn't exactly confident that I'd be able to make this work :roll:

However there's no way I'm giving up yet! I like learning and I'm now determined to understand what's going on here, if you guys will forgive my limited experience...

@ Frosch - thanks for the example, I'll re-read documentation and see how I get on.
(EDIT) I tried copy and paste of the example code above (I changed the action 2 ID), but nfo-renum is reporting an error with it.

Code: Select all

//!!Fatal Error (43): Offset 5: Linter requires 1 byte(s) which do(es) not exist.
   11 * 5	 02 0A 0E 85
            1A    20 \wx0
      \2sto 1A    20 \wx100
      \2rst 67 00 00 \wxFFFF
      01
      \wx8401 \w0 \w30
      \wx8400
@ Michael, thanks for the clarification.

cheers,

Andy
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 990
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NFO - industry construction callback query...

Post by frosch »

0x74? Why did I write 0x74 :s

However, my pasted code is fine for my versions of renum, grfcodec and grf2html.
Maybe you have a old one which does not understand some of the escape sequences.

In that case use

Code: Select all

    1 * 28	 02 0A 99 85
		    1A    20 00 00
		 0E 1A    20 00 01
		 0F 67 00 00 FF FF
		 01
		 01 84 00 00 1E 00
		 00 84
Edit: And yes, advanced action2 are like assembly-programming a cpu with one accumulator, some registers ("temporary storage registers"), some memory ("persistent storage registers", only industries), and various I/O ports ("variables" of varaction"), which are partly writeonly and mapped into the register address space ("temporary registers" starting from 0x100)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: NFO - industry construction callback query...

Post by andythenorth »

frosch wrote: In that case use

Code: Select all

    1 * 28	 02 0A 99 85
		    1A    20 00 00
		 0E 1A    20 00 01
		 0F 67 00 00 FF FF
		 01
		 00 84 00 00 1E 00
		 01 84
Thanks - that compiles ok. :)

So that I'm learning, not just asking other people to write my code:
- are the 20s in the code above setting bit 5?
- does the code above set the industry type to 01 (power station)? (I can't work it out).

thanks,

Andy
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: NFO - industry construction callback query...

Post by DJ Nekkid »

to figure out what bit it is, use the built-in calc.exe in windows

set it to scientific
set it to hex
type in 20
set it to bin
then you end up with 100000 ... i.e. bit 5 :)
Member of the
ImageImage
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 13 guests