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

2008/7/4 Marko Lindqvist:
>
>  $subject.
>
>  See forum thread about Dune modpack:
>  http://forum.freeciv.org/viewtopic.php?t=4892

 Fix


 - ML

diff -Nurd -X.diff_ignore freeciv/client/gui-gtk-2.0/wldlg.c 
freeciv/client/gui-gtk-2.0/wldlg.c
--- freeciv/client/gui-gtk-2.0/wldlg.c  2008-04-25 02:24:58.000000000 +0300
+++ freeciv/client/gui-gtk-2.0/wldlg.c  2008-07-05 14:33:05.000000000 +0300
@@ -1014,7 +1014,8 @@
     if (!target.is_unit && *pcity) {
       plr = city_owner(*pcity);
       useless = improvement_obsolete(plr, target.value)
-       || is_building_replaced(*pcity, target.value, RPT_CERTAIN);
+        || (! impr_provides_buildable_units(plr, target.value)
+            && is_building_replaced(*pcity, target.value, RPT_CERTAIN));
       /* Mark building redundant if we are really certain that there is
        * no use for it. */
       g_object_set(rend, "strikethrough", useless, NULL);
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c   2008-06-26 21:52:09.000000000 +0300
+++ freeciv/client/packhand.c   2008-07-05 14:26:49.000000000 +0300
@@ -2358,7 +2358,15 @@
     } impr_type_iterate_end;
   }
 #endif
-  
+
+  b->allows_units = FALSE;
+  unit_type_iterate(ut) {
+    if (ut->impr_requirement == p->id) {
+      b->allows_units = TRUE;
+      break;
+    }
+  } unit_type_iterate_end;
+
   tileset_setup_impr_type(tileset, p->id);
 }
 
diff -Nurd -X.diff_ignore freeciv/common/improvement.c 
freeciv/common/improvement.c
--- freeciv/common/improvement.c        2008-01-15 04:04:30.000000000 +0200
+++ freeciv/common/improvement.c        2008-07-05 14:35:42.000000000 +0300
@@ -306,6 +306,30 @@
 }
 
 /**************************************************************************
+  Returns TRUE iff improvement provides units buildable by player
+**************************************************************************/
+bool impr_provides_buildable_units(const struct player *pplayer,
+                                   Impr_type_id id)
+{
+  struct impr_type *impr = improvement_by_number(id);
+
+  /* Fast check */
+  if (! impr->allows_units) {
+    return FALSE;
+  }
+
+  unit_type_iterate(ut) {
+    if (ut->impr_requirement == id) {
+      if (can_player_build_unit(pplayer, ut)) {
+        return TRUE;
+      }
+    }
+  } unit_type_iterate_end;
+
+  return FALSE;
+}
+
+/**************************************************************************
    Whether player can build given building somewhere, ignoring whether it
    is obsolete.
 **************************************************************************/
diff -Nurd -X.diff_ignore freeciv/common/improvement.h 
freeciv/common/improvement.h
--- freeciv/common/improvement.h        2007-07-04 14:04:25.000000000 +0300
+++ freeciv/common/improvement.h        2008-07-05 14:30:08.000000000 +0300
@@ -70,6 +70,8 @@
   char *helptext;
   char soundtag[MAX_LEN_NAME];
   char soundtag_alt[MAX_LEN_NAME];
+
+  bool allows_units;   /* Cache */
 };
 
 
@@ -96,6 +98,7 @@
 
 /* player related improvement functions */
 bool improvement_obsolete(const struct player *pplayer, Impr_type_id id);
+bool impr_provides_buildable_units(const struct player *pplayer, Impr_type_id 
id);
 
 bool can_player_build_improvement_direct(const struct player *p,
                                         Impr_type_id id);
@@ -136,4 +139,3 @@
 bool can_city_sell_building(struct city *pcity, Impr_type_id id);
 
 #endif  /* FC__IMPROVEMENT_H */
-
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c    2008-05-08 00:24:57.000000000 +0300
+++ freeciv/server/ruleset.c    2008-07-05 14:22:48.000000000 +0300
@@ -1398,6 +1398,14 @@
               secfile_lookup_str_default(file, "-", "%s.sound_alt",
                                          sec[i]));
     b->helptext = lookup_helptext(file, sec[i]);
+
+    b->allows_units = FALSE;
+    unit_type_iterate(ut) {
+      if (ut->impr_requirement == i) {
+        b->allows_units = TRUE;
+        break;
+      }
+    } unit_type_iterate_end;
   }
 
   /* Some more consistency checking: */
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to