Page 62 of 65

Re: NML - a Newgrf Meta Language

Posted: 07 Sep 2017 17:50
by Greyfur
Actually the #2 is not really what I wanted to achieve.

At the end of WWII many German buses were taken by the armies and these were later distributed by the ministry of transportation. So basically what happened was that the companies got various buses as a compensation for buses that were in desolate condition (during WWII there was not enough tires and spare parts as all were sent to the armies), and as a compensation for buses taken by the German forces at the end of war for evacuation of German families, officers, etc.

So basically the company sent an order to the ministry and they got buses from a certain pool, not really able to decide what capacity, age or producer/type they will be.

I know, that several railway carriages sets have several variations of the same carriage (like several different liveries) and as you buy it will randomly pick the livery. My question was rather if this can be used on road vehicles and if yes, if it can be used to not only pick the livery, but attributes like running costs, # of passengers, top speed, loading speed, etc.

Re: NML - a Newgrf Meta Language

Posted: 07 Sep 2017 17:53
by Greyfur
andythenorth wrote: No, the vehicle can be built, but can't be given any station orders (vehicles fitted for pax can't route to truck stations and vice versa).
So, a bus station can't load mail? As if you build a bus station next to a train station, you will have mail and passengers there. So the mail is on the station and the bus will stop at the bus station, which contains mail.

Re: NML - a Newgrf Meta Language

Posted: 07 Sep 2017 18:31
by Leanden
Greyfur wrote:
andythenorth wrote: No, the vehicle can be built, but can't be given any station orders (vehicles fitted for pax can't route to truck stations and vice versa).
So, a bus station can't load mail? As if you build a bus station next to a train station, you will have mail and passengers there. So the mail is on the station and the bus will stop at the bus station, which contains mail.
Yep thats Openttd 101. Buses dont stop at Truck stops and vice versa, regardless of what cargo is waiting

Re: NML - a Newgrf Meta Language

Posted: 08 Sep 2017 12:49
by Wahazar
andythenorth wrote:
Greyfur wrote:1) Have a bus transport both passengers and mail at once?
No, the vehicle can be built, but can't be given any station orders (vehicles fitted for pax can't route to truck stations and vice versa).
:)

Of course they can, just build all scheduled stations as universal freight/passenger stops (bus stop adjacent to truck stop). I tried it many times :)

Re: NML - a Newgrf Meta Language

Posted: 15 Sep 2017 09:49
by Kaaskroket
hello guys,

I recently made an attempt to create my first grf file using the nml language. I am not a good programmer, but with the help of some examples from both the wiki and the forums I succeeded in creating a grf which adds a few fictional planes and other air vehicles for gameplay.

One of these planes is the Arwing from Starfox which has an maximum speed of 5130 km/h. At first I wasn't able to apply this speed to the vehicle, because the maximum speed is 3280 km/h when the property speed is set to 255. After reading several posts of the forums I figured out that this limitation can be lifted with the use of a callback. After applying this to the vehicle I however experienced a problem: due to the enormous speed, the aircraft keeps circling around an airport when trying to land even if the runway is empty.

So my question is: Is there a simple way to make the aircraft slow down when it has reached the airport of destination so that it can land?

Re: NML - a Newgrf Meta Language

Posted: 26 Apr 2018 12:46
by Pyoro
I have a question about snow-awareness and animation - I'm always doing it the same way for my tiles:

Code: Select all

spritelayout spritelayout_emptytile_12 {
    ground {
        sprite: 4023; 
    }
	building {
        sprite: LOAD_TEMP(1);
		hide_sprite: (terrain_type != TILETYPE_SNOW);
    }
}
So there's the groundtile and if it's above the snowline this switch I copied from somewhere says what other groundtile to draw:

Code: Select all

switch (FEAT_OBJECTS, SELF, switch_emptytile_1_object, [
        //tile slope offset in storage register 0
        STORE_TEMP(slope_to_sprite_offset(tile_slope), 0),
        //terrain type in storage register 1
        STORE_TEMP(GROUNDSPRITE_NORMAL, 1),
		STORE_TEMP( (nearby_tile_terrain_type(0,0) == TILETYPE_DESERT) * GROUNDSPRITE_DESERT, 1),
		STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 1, 0) == TILETYPE_DESERT), 1),
		STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type(-1, 0) == TILETYPE_DESERT), 1),
		STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0, 1) == TILETYPE_DESERT), 1),
		STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0,-1) == TILETYPE_DESERT), 1),
		STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * GROUNDSPRITE_NORMAL, 1),
		STORE_TEMP(terrain_type == TILETYPE_SNOW   ? GROUNDSPRITE_SNOW : LOAD_TEMP(1), 1),
		STORE_TEMP(snowline_height == 0xFF ? 0xFF : nearby_tile_height(0,0) - snowline_height, 255),
		STORE_TEMP((LOAD_TEMP(255) == -1) ? GROUNDSPRITE_SNOW_1_4 : LOAD_TEMP(1), 1),
		STORE_TEMP((LOAD_TEMP(255) ==  0) ? GROUNDSPRITE_SNOW_2_4 : LOAD_TEMP(1), 1),
		STORE_TEMP((LOAD_TEMP(255) ==  1) ? GROUNDSPRITE_SNOW_3_4 : LOAD_TEMP(1), 1)
        ]) {
    switch_emptytile_1_view;
}
(slope isn't actually needed here but whatever). Anyway, this works reliably, as far as I've found.

But when I do the same thing for an animated ground tile:

Code: Select all

spritelayout spritelayout_field_41 {
	ground {
		sprite: 4202 + (animation_frame * 19);
	}
	building {
		sprite: LOAD_TEMP(1);
		hide_sprite: (terrain_type != TILETYPE_SNOW);
	}
It doesn't work and instead always draws the non-snow groundtile.

However, if I just use the "simple" method:

Code: Select all

spritelayout spritelayout_field_41 {
	ground {
		sprite: 4202 + (animation_frame * 19);
	}
	building {
		sprite: GROUNDSPRITE_SNOW;
		hide_sprite: (terrain_type != TILETYPE_SNOW);
	}
and draw the snow-tile like this (disregarding the transitions) ... it does actually work again.

I've tried a bunch of variations and the results are always the same. Can't "hide" the ground sprite 'cause that causes glitches. Reversing the order of groundsprite and animated sprite doesn't help either. I might have overlooked a possible combination of groundsprites, childsprites, buildings, in various orders, but I've fiddled around quite a bit ^^;

So, basically: why does the load_temp-switch method work for non-animated ground tiles but not for animated ones? And why does it still work if the tile in question is directly given? ^^;
Or, heck, I don't care so much about the "why", and I suppose just losing the snowy transitions isn't such a big deal - but if anyone has a solution I'd still be interested (or maybe there's generally a flaw in the method that could be fixed/improved ;) ).

Re: NML - a Newgrf Meta Language

Posted: 30 Apr 2018 14:52
by Pyoro
Alright, an easier(?) question.

I thought about doing a date-aware item, and looked at VAST on how to do that with animations, but it's too incomprehensible. Basically he's made some switch that controls animations and then magic happens and it works.
So I decided to just go with what I know and simply hide sprites:

Code: Select all

building { //FRUIT
		sprite: spriteset_fruit(0);
		xoffset: 8;
		yoffset: -8;
		zoffset: 48;
		xextent: 8;
		yextent: 8;
		zextent: 8;
	}
	childsprite {
		sprite: spriteset_fruit(1);
		hide_sprite: current_month != 3;
	}
	childsprite {
		sprite: spriteset_fruit(2);
		hide_sprite: current_month != 4 && current_month != 5 && current_month != 6 && current_month != 7;
	}
	childsprite {
		sprite: spriteset_fruit(3);
		hide_sprite: current_month != 8 && current_month != 9;
	}
And that works, mostly, except that sprites don't update reliably. That never seemed to be an issue if I do the same thing for example for snow-awareness - as soon as the snow is there, the sprite updates. But here date changes and sometimes something happens and sometimes nothing does, unless I zoom in and out, then it refreshes and works properly.

I guess it has something to do with objects not being redrawn randomly all the time, to help performance or whatever, but is there anything I can do about that? Otherwise I guess I'll have to try and figure out how that animation thing actually works ^^;

Re: NML - a Newgrf Meta Language

Posted: 02 May 2018 07:51
by Eddi
basically, you cannot rely on the sprite being redrawn at a specific time, and you cannot trigger that from your NewGRF. The game redraws the tile every 256 ticks ("tileloop"), or whenever it was invisible due to something else (like a window drawn over it, or a vehicle passing by). this works with snow-awareness, because changing snow levels is also done in the tieloop, so it's redrawn then anyway, but you cannot use "current_month" in your calculation, because that changes at different times.

what you instead could do is put your date calculation into the animation callback, and use the animation frame for drawing

Re: NML - a Newgrf Meta Language

Posted: 18 Sep 2018 21:31
by Sunmannus
Following the tutorial, I'm trying to make an articulated road vehicle. The vehicle and trailer appear ingame, but for some reason, the trailer sprites don't show up correctly in some views. Let me show you.
Image
That's the expected behaviour, trailer sprite appears above the truck

Image
In this case, the trailer should overlap part of the truck, but it doesn't.

Please check the code. Am I missing something?
[+] Spoiler

Code: Select all

//DEFAULT
spriteset (SpS_TRUCK, "gfx/TRUCKS.png") { TMP_32px_A (0,820) }
spriteset (SpS_TRAILER_000, "gfx/TRUCKS.png") { TMP_32px_A (0,860) }
spriteset (SpS_TRAILER_100, "gfx/TRUCKS.png") { TMP_32px_B (0,860) }

spritegroup SpG_TRAILER {
	loading: [SpS_TRAILER_000, SpS_TRAILER_100];
	loaded:  [SpS_TRAILER_000, SpS_TRAILER_100];
}
//set default gfxs
switch (FEAT_ROADVEHS, SELF, SWI_TRUCK_PartsGFx, position_in_consist ) {
    0: return SpS_TRUCK;
    1: return SpG_TRAILER; 
    return SpS_TRUCK; 
}

//set number of articulated parts
switch (FEAT_ROADVEHS, SELF, SWI_TRUCK_NumberParts, extra_callback_info1) {
    0: return ITEM_TRUCK;
	1: return ITEM_TRAILER;
    return CB_RESULT_NO_MORE_ARTICULATED_PARTS;
}
//set capacity of each part
switch (FEAT_ROADVEHS, SELF, SWI_TRUCK_PartCap, position_in_consist ) {
    0: return 0;
	1: return 30;
    return 30; //default
}
//to adjust veh length
switch (FEAT_ROADVEHS, SELF, SWI_TRUCK_Length, position_in_consist) {
    0: return 4;
    return 8;
}

item (FEAT_ROADVEHS, ITEM_TRAILER) {
    property {
		sprite_id:                      SPRITE_ID_NEW_ROADVEH;       
	    name:                           string(STR_NAME_TRAILER);
        climates_available:             NO_CLIMATE;
        refittable_cargo_classes:       bitmask(CC_PIECE_GOODS);
        non_refittable_cargo_classes:   bitmask();
		cargo_allow_refit:			    [];
		cargo_disallow_refit:			[];
		default_cargo_type:				GOOD;
        loading_speed:                  5;
        cost_factor:                    0;
        running_cost_base:              RUNNING_COST_NONE;
		running_cost_factor:            0;
		refit_cost:                     25;
		cargo_age_period:				185;
		power:                          0 hp;
        weight:                         0 ton;
		tractive_effort_coefficient:	0;
		air_drag_coefficient:			0;
		cargo_capacity:                 30;
        sound_effect:                   SOUND_TRUCK_START;
        misc_flags:                     bitmask(ROADVEH_FLAG_2CC, ROADVEH_FLAG_AUTOREFIT);
}
	graphics {
	default: SpG_TRAILER;
	}
}
item (FEAT_ROADVEHS, ITEM_TRUCK) {
    property {
		sprite_id:                      SPRITE_ID_NEW_ROADVEH;       
	    name:                           string(STR_NAME_TRUCK);
        climates_available:             ALL_CLIMATES;
        introduction_date:              date(2001,01,01);
        model_life:                     30;
        vehicle_life:                   20;
        reliability_decay:              20;
        refittable_cargo_classes:       bitmask(CC_PIECE_GOODS);
        non_refittable_cargo_classes:   bitmask();
		cargo_allow_refit:			    [];
		cargo_disallow_refit:			[];
		default_cargo_type:				GOOD;
        loading_speed:                  5;
        cost_factor:                    20;
        running_cost_base:              RUNNING_COST_ROADVEH;
		running_cost_factor:            125;
		refit_cost:                     25; // Refitting is free (25% purchase cost)
		cargo_age_period:				185;
        speed:                          98 km/h;
		power:                          480 hp;
        weight:                         15 ton;
		cargo_capacity:                 30;
        sound_effect:                   SOUND_TRUCK_START;
        misc_flags:                     bitmask(ROADVEH_FLAG_2CC, ROADVEH_FLAG_AUTOREFIT);
}
	graphics {
	default: SWI_TRUCK_PartsGFx;
	articulated_part: SWI_TRUCK_NumberParts;
	length: SWI_TRUCK_Length;
	cargo_capacity: SWI_TRUCK_PartCap;
	purchase: SpS_TRUCK_Purchase;
	additional_text: string(STR_INFO_TRUCK);
	}
}

Re: NML - a Newgrf Meta Language

Posted: 18 Sep 2018 22:53
by Eddi
you need to be careful with overlaps, as the game has a rather primitive algorithm of using bounding boxes to decide which sprite must be drawn on top

Re: NML - a Newgrf Meta Language

Posted: 19 Sep 2018 18:13
by Gwyd
In this case, the truck's bounding box is in front of the trailer's, so the truck is drawn on top.

Re: NML - a Newgrf Meta Language

Posted: 06 Oct 2018 19:52
by PNDA_
Hey,
This might be a slightly out of place (in the meaning of wrong thread or forum) question, but will there be any future Updates on Stations (or even any of the other missing Features (0x04, 5, 6, 7, C, E))?

I am currently looking through the code and seeing if I could help out a bit. From the wiki and in the code, I see that only the Action0 Properties are missing for Stations, same Information I get when trying to compile a NML File with an item (FEAT_STATIONS). (And I have never done anything in NFO either, though it doesnt seem to be that hard)

action0properties.py:

Code: Select all

#
# Feature 0x04 (Stations)
#

properties[0x04] = {
	'station_type'							: [{'size': 4, 'num': 0x08, 'value_function': default_station}, {'size': 4, 'num': 0x08, 'value_function': waypoint}],
	'sprite_layout'							: {'size': 5, 'num': 0x09},
	'copy_sprite_layout'					: {'size': 1, 'num': 0x0A},
	'callback_flags'						: {'size': 1, 'num': 0x0B},
	'number_of_disabled_platforms'			: {'size': 1, 'num': 0x0C},
	'number_of_disabled_platforms_length'	: {'size': 1, 'num': 0x0D},
	'custom_layout'							: {'size': 5, 'num': 0x0E},
	'copy_layout_by_station_id'				: {'size': 1, 'num': 0x0F},
	'lots_threshold'						: {'size': 2, 'num': 0x10},
	'pylon_placement'						: {'size': 1, 'num': 0x11},
	'cargo_type_sprites'					: {'size': 4, 'num': 0x12},
	'general_flags'							: {'size': 1, 'num': 0x13},
	'overhead_wire_placement'				: {'size': 1, 'num': 0x14},
	'allow_train_to_enter'					: {'size': 1, 'num': 0x15},
	'animation_info'						: {'size': 2, 'num': 0x16},
	'animation_speed'						: {'size': 1, 'num': 0x17},
	'animation_triggers'					: {'size': 2, 'num': 0x18},
	# 19 Road Routing not yet implemented
	'register_modifiers'					: {'size': 5, 'num': 0x1A},
}
global_constants.py:

Code: Select all

# Stations Callback Flags
	'AVAILABLE_CONSTRUCTION':			0,
	'':									1,
	'':									2,
	'':									3,
	'':									4,

	# Stations General Flags
	'DIFFERENT_GROUND_SPRITES':			0,
	'SIMULATE_CARGO_OVER_TILES':		1,
	'':									2,
	'CUSTOM_FOUNDATION_ON_SLOPE':		3,
	'USE_EXTENDED_FOUNDATION_ON_SLOPE':	4,

	#Stations Animation triggers
	'STATION_PART_IS_BUILT':			0,
	'NEW_CARGO_AT_STATION':				1,
	'CARGO_REMOVED_FROM_STATION':		2,
	'TRAIN_ENTERS_STATION':				3,
	'TRAIN_LEAVES_STATION':				4,
	'TRAIN_LOADS_CARGO':				5,
	'REGULAR_RELOAD':					6,

	#Stations Custom layout
	'PLAIN_PLATFORM':					0x00;
	'PLATFORM_WITH_BUILDING':			0x02;
	'PLATFORM_WITH_ROOF_LEFT':			0x04;
	'PLATFORM_WITH_ROOF_RIGHT':			0x06;
Some of this might be wrong, or not work, so any Info and Help on how to continue would be nice :D
Also it would be great if any of the Devs that already know how nml works, continue adding the missing features and I would be happy to help!
Also, I haven't quite figured out how to compile yet, if anyone could show how to that would be great!
Thanks

Re: NML - a Newgrf Meta Language

Posted: 15 Oct 2018 07:09
by Greyfur
Is it possible to do new graphics for stations in NML? The online wiki page says it is not, but it also says it has not been updated for 6 years...

Thank you!

Re: NML - a Newgrf Meta Language

Posted: 15 Oct 2018 10:49
by Gwyd
No, you cannot yet code stations with NML.

Re: NML - a Newgrf Meta Language

Posted: 15 Oct 2018 11:51
by GarryG
If any one want to build stations .. can be done in NFO.

Quast65 has a tutorial in Simuscape at
http://www.simuscape.net/simutalk/viewt ... e6a57974f2

Step by step guide making platforms and station buildings both track and non-tracks.

Re: NML - a Newgrf Meta Language

Posted: 15 Oct 2018 21:21
by Gwyd
m4nfo is also a language that I have tried for coding stations and it seems to work quite well... If only I could have some help from the developer...

Re: NML - a Newgrf Meta Language

Posted: 04 Dec 2018 18:40
by PNDA_
Hey, so I am here again, trying to implement Stations into NML. Because it seems like development isn't going anywhere just now.

I have managed for the NML Compiler to ouput a file, a working GRF File, and also accept Station Properties and Callbacks. I only have a few problems with the properties so OpenTTD can actually use the file and the Stations show up ingame.
I will show the outputed NFO Code with the Errors marked by NFORenum. I also got a bit of Information on how NFO works of of the output of m4NFO.

Code: Select all

//!!Warning (209): Offset 4: Found byte 1 of a 4-byte escape while reading byte 1 of a 1-byte field.
//!!Warning (42): Length does not match nument1 and nument2 of 01 and 00. (Expected 7 bytes)
//!!Error (58): Action 2 declaring no lots-of-cargo sets.
//!!Warning (209): Offset 5: Found byte 2 of a 4-byte escape while reading byte 1 of a 2-byte field.
    5 * 18	 02 04 FF \b1 \dx80000000 
\dx80000000 \b0 \b0 \b0 \b16 \b16 \b16

//!!Fatal Error (47): Offset 7: Invalid property C5.
    6 * 13	 00 04 \b2 01 FF \wx0000 
C5 \wx0000 
08 \wx0000 

//!!Error (206): Cannot set (extended-)byte IDs for feature 04.
    7 * 15	 04 04 7F 01 00 "Station_1" 00 

//!!Error (206): Cannot set (extended-)byte IDs for feature 04.
    8 * 21	 04 04 7F 01 00 "Single Platform" 00 

//!!Error (200): Offset 3: Prop 08 has not been set for ID 00.
    9 * 7	 03 04 01 00 \b0 
\wx00FF 	// station_tile_layout; 
So sprite 5 to 9 all have some kind of Warning or Error. I just can't really get on what produces these errors and why they are happening. And what are these \wx and \dx, those are quite easy to find in the python compiler:

Code: Select all

def print_varx(self, value, size):
        """
        Print a variable sized value.

        @param value: Value to output.
        @type  value: C{int}

        @param size: Size of the output (1..4), 3 means extended byte.
        @type  size: C{int}
        """
        if size == 1:
            self.print_bytex(value)
        elif size == 2:
            self.print_wordx(value)
        elif size == 3:
            self.print_bytex(0xFF)
            self.print_wordx(value)
        elif size == 4:
            self.print_dwordx(value)
        else:
            assert False
The NML Code is very basic I would say:

Code: Select all

item (FEAT_STATIONS, i_station) {
	property {
		name: 					string(STR_STATION_TEST);
		station_class:			string(STR_STATION_CLASS);
	}
	graphics {
		default: station_tile_layout;
	}
}
and the new Internal Code of NML looks like this:

Code: Select all

properties[0x04] = {
    'name'                                   : {'size': 2, 'num': 0xC5, 'string': None},
    'station_class'                          : {'size': 2, 'num': 0x08, 'string': None},
    'sprite_layout'                          : {'size': 5, 'num': 0x09},
    'copy_sprite_layout'                     : {'size': 1, 'num': 0x0A},
    'callback_flags'                         : {'size': 1, 'num': 0x0B},
    'number_of_disabled_platforms'           : {'size': 1, 'num': 0x0C},
    'number_of_disabled_platforms_length'    : {'size': 1, 'num': 0x0D},
    'custom_layout'                          : {'size': 5, 'num': 0x0E},
    'copy_layout_by_station_id'              : {'size': 1, 'num': 0x0F},
    'lots_threshold'                         : {'size': 2, 'num': 0x10},
    'pylon_placement'                        : {'size': 1, 'num': 0x11},
    'cargo_type_sprites'                     : {'size': 4, 'num': 0x12},
    'general_flags'                          : {'size': 1, 'num': 0x13},
    'overhead_wire_placement'                : {'size': 1, 'num': 0x14},
    'allow_train_to_enter'                   : {'size': 1, 'num': 0x15},
    'animation_info'                         : {'size': 2, 'num': 0x16},
    'animation_speed'                        : {'size': 1, 'num': 0x17},
    'animation_triggers'                     : {'size': 2, 'num': 0x18},
    # 19 Road Routing not yet implemented
    'register_modifiers'                     : {'size': 5, 'num': 0x1A},
}
(I left out the global constants because those are irrelevant, I think.)
If anyone sees an Issue please report, and I probably have more than one mistake in the properties[0x04] = {} part.

Re: NML - a Newgrf Meta Language

Posted: 04 Dec 2018 22:59
by Eddi
so, let's go backwards, as far as i understand stuff:
  • property 08 is a 4 byte-ID (like GRF-ID, Cargo-Label, etc.), not a String
  • where did you get 0xC5 from for "name"? couldn't find that anywhere
  • the two action4 complain that you're using language ID 7F (indicating byte-IDs) instead of FF (indicating word-IDs). what that means i have no clue.
  • the action0 complains about C5 being unknown (see previous question)
  • the action2 is completely ill-formed. as far as i understand stations, tile layout should be a property (action0), not "graphics" (action2). no clue what you were trying to achieve there

Re: NML - a Newgrf Meta Language

Posted: 05 Dec 2018 06:29
by Gwyd
In my limited knowledge on NFO, I know for sure that sprite layout goes into Action 0, but tile layout of multi tile stations gets defined in Action 2.

Re: NML - a Newgrf Meta Language

Posted: 05 Dec 2018 11:26
by planetmaker
PNDA_ wrote:Hey,
This might be a slightly out of place (in the meaning of wrong thread or forum) question, but will there be any future Updates on Stations (or even any of the other missing Features (0x04, 5, 6, 7, C, E))?
Yes. But as you have figured, it is mostly a lack of developer time. So contributions to add these missing stuff are greatly appreciated.

Do you happen to have a WIP git repo for your station code?