Author: sveinung
Date: Thu Mar 17 16:43:19 2016
New Revision: 32258

URL: http://svn.gna.org/viewcvs/freeciv?rev=32258&view=rev
Log:
Metaknowledge evaluation RPT_POSSIBLE mode.

Meta knowledge requirement evaluation considers what information a player
has access to when evaluating a requirement. It can end up returning maybe
when the player don't have the needed information. Up until now it has only
supported the RPT_CERTAIN requirement evaluation mode.

Support the RPT_POSSIBLE requirement evaluation mode in meta knowledge
requirement evaluation.

See patch #7066

Modified:
    trunk/common/actions.c
    trunk/common/metaknowledge.c
    trunk/common/metaknowledge.h

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=32258&r1=32257&r2=32258&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Thu Mar 17 16:43:19 2016
@@ -1887,13 +1887,13 @@
                                     actor_building, actor_tile,
                                     actor_unit, actor_output,
                                     actor_specialist,
-                                    &enabler->actor_reqs),
+                                    &enabler->actor_reqs, RPT_CERTAIN),
                       mke_eval_reqs(actor_player, target_player,
                                     actor_player, target_city,
                                     target_building, target_tile,
                                     target_unit, target_output,
                                     target_specialist,
-                                    &enabler->target_reqs));
+                                    &enabler->target_reqs, RPT_CERTAIN));
     if (current == TRI_YES) {
       return TRI_YES;
     } else if (current == TRI_MAYBE) {
@@ -1928,7 +1928,7 @@
                                    target_building, target_tile,
                                    target_unit, target_output,
                                    target_specialist,
-                                   &(peffect->reqs))) {
+                                   &(peffect->reqs), RPT_CERTAIN)) {
       return FALSE;
     }
   } effect_list_iterate_end;

Modified: trunk/common/metaknowledge.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/metaknowledge.c?rev=32258&r1=32257&r2=32258&view=diff
==============================================================================
--- trunk/common/metaknowledge.c        (original)
+++ trunk/common/metaknowledge.c        Thu Mar 17 16:43:19 2016
@@ -188,7 +188,8 @@
                             const struct unit *target_unit,
                             const struct output_type *target_output,
                             const struct specialist *target_specialist,
-                            const struct requirement *req)
+                            const struct requirement *req,
+                            const enum   req_problem_type prob_type)
 {
   fc_assert_ret_val_msg(NULL != pow_player, false, "No point of view");
 
@@ -200,6 +201,12 @@
       || req->source.kind == VUT_MINHP) {
     switch (req->range) {
     case REQ_RANGE_LOCAL:
+      if (target_unit == NULL) {
+        /* The unit may exist but not be passed when the problem type is
+         * RPT_POSSIBLE. */
+        return prob_type == RPT_CERTAIN;
+      }
+
       return target_unit && can_player_see_unit(pow_player, target_unit);
     case REQ_RANGE_CADJACENT:
     case REQ_RANGE_ADJACENT:
@@ -217,6 +224,12 @@
 
   if (req->source.kind == VUT_UNITSTATE) {
     fc_assert_ret_val_msg(req->range == REQ_RANGE_LOCAL, FALSE, "Wrong range");
+
+    if (target_unit == NULL) {
+      /* The unit may exist but not be passed when the problem type is
+       * RPT_POSSIBLE. */
+      return prob_type == RPT_CERTAIN;
+    }
 
     switch (req->source.value.unit_state) {
     case USP_TRANSPORTED:
@@ -237,6 +250,12 @@
 
   if (req->source.kind == VUT_MINMOVES) {
     fc_assert_ret_val_msg(req->range == REQ_RANGE_LOCAL, FALSE, "Wrong range");
+
+    if (target_unit == NULL) {
+      /* The unit may exist but not be passed when the problem type is
+       * RPT_POSSIBLE. */
+      return prob_type == RPT_CERTAIN;
+    }
 
     switch (req->range) {
     case REQ_RANGE_LOCAL:
@@ -260,6 +279,13 @@
   if (req->source.kind == VUT_DIPLREL) {
     switch (req->range) {
     case REQ_RANGE_LOCAL:
+      if (other_player == NULL
+          || target_player == NULL) {
+        /* The two players may exist but not be passed when the problem
+         * type is RPT_POSSIBLE. */
+        return prob_type == RPT_CERTAIN;
+      }
+
       if (pow_player == target_player
           || pow_player == other_player)  {
         return TRUE;
@@ -273,6 +299,12 @@
       /* TODO: Non symmetric diplomatic relationships. */
       break;
     case REQ_RANGE_PLAYER:
+      if (target_player == NULL) {
+        /* The target player may exist but not be passed when the problem
+         * type is RPT_POSSIBLE. */
+        return prob_type == RPT_CERTAIN;
+      }
+
       if (pow_player == target_player) {
         return TRUE;
       }
@@ -304,7 +336,13 @@
     }
   }
 
-  if (req->source.kind == VUT_MINSIZE && target_city != NULL) {
+  if (req->source.kind == VUT_MINSIZE) {
+    if (target_city == NULL) {
+      /* The city may exist but not be passed when the problem type is
+       * RPT_POSSIBLE. */
+      return prob_type == RPT_CERTAIN;
+    }
+
     if (mke_can_see_city_externals(pow_player, target_city)) {
       return TRUE;
     }
@@ -312,6 +350,12 @@
 
   if (req->source.kind == VUT_CITYTILE) {
     struct city *pcity;
+
+    if (target_tile == NULL) {
+      /* The tile may exist but not be passed when the problem type is
+       * RPT_POSSIBLE. */
+      return prob_type == RPT_CERTAIN;
+    }
 
     switch (req->range) {
     case REQ_RANGE_LOCAL:
@@ -373,8 +417,9 @@
     fc_assert(req->range == REQ_RANGE_LOCAL);
 
     if (!target_city) {
-      /* Can't be. No city to contain it. */
-      return TRUE;
+      /* RPT_CERTAIN: Can't be. No city to contain it.
+       * RPT_POSSIBLE: A city like that may exist but not be passed. */
+      return prob_type == RPT_CERTAIN;
     }
 
     /* Local BuildingGenus could be about city production. */
@@ -401,8 +446,9 @@
     case REQ_RANGE_CITY:
     case REQ_RANGE_LOCAL:
       if (!target_city) {
-        /* Can't be. No city to contain it. */
-        return TRUE;
+        /* RPT_CERTAIN: Can't be. No city to contain it.
+         * RPT_POSSIBLE: A city like that may exist but not be passed. */
+        return prob_type == RPT_CERTAIN;
       }
 
       if (can_player_see_city_internals(pow_player, target_city)) {
@@ -430,25 +476,51 @@
 
   if (req->source.kind == VUT_NATION
       || req->source.kind == VUT_NATIONGROUP) {
+    if (!target_player
+        && (req->range == REQ_RANGE_PLAYER
+            || req->range == REQ_RANGE_TEAM
+            || req->range == REQ_RANGE_ALLIANCE)) {
+      /* The player (that can have a nationality or be alllied to someone
+       * with the nationality) may exist but not be passed when the problem
+       * type is RPT_POSSIBLE. */
+      return prob_type == RPT_CERTAIN;
+    }
+
     return TRUE;
   }
 
   if (req->source.kind == VUT_ADVANCE || req->source.kind == VUT_TECHFLAG) {
-    if (req->range == REQ_RANGE_PLAYER
-        && can_see_techs_of_target(pow_player, target_player)) {
-      return TRUE;
+    if (req->range == REQ_RANGE_PLAYER) {
+      if (!target_player) {
+        /* The player (that may or may not possess the tech) may exist but
+         * not be passed when the problem type is RPT_POSSIBLE. */
+        return prob_type == RPT_CERTAIN;
+      }
+
+      return can_see_techs_of_target(pow_player, target_player);
     }
   }
 
   if (req->source.kind == VUT_GOVERNMENT) {
-    if (req->range == REQ_RANGE_PLAYER
-        && (pow_player == target_player
-            || could_intel_with_player(pow_player, target_player))) {
-      return TRUE;
+    if (req->range == REQ_RANGE_PLAYER) {
+      if (!target_player) {
+        /* The player (that may or may not possess the tech) may exist but
+         * not be passed when the problem type is RPT_POSSIBLE. */
+        return prob_type == RPT_CERTAIN;
+      }
+
+      return (pow_player == target_player
+              || could_intel_with_player(pow_player, target_player));
     }
   }
 
   if (req->source.kind == VUT_MAXTILEUNITS) {
+    if (target_tile == NULL) {
+      /* The tile may exist but not be passed when the problem type is
+       * RPT_POSSIBLE. */
+      return prob_type == RPT_CERTAIN;
+    }
+
     switch (req->range) {
     case REQ_RANGE_LOCAL:
       return can_player_see_hypotetic_units_at(pow_player, target_tile);
@@ -494,6 +566,12 @@
       || req->source.kind == VUT_EXTRAFLAG
       || req->source.kind == VUT_BASEFLAG
       || req->source.kind == VUT_BASEFLAG) {
+    if (target_tile == NULL) {
+      /* The tile may exist but not be passed when the problem type is
+       * RPT_POSSIBLE. */
+      return prob_type == RPT_CERTAIN;
+    }
+
     switch (req->range) {
     case REQ_RANGE_LOCAL:
       return is_tile_seen(pow_player, target_tile);
@@ -553,14 +631,15 @@
              const struct unit *target_unit,
              const struct output_type *target_output,
              const struct specialist *target_specialist,
-             const struct requirement *req)
+             const struct requirement *req,
+             const enum   req_problem_type prob_type)
 {
   const struct unit_type *target_unittype;
 
   if (!is_req_knowable(pow_player, target_player, other_player,
                        target_city, target_building, target_tile,
                        target_unit, target_output,
-                       target_specialist, req)) {
+                       target_specialist, req, prob_type)) {
     return TRI_MAYBE;
   }
 
@@ -572,7 +651,7 @@
 
   if (is_req_active(target_player, other_player, target_city,
                     target_building, target_tile, target_unit, target_unittype,
-                    target_output, target_specialist, NULL, req, RPT_CERTAIN)) 
{
+                    target_output, target_specialist, NULL, req, prob_type)) {
     return TRI_YES;
   } else {
     return TRI_NO;
@@ -594,7 +673,8 @@
               const struct unit *target_unit,
               const struct output_type *target_output,
               const struct specialist *target_specialist,
-              const struct requirement_vector *reqs)
+              const struct requirement_vector *reqs,
+              const enum   req_problem_type prob_type)
 {
   enum fc_tristate current;
   enum fc_tristate result;
@@ -604,7 +684,7 @@
     current = mke_eval_req(pow_player, target_player, other_player,
                            target_city, target_building, target_tile,
                            target_unit, target_output,
-                           target_specialist, preq);
+                           target_specialist, preq, prob_type);
     if (current == TRI_NO) {
       return TRI_NO;
     } else if (current == TRI_MAYBE) {

Modified: trunk/common/metaknowledge.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/metaknowledge.h?rev=32258&r1=32257&r2=32258&view=diff
==============================================================================
--- trunk/common/metaknowledge.h        (original)
+++ trunk/common/metaknowledge.h        Thu Mar 17 16:43:19 2016
@@ -34,7 +34,8 @@
              const struct unit *target_unit,
              const struct output_type *target_output,
              const struct specialist *target_specialist,
-             const struct requirement *req);
+             const struct requirement *req,
+             const enum   req_problem_type prob_type);
 
 enum fc_tristate
 mke_eval_reqs(const struct player *pow_player,
@@ -46,7 +47,8 @@
               const struct unit *target_unit,
               const struct output_type *target_output,
               const struct specialist *target_specialist,
-              const struct requirement_vector *reqs);
+              const struct requirement_vector *reqs,
+              const enum   req_problem_type prob_type);
 
 
 bool can_see_techs_of_target(const struct player *pow_player,


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

Reply via email to