<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15416 >
Untested patch for S2_1 and TRUNK.
Usually we choose best defender from those costing less than
limit_cost. If all units cost more than limit_cost, cheapest is
selected.
- ML
diff -Nurd -X.diff_ignore freeciv/ai/advmilitary.c freeciv/ai/advmilitary.c
--- freeciv/ai/advmilitary.c 2006-07-17 14:28:36.000000000 +0300
+++ freeciv/ai/advmilitary.c 2007-01-11 04:42:54.000000000 +0200
@@ -663,6 +663,7 @@
/* Our favourite unit. */
int best = -1;
struct unit_type *best_unit_type = NULL;
+ int best_unit_cost = 1;
memset(tech_desire, 0, sizeof(tech_desire));
@@ -695,18 +696,26 @@
if (can_build_unit(pcity, punittype)) {
/* We can build the unit now... */
+ int build_cost = unit_build_shield_cost(punittype);
+ int limit_cost = pcity->shield_stock + 40;
+
if (walls && move_type == LAND_MOVING) {
desire *= pcity->ai.wallvalue;
/* TODO: More use of POWER_FACTOR ! */
desire /= POWER_FACTOR;
}
- if ((desire > best ||
- (desire == best && unit_build_shield_cost(punittype) <=
- unit_build_shield_cost(best_unit_type)))
- && unit_build_shield_cost(punittype) <= pcity->shield_stock + 40) {
+
+ if ((best_unit_cost > limit_cost
+ && build_cost < best_unit_cost)
+ || ((desire > best ||
+ (desire == best && build_cost <= best_unit_cost))
+ && (best_unit_type == NULL
+ /* In case all units are more expensive than limit_cost */
+ || limit_cost <= pcity->shield_stock + 40))) {
best = desire;
best_unit_type = punittype;
+ best_unit_cost = build_cost;
}
} else if (can_eventually_build_unit(pcity, punittype)) {
/* We first need to develop the tech required by the unit... */
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev