Page 3 of 3

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

Posted: 22 Jan 2014 13:26
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"

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

Posted: 23 Jan 2014 23:14
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).

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

Posted: 24 Jan 2014 06:38
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.

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

Posted: 26 Jan 2014 11:37
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.

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

Posted: 13 Aug 2014 15:14
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 :(

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

Posted: 13 Aug 2014 22:34
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;
				}
			}
		}
	}

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

Posted: 05 Apr 2015 08:28
by Patagonicus
For the lazy, here's the patch file updated to r27219. Compiles, seems to run, but not otherwise tested.