[Freeciv-Dev] PATCH: unique city names (version 2)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
I finally had that little time needed to finish and test "unique city
names" patch. I added server variable that can be used to control city
naming. There's three possibilities:
0 - no restrictions (current situation)
1 - unique to nation
2 - globally unique
Number 1 is set to default.
As my english isn't that good, I'd appreciate, if someone comes up with
better message and description texts.
Teemu Kurppa
tkurppa@xxxxxxxxxx diff -Nur -Xfreeciv-cvs/diff_ignore freeciv-cvs/common/game.c
freeciv/common/game.c
--- freeciv-cvs/common/game.c Sun Nov 25 17:26:28 2001
+++ freeciv/common/game.c Sun Nov 25 17:32:05 2001
@@ -709,7 +709,8 @@
game.randseed=GAME_DEFAULT_RANDSEED;
game.watchtower_vision=GAME_DEFAULT_WATCHTOWER_VISION;
game.watchtower_extra_vision=GAME_DEFAULT_WATCHTOWER_EXTRA_VISION,
-
+ game.allowed_city_names=GAME_DEFAULT_ALLOWED_CITY_NAMES;
+
sz_strlcpy(game.ruleset.techs, GAME_DEFAULT_RULESET);
sz_strlcpy(game.ruleset.units, GAME_DEFAULT_RULESET);
sz_strlcpy(game.ruleset.buildings, GAME_DEFAULT_RULESET);
diff -Nur -Xfreeciv-cvs/diff_ignore freeciv-cvs/common/game.h
freeciv/common/game.h
--- freeciv-cvs/common/game.h Fri Oct 26 10:33:23 2001
+++ freeciv/common/game.h Sun Nov 25 17:31:08 2001
@@ -144,6 +144,8 @@
int watchtower_extra_vision;
int watchtower_vision;
+ int allowed_city_names;
+
struct {
char techs[MAX_LEN_NAME];
char units[MAX_LEN_NAME];
@@ -435,6 +437,10 @@
#define GAME_DEFAULT_WATCHTOWER_EXTRA_VISION 0
#define GAME_MIN_WATCHTOWER_EXTRA_VISION 0
#define GAME_MAX_WATCHTOWER_EXTRA_VISION 2
+
+#define GAME_DEFAULT_ALLOWED_CITY_NAMES 1
+#define GAME_MIN_ALLOWED_CITY_NAMES 0
+#define GAME_MAX_ALLOWED_CITY_NAMES 2
#define GAME_START_YEAR -4000
diff -Nur -Xfreeciv-cvs/diff_ignore freeciv-cvs/server/cityhand.c
freeciv/server/cityhand.c
--- freeciv-cvs/server/cityhand.c Thu Nov 22 13:00:07 2001
+++ freeciv/server/cityhand.c Sun Nov 25 16:13:22 2001
@@ -387,10 +387,11 @@
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(is_proper_city_name(cp, pcity->x, pcity->y, pplayer)) {
+ 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 -Nur -Xfreeciv-cvs/diff_ignore freeciv-cvs/server/citytools.c
freeciv/server/citytools.c
--- freeciv-cvs/server/citytools.c Thu Nov 22 13:00:07 2001
+++ freeciv/server/citytools.c Sun Nov 25 18:00:39 2001
@@ -58,6 +58,27 @@
char **misc_city_names;
int num_misc_city_names;
+
+int is_proper_city_name(char* city_name, int x, int y,
+ struct player* pplayer)
+{
+ if( game.allowed_city_names == 1 &&
+ city_list_find_name(&pplayer->cities,city_name) ) {
+ notify_player_ex(pplayer, x, y, E_NOEVENT,
+ _("Game: You already have a city called %s"),
+ city_name);
+ return FALSE;
+ }
+ else if( game.allowed_city_names == 2 &&
+ game_find_city_by_name(city_name) ) {
+ notify_player_ex(pplayer, x, y, E_NOEVENT,
+ _("Game: A city called %s already exists."),
+ city_name);
+ return FALSE;
+ }
+ return TRUE;
+}
+
/****************************************************************
Come up with a default name when a new city is about to be built.
Handle running out of names etc. gracefully. Maybe we should keep
@@ -679,6 +700,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 +725,16 @@
}
}
+ sz_strlcpy(old_city_name,pcity->name);
+ if(game.allowed_city_names == 1 &&
+ 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,
+ _("You already had a city called %s."
+ " A city renamed to %s."),
+ old_city_name, pcity->name);
+ }
+
city_list_unlink(&pgiver->cities, pcity);
pcity->owner = ptaker->player_no;
city_list_insert(&ptaker->cities, pcity);
@@ -802,7 +834,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 -Nur -Xfreeciv-cvs/diff_ignore freeciv-cvs/server/citytools.h
freeciv/server/citytools.h
--- freeciv-cvs/server/citytools.h Thu Aug 30 16:00:15 2001
+++ freeciv/server/citytools.h Sun Nov 25 16:35:32 2001
@@ -80,6 +80,7 @@
void change_build_target(struct player *pplayer, struct city *pcity,
int target, int is_unit, int event);
+int is_proper_city_name(char* city_name, int x, int y, struct player *pplayer);
char *city_name_suggestion(struct player *pplayer);
extern char **misc_city_names;
extern int num_misc_city_names;
diff -Nur -Xfreeciv-cvs/diff_ignore freeciv-cvs/server/savegame.c
freeciv/server/savegame.c
--- freeciv-cvs/server/savegame.c Sun Nov 25 17:26:28 2001
+++ freeciv/server/savegame.c Wed Nov 28 22:42:55 2001
@@ -1823,6 +1823,9 @@
game.randseed = secfile_lookup_int_default(file, game.randseed,
"game.randseed");
+ game.allowed_city_names = secfile_lookup_int_default(file,
game.allowed_city_names,
+
"game.allowed_city_names");
+
sz_strlcpy(game.ruleset.techs,
secfile_lookup_str_default(file, "default",
"game.ruleset.techs"));
sz_strlcpy(game.ruleset.units,
@@ -2144,6 +2147,7 @@
secfile_insert_str(file, game.demography, "game.demography");
secfile_insert_int(file, game.watchtower_vision, "game.watchtower_vision");
secfile_insert_int(file, game.watchtower_extra_vision,
"game.watchtower_extra_vision");
+ secfile_insert_int(file, game.allowed_city_names, "game.allowed_city_names");
if (1) {
/* Now always save these, so the server options reflect the
diff -Nur -Xfreeciv-cvs/diff_ignore freeciv-cvs/server/stdinhand.c
freeciv/server/stdinhand.c
--- freeciv-cvs/server/stdinhand.c Fri Oct 26 10:33:24 2001
+++ freeciv/server/stdinhand.c Wed Nov 28 22:12:28 2001
@@ -606,6 +606,17 @@
"Always the larger value of wtowervision and wtowerevision will \n"
"be used. Also see wtowervision.") },
+ { "citynames", &game.allowed_city_names, NULL, NULL,
+ SSET_RULES, SSET_TO_CLIENT,
+ GAME_MIN_ALLOWED_CITY_NAMES, GAME_MAX_ALLOWED_CITY_NAMES,
GAME_DEFAULT_ALLOWED_CITY_NAMES,
+ N_("Allowed city names"),
+ N_("If set to 0, there's no restrictions, players can have\n"
+ "multiple cities with same names.\n"
+ "If set to 1, city names have to be unique to player, \n"
+ "one player can't have multiple cities with a same name.\n"
+ "If set to 2, city names have to be globally unique, \n"
+ "all cities in a game have to have different names.\n") },
+
/* Flexible rules: these can be changed after the game has started.
*
* The distinction between "rules" and "flexible rules" is not always
diff -Nur -Xfreeciv-cvs/diff_ignore freeciv-cvs/server/unithand.c
freeciv/server/unithand.c
--- freeciv-cvs/server/unithand.c Thu Nov 22 13:00:07 2001
+++ freeciv/server/unithand.c Sun Nov 25 17:32:12 2001
@@ -546,13 +546,17 @@
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 (!is_proper_city_name(city_name, punit->x, punit->y, pplayer))
+ return;
+
create_city(pplayer, punit->x, punit->y, city_name);
wipe_unit(punit);
}
- [Freeciv-Dev] PATCH: unique city names (version 2),
Teemu Kurppa <=
|
|