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

2007/8/11 ba...@actrix.co.nz <ba...@actrix.co.nz>:
>
> Hi
>
> With rndCiv i use Wonders to define special races,
> ie if you build "The Elves" wonder you can build Elvish units.
>
> I found that this didn't work, so i made building "The Elves"
> allowed you to build "Elveshome" in your cities which allowed
> you to build Elvish units.

 Only now I understood this bug report; how badly broken that part of
code is. This far I assumed you referred to wonders at different
range, but actually even local wonders cannot enable unit building. So
they do *worse* than normal buildings.

 Untested fix attached


 - ML

diff -Nurd -X.diff_ignore freeciv/common/improvement.c freeciv/common/improvement.c
--- freeciv/common/improvement.c	2008-10-27 04:13:30.000000000 +0200
+++ freeciv/common/improvement.c	2009-05-05 01:23:15.000000000 +0300
@@ -532,6 +532,20 @@
 }
 
 /**************************************************************************
+  Get the player owning this small wonder.
+**************************************************************************/
+struct player *great_wonder_owner(const struct impr_type *pimprove)
+{
+  struct city *pcity = find_city_from_great_wonder(pimprove);
+
+  if (!pcity) {
+    return NULL;
+  }
+
+  return city_owner(pcity);
+}
+
+/**************************************************************************
   Get the player city with this small wonder.
 **************************************************************************/
 struct city *find_city_from_small_wonder(const struct player *pplayer,
diff -Nurd -X.diff_ignore freeciv/common/improvement.h freeciv/common/improvement.h
--- freeciv/common/improvement.h	2008-10-27 04:13:30.000000000 +0200
+++ freeciv/common/improvement.h	2009-05-05 01:24:30.000000000 +0300
@@ -116,6 +116,7 @@
 struct city *find_city_from_great_wonder(const struct impr_type *pimprove);
 struct city *find_city_from_small_wonder(const struct player *pplayer,
 					 const struct impr_type *pimprove);
+struct player *great_wonder_owner(const struct impr_type *pimprove);
 
 /* player related improvement functions */
 bool improvement_obsolete(const struct player *pplayer,
diff -Nurd -X.diff_ignore freeciv/common/unittype.c freeciv/common/unittype.c
--- freeciv/common/unittype.c	2008-10-27 04:13:30.000000000 +0200
+++ freeciv/common/unittype.c	2009-05-05 01:24:02.000000000 +0300
@@ -697,9 +697,21 @@
   /* If the unit has a building requirement, we check to see if the player
    * can build that building.  Note that individual cities may not have
    * that building, so they still may not be able to build the unit. */
-  if (punittype->need_improvement
-      && !can_player_build_improvement_direct(p, punittype->need_improvement)) {
-    return FALSE;
+  if (punittype->need_improvement) {
+    if (is_great_wonder(punittype->need_improvement) &&
+        great_wonder_was_built(punittype->need_improvement)) {
+      /* It's already built great wonder */
+      if (great_wonder_owner(punittype->need_improvement) != p) {
+        /* Not owned by this player. Either destroyed or owned by somebody
+         * else. */
+        return FALSE;
+      }
+    } else {
+      if (!can_player_build_improvement_direct(p,
+                                               punittype->need_improvement)) {
+        return FALSE;
+      }
+    }
   }
 
   return TRUE;
diff -Nurd -X.diff_ignore freeciv/common/improvement.c freeciv/common/improvement.c
--- freeciv/common/improvement.c	2008-07-09 10:44:51.000000000 +0300
+++ freeciv/common/improvement.c	2009-05-05 01:31:31.000000000 +0300
@@ -473,6 +473,20 @@
 }
 
 /**************************************************************************
+  Get the player owning this small wonder.
+**************************************************************************/
+struct player *great_wonder_owner(Impr_type_id id)
+{
+  struct city *pcity = find_city_from_great_wonder(id);
+
+  if (!pcity) {
+    return NULL;
+  }
+
+  return city_owner(pcity);
+}
+
+/**************************************************************************
   Get the player city with this small wonder.
 **************************************************************************/
 struct city *find_city_from_small_wonder(const struct player *pplayer,
diff -Nurd -X.diff_ignore freeciv/common/improvement.h freeciv/common/improvement.h
--- freeciv/common/improvement.h	2008-07-09 10:44:51.000000000 +0300
+++ freeciv/common/improvement.h	2009-05-05 01:30:48.000000000 +0300
@@ -132,6 +132,7 @@
 struct city *find_city_from_great_wonder(Impr_type_id id);
 struct city *find_city_from_small_wonder(const struct player *pplayer,
 					 Impr_type_id id);
+struct player *great_wonder_owner(Impr_type_id id);
 
 bool great_wonder_was_built(Impr_type_id id);
 
diff -Nurd -X.diff_ignore freeciv/common/unittype.c freeciv/common/unittype.c
--- freeciv/common/unittype.c	2007-07-04 14:04:25.000000000 +0300
+++ freeciv/common/unittype.c	2009-05-05 01:34:53.000000000 +0300
@@ -535,9 +535,20 @@
    * can build that building.  Note that individual cities may not have
    * that building, so they still may not be able to build the unit. */
   impr_req = punittype->impr_requirement;
-  if (impr_req != B_LAST
-      && !can_player_build_improvement_direct(p, impr_req)) {
-    return FALSE;
+  if (impr_req != B_LAST) {
+    if (is_great_wonder(impr_req) &&
+        great_wonder_was_built(impr_req)) {
+      /* It's already built great wonder */
+      if (great_wonder_owner(impr_req) != p) {
+        /* Not owned by this player. Either destroyed or owned by somebody
+         * else. */
+        return FALSE;
+      }
+    } else {
+      if (!can_player_build_improvement_direct(p, impr_req)) {
+        return FALSE;
+      }
+    }
   }
 
   return TRUE;
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to