Author: sveinung
Date: Thu Jun  9 12:06:43 2016
New Revision: 32809

URL: http://svn.gna.org/viewcvs/freeciv?rev=32809&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:
    branches/S2_6/ai/default/aiair.c
    branches/S2_6/ai/default/aitools.c
    branches/S2_6/server/advisors/advgoto.c
    branches/S2_6/server/barbarian.c
    branches/S2_6/server/citytools.c
    branches/S2_6/server/diplomats.c
    branches/S2_6/server/unithand.c
    branches/S2_6/server/unittools.c

Modified: branches/S2_6/ai/default/aiair.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aiair.c?rev=32809&r1=32808&r2=32809&view=diff
==============================================================================
--- branches/S2_6/ai/default/aiair.c    (original)
+++ branches/S2_6/ai/default/aiair.c    Thu Jun  9 12:06:43 2016
@@ -393,7 +393,8 @@
       /* We could use ai_military_findvictim here, but I don't trust it... */
       unit_activity_handling(punit, ACTIVITY_IDLE);
       if (is_tiles_adjacent(unit_tile(punit), dst_tile)) {
-        (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))) {
       log_debug("%s will fly to (%i, %i) (%s) to fight there",

Modified: branches/S2_6/ai/default/aitools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aitools.c?rev=32809&r1=32808&r2=32809&view=diff
==============================================================================
--- branches/S2_6/ai/default/aitools.c  (original)
+++ branches/S2_6/ai/default/aitools.c  Thu Jun  9 12:06:43 2016
@@ -839,7 +839,8 @@
   fc_assert_ret_val(is_tiles_adjacent(unit_tile(punit), ptile), TRUE);
 
   unit_activity_handling(punit, ACTIVITY_IDLE);
-  (void) unit_move_handling(punit, ptile, FALSE, FALSE, NULL);
+  /* Regular attack. */
+  (void) unit_move_handling(punit, ptile, FALSE, TRUE, NULL);
   alive = (game_unit_by_number(sanity) != NULL);
 
   if (alive && same_pos(ptile, unit_tile(punit))
@@ -921,6 +922,7 @@
 
   /* go */
   unit_activity_handling(punit, ACTIVITY_IDLE);
+  /* Move */
   (void) unit_move_handling(punit, ptile, FALSE, TRUE, NULL);
 
   /* handle the results */

Modified: branches/S2_6/server/advisors/advgoto.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/advisors/advgoto.c?rev=32809&r1=32808&r2=32809&view=diff
==============================================================================
--- branches/S2_6/server/advisors/advgoto.c     (original)
+++ branches/S2_6/server/advisors/advgoto.c     Thu Jun  9 12:06:43 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: branches/S2_6/server/barbarian.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/barbarian.c?rev=32809&r1=32808&r2=32809&view=diff
==============================================================================
--- branches/S2_6/server/barbarian.c    (original)
+++ branches/S2_6/server/barbarian.c    Thu Jun  9 12:06:43 2016
@@ -325,7 +325,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;
@@ -368,7 +370,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;
@@ -389,7 +392,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: branches/S2_6/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/citytools.c?rev=32809&r1=32808&r2=32809&view=diff
==============================================================================
--- branches/S2_6/server/citytools.c    (original)
+++ branches/S2_6/server/citytools.c    Thu Jun  9 12:06:43 2016
@@ -1631,6 +1631,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: branches/S2_6/server/diplomats.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/diplomats.c?rev=32809&r1=32808&r2=32809&view=diff
==============================================================================
--- branches/S2_6/server/diplomats.c    (original)
+++ branches/S2_6/server/diplomats.c    Thu Jun  9 12:06:43 2016
@@ -519,7 +519,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: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=32809&r1=32808&r2=32809&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Thu Jun  9 12:06:43 2016
@@ -2217,7 +2217,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;
@@ -2340,14 +2341,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);
@@ -2379,17 +2384,17 @@
    * 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))) {
     struct unit *tunit = tgt_unit(punit, pdesttile);
     struct city *tcity = tgt_city(punit, pdesttile);
 
     if ((0 < unit_list_size(pdesttile->units) || pcity)
-        && !(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
@@ -3160,7 +3165,8 @@
   }
 
   if (moves) {
-    unit_move_handling(pcargo, ttile, FALSE, FALSE, ptrans);
+    /* Pre load move. */
+    unit_move_handling(pcargo, ttile, FALSE, TRUE, ptrans);
     return;
   }
 

Modified: branches/S2_6/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.c?rev=32809&r1=32808&r2=32809&view=diff
==============================================================================
--- branches/S2_6/server/unittools.c    (original)
+++ branches/S2_6/server/unittools.c    Thu Jun  9 12:06:43 2016
@@ -3035,7 +3035,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