<URL: http://bugs.freeciv.org/Ticket/Display.html?id=38245 >

On 16/03/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  Sun Tzu's War Academy is always displayed as redundant.
>
>  I think this relates to the fact that its effects have nreq UnitFlag 
> Diplomat.

 Totally untested patch

 Be always optimistic about effects: enabling requirements are
considered TRUE by default, disabling requirements FALSE.


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aicity.c freeciv/ai/aicity.c
--- freeciv/ai/aicity.c	2007-08-01 17:17:27.000000000 +0300
+++ freeciv/ai/aicity.c	2007-08-04 05:10:41.000000000 +0300
@@ -683,7 +683,8 @@
 
   requirement_vector_iterate(&pimpr->reqs, preq) {
     const bool active = is_req_active(pplayer, pcity, pimpr,
-                                      pcity->tile, NULL, NULL, NULL, preq);
+                                      pcity->tile, NULL, NULL, NULL, preq,
+                                      TRUE);
 
     if (preq->source.type == REQ_TECH && !active) {
       /* Found a missing technology requirement for this improvement. */
@@ -859,7 +860,7 @@
         continue;
       }
       if (!is_req_active(pplayer, pcity, pimpr, NULL, NULL, NULL, NULL,
-			 preq)) {
+			 preq, TRUE)) {
 	active = FALSE;
 	if (preq->source.type == REQ_TECH) {
 	  /* This missing requirement is a missing tech requirement.
diff -Nurd -X.diff_ignore freeciv/common/base.c freeciv/common/base.c
--- freeciv/common/base.c	2007-08-01 17:17:24.000000000 +0300
+++ freeciv/common/base.c	2007-08-04 05:06:01.000000000 +0300
@@ -91,7 +91,7 @@
   }
 
   return are_reqs_active(unit_owner(punit), NULL, NULL, ptile,
-                         unit_type(punit), NULL, NULL, &pbase->reqs);
+                         unit_type(punit), NULL, NULL, &pbase->reqs, TRUE);
 }
 
 /****************************************************************************
diff -Nurd -X.diff_ignore freeciv/common/city.c freeciv/common/city.c
--- freeciv/common/city.c	2007-08-01 17:17:24.000000000 +0300
+++ freeciv/common/city.c	2007-08-04 05:08:09.000000000 +0300
@@ -411,7 +411,7 @@
 
   return are_reqs_active(city_owner(pcity), pcity, NULL,
 			 pcity->tile, NULL, NULL, NULL,
-			 &building->reqs);
+			 &building->reqs, TRUE);
 }
 
 /**************************************************************************
@@ -448,7 +448,7 @@
   requirement_vector_iterate(&building->reqs, preq) {
     if (is_req_unchanging(preq)
 	&& !is_req_active(city_owner(pcity), pcity, NULL,
-	  		  pcity->tile, NULL, NULL, NULL, preq)) {
+	  		  pcity->tile, NULL, NULL, NULL, preq, TRUE)) {
       return FALSE;
     }
   } requirement_vector_iterate_end;
@@ -531,7 +531,7 @@
 {
   return are_reqs_active(city_owner(pcity), pcity, NULL,
 			 NULL, NULL, NULL, NULL,
-			 &get_specialist(type)->reqs);
+			 &get_specialist(type)->reqs, TRUE);
 }
 
 /****************************************************************************
@@ -1102,7 +1102,7 @@
   while ((replace = city_styles[prev].replaced_by) != -1) {
     prev = replace;
     if (are_reqs_active(plr, NULL, NULL, NULL, NULL, NULL, NULL,
-			&city_styles[replace].reqs)) {
+			&city_styles[replace].reqs, TRUE)) {
       style = replace;
     }
   }
diff -Nurd -X.diff_ignore freeciv/common/effects.c freeciv/common/effects.c
--- freeciv/common/effects.c	2007-08-01 17:17:24.000000000 +0300
+++ freeciv/common/effects.c	2007-08-04 05:01:06.000000000 +0300
@@ -573,7 +573,7 @@
     if (is_req_active(target_player, target_city, target_building,
 		      target_tile, target_unittype, target_output,
 		      target_specialist,
-		      preq)) {
+		      preq, FALSE)) {
       return TRUE;
     }
   } requirement_list_iterate_end;
@@ -581,7 +581,7 @@
 }
 
 /**************************************************************************
-  Return TRUE iff any of the disabling requirements for this effect are
+  Return TRUE iff all of the enabling requirements for this effect are
   active (an effect is active if all of its enabling requirements and
   none of its disabling ones are active).
 **************************************************************************/
@@ -598,7 +598,7 @@
     if (!is_req_active(target_player, target_city, target_building,
 		       target_tile, target_unittype, target_output,
 		       target_specialist,
-		       preq)) {
+		       preq, TRUE)) {
       return FALSE;
     }
   } requirement_list_iterate_end;
@@ -668,7 +668,7 @@
     if (!is_req_active(target_player, target_city, target_building,
 		       target_tile, target_unittype, target_output,
 		       target_specialist,
-		       preq)) {
+		       preq, TRUE)) {
       return FALSE;
     }
   } requirement_list_iterate_end;
diff -Nurd -X.diff_ignore freeciv/common/government.c freeciv/common/government.c
--- freeciv/common/government.c	2007-08-02 23:25:07.000000000 +0300
+++ freeciv/common/government.c	2007-08-04 05:08:23.000000000 +0300
@@ -228,7 +228,7 @@
   }
 
   return are_reqs_active(pplayer, NULL, NULL, NULL, NULL, NULL, NULL,
-			 &gov->reqs);
+			 &gov->reqs, TRUE);
 }
 
 /**************************************************************************
diff -Nurd -X.diff_ignore freeciv/common/improvement.c freeciv/common/improvement.c
--- freeciv/common/improvement.c	2007-08-01 17:17:24.000000000 +0300
+++ freeciv/common/improvement.c	2007-08-04 05:02:43.000000000 +0300
@@ -324,7 +324,7 @@
 
   requirement_vector_iterate(&impr->reqs, preq) {
     if (preq->range >= REQ_RANGE_PLAYER
-        && !is_req_active(p, NULL, NULL, NULL, NULL, NULL, NULL, preq)) {
+        && !is_req_active(p, NULL, NULL, NULL, NULL, NULL, NULL, preq, TRUE)) {
       return FALSE;
     }
   } requirement_vector_iterate_end;
@@ -404,7 +404,7 @@
   requirement_vector_iterate(&building->reqs, preq) {
     if (preq->range >= REQ_RANGE_PLAYER
 	&& is_req_unchanging(preq)
-        && !is_req_active(p, NULL, NULL, NULL, NULL, NULL, NULL, preq)) {
+        && !is_req_active(p, NULL, NULL, NULL, NULL, NULL, NULL, preq, TRUE)) {
       return FALSE;
     }
   } requirement_vector_iterate_end;
diff -Nurd -X.diff_ignore freeciv/common/requirements.c freeciv/common/requirements.c
--- freeciv/common/requirements.c	2007-08-01 17:17:24.000000000 +0300
+++ freeciv/common/requirements.c	2007-08-04 05:05:07.000000000 +0300
@@ -805,14 +805,20 @@
 ****************************************************************************/
 static bool is_unitflag_in_range(const struct unit_type *target_unittype,
 				 enum req_range range, bool survives,
-				 enum unit_flag_id unitflag)
+				 enum unit_flag_id unitflag,
+                                 bool enabled_by_default)
 {
   /* If no target_unittype is given, we allow the req to be met.  This is
    * to allow querying of certain effect types (like the presence of city
    * walls) without actually knowing the target unit. */
-  return (range == REQ_RANGE_LOCAL
-	  && (!target_unittype
-	      || utype_has_flag(target_unittype, unitflag)));
+  if (range != REQ_RANGE_LOCAL) {
+    return FALSE;
+  }
+  if (!target_unittype) {
+    return enabled_by_default;
+  }
+
+  return utype_has_flag(target_unittype, unitflag);
 }
 
 /****************************************************************************
@@ -848,7 +854,8 @@
 		   const struct unit_type *target_unittype,
 		   const struct output_type *target_output,
 		   const struct specialist *target_specialist,
-		   const struct requirement *req)
+		   const struct requirement *req,
+                   const bool enabled_by_default)
 {
   bool eval = FALSE;
 
@@ -900,7 +907,8 @@
   case REQ_UNITFLAG:
     eval = is_unitflag_in_range(target_unittype,
 				req->range, req->survives,
-				req->source.value.unitflag);
+				req->source.value.unitflag,
+                                enabled_by_default);
     break;
   case REQ_UNITCLASS:
     eval = is_unitclass_in_range(target_unittype,
@@ -960,13 +968,14 @@
 		     const struct unit_type *target_unittype,
 		     const struct output_type *target_output,
 		     const struct specialist *target_specialist,
-		     const struct requirement_vector *reqs)
+		     const struct requirement_vector *reqs,
+                     const bool enabled_by_default)
 {
   requirement_vector_iterate(reqs, preq) {
     if (!is_req_active(target_player, target_city, target_building,
 		       target_tile, target_unittype, target_output,
 		       target_specialist,
-		       preq)) {
+		       preq, enabled_by_default)) {
       return FALSE;
     }
   } requirement_vector_iterate_end;
diff -Nurd -X.diff_ignore freeciv/common/requirements.h freeciv/common/requirements.h
--- freeciv/common/requirements.h	2007-08-01 17:17:24.000000000 +0300
+++ freeciv/common/requirements.h	2007-08-04 05:05:28.000000000 +0300
@@ -126,7 +126,8 @@
 		   const struct unit_type *target_unittype,
 		   const struct output_type *target_output,
 		   const struct specialist *target_specialist,
-		   const struct requirement *req);
+		   const struct requirement *req,
+                   const bool enabled_by_default);
 bool are_reqs_active(const struct player *target_player,
 		     const struct city *target_city,
 		     const struct impr_type *target_building,
@@ -134,7 +135,8 @@
 		     const struct unit_type *target_unittype,
 		     const struct output_type *target_output,
 		     const struct specialist *target_specialist,
-		     const struct requirement_vector *reqs);
+		     const struct requirement_vector *reqs,
+                     const bool enabled_by_default);
 
 bool is_req_unchanging(const struct requirement *req);
 
diff -Nurd -X.diff_ignore freeciv/server/citytools.c freeciv/server/citytools.c
--- freeciv/server/citytools.c	2007-08-01 17:17:23.000000000 +0300
+++ freeciv/server/citytools.c	2007-08-04 05:11:27.000000000 +0300
@@ -2134,7 +2134,7 @@
 	  if (preq->source.type == REQ_TERRAIN
 	      && !is_req_active(city_owner(pcity), pcity, NULL,
 				NULL, NULL, NULL, NULL,
-				preq)) {
+				preq, TRUE)) {
           do_sell_building(pplayer, pcity, impr);
           notify_player(pplayer, tile1, E_IMP_SOLD,
                            _("You sell %s in %s (now landlocked)"
diff -Nurd -X.diff_ignore freeciv/server/cityturn.c freeciv/server/cityturn.c
--- freeciv/server/cityturn.c	2007-08-01 17:17:23.000000000 +0300
+++ freeciv/server/cityturn.c	2007-08-04 05:11:51.000000000 +0300
@@ -763,7 +763,7 @@
 	/* Nope, no use.  *sigh*  */
 	requirement_vector_iterate(&building->reqs, preq) {
 	  if (!is_req_active(pplayer, pcity, NULL, NULL, NULL, NULL, NULL,
-			     preq)) {
+			     preq, TRUE)) {
 	    known = TRUE;
 	    switch (preq->source.type) {
 	    case REQ_TECH:
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to