Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2005:
[Freeciv-Dev] (PR#14175) fortification rewrite
Home

[Freeciv-Dev] (PR#14175) fortification rewrite

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#14175) fortification rewrite
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 3 Oct 2005 14:47:25 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Inspired by PR#13916.

This patch rewrites unit fortification.  To the casual player the 
behavior should be the same, but the mechanism is quite different and 
should give better handling of corner cases.

Fortified is no longer an activity.  Fortifying remains an activity but 
is available to any units (you may use it for boats).  Units that are 
fortifying for one turn and meet the qualifications will have their 
fortified flag set.  The flag is not reset when the activity is changed, 
so simply clicking on the unit does not "un-fortify" it.  The unit will 
remain fortified as long as it does not move.

Other internal code is cleaned up a bit. 
can_unit_continue_current_activity is moved into the server, and all its 
users are merged into one function.  In another minor bugfix loading a 
unit has the same handling as moving one (this might be worth 
backporting to 2.0 to prevent fortified loaded units, though the client 
doesn't normally allow this).

-jason

Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.365
diff -p -u -r1.365 aiunit.c
--- ai/aiunit.c 22 Jul 2005 16:18:04 -0000      1.365
+++ ai/aiunit.c 3 Oct 2005 21:35:03 -0000
@@ -1940,7 +1940,7 @@ void ai_manage_military(struct player *p
   }
 
   if ((punit->activity == ACTIVITY_SENTRY
-       || punit->activity == ACTIVITY_FORTIFIED)
+       || punit->activity == ACTIVITY_FORTIFYING)
       && ai_handicap(pplayer, H_AWAY)) {
     /* Don't move sentried or fortified units controlled by a player
      * in away mode. */
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.551
diff -p -u -r1.551 packhand.c
--- client/packhand.c   3 Oct 2005 02:50:42 -0000       1.551
+++ client/packhand.c   3 Oct 2005 21:35:10 -0000
@@ -108,6 +108,7 @@ static struct unit * unpackage_unit(stru
   }
   punit->activity_target = packet->activity_target;
   punit->paradropped = packet->paradropped;
+  punit->fortified = packet->fortified;
   punit->done_moving = packet->done_moving;
   punit->occupy = packet->occupy;
   if (packet->transported) {
@@ -157,6 +158,7 @@ static struct unit *unpackage_short_unit
   } else {
     punit->transported_by = -1;
   }
+  punit->fortified = packet->fortified;
 
   return punit;
 }
@@ -979,6 +981,7 @@ static bool handle_unit_packet_common(st
     if (punit->activity != packet_unit->activity
        || punit->activity_target != packet_unit->activity_target
        || punit->transported_by != packet_unit->transported_by
+       || punit->fortified != packet_unit->fortified
        || punit->occupy != packet_unit->occupy
        || punit->has_orders != packet_unit->has_orders
        || punit->orders.repeat != packet_unit->orders.repeat
@@ -1021,6 +1024,7 @@ static bool handle_unit_packet_common(st
 
       punit->activity = packet_unit->activity;
       punit->activity_target = packet_unit->activity_target;
+      punit->fortified = packet_unit->fortified;
 
       punit->transported_by = packet_unit->transported_by;
       if (punit->occupy != packet_unit->occupy
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.327
diff -p -u -r1.327 tilespec.c
--- client/tilespec.c   3 Oct 2005 18:15:10 -0000       1.327
+++ client/tilespec.c   3 Oct 2005 21:35:12 -0000
@@ -2836,11 +2836,12 @@ static int fill_unit_sprite_array(const 
     case ACTIVITY_EXPLORE:
       s = t->sprites.unit.auto_explore;
       break;
-    case ACTIVITY_FORTIFIED:
-      s = t->sprites.unit.fortified;
-      break;
     case ACTIVITY_FORTIFYING:
-      s = t->sprites.unit.fortifying;
+      if (punit->fortified) {
+       s = t->sprites.unit.fortified;
+      } else {
+       s = t->sprites.unit.fortifying;
+      }
       break;
     case ACTIVITY_FORTRESS:
       s = t->sprites.unit.fortress;
Index: common/combat.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/combat.c,v
retrieving revision 1.63
diff -p -u -r1.63 combat.c
--- common/combat.c     3 Oct 2005 06:38:04 -0000       1.63
+++ common/combat.c     3 Oct 2005 21:35:13 -0000
@@ -529,7 +529,7 @@ int get_total_defense_power(const struct
   return defense_multiplication(attacker->type, defender->type,
                                defender->tile,
                                get_defense_power(defender),
-                               defender->activity == ACTIVITY_FORTIFIED);
+                               defender->fortified);
 }
 
 /**************************************************************************
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.159
diff -p -u -r1.159 packets.def
--- common/packets.def  3 Oct 2005 02:50:44 -0000       1.159
+++ common/packets.def  3 Oct 2005 21:35:14 -0000
@@ -717,8 +717,7 @@ PACKET_UNIT_INFO=49; sc,lsend
   CITY homecity;
 
   UINT8 veteran;
-  BOOL ai, paradropped;
-  BOOL transported, done_moving;
+  BOOL ai, paradropped, fortified, transported, done_moving;
 
   UNIT_TYPE type;
   UNIT transported_by; /* Only valid if transported is set. */
@@ -743,7 +742,7 @@ PACKET_UNIT_SHORT_INFO=50; sc,lsend
   UNIT_TYPE type;
 
   UINT8 veteran;
-  BOOL occupied, goes_out_of_sight, transported;
+  BOOL occupied, goes_out_of_sight, transported, fortified;
 
   UINT8 hp, activity;
   UNIT transported_by; /* Only valid if transported is set. */
Index: common/tile.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.c,v
retrieving revision 1.13
diff -p -u -r1.13 tile.c
--- common/tile.c       13 Aug 2005 05:22:55 -0000      1.13
+++ common/tile.c       3 Oct 2005 21:35:14 -0000
@@ -406,13 +406,13 @@ bool tile_apply_activity(struct tile *pt
     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_FORTIFIED_UNUSED:
   case ACTIVITY_LAST:
     /* do nothing - these activities have no effect
        on terrain type or tile specials */
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.251
diff -p -u -r1.251 unit.c
--- common/unit.c       24 Sep 2005 01:28:06 -0000      1.251
+++ common/unit.c       3 Oct 2005 21:35:16 -0000
@@ -431,6 +431,18 @@ bool can_unit_change_homecity(const stru
 }
 
 /**************************************************************************
+  Return TRUE iff the unit can be fortified at its current
+  location (all units may use ACTIVITY_FORTIFYING but only some actually
+  get fortified).
+**************************************************************************/
+bool can_unit_be_fortified(const struct unit *punit)
+{
+  return (is_ground_unit(punit)
+         && punit->transported_by == -1
+         && !unit_flag(punit, F_SETTLERS));
+}
+
+/**************************************************************************
   Returns the speed of a unit doing an activity.  This depends on the
   veteran level and the base move_rate of the unit (regardless of HP or
   effects).  Usually this is just used for settlers but the value is also
@@ -525,8 +537,6 @@ const char *get_activity_text(enum unit_
     return _("Irrigation");
   case ACTIVITY_FORTIFYING:
     return _("Fortifying");
-  case ACTIVITY_FORTIFIED:
-    return _("Fortified");
   case ACTIVITY_FORTRESS:
     return _("Fortress");
   case ACTIVITY_SENTRY:
@@ -546,6 +556,7 @@ const char *get_activity_text(enum unit_
   case ACTIVITY_FALLOUT:
     return _("Fallout");
   case ACTIVITY_UNKNOWN:
+  case ACTIVITY_FORTIFIED_UNUSED:
   case ACTIVITY_PATROL_UNUSED:
   case ACTIVITY_LAST:
     break;
@@ -678,28 +689,6 @@ bool can_unit_bombard(const struct unit 
 }
 
 /**************************************************************************
-  Check if the unit's current activity is actually legal.
-**************************************************************************/
-bool can_unit_continue_current_activity(struct unit *punit)
-{
-  enum unit_activity current = punit->activity;
-  enum tile_special_type target = punit->activity_target;
-  enum unit_activity current2 = 
-              (current == ACTIVITY_FORTIFIED) ? ACTIVITY_FORTIFYING : current;
-  bool result;
-
-  punit->activity = ACTIVITY_IDLE;
-  punit->activity_target = S_LAST;
-
-  result = can_unit_do_activity_targeted(punit, current2, target);
-
-  punit->activity = current;
-  punit->activity_target = target;
-
-  return result;
-}
-
-/**************************************************************************
   Return TRUE iff the unit can do the given untargeted activity at its
   current location.
 
@@ -819,13 +808,9 @@ bool can_unit_do_activity_targeted_at(co
     }
 
   case ACTIVITY_FORTIFYING:
-    return (is_ground_unit(punit)
-           && punit->activity != ACTIVITY_FORTIFIED
-           && !unit_flag(punit, F_SETTLERS)
-           && !is_ocean(ptile->terrain));
-
-  case ACTIVITY_FORTIFIED:
-    return FALSE;
+    /* Don't let units fortify on tiles they will die on. */
+    return (can_unit_survive_at_tile(punit, ptile)
+           || (ptile == punit->tile && punit->transported_by != -1));
 
   case ACTIVITY_FORTRESS:
     return (unit_flag(punit, F_SETTLERS)
@@ -841,12 +826,9 @@ bool can_unit_do_activity_targeted_at(co
            && !is_ocean(ptile->terrain));
 
   case ACTIVITY_SENTRY:
-    if (!can_unit_survive_at_tile(punit, punit->tile)
-       && punit->transported_by == -1) {
-      /* Don't let units sentry on tiles they will die on. */
-      return FALSE;
-    }
-    return TRUE;
+    /* Don't let units sentry on tiles they will die on. */
+    return (can_unit_survive_at_tile(punit, ptile)
+           || (ptile == punit->tile && punit->transported_by != -1));
 
   case ACTIVITY_RAILROAD:
     /* if the tile has road, the terrain must be ok.. */
@@ -911,6 +893,7 @@ bool can_unit_do_activity_targeted_at(co
            && unit_flag(punit, F_TRANSFORM));
 
   case ACTIVITY_PATROL_UNUSED:
+  case ACTIVITY_FORTIFIED_UNUSED:
   case ACTIVITY_LAST:
   case ACTIVITY_UNKNOWN:
     break;
@@ -1036,7 +1019,6 @@ const char *unit_activity_text(const str
    case ACTIVITY_IRRIGATE:
    case ACTIVITY_TRANSFORM:
    case ACTIVITY_FORTIFYING:
-   case ACTIVITY_FORTIFIED:
    case ACTIVITY_AIRBASE:
    case ACTIVITY_FORTRESS:
    case ACTIVITY_SENTRY:
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.147
diff -p -u -r1.147 unit.h
--- common/unit.h       22 Jul 2005 16:18:06 -0000      1.147
+++ common/unit.h       3 Oct 2005 21:35:46 -0000
@@ -26,7 +26,8 @@ struct unit_order;
 /* Changing this enum will break savegame and network compatability. */
 enum unit_activity {
   ACTIVITY_IDLE, ACTIVITY_POLLUTION, ACTIVITY_ROAD, ACTIVITY_MINE,
-  ACTIVITY_IRRIGATE, ACTIVITY_FORTIFIED, ACTIVITY_FORTRESS, ACTIVITY_SENTRY,
+  ACTIVITY_IRRIGATE, ACTIVITY_FORTIFIED_UNUSED,
+  ACTIVITY_FORTRESS, ACTIVITY_SENTRY,
   ACTIVITY_RAILROAD, ACTIVITY_PILLAGE, ACTIVITY_GOTO, ACTIVITY_EXPLORE,
   ACTIVITY_TRANSFORM, ACTIVITY_UNKNOWN, ACTIVITY_AIRBASE, ACTIVITY_FORTIFYING,
   ACTIVITY_FALLOUT,
@@ -154,6 +155,7 @@ struct unit {
   bool debug;
   bool moved;
   bool paradropped;
+  bool fortified;
 
   /* This value is set if the unit is done moving for this turn. This
    * information is used by the client.  The invariant is:
@@ -246,8 +248,8 @@ bool can_unit_unload(const struct unit *
 bool can_unit_paradrop(const struct unit *punit);
 bool can_unit_bombard(const struct unit *punit);
 bool can_unit_change_homecity(const struct unit *punit);
+bool can_unit_be_fortified(const struct unit *punit);
 const char *get_activity_text(enum unit_activity activity);
-bool can_unit_continue_current_activity(struct unit *punit);
 bool can_unit_do_activity(const struct unit *punit,
                          enum unit_activity activity);
 bool can_unit_do_activity_targeted(const struct unit *punit,
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.348
diff -p -u -r1.348 citytools.c
--- server/citytools.c  8 Sep 2005 19:51:23 -0000       1.348
+++ server/citytools.c  3 Oct 2005 21:35:50 -0000
@@ -1028,9 +1028,7 @@ void create_city(struct player *pplayer,
     struct city *home = find_city_by_id(punit->homecity);
 
     /* Catch fortress building, transforming into ocean, etc. */
-    if (!can_unit_continue_current_activity(punit)) {
-      handle_unit_activity_request(punit, ACTIVITY_IDLE);
-    }
+    check_unit_activities(punit, FALSE);
 
     /* Update happiness (the unit may no longer cause unrest). */
     if (home) {
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.177
diff -p -u -r1.177 maphand.c
--- server/maphand.c    15 Sep 2005 17:34:40 -0000      1.177
+++ server/maphand.c    3 Oct 2005 21:35:54 -0000
@@ -236,9 +236,7 @@ void global_warming(int effect)
       check_terrain_change(ptile, old);
       update_tile_knowledge(ptile);
       unit_list_iterate(ptile->units, punit) {
-       if (!can_unit_continue_current_activity(punit)) {
-         handle_unit_activity_request(punit, ACTIVITY_IDLE);
-       }
+       check_unit_activities(punit, FALSE);
       } unit_list_iterate_end;
     } else if (old == new) {
       /* This counts toward warming although nothing is changed. */
@@ -280,9 +278,7 @@ void nuclear_winter(int effect)
       check_terrain_change(ptile, old);
       update_tile_knowledge(ptile);
       unit_list_iterate(ptile->units, punit) {
-       if (!can_unit_continue_current_activity(punit)) {
-         handle_unit_activity_request(punit, ACTIVITY_IDLE);
-       }
+       check_unit_activities(punit, FALSE);
       } unit_list_iterate_end;
     } else if (old == new) {
       /* This counts toward winter although nothing is changed. */
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.75
diff -p -u -r1.75 sanitycheck.c
--- server/sanitycheck.c        5 Sep 2005 15:55:47 -0000       1.75
+++ server/sanitycheck.c        3 Oct 2005 21:35:54 -0000
@@ -350,13 +350,7 @@ static void check_units(void) {
        SANITY_CHECK(city_owner(pcity) == pplayer);
       }
 
-      if (!can_unit_continue_current_activity(punit)) {
-       freelog(LOG_ERROR, "%s at %d,%d (%s) has activity %s, "
-               "which it can't continue!",
-               unit_type(punit)->name,
-               TILE_XY(ptile), tile_get_info_text(ptile),
-               get_activity_text(punit->activity));
-      }
+      check_unit_activities(punit, TRUE);
 
       pcity = tile_get_city(ptile);
       if (pcity) {
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.279
diff -p -u -r1.279 savegame.c
--- server/savegame.c   3 Oct 2005 02:50:47 -0000       1.279
+++ server/savegame.c   3 Oct 2005 21:35:58 -0000
@@ -399,8 +399,6 @@ static char activity2char(enum unit_acti
     return 'm';
   case ACTIVITY_IRRIGATE:
     return 'i';
-  case ACTIVITY_FORTIFIED:
-    return 'f';
   case ACTIVITY_FORTRESS:
     return 't';
   case ACTIVITY_SENTRY:
@@ -423,6 +421,7 @@ static char activity2char(enum unit_acti
     return 'u';
   case ACTIVITY_UNKNOWN:
   case ACTIVITY_PATROL_UNUSED:
+  case ACTIVITY_FORTIFIED_UNUSED:
     return '?';
   case ACTIVITY_LAST:
     break;
@@ -1395,6 +1394,7 @@ static void load_player_units(struct pla
     int nat_x, nat_y;
     const char* type_name;
     struct unit_type *type;
+    bool fortified = FALSE;
     
     type_name = secfile_lookup_str_default(file, NULL, 
                                            "player%d.u%d.type_by_name",
@@ -1452,6 +1452,9 @@ static void load_player_units(struct pla
        * Old client-side patrol units lose their patrol routes and are put
        * into idle mode. */
       activity = ACTIVITY_IDLE;
+    } else if (activity == ACTIVITY_FORTIFIED_UNUSED) {
+      activity = ACTIVITY_FORTIFYING;
+      fortified = TRUE;
     }
     set_unit_activity(punit, activity);
 
@@ -1505,6 +1508,9 @@ static void load_player_units(struct pla
     punit->paradropped
       = secfile_lookup_bool_default(file, FALSE,
                                    "player%d.u%d.paradropped", plrno, i);
+    punit->fortified
+      = secfile_lookup_bool_default(file, fortified,
+                                   "player%d.u%d.fortified", plrno, i);
     punit->transported_by
       = secfile_lookup_int_default(file, -1, "player%d.u%d.transported_by",
                                   plrno, i);
@@ -3661,10 +3667,7 @@ void game_load(struct section_file *file
     /* Make sure everything is consistent. */
     players_iterate(pplayer) {
       unit_list_iterate(pplayer->units, punit) {
-       if (!can_unit_continue_current_activity(punit)) {
-         freelog(LOG_ERROR, "ERROR: Unit doing illegal activity in savegame!");
-         punit->activity = ACTIVITY_IDLE;
-       }
+       check_unit_activities(punit, TRUE);
       } unit_list_iterate_end;
 
       city_list_iterate(pplayer->cities, pcity) {
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.387
diff -p -u -r1.387 unittools.c
--- server/unittools.c  15 Sep 2005 17:41:28 -0000      1.387
+++ server/unittools.c  3 Oct 2005 21:36:07 -0000
@@ -554,8 +554,9 @@ static int hp_gain_coord(struct unit *pu
     hp++;
   }
 
-  if(punit->activity==ACTIVITY_FORTIFIED)
+  if (punit->fortified) {
     hp++;
+  }
   
   return hp;
 }
@@ -624,7 +625,7 @@ static void update_unit_activity(struct 
   struct tile *ptile = punit->tile;
   bool check_adjacent_units = FALSE;
   
-  if (activity != ACTIVITY_IDLE && activity != ACTIVITY_FORTIFIED
+  if (activity != ACTIVITY_IDLE
       && activity != ACTIVITY_GOTO && activity != ACTIVITY_EXPLORE) {
     /*  We don't need the activity_count for the above */
     punit->activity_count += get_activity_rate_this_turn(punit);
@@ -837,17 +838,15 @@ static void update_unit_activity(struct 
   if (check_adjacent_units) {
     adjc_iterate(ptile, ptile2) {
       unit_list_iterate(ptile2->units, punit2) {
-        if (!can_unit_continue_current_activity(punit2)) {
-          handle_unit_activity_request(punit2, ACTIVITY_IDLE);
-        }
+       check_unit_activities(punit2, FALSE);
       } unit_list_iterate_end;
     } adjc_iterate_end;
   }
 
-  if (activity==ACTIVITY_FORTIFYING) {
-    if (punit->activity_count >= 1) {
-      set_unit_activity(punit,ACTIVITY_FORTIFIED);
-    }
+  if (activity==ACTIVITY_FORTIFYING
+      && punit->activity_count >= 1
+      && can_unit_be_fortified(punit)) {
+    punit->fortified = TRUE;
   }
 
   if (activity==ACTIVITY_GOTO) {
@@ -873,10 +872,7 @@ UNIT_LOG(LOG_ERROR, punit, "using old go
   }
 
   unit_list_iterate(ptile->units, punit2) {
-    if (!can_unit_continue_current_activity(punit2))
-    {
-      handle_unit_activity_request(punit2, ACTIVITY_IDLE);
-    }
+    check_unit_activities(punit2, FALSE);
   } unit_list_iterate_end;
 }
 
@@ -1017,8 +1013,8 @@ static void place_partisans(struct city 
     struct unit *punit;
 
     punit = create_unit(city_owner(pcity), ptile, u_type, 0, 0, -1);
-    if (can_unit_do_activity(punit, ACTIVITY_FORTIFYING)) {
-      punit->activity = ACTIVITY_FORTIFIED; /* yes; directly fortified */
+    if (can_unit_be_fortified(punit)) {
+      punit->fortified = TRUE; /* yes; directly fortified */
       send_unit_info(NULL, punit);
     }
   }
@@ -1149,6 +1145,51 @@ void bounce_unit(struct unit *punit, boo
   }
 }
 
+/**************************************************************************
+  Check if the unit's current activity is actually legal.
+**************************************************************************/
+static bool can_unit_continue_current_activity(struct unit *punit)
+{
+  const enum unit_activity current = punit->activity;
+  const enum tile_special_type target = punit->activity_target;
+  bool result;
+
+  punit->activity = ACTIVITY_IDLE;
+  punit->activity_target = S_LAST;
+
+  result = can_unit_do_activity_targeted(punit, current, target);
+
+  punit->activity = current;
+  punit->activity_target = target;
+
+  return result;
+}
+
+/**************************************************************************
+  Check the unit for activities it cannot continue.
+**************************************************************************/
+void check_unit_activities(struct unit *punit, bool verbose)
+{
+  if (!can_unit_continue_current_activity(punit)) {
+    handle_unit_activity_request(punit, ACTIVITY_IDLE);
+    if (verbose) {
+      freelog(LOG_ERROR, "%s at %d,%d (%s) has activity %s, "
+             "which it can't continue!",
+             punit->type->name,
+             TILE_XY(punit->tile), tile_get_info_text(punit->tile),
+             get_activity_text(punit->activity));
+    }
+  }
+  if (punit->fortified && !can_unit_be_fortified(punit)) {
+    if (verbose) {
+      freelog(LOG_ERROR, "%s at %d,%d (%s) cannot stay fortified!",
+             punit->type->name, TILE_XY(punit->tile),
+             tile_get_info_text(punit->tile));
+    }
+    punit->fortified = FALSE;
+    send_unit_info(NULL, punit);
+  }
+}
 
 /**************************************************************************
   Throw pplayer's units from non allied cities
@@ -1823,6 +1864,7 @@ void package_unit(struct unit *punit, st
   }
   packet->activity_target = punit->activity_target;
   packet->paradropped = punit->paradropped;
+  packet->fortified = punit->fortified;
   packet->done_moving = punit->done_moving;
   if (punit->transported_by == -1) {
     packet->transported = FALSE;
@@ -1889,6 +1931,7 @@ void package_short_unit(struct unit *pun
   } else {
     packet->activity = punit->activity;
   }
+  packet->fortified = punit->fortified;
 
   /* Transported_by information is sent to the client even for units that
    * aren't fully known.  Note that for non-allied players, any transported
@@ -2378,6 +2421,21 @@ static bool unit_enter_hut(struct unit *
   return ok;
 }
 
+/**************************************************************************
+Check if the units activity is legal for a move , and reset it if it isn't.
+**************************************************************************/
+static void check_unit_activity_for_move(struct unit *punit)
+{
+  if (punit->activity != ACTIVITY_IDLE
+      && punit->activity != ACTIVITY_SENTRY
+      && punit->activity != ACTIVITY_FORTIFYING
+      && punit->activity != ACTIVITY_EXPLORE
+      && punit->activity != ACTIVITY_GOTO) {
+    set_unit_activity(punit, ACTIVITY_IDLE);
+  }
+  punit->fortified = FALSE;
+}
+
 /****************************************************************************
   Put the unit onto the transporter.  Don't do any other work.
 ****************************************************************************/
@@ -2386,6 +2444,7 @@ static void put_unit_onto_transporter(st
   /* In the future we may updated ptrans->occupancy. */
   assert(punit->transported_by == -1);
   punit->transported_by = ptrans->id;
+  check_unit_activity_for_move(punit);
 }
 
 /****************************************************************************
@@ -2705,19 +2764,6 @@ static void handle_unit_move_consequence
 }
 
 /**************************************************************************
-Check if the units activity is legal for a move , and reset it if it isn't.
-**************************************************************************/
-static void check_unit_activity(struct unit *punit)
-{
-  if (punit->activity != ACTIVITY_IDLE
-      && punit->activity != ACTIVITY_SENTRY
-      && punit->activity != ACTIVITY_EXPLORE
-      && punit->activity != ACTIVITY_GOTO) {
-    set_unit_activity(punit, ACTIVITY_IDLE);
-  }
-}
-
-/**************************************************************************
   Moves a unit. No checks whatsoever! This is meant as a practical 
   function for other functions, like do_airline, which do the checking 
   themselves.
@@ -2760,7 +2806,7 @@ bool move_unit(struct unit *punit, struc
       pcargo->tile = pdesttile;
 
       unit_list_prepend(pdesttile->units, pcargo);
-      check_unit_activity(pcargo);
+      check_unit_activity_for_move(pcargo);
       send_unit_info_to_onlookers(NULL, pcargo, psrctile, FALSE);
       fog_area(unit_owner(pcargo), psrctile, unit_type(pcargo)->vision_range);
       handle_unit_move_consequences(pcargo, psrctile, pdesttile);
@@ -2795,7 +2841,7 @@ bool move_unit(struct unit *punit, struc
     punit->done_moving = TRUE;
   }
   unit_list_prepend(pdesttile->units, punit);
-  check_unit_activity(punit);
+  check_unit_activity_for_move(punit);
 
   /*
    * Transporter info should be send first becouse this allow us get right
Index: server/unittools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.h,v
retrieving revision 1.77
diff -p -u -r1.77 unittools.h
--- server/unittools.h  15 Sep 2005 17:41:28 -0000      1.77
+++ server/unittools.h  3 Oct 2005 21:36:07 -0000
@@ -50,6 +50,7 @@ int get_watchtower_vision(struct unit *p
 bool unit_profits_of_watchtower(struct unit *punit);
 void pay_for_units(struct player *pplayer, struct city *pcity);
 void bounce_unit(struct unit *punit, bool verbose);
+void check_unit_activities(struct unit *punit, bool verbose);
 
 /* creation/deletion/upgrading */
 void upgrade_unit(struct unit *punit, struct unit_type *to_unit,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#14175) fortification rewrite, Jason Short <=