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

 This adds new function city_got_defense_effect(). Old
city_got_citywalls() callers that are interested in actual defense
bonuses now use it. city_got_citywalls() is meant to check if city
should use wall gfx.

 This patch is step toward fixing #37977 and as such should be
committed to both trunk and S2_1.


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/advmilitary.c freeciv/ai/advmilitary.c
--- freeciv/ai/advmilitary.c	2007-03-05 21:11:52.000000000 +0200
+++ freeciv/ai/advmilitary.c	2007-03-12 02:15:51.000000000 +0200
@@ -185,7 +185,10 @@
     defense *= unit_type(punit)->firepower;
     if (is_ground_unit(punit)) {
       if (pcity) {
-        do_wall = (!igwall && city_got_citywalls(pcity));
+        /* FIXME: We check if city got defense effect against *some*
+         * unit type. Sea unit danger might cause us to build defenses
+         * against air units... */
+        do_wall = (!igwall && city_got_defense_effect(pcity, NULL));
         defense *= 3;
       }
     }
@@ -683,7 +686,10 @@
 static void process_defender_want(struct player *pplayer, struct city *pcity,
                                   unsigned int danger, struct ai_choice *choice)
 {
-  bool walls = city_got_citywalls(pcity);
+  /* FIXME: We check if city got defense effect against *some*
+   * unit type. Sea unit danger might cause us to build defenses
+   * against air units... */
+  bool walls = city_got_defense_effect(pcity, NULL);
   /* Technologies we would like to have. */
   int tech_desire[U_LAST];
   /* Our favourite unit. */
diff -Nurd -X.diff_ignore freeciv/common/city.c freeciv/common/city.c
--- freeciv/common/city.c	2007-03-05 21:11:49.000000000 +0200
+++ freeciv/common/city.c	2007-03-12 02:20:11.000000000 +0200
@@ -981,7 +981,7 @@
 }
 
 /**************************************************************************
- Whether a city has its own City Walls, or the same effect via a wonder.
+ Whether a city should have visible walls
 **************************************************************************/
 bool city_got_citywalls(const struct city *pcity)
 {
@@ -989,6 +989,22 @@
 }
 
 /**************************************************************************
+ This can be City Walls, Coastal defense... depending on attacker type.
+ If attacker type is not given, just any defense effect will do.
+**************************************************************************/
+bool city_got_defense_effect(const struct city *pcity,
+                             const struct unit_type *attacker)
+{
+  if (!attacker) {
+    /* Any defense building will do */
+    return get_city_bonus(pcity, EFT_DEFEND_BONUS) > 0;
+  }
+
+  return get_unittype_bonus(pcity->owner, pcity->tile, attacker,
+                            EFT_DEFEND_BONUS) > 0;
+}
+
+/**************************************************************************
   Return TRUE iff the city is happy.  A happy city will start celebrating
   soon.
   A city can only be happy if half or more of the population is happy,
diff -Nurd -X.diff_ignore freeciv/common/city.h freeciv/common/city.h
--- freeciv/common/city.h	2007-03-05 21:11:49.000000000 +0200
+++ freeciv/common/city.h	2007-03-12 02:14:29.000000000 +0200
@@ -390,6 +390,8 @@
 bool city_got_building(const struct city *pcity,  Impr_type_id id); 
 bool is_capital(const struct city *pcity);
 bool city_got_citywalls(const struct city *pcity);
+bool city_got_defense_effect(const struct city *pcity,
+                             const struct unit_type *attacker);
 bool building_replaced(const struct city *pcity, Impr_type_id id);
 int city_change_production_penalty(const struct city *pcity,
 				   struct city_production target);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to