<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39452 >
Committed trunk revision 13095.
Index: server/ruleset.c =================================================================== --- server/ruleset.c (revision 13094) +++ server/ruleset.c (working copy) @@ -1685,7 +1685,7 @@ filename, tsec[i]); exit(EXIT_FAILURE); } - if (UNKNOWN_TERRAIN_IDENTIFIER == pterrain->identifier) { + if (TERRAIN_UNKNOWN_IDENTIFIER == pterrain->identifier) { freelog(LOG_FATAL, "\"%s\" [%s] cannot use '%c' as an identifier;" " it is reserved.", filename, tsec[i], pterrain->identifier); Index: server/maphand.c =================================================================== --- server/maphand.c (revision 13094) +++ server/maphand.c (working copy) @@ -129,7 +129,6 @@ **************************************************************************/ void assign_continent_numbers(void) { - /* Initialize */ map.num_continents = 0; map.num_oceans = 0; @@ -172,6 +171,164 @@ map.num_continents, map.num_oceans); } +/************************************************************************** + Regenerate all oceanic tiles with coasts, lakes, and deeper oceans. + Assumes assign_continent_numbers() and recalculate_lake_surrounders() + have already been done! + FIXME: insufficiently generalized, use terrain property. +**************************************************************************/ +void map_regenerate_water(void) +{ +#define DEFAULT_LAKE_SEA_SIZE (4) /* should be configurable */ +#define DEFAULT_NEAR_COAST (6) + struct terrain *lake = terrain_by_identifier(TERRAIN_LAKE_IDENTIFIER); + struct terrain *sea = terrain_by_identifier(TERRAIN_SEA_IDENTIFIER); + struct terrain *coast = terrain_by_identifier(TERRAIN_COAST_IDENTIFIER); + struct terrain *shelf = terrain_by_identifier(TERRAIN_SHELF_IDENTIFIER); + struct terrain *floor = terrain_by_identifier(TERRAIN_FLOOR_IDENTIFIER); + int shelf_depth = shelf->property[MG_OCEAN_DEPTH]; + int coast_count = 0; + int shelf_count = 0; + int floor_count = 0; + + /* coasts, lakes, and seas */ + whole_map_iterate(ptile) { + struct terrain *pterrain = tile_get_terrain(ptile); + Continent_id here = tile_get_continent(ptile); + + if (T_UNKNOWN == pterrain) { + continue; + } + if (!is_ocean(pterrain)) { + continue; + } + if (0 < lake_surrounders[-here]) { + if (DEFAULT_LAKE_SEA_SIZE < ocean_sizes[-here]) { + tile_change_terrain(ptile, lake); + } else { + tile_change_terrain(ptile, sea); + } + update_tile_knowledge(ptile); + continue; + } + /* leave any existing deep features in place */ + if (pterrain->property[MG_OCEAN_DEPTH] > shelf_depth) { + continue; + } + + /* default to shelf */ + tile_change_terrain(ptile, shelf); + update_tile_knowledge(ptile); + shelf_count++; + + adjc_iterate(ptile, tile2) { + if (T_UNKNOWN == tile2->terrain) { + continue; + } + /* glacier not otherwise near land floats */ + if (TERRAIN_GLACIER_IDENTIFIER == tile2->terrain->identifier) { + continue; + } + /* any land makes coast */ + if (!is_ocean(tile2->terrain)) { + tile_change_terrain(ptile, coast); + update_tile_knowledge(ptile); + coast_count++; + shelf_count--; + break; + } + } adjc_iterate_end; + } whole_map_iterate_end; + + /* continental shelf */ + whole_map_iterate(ptile) { + struct terrain *pterrain = tile_get_terrain(ptile); + int shallow = 0; + + if (T_UNKNOWN == pterrain) { + continue; + } + if (!is_ocean(pterrain)) { + continue; + } + /* leave any other existing features in place */ + if (pterrain != shelf) { + continue; + } + + adjc_iterate(ptile, tile2) { + if (T_UNKNOWN == tile2->terrain) + continue; + + switch (tile2->terrain->identifier) { + case TERRAIN_COAST_IDENTIFIER: + shallow++; + break; + default: + break; + }; + } adjc_iterate_end; + + if (DEFAULT_NEAR_COAST < shallow) { + /* smooth with neighbors */ + tile_change_terrain(ptile, coast); + update_tile_knowledge(ptile); + coast_count++; + shelf_count--; + } else if (0 == shallow) { + tile_change_terrain(ptile, floor); + update_tile_knowledge(ptile); + floor_count++; + shelf_count--; + } + } whole_map_iterate_end; + + /* deep ocean floor */ + whole_map_iterate(ptile) { + struct terrain *pterrain = tile_get_terrain(ptile); + int shallow = 0; + + if (T_UNKNOWN == pterrain) { + continue; + } + if (!is_ocean(pterrain)) { + continue; + } + /* leave any other existing features in place */ + if (pterrain != floor) { + continue; + } + + adjc_iterate(ptile, tile2) { + if (T_UNKNOWN == tile2->terrain) + continue; + + switch (tile2->terrain->identifier) { +; case TERRAIN_GLACIER_IDENTIFIER: + case TERRAIN_COAST_IDENTIFIER: + case TERRAIN_SHELF_IDENTIFIER: + shallow++; + break; + default: + break; + }; + } adjc_iterate_end; + + if (DEFAULT_NEAR_COAST < shallow) { + /* smooth with neighbors */ + tile_change_terrain(ptile, shelf); + update_tile_knowledge(ptile); + floor_count--; + shelf_count++; + } + } whole_map_iterate_end; + + freelog(LOG_VERBOSE, "Map has %d coast, %d shelf, and %d floor tiles", + coast_count, + shelf_count, + floor_count); +} + static void player_tile_init(struct tile *ptile, struct player *pplayer); static void give_tile_info_from_player_to_player(struct player *pfrom, struct player *pdest, @@ -1542,7 +1699,7 @@ more land to sources in range, unless there are enemy units within this range. *************************************************************************/ -void map_calculate_borders() +void map_calculate_borders(void) { struct city_list *cities_to_refresh = NULL; Index: server/maphand.h =================================================================== --- server/maphand.h (revision 13094) +++ server/maphand.h (working copy) @@ -52,6 +52,7 @@ }; void assign_continent_numbers(void); +void map_regenerate_water(void); void global_warming(int effect); void nuclear_winter(int effect); Index: server/edithand.c =================================================================== --- server/edithand.c (revision 13094) +++ server/edithand.c (working copy) @@ -521,3 +521,13 @@ map_calculate_borders(); } } + +/**************************************************************************** + Client editor requests us to regenerate water. +****************************************************************************/ +void handle_edit_regenerate_water(struct connection *pc) +{ + if (can_conn_edit(pc)) { + map_regenerate_water(); + } +} Index: server/savegame.c =================================================================== --- server/savegame.c (revision 13094) +++ server/savegame.c (working copy) @@ -250,7 +250,7 @@ static struct terrain *char2terrain(char ch) { /* terrain_by_identifier plus fatal error */ - if (ch == UNKNOWN_TERRAIN_IDENTIFIER) { + if (ch == TERRAIN_UNKNOWN_IDENTIFIER) { return T_UNKNOWN; } terrain_type_iterate(pterrain) { @@ -270,7 +270,7 @@ static char terrain2char(const struct terrain *pterrain) { if (pterrain == T_UNKNOWN) { - return UNKNOWN_TERRAIN_IDENTIFIER; + return TERRAIN_UNKNOWN_IDENTIFIER; } else { return pterrain->identifier; } Index: data/default/cities.ruleset =================================================================== --- data/default/cities.ruleset (revision 13094) +++ data/default/cities.ruleset (working copy) @@ -53,8 +53,8 @@ add_to_size_limit = 8 ; cities >= this cannot be added to. angry_citizens = 1 ; set to zero to disable angry citizens celebrate_size_limit = 3 ; cities >= can celebrate + changable_tax = 1 ; set to zero to disallow changing of tax rates - ;forced_science = 0 ; set these fields when changeable_tax is turned off ;forced_luxury = 100 ;forced_gold = 0 Index: common/packets.def =================================================================== --- common/packets.def (revision 13094) +++ common/packets.def (working copy) @@ -1490,3 +1490,6 @@ TECH tech; EDIT_TECH_MODE mode; end + +PACKET_EDIT_REGENERATE_WATER=134;cs,handle-per-conn +end Index: common/terrain.c =================================================================== --- common/terrain.c (revision 13094) +++ common/terrain.c (working copy) @@ -71,7 +71,7 @@ ****************************************************************************/ struct terrain *terrain_by_identifier(const char identifier) { - if (UNKNOWN_TERRAIN_IDENTIFIER == identifier) { + if (TERRAIN_UNKNOWN_IDENTIFIER == identifier) { return T_UNKNOWN; } terrain_type_iterate(pterrain) { Index: common/terrain.h =================================================================== --- common/terrain.h (revision 13094) +++ common/terrain.h (working copy) @@ -123,9 +123,14 @@ char graphic_alt[MAX_LEN_NAME]; /* TODO: retire, never used! */ char identifier; /* Single-character identifier used in savegames. */ -#define WATER_TERRAIN_IDENTIFIER ' ' -#define GLACIER_TERRAIN_IDENTIFIER 'a' -#define UNKNOWN_TERRAIN_IDENTIFIER 'u' +#define TERRAIN_WATER_IDENTIFIER ' ' +#define TERRAIN_LAKE_IDENTIFIER '+' +#define TERRAIN_SEA_IDENTIFIER '-' +#define TERRAIN_COAST_IDENTIFIER '.' +#define TERRAIN_SHELF_IDENTIFIER ',' +#define TERRAIN_FLOOR_IDENTIFIER ':' +#define TERRAIN_GLACIER_IDENTIFIER 'a' +#define TERRAIN_UNKNOWN_IDENTIFIER 'u' int movement_cost; int defense_bonus; /* % defense bonus - defaults to zero */ Index: client/control.c =================================================================== --- client/control.c (revision 13094) +++ client/control.c (working copy) @@ -2782,7 +2782,15 @@ /************************************************************************** Recalculate borders. **************************************************************************/ -void key_editor_recalc_borders(void) +void key_editor_recalculate_borders(void) { send_packet_edit_recalculate_borders(&aconnection); } + +/************************************************************************** + Regenerate water. +**************************************************************************/ +void key_editor_regenerate_water(void) +{ + send_packet_edit_regenerate_water(&aconnection); +} Index: client/gui-gtk-2.0/menu.c =================================================================== --- client/gui-gtk-2.0/menu.c (revision 13094) +++ client/gui-gtk-2.0/menu.c (working copy) @@ -163,7 +163,8 @@ MENU_EDITOR_TOGGLE, MENU_EDITOR_TOOLS, - MENU_EDITOR_RECALC_BORDERS, + MENU_EDITOR_RECALCULATE_BORDERS, + MENU_EDITOR_REGENERATE_WATER, MENU_HELP_LANGUAGES, MENU_HELP_CONNECTING, @@ -611,9 +612,12 @@ case MENU_EDITOR_TOOLS: editdlg_show_tools(); break; - case MENU_EDITOR_RECALC_BORDERS: - key_editor_recalc_borders(); + case MENU_EDITOR_RECALCULATE_BORDERS: + key_editor_recalculate_borders(); break; + case MENU_EDITOR_REGENERATE_WATER: + key_editor_regenerate_water(); + break; } } @@ -951,8 +955,10 @@ editor_menu_callback, MENU_EDITOR_TOGGLE, "<CheckItem>" }, { "/" N_("_Editor") "/" N_("_Tools"), NULL, editor_menu_callback, MENU_EDITOR_TOOLS }, - { "/" N_("_Editor") "/" N_("_Recalculate Borders"), NULL, - editor_menu_callback, MENU_EDITOR_RECALC_BORDERS }, + { "/" N_("_Editor") "/" N_("Recalculate _Borders"), NULL, + editor_menu_callback, MENU_EDITOR_RECALCULATE_BORDERS }, + { "/" N_("_Editor") "/" N_("Regenerate _Water"), NULL, + editor_menu_callback, MENU_EDITOR_REGENERATE_WATER }, /* Help menu ... */ { "/" N_("_Help"), NULL, Index: client/control.h =================================================================== --- client/control.h (revision 13094) +++ client/control.h (working copy) @@ -187,7 +187,8 @@ void key_unit_select_battlegroup(int battlegroup, bool append); void key_editor_toggle(void); -void key_editor_recalc_borders(void); +void key_editor_recalculate_borders(void); +void key_editor_regenerate_water(void); /* don't change this unless you also put more entries in data/Freeciv */ #define MAX_NUM_UNITS_BELOW 4
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev