Author: sveinung
Date: Thu Jun  9 12:03:23 2016
New Revision: 32806

URL: http://svn.gna.org/viewcvs/freeciv?rev=32806&view=rev
Log:
Moving while able to act isn't Diplomat only.

The function unit_move_handling() can result in the server asking the client
to choose what action to perform to the destination tile. A parameter allows
the caller to specify that the unit should move even if it can act.

Traditionally the "move rather than ask what action to perform" parameter
was used to tell a Diplomat to move to an allied city instead of performing
a diplomatic action against it.

The "move rather than ask for action clarification" parameter was therefore
called move_diplomat_city. Rename it to move_do_not_act.

Another consequence of the "act vs clarify" parameter being diplomat only
was that callers that didn't expect to handle a unit capable of diplomatic
actions didn't care what value it had. Change the move_do_not_act argument
of unit_move_handling() callers so it reflects what the call intends to
achieve.

Reported by Marko Lindqvist <cazfi>

See bug #24665

Modified:
    trunk/ai/default/aiair.c
    trunk/ai/default/aitools.c
    trunk/server/advisors/advgoto.c
    trunk/server/barbarian.c
    trunk/server/citytools.c
    trunk/server/diplomats.c
    trunk/server/unithand.c
    trunk/server/unittools.c

Modified: trunk/ai/default/aiair.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aiair.c?rev=32806&r1=32805&r2=32806&view=diff
==============================================================================
--- trunk/ai/default/aiair.c    (original)
+++ trunk/ai/default/aiair.c    Thu Jun  9 12:03:23 2016
@@ -412,7 +412,8 @@
                                 punit->id, tile_index(dst_tile),
                                 0, "", ACTION_NUKE);
         } else {
-          (void) unit_move_handling(punit, dst_tile, TRUE, FALSE, NULL);
+          /* Regular attack. */
+          (void) unit_move_handling(punit, dst_tile, TRUE, TRUE, NULL);
         }
       }
     } else if ((dst_tile = dai_find_strategic_airbase(ait, punit, &path))) {

Modified: trunk/ai/default/aitools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aitools.c?rev=32806&r1=32805&r2=32806&view=diff
==============================================================================
--- trunk/ai/default/aitools.c  (original)
+++ trunk/ai/default/aitools.c  Thu Jun  9 12:03:23 2016
@@ -860,7 +860,7 @@
                           0, "", ACTION_NUKE);
   } else {
     /* Regular attack. */
-    (void) unit_move_handling(punit, ptile, FALSE, FALSE, NULL);
+    (void) unit_move_handling(punit, ptile, FALSE, TRUE, NULL);
   }
   alive = (game_unit_by_number(sanity) != NULL);
 
@@ -943,6 +943,7 @@
 
   /* go */
   unit_activity_handling(punit, ACTIVITY_IDLE);
+  /* Move */
   (void) unit_move_handling(punit, ptile, FALSE, TRUE, NULL);
 
   /* handle the results */

Modified: trunk/server/advisors/advgoto.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/advisors/advgoto.c?rev=32806&r1=32805&r2=32806&view=diff
==============================================================================
--- trunk/server/advisors/advgoto.c     (original)
+++ trunk/server/advisors/advgoto.c     Thu Jun  9 12:03:23 2016
@@ -149,6 +149,7 @@
 
   /* go */
   unit_activity_handling(punit, ACTIVITY_IDLE);
+  /* Move */
   (void) unit_move_handling(punit, ptile, FALSE, TRUE, NULL);
 
   return TRUE;

Modified: trunk/server/barbarian.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/barbarian.c?rev=32806&r1=32805&r2=32806&view=diff
==============================================================================
--- trunk/server/barbarian.c    (original)
+++ trunk/server/barbarian.c    Thu Jun  9 12:03:23 2016
@@ -339,7 +339,9 @@
           int rdir = random_unchecked_direction(land_tiles - checked_count, 
checked);
 
           if (unit_can_move_to_tile(punit2, dir_tiles[rdir], TRUE)) {
-            (void) unit_move_handling(punit2, dir_tiles[rdir], TRUE, FALSE, 
NULL);
+            /* Move */
+            (void) unit_move_handling(punit2, dir_tiles[rdir],
+                                      TRUE, TRUE, NULL);
             log_debug("Moved barbarian unit from (%d, %d) to (%d, %d)", 
                       TILE_XY(ptile), TILE_XY(dir_tiles[rdir]));
             dest_found = TRUE;
@@ -382,7 +384,8 @@
         unit_list_iterate_safe((ptile)->units, punit2) {
           if (unit_owner(punit2) == barbarians) {
             if (unit_can_move_to_tile(punit2, btile, TRUE)) {
-              (void) unit_move_handling(punit2, btile, TRUE, FALSE, NULL);
+              /* Load */
+              (void) unit_move_handling(punit2, btile, TRUE, TRUE, NULL);
             }
           }
         } unit_list_iterate_safe_end;
@@ -403,7 +406,9 @@
             rdir = random_unchecked_direction(land_tiles - checked_count, 
checked);
 
             if (unit_can_move_to_tile(punit2, dir_tiles[rdir], TRUE)) {
-              (void) unit_move_handling(punit2, dir_tiles[rdir], TRUE, FALSE, 
NULL);
+              /* Move */
+              (void) unit_move_handling(punit2, dir_tiles[rdir],
+                                        TRUE, TRUE, NULL);
               dest_found = TRUE;
             }
 

Modified: trunk/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.c?rev=32806&r1=32805&r2=32806&view=diff
==============================================================================
--- trunk/server/citytools.c    (original)
+++ trunk/server/citytools.c    Thu Jun  9 12:03:23 2016
@@ -1637,6 +1637,7 @@
     adjc_iterate(pcenter, tile1) {
       if (!moved && is_native_tile(punittype, tile1)) {
         if (adv_could_unit_move_to_tile(punit, tile1) == 1) {
+          /* Move */
           moved = unit_move_handling(punit, tile1, FALSE, TRUE, NULL);
           if (moved) {
             notify_player(unit_owner(punit), tile1,

Modified: trunk/server/diplomats.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/diplomats.c?rev=32806&r1=32805&r2=32806&view=diff
==============================================================================
--- trunk/server/diplomats.c    (original)
+++ trunk/server/diplomats.c    Thu Jun  9 12:03:23 2016
@@ -564,7 +564,8 @@
   /* Try to move the briber onto the victim's square unless its a city or
    * have other units. */
   if (NULL == pcity && unit_list_size(unit_tile(pvictim)->units) < 2
-      && !unit_move_handling(pdiplomat, victim_tile, FALSE, FALSE, NULL)
+      /* Post bribe move. */
+      && !unit_move_handling(pdiplomat, victim_tile, FALSE, TRUE, NULL)
       /* May have died while trying to move. */
       && unit_is_alive(diplomat_id)) {
     pdiplomat->moves_left = 0;

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=32806&r1=32805&r2=32806&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Thu Jun  9 12:03:23 2016
@@ -3117,7 +3117,8 @@
     int full_moves = unit_move_rate(punit);
 
     punit->moves_left = full_moves;
-    if (unit_move_handling(punit, def_tile, FALSE, FALSE, NULL)) {
+    /* Post attack occupy move. */
+    if (unit_move_handling(punit, def_tile, FALSE, TRUE, NULL)) {
       punit->moves_left = old_moves - (full_moves - punit->moves_left);
       if (punit->moves_left < 0) {
        punit->moves_left = 0;
@@ -3240,14 +3241,18 @@
   done in some special cases (moving barbarians out of initial hut).
   Should normally be FALSE.
 
-  'move_diplomat_city' is another special case which should normally be
-  FALSE.  If TRUE, try to move diplomat (or spy) into city (should be
-  allied) instead of telling client to popup diplomat/spy dialog.
+  'move_do_not_act' is another special case which should normally be
+  FALSE.  If TRUE any enabler controlled actions punit can perform to
+  pdesttile it self or something located at it will be ignored. If FALSE
+  the system will check if punit can perform any enabler controlled action
+  to pdesttile. If it can the player will be asked to choose what to do. If
+  it can't and punit is unable to move (or perform another non enabler
+  controlled action) to pdesttile the game will try to explain why.
 
   FIXME: This function needs a good cleaning.
 **************************************************************************/
 bool unit_move_handling(struct unit *punit, struct tile *pdesttile,
-                        bool igzoc, bool move_diplomat_city,
+                        bool igzoc, bool move_do_not_act,
                         struct unit *embark_to)
 {
   struct player *pplayer = unit_owner(punit);
@@ -3279,7 +3284,7 @@
    * If the AI has used a goto to send an actor to a target do not
    * pop up a dialog in the client.
    * For tiles occupied by allied cities or units, keep moving if
-   * move_diplomat_city tells us to, or if the unit is on goto and the tile
+   * move_do_not_act tells us to, or if the unit is on goto and the tile
    * is not the final destination. */
   if (utype_may_act_at_all(unit_type_get(punit))) {
     bool can_not_move = !unit_can_move_to_tile(punit, pdesttile, igzoc);
@@ -3291,10 +3296,10 @@
      * unit or units target exists at the destination tile. A tile target
      * will only trigger the pop up if it may be legal. */
     if ((0 < unit_list_size(pdesttile->units) || pcity || ttile)
-        && !(move_diplomat_city
+        && !(move_do_not_act
              && may_non_act_move(punit, pcity, pdesttile, igzoc))) {
       /* A target (unit or city) exists at the tile. If a target is an ally
-       * it still looks like a target since move_diplomat_city isn't set.
+       * it still looks like a target since move_do_not_act isn't set.
        * Assume that the intention is to do an action. */
 
       /* If a tcity or a tunit exists it must be possible to act against it
@@ -4121,7 +4126,8 @@
   }
 
   if (moves) {
-    unit_move_handling(pcargo, ttile, FALSE, FALSE, ptrans);
+    /* Pre load move. */
+    unit_move_handling(pcargo, ttile, FALSE, TRUE, ptrans);
     return;
   }
 

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=32806&r1=32805&r2=32806&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Thu Jun  9 12:03:23 2016
@@ -3055,7 +3055,9 @@
 #endif
 
       unit_activity_handling(penemy, ACTIVITY_IDLE);
-      (void) unit_move_handling(penemy, unit_tile(punit), FALSE, FALSE, NULL);
+      /* Attack */
+      (void) unit_move_handling(penemy, unit_tile(punit),
+                                FALSE, TRUE, NULL);
     } else {
 #ifdef REALLY_DEBUG_THIS
       log_test("!AA %s -> %s (%d,%d) %.2f > %.2f && > %.2f",


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to