Author: sveinung
Date: Fri May  8 15:10:31 2015
New Revision: 29021

URL: http://svn.gna.org/viewcvs/freeciv?rev=29021&view=rev
Log:
Identify self contradicting MinMoveFrags reqs.

See patch #6068

Modified:
    branches/S2_6/common/requirements.c

Modified: branches/S2_6/common/requirements.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/requirements.c?rev=29021&r1=29020&r2=29021&view=diff
==============================================================================
--- branches/S2_6/common/requirements.c (original)
+++ branches/S2_6/common/requirements.c Fri May  8 15:10:31 2015
@@ -881,24 +881,52 @@
 bool are_requirements_contradictions(const struct requirement *req1,
                                      const struct requirement *req2)
 {
-  if (req1->source.kind == VUT_DIPLREL
-      && req2->source.kind == VUT_DIPLREL) {
-    /* Use the special knowledge about DiplRel requirements to find
-     * contradictions. */
-
-    bv_diplrel_all_reqs req1_contra;
-    int req2_pos;
-
-    req1_contra = diplrel_req_contradicts(req1);
-    req2_pos = requirement_diplrel_ereq(req2->source.value.diplrel,
-                                        req2->range,
-                                        req2->present);
-
-    return BV_ISSET(req1_contra, req2_pos);
-  } else {
+  switch (req1->source.kind) {
+  case VUT_DIPLREL:
+    if (req2->source.kind != VUT_DIPLREL) {
+      /* Finding contradictions across requirement kinds aren't supported
+       * for DiplRel requirements. */
+      return FALSE;
+    } else {
+      /* Use the special knowledge about DiplRel requirements to find
+       * contradictions. */
+
+      bv_diplrel_all_reqs req1_contra;
+      int req2_pos;
+
+      req1_contra = diplrel_req_contradicts(req1);
+      req2_pos = requirement_diplrel_ereq(req2->source.value.diplrel,
+                                          req2->range,
+                                          req2->present);
+
+      return BV_ISSET(req1_contra, req2_pos);
+    }
+    break;
+  case VUT_MINMOVES:
+    if (req2->source.kind != VUT_MINMOVES) {
+      /* Finding contradictions across requirement kinds aren't supported
+       * for MinMoveFrags requirements. */
+      return FALSE;
+    } else if (req1->present == req2->present) {
+      /* No contradiction possible. */
+      return FALSE;
+    } else {
+      /* Number of move fragments left can't be larger than the number
+       * required to be present and smaller than the number required to not
+       * be present when the number required to be present is smaller than
+       * the number required to not be present. */
+      if (req1->present) {
+        return req1->source.value.minmoves > req2->source.value.minmoves;
+      } else {
+        return req1->source.value.minmoves < req2->source.value.minmoves;
+      }
+    }
+    break;
+  default:
     /* No special knowledge exists. All that can be done is to detect if
      * the requirements are opposite to each other. */
     return are_requirements_opposites(req1, req2);
+    break;
   }
 }
 


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

Reply via email to