Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] (PR#13613) enhance the tile modification functions
Home

[Freeciv-Dev] (PR#13613) enhance the tile modification functions

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13613) enhance the tile modification functions
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 4 Aug 2005 19:55:19 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13613 >

This patch adds two new tile functions, tile_add_special and 
tile_remove_special.  These add/remove the given special and also handle 
side effects.

Currently they're used only by the other tile functions (specificially 
tile_apply_activity).  Later they should be used by the server code 
during map edits.

-jason

Index: common/tile.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.c,v
retrieving revision 1.10
diff -p -u -r1.10 tile.c
--- common/tile.c       1 Aug 2005 22:38:25 -0000       1.10
+++ common/tile.c       5 Aug 2005 02:53:08 -0000
@@ -238,25 +238,94 @@ void tile_change_terrain(struct tile *pt
 }
 
 /****************************************************************************
+  Add the special to the tile.  This does secondary tile updates to
+  the tile.
+****************************************************************************/
+void tile_add_special(struct tile *ptile, enum tile_special_type special)
+{
+  tile_add_special(ptile, special);
+
+  switch (special) {
+  case S_FARMLAND:
+    tile_add_special(ptile, S_IRRIGATION);
+    /* Fall through to irrigation */
+  case S_IRRIGATION:
+    tile_clear_special(ptile, S_MINE);
+    break;
+  case S_RAILROAD:
+    tile_add_special(ptile, S_ROAD);
+    break;
+  case S_MINE:
+    tile_clear_special(ptile, S_IRRIGATION);
+    tile_clear_special(ptile, S_FARMLAND);
+    break;
+
+  case S_SPECIAL_1:
+    tile_clear_special(ptile, S_SPECIAL_2);
+    break;
+
+  case S_SPECIAL_2:
+    tile_clear_special(ptile, S_SPECIAL_1);
+    break;
+
+  case S_ROAD:
+  case S_POLLUTION:
+  case S_HUT:
+  case S_FORTRESS:
+  case S_RIVER:
+  case S_AIRBASE:
+  case S_FALLOUT:
+  case S_LAST:
+    break;
+  }
+}
+
+/****************************************************************************
+  Remove the special from the tile.  This does secondary tile updates to
+  the tile.
+****************************************************************************/
+void tile_remove_special(struct tile *ptile, enum tile_special_type special)
+{
+  tile_remove_special(ptile, special);
+
+  switch (special) {
+  case S_IRRIGATION:
+    tile_clear_special(ptile, S_FARMLAND);
+    break;
+  case S_ROAD:
+    tile_clear_special(ptile, S_RAILROAD);
+    break;
+
+  case S_SPECIAL_1:
+  case S_RAILROAD:
+  case S_MINE:
+  case S_POLLUTION:
+  case S_HUT:
+  case S_FORTRESS:
+  case S_SPECIAL_2:
+  case S_RIVER:
+  case S_FARMLAND:
+  case S_AIRBASE:
+  case S_FALLOUT:
+  case S_LAST:
+    break;
+  }
+}
+
+/****************************************************************************
   Build irrigation on the tile.  This may change the specials of the tile
   or change the terrain type itself.
 ****************************************************************************/
 static void tile_irrigate(struct tile *ptile)
 {
-  struct terrain *now, *result;
-  
-  now = ptile->terrain;
-  result = now->irrigation_result;
-
-  if (now == result) {
+  if (ptile->terrain == ptile->terrain->irrigation_result) {
     if (tile_has_special(ptile, S_IRRIGATION)) {
-      tile_set_special(ptile, S_FARMLAND);
+      tile_add_special(ptile, S_FARMLAND);
     } else {
-      tile_set_special(ptile, S_IRRIGATION);
+      tile_add_special(ptile, S_IRRIGATION);
     }
-    tile_clear_special(ptile, S_MINE);
-  } else if (result != T_NONE) {
-    tile_change_terrain(ptile, result);
+  } else if (ptile->terrain->irrigation_result) {
+    tile_change_terrain(ptile, ptile->terrain->irrigation_result);
   }
 }
 
@@ -266,17 +335,12 @@ static void tile_irrigate(struct tile *p
 ****************************************************************************/
 static void tile_mine(struct tile *ptile)
 {
-  struct terrain *now, *result;
-  
-  now = ptile->terrain;
-  result = now->mining_result;
-  
-  if (now == result) {
+  if (ptile->terrain == ptile->terrain->mining_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);
+  } else if (ptile->terrain->mining_result) {
+    tile_change_terrain(ptile, ptile->terrain->mining_result);
   }
 }
 
@@ -286,13 +350,8 @@ static void tile_mine(struct tile *ptile
 ****************************************************************************/
 static void tile_transform(struct tile *ptile)
 {
-  struct terrain *now, *result;
-  
-  now = ptile->terrain;
-  result = now->transform_result;
-  
-  if (result != T_NONE) {
-    tile_change_terrain(ptile, result);
+  if (ptile->terrain->transform_result != T_NONE) {
+    tile_change_terrain(ptile, ptile->terrain->transform_result);
   }
 }
 
Index: common/tile.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.h,v
retrieving revision 1.11
diff -p -u -r1.11 tile.h
--- common/tile.h       14 Jul 2005 19:25:45 -0000      1.11
+++ common/tile.h       5 Aug 2005 02:53:08 -0000
@@ -73,7 +73,10 @@ enum known_type tile_get_known(const str
 int tile_activity_time(enum unit_activity activity,
                       const struct tile *ptile);
 
+/* These are higher-level functions that handle side effects on the tile. */
 void tile_change_terrain(struct tile *ptile, struct terrain *pterrain);
+void tile_add_special(struct tile *ptile, enum tile_special_type special);
+void tile_remove_special(struct tile *ptile, enum tile_special_type special);
 bool tile_apply_activity(struct tile *ptile, Activity_type_id act);
 
 const char *tile_get_info_text(const struct tile *ptile);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13613) enhance the tile modification functions, Jason Short <=