Author: sveinung
Date: Thu Nov  5 18:57:33 2015
New Revision: 30416

URL: http://svn.gna.org/viewcvs/freeciv?rev=30416&view=rev
Log:
All target finders to actiontools.c

Change the target finders against a tile and against tile units from bool
functions to functions that returns the tile if it is a target. This makes
them consistent with the target finders for city and unit targets. Move
them to actiontools.c.

See patch #6529

Modified:
    trunk/server/actiontools.c
    trunk/server/actiontools.h
    trunk/server/unithand.c

Modified: trunk/server/actiontools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/actiontools.c?rev=30416&r1=30415&r2=30416&view=diff
==============================================================================
--- trunk/server/actiontools.c  (original)
+++ trunk/server/actiontools.c  Thu Nov  5 18:57:33 2015
@@ -660,3 +660,93 @@
 
   return NULL;
 }
+
+/**************************************************************************
+  Returns the tile iff it, from the point of view of the owner of the
+  actor unit, looks like each unit on it is an ATK_UNITS target for the
+  actor unit.
+
+  Returns NULL if the player knows that the actor unit can't do any
+  ATK_UNITS action to all units at the target tile.
+
+  If the owner of the actor unit don't have the knowledge needed to know
+  for sure if the unit can act the tile will be returned.
+
+  If the only action(s) that can be performed against a target has the
+  rare_pop_up property the target will only be considered valid if the
+  accept_all_actions argument is TRUE.
+**************************************************************************/
+struct tile *action_tgt_tile_units(struct unit *actor,
+                                   struct tile *target,
+                                   bool accept_all_actions)
+{
+  if (actor == NULL || target == NULL) {
+    /* Can't do any actions if actor or target are missing. */
+    return NULL;
+  }
+
+  action_iterate(act) {
+    if (!(action_get_actor_kind(act) == AAK_UNIT
+        && action_get_target_kind(act) == ATK_UNITS)) {
+      /* Not a relevant action. */
+      continue;
+    }
+
+    if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
+      /* Not relevant since not accepted here. */
+      continue;
+    }
+
+    if (action_prob_possible(action_prob_vs_units(actor, act, target))) {
+      /* One action is enough. */
+      return target;
+    }
+  } action_iterate_end;
+
+  return NULL;
+}
+
+/**************************************************************************
+  Returns the tile iff it, from the point of view of the owner of the
+  actor unit, looks like a target tile.
+
+  Returns NULL if the player knows that the actor unit can't do any
+  ATK_TILE action to the tile.
+
+  If the owner of the actor unit doesn't have the knowledge needed to know
+  for sure if the unit can act the tile will be returned.
+
+  If the only action(s) that can be performed against a target has the
+  rare_pop_up property the target will only be considered valid if the
+  accept_all_actions argument is TRUE.
+**************************************************************************/
+struct tile *action_tgt_tile(struct unit *actor,
+                             struct tile *target,
+                             bool accept_all_actions)
+{
+  if (actor == NULL || target == NULL) {
+    /* Can't do any actions if actor or target are missing. */
+    return NULL;
+  }
+
+  action_iterate(act) {
+    if (!(action_get_actor_kind(act) == AAK_UNIT
+        && action_get_target_kind(act) == ATK_TILE)) {
+      /* Not a relevant action. */
+      continue;
+    }
+
+    if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
+      /* Not relevant since not accepted here. */
+      continue;
+    }
+
+    if (action_prob_possible(action_prob_vs_tile(actor, act, target))) {
+      /* The actor unit may be able to do this action to the target
+       * tile. */
+      return target;
+    }
+  } action_iterate_end;
+
+  return NULL;
+}

Modified: trunk/server/actiontools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/actiontools.h?rev=30416&r1=30415&r2=30416&view=diff
==============================================================================
--- trunk/server/actiontools.h  (original)
+++ trunk/server/actiontools.h  Thu Nov  5 18:57:33 2015
@@ -36,4 +36,12 @@
 struct unit *action_tgt_unit(struct unit *actor, struct tile *target_tile,
                              bool accept_all_actions);
 
+struct tile *action_tgt_tile_units(struct unit *actor,
+                                   struct tile *target_tile,
+                                   bool accept_all_actions);
+
+struct tile *action_tgt_tile(struct unit *actor,
+                             struct tile *target_tile,
+                             bool accept_all_actions);
+
 #endif /* FC__ACTIONTOOLS_H */

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=30416&r1=30415&r2=30416&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Thu Nov  5 18:57:33 2015
@@ -491,91 +491,6 @@
     /* Attack. Includes nuking. */
     return TRUE;
   }
-
-  return FALSE;
-}
-
-/**************************************************************************
-  Returns TRUE iff, from the point of view of the owner of the actor unit,
-  it looks like the actor unit may be able to do any action to all units at
-  the target tile.
-
-  If the owner of the actor unit don't have the knowledge needed to know
-  for sure if the unit can act TRUE will be returned.
-
-  If the only action(s) that can be performed against a target has the
-  rare_pop_up property the target will only be considered valid if the
-  accept_all_actions argument is TRUE.
-**************************************************************************/
-static bool may_unit_act_vs_tile_units(struct unit *actor,
-                                       struct tile *target,
-                                       bool accept_all_actions)
-{
-  if (actor == NULL || target == NULL) {
-    /* Can't do any actions if actor or target are missing. */
-    return FALSE;
-  }
-
-  action_iterate(act) {
-    if (!(action_get_actor_kind(act) == AAK_UNIT
-        && action_get_target_kind(act) == ATK_UNITS)) {
-      /* Not a relevant action. */
-      continue;
-    }
-
-    if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
-      /* Not relevant since not accepted here. */
-      continue;
-    }
-
-    if (action_prob_possible(action_prob_vs_units(actor, act, target))) {
-      /* One action is enough. */
-      return TRUE;
-    }
-  } action_iterate_end;
-
-  return FALSE;
-}
-
-/**************************************************************************
-  Returns TRUE iff, from the point of view of the owner of the actor unit,
-  it looks like the actor unit may be able to do any action to the target
-  tile.
-
-  If the owner of the actor unit don't have the knowledge needed to know
-  for sure if the unit can act TRUE will be returned.
-
-  If the only action(s) that can be performed against a target has the
-  rare_pop_up property the target will only be considered valid if the
-  accept_all_actions argument is TRUE.
-**************************************************************************/
-static bool may_unit_act_vs_tile(struct unit *actor,
-                                 struct tile *target,
-                                 bool accept_all_actions)
-{
-  if (actor == NULL || target == NULL) {
-    /* Can't do any actions if actor or target are missing. */
-    return FALSE;
-  }
-
-  action_iterate(act) {
-    if (!(action_get_actor_kind(act) == AAK_UNIT
-        && action_get_target_kind(act) == ATK_TILE)) {
-      /* Not a relevant action. */
-      continue;
-    }
-
-    if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
-      /* Not relevant since not accepted here. */
-      continue;
-    }
-
-    if (action_prob_possible(action_prob_vs_tile(actor, act, target))) {
-      /* The actor unit may be able to do this action to the target
-       * tile. */
-      return TRUE;
-    }
-  } action_iterate_end;
 
   return FALSE;
 }
@@ -3017,12 +2932,12 @@
     bool can_not_move = !unit_can_move_to_tile(punit, pdesttile, igzoc);
     struct unit *tunit = action_tgt_unit(punit, pdesttile, can_not_move);
     struct city *tcity = action_tgt_city(punit, pdesttile, can_not_move);
-    bool ttile_ok = may_unit_act_vs_tile(punit, pdesttile, can_not_move);
+    struct tile *ttile = action_tgt_tile(punit, pdesttile, can_not_move);
 
     /* Consider to pop up the action selection dialog if a potential city,
      * 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_ok)
+    if ((0 < unit_list_size(pdesttile->units) || pcity || ttile)
         && !(move_diplomat_city
              && may_non_act_move(punit, pcity, pdesttile, igzoc))) {
       /* A target (unit or city) exists at the tile. If a target is an ally
@@ -3033,8 +2948,8 @@
        * since action_tgt_city() or action_tgt_unit() wouldn't have
        * targeted it otherwise. */
       if (tcity || tunit
-          || may_unit_act_vs_tile_units(punit, pdesttile, can_not_move)
-          || ttile_ok) {
+          || action_tgt_tile_units(punit, pdesttile, can_not_move)
+          || ttile) {
         if (is_ai(pplayer)) {
           return FALSE;
         }


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

Reply via email to