Author: sveinung
Date: Thu Oct 13 01:23:29 2016
New Revision: 34111

URL: http://svn.gna.org/viewcvs/freeciv?rev=34111&view=rev
Log:
Centralize action obligatory hard req handling.

Introduce action_enabler_obligatory_reqs_add(). Have it use the same data as
the sanity cheking. Use it when upgrading a ruleset.

See patch #7803

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

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=34111&r1=34110&r2=34111&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Thu Oct 13 01:23:29 2016
@@ -1062,6 +1062,51 @@
 }
 
 /**************************************************************************
+  Inserts any missing obligatory hard requirements in the action enabler
+  based on its action.
+
+  See action_enabler_obligatory_reqs_missing()
+**************************************************************************/
+void action_enabler_obligatory_reqs_add(struct action_enabler *enabler)
+{
+  /* Sanity check: a non existing action enabler is missing but it doesn't
+   * miss any obligatory hard requirements. */
+  fc_assert_ret(enabler);
+
+  /* Sanity check: a non existing action doesn't have any obligatory hard
+   * requirements. */
+  fc_assert_ret(action_id_is_valid(enabler->action));
+
+  obligatory_req_vector_iterate(&obligatory_hard_reqs[enabler->action],
+                                obreq) {
+    struct requirement_vector *ae_vec;
+
+    /* Select action enabler requirement vector. */
+    ae_vec = (obreq->is_target ? &enabler->target_reqs :
+                                 &enabler->actor_reqs);
+
+    if (!does_req_contradicts_reqs(&obreq->contradiction, ae_vec)) {
+      struct requirement missing;
+
+      /* Change the requirement from what should conflict to what is
+       * wanted. */
+      missing.present = !obreq->contradiction.present;
+      missing.source = obreq->contradiction.source;
+      missing.range = obreq->contradiction.range;
+      missing.survives = obreq->contradiction.survives;
+      missing.quiet = obreq->contradiction.quiet;
+
+      /* Insert the missing requirement. */
+      requirement_vector_append(ae_vec, missing);
+    }
+  } obligatory_req_vector_iterate_end;
+
+  /* Sanity check: obligatory requirement insertion should have fixed the
+   * action enabler. */
+  fc_assert(action_enabler_obligatory_reqs_missing(enabler) == NULL);
+}
+
+/**************************************************************************
   Returns TRUE iff the specified player knows (has seen) the specified
   tile.
 **************************************************************************/

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=34111&r1=34110&r2=34111&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Thu Oct 13 01:23:29 2016
@@ -365,6 +365,7 @@
 
 const char *
 action_enabler_obligatory_reqs_missing(struct action_enabler *enabler);
+void action_enabler_obligatory_reqs_add(struct action_enabler *enabler);
 
 struct action *action_is_blocked_by(const int action_id,
                                     const struct unit *actor_unit,

Modified: trunk/server/rscompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/rscompat.c?rev=34111&r1=34110&r2=34111&view=diff
==============================================================================
--- trunk/server/rscompat.c     (original)
+++ trunk/server/rscompat.c     Thu Oct 13 01:23:29 2016
@@ -935,23 +935,9 @@
 
       }
 
-      if (ae->action == ACTION_ESTABLISH_EMBASSY
-          || ae->action == ACTION_SPY_INVESTIGATE_CITY
-          || ae->action == ACTION_SPY_STEAL_GOLD
-          || ae->action == ACTION_SPY_STEAL_TECH
-          || ae->action == ACTION_SPY_TARGETED_STEAL_TECH
-          || ae->action == ACTION_SPY_INCITE_CITY
-          || ae->action == ACTION_SPY_BRIBE_UNIT) {
-        /* The rule that the target must be foreign used to be implicit. It
-         * must now be explicitly stated in the ruleset. */
-
-        struct requirement req
-            = req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
-                              FALSE, TRUE, TRUE, DRO_FOREIGN);
-
-        if (!is_req_in_vec(&req, &ae->actor_reqs)) {
-          requirement_vector_append(&ae->actor_reqs, req);
-        }
+      if (action_enabler_obligatory_reqs_missing(ae)) {
+        /* Add previously implicit obligatory hard requirement(s). */
+        action_enabler_obligatory_reqs_add(ae);
       }
     } action_enablers_iterate_end;
   }


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

Reply via email to