Author: sveinung
Date: Sun Sep  6 13:04:54 2015
New Revision: 29788

URL: http://svn.gna.org/viewcvs/freeciv?rev=29788&view=rev
Log:
Make actor unit type check clearer

The function is_actor_unit() may give the impression that the check is for
the unit rather than the unit type. It is easy to ignore the unit type part
of the name is_actor_unit_type() (as opposed to unit). Replace the both with
utype_may_act_at_all()

See patch #6321

Modified:
    trunk/ai/default/aitools.c
    trunk/ai/default/aiunit.c
    trunk/client/climisc.c
    trunk/client/control.c
    trunk/client/goto.c
    trunk/client/packhand.c
    trunk/common/aicore/pf_tools.c
    trunk/common/city.c
    trunk/common/unit.c
    trunk/common/unit.h
    trunk/common/unittype.c
    trunk/common/unittype.h
    trunk/server/unithand.c

Modified: trunk/ai/default/aitools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aitools.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/ai/default/aitools.c  (original)
+++ trunk/ai/default/aitools.c  Sun Sep  6 13:04:54 2015
@@ -573,7 +573,7 @@
   } else if (unit_is_cityfounder(punit)) {
     /* Short path */
     parameter->get_TB = no_fights;
-  } else if (is_actor_unit(punit)
+  } else if (utype_may_act_at_all(unit_type(punit))
              && !utype_acts_hostile(unit_type(punit))) {
     /* While the AI currently won't establish a trade route to a non ally
      * it will establish an embassy. */

Modified: trunk/ai/default/aiunit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aiunit.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/ai/default/aiunit.c   (original)
+++ trunk/ai/default/aiunit.c   Sun Sep  6 13:04:54 2015
@@ -1482,7 +1482,7 @@
       }
 
       if ((unit_has_type_flag(aunit, UTYF_CIVILIAN)
-           || (is_actor_unit(aunit)
+           || (utype_may_act_at_all(unit_type(aunit))
                && !utype_acts_hostile(unit_type(aunit))))
           && 0 == punit->id) {
         /* We will not build units just to chase caravans and

Modified: trunk/client/climisc.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/climisc.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/client/climisc.c      (original)
+++ trunk/client/climisc.c      Sun Sep  6 13:04:54 2015
@@ -1245,7 +1245,7 @@
   struct city *tgt_city;
   struct tile *tgt_tile;
 
-  if (!is_actor_unit(act_unit)) {
+  if (!utype_may_act_at_all(unit_type(act_unit))) {
     /* Not an actor unit. */
     return FALSE;
   }

Modified: trunk/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/client/control.c      (original)
+++ trunk/client/control.c      Sun Sep  6 13:04:54 2015
@@ -981,7 +981,8 @@
     pdiplomat = player_unit_by_number(client_player(), diplomat_id);
     ptile = index_to_tile(tgt_tile_id);
 
-    if (ptile && pdiplomat && is_actor_unit(pdiplomat)) {
+    if (ptile && pdiplomat
+        && utype_may_act_at_all(unit_type(pdiplomat))) {
       have_asked_server_for_actions = TRUE;
       dsend_packet_unit_get_actions(&client.conn,
                                     diplomat_id,
@@ -2732,7 +2733,7 @@
 {
   struct tile *ptile;
   unit_list_iterate(get_units_in_focus(), punit) {
-    if (is_actor_unit(punit)
+    if (utype_may_act_at_all(unit_type(punit))
         && (ptile = unit_tile(punit))) {
       process_diplomat_arrival(punit, ptile->index);
       return;

Modified: trunk/client/goto.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/goto.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/client/goto.c (original)
+++ trunk/client/goto.c Sun Sep  6 13:04:54 2015
@@ -891,7 +891,7 @@
   if (is_attack_unit(punit)
       || utype_acts_hostile(unit_type(punit))) {
     parameter->get_TB = get_TB_aggr;
-  } else if (is_actor_unit(punit)
+  } else if (utype_may_act_at_all(unit_type(punit))
              && !utype_acts_hostile(unit_type(punit))) {
     parameter->get_TB = get_TB_caravan;
   } else {

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Sun Sep  6 13:04:54 2015
@@ -1672,7 +1672,7 @@
             && !unit_has_orders(punit)
              /* the server handles non transported units */
             && NULL != unit_transport_get(punit)
-            && is_actor_unit(punit)) {
+            && utype_may_act_at_all(unit_type(punit))) {
           /* Open action dialog only if 'punit' and all its transporters
            * (recursively) don't have orders. */
           struct unit *ptrans;

Modified: trunk/common/aicore/pf_tools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/aicore/pf_tools.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/common/aicore/pf_tools.c      (original)
+++ trunk/common/aicore/pf_tools.c      Sun Sep  6 13:04:54 2015
@@ -682,7 +682,7 @@
       parameter->actions |= PF_AA_CITY_ATTACK;
     }
   }
-  if (is_actor_unit_type(parameter->utype)) {
+  if (utype_may_act_at_all(parameter->utype)) {
     /* FIXME: it should consider action enablers. */
     if (utype_can_do_action(parameter->utype, ACTION_TRADE_ROUTE)
         || utype_can_do_action(parameter->utype, ACTION_MARKETPLACE)) {

Modified: trunk/common/city.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/city.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/common/city.c (original)
+++ trunk/common/city.c Sun Sep  6 13:04:54 2015
@@ -1406,7 +1406,7 @@
   struct requirement tile_is_claimed;
   struct requirement tile_is_foreign;
 
-  if (!is_actor_unit_type(punit_type)) {
+  if (!utype_may_act_at_all(punit_type)) {
     /* Not an actor unit type. */
     return FALSE;
   }

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Sun Sep  6 13:04:54 2015
@@ -269,15 +269,6 @@
 bool is_diplomat_unit(const struct unit *punit)
 {
   return (unit_has_type_flag(punit, UTYF_DIPLOMAT));
-}
-
-/**************************************************************************
-  Return TRUE iff this unit can do actions controlled by generalized
-  (ruleset defined) action enablers.
-**************************************************************************/
-bool is_actor_unit(const struct unit *punit)
-{
-  return is_actor_unit_type(unit_type(punit));
 }
 
 /**************************************************************************

Modified: trunk/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.h?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Sun Sep  6 13:04:54 2015
@@ -297,7 +297,6 @@
 bool is_attack_unit(const struct unit *punit);
 bool is_military_unit(const struct unit *punit);           /* !set !dip !cara 
*/
 bool is_diplomat_unit(const struct unit *punit);
-bool is_actor_unit(const struct unit *punit);
 bool unit_can_do_action(const struct unit *punit,
                         const int action_id);
 bool is_square_threatened(const struct player *pplayer,

Modified: trunk/common/unittype.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unittype.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/common/unittype.c     (original)
+++ trunk/common/unittype.c     Sun Sep  6 13:04:54 2015
@@ -310,7 +310,7 @@
   Return TRUE iff units of this type can do actions controlled by
   generalized (ruleset defined) action enablers.
 **************************************************************************/
-bool is_actor_unit_type(const struct unit_type *putype)
+bool utype_may_act_at_all(const struct unit_type *putype)
 {
   return utype_can_do_action(putype, ACTION_ANY);
 }
@@ -374,7 +374,7 @@
   BV_CLR_ALL(ustate_act_cache[uidx][ACTION_ANY]);
   BV_CLR_ALL(ustate_act_cache[uidx][ACTION_HOSTILE]);
 
-  if (!is_actor_unit_type(putype)) {
+  if (!utype_may_act_at_all(putype)) {
     /* Not an actor unit. */
     return;
   }
@@ -454,7 +454,7 @@
   BV_CLR_ALL(dipl_rel_action_cache[putype_id][ACTION_ANY]);
   BV_CLR_ALL(dipl_rel_action_cache[putype_id][ACTION_HOSTILE]);
 
-  if (!is_actor_unit_type(putype)) {
+  if (!utype_may_act_at_all(putype)) {
     /* Not an actor unit. */
     return;
   }
@@ -625,7 +625,7 @@
 
   fc_assert(action_id_is_valid(action_id) || action_id == ACTION_ANY);
 
-  if (!is_actor_unit_type(punit_type)) {
+  if (!utype_may_act_at_all(punit_type)) {
     /* Not an actor unit. */
     return FALSE;
   }
@@ -690,7 +690,7 @@
 {
   struct requirement req;
 
-  if (!is_actor_unit_type(punit_type)) {
+  if (!utype_may_act_at_all(punit_type)) {
     /* Not an actor unit. */
     return FALSE;
   }

Modified: trunk/common/unittype.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unittype.h?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/common/unittype.h     (original)
+++ trunk/common/unittype.h     Sun Sep  6 13:04:54 2015
@@ -523,7 +523,7 @@
 bool utype_can_freely_unload(const struct unit_type *pcargotype,
                              const struct unit_type *ptranstype);
 
-bool is_actor_unit_type(const struct unit_type *putype);
+bool utype_may_act_at_all(const struct unit_type *putype);
 bool utype_can_do_action(const struct unit_type *putype,
                          const int action_id);
 bool utype_acts_hostile(const struct unit_type *putype);

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=29788&r1=29787&r2=29788&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Sun Sep  6 13:04:54 2015
@@ -1288,7 +1288,7 @@
     return;
   }
 
-  if (!is_actor_unit(pactor)) {
+  if (!utype_may_act_at_all(unit_type(pactor))) {
     /* Shouldn't happen */
     log_error("handle_unit_action_query() %s (%d) is not an actor",
               unit_rule_name(pactor), actor_id);
@@ -1401,7 +1401,7 @@
     return FALSE;
   }
 
-  if (!is_actor_unit(actor_unit)) {
+  if (!utype_may_act_at_all(unit_type(actor_unit))) {
     /* Shouldn't happen */
     log_error("handle_unit_do_action() %s (%d) is not an actor unit",
               unit_rule_name(actor_unit), actor_id);
@@ -2904,7 +2904,7 @@
    * 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
    * is not the final destination. */
-  if (is_actor_unit(punit)) {
+  if (utype_may_act_at_all(unit_type(punit))) {
     struct unit *tunit = action_tgt_unit(punit, pdesttile);
     struct city *tcity = action_tgt_city(punit, pdesttile);
 


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

Reply via email to