Author: sveinung
Date: Fri Jun 24 01:47:22 2016
New Revision: 32988

URL: http://svn.gna.org/viewcvs/freeciv?rev=32988&view=rev
Log:
Force rulesets to include hard action reqs.

Fail sanity checks when an action's hard requirements are missing from one
or more of its action enablers rather than adding it via ruleset auto
adjustment. This avoids giving the impression that one can remove a hard
requirement from the ruleset.

Requested by Marko Lindqvist <cazfi>

See bug #24770

Modified:
    trunk/server/rscompat.c
    trunk/server/rssanity.c

Modified: trunk/server/rscompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/rscompat.c?rev=32988&r1=32987&r2=32988&view=diff
==============================================================================
--- trunk/server/rscompat.c     (original)
+++ trunk/server/rscompat.c     Fri Jun 24 01:47:22 2016
@@ -592,6 +592,12 @@
 
     enabler->action = ACTION_HOME_CITY;
 
+    /* The actor unit can't have the unit type flag NoHome. */
+    requirement_vector_append(&enabler->actor_reqs,
+                              req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL,
+                                              FALSE, FALSE, TRUE,
+                                              UTYF_NOHOME));
+
     /* The actor unit has a home city. (This is a feature since being
      * homeless is a big benefit. Unless the killunhomed setting is above
      * 0.) */
@@ -611,6 +617,11 @@
     enabler = action_enabler_new();
 
     enabler->action = ACTION_UPGRADE_UNIT;
+
+    /* The target city must be domestic. */
+    requirement_vector_append(&enabler->actor_reqs,
+                              req_from_str("DiplRel", "Local", FALSE,
+                                           FALSE, TRUE, "Is foreign"));
 
     action_enabler_add(enabler);
 
@@ -704,6 +715,26 @@
                                   req_from_str("BuildingGenus", "Local", FALSE,
                                                TRUE, TRUE, "SmallWonder"));
 
+      }
+
+      if (ae->action == ACTION_ESTABLISH_EMBASSY
+          || ae->action == ACTION_SPY_INVESTIGATE_CITY
+          || ae->action == ACTION_SPY_STEAL_GOLD
+          || ae->action == ACTION_STEAL_MAPS
+          || 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);
+        }
       }
     } action_enablers_iterate_end;
   }

Modified: trunk/server/rssanity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/rssanity.c?rev=32988&r1=32987&r2=32988&view=diff
==============================================================================
--- trunk/server/rssanity.c     (original)
+++ trunk/server/rssanity.c     Fri Jun 24 01:47:22 2016
@@ -949,6 +949,94 @@
         }
       } requirement_vector_iterate_end;
     } action_enabler_list_iterate_end;
+
+    if (!ignore_retired) {
+      /* Support for letting the following hard requirements be implicit
+       * were retired in Freeciv 3.0. Make sure that the opposite of each
+       * hard action requirement blocks all its action enablers. */
+
+      if (act == ACTION_ESTABLISH_EMBASSY
+          || act == ACTION_SPY_INVESTIGATE_CITY
+          || act == ACTION_SPY_STEAL_GOLD
+          || act == ACTION_STEAL_MAPS
+          || act == ACTION_SPY_STEAL_TECH
+          || act == ACTION_SPY_TARGETED_STEAL_TECH
+          || act == ACTION_SPY_INCITE_CITY
+          || act == ACTION_SPY_BRIBE_UNIT
+          || act == ACTION_CAPTURE_UNITS) {
+        /* Why this is a hard requirement: There is currently no point in
+         * allowing the listed actions against domestic targets.
+         * (Possible counter argument: crazy hack involving the Lua
+         * callback action_started_callback() to use an action to do
+         * something else. */
+        /* TODO: Unhardcode as a part of false flag operation support. */
+
+        struct requirement domestic_tgt
+            = req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
+                              FALSE, FALSE, TRUE, DRO_FOREIGN);
+
+        if (!action_id_blocked_by_situation_act(act, &domestic_tgt)) {
+          ruleset_error(LOG_ERROR,
+                        "All action enablers for %s must require a "
+                        "foreign target.",
+                        action_get_rule_name(act));
+          ok = FALSE;
+        }
+      }
+
+      if (act == ACTION_UPGRADE_UNIT) {
+        /* Why this is a hard requirement: Keep the old rules. Need to work
+         * out corner cases. */
+
+        struct requirement foreign_tgt
+            = req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
+                              FALSE, TRUE, TRUE, DRO_FOREIGN);
+
+        if (!action_id_blocked_by_situation_act(act, &foreign_tgt)) {
+          ruleset_error(LOG_ERROR,
+                        "All action enablers for %s must require a "
+                        "domestic target.",
+                        action_get_rule_name(act));
+          ok = FALSE;
+        }
+      }
+
+      if (act == ACTION_HOME_CITY) {
+        /* Why this is a hard requirement: Preserve semantics of NoHome
+         * flag. Need to replace other uses in game engine before this can
+         * be demoted to a regular unit flag. */
+
+        struct requirement nohome_flag
+            = req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL,
+                              FALSE, TRUE, TRUE, UTYF_NOHOME);
+
+        if (!action_id_blocked_by_situation_act(act, &nohome_flag)) {
+          ruleset_error(LOG_ERROR,
+                        "All action enablers for %s must require that "
+                        "the actor doesn't have the NoHome utype flag.",
+                        action_get_rule_name(act));
+          ok = FALSE;
+        }
+      }
+
+      if (act == ACTION_ATTACK) {
+        /* Why this is a hard requirement: Preserve semantics of NonMil
+         * flag. Need to replace other uses in game engine before this can
+         * be demoted to a regular unit flag. */
+
+        struct requirement nonmil_flag
+            = req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL,
+                              FALSE, TRUE, TRUE, UTYF_CIVILIAN);
+
+        if (!action_id_blocked_by_situation_act(act, &nonmil_flag)) {
+          ruleset_error(LOG_ERROR,
+                        "All action enablers for %s must require that "
+                        "the actor doesn't have the NonMil utype flag.",
+                        action_get_rule_name(act));
+          ok = FALSE;
+        }
+      }
+    }
   } action_iterate_end;
 
   /* There must be basic city style for each nation style to start with */
@@ -1126,88 +1214,6 @@
     }
   }
 
-  /* Hard coded action enabler requirements. */
-  action_enablers_iterate(enabler) {
-    enum gen_action action = enabler->action;
-
-    if (action == ACTION_ESTABLISH_EMBASSY
-        || action == ACTION_SPY_INVESTIGATE_CITY
-        || action == ACTION_SPY_STEAL_GOLD
-        || action == ACTION_STEAL_MAPS
-        || action == ACTION_SPY_STEAL_TECH
-        || action == ACTION_SPY_TARGETED_STEAL_TECH
-        || action == ACTION_SPY_INCITE_CITY
-        || action == ACTION_SPY_BRIBE_UNIT
-        || action == ACTION_CAPTURE_UNITS) {
-      /* Why this is a hard requirement: There is currently no point in
-       * allowing the listed actions against domestic targets.
-       * (Possible counter argument: crazy hack involving the Lua callback
-       * action_started_callback() to use an action to do something else. */
-      /* TODO: Unhardcode as a part of false flag operation support. */
-
-      struct requirement req
-          = req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
-                            FALSE, TRUE, TRUE, DRO_FOREIGN);
-
-      if (!is_req_in_vec(&req, &enabler->actor_reqs)) {
-        log_debug("Autorequiring that %s has a foreign target.",
-                  action_get_rule_name(action));
-
-        requirement_vector_append(&enabler->actor_reqs, req);
-      }
-    }
-
-    if (action == ACTION_UPGRADE_UNIT) {
-      /* Why this is a hard requirement: Keep the old rules. Need to work
-       * out corner cases. */
-
-      struct requirement req
-          = req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
-                            FALSE, FALSE, TRUE, DRO_FOREIGN);
-
-      if (!is_req_in_vec(&req, &enabler->actor_reqs)) {
-        log_debug("Autorequiring that %s has a domestic target.",
-                  action_get_rule_name(action));
-
-        requirement_vector_append(&enabler->actor_reqs, req);
-      }
-    }
-
-    if (action == ACTION_HOME_CITY) {
-      /* Why this is a hard requirement: Preserve semantics of NoHome
-       * flag. Need to replace other uses in game engine before this can
-       * be demoted to a regular unit flag. */
-
-      struct requirement req
-          = req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL,
-                            FALSE, FALSE, TRUE, UTYF_NOHOME);
-
-      if (!is_req_in_vec(&req, &enabler->actor_reqs)) {
-        log_debug("Autorequiring that %s can't be done to NoHome units.",
-                  action_get_rule_name(action));
-
-        requirement_vector_append(&enabler->actor_reqs, req);
-      }
-    }
-
-    if (action == ACTION_ATTACK) {
-      /* Why this is a hard requirement: Preserve semantics of NonMil
-       * flag. Need to replace other uses in game engine before this can
-       * be demoted to a regular unit flag. */
-
-      struct requirement req
-          = req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL,
-                            FALSE, FALSE, TRUE, UTYF_CIVILIAN);
-
-      if (!is_req_in_vec(&req, &enabler->actor_reqs)) {
-        log_debug("Autorequiring that %s can't be done to NonMil units.",
-                  action_get_rule_name(action));
-
-        requirement_vector_append(&enabler->actor_reqs, req);
-      }
-    }
-  } action_enablers_iterate_end;
-
   return ok;
 }
 


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

Reply via email to