Station Name Patch?

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

User avatar
Salvo_guy
Traffic Manager
Traffic Manager
Posts: 128
Joined: 06 Jul 2006 06:40
Location: Somewhere Down Under

Post by Salvo_guy »

i think i may have actually got it working... but i'm waiting for it too compile... WOOT

edit: i was wrong... just changed it to "OFF edge of map" (in white)

edit: now its called the town name... although i think it cycles through names now...

Edit: updated the patch (beta 2, one error... station numbers randomly change value while placing a new station with the new station name formulae)
Attachments
Frudinghall Transport, 21st May 1950.png
Frudinghall Transport, 21st May 1950.png (143.36 KiB) Viewed 1146 times
station_name.patch
the patch so far... unlimited station names... but no new naming yet
(1.16 KiB) Downloaded 196 times
station_name.patch
only works with english currently (for testing)
(2.12 KiB) Downloaded 175 times
Last edited by Salvo_guy on 01 Aug 2006 14:52, edited 2 times in total.
l_Blue_l
Transport Coordinator
Transport Coordinator
Posts: 285
Joined: 29 Mar 2006 22:42
Contact:

Post by l_Blue_l »

I'm stupid.... but i found what i was looking for in the end

Code: Select all

static void TrainViewWndProc(Window *w, WindowEvent *e)
......
......
		SetDParam(0, v->string_id);  
		SetDParam(1, v->unitnumber);
		DrawWindowWidgets(w);
i believe something like this would be the best way to show a Statation Number and never run out of different station names .... just make it do the same thing as trains (except this would be for all players and there wouldnt be any backwards counting) . In this case there should also be a boolean value to say if it should show the station number or not. i think this is a good step before makeing it town and or player related if thats what you want to do. Doing it this way would mean you would have to save these new values but i doubt it would be hard to work out as you have the other code to look at.

Good luck
User avatar
Salvo_guy
Traffic Manager
Traffic Manager
Posts: 128
Joined: 06 Jul 2006 06:40
Location: Somewhere Down Under

Post by Salvo_guy »

well the idea was just to have an extend "list" of station names... but being able to have the same names with different companies would b good...

when i get the initail patch working the way i want... then i might think about this..
l_Blue_l
Transport Coordinator
Transport Coordinator
Posts: 285
Joined: 29 Mar 2006 22:42
Contact:

Post by l_Blue_l »

What exactly is it that you want?

As i understand it you want to have

"town name" + "number" or a combination of other station names? ie "town name" + "east" + "woods
or "town name" + "south" + "sidings"
As I understand it currenly it is only possible to store one string for a station name. Every possiblitly has its own string "town name east" "town name west" etc etc so to get around this you add all the places where it displays the station name which is around 6 i think (you would also need to change this to display "town name" + "east" or "town name" + "east" + "woods") and this method would also work well for extending names of stations adding numbers to all of the existing strings but the first idea would be easier to achive just adding the number in which the station was build with the town name.

In the end whatever you get this done it will be good.
Last edited by l_Blue_l on 29 Jul 2006 03:59, edited 1 time in total.
User avatar
Salvo_guy
Traffic Manager
Traffic Manager
Posts: 128
Joined: 06 Jul 2006 06:40
Location: Somewhere Down Under

Post by Salvo_guy »

hmm.. i'll try and think about what you've just said... but i have a problem...

I'm getting a mysterious "if" and "else" syntax error.. and ideas?

Code: Select all

static bool GenerateStationName(Station *st, TileIndex tile, int flag)
{	static unsigned char STNUM;
	STNUM = 0; //neccessary to have unlimited station names
}
if (STNUM == 0) {
	static const uint32 _gen_station_name_bits[] = {
		0,                                      /* 0 */
		1 << M(STR_SV_STNAME_AIRPORT),          /* 1 */
		1 << M(STR_SV_STNAME_OILFIELD),         /* 2 */
		1 << M(STR_SV_STNAME_DOCKS),            /* 3 */
		0x1FF << M(STR_SV_STNAME_BUOY_1),       /* 4 */
		1 << M(STR_SV_STNAME_HELIPORT),         /* 5 */
	};

	Town *t = st->town;
	uint32 free_names = (uint32)-1;
	int found;
	uint z,z2;
	unsigned long tmp;

	{
		Station *s;

		FOR_ALL_STATIONS(s) {
			if (s != st && s->xy != 0 && s->town==t) {
				uint str = M(s->string_id);
				if (str <= 0x20) {
					if (str == M(STR_SV_STNAME_FOREST))
						str = M(STR_SV_STNAME_WOODS);
					CLRBIT(free_names, str);
				}
			}
		}
	}

	/* check default names */
	tmp = free_names & _gen_station_name_bits[flag];
	if (tmp != 0) {
		found = FindFirstBit(tmp);
		goto done;
	}

	/* check mine? */
	if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) {
		if (CountMapSquareAround(tile, MP_INDUSTRY, IT_COAL_MINE) >= 2 ||
				CountMapSquareAround(tile, MP_INDUSTRY, IT_IRON_MINE) >= 2 ||
				CountMapSquareAround(tile, MP_INDUSTRY, IT_COPPER_MINE) >= 2 ||
				CountMapSquareAround(tile, MP_INDUSTRY, IT_GOLD_MINE) >= 2 ||
				CountMapSquareAround(tile, MP_INDUSTRY, IT_DIAMOND_MINE) >= 2) {
			found = M(STR_SV_STNAME_MINES);
			goto done;
		}
	}

	/* check close enough to town to get central as name? */
	if (DistanceMax(tile,t->xy) < 8) {
		found = M(STR_SV_STNAME);
		if (HASBIT(free_names, M(STR_SV_STNAME))) goto done;

		found = M(STR_SV_STNAME_CENTRAL);
		if (HASBIT(free_names, M(STR_SV_STNAME_CENTRAL))) goto done;
	}

	/* Check lakeside */
	if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
			DistanceFromEdge(tile) < 20 &&
			CountMapSquareAround(tile, MP_WATER, 0) >= 5) {
		found = M(STR_SV_STNAME_LAKESIDE);
		goto done;
	}

	/* Check woods */
	if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && (
				CountMapSquareAround(tile, MP_TREES, 0) >= 8 ||
				CountMapSquareAround(tile, MP_INDUSTRY, IT_FOREST) >= 2)
			) {
		found = _opt.landscape == LT_DESERT ?
			M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);
		goto done;
	}

	/* check elevation compared to town */
	z = GetTileZ(tile);
	z2 = GetTileZ(t->xy);
	if (z < z2) {
		found = M(STR_SV_STNAME_VALLEY);
		if (HASBIT(free_names, M(STR_SV_STNAME_VALLEY))) goto done;
	} else if (z > z2) {
		found = M(STR_SV_STNAME_HEIGHTS);
		if (HASBIT(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done;
	}

	/* check direction compared to town */
	{
		static const int8 _direction_and_table[] = {
			~( (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
			~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
			~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
			~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) ),
		};

		free_names &= _direction_and_table[
			(TileX(tile) < TileX(t->xy)) +
			(TileY(tile) < TileY(t->xy)) * 2];
	}

	tmp = free_names & ((1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<6)|(1<<7)|(1<<12)|(1<<26)|(1<<27)|(1<<28)|(1<<29)|(1<<30)); 
   if (tmp == 0) {
	   ++STNUM;
		return false;
	}
	found = FindFirstBit(tmp);

done:
	st->string_id = found + STR_SV_STNAME; 
	++STNUM;
	return true;
	};
	
else { if (STNUM <=30) {
		return false;
	}
else (STNUM >=30){
	  st->string_id = 24582 && string_id = 440 + STNUM;
	  ++STNUM;
}
}
Edit: if you would like to tell me what i'm doing wrong here.. that would b great.. and if that would b likely to work...
l_Blue_l
Transport Coordinator
Transport Coordinator
Posts: 285
Joined: 29 Mar 2006 22:42
Contact:

Post by l_Blue_l »

Code: Select all

static bool GenerateStationName(Station *st, TileIndex tile, int flag)
{   static unsigned char STNUM;
   STNUM = 0; //neccessary to have unlimited station names
}   //end of Function
if (STNUM == 0) { 
the closed the function off in the 3 line. just move it down to the last line and that compile error will be gone.
User avatar
Salvo_guy
Traffic Manager
Traffic Manager
Posts: 128
Joined: 06 Jul 2006 06:40
Location: Somewhere Down Under

Post by Salvo_guy »

l_Blue_l wrote: the closed the function off in the 3 line. just move it down to the last line and that compile error will be gone.
I don't think i quite understand you there... did you just mean put a "}" at the end of all the code?
l_Blue_l
Transport Coordinator
Transport Coordinator
Posts: 285
Joined: 29 Mar 2006 22:42
Contact:

Post by l_Blue_l »

what i ment is you had a "}" ending the function so it didnt know the rest of the code was included in the GenerateStationName

Code: Select all

static bool GenerateStationName(Station *st, TileIndex tile, int flag)
{   static unsigned char STNUM;
   STNUM = 0; //neccessary to have unlimited station names

if (STNUM == 0) {
   static const uint32 _gen_station_name_bits[] = {
      0,                                      /* 0 */
      1 << M(STR_SV_STNAME_AIRPORT),          /* 1 */
      1 << M(STR_SV_STNAME_OILFIELD),         /* 2 */
      1 << M(STR_SV_STNAME_DOCKS),            /* 3 */
      0x1FF << M(STR_SV_STNAME_BUOY_1),       /* 4 */
      1 << M(STR_SV_STNAME_HELIPORT),         /* 5 */
   };

   Town *t = st->town;
   uint32 free_names = (uint32)-1;
   int found;
   uint z,z2;
   unsigned long tmp;

   {
      Station *s;

      FOR_ALL_STATIONS(s) {
         if (s != st && s->xy != 0 && s->town==t) {
            uint str = M(s->string_id);
            if (str <= 0x20) {
               if (str == M(STR_SV_STNAME_FOREST))
                  str = M(STR_SV_STNAME_WOODS);
               CLRBIT(free_names, str);
            }
         }
      }
   }

   /* check default names */
   tmp = free_names & _gen_station_name_bits[flag];
   if (tmp != 0) {
      found = FindFirstBit(tmp);
      goto done;
   }

   /* check mine? */
   if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) {
      if (CountMapSquareAround(tile, MP_INDUSTRY, IT_COAL_MINE) >= 2 ||
            CountMapSquareAround(tile, MP_INDUSTRY, IT_IRON_MINE) >= 2 ||
            CountMapSquareAround(tile, MP_INDUSTRY, IT_COPPER_MINE) >= 2 ||
            CountMapSquareAround(tile, MP_INDUSTRY, IT_GOLD_MINE) >= 2 ||
            CountMapSquareAround(tile, MP_INDUSTRY, IT_DIAMOND_MINE) >= 2) {
         found = M(STR_SV_STNAME_MINES);
         goto done;
      }
   }

   /* check close enough to town to get central as name? */
   if (DistanceMax(tile,t->xy) < 8) {
      found = M(STR_SV_STNAME);
      if (HASBIT(free_names, M(STR_SV_STNAME))) goto done;

      found = M(STR_SV_STNAME_CENTRAL);
      if (HASBIT(free_names, M(STR_SV_STNAME_CENTRAL))) goto done;
   }

   /* Check lakeside */
   if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
         DistanceFromEdge(tile) < 20 &&
         CountMapSquareAround(tile, MP_WATER, 0) >= 5) {
      found = M(STR_SV_STNAME_LAKESIDE);
      goto done;
   }

   /* Check woods */
   if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && (
            CountMapSquareAround(tile, MP_TREES, 0) >= 8 ||
            CountMapSquareAround(tile, MP_INDUSTRY, IT_FOREST) >= 2)
         ) {
      found = _opt.landscape == LT_DESERT ?
         M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);
      goto done;
   }

   /* check elevation compared to town */
   z = GetTileZ(tile);
   z2 = GetTileZ(t->xy);
   if (z < z2) {
      found = M(STR_SV_STNAME_VALLEY);
      if (HASBIT(free_names, M(STR_SV_STNAME_VALLEY))) goto done;
   } else if (z > z2) {
      found = M(STR_SV_STNAME_HEIGHTS);
      if (HASBIT(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done;
   }

   /* check direction compared to town */
   {
      static const int8 _direction_and_table[] = {
         ~( (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
         ~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
         ~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
         ~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) ),
      };

      free_names &= _direction_and_table[
         (TileX(tile) < TileX(t->xy)) +
         (TileY(tile) < TileY(t->xy)) * 2];
   }

   tmp = free_names & ((1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<6)|(1<<7)|(1<<12)|(1<<26)|(1<<27)|(1<<28)|(1<<29)|(1<<30));
   if (tmp == 0) {
      ++STNUM;
      return false;
   }
		else { 
			if (STNUM <=30) {
			  return false;
			}
		else (STNUM >=30){
				  st->string_id = 24582 && string_id = 440 + STNUM; 
		  // have no idea what happening there
		  // but string_id is a preset phrase you can ither make more 
		  // strings or or store two strings and display them both or  
		  // display a number after the string like trains do
				  ++STNUM;
			}
	   found = FindFirstBit(tmp);

	done:
		st->string_id = found + STR_SV_STNAME;
		++STNUM;
		return true;
		};
   

}
}

i fix all the compile errors bar the one at the end of the code where i have added a compment to
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Post by gigajum »

Code: Select all

st->string_id = 24582 && string_id = 440 + STNUM;
please replace the 24582 by a definition, so that everybody can understand where the value comes from or where it is needed.

The && is a logical AND operator and should not be used that way (IMO).

those two lines should look like something like this:

Code: Select all

st->string_id = STR_NAME_FOR_DUNNO;
string_id = STR_NAME_FOR_SOMETHING_OTHER + stnum;
Please read the coding style pages here in the forum or in the wiki

And if you have errors, write them down here. So that we can help here without having to patch our workingspace. And last but not least: create a damn diff file. That helps us much more to help you if there are serious problems.

Code: Select all

else (STNUM >=30){ 
there is a "if" missing after the else and before the (

Code: Select all

   } 
      else { 
         if (STNUM <=30) { 
           return false; 
         }
should be

Code: Select all

} else if (stnum <= 30) {
  return false;
} 
i'll give up here. I will not replace your code by a working one.
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

Salvo_guy wrote:well the idea was just to have an extend "list" of station names... but being able to have the same names with different companies would b good...
So, when two companies both have a station named "Foo City Central", and one buys the other out, what happens? Does the one company now have two stations named "Foo City Central"? Does the buyout fail? Does something else happen?
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
uzurpator
Tycoon
Tycoon
Posts: 2225
Joined: 10 Jan 2003 12:21
Location: Katowice, Poland

Post by uzurpator »

The best option would be to append a number to a station name when there are no other names.

Like

Foobarbridge 1
Foobarbridge 2
Foobarbridge 3


etc.
User avatar
Salvo_guy
Traffic Manager
Traffic Manager
Posts: 128
Joined: 06 Jul 2006 06:40
Location: Somewhere Down Under

Post by Salvo_guy »

currently it is just a coded "error" because if you compile my last patch... you'll notice that you can have 100 stations called the same thing...

the only thing that matters really is the station id (which is what the computer actually looks at...) you only see a name not an ID number

so you can have every station using the same name it would just get very confusing
User avatar
Salvo_guy
Traffic Manager
Traffic Manager
Posts: 128
Joined: 06 Jul 2006 06:40
Location: Somewhere Down Under

Post by Salvo_guy »

UPDATE:

Reason why my patch didn't not work the right way...

i wasn't supposed to be changing the code that much... i was supposed to b making strings...

Progress...
String formula stolen from waypoint strings
User avatar
Salvo_guy
Traffic Manager
Traffic Manager
Posts: 128
Joined: 06 Jul 2006 06:40
Location: Somewhere Down Under

Post by Salvo_guy »

Patch updated... still nqr
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

is this patch able to rename buoys also? that because i need to assign them names to understand what routes pass throught them
User avatar
Salvo_guy
Traffic Manager
Traffic Manager
Posts: 128
Joined: 06 Jul 2006 06:40
Location: Somewhere Down Under

Post by Salvo_guy »

if i can be bothered to start coding this again.. (had a break for schooling reasons)

it should be able to do the same for bouys as it does for station names
User avatar
Salvo_guy
Traffic Manager
Traffic Manager
Posts: 128
Joined: 06 Jul 2006 06:40
Location: Somewhere Down Under

Post by Salvo_guy »

so i've revised my code... but getting one error...

the patch displays

Code: Select all

{"Town Name" +Station #"random constantly changing number"}
i'm using mainly strings to do this...

help?
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 16 guests