Page 1 of 1

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

Posted: 18 Apr 2009 16:59
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.

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

Posted: 18 Apr 2009 19:22
by ISA
SirkoZ wrote:-Farm can only be built under the snow-line
What about farms when there is variable snow line grf activated?

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

Posted: 18 Apr 2009 19:51
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.

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

Posted: 18 Apr 2009 20:04
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 92 times

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

Posted: 19 Apr 2009 01:53
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. :)

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

Posted: 19 Apr 2009 07:04
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

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

Posted: 19 Apr 2009 14:20
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!

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

Posted: 20 Apr 2009 23:51
by Eddi
the alpine farms do it like that, too.

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

Posted: 21 Apr 2009 06:44
by andythenorth
Eddi wrote:the alpine farms do it like that, too.
:oops: Ooops, it might be that I had the Alpine Climate grf active in a game where PBI was also active.