Author: sveinung
Date: Sun Sep  6 13:36:38 2015
New Revision: 29793

URL: http://svn.gna.org/viewcvs/freeciv?rev=29793&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:
    branches/S2_6/ai/default/aitools.c
    branches/S2_6/ai/default/aiunit.c
    branches/S2_6/client/climisc.c
    branches/S2_6/client/control.c
    branches/S2_6/client/goto.c
    branches/S2_6/client/packhand.c
    branches/S2_6/common/aicore/pf_tools.c
    branches/S2_6/common/unit.c
    branches/S2_6/common/unit.h
    branches/S2_6/common/unittype.c
    branches/S2_6/common/unittype.h
    branches/S2_6/server/unithand.c

Modified: branches/S2_6/ai/default/aitools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aitools.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/ai/default/aitools.c  (original)
+++ branches/S2_6/ai/default/aitools.c  Sun Sep  6 13:36:38 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: branches/S2_6/ai/default/aiunit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aiunit.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/ai/default/aiunit.c   (original)
+++ branches/S2_6/ai/default/aiunit.c   Sun Sep  6 13:36:38 2015
@@ -1479,7 +1479,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: branches/S2_6/client/climisc.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/climisc.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/client/climisc.c      (original)
+++ branches/S2_6/client/climisc.c      Sun Sep  6 13:36:38 2015
@@ -1242,7 +1242,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: branches/S2_6/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/control.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/client/control.c      (original)
+++ branches/S2_6/client/control.c      Sun Sep  6 13:36:38 2015
@@ -969,7 +969,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,
@@ -2781,7 +2782,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: branches/S2_6/client/goto.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/goto.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/client/goto.c (original)
+++ branches/S2_6/client/goto.c Sun Sep  6 13:36:38 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: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Sun Sep  6 13:36:38 2015
@@ -1637,7 +1637,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: branches/S2_6/common/aicore/pf_tools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/aicore/pf_tools.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/common/aicore/pf_tools.c      (original)
+++ branches/S2_6/common/aicore/pf_tools.c      Sun Sep  6 13:36:38 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: branches/S2_6/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unit.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/common/unit.c (original)
+++ branches/S2_6/common/unit.c Sun Sep  6 13:36:38 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: branches/S2_6/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unit.h?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/common/unit.h (original)
+++ branches/S2_6/common/unit.h Sun Sep  6 13:36:38 2015
@@ -300,7 +300,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: branches/S2_6/common/unittype.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unittype.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/common/unittype.c     (original)
+++ branches/S2_6/common/unittype.c     Sun Sep  6 13:36:38 2015
@@ -309,7 +309,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);
 }
@@ -373,7 +373,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;
   }
@@ -443,7 +443,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;
   }
@@ -614,7 +614,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;
   }

Modified: branches/S2_6/common/unittype.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unittype.h?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/common/unittype.h     (original)
+++ branches/S2_6/common/unittype.h     Sun Sep  6 13:36:38 2015
@@ -529,7 +529,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: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=29793&r1=29792&r2=29793&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Sun Sep  6 13:36:38 2015
@@ -955,7 +955,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);
@@ -1045,7 +1045,7 @@
     return;
   }
 
-  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);
@@ -2260,7 +2260,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 = tgt_unit(punit, pdesttile);
     struct city *tcity = tgt_city(punit, pdesttile);
 


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

Reply via email to