[Patch] Industry Station Names (v1; r12436)

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

KeldorKatarn
Transport Coordinator
Transport Coordinator
Posts: 274
Joined: 13 Apr 2010 21:31

Re: [Patch] Industry Station Names (v1; r12436)

Post by KeldorKatarn »

Updated this patch for my own build. Some things I found problematic and fixed for my version:

Why a distance of 3 instead of 4? In my game the catchment area is 4 so I did get stations not grabbing the name of industries they served.

The standard industry names are still used before the new names.

So if I build next to a Coal mine I first get "New York Mines", then "New York Coal Mine"

That is VERY problematic with NewGRF industries since sometimes their Sand Pit is in fact not a mine. And their Fishing grounds are not an Oil field etc etc, so the default name is often simply wrong. If these new names are used, old default industry names (aside from docks/airport etc) should be ignored.

Also is it just me or are airport names and docks names messed up by this patch. I had to fix something to get those default names working again and not have Airports and Docks named "Wellington South" or "New York Woods"
R2dical
Traffic Manager
Traffic Manager
Posts: 163
Joined: 18 Mar 2013 22:22

Re: [Patch] Industry Station Names (v1; r12436)

Post by R2dical »

KeldorKatarn wrote:Why a distance of 3 instead of 4? In my game the catchment area is 4 so I did get stations not grabbing the name of industries they served.
If you have the "realistic catchment" enabled then bus/truck stations have a radius of 3 and you get the inverse of that problem...but yeah it is kind of arbitrary, maybe needs a setting?
KeldorKatarn wrote:The standard industry names are still used before the new names.
Isn't that easy to fix, just changing the order of the "if...else if..." structure? Why not post your version (hope the OP doesn't mind the updating).
KeldorKatarn
Transport Coordinator
Transport Coordinator
Posts: 274
Joined: 13 Apr 2010 21:31

Re: [Patch] Industry Station Names (v1; r12436)

Post by KeldorKatarn »

I dond't really have that single change as a patch file right now but yeah that's basically what I did. I actually removed the clause completely. Since I didn't want the default "Mines" stuff at all anymore. Because it might put in the wrong name with newGRFs, like interpreting something as what it was in the original industry. I don't want that even as the secondary name. But overall it was just changing the if..else stuff yes.

Also yes, the "catchment area" of that naming scheme should be a setting or at least always identical with what the game is using.
R2dical
Traffic Manager
Traffic Manager
Posts: 163
Joined: 18 Mar 2013 22:22

Re: [Patch] Industry Station Names (v1; r12436)

Post by R2dical »

Ok I see, I will take a look at doing the changes you made. I think a setting would be simpler, but maybe some code could be used from the "catchment area" patch to make it so that the name is applied if the station you are building covers the industry.
beginner2
Engineer
Engineer
Posts: 17
Joined: 12 Mar 2008 21:16

Re: [Patch] Industry Station Names (v1; r12436)

Post by beginner2 »

Sorry for resurrecting this, but on current trunk, this does not work anymore; during compilation, the error "station_cmd.cpp:336:20: error: 'SAFEGUARD_DO_NOT_USE_THIS_METHOD' was not declared in this scope" appears, and from my investigation it seems to be related to the use of strcat and strdup (seems they are obsolete now and strecat and stredup are supposed to be used instead). A dirty fix is to remove #include safeguards.h from the file station_cmd.cpp. I was unable to fix it replacing strcat with strecat and strdup with stredup :(
Supercheese
Tycoon
Tycoon
Posts: 1660
Joined: 16 Dec 2007 22:24
Location: Idaho, USA

Re: [Patch] Industry Station Names (v1; r12436)

Post by Supercheese »

beginner2 wrote:Sorry for resurrecting this, but on current trunk, this does not work anymore; during compilation, the error "station_cmd.cpp:336:20: error: 'SAFEGUARD_DO_NOT_USE_THIS_METHOD' was not declared in this scope" appears, and from my investigation it seems to be related to the use of strcat and strdup (seems they are obsolete now and strecat and stredup are supposed to be used instead). A dirty fix is to remove #include safeguards.h from the file station_cmd.cpp. I was unable to fix it replacing strcat with strecat and strdup with stredup :(
Try this:

Code: Select all

	/* check industry >>variable names<< */
	for (int dx = -3; dx <= (width-1) + 3; dx++) {
		for (int dy = -3; dy <= (height-1) + 3; dy++) {
			if (CMSAIndustry(TILE_MASK(tile + TileDiffXY(dx, dy)))) {
				char buf[512];

				// Get town name (code mostly stolen from FormatString)
				const Industry *ind = Industry::GetByTile(tile + TileDiffXY(dx, dy));
				const Town *ind_t = ind->town;
				int64 temp[1];

				temp[0] = ind_t->townnameparts;
				StringParameters tmp_params(temp);
				uint32 grfid = ind_t->townnamegrfid;

				if (ind_t->name != NULL) {
					strecpy(buf, ind_t->name, lastof(buf));
				} else if (grfid == 0) {
					/* Original town name */
					GetStringWithArgs(buf, ind_t->townnametype, &tmp_params, lastof(buf));
				} else {
					/* Newgrf town name */
					if (GetGRFTownName(grfid) != NULL) {
						/* The grf is loaded */
						GRFTownNameGenerate(buf, ind_t->townnamegrfid, ind_t->townnametype, ind_t->townnameparts, lastof(buf));
					} else {
						/* Fallback to english original */
						GetStringWithArgs(buf, SPECSTR_TOWNNAME_ENGLISH, &tmp_params, lastof(buf));
					}
				}
				// End of get town name

				// Add space :P
				strecat(buf, " ", lastof(buf));

				// Add industry name
				GetString(buf+strlen(buf), (GetIndustrySpec(ind->type))->name, lastof(buf));

				if (IsUniqueStationName(buf)) {
					free(st->name);
					st->name = stredup(buf);
					return true;
				}
			}
		}
	}
Eyecandy Road Vehicles | Fake Subways | Supercheese's NewObjects

"Fashions and cultures change, but steam trains shall always be majestic."
-Professor Hershel Layton
Patagonicus
Engineer
Engineer
Posts: 26
Joined: 24 Oct 2011 20:42

Re: [Patch] Industry Station Names (v1; r12436)

Post by Patagonicus »

For the lazy, here's the patch file updated to r27219. Compiles, seems to run, but not otherwise tested.
Attachments
Station_Names_From_Industries_r27219.diff
(5.04 KiB) Downloaded 76 times
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 12 guests