[Freeciv-Dev] (PR#12918) move tile_change_terrain and friends into tile.
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12918 >
This patch moves
map_change_terrain
map_irrigate_tile
map_mine_tile
map_transform_tile
from map.[ch] into tile.[ch]. They are renamed as
tile_change_terrain
tile_irrigate
tile_mine
tile_transform
. I also moved two static helper functions over.
In the process I cleaned up the internals. I added comments, fixed
style, and changed tile_irrigate and tile_mine to use
tile_change_terrain. This should make behavior of terraforming more
consistent.
-jason
? barbs
? diff
Index: client/gui-ftwl/gui_text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/gui_text.c,v
retrieving revision 1.6
diff -u -r1.6 gui_text.c
--- client/gui-ftwl/gui_text.c 23 Apr 2005 17:40:23 -0000 1.6
+++ client/gui-ftwl/gui_text.c 28 Apr 2005 05:26:18 -0000
@@ -172,15 +172,15 @@
tile_set_special(ptile, S_RAILROAD);
break;
case ACTIVITY_MINE:
- map_mine_tile(ptile);
+ tile_mine(ptile);
break;
case ACTIVITY_IRRIGATE:
- map_irrigate_tile(ptile);
+ tile_irrigate(ptile);
break;
case ACTIVITY_TRANSFORM:
- map_transform_tile(ptile);
+ tile_transform(ptile);
break;
default:
assert(0);
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.73
diff -u -r1.73 menu.c
--- client/gui-gtk-2.0/menu.c 23 Apr 2005 17:40:24 -0000 1.73
+++ client/gui-gtk-2.0/menu.c 28 Apr 2005 05:26:18 -0000
@@ -1171,19 +1171,19 @@
case ACTIVITY_IRRIGATE:
assert(ptype->irrigation_result != ptile->terrain
&& ptype->irrigation_result != T_NONE);
- map_irrigate_tile(ptile);
+ tile_irrigate(ptile);
break;
case ACTIVITY_MINE:
assert(ptype->mining_result != ptile->terrain
&& ptype->mining_result != T_NONE);
- map_mine_tile(ptile);
+ tile_mine(ptile);
break;
case ACTIVITY_TRANSFORM:
assert(ptype->transform_result != ptile->terrain
&& ptype->transform_result != T_NONE);
- map_transform_tile(ptile);
+ tile_transform(ptile);
break;
default:
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.220
diff -u -r1.220 map.c
--- common/map.c 28 Apr 2005 03:47:56 -0000 1.220
+++ common/map.c 28 Apr 2005 05:26:19 -0000
@@ -738,119 +738,6 @@
return FALSE;
}
-/***************************************************************
-...
-***************************************************************/
-static void clear_infrastructure(struct tile *ptile)
-{
- tile_clear_special(ptile, S_INFRASTRUCTURE_MASK);
-}
-
-/***************************************************************
-...
-***************************************************************/
-static void clear_dirtiness(struct tile *ptile)
-{
- tile_clear_special(ptile, S_POLLUTION | S_FALLOUT);
-}
-
-/***************************************************************
-...
-***************************************************************/
-void map_irrigate_tile(struct tile *ptile)
-{
- Terrain_type_id now, result;
-
- now = ptile->terrain;
- result = tile_types[now].irrigation_result;
-
- if (now == result) {
- if (tile_has_special(ptile, S_IRRIGATION)) {
- tile_set_special(ptile, S_FARMLAND);
- } else {
- tile_set_special(ptile, S_IRRIGATION);
- }
- } else if (result != T_NONE) {
- tile_set_terrain(ptile, result);
- if (is_ocean(result)) {
- clear_infrastructure(ptile);
- clear_dirtiness(ptile);
-
- /* FIXME: When rest of code can handle
- * rivers in oceans, don't clear this! */
- tile_clear_special(ptile, S_RIVER);
- }
- }
- tile_clear_special(ptile, S_MINE);
-}
-
-/***************************************************************
-...
-***************************************************************/
-void map_mine_tile(struct tile *ptile)
-{
- Terrain_type_id now, result;
-
- now = ptile->terrain;
- result = tile_types[now].mining_result;
-
- if (now == result) {
- tile_set_special(ptile, S_MINE);
- } else if (result != T_NONE) {
- tile_set_terrain(ptile, result);
- if (is_ocean(result)) {
- clear_infrastructure(ptile);
- clear_dirtiness(ptile);
-
- /* FIXME: When rest of code can handle
- * rivers in oceans, don't clear this! */
- tile_clear_special(ptile, S_RIVER);
- }
- }
- tile_clear_special(ptile, S_FARMLAND);
- tile_clear_special(ptile, S_IRRIGATION);
-}
-
-/***************************************************************
-...
-***************************************************************/
-void change_terrain(struct tile *ptile, Terrain_type_id type)
-{
- tile_set_terrain(ptile, type);
- if (is_ocean(type)) {
- clear_infrastructure(ptile);
- clear_dirtiness(ptile);
- tile_clear_special(ptile, S_RIVER); /* FIXME: When rest of code can
handle
- rivers in oceans, don't clear this!
*/
- }
-
- /* Clear mining/irrigation if resulting terrain type cannot support
- that feature. (With current rules, this should only clear mines,
- but I'm including both cases in the most general form for possible
- future ruleset expansion. -GJW) */
-
- if (tile_types[type].mining_result != type)
- tile_clear_special(ptile, S_MINE);
-
- if (tile_types[type].irrigation_result != type)
- tile_clear_special(ptile, S_FARMLAND | S_IRRIGATION);
-}
-
-/***************************************************************
-...
-***************************************************************/
-void map_transform_tile(struct tile *ptile)
-{
- Terrain_type_id now, result;
-
- now = ptile->terrain;
- result = tile_types[now].transform_result;
-
- if (result != T_NONE) {
- change_terrain(ptile, result);
- }
-}
-
/**************************************************************************
This function returns true if the tile at the given location can be
"reclaimed" from ocean into land. This is the case only when there are
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.242
diff -u -r1.242 map.h
--- common/map.h 28 Apr 2005 03:47:56 -0000 1.242
+++ common/map.h 28 Apr 2005 05:26:19 -0000
@@ -284,11 +284,6 @@
enum tile_special_type map_get_infrastructure_prerequisite(enum
tile_special_type spe);
enum tile_special_type get_preferred_pillage(enum tile_special_type pset);
-void map_irrigate_tile(struct tile *ptile);
-void map_mine_tile(struct tile *ptile);
-void change_terrain(struct tile *ptile, Terrain_type_id type);
-void map_transform_tile(struct tile *ptile);
-
bool can_channel_land(const struct tile *ptile);
bool can_reclaim_ocean(const struct tile *ptile);
Index: common/tile.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.c,v
retrieving revision 1.2
diff -u -r1.2 tile.c
--- common/tile.c 27 Apr 2005 02:48:00 -0000 1.2
+++ common/tile.c 28 Apr 2005 05:26:19 -0000
@@ -167,3 +167,109 @@
return 0;
}
}
+
+/****************************************************************************
+ Clear all infrastructure (man-made specials) from the tile.
+****************************************************************************/
+static void tile_clear_infrastructure(struct tile *ptile)
+{
+ tile_clear_special(ptile, S_INFRASTRUCTURE_MASK);
+}
+
+/****************************************************************************
+ Clear all "dirtiness" (pollution and fallout) from the tile.
+****************************************************************************/
+static void tile_clear_dirtiness(struct tile *ptile)
+{
+ tile_clear_special(ptile, S_POLLUTION);
+ tile_clear_special(ptile, S_FALLOUT);
+}
+
+/****************************************************************************
+ Change the terrain to the given type. This does secondary tile updates to
+ the tile (as will happen when mining/irrigation/transforming changes the
+ tile's terrain).
+****************************************************************************/
+void tile_change_terrain(struct tile *ptile, Terrain_type_id type)
+{
+ tile_set_terrain(ptile, type);
+ if (is_ocean(type)) {
+ tile_clear_infrastructure(ptile);
+ tile_clear_dirtiness(ptile);
+
+ /* FIXME: When rest of code can handle
+ * rivers in oceans, then maybe we can leave it in place. */
+ tile_clear_special(ptile, S_RIVER);
+ }
+
+ /* Clear mining/irrigation if resulting terrain type cannot support
+ * that feature. */
+
+ if (tile_types[type].mining_result != type) {
+ tile_clear_special(ptile, S_MINE);
+ }
+
+ if (tile_types[type].irrigation_result != type) {
+ tile_clear_special(ptile, S_IRRIGATION);
+ tile_clear_special(ptile, S_FARMLAND);
+ }
+}
+
+/****************************************************************************
+ Build irrigation on the tile. This may change the specials of the tile
+ or change the terrain type itself.
+****************************************************************************/
+void tile_irrigate(struct tile *ptile)
+{
+ Terrain_type_id now, result;
+
+ now = ptile->terrain;
+ result = tile_types[now].irrigation_result;
+
+ if (now == result) {
+ if (tile_has_special(ptile, S_IRRIGATION)) {
+ tile_set_special(ptile, S_FARMLAND);
+ } else {
+ tile_set_special(ptile, S_IRRIGATION);
+ }
+ tile_clear_special(ptile, S_MINE);
+ } else if (result != T_NONE) {
+ tile_change_terrain(ptile, result);
+ }
+}
+
+/****************************************************************************
+ Build a mine on the tile. This may change the specials of the tile
+ or change the terrain type itself.
+****************************************************************************/
+void tile_mine(struct tile *ptile)
+{
+ Terrain_type_id now, result;
+
+ now = ptile->terrain;
+ result = tile_types[now].mining_result;
+
+ if (now == result) {
+ tile_set_special(ptile, S_MINE);
+ tile_clear_special(ptile, S_FARMLAND);
+ tile_clear_special(ptile, S_IRRIGATION);
+ } else if (result != T_NONE) {
+ tile_change_terrain(ptile, result);
+ }
+}
+
+/****************************************************************************
+ Transform (ACTIVITY_TRANSFORM) the tile. This usually changes the tile's
+ terrain type.
+****************************************************************************/
+void tile_transform(struct tile *ptile)
+{
+ Terrain_type_id now, result;
+
+ now = ptile->terrain;
+ result = tile_types[now].transform_result;
+
+ if (result != T_NONE) {
+ tile_change_terrain(ptile, result);
+ }
+}
Index: common/tile.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.h,v
retrieving revision 1.2
diff -u -r1.2 tile.h
--- common/tile.h 27 Apr 2005 02:48:00 -0000 1.2
+++ common/tile.h 28 Apr 2005 05:26:19 -0000
@@ -73,4 +73,9 @@
int tile_activity_time(enum unit_activity activity,
const struct tile *ptile);
+void tile_change_terrain(struct tile *ptile, Terrain_type_id type);
+void tile_irrigate(struct tile *ptile);
+void tile_mine(struct tile *ptile);
+void tile_transform(struct tile *ptile);
+
#endif /* FC__TILE_H */
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.160
diff -u -r1.160 maphand.c
--- server/maphand.c 23 Apr 2005 17:40:29 -0000 1.160
+++ server/maphand.c 28 Apr 2005 05:26:20 -0000
@@ -221,7 +221,7 @@
}
if (new != T_NONE && old != new) {
effect--;
- change_terrain(ptile, new);
+ tile_change_terrain(ptile, new);
update_tile_knowledge(ptile);
unit_list_iterate(ptile->units, punit) {
if (!can_unit_continue_current_activity(punit)) {
@@ -263,7 +263,7 @@
}
if (new != T_NONE && old != new) {
effect--;
- change_terrain(ptile, new);
+ tile_change_terrain(ptile, new);
update_tile_knowledge(ptile);
unit_list_iterate(ptile->units, punit) {
if (!can_unit_continue_current_activity(punit)) {
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.341
diff -u -r1.341 unittools.c
--- server/unittools.c 28 Apr 2005 04:15:42 -0000 1.341
+++ server/unittools.c 28 Apr 2005 05:26:21 -0000
@@ -770,7 +770,7 @@
if (total_activity (punit->tile, ACTIVITY_IRRIGATE)
>= tile_activity_time(ACTIVITY_IRRIGATE, punit->tile)) {
Terrain_type_id old = tile_get_terrain(punit->tile);
- map_irrigate_tile(punit->tile);
+ tile_irrigate(punit->tile);
solvency = check_terrain_ocean_land_change(punit->tile, old);
unit_activity_done = TRUE;
}
@@ -797,7 +797,7 @@
if (total_activity (punit->tile, ACTIVITY_MINE)
>= tile_activity_time(ACTIVITY_MINE, punit->tile)) {
Terrain_type_id old = tile_get_terrain(punit->tile);
- map_mine_tile(punit->tile);
+ tile_mine(punit->tile);
solvency = check_terrain_ocean_land_change(punit->tile, old);
unit_activity_done = TRUE;
check_adjacent_units = TRUE;
@@ -808,7 +808,7 @@
if (total_activity (punit->tile, ACTIVITY_TRANSFORM)
>= tile_activity_time(ACTIVITY_TRANSFORM, punit->tile)) {
Terrain_type_id old = tile_get_terrain(punit->tile);
- map_transform_tile(punit->tile);
+ tile_transform(punit->tile);
solvency = check_terrain_ocean_land_change(punit->tile, old);
unit_activity_done = TRUE;
check_adjacent_units = TRUE;
Index: server/generator/startpos.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/generator/startpos.c,v
retrieving revision 1.10
diff -u -r1.10 startpos.c
--- server/generator/startpos.c 23 Apr 2005 17:40:29 -0000 1.10
+++ server/generator/startpos.c 28 Apr 2005 05:26:21 -0000
@@ -54,7 +54,7 @@
old_special = ptile->special;
tile_set_special(ptile, S_ROAD);
- map_irrigate_tile(ptile);
+ tile_irrigate(ptile);
irrig_bonus = -value;
output_type_iterate(o) {
irrig_bonus += get_output_tile(ptile, o);
@@ -63,7 +63,7 @@
ptile->terrain = old_terrain;
ptile->special = old_special;
tile_set_special(ptile, S_ROAD);
- map_mine_tile(ptile);
+ tile_mine(ptile);
mine_bonus = -value;
output_type_iterate(o) {
mine_bonus += get_output_tile(ptile, o);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12918) move tile_change_terrain and friends into tile.h,
Jason Short <=
|
|