From 01d565aab05a050bc87bb3d7a973147eb4fda75f Mon Sep 17 00:00:00 2001
From: Sveinung Kvilhaugsvik <sveinung84@users.sourceforge.net>
Date: Tue, 16 Feb 2021 16:19:15 +0100
Subject: [PATCH] Introduce universals_say_everything().

Make it possible to check if the specified universals is everything required
to find out whether the specified requirement vector is fulfilled or not.

See osdn #41590
---
 common/requirements.c | 47 +++++++++++++++++++++++++++++++++++++++++++
 common/requirements.h |  3 +++
 2 files changed, 50 insertions(+)

diff --git a/common/requirements.c b/common/requirements.c
index 28080986a5..1005237bbe 100644
--- a/common/requirements.c
+++ b/common/requirements.c
@@ -4270,6 +4270,53 @@ bool universals_mean_unfulfilled(struct requirement_vector *reqs,
   return FALSE;
 }
 
+/**********************************************************************//**
+  Returns TRUE iff the presence of the specified universals is enough to
+  know if the specified requirement vector is fulfilled. This means that
+  the requirement vector can't check anything it can't find in the listed
+  universals.
+  Note that TRUE is returned both when the requirement vector is known to
+  be fulfilled and when it is known to be unfulfilled.
+  @param reqs   the requirement vector certainty is wanted about
+  @param unis   the universals that are present
+  @param n_unis the number of universals in unis
+  @return TRUE iff the specified universals is everything required to find
+               out whether the specified requirement vector is fulfilled or
+               not
+**************************************************************************/
+bool universals_say_everything(struct requirement_vector *reqs,
+                               struct universal *unis,
+                               size_t n_unis)
+{
+  requirement_vector_iterate(reqs, preq) {
+    int i;
+    bool req_mentioned_a_source = FALSE;
+
+    for (i = 0; i < n_unis; i++) {
+      switch (universal_fulfills_requirement(preq, &(unis[i]))) {
+      case ITF_NO:
+      case ITF_YES:
+        /* this req matched this source */
+        req_mentioned_a_source = TRUE;
+        break;
+      case ITF_NOT_APPLICABLE:
+        /* Not a mention. */
+        break;
+      }
+    }
+
+    if (!req_mentioned_a_source) {
+      /* A requirement not relevant to any of the specified universals was
+       * found in the requirement vector. */
+      return FALSE;
+    }
+  } requirement_vector_iterate_end;
+
+  /* No requirement not relevant to any of the specified universals was
+   * found in the requirement vector. */
+  return TRUE;
+}
+
 /**********************************************************************//**
   Will the universal 'source' fulfill this requirement?
 **************************************************************************/
diff --git a/common/requirements.h b/common/requirements.h
index e8b9abadf3..40e9830115 100644
--- a/common/requirements.h
+++ b/common/requirements.h
@@ -283,6 +283,9 @@ bool universal_is_relevant_to_requirement(const struct requirement *req,
 bool universals_mean_unfulfilled(struct requirement_vector *reqs,
                                  struct universal *unis,
                                  size_t n_unis);
+bool universals_say_everything(struct requirement_vector *reqs,
+                               struct universal *unis,
+                               size_t n_unis);
 
 #define universals_iterate(_univ_) \
   {                                \
-- 
2.20.1