Page 60 of 65

Re: NML - a Newgrf Meta Language

Posted: 26 Nov 2016 21:08
by GarryG
Hi Pyoro and frosch,

I seem to have won and not getting any undefined string messages now. At least not see any visible.

What I done in the language files for instance like Pyoro mention I reduced the strings on many of the objects from this:

Code: Select all

STR_reef4                  :Reef Large Rocks
STR_reef4_purchase_view1   :Reef Rocks
STR_reef4_purchase_view2   :Reef Rocks
STR_reef4_purchase_view3   :Reef Rocks
STR_reef4_purchase_view4   :Reef Rocks
to this

Code: Select all

STR_reef4            :Reef Large Rocks
There would have been over 100 entries that I was able to change like that above and still some I can change in the other object sets I done and doing.

And in the NML file I delete the code for the string switch (switch (FEAT_OBJECTS, SELF, switch_add_text_STR_reef4, view) ...). Not needed anymore, obviously.

Also changed reference to the PURCHASE sprites.

Code: Select all

spriteset (spriteset_reef4_PURCHASE) {
    template_building_low(0,0,"gfx/reef4.png")
}
I did this for all objects that the Purchase sprite was same size as the normal sprite.
frosch wrote:About your sprite sharing: You can share sprites between different graphic chains and even different objects just fine. Sharing them reduces memory usage.
Good if I can do this, I will alter the class and classnames again so this will share same chains.

Thank you all kindly for your help in solving this problem.

Cheers fellas

Garry

Re: NML - a Newgrf Meta Language

Posted: 30 Nov 2016 11:36
by Quast65
Suggestion:
Not sure if it is at all possible (if not please ignore this ;-) )

I often like to make minute changes to other GRFs, replacing just certain graphics and keeping the rest as is. (for example I have edited the UK-roadset in my games in such a way that it displays sidewalks also on rural roads)
Now I do this by recompiling the edited GRF, just with a change to the original name and keeping the same GRF-ID, so I can easily find it in my unused GRF-list next to its original version and it will also not disrupt my save-games or scenarios.

However, in some cases depending on the license of the GRF, these kind of changes are not allowed to be publically released and one needs to contact the original creator(s) of the GRF and donate these sprites, hoping they will be implimented (or implimented as extra option via parameter). This process can take up some time as some creators cant be contacted easily or dont want to make the changes to their GRF.
An example I could give for this is with one of my own sets, the Fake Airport Objects. For the taxiways I use yellow lines, some people suggested that they would like these lines to be thinner/sharper. I dont agree ;-) Therefor I wont impliment this (not even as a parameter, I really dont like the look of it ;-) ). The set is GPL licensed though, so someone else could make these changes and re-release the set, but if they dont add it as a parameter they will need to release it as a completely separate set, including also graphics that havent been changed.
But hopefully that wont be necessary anymore if my suggestion is feasible....

Therefor I would like to know if it is possible to have an option to change graphics within a GRF, working a bit like Action-5 in NFO for replacing base set sprites not present in the original TTD.
For example, by combining the unique GRF-ID of a GRF with an offset to the graphics within it that you want to change.

Is this at all possible and if so, interesting enough to impliment?

Re: NML - a Newgrf Meta Language

Posted: 07 Jan 2017 22:36
by GarryG
Bounding Boxes.

Can anyone tell me how to add bounding boxes to my coding?

Been told could be reason I having a few graphic issues in the object sets I doing.

Cheers

Re: NML - a Newgrf Meta Language

Posted: 08 Jan 2017 12:14
by frosch
Bounding boxes are mostly a myth. While there is a thing called "bounding boxes" in the game, I am 99% sure whoever hinted towards them did not know how bounding boxes work, and bounding boxes won't help fix your issues.
The purpose of bounding boxes is to sort sprites within a tile. But in case of NewObjects there is only one thing on the tile (your object), so there is not much to sort. People often think they can use bounding boxes to sort stuff against stuff on neighbouring tiles, however bounding boxes have hardly any influence on that. (mostly because bounding boxes only affect "how" to draw, but not "what" to draw)

Regarding bounding boxes:
For NewObjects the only part you may possibly want to adjust is "zextent" in the "building" part of your "spritelayout".
Set it to approximately reflect the height of your object. That helps in case of bridges next to your object.

Regarding glitches:
You need to distinguish two types of glitches:
* Glitches because sprites change the order they are drawn in. ("how" to draw)
* Glitches because sprites are skipped, and not drawn at all. ("what" to draw)

Bounding boxes help in the first case, but not in the second.
The most often glitch I see is the second case, when sprites extent over the left or right corner of the tile. In that case you have to cut the object more precisely. (Changing bounding boxes does not affect this, because this is an issue about "what" to draw, and bounding boxes have no influence on that)

Re: NML - a Newgrf Meta Language

Posted: 08 Jan 2017 12:28
by GarryG
Thank you kindly frosch for explain that too me.

Much appreciated and a relief as not need to find out how to install it.

Cheers pal

Re: NML - a Newgrf Meta Language

Posted: 12 Jan 2017 09:17
by GarryG
I having a play around with my Industry set seeing if I can figure out what different codes do and where to find things.

I playing around with a Industry to open a certain date or close before a certain date.

When I insert this code:

Code: Select all

/* Allow only within the availability years */
switch (FEAT_INDUSTRIES, SELF, timber_siding_check_availability, current_date) {
 date(1840,1,1) .. date(5000000,12,31): timber_siding_available_game_mode;
 return CB_RESULT_IND_NO_CONSTRUCTION;
}
I get this error:
Unrecognized identifier 'timber_siding_available_game_mode' encounted
Can someone tell me what am I missing?

Thanks kindly

Re: NML - a Newgrf Meta Language

Posted: 12 Jan 2017 11:44
by planetmaker
GarryG wrote: I get this error:
Unrecognized identifier 'timber_siding_available_game_mode' encounted
Can someone tell me what am I missing?
It is not defined in the code above. Does it exist or did you mis-spell it?

Re: NML - a Newgrf Meta Language

Posted: 12 Jan 2017 12:11
by GarryG
checked and re-check spelling and all looks correct.

The code is what I copied from the Oil_Rigs and I just changed the file it reference to.

Seems like I left some other code out .. as you mentioned "It is not defined in the code above."

I'll sleep on it tonight and try again a fresh in morning.

Cheers and thanks for helping

Re: NML - a Newgrf Meta Language

Posted: 24 Feb 2017 00:40
by Eddi
going back to the bounding box discussion:

if you want to check your bounding boxes, you can enable newgrf developer tools in the console, and then press Ctrl+B ingame to have the game display them.

what you want to do is have your bounding box roughly the size of the object you draw, but avoid having two bounding boxes overlap (touch is usually fine, although there are some exceptions). that means, sometimes you can avoid glitches by making the bounding box smaller, instead of larger.

the game handles overlapping bounding boxes very poorly (and also, there is no good way to handle it. fixing it for one case will break it for other cases)

Re: NML - a Newgrf Meta Language

Posted: 21 Mar 2017 10:39
by TadeuszD
Hello!
How can I check in NML whether the leading vehicle in the train is engine or not?
I'm using some switches with PARENT argument to determine wagons appearance. But they generates some glitches when the train is waiting in the depot without engine. In this case variable date_of_last_service for the first vehicle (wagon) returns undefined value.
Is it posible to check engine-specific variable (for example: power) to determine vehicle type?

Re: NML - a Newgrf Meta Language

Posted: 21 Mar 2017 17:33
by Transportman
TadeuszD wrote:Hello!
How can I check in NML whether the leading vehicle in the train is engine or not?
I'm using some switches with PARENT argument to determine wagons appearance. But they generates some glitches when the train is waiting in the depot without engine. In this case variable date_of_last_service for the first vehicle (wagon) returns undefined value.
Is it posible to check engine-specific variable (for example: power) to determine vehicle type?
I think you have 4 options, based on needs, requirements and future plans:
1: You could check for vehicle_is_potentially_powered, if I read the spec right it should return false if the leading vehicle cannot deliver power, which defines a wagon. I'm not sure what would happen if you also use the power callback and that returns 0 in some cases for engines.
2: You check for a range of vehicle IDs, just like I do in the 2cc TrainsInNML to check if wagons can be attached to a train. The check itself has no potential side effects, as it only depends on one value that does not change unless you change it. Downside is that it would break compatibility if you already released your work and the ID grouping has not yet been implemented.
3: Define livery overrides for the wagons on the engines. This only makes sense if the wagons should normally not be used separately of engines and the properties depend on the engine that is in front of them.
4: Check for vehicle_is_in_depot and show some default graphics if that is the case.

Re: NML - a Newgrf Meta Language

Posted: 21 Mar 2017 20:56
by TadeuszD
Transportman wrote:You could check for vehicle_is_potentially_powered, if I read the spec right it should return false if the leading vehicle cannot deliver power, which defines a wagon. I'm not sure what would happen if you also use the power callback and that returns 0 in some cases for engines.
Thank you, Transportman! I hope that vehicle_is_potentially_powered will be good way for better research. :D
Other methods looks like less usefull, because I have too many loco's and wagon's combinations in my set to prepare all livery overrides or to check all dependencies ID by ID (my engines are not grouped in the way easy to do it).

Re: NML - a Newgrf Meta Language

Posted: 08 Apr 2017 14:46
by Pyoro
I'm trying to figure out how to properly animate an object in NML, but the one example I found kinda didn't help me. Well, it did get me started:
First I got this:

Code: Select all

spritelayout spritelayout_parking_11 {
    ground {
        sprite: LOAD_TEMP(1);
	}
	building {
        sprite: spriteset_parking_ground_1(0);
    }
	building {
        sprite: spriteset_parking_cars_1(animation_counter % 4);
    }
}
Nvm the lack of dimensions and such (unless that's the problem ^^).

And then define the object:

Code: Select all

item (FEAT_OBJECTS, item_parking_1) {
    property {
        class:                  "PRLT";
		classname:				string(STR_PRLT);
        name:                   string(STR_PARKING_1);
        climates_available:     ALL_CLIMATES;
        size:                   [1,1];
        build_cost_multiplier:  1;
        remove_cost_multiplier: 1;
        introduction_date:      date(1111,1,1);
        end_of_life_date:       0xFFFFFFFF;
        object_flags:           bitmask(OBJ_FLAG_ANIMATED, OBJ_FLAG_REMOVE_IS_INCOME, OBJ_FLAG_ALLOW_BRIDGE, OBJ_FLAG_ANYTHING_REMOVE);
		animation_info:			[ANIMATION_LOOPING,4];
		animation_speed:		10;
		animation_triggers:		ANIM_TRIGGER_OBJ_TILELOOP;
        height:                 1;
        num_views:              4;
    }
    graphics {
        default:            switch_parking_1_object;
        purchase:           switch_parking_1_purchase;
        autoslope:          return(CB_RESULT_AUTOSLOPE);
        additional_text:    string(STR_PARKING_1_PURCHASE);
    }
}
The "only" problem is that the animation is incredibly fast and kinda glitchy, which I would've thought according to https://newgrf-specs.tt-wiki.net/wiki/N ... tion_speed it shouldn't be. But playing around with values and trying some different things didn't really get me anywhere. Didn't find much in the documentation about animation either :/

So as usual I don't really know what I'm doing here. I'd appreciate if someone could point me in the right direction ;)

edit: &$/$( Figured it out. Should have looked at OpenGFX landscapes first, but forgot it had an animated wind power thing. So I did the frames like that:

Code: Select all

((animation_frame + nearby_tile_random_bits(0,0)) % 3)
And most importantly didn't forget the animation CBs for graphics:

Code: Select all

		anim_control:    return CB_RESULT_NEXT_FRAME;
		anim_next_frame: return CB_RESULT_NEXT_FRAME;
I won't pretend I "get" everything but it works ;)

Re: NML - a Newgrf Meta Language

Posted: 08 Apr 2017 16:09
by Quast65
Have you tried changing

Code: Select all

ANIM_TRIGGER_OBJ_TILELOOP
to

Code: Select all

ANIM_TRIGGER_OBJ_BUILT
?

EDIT: Saw your edit, never mind the above ;-)

Re: NML - a Newgrf Meta Language

Posted: 08 Apr 2017 16:14
by Pyoro
Quast65 wrote:EDIT: Saw your edit, never mind the above ;-)
Sorry, bad timing ^^;

OBJ_BUILT had the fun effect of updating all parking lots whenever a new parking lot was built if I remember that right. Not exactly what I wanted in this case but who knows, might make sense for some obscure object of some kind (a counter-object ^^).

Re: NML - a Newgrf Meta Language

Posted: 19 Apr 2017 03:22
by Andrew350
So I'm trying to change a few properties based on chosen parameter settings (properties for which there are no callbacks), and instead of defining all-new items I tried using some kind of nested ternary operators, like so:

Code: Select all

item(...) {
	property {
		speed_limit:                 ((param_difficulty == 0) ? 35 : ((param_difficulty == 1) ? 20 : 0)) mph;
It compiles fine, and seems to work just fine in the game, but is it "safe" to do something like this?

Re: NML - a Newgrf Meta Language

Posted: 20 Apr 2017 19:31
by Transportman
Why would it not be? It resolves to something constant while using it as changing parameters is a risk for the player.

Re: NML - a Newgrf Meta Language

Posted: 22 Apr 2017 09:21
by Andrew350
Well, I wasn't sure because I've never seen or done anything like this before; I've always defined all properties explicitly except for callbacks. After reading a post about how ternary operators should be avoided I thought there might be some fault with it, so I wanted to make sure. :)

Re: NML - a Newgrf Meta Language

Posted: 08 May 2017 14:21
by Wahazar
How to switch industry sounds off?
I tried to define it as empty array: random_sound_effects: [];
but it is not working (I can still hear sawmill sound in my logging camp)

Re: NML - a Newgrf Meta Language

Posted: 08 May 2017 17:55
by frosch
Nothing wrong with that. It should work as you described.