[Freeciv-Dev] Patch: Unique city names
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
The following small patch prevents naming two cities of one player with
same name.
In online games one common tactic among players is to rename all their
cities
to same name, usually something short, simple but obscure like "@" or
"2".
This serves mainly one purpose: other players cannot know where their
capitol
is located. Usually this information is available in Intelligence
Report, when
you have established embassy with other player. But as all cities have
same
name, it doesn't help to know that capitol is called "2"... However,
this information
is essential or important to many strategies, because capitol plays
quite big part in many
of them (which becomes very clear from new "Art of Freeciv" tutorial)
(civil war, city bribing, etc.)
The following patch prevents player from naming or renaming city to name
that
is already in use by that particular player. If player captures or by
some other means gets
city and its name conflicts with another player's city, city is
automatically
renamed to new name suggested by city_name_suggestion.
city_name_suggestion seems to give globally unique names, so there
should be no problems with this.
So one player cannot have two cities
with same name, but two different players can. This is enough to
guarantee that
capitol can be figured out from Intelligence Report.
I have initially tested patch and it seems to work well.
Teemu Kurppa
tkurppa@xxxxxxxxxx diff -u freeciv-cvs/server/cityhand.c freeciv/server/cityhand.c
--- freeciv-cvs/server/cityhand.c Thu Oct 4 23:23:36 2001
+++ freeciv/server/cityhand.c Thu Nov 22 00:29:46 2001
@@ -387,10 +387,16 @@
return;
if((cp=get_sane_name(preq->name))) {
- /* more sanity tests! any existing city with that name? */
- sz_strlcpy(pcity->name, cp);
- city_refresh(pcity);
- send_city_info(0, pcity);
+ if( city_list_find_name(&pplayer->cities, cp) ) {
+ notify_player_ex(pplayer, pcity->x, pcity->y, E_NOEVENT,
+ _("Game: You already have city called %s"),
+ cp);
+ }
+ else {
+ sz_strlcpy(pcity->name, cp);
+ city_refresh(pcity);
+ send_city_info(0, pcity);
+ }
} else {
notify_player(pplayer, _("Game: %s is not a valid name."), preq->name);
}
diff -u freeciv-cvs/server/citytools.c freeciv/server/citytools.c
--- freeciv-cvs/server/citytools.c Sun Oct 7 00:02:02 2001
+++ freeciv/server/citytools.c Thu Nov 22 12:30:02 2001
@@ -679,6 +679,7 @@
struct unit_list old_city_units;
struct player *pgiver = city_owner(pcity);
int old_trade_routes[4];
+ char old_city_name[MAX_LEN_NAME];
assert(pgiver != ptaker);
@@ -703,6 +704,14 @@
}
}
+ sz_strlcpy(old_city_name,pcity->name);
+ if(city_list_find_name(&ptaker->cities, pcity->name)) {
+ sz_strlcpy(pcity->name,city_name_suggestion(ptaker));
+ notify_player_ex(ptaker, pcity->x, pcity->y, E_NOEVENT,
+ _("City renamed to %s from %s."),
+ pcity->name, old_city_name);
+ }
+
city_list_unlink(&pgiver->cities, pcity);
pcity->owner = ptaker->player_no;
city_list_insert(&ptaker->cities, pcity);
@@ -802,7 +811,7 @@
gamelog(GAMELOG_LOSEC,"%s lose %s (%i,%i)",
get_nation_name_plural(pgiver->nation),
- pcity->name, pcity->x, pcity->y);
+ old_city_name, pcity->x, pcity->y);
sync_cities();
return pcity;
diff -u freeciv-cvs/server/unithand.c freeciv/server/unithand.c
--- freeciv-cvs/server/unithand.c Tue Oct 30 12:37:17 2001
+++ freeciv/server/unithand.c Thu Nov 22 12:30:48 2001
@@ -546,13 +546,21 @@
char *name)
{
char *city_name = get_sane_name(name);
-
+
if (!city_name) {
notify_player_ex(pplayer, punit->x, punit->y, E_NOEVENT,
_("Game: Let's not build a city with "
"such a stupid name."));
return;
}
+
+ if( city_list_find_name(&pplayer->cities,city_name) ) {
+ notify_player_ex(pplayer, punit->x, punit->y, E_NOEVENT,
+ _("Game: You already have city called %s"),
+ city_name);
+ return;
+ }
+
create_city(pplayer, punit->x, punit->y, city_name);
wipe_unit(punit);
}
- [Freeciv-Dev] Patch: Unique city names,
Teemu Kurppa <=
- [Freeciv-Dev] Re: Patch: Unique city names, Raimar Falke, 2001/11/22
- [Freeciv-Dev] Re: Patch: Unique city names, Raimar Falke, 2001/11/23
- [Freeciv-Dev] Re: Patch: Unique city names, Miguel Farah F., 2001/11/24
- [Freeciv-Dev] Re: Patch: Unique city names, Raimar Falke, 2001/11/25
- [Freeciv-Dev] Re: Patch: Unique city names, Miguel Farah F., 2001/11/25
|
|