? rc ? msgfmt1.diff ? unit_move_turns1.diff ? old ? diff ? map_distance_vector2.diff ? short_worklists1.diff ? gift.txt ? sound4.patch ? natural_citynames-code2.diff ? server/a.c Index: common/nation.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v retrieving revision 1.6 diff -u -r1.6 nation.h --- common/nation.h 2001/10/12 12:22:18 1.6 +++ common/nation.h 2001/12/04 09:25:14 @@ -37,6 +37,10 @@ int leader_is_male[MAX_NUM_LEADERS]; int city_style; char **default_city_names; + char **default_rcity_names; /* river city names */ + char **default_crcity_names; /* coastal-river city names */ + char **default_ccity_names; /* coastal city names */ + char **default_tcity_names[T_COUNT]; /* terrain-specific city names */ struct Sprite *flag_sprite; /* untranslated copies: */ Index: server/cityhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v retrieving revision 1.104 diff -u -r1.104 cityhand.c --- server/cityhand.c 2001/10/04 20:23:36 1.104 +++ server/cityhand.c 2001/12/04 09:25:15 @@ -47,13 +47,21 @@ struct packet_generic_integer *packet) { struct packet_city_name_suggestion reply; + struct unit *punit = + player_find_unit_by_id(pconn->player, packet->value); + if (!pconn->player) { freelog(LOG_ERROR, "City-name suggestion request from non-player %s", conn_description(pconn)); return; } + + freelog(LOG_VERBOSE, "handle_city_name_suggest_req(unit_pos=(%d,%d))", + punit->x, punit->y); + reply.id = packet->value; - sz_strlcpy(reply.name, city_name_suggestion(pconn->player)); + sz_strlcpy(reply.name, + city_name_suggestion(pconn->player, punit->x, punit->y)); send_packet_city_name_suggestion(pconn, &reply); } Index: server/citytools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v retrieving revision 1.146 diff -u -r1.146 citytools.c --- server/citytools.c 2001/10/06 21:02:02 1.146 +++ server/citytools.c 2001/12/04 09:25:17 @@ -67,20 +67,56 @@ buffer etc, and should be considered read-only (and not freed) by caller. *****************************************************************/ -char *city_name_suggestion(struct player *pplayer) +char *city_name_suggestion(struct player *pplayer, int x, int y) { char **nptr; int i, j; + struct nation_type *nation = get_nation_by_plr(pplayer); static char tempname[MAX_LEN_NAME]; static const int num_tiles = MAP_MAX_WIDTH * MAP_MAX_HEIGHT; - freelog(LOG_VERBOSE, "Suggesting city name for %s", pplayer->name); + freelog(LOG_VERBOSE, "Suggesting city name for %s at (%d,%d)", + pplayer->name, x, y); - for(nptr=get_nation_by_plr(pplayer)->default_city_names; *nptr; nptr++) { - if(!game_find_city_by_name(*nptr)) - return *nptr; + CHECK_MAP_POS(x,y); + +#define SEARCH_AND_RETURN_CITY_NAME(list) \ + for(nptr=list; *nptr; nptr++) { \ + if(!game_find_city_by_name(*nptr)) { \ + return *nptr; \ + } \ + } + + /* + * Use a special name if the tile has a river, is coastal or there + * is an available name depending on the terrain. + */ + + /* deal with rivers */ + if (map_get_special(x, y) & S_RIVER) { + if (is_terrain_near_tile(x, y, T_OCEAN)) { + /* coastal river */ + SEARCH_AND_RETURN_CITY_NAME(nation->default_crcity_names); + } else { + /* non-coastal river */ + SEARCH_AND_RETURN_CITY_NAME(nation->default_rcity_names); + } + } + + /* coastal */ + if (is_terrain_near_tile(x, y, T_OCEAN)) { + SEARCH_AND_RETURN_CITY_NAME(nation->default_ccity_names); } + + /* check terrain type */ + SEARCH_AND_RETURN_CITY_NAME(nation-> + default_tcity_names[map_get_terrain(x, y)]); + + /* we haven't found a name: it's a normal tile or they're all used */ + SEARCH_AND_RETURN_CITY_NAME(nation->default_city_names); + +#undef SEARCH_AND_RETURN_CITY_NAME if (num_misc_city_names > 0) { j = myrand(num_misc_city_names); Index: server/citytools.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/citytools.h,v retrieving revision 1.32 diff -u -r1.32 citytools.h --- server/citytools.h 2001/08/30 13:00:15 1.32 +++ server/citytools.h 2001/12/04 09:25:17 @@ -80,7 +80,7 @@ void change_build_target(struct player *pplayer, struct city *pcity, int target, int is_unit, int event); -char *city_name_suggestion(struct player *pplayer); +char *city_name_suggestion(struct player *pplayer, int x, int y); extern char **misc_city_names; extern int num_misc_city_names; Index: server/ruleset.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v retrieving revision 1.82 diff -u -r1.82 ruleset.c --- server/ruleset.c 2001/10/26 07:33:23 1.82 +++ server/ruleset.c 2001/12/04 09:25:20 @@ -1802,6 +1802,7 @@ char temp_name[MAX_LEN_NAME]; char **cities, **techs, **leaders, **sec; const char *filename = secfile_filename(file); + enum tile_terrain_type type; datafile_options = check_ruleset_capabilities(file, "+1.9", filename); @@ -2009,34 +2010,57 @@ } pl->goals.government = val; - /* read city names */ +#define BASE_READ_CITY_NAME_LIST(target,format,arg1,arg2,arg3) \ + cities = secfile_lookup_str_vec(file, &dim, format, \ + arg1, arg2, arg3); \ + target = fc_calloc(dim + 1, sizeof(char *)); \ + target[dim] = NULL; \ + for (j = 0; j < dim; j++) { \ + target[j] = mystrdup(cities[j]); \ + if (check_name(cities[j])) { \ + target[j][MAX_LEN_NAME - 1] = 0; \ + } \ + } \ + if (cities) { \ + free(cities); \ + } + +#define READ_CITY_NAME_LIST(target_field,format,arg) \ + BASE_READ_CITY_NAME_LIST(pl->target_field, "%s." format "%s", \ + sec[i], arg, "cities") + + /* read "normal" city names */ + READ_CITY_NAME_LIST(default_city_names, "%s", ""); - cities = secfile_lookup_str_vec(file, &dim, "%s.cities", sec[i]); - pl->default_city_names = fc_calloc(dim+1, sizeof(char*)); - pl->default_city_names[dim] = NULL; - for (j = 0; j < dim; j++) { - pl->default_city_names[j] = mystrdup(cities[j]); - if (check_name(cities[j])) { - pl->default_city_names[j][MAX_LEN_NAME - 1] = 0; - } + /* read river city names */ + READ_CITY_NAME_LIST(default_rcity_names, "%s", "river_"); + + /* read coastal-river city names */ + READ_CITY_NAME_LIST(default_crcity_names, "%s","coastal_river_"); + + /* read coastal city names */ + READ_CITY_NAME_LIST(default_ccity_names, "%s", "coastal_"); + + for(type=T_FIRST; typeid; - sz_strlcpy(req.name, city_name_suggestion(pplayer)); x = punit->x; y = punit->y; /* Trevor Pering points out that punit gets freed */ + sz_strlcpy(req.name, city_name_suggestion(pplayer, x, y)); handle_unit_build_city(pplayer, &req); pcity=map_get_city(x, y); /* so we need to cache x and y for a very short time */ if (!pcity) Index: server/unittools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v retrieving revision 1.144 diff -u -r1.144 unittools.c --- server/unittools.c 2001/11/11 15:49:20 1.144 +++ server/unittools.c 2001/12/04 09:25:25 @@ -2389,7 +2389,8 @@ struct player *pplayer = unit_owner(punit); if (is_ok_city_spot(punit->x, punit->y)) { - create_city(pplayer, punit->x, punit->y, city_name_suggestion(pplayer)); + create_city(pplayer, punit->x, punit->y, + city_name_suggestion(pplayer, punit->x, punit->y)); } else { notify_player_ex(pplayer, punit->x, punit->y, E_NOEVENT, _("Game: Friendly nomads are impressed by you,"