How to make: industry can only be built on specific spot

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
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

How to make: industry can only be built on specific spot

Post by SirkoZ »

After looking at the confusion of Var-action 2 specifications I would like to know what's the easiest way to make:
-Oil Refinery can only be built so many squares near the water
-Farm can only be built under the snow-line
-Forest can only be built over the snow-line and so forth.

Can it be a simple Action 0 or a confusing Action 2 (a version of it)?
Please write me some commented examples if you will, because there aren't any in the GRF-specs.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: How to make: industry can only be built on specific spot

Post by frosch »

SirkoZ wrote:After looking at the confusion of Var-action 2 specifications I would like to know what's the easiest way to make:
(...)
Can it be a simple Action 0 or a confusing Action 2 (a version of it)?
You will need callback 0x28 for that.
-Oil Refinery can only be built so many squares near the water
Check industry variable 8B (Distance to the closest water tile if property 1A bit 2 is clear (built on land); distance to the closest empty dry land tile if property 1A bit 2 is clear (built on water)) in callback 28 (*) and compare it to the wanted value
-Farm can only be built under the snow-line
-Forest can only be built over the snow-line and so forth.
Check variable 87 (Ground type of the selected spot (see canal variable 81 for details) in callback 28 (*). It tells you whether the north tile of the industry is currently on/above the snowline.
Checking the summer snowline (as OTTD does for both) is not possible for newgrfs.
Please write me some commented examples if you will, because there aren't any in the GRF-specs.
If you get the basics of varaction2 you can use grf2html to take a look at other newgrfs. But do not do that in the beginning, as you would likely choose a very advanced newgrf, which might frighten you :)

However you need (in reversed order):
1) Action 3
2) VarAction2: check word variable 0C "current callback"
2a) If variable is 0x28: Chain to 4)
2b) Else: chain to 10)
3) VarAction2: Check the snow/water stuff
3a) If acceptable: return 0x400 (resp. 0x8400; 0x8000 is actually the return)
3b) If not acceptable: return 0x401 resp. 0x8401
4) Action2 Production callback: If you do not need production callbacks, just put here some arbitrary values (like producing 0 out of 0). It is just needed to terminate the chain with a callback-failed.

Note that these actions have to appear in the grf in reversed order, i.e. 4) first, 1) last.
You also have to activate callback 28 in action0 industry property 21 (Callback flags)


(*) Note: These are special variables only available during callback 28, as the normal variables are not available until the industry is built.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: How to make: industry can only be built on specific spot

Post by andythenorth »

This isn't exactly what you need (there's loads of stuff going on in this short nfo). It is reasonably commented, and it *does* use CB 28 to determine whether the 'catfood mine' industry can be built. In my case, it's checking for another industry nearby. You'll need to check a different variable. It also checks loads of other things in CBs :)

If I recall correctly, my code may also give the player some feedback via 'error' strings, which you might find useful. I wrote this at christmas though and haven't looked at it since! It has two industries in it by the way.

This code also includes the production callback you'll need to terminate the varaction 2 chain. Weirded me out the first time I saw it - I was used to coding vehicles.

(EDIT) Looks like Frosch has indicated which variables you'll need to check.

cheers,

Andy
industry_chain.nfo
(6.69 KiB) Downloaded 91 times
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: How to make: industry can only be built on specific spot

Post by SirkoZ »

ISA wrote:
SirkoZ wrote:-Farm can only be built under the snow-line
What about farms when there is variable snow line grf activated?
That's a very good question, however at this time I don't have any good solution to that problem.
__________________________________________________________________________________

Thank you very much to both of you, Frosch and Andythenorth.
I hoped it could be solved by a simple action 0, but with your pointers Frosch and Andythenorth's example .nfo I should be able to solve this one. A doozy indeed. :)
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: How to make: industry can only be built on specific spot

Post by andythenorth »

SirkoZ wrote:That's a very good question, however at this time I don't have any good solution to that problem.
PBI farms stop producing for the winter (i.e when they are above the snowline). That's one option.
(EDIT), actually, I'm not sure, it might be Alpine Climate that caused that to happen in a game where I was also using PBI.
cheers,

Andy
Last edited by andythenorth on 21 Apr 2009 06:43, edited 1 time in total.
User avatar
ISA
Tycoon
Tycoon
Posts: 3384
Joined: 17 Oct 2005 20:56
Location: Estonia

Re: How to make: industry can only be built on specific spot

Post by ISA »

andythenorth wrote:
SirkoZ wrote:That's a very good question, however at this time I don't have any good solution to that problem.
PBI farms stop producing for the winter (i.e when they are above the snowline). That's one option.

cheers,

Andy
They do?
Haven't seen that! That would be solution!
Eddi
Tycoon
Tycoon
Posts: 8289
Joined: 17 Jan 2007 00:14

Re: How to make: industry can only be built on specific spot

Post by Eddi »

the alpine farms do it like that, too.
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: Bing [Bot] and 7 guests