Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] Re: (PR#13003) tile_activity patch
Home

[Freeciv-Dev] Re: (PR#13003) tile_activity patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#13003) tile_activity patch
From: "Brian Dunstan" <bdunstan149@xxxxxxxxx>
Date: Sat, 7 May 2005 16:50:18 -0700
Reply-to: bugs@xxxxxxxxxxx

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

OK, v.2 of the patch has changes 1. - 3.

Since tile_irrigate, etc, are now static, these calls
have been replaced with tile_apply_activity elsewhere
in the  freeciv code.

--- Jason Short <jdorje@xxxxxxxxxxxxxxxxxxxxx> wrote:
> 
> <URL:
> http://bugs.freeciv.org/Ticket/Display.html?id=13003
> >
> 
> Brian Dunstan wrote:
> > <URL:
> http://bugs.freeciv.org/Ticket/Display.html?id=13003
> >
> > 
> > This patch adds a function
> > 
> > tile_activity(tile, activity)
> 
> Seems reasonable.  I think it should be
> tile_apply_activity or
> tile_do_activity instead.
> 
> > The patch I've made is one implementation; I'm
> sure
> > others can think of some way it might be done
> better :)
> 
> 1.  I think the functions tile_transform, etc.,
> should be made static.
> 
> 2.  Don't have a "default" case.
> 
> 3.  Don't manipulate ptile->special directly.  Use
> map_set_special or
> map_clear_special.
> 
> -jason
> 
> 
> 
> 
> 


                
__________________________________ 
Yahoo! Mail Mobile 
Take Yahoo! Mail with you! Check email on your mobile phone. 
http://mobile.yahoo.com/learn/mail 
diff -Nur -Xfreeciv/diff_ignore freeciv/client/gui-ftwl/gui_text.c 
freeciv-altered/client/gui-ftwl/gui_text.c
--- freeciv/client/gui-ftwl/gui_text.c  2005-05-07 07:22:31.000000000 -0400
+++ freeciv-altered/client/gui-ftwl/gui_text.c  2005-05-07 16:38:30.157757176 
-0400
@@ -166,21 +166,11 @@
 
   switch (activity) {
   case ACTIVITY_ROAD:
-    tile_set_special(ptile, S_ROAD);
-    break;
   case ACTIVITY_RAILROAD:
-    tile_set_special(ptile, S_RAILROAD);
-    break;
   case ACTIVITY_MINE:
-    tile_mine(ptile);
-    break;
-
   case ACTIVITY_IRRIGATE:
-    tile_irrigate(ptile);
-    break;
-
   case ACTIVITY_TRANSFORM:
-    tile_transform(ptile);
+    tile_apply_activity(ptile, activity);
     break;
   default:
     assert(0);
diff -Nur -Xfreeciv/diff_ignore freeciv/client/gui-gtk-2.0/menu.c 
freeciv-altered/client/gui-gtk-2.0/menu.c
--- freeciv/client/gui-gtk-2.0/menu.c   2005-05-07 07:22:37.000000000 -0400
+++ freeciv-altered/client/gui-gtk-2.0/menu.c   2005-05-07 16:44:40.497456984 
-0400
@@ -1161,35 +1161,17 @@
 {
   Terrain_type_id old_terrain = ptile->terrain;
   enum tile_special_type old_special = ptile->special;
-#ifndef NDEBUG
-  struct tile_type *ptype = get_tile_type(ptile->terrain);
-#endif
   const char *text;
 
-  /* Change the terrain manually to avoid any side effects. */
-  switch (activity) {
-  case ACTIVITY_IRRIGATE:
-    assert(ptype->irrigation_result != ptile->terrain
-          && ptype->irrigation_result != T_NONE);
-    tile_irrigate(ptile);
-    break;
-
-  case ACTIVITY_MINE:
-    assert(ptype->mining_result != ptile->terrain
-          && ptype->mining_result != T_NONE);
-    tile_mine(ptile);
-    break;
-
-  case ACTIVITY_TRANSFORM:
-    assert(ptype->transform_result != ptile->terrain
-          && ptype->transform_result != T_NONE);
-    tile_transform(ptile);
-    break;
-
-  default:
+  if(!(activity == ACTIVITY_IRRIGATE
+       || activity == ACTIVITY_MINE
+       || activity == ACTIVITY_TRANSFORM)) {
     assert(0);
     return "-";
   }
+  else {
+    tile_apply_activity(ptile, activity);
+  }
 
   text = tile_get_info_text(ptile);
 
diff -Nur -Xfreeciv/diff_ignore freeciv/common/tile.c 
freeciv-altered/common/tile.c
--- freeciv/common/tile.c       2005-05-07 07:22:25.000000000 -0400
+++ freeciv-altered/common/tile.c       2005-05-07 16:35:24.317009264 -0400
@@ -238,7 +238,7 @@
   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)
+static void tile_irrigate(struct tile *ptile)
 {
   Terrain_type_id now, result;
   
@@ -261,7 +261,7 @@
   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)
+static void tile_mine(struct tile *ptile)
 {
   Terrain_type_id now, result;
   
@@ -281,7 +281,7 @@
   Transform (ACTIVITY_TRANSFORM) the tile.  This usually changes the tile's
   terrain type.
 ****************************************************************************/
-void tile_transform(struct tile *ptile)
+static void tile_transform(struct tile *ptile)
 {
   Terrain_type_id now, result;
   
@@ -294,6 +294,74 @@
 }
 
 /****************************************************************************
+  Apply an activity (Activity_type_id, e.g. ACTIVITY_TRANSFORM) to a tile.
+  Return false if there was a error or if the activity is not implemented
+  by this function.
+****************************************************************************/
+bool tile_apply_activity(struct tile *ptile, Activity_type_id act) 
+{
+  switch(act) {
+    
+  case ACTIVITY_POLLUTION:
+  case ACTIVITY_FALLOUT: 
+    tile_clear_dirtiness(ptile);
+    return TRUE;
+    
+  case ACTIVITY_MINE:
+    tile_mine(ptile);
+    return TRUE;
+
+  case ACTIVITY_IRRIGATE: 
+    tile_irrigate(ptile);
+    return TRUE;
+
+  case ACTIVITY_ROAD: 
+    if (!is_ocean(ptile->terrain)
+       && !tile_has_special(ptile, S_ROAD)) {
+      tile_set_special(ptile, S_ROAD);
+      return TRUE;
+    }
+    return FALSE;
+
+  case ACTIVITY_RAILROAD:
+    if (!is_ocean(ptile->terrain)
+       && !tile_has_special(ptile, S_RAILROAD)
+       && tile_has_special(ptile, S_ROAD)) {
+      tile_set_special(ptile, S_RAILROAD);
+      return TRUE;
+    }
+    return FALSE;
+
+  case ACTIVITY_TRANSFORM:
+    tile_transform(ptile);
+    return TRUE;
+    
+  case ACTIVITY_FORTRESS:
+  case ACTIVITY_PILLAGE: 
+  case ACTIVITY_AIRBASE:   
+    /* do nothing  - not implemented */
+    return FALSE;
+
+  case ACTIVITY_IDLE:
+  case ACTIVITY_FORTIFIED:
+  case ACTIVITY_SENTRY:
+  case ACTIVITY_GOTO:
+  case ACTIVITY_EXPLORE:
+  case ACTIVITY_UNKNOWN:
+  case ACTIVITY_FORTIFYING:
+  case ACTIVITY_PATROL_UNUSED:
+  case ACTIVITY_LAST:
+    /* do nothing - these activities have no effect
+       on terrain type or tile specials */
+
+    return FALSE;
+  }
+  return FALSE;
+}
+
+
+
+/****************************************************************************
   Return a (static) string with tile name describing terrain and specials.
 
   Examples:
diff -Nur -Xfreeciv/diff_ignore freeciv/common/tile.h 
freeciv-altered/common/tile.h
--- freeciv/common/tile.h       2005-05-07 07:22:25.000000000 -0400
+++ freeciv-altered/common/tile.h       2005-05-07 16:18:02.991314832 -0400
@@ -74,9 +74,7 @@
                       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);
+bool tile_apply_activity(struct tile *ptile, Activity_type_id act);
 
 const char *tile_get_info_text(const struct tile *ptile);
 
diff -Nur -Xfreeciv/diff_ignore freeciv/server/generator/startpos.c 
freeciv-altered/server/generator/startpos.c
--- freeciv/server/generator/startpos.c 2005-05-07 07:22:38.000000000 -0400
+++ freeciv-altered/server/generator/startpos.c 2005-05-07 16:15:33.816992776 
-0400
@@ -55,7 +55,7 @@
   old_special = ptile->special;
 
   tile_set_special(ptile, S_ROAD);
-  tile_irrigate(ptile);
+  tile_apply_activity(ptile, ACTIVITY_IRRIGATE);
   irrig_bonus = -value;
   output_type_iterate(o) {
     irrig_bonus += get_output_tile(ptile, o);
@@ -64,7 +64,7 @@
   ptile->terrain = old_terrain;
   ptile->special = old_special;
   tile_set_special(ptile, S_ROAD);
-  tile_mine(ptile);
+  tile_apply_activity(ptile, ACTIVITY_MINE);
   mine_bonus = -value;
   output_type_iterate(o) {
     mine_bonus += get_output_tile(ptile, o);
diff -Nur -Xfreeciv/diff_ignore freeciv/server/unittools.c 
freeciv-altered/server/unittools.c
--- freeciv/server/unittools.c  2005-05-07 07:22:38.000000000 -0400
+++ freeciv-altered/server/unittools.c  2005-05-07 16:26:05.065028488 -0400
@@ -775,7 +775,7 @@
     if (total_activity (ptile, ACTIVITY_IRRIGATE)
         >= tile_activity_time(ACTIVITY_IRRIGATE, ptile)) {
       Terrain_type_id old = tile_get_terrain(ptile);
-      tile_irrigate(ptile);
+      tile_apply_activity(ptile, ACTIVITY_IRRIGATE);
       solvency = check_terrain_ocean_land_change(ptile, old);
       unit_activity_done = TRUE;
     }
@@ -803,7 +803,7 @@
         >= tile_activity_time(ACTIVITY_MINE, ptile)) {
       Terrain_type_id old = tile_get_terrain(ptile);
 
-      tile_mine(ptile);
+      tile_apply_activity(ptile, ACTIVITY_MINE);
       solvency = check_terrain_ocean_land_change(ptile, old);
       unit_activity_done = TRUE;
       check_adjacent_units = TRUE;
@@ -815,7 +815,7 @@
         >= tile_activity_time(ACTIVITY_TRANSFORM, ptile)) {
       Terrain_type_id old = tile_get_terrain(ptile);
 
-      tile_transform(ptile);
+      tile_apply_activity(ptile, ACTIVITY_TRANSFORM);
       solvency = check_terrain_ocean_land_change(ptile, old);
       unit_activity_done = TRUE;
       check_adjacent_units = TRUE;

[Prev in Thread] Current Thread [Next in Thread]