Author: sveinung
Date: Fri Sep 18 14:40:05 2015
New Revision: 29917

URL: http://svn.gna.org/viewcvs/freeciv?rev=29917&view=rev
Log:
A local building can contradict a building genus

Find local improvement requirements that contradicts (local) improvement
genus requirements.

See patch #6360

Modified:
    trunk/common/requirements.c

Modified: trunk/common/requirements.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/requirements.c?rev=29917&r1=29916&r2=29917&view=diff
==============================================================================
--- trunk/common/requirements.c (original)
+++ trunk/common/requirements.c Fri Sep 18 14:40:05 2015
@@ -930,6 +930,38 @@
 }
 
 /**************************************************************************
+  Returns TRUE if the specified building requirement contradicts the
+  specified building genus requirement.
+**************************************************************************/
+static bool impr_contra_genus(const struct requirement *impr_req,
+                              const struct requirement *genus_req)
+{
+  /* The input is sane. */
+  fc_assert_ret_val(impr_req->source.kind == VUT_IMPROVEMENT, FALSE);
+  fc_assert_ret_val(genus_req->source.kind == VUT_IMPR_GENUS, FALSE);
+
+  if (impr_req->range == REQ_RANGE_LOCAL
+      && genus_req->range == REQ_RANGE_LOCAL) {
+    /* Applies to the same target building. */
+
+    if (impr_req->present && !genus_req->present) {
+      /* The target building can't not have the genus it has. */
+      return (impr_req->source.value.building->genus
+              == genus_req->source.value.impr_genus);
+    }
+
+    if (impr_req->present && genus_req->present) {
+      /* The target building can't have another genus than it has. */
+      return (impr_req->source.value.building->genus
+              != genus_req->source.value.impr_genus);
+    }
+  }
+
+  /* No special knowledge. */
+  return are_requirements_opposites(impr_req, genus_req);
+}
+
+/**************************************************************************
   Returns TRUE if req1 and req2 contradicts each other.
 
   TODO: If information about what entity each requirement type will be
@@ -940,6 +972,22 @@
                                      const struct requirement *req2)
 {
   switch (req1->source.kind) {
+  case VUT_IMPROVEMENT:
+    if (req2->source.kind == VUT_IMPR_GENUS) {
+      return impr_contra_genus(req1, req2);
+    }
+
+    /* No special knowledge. */
+    return are_requirements_opposites(req1, req2);
+    break;
+  case VUT_IMPR_GENUS:
+    if (req2->source.kind == VUT_IMPROVEMENT) {
+      return impr_contra_genus(req2, req1);
+    }
+
+    /* No special knowledge. */
+    return are_requirements_opposites(req1, req2);
+    break;
   case VUT_DIPLREL:
     if (req2->source.kind != VUT_DIPLREL) {
       /* Finding contradictions across requirement kinds aren't supported


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

Reply via email to