Author: sveinung
Date: Thu Nov 12 15:54:31 2015
New Revision: 30572

URL: http://svn.gna.org/viewcvs/freeciv?rev=30572&view=rev
Log:
Be aware of action requester identity

Let unit_perform_action() know how responsible the player is for an attempt
to perform an action.

At the moment a request to perform an action can come from two sources: the
player or the game rules. A third action requester that hasn't appeared yet
is server side agents like auto settlers.

See patch #6581

Modified:
    trunk/ai/default/aicity.c
    trunk/common/actions.h
    trunk/server/cityturn.c
    trunk/server/unithand.c
    trunk/server/unithand.h
    trunk/server/unittools.c
    trunk/server/unittools.h

Modified: trunk/ai/default/aicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aicity.c?rev=30572&r1=30571&r2=30572&view=diff
==============================================================================
--- trunk/ai/default/aicity.c   (original)
+++ trunk/ai/default/aicity.c   Thu Nov 12 15:54:31 2015
@@ -463,7 +463,7 @@
           && def_ai_city_data(pcity, ait)->urgency == 0) {
         CITY_LOG(LOG_BUY, pcity, "disbanding %s to increase production",
                  unit_rule_name(punit));
-        unit_do_disband_trad(pplayer, punit);
+        unit_do_disband_trad(pplayer, punit, ACT_REQ_PLAYER);
       }
     } unit_list_iterate_safe_end;
   } city_list_iterate_end;
@@ -938,7 +938,7 @@
       /* TODO: Should the unit try to find legal targets at adjacent tiles?
        * Should it consider other self eliminating actions than the
        * components of the traditional disband? */
-      unit_do_disband_trad(pplayer, punit);
+      unit_do_disband_trad(pplayer, punit, ACT_REQ_PLAYER);
       city_refresh(pcity);
     }
   } unit_list_iterate_safe_end;

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=30572&r1=30571&r2=30572&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Thu Nov 12 15:54:31 2015
@@ -153,6 +153,21 @@
  */
 #define ACTPROB_NOT_KNOWN 255
 
+/* Who ordered the action to be performed? */
+#define SPECENUM_NAME action_requester
+/* The player ordered it directly. */
+#define SPECENUM_VALUE0 ACT_REQ_PLAYER
+#define SPECENUM_VALUE0NAME N_("the player")
+/* The game it self because the rules requires it. */
+#define SPECENUM_VALUE1 ACT_REQ_RULES
+#define SPECENUM_VALUE1NAME N_("the game rules")
+/* A server side autonomous agent working for the player. */
+#define SPECENUM_VALUE2 ACT_REQ_SS_AGENT
+#define SPECENUM_VALUE2NAME N_("a server agent")
+/* Number of action requesters. */
+#define SPECENUM_COUNT ACT_REQ_COUNT
+#include "specenum_gen.h"
+
 struct action
 {
   enum gen_action id;

Modified: trunk/server/cityturn.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityturn.c?rev=30572&r1=30571&r2=30572&view=diff
==============================================================================
--- trunk/server/cityturn.c     (original)
+++ trunk/server/cityturn.c     Thu Nov 12 15:54:31 2015
@@ -2052,7 +2052,7 @@
         /* TODO: Should the unit try to help cities on adjacent tiles? That
          * would be a rules change. (This action is performed by the game
          * it self) */
-        unit_do_disband_trad(pplayer, punit);
+        unit_do_disband_trad(pplayer, punit, ACT_REQ_RULES);
        /* pcity->surplus[O_SHIELD] is automatically updated. */
       }
     } unit_list_iterate_safe_end;

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=30572&r1=30571&r2=30572&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Thu Nov 12 15:54:31 2015
@@ -1337,7 +1337,7 @@
                           const enum gen_action action_type)
 {
   (void) unit_perform_action(pplayer, actor_id, target_id, value, name,
-                             action_type);
+                             action_type, ACT_REQ_PLAYER);
 }
 
 /**************************************************************************
@@ -1356,7 +1356,8 @@
                          const int target_id,
                          const int value,
                          const char *name,
-                         const enum gen_action action_type)
+                         const enum gen_action action_type,
+                         const enum action_requester requester)
 {
   struct unit *actor_unit = player_unit_by_number(pplayer, actor_id);
   struct tile *target_tile = index_to_tile(target_id);

Modified: trunk/server/unithand.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.h?rev=30572&r1=30571&r2=30572&view=diff
==============================================================================
--- trunk/server/unithand.h     (original)
+++ trunk/server/unithand.h     Thu Nov 12 15:54:31 2015
@@ -35,7 +35,8 @@
                          const int target_id,
                          const int value,
                          const char *name,
-                         const enum gen_action action_type);
+                         const enum gen_action action_type,
+                         const enum action_requester requester);
 
 void illegal_action_msg(struct player *pplayer,
                         const enum event_type event,

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=30572&r1=30571&r2=30572&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Thu Nov 12 15:54:31 2015
@@ -3759,7 +3759,8 @@
   Try to disband the specified unit. Match the old behavior in what kind
   of disbanding is tried and who benefits from it.
 **************************************************************************/
-void unit_do_disband_trad(struct player *owner, struct unit *punit)
+void unit_do_disband_trad(struct player *owner, struct unit *punit,
+                          const enum action_requester requester)
 {
   const int punit_id_stored = punit->id;
 
@@ -3777,7 +3778,7 @@
         && is_action_enabled_unit_on_city(ACTION_HELP_WONDER,
                                           punit, tgt_city)) {
       if (unit_perform_action(owner, punit->id, tgt_city->id,
-                              0, NULL, ACTION_HELP_WONDER)) {
+                              0, NULL, ACTION_HELP_WONDER, requester)) {
         /* No shields wasted. The unit did Help Wonder. */
         return;
       }
@@ -3801,7 +3802,7 @@
         && is_action_enabled_unit_on_city(ACTION_RECYCLE_UNIT,
                                           punit, tgt_city)) {
       if (unit_perform_action(owner, punit->id, tgt_city->id,
-                              0, NULL, ACTION_RECYCLE_UNIT)) {
+                              0, NULL, ACTION_RECYCLE_UNIT, requester)) {
         /* The unit did Recycle Unit. 50% of the shields wasted. */
         return;
       }
@@ -3817,7 +3818,7 @@
   if (unit_can_do_action(punit, ACTION_DISBAND_UNIT)) {
     if (is_action_enabled_unit_on_self(ACTION_DISBAND_UNIT, punit)) {
       if (unit_perform_action(owner, punit->id, punit->id,
-                              0, NULL, ACTION_DISBAND_UNIT)) {
+                              0, NULL, ACTION_DISBAND_UNIT, requester)) {
         /* All shields wasted. The unit did Disband Unit. */
         return;
       }
@@ -4292,7 +4293,8 @@
                                       tgt_id,
                                       order.target,
                                       name,
-                                      order.action);
+                                      order.action,
+                                      ACT_REQ_PLAYER);
 
       if (!player_unit_by_number(pplayer, unitid)) {
         /* The unit "died" while performing the action. */

Modified: trunk/server/unittools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.h?rev=30572&r1=30571&r2=30572&view=diff
==============================================================================
--- trunk/server/unittools.h    (original)
+++ trunk/server/unittools.h    Thu Nov 12 15:54:31 2015
@@ -150,7 +150,8 @@
 void unit_transport_load_send(struct unit *punit, struct unit *ptrans);
 void unit_transport_unload_send(struct unit *punit);
 bool unit_move(struct unit *punit, struct tile *ptile, int move_cost);
-void unit_do_disband_trad(struct player *owner, struct unit *punit);
+void unit_do_disband_trad(struct player *owner, struct unit *punit,
+                          const enum action_requester requester);
 bool execute_orders(struct unit *punit, const bool fresh);
 
 bool unit_can_do_action_now(const struct unit *punit);


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

Reply via email to