diff -Nur -Xfreecivdiff.ignore freeciv-cvs/ai/advdomestic.c freeciv-patched/ai/advdomestic.c --- freeciv-cvs/ai/advdomestic.c 2003-07-24 17:01:32.000000000 +0100 +++ freeciv-patched/ai/advdomestic.c 2003-07-24 17:04:14.000000000 +0100 @@ -479,6 +479,11 @@ || !can_build_improvement(pcity, id)) continue; + if (id == B_CITY) { + /* if (!built_elsewhere(pcity, B_WALL)) was counterproductive -- Syela */ + values[id] = ai_eval_threat_land(pplayer, pcity); + } + switch (id) { /* food/growth production */ @@ -605,10 +610,6 @@ * anyway. It was so stupid, AI wouldn't start building walls until it was * in danger and it would have no chance to finish them before it was too * late */ - case B_CITY: - /* if (!built_elsewhere(pcity, B_WALL)) was counterproductive -- Syela */ - values[id] = ai_eval_threat_land(pplayer, pcity); - break; case B_COASTAL: values[id] = ai_eval_threat_sea(pplayer, pcity); break; diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/packhand.c freeciv-patched/client/packhand.c --- freeciv-cvs/client/packhand.c 2003-07-24 17:02:26.000000000 +0100 +++ freeciv-patched/client/packhand.c 2003-07-24 17:04:14.000000000 +0100 @@ -1211,6 +1211,22 @@ game.nuclearwinter=pinfo->nuclearwinter; game.cooling=pinfo->cooling; if (!can_client_change_view()) { + /* Nasty kludge to let old code which assumes B_PALACE and B_CITY work */ + B_PALACE = get_improvement_for_effect(NULL, EFT_CAPITAL_CITY, UCL_LAST); + if (B_PALACE == B_LAST) { + freelog(LOG_ERROR, "Cannot find any capital city improvement"); + exit(EXIT_FAILURE); + } + + B_CITY = get_improvement_for_effect(NULL, EFT_UNIT_DEFEND, UCL_LAND); + if (B_CITY == B_LAST) { + B_CITY = get_improvement_for_effect(NULL, EFT_UNIT_DEFEND, UCL_LAST); + } + if (B_CITY == B_LAST) { + freelog(LOG_ERROR, "Cannot find any city walls improvement"); + exit(EXIT_FAILURE); + } + improvement_status_init(game.improvements, ARRAY_SIZE(game.improvements)); diff -Nur -Xfreecivdiff.ignore freeciv-cvs/common/city.c freeciv-patched/common/city.c --- freeciv-cvs/common/city.c 2003-07-24 17:02:53.000000000 +0100 +++ freeciv-patched/common/city.c 2003-07-24 17:04:14.000000000 +0100 @@ -219,10 +219,10 @@ && city_affected_by_wonder(pcity, B_MICHELANGELO)) return TRUE; break; - case B_CITY: +/*case B_CITY: if (city_affected_by_wonder(pcity, B_WALL)) return TRUE; - break; + break;*/ case B_HYDRO: case B_POWER: case B_NUCLEAR: diff -Nur -Xfreecivdiff.ignore freeciv-cvs/common/improvement.c freeciv-patched/common/improvement.c --- freeciv-cvs/common/improvement.c 2003-07-24 17:02:26.000000000 +0100 +++ freeciv-patched/common/improvement.c 2003-07-24 17:04:14.000000000 +0100 @@ -28,6 +28,8 @@ #include "improvement.h" +int B_CITY, B_PALACE; + /* get 'struct ceff_vector' functions: */ #define SPECVEC_TAG ceff #define SPECVEC_TYPE struct eff_city @@ -1263,3 +1265,28 @@ || imeff->aff_terr == T_UNKNOWN || imeff->aff_terr == aff_terr) || imeff->aff_spec & aff_spec); } + +/************************************************************************** + Returns the index of the improvement which provides the given effect + (constrained to the given unit class and player, if not UCL_LAST and + NULL respectively) or B_LAST if no suitable improvement could be found. +**************************************************************************/ +Impr_Type_id get_improvement_for_effect(struct player *pplayer, + enum effect_type id, + Unit_Class_id aff_unit) +{ + int impr; + struct impr_effect *eff; + + for (impr = 0; impr < game.num_impr_types; impr++) { + for (eff = improvement_types[impr].effect; + eff && eff->type != EFT_LAST; eff++) { + if (eff->type == id + && (!pplayer || can_player_build_improvement(pplayer, impr)) + && is_unit_terrain_affected(eff, aff_unit, T_UNKNOWN, S_ALL)) { + return impr; + } + } + } + return B_LAST; +} diff -Nur -Xfreecivdiff.ignore freeciv-cvs/common/improvement.h freeciv-patched/common/improvement.h --- freeciv-cvs/common/improvement.h 2003-07-24 17:02:53.000000000 +0100 +++ freeciv-patched/common/improvement.h 2003-07-24 17:04:14.000000000 +0100 @@ -45,9 +45,9 @@ #ifdef OLD_IMPR_TYPE_ENUM enum improvement_type_id { B_AIRPORT=0, B_AQUEDUCT, B_BANK, B_BARRACKS, B_BARRACKS2, B_BARRACKS3, - B_CATHEDRAL, B_CITY, B_COASTAL, B_COLOSSEUM, B_COURTHOUSE, B_FACTORY, + B_CATHEDRAL, B_orCITY, B_COASTAL, B_COLOSSEUM, B_COURTHOUSE, B_FACTORY, B_GRANARY, B_HARBOUR, B_HYDRO, B_LIBRARY, B_MARKETPLACE, B_MASS, B_MFG, - B_NUCLEAR, B_OFFSHORE, B_PALACE, B_POLICE, B_PORT, B_POWER, + B_NUCLEAR, B_OFFSHORE, B_orPALACE, B_POLICE, B_PORT, B_POWER, B_RECYCLING, B_RESEARCH, B_SAM, B_SDI, B_SEWER, B_SOLAR, B_SCOMP, B_SMODULE, B_SSTRUCTURAL, B_STOCK, B_SUPERHIGHWAYS, B_SUPERMARKET, B_TEMPLE, B_UNIVERSITY, @@ -61,6 +61,11 @@ }; #endif +/* Some code checks explicitly for City Walls or Palace - as a temporary + fix, set these to the indices of improvements which provide the + EFT_UNIT_DEFEND (aff_unit=Land) and EFT_CAPITAL_CITY effects */ +extern int B_CITY, B_PALACE; + /* B_LAST is a value which is guaranteed to be larger than all * actual Impr_Type_id values. It is used as a flag value; * it can also be used for fixed allocations to ensure ability @@ -393,6 +398,9 @@ bool is_wonder_useful(Impr_Type_id id); Impr_Type_id find_improvement_by_name(const char *s); void improvement_status_init(Impr_Status * improvements, size_t elements); +Impr_Type_id get_improvement_for_effect(struct player *pplayer, + enum effect_type id, + Unit_Class_id aff_unit); /* player related improvement and unit functions */ bool could_player_eventually_build_improvement(struct player *p, diff -Nur -Xfreecivdiff.ignore freeciv-cvs/common/player.c freeciv-patched/common/player.c --- freeciv-cvs/common/player.c 2003-07-24 17:03:11.000000000 +0100 +++ freeciv-patched/common/player.c 2003-07-24 17:04:14.000000000 +0100 @@ -447,7 +447,7 @@ struct city *find_palace(struct player *pplayer) { city_list_iterate(pplayer->cities, pcity) - if (city_got_building(pcity, B_PALACE)) + if (city_got_building(pcity, B_PALACE)) return pcity; city_list_iterate_end; return NULL; diff -Nur -Xfreecivdiff.ignore freeciv-cvs/server/ruleset.c freeciv-patched/server/ruleset.c --- freeciv-cvs/server/ruleset.c 2003-07-24 17:03:11.000000000 +0100 +++ freeciv-patched/server/ruleset.c 2003-07-24 17:04:14.000000000 +0100 @@ -1283,6 +1283,22 @@ b->helptext = lookup_helptext(file, sec[i]); } + /* Nasty kludge to let old code which assumes B_PALACE and B_CITY work */ + B_PALACE = get_improvement_for_effect(NULL, EFT_CAPITAL_CITY, UCL_LAST); + if (B_PALACE == B_LAST) { + freelog(LOG_ERROR, "Cannot find any capital city improvement"); + exit(EXIT_FAILURE); + } + + B_CITY = get_improvement_for_effect(NULL, EFT_UNIT_DEFEND, UCL_LAND); + if (B_CITY == B_LAST) { + B_CITY = get_improvement_for_effect(NULL, EFT_UNIT_DEFEND, UCL_LAST); + } + if (B_CITY == B_LAST) { + freelog(LOG_ERROR, "Cannot find any city walls improvement"); + exit(EXIT_FAILURE); + } + /* Some more consistency checking: */ impr_type_iterate(i) { b = &improvement_types[i];