Various NML related questions

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

Moderator: Graphics Moderators

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

Re: Various NML related questions

Post by frosch »

3iff wrote: The code.

in the relevant switch,

return [STORE_TEMP(string(STR_CONCAT2, string(STR_TOWN), string(STR_IND_COAL_MINE), string(STR_RESERVE_ANNOUNCE)), 0x100), CB_RESULT_IND_PROD_DECREMENT_BY_1 | 1 << 8];

in the lang file,

STR_CONCAT2 :{BLACK}{BIGFONT}{STRING}{NBSP}{STRING}{}{STRING}
(allows 3 strings to be displayed, town, industry type and the announcement)

STR_IND_COAL_MINE :Coal Mine
STR_RESERVE_ANNOUNCE :{BIGFONT}{BLACK}announces reserves are likely to be {RED}exhausted{BLACK} within 5 years.


It might not be pretty or elegant but it seems to work. I hadn't realised it might have been that easy.
It's funny that you say that works :p

Anyway, there is no such thnig as "text stack" for the production change callbacks.
However, the first "{STRING}" in the text will be replaced by the town name, and the second "{STRING}" will be replaced by the industry name.

So your case can be simplified to:

Code: Select all

STR_RESERVE_ANNOUNCE  :{BIGFONT}{BLACK}{STRING} {STRING} announces reserves are likely to be {RED}exhausted{BLACK} within 5 years.

 return [STORE_TEMP(string(STR_RESERVE_ANNOUNCE), 0x100), CB_RESULT_IND_PROD_DECREMENT_BY_1 | 1 << 8];
The rest probably prints error messages somewhere, or is ignored.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

Thanks for that. The new code does work as you suggest. I admit I was surprised that my code worked - in that I got the expected result - perhaps despite my coding.

I hadn't expected the news report to display the industry name unless I passed the data across, I obviously underestimated the code.

Still, I'm getting better...
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

I currently have code to potentially close down an industry.

switch (FEAT_INDUSTRIES, SELF, oil_refineryclose_random, (extra_callback_info2 & 32)) {
0: return CB_RESULT_IND_PROD_CLOSE;
return CB_RESULT_IND_PROD_NO_CHANGE;
}

"extra_callback_info2 & 32" is what I'm having trouble understanding. I think that extra_callback_info2 contains random bits and 'if' I have my thoughts right, if bit 6 of info2 (counting from the right) is 1 then the test is true.

extra_callback_info2 = ....010010
32 = 100000

so 010010 & 100000 = 0 , Yes?

If so, that's a 50/50 chance. If I wanted a 1 in 4 chance could I do "extra_callback_info2 & 48"?

Basically I want to reduce the chance of some industries closing. Other code controls whether the industry is permitted to close and that's working fine.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Various NML related questions

Post by Alberth »

3iff wrote:I currently have code to potentially close down an industry.

switch (FEAT_INDUSTRIES, SELF, oil_refineryclose_random, (extra_callback_info2 & 32)) {
0: return CB_RESULT_IND_PROD_CLOSE;
return CB_RESULT_IND_PROD_NO_CHANGE;
}

"extra_callback_info2 & 32" is what I'm having trouble understanding. I think that extra_callback_info2 contains random bits and 'if' I have my thoughts right, if bit 6 of info2 (counting from the right) is 1 then the test is true.

extra_callback_info2 = ....010010
32 = 100000

so 010010 & 100000 = 0 , Yes?
I have no idea about the NML code, but I understand bits :)
Your bit number is off by one (it's bit 5 rather than 6), as it starts counting from 0 (2^0 = 1, 2^1 = 2, ... 2^5 = 32), but otherwise, it's all correct.
If so, that's a 50/50 chance. If I wanted a 1 in 4 chance could I do "extra_callback_info2 & 48"?
hmm, bloody decimal numbers :?
ah, 0x30, indeed, fully correct again :)
If you use that as mask, you can get 0, 0x10, 0x20, and 0x30. You close on 0, and you keep it open on the other cases, indeed 1/4.

For enhanced readability, you may want to write "extra_callback_info2 & (16+32)", or use the "bitmask" function, as in "extra_callback_info2 & bitmask(4, 5)". The bitmask function constructs the 2^4+2^5 = 0x30 = 48 value for you from the given list of bit positions.
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

Thanks yet again, you're always reliable.

Binary is something I've only ever tried in small doses. Sorry about the decimals.
I'll use (16+32) as that's clearer to me than bitmask().

At last, I got something right!
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Various NML related questions

Post by Alberth »

3iff wrote:Binary is something I've only ever tried in small doses. Sorry about the decimals.
No problem, it's just me. I use decimal notation for 'numbers', like length, speed, life time, etc, and hexadecimal notation for collections of bits (were you don't care about the numerical value, you only want to know which bits are 1, and which bits are 0). When I read a hexadecimal digit, I see its bit pattern as I have them all in my head.

0x30 is thus not 48 for me, it's "lowest 2 bits are 1 in the high nibble"
3iff wrote:I'll use (16+32) as that's clearer to me than bitmask().
Same here
At last, I got something right!
yay!
Before you know it, you're an expert :)
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

An expert is someone who knows more and more about less and less until they know everything about nothing. :mrgreen:
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

I'm back again with another problem.

I have a new industry type that becomes redundant around a certain date. I want the ability to close them all down eventually, but the game persists in keeping the last one. While testing, I've seen the last one trigger a closedown call but it's apparently being ignored.

Is there an way to override this or do I have to put up with keeping this last one of its kind persisting forever?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Various NML related questions

Post by planetmaker »

3iff wrote:I'm back again with another problem.

I have a new industry type that becomes redundant around a certain date. I want the ability to close them all down eventually, but the game persists in keeping the last one. While testing, I've seen the last one trigger a closedown call but it's apparently being ignored.

Is there an way to override this or do I have to put up with keeping this last one of its kind persisting forever?
That's related to the properties prob_random and prob_in_game. if prob_random is non-zero at least one of those industries is *guaranteed* to be around to the extend OpenTTD can assure. Keeping the last one around is one of those means.
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

So, if I set prob_random to zero then none will appear at game start but they should be built during the game and they will eventually go away?

I'll give that a try. I wouldn't have thought to look in that place.

Thanks yet again.

Just checked the wiki and it does say that...but I would not have looked there for that info...(just a comment, not a criticism).

-----

No, that didn't work. I set prob_random to zero and starting a new game didn't produce any of that industry type (as expected) so I built 3. Two closed down and although the third did produce a closedown trigger (I test and display a number in the perm registers) it's still there.

In any case, even if it did work it's not an ideal solution...but one I may have to put up with.
I'll test some more anyway.

-----


I might be misreading or misunderstanding. If prob_random is nonzero then at least one is formed at game start...

I haven't tried prob_in_game = zero yet but that's not really a solution either as I want/need the possibility for others to be built during the game.

I might be stuck...but perhaps I can keep one for posterity (or just blow it up).
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

you might want to have special industry flag 17: http://newgrf-specs.tt-wiki.net/wiki/Ac ... r_.281A.29
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Various NML related questions

Post by planetmaker »

Ah, indeed setting IND_FLAG_ALLOW_CLOSING_LAST_INSTANCE in spec_flags is more likely to do the trick.
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

Wonderful, I'll try that. Thanks all.

Perfect! It works. Thanks Eddi, well spotted.
meslinjf
Engineer
Engineer
Posts: 20
Joined: 09 Jul 2015 17:32

Re: Various NML related questions

Post by meslinjf »

Hi,

As you can see in these last posts, I've been modifying the source of the ogfx-rv set and am now trying to compile the grf. I've gone through the tutorial available here: http://dev.openttdcoop.org/projects/hom ... nvironment

Unfortunately, I'm stuck and received the following error message: Image

Can anyone help me out with what to do next?
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

This question is better posted in the relevant thread. I see you posted there saying there's an error post here...

That's confusing.

Have you compiled something before? If not then your compile setup might be wrong...but I'm not really the one to point you in the right direction to fix it.
meslinjf
Engineer
Engineer
Posts: 20
Joined: 09 Jul 2015 17:32

Re: Various NML related questions

Post by meslinjf »

It's my first time compiling, so I'll look into my setup.

I'm sorry if this is not the best thread to post such a question. I felt this was just another question on how NML works.
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

I don't mind...but I think your problem might be compiler setup related rather than NML issues.

(It can be confusing until you get a working environment, and then it can get very confusing... :wink: )
User avatar
TrainLover
Engineer
Engineer
Posts: 107
Joined: 01 Jul 2015 15:03

Re: Various NML related questions

Post by TrainLover »

How do you do the spriteset thing? I am using the old way of defining the spriteset. And also how do you do a purchase menu thing?
Developer of North American Passenger Liveries: viewtopic.php?f=26&t=87228
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: Various NML related questions

Post by Transportman »

meslinjf wrote:Hi,

As you can see in these last posts, I've been modifying the source of the ogfx-rv set and am now trying to compile the grf. I've gone through the tutorial available here: http://dev.openttdcoop.org/projects/hom ... nvironment

Unfortunately, I'm stuck and received the following error message:

Can anyone help me out with what to do next?
Which software versions did you install when following my guide? I do recall having had that error, and it was related to using the wrong Python version for the FindVersion script (which needs Python 2.7).
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: Various NML related questions

Post by Sylf »

Something I didn't see in the guide after a quick skim: you need a c compiler to compile OpenGFX+ RV set. There's no C code, but it uses C preprocessor.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 24 guests