Author: sveinung
Date: Fri Jun 24 01:47:03 2016
New Revision: 32987

URL: http://svn.gna.org/viewcvs/freeciv?rev=32987&view=rev
Log:
Check if a situation blocks an action.

Make it easy to checks if an action never is possible in a certain
situation. The situation is specified as a requirement. The new function is
called action_blocked_by_situation_act().

See patch #7298

Modified:
    trunk/common/actions.c
    trunk/common/actions.h

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=32987&r1=32986&r2=32987&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Fri Jun 24 01:47:03 2016
@@ -2776,6 +2776,23 @@
 }
 
 /**************************************************************************
+  Returns TRUE if the specified action never can be performed when the
+  situation requirement is fulfilled for the actor.
+**************************************************************************/
+bool action_blocked_by_situation_act(struct action *action,
+                                     const struct requirement *situation)
+{
+  action_enabler_list_iterate(action_enablers_for_action(action->id),
+                              enabler) {
+    if (!does_req_contradicts_reqs(situation, &enabler->actor_reqs)) {
+      return FALSE;
+    }
+  } action_enabler_list_iterate_end;
+
+  return TRUE;
+}
+
+/**************************************************************************
   Returns TRUE if the wanted action can be done to the target.
 **************************************************************************/
 static bool is_target_possible(const enum gen_action wanted_action,

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=32987&r1=32986&r2=32987&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Fri Jun 24 01:47:03 2016
@@ -382,6 +382,11 @@
 /* Reasoning about actions */
 bool action_immune_government(struct government *gov, int act);
 
+bool action_blocked_by_situation_act(struct action *action,
+                                     const struct requirement *situation);
+#define action_id_blocked_by_situation_act(action_id, situation)          \
+  action_blocked_by_situation_act(action_by_number(action_id), situation)
+
 bool is_action_possible_on_city(const enum gen_action action_id,
                                 const struct player *actor_player,
                                 const struct city* target_city);


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

Reply via email to