Author: sveinung
Date: Wed Mar  1 11:19:18 2017
New Revision: 35070

URL: http://svn.gna.org/viewcvs/freeciv?rev=35070&view=rev
Log:
action_get_role(): take action struct.

The function action_get_role() took an action id rather than an action. Make
it take an action structure. Introduce action_id_get_role() for getting role
by ID.

See gna patch #8120

Modified:
    trunk/ai/default/aicity.c
    trunk/ai/default/aisettler.c
    trunk/ai/default/daidomestic.c
    trunk/client/control.c
    trunk/client/helpdata.c
    trunk/common/actions.c
    trunk/common/actions.h
    trunk/common/aicore/aisupport.c
    trunk/server/advisors/advbuilding.c
    trunk/server/advisors/advdata.c
    trunk/server/unithand.c

Modified: trunk/ai/default/aicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aicity.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/ai/default/aicity.c   (original)
+++ trunk/ai/default/aicity.c   Wed Mar  1 11:19:18 2017
@@ -282,9 +282,9 @@
     CITY_LOG(LOG_WANT, pcity, "Falling back - didn't want to build soldiers,"
             " workers, caravans, settlers, or buildings!");
     city_data->choice.want = 1;
-    if (best_role_unit(pcity, action_get_role(ACTION_TRADE_ROUTE))) {
+    if (best_role_unit(pcity, action_id_get_role(ACTION_TRADE_ROUTE))) {
       city_data->choice.value.utype
-        = best_role_unit(pcity, action_get_role(ACTION_TRADE_ROUTE));
+        = best_role_unit(pcity, action_id_get_role(ACTION_TRADE_ROUTE));
       city_data->choice.type = CT_CIVILIAN;
       adv_choice_set_use(&(city_data->choice), "fallback trade route");
     } else {

Modified: trunk/ai/default/aisettler.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aisettler.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/ai/default/aisettler.c        (original)
+++ trunk/ai/default/aisettler.c        Wed Mar  1 11:19:18 2017
@@ -1300,7 +1300,7 @@
     return;
   }
 
-  unit_type = best_role_unit(pcity, action_get_role(ACTION_FOUND_CITY));
+  unit_type = best_role_unit(pcity, action_id_get_role(ACTION_FOUND_CITY));
 
   if (unit_type == NULL) {
     log_debug("No ACTION_FOUND_CITY role unit available");

Modified: trunk/ai/default/daidomestic.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/daidomestic.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/ai/default/daidomestic.c      (original)
+++ trunk/ai/default/daidomestic.c      Wed Mar  1 11:19:18 2017
@@ -86,7 +86,7 @@
   struct unit_type *unit_type;
   struct city *wonder_city = game_city_by_number(ai->wonder_city);
 
-  if (num_role_units(action_get_role(ACTION_HELP_WONDER)) == 0) {
+  if (num_role_units(action_id_get_role(ACTION_HELP_WONDER)) == 0) {
     /* No such units available in the ruleset */
     return;
   }
@@ -122,12 +122,12 @@
     }
   } city_list_iterate_end;
 
-  unit_type = best_role_unit(pcity, action_get_role(ACTION_HELP_WONDER));
+  unit_type = best_role_unit(pcity, action_id_get_role(ACTION_HELP_WONDER));
 
   if (!unit_type) {
     /* We cannot build such units yet
      * but we will consider it to stimulate science */
-    unit_type = get_role_unit(action_get_role(ACTION_HELP_WONDER), 0);
+    unit_type = get_role_unit(action_id_get_role(ACTION_HELP_WONDER), 0);
   }
 
   fc_assert_msg(utype_can_do_action(unit_type, ACTION_HELP_WONDER),
@@ -152,7 +152,7 @@
       /* This sets our tech want in cases where we cannot actually build
        * the unit. */
       unit_type = dai_wants_role_unit(ait, pplayer, pcity,
-                                      action_get_role(ACTION_HELP_WONDER),
+                                      action_id_get_role(ACTION_HELP_WONDER),
                                       want);
       if (unit_type != NULL) {
         choice->want = want;
@@ -202,8 +202,8 @@
     return;
   }
 
-  if (num_role_units(action_get_role(ACTION_TRADE_ROUTE)) == 0
-      && num_role_units(action_get_role(ACTION_MARKETPLACE)) == 0) {
+  if (num_role_units(action_id_get_role(ACTION_TRADE_ROUTE)) == 0
+      && num_role_units(action_id_get_role(ACTION_MARKETPLACE)) == 0) {
     /* No such units available in the ruleset */
     return;
   }
@@ -282,7 +282,8 @@
     return;
   }
 
-  unit_type = best_role_unit(pcity, action_get_role(ACTION_TRADE_ROUTE));
+  unit_type = best_role_unit(pcity,
+                             action_id_get_role(ACTION_TRADE_ROUTE));
 
   if (!unit_type) {
     /* Can't establish trade route yet. What about entering a marketplace? */
@@ -290,19 +291,20 @@
      * prioritized above a present unit capable of entering a market place?
      * In that case this should be below the check for a future unit
      * capable of establishing a trade route. */
-    unit_type = best_role_unit(pcity, action_get_role(ACTION_MARKETPLACE));
+    unit_type = best_role_unit(pcity,
+                               action_id_get_role(ACTION_MARKETPLACE));
   }
 
   if (!unit_type) {
     /* We cannot build such units yet
      * but we will consider it to stimulate science */
-    unit_type = get_role_unit(action_get_role(ACTION_TRADE_ROUTE), 0);
+    unit_type = get_role_unit(action_id_get_role(ACTION_TRADE_ROUTE), 0);
   }
 
   if (!unit_type) {
     /* We'll never be able to establish a trade route. Consider a unit that
      * can enter the marketplace in stead to stimulate science. */
-    unit_type = get_role_unit(action_get_role(ACTION_MARKETPLACE), 0);
+    unit_type = get_role_unit(action_id_get_role(ACTION_MARKETPLACE), 0);
   }
 
   fc_assert_msg(unit_type,
@@ -426,12 +428,12 @@
     /* This sets our tech want in cases where we cannot actually build
      * the unit. */
     unit_type = dai_wants_role_unit(ait, pplayer, pcity,
-                                    action_get_role(ACTION_TRADE_ROUTE),
+                                    action_id_get_role(ACTION_TRADE_ROUTE),
                                     want);
 
     if (unit_type == NULL) {
       unit_type = dai_wants_role_unit(ait, pplayer, pcity,
-                                      action_get_role(ACTION_MARKETPLACE),
+                                      action_id_get_role(ACTION_MARKETPLACE),
                                       want);
     }
 
@@ -498,7 +500,7 @@
   /* Basically, copied from above and adjusted. -- jjm */
   if (!game.scenario.prevent_new_cities) {
     founder_type = best_role_unit(pcity,
-                                  action_get_role(ACTION_FOUND_CITY));
+                                  action_id_get_role(ACTION_FOUND_CITY));
 
     /* founder_want calculated in aisettlers.c */
     founder_want = city_data->founder_want;
@@ -525,7 +527,7 @@
         CITY_LOG(LOG_DEBUG, pcity, "desires founders with passion " 
ADV_WANT_PRINTF,
                  founder_want);
         dai_choose_role_unit(ait, pplayer, pcity, choice, CT_CIVILIAN,
-                             action_get_role(ACTION_FOUND_CITY),
+                             action_id_get_role(ACTION_FOUND_CITY),
                              founder_want,
                              city_data->founder_boat);
         adv_choice_set_use(choice, "founder");
@@ -556,7 +558,7 @@
                && (founder_want > choice->want || founder_want < 
-choice->want)) {
       /* Can't build founders. Lets stimulate science */
       dai_wants_role_unit(ait, pplayer, pcity,
-                          action_get_role(ACTION_FOUND_CITY),
+                          action_id_get_role(ACTION_FOUND_CITY),
                           founder_want);
     }
   }
@@ -615,7 +617,7 @@
   }
 
   punittype = best_role_unit_for_player(pplayer,
-      action_get_role(ACTION_HELP_WONDER));
+      action_id_get_role(ACTION_HELP_WONDER));
 
   if (!punittype) {
     return;

Modified: trunk/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/client/control.c      (original)
+++ trunk/client/control.c      Wed Mar  1 11:19:18 2017
@@ -1118,7 +1118,7 @@
         struct astring astr = ASTRING_INIT;
 
         if (role_units_translations(&astr,
-                                    action_get_role(action_id),
+                                    action_id_get_role(action_id),
                                     TRUE)) {
           /* ...but other units can perform it. */
 

Modified: trunk/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/client/helpdata.c     (original)
+++ trunk/client/helpdata.c     Wed Mar  1 11:19:18 2017
@@ -1164,8 +1164,8 @@
    * uniqueness, so we don't mention it here.) */
 
   if (building_has_effect(pimprove, EFT_ENABLE_NUKE)
-      && num_role_units(action_get_role(ACTION_NUKE)) > 0) {
-    struct unit_type *u = get_role_unit(action_get_role(ACTION_NUKE), 0);
+      && num_role_units(action_id_get_role(ACTION_NUKE)) > 0) {
+    struct unit_type *u = get_role_unit(action_id_get_role(ACTION_NUKE), 0);
 
     cat_snprintf(buf, bufsz,
                 /* TRANS: 'Allows all players with knowledge of atomic

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Wed Mar  1 11:19:18 2017
@@ -985,17 +985,16 @@
 }
 
 /**************************************************************************
-  Get the unit type role corresponding to the ability to do action.
-**************************************************************************/
-int action_get_role(int action_id)
-{
-  fc_assert_msg(actions[action_id], "Action %d don't exist.", action_id);
-
-  fc_assert_msg(AAK_UNIT == action_id_get_actor_kind(action_id),
+  Get the unit type role corresponding to the ability to do the specified
+  action.
+**************************************************************************/
+int action_get_role(const struct action *paction)
+{
+  fc_assert_msg(AAK_UNIT == action_get_actor_kind(paction),
                 "Action %s isn't performed by a unit",
-                action_id_rule_name(action_id));
-
-  return action_id + L_LAST;
+                action_rule_name(paction));
+
+  return paction->id + L_LAST;
 }
 
 /**************************************************************************

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Wed Mar  1 11:19:18 2017
@@ -365,7 +365,9 @@
   action_would_be_blocked_by(action_by_number(blocked_id),                \
                              action_by_number(blocker_id))
 
-int action_get_role(int action_id);
+int action_get_role(const struct action *paction);
+#define action_id_get_role(action_id)                                     \
+  action_get_role(action_by_number(action_id))
 
 const char *action_rule_name(const struct action *action);
 const char *action_id_rule_name(int action_id);

Modified: trunk/common/aicore/aisupport.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/aicore/aisupport.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/common/aicore/aisupport.c     (original)
+++ trunk/common/aicore/aisupport.c     Wed Mar  1 11:19:18 2017
@@ -114,7 +114,7 @@
 
   if (!game.scenario.prevent_new_cities) {
     u = best_role_unit_for_player(city_owner(pcity),
-                                  action_get_role(ACTION_FOUND_CITY));
+                                  action_id_get_role(ACTION_FOUND_CITY));
   }
 
   if (u != NULL) {

Modified: trunk/server/advisors/advbuilding.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/advisors/advbuilding.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/server/advisors/advbuilding.c (original)
+++ trunk/server/advisors/advbuilding.c Wed Mar  1 11:19:18 2017
@@ -65,16 +65,16 @@
     pcity->server.adv->downtown = 0;
   } city_list_iterate_end;
 
-  if (num_role_units(action_get_role(ACTION_HELP_WONDER)) == 0) {
+  if (num_role_units(action_id_get_role(ACTION_HELP_WONDER)) == 0) {
     return; /* ruleset has no help wonder unit */
   }
 
   punittype = best_role_unit_for_player(pplayer,
-      action_get_role(ACTION_HELP_WONDER));
+      action_id_get_role(ACTION_HELP_WONDER));
 
   if (!punittype) {
     /* simulate future unit */
-    punittype = get_role_unit(action_get_role(ACTION_HELP_WONDER), 0);
+    punittype = get_role_unit(action_id_get_role(ACTION_HELP_WONDER), 0);
   }
 
   fc_assert_msg(utype_can_do_action(punittype, ACTION_HELP_WONDER),
@@ -205,7 +205,7 @@
     struct city *best_candidate = NULL;
     /* Whether ruleset has a help wonder unit type */
     bool has_help =
-        (num_role_units(action_get_role(ACTION_HELP_WONDER)) > 0);
+        (num_role_units(action_id_get_role(ACTION_HELP_WONDER)) > 0);
 
     calculate_city_clusters(pplayer);
 
@@ -232,7 +232,7 @@
        * These may be able to help with caravans. Also look at the whole
        * continent. */
       if (first_role_unit_for_player(pplayer,
-                                     action_get_role(ACTION_HELP_WONDER))) {
+              action_id_get_role(ACTION_HELP_WONDER))) {
         value += city_data->downtown;
 
         if (place >= 0) {

Modified: trunk/server/advisors/advdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/advisors/advdata.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/server/advisors/advdata.c     (original)
+++ trunk/server/advisors/advdata.c     Wed Mar  1 11:19:18 2017
@@ -270,7 +270,7 @@
 
   TIMING_LOG(AIT_AIDATA, TIMER_START);
 
-  nuke_units = num_role_units(action_get_role(ACTION_NUKE));
+  nuke_units = num_role_units(action_id_get_role(ACTION_NUKE));
   danger_of_nukes = FALSE;
 
   /*** Threats ***/
@@ -355,7 +355,8 @@
 
     /* Check for nuke capability */
     for (i = 0; i < nuke_units; i++) {
-      struct unit_type *nuke = get_role_unit(action_get_role(ACTION_NUKE), i);
+      struct unit_type *nuke =
+          get_role_unit(action_id_get_role(ACTION_NUKE), i);
 
       if (can_player_build_unit_direct(aplayer, nuke)) { 
         adv->threats.nuclear = 1;

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=35070&r1=35069&r2=35070&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed Mar  1 11:19:18 2017
@@ -1640,7 +1640,7 @@
       struct astring astr = ASTRING_INIT;
 
       if (role_units_translations(&astr,
-                                  action_get_role(stopped_action),
+                                  action_id_get_role(stopped_action),
                                   TRUE)) {
         notify_player(pplayer, unit_tile(actor),
                       event, ftc_server,


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

Reply via email to