From 6e55b20a4cba1f68f89f49ef51b4b25b12fbc128 Mon Sep 17 00:00:00 2001
From: Sveinung Kvilhaugsvik <sveinung84@users.sourceforge.net>
Date: Tue, 16 Feb 2021 15:48:59 +0100
Subject: [PATCH] Introduce universals_mean_unfulfilled().

Make it possible to check if the presence of any universal from a list
means that a requirement vector never can be fulfilled.

See osdn #41589
---
 common/requirements.c | 28 ++++++++++++++++++++++++++++
 common/requirements.h |  3 +++
 2 files changed, 31 insertions(+)

diff --git a/common/requirements.c b/common/requirements.c
index 69b1119b90..28080986a5 100644
--- a/common/requirements.c
+++ b/common/requirements.c
@@ -4242,6 +4242,34 @@ bool universal_is_mentioned_by_requirements(
   return FALSE;
 }
 
+/**********************************************************************//**
+  Returns TRUE iff the presence of any of the specified universals is
+  enough to guarantee that the specified requirement vector never will be
+  fulfilled.
+  @param reqs   the requirement vector that never should be fulfilled
+  @param unis   the universals that are present
+  @param n_unis the number of universals in unis
+  @return if the universals blocks fulfillment of the req vector
+**************************************************************************/
+bool universals_mean_unfulfilled(struct requirement_vector *reqs,
+                                 struct universal *unis,
+                                 size_t n_unis)
+{
+  int i;
+
+  for (i = 0; i < n_unis; i++) {
+    if (!universal_fulfills_requirements(FALSE, reqs, &unis[i])) {
+      /* This universal makes it impossible to fulfill the specified
+       * requirement vector */
+      return TRUE;
+    }
+  }
+
+  /* No specified universal is known to guarantee that the requirement
+   * vector never will be fulfilled. */
+  return FALSE;
+}
+
 /**********************************************************************//**
   Will the universal 'source' fulfill this requirement?
 **************************************************************************/
diff --git a/common/requirements.h b/common/requirements.h
index 672faa842b..e8b9abadf3 100644
--- a/common/requirements.h
+++ b/common/requirements.h
@@ -280,6 +280,9 @@ bool universal_fulfills_requirements(bool check_necessary,
                                      const struct universal *source);
 bool universal_is_relevant_to_requirement(const struct requirement *req,
                                           const struct universal *source);
+bool universals_mean_unfulfilled(struct requirement_vector *reqs,
+                                 struct universal *unis,
+                                 size_t n_unis);
 
 #define universals_iterate(_univ_) \
   {                                \
-- 
2.20.1