New Cargos - NML question

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

Moderator: Graphics Moderators

Post Reply
User avatar
oftcrash
Transport Coordinator
Transport Coordinator
Posts: 304
Joined: 03 Jan 2013 17:20
Location: New England, USA

New Cargos - NML question

Post by oftcrash »

I've been lurking for quite some time now, playing for even longer, and finally decided to try out some newgrf creation. I've read a ton of posts, looked at code in other GRFs, even delved into the game source code a bit. So far I've successfully modified existing industries and thought I had successfully created a new cargo, but I've stumbled a bit.

I'm trying to create an additional passenger type called VIP. It compiles, but I get some odd results. If I don't item stub to the PASS cargo (but don't make any mods), then my industry doesn't see the type and vehicles can be somewhat refitted. By putting the item stub in there, it seems to work, but when I go to refit an aircraft, it comes up as "7 tonnes of coal" despite no reference to coal being in my grf at all.

I've removed pretty much everything I was trying to muck with and boiled it down to just the one cargo and one industry so I can test. For my testing, the only other newgrf I'm loading is "Use-able Default Aircraft" in order to get the refit option. I even removed nearly all the inline comments, just in case.

vip.nml

Code: Select all

grf {
	grfid: "KK\02\01";
	name: string(STR_GRF_NAME);
	desc: string(STR_GRF_DESCRIPTION);
	version: 0;
	min_compatible_version: 0;
}

/*	declare the cargos that will be used in the GRF with their 4 letter labels
	http://www.tt-wiki.net/wiki/NMLTutorial/Cargotable */
cargotable {
	PASS, VIPS, OIL_, MAIL
}

/*	create a new cargo
	http://newgrf-specs.tt-wiki.net/wiki/NML:Cargos */

item (FEAT_CARGOS, cargo_pass, 0) {
	property {
		number:						00;
	}
}

item (FEAT_CARGOS, cargo_vips) {
	property {
		number:						31;
		type_name:					string(STR_CARGO_VIPS);
		unit_name: 					string(STR_CARGO_SINGLE_VIPS);
		units_of_cargo:				string(STR_CARGO_VIPS);
		type_abbreviation:			string(STR_CARGO_ABBR_VIPS);
		sprite: 					4297;
		weight:						1;
		penalty_lowerbound:			0;
		single_penalty_length:		18;
		price_factor:				10000;
		station_list_colour:		97;
		cargo_payment_list_colour:	97;
		is_freight:					0;
		cargo_classes:				bitmask(CC_PASSENGERS);
		cargo_label:				"VIPS";
		town_growth_effect:			TOWNGROWTH_NONE;
		capacity_multiplier:		0.5;
	}
}

/*	create or modify an industry
	http://newgrf-specs.tt-wiki.net/wiki/NML:Industries */
item(FEAT_INDUSTRIES, industry_lngp) {
    property {
		substitute:					INDUSTRYTYPE_OIL_RIG;
		override:					INDUSTRYTYPE_OIL_RIG;
		prod_cargo_types:			[VIPS,OIL_];
		accept_cargo_types:			[VIPS,MAIL];
		prod_multiplier:			[1,15];
		min_cargo_distr:			2;
		prob_random:				20;
		prob_in_game:				20;
	}
}
english.lng

Code: Select all

##grflangid 0x00
# English US language file

# GRF info
STR_GRF_NAME				:  {TITLE} {VERSION}
STR_GRF_DESCRIPTION			:First class travel isn't enough for these passengers...

# Cargo
STR_CARGO_VIPS				:VIPs
STR_CARGO_SINGLE_VIPS		:VIP
STR_CARGO_QUANTITY_VIPS		:{COMMA} VIPs
STR_CARGO_ABBR_VIPS			:{TINYFONT}VP
custom_tags.txt

Code: Select all

VERSION					:alpha-05
UPDATEDT				:03 01 2013
TITLE					:VIPs (Very Important Passengers)
AUTHOR					:Kris Knowlton
COPYRIGHTDT				:2013
LICENSE					:GPL v2
Oh, one other note. On the items_of_cargo field, {COMMA} passenger{P "" s} gives me an error when I compile: "Using {P} without a ##plural pragma". This goes in the .lng file, right? I tried to all sorts of combinations of ##, but couldn't sort it out.

I'm running Mac OS 10.6.8 and have the latest nightly NML build.

Thanks!

edit: cropped the description so it fit on the screen better.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: New Cargos - NML question

Post by frosch »

Cargos are not dynamically created like e.g. industries or engines.
There is a only a fixed number of cargo slots, so whenever you want to define a cargo, you have to assign a cargo slot to it, replacing the cargo which was in there before. (This is also the reason why most NewGRF defining cargos are incompatible with each other)

Wrt. NML that means that all cargo "item" should have 3 parameters.
oftcrash wrote:item (FEAT_CARGOS, cargo_vips) {
This one has only two, I suspect that NML assigned slot 1 to it. Slot 1 is "coal" when using default cargos.
Try to pick a slot which is empty by default: http://newgrf-specs.tt-wiki.net/wiki/CargoDefaultProps
It is also a good idea nowadays, to pick the slot equal to the "number" property.

About the plurals, you can find an example here: http://dev.openttdcoop.org/projects/fir ... nglish.lng
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
oftcrash
Transport Coordinator
Transport Coordinator
Posts: 304
Joined: 03 Jan 2013 17:20
Location: New England, USA

Re: New Cargos - NML question

Post by oftcrash »

Thanks for the reply! It looks like I have the cargos and a couple industries modified properly now. I specified the IDs in the cargo, plus I'd forgotten the items_of_cargo property which was screwing up my output.

And I guess I finally figured out how to get the town name in the nearby_station_name. Does "{STRING}" grab the default variable of whatever the game would normally expect to put there? In this case, the town name? Can I use that same thing in other types of features to grab other default names?
Eddi
Tycoon
Tycoon
Posts: 8289
Joined: 17 Jan 2007 00:14

Re: New Cargos - NML question

Post by Eddi »

if you use {STRING} in places that don't expect a string (like vehicle names and stuff), the game will likely crash...
User avatar
oftcrash
Transport Coordinator
Transport Coordinator
Posts: 304
Joined: 03 Jan 2013 17:20
Location: New England, USA

Re: New Cargos - NML question

Post by oftcrash »

Ok, I'll leave well enough alone with the string :)

I am still seeing one issue in the industry setup. I modified the oil well and oil rig. The industries themselves show the new cargo for both production and required, however, the stations still show the default cargos in the accepted field. In the case of the oil rig its passengers, mail. In the oil well, it doesn't show anything. Is there another setting I missed with the stations?

I've tried putting in the IDs as the NML name, the base 10 number and the hex number. I also tried putting in the cargo using the cargotype() function as well as just the label. Again, same result. The latest version I tried is below. Both NGAS and VIPS are in the cargotable block.

Code: Select all

item(FEAT_INDUSTRIES, industry_lngp, 0x05) {
    property {
		substitute:					0x05;
		override:					0x05;
		prod_cargo_types:			[cargotype("NGAS"), cargotype("VIPS")];
		accept_cargo_types:			[cargotype("VIPS")];
		prod_multiplier:			[1,15];
		min_cargo_distr:			2;
		prob_random:				20;
		prob_in_game:				20;
		name:						string(STR_IND_NAME_NGAS_PLATFORM);
		nearby_station_name:		string(STR_IND_STATION_NGAS_PLATFORM);
	}
}

item(FEAT_INDUSTRIES, industry_lngf, 0x0B) {
    property {
		substitute:					0x0B;
		override:					0x0B;
		prod_cargo_types:			[cargotype("NGAS")];
		accept_cargo_types:			[cargotype("VIPS")];
		prod_multiplier:			[15];
		min_cargo_distr:			2;
		prob_random:				20;
		prob_in_game:				20;
		name:						string(STR_IND_NAME_NGAS_DRILL);
		nearby_station_name:		string(STR_IND_STATION_NGAS_DRILL);
	}
}
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: New Cargos - NML question

Post by PikkaBird »

oftcrash wrote:The industries themselves show the new cargo for both production and required, however, the stations still show the default cargos in the accepted field.
Station acceptance is a property of the industry tiles, not of the industry itself. You will need to modify the tiles as well as the industry.

http://newgrf-specs.tt-wiki.net/wiki/NM ... properties
http://newgrf-specs.tt-wiki.net/wiki/NM ... stry_tiles
http://newgrf-specs.tt-wiki.net/wiki/In ... ry_Layouts
User avatar
oftcrash
Transport Coordinator
Transport Coordinator
Posts: 304
Joined: 03 Jan 2013 17:20
Location: New England, USA

Re: New Cargos - NML question

Post by oftcrash »

Thanks for the help - the stations are reporting cargo's correctly now. Every unique tile ID needs to be assigned, correct, not just one of them in the industry?

Also, is there something special that needs to be done (or a tile that can't be touched?) on the oil rig for the automatic station to work?

I can definitely see the necessity of a good templating script now. I'm going to read through Andythenorth's guide on the topic, and then see about working with what's already been done in Python. My Python knowledge is pretty limited, but I've been looking for a fun project to spur me along. By the way, for learning the syntax I recommend learnpythonthehardway.org.

I'm sure I'll have a lot more questions as I go along. I'm not doing anything yet I'd want to distribute, but who knows. Instead of working today like I should have been, I decided to "fix" the industries in the toyland to mars conversion to match the graphics. Its been a good learning experience.

Next step is to start messing with sprites. :)
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 11 guests