Index: ai/advmilitary.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v retrieving revision 1.97 diff -u -r1.97 advmilitary.c --- ai/advmilitary.c 2002/03/06 10:05:31 1.97 +++ ai/advmilitary.c 2002/03/06 11:37:52 @@ -475,8 +475,7 @@ bool isdef = has_a_normal_defender(pcity); memset(desire, 0, sizeof(desire)); - unit_type_iterate(i) { - if (!is_ai_simple_military(i)) continue; + simple_ai_unit_type_iterate(i) { m = unit_types[i].move_type; if ((m == LAND_MOVING || m == SEA_MOVING)) { k = num_unknown_techs_for_goal(pplayer,unit_types[i].tech_requirement); @@ -505,7 +504,7 @@ desire[i] = j * danger / (unit_types[i].build_cost + l); } } - } unit_type_iterate_end; + } simple_ai_unit_type_iterate_end; if (!walls && unit_types[bestid].move_type == LAND_MOVING) { best *= pcity->ai.wallvalue; @@ -516,15 +515,15 @@ if (best == 0) best = 1; /* avoid divide-by-zero below */ /* multiply by unit_types[bestid].build_cost / best */ - unit_type_iterate(i) { - if (desire[i] != 0 && is_ai_simple_military(i)) { + simple_ai_unit_type_iterate(i) { + if (desire[i] != 0) { tech_req = unit_types[i].tech_requirement; n = desire[i] * unit_types[bestid].build_cost / best; pplayer->ai.tech_want[tech_req] += n; freelog(LOG_DEBUG, "%s wants %s for defense with desire %d <%d>", pcity->name, advances[tech_req].name, n, desire[i]); } - } unit_type_iterate_end; + } simple_ai_unit_type_iterate_end; choice->choice = bestid; choice->want = danger; @@ -549,8 +548,7 @@ struct city *acity = map_get_city(x, y); int movetype = unit_types[*v].move_type; - unit_type_iterate(i) { - if (!is_ai_simple_military(i)) continue; + simple_ai_unit_type_iterate(i) { m = unit_types[i].move_type; j = unit_types[i].tech_requirement; if (j != A_LAST) k = num_unknown_techs_for_goal(pplayer,j); @@ -655,7 +653,7 @@ } } } - } unit_type_iterate_end; + } simple_ai_unit_type_iterate_end; } static void kill_something_with(struct player *pplayer, struct city *pcity, Index: ai/aicity.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v retrieving revision 1.107 diff -u -r1.107 aicity.c --- ai/aicity.c 2002/03/06 10:05:31 1.107 +++ ai/aicity.c 2002/03/06 11:37:52 @@ -596,9 +596,7 @@ int best = 0; int cur; - unit_type_iterate(i) { - /* not dealing with planes yet */ - if (!is_ai_simple_military(i)) continue; + simple_ai_unit_type_iterate(i) { cur = unit_attack_desirability(i); if (which == unit_types[i].move_type) { if (can_build_unit(pcity, i) && (cur > best || (cur == best && @@ -607,7 +605,7 @@ bestid = i; } } - } unit_type_iterate_end; + } simple_ai_unit_type_iterate_end; return bestid; } @@ -628,8 +626,7 @@ int j, m; int best= 0; - unit_type_iterate(i) { - if (!is_ai_simple_military(i)) continue; + simple_ai_unit_type_iterate(i) { m = unit_types[i].move_type; if (can_build_unit(pcity, i) && (m == LAND_MOVING || m == SEA_MOVING)) { j = get_virtual_defense_power(v, i, pcity->x, pcity->y); @@ -639,7 +636,7 @@ bestid = i; } } - } unit_type_iterate_end; + } simple_ai_unit_type_iterate_end; return bestid; } @@ -684,8 +681,7 @@ const bool walls = TRUE; /* just assume city_got_citywalls(pcity); in the long run -- Syela */ bool isdef = has_a_normal_defender(pcity); - unit_type_iterate(i) { - if (!is_ai_simple_military(i)) continue; + simple_ai_unit_type_iterate(i) { m = unit_types[i].move_type; if (can_build_unit(pcity, i) && get_unit_type(i)->build_cost <= n && (m == LAND_MOVING || m == SEA_MOVING) && @@ -700,7 +696,7 @@ bestid = i; } } - } unit_type_iterate_end; + } simple_ai_unit_type_iterate_end; return bestid; } Index: ai/aiunit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v retrieving revision 1.185 diff -u -r1.185 aiunit.c --- ai/aiunit.c 2002/03/06 05:28:19 1.185 +++ ai/aiunit.c 2002/03/06 11:37:55 @@ -2280,20 +2280,6 @@ #endif } -/************************************************************************** - This a hack to enable emulation of old loops previously hardwired as - for (i = U_WARRIORS; i <= U_BATTLESHIP; i++) - (Could probably just adjust the loops themselves fairly simply, but this - is safer for regression testing.) -**************************************************************************/ -bool is_ai_simple_military(Unit_Type_id type) -{ - return !unit_type_flag(type, F_NONMIL) - && !unit_type_flag(type, F_MISSILE) - && !unit_type_flag(type, F_NO_LAND_ATTACK) - && !(get_unit_type(type)->transport_capacity >= 8); -} - /* * If we are the only diplomat in a city, defend against enemy actions. * The passive defense is set by game.diplchance. The active defense is Index: ai/aiunit.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.h,v retrieving revision 1.32 diff -u -r1.32 aiunit.h --- ai/aiunit.h 2002/03/01 14:07:29 1.32 +++ ai/aiunit.h 2002/03/06 11:37:55 @@ -53,11 +53,21 @@ int military_amortize(int value, int delay, int build_cost); bool is_on_unit_upgrade_path(Unit_Type_id test, Unit_Type_id base); -bool is_ai_simple_military(Unit_Type_id type); Unit_Type_id ai_wants_role_unit(struct player *pplayer, struct city *pcity, int role, int want); void ai_choose_role_unit(struct player *pplayer, struct city *pcity, struct ai_choice *choice, int role, int want); + +/* not dealing with planes yet */ +#define simple_ai_unit_type_iterate(m_i) \ + unit_type_iterate(m_i) { \ + if (!unit_types[m_i].is_simple_ai_military) { \ + continue; \ + } + +#define simple_ai_unit_type_iterate_end \ + } unit_type_iterate_end; + #endif /* FC__AIUNIT_H */ Index: common/unittype.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v retrieving revision 1.9 diff -u -r1.9 unittype.h --- common/unittype.h 2002/03/06 10:05:38 1.9 +++ common/unittype.h 2002/03/06 11:38:07 @@ -176,6 +176,18 @@ int paratroopers_mr_sub; char *helptext; + + /* + * Cached value. Updated by load_ruleset_units. + * + * This a hack to enable emulation of old loops previously hardwired + * as + * for (i = U_WARRIORS; i <= U_BATTLESHIP; i++) + * + * (Could probably just adjust the loops themselves fairly simply, + * but this is safer for regression testing.) + */ + bool is_simple_ai_military; }; Index: server/ruleset.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v retrieving revision 1.103 diff -u -r1.103 ruleset.c --- server/ruleset.c 2002/03/06 10:05:39 1.103 +++ server/ruleset.c 2002/03/06 11:38:12 @@ -871,7 +871,16 @@ j = game.rtech.u_partisan = get_unit_type(j)->tech_requirement; freelog(LOG_DEBUG, "partisan tech is %s", advances[j].name); } - + + /* pre-calculate unit_types[i].is_ai_simple_military */ + unit_type_iterate(i) { + unit_types[i].is_simple_ai_military = + (unit_type_exists(i) && !unit_type_flag(i, F_NONMIL) + && !unit_type_flag(i, F_MISSILE) + && !unit_type_flag(i, F_NO_LAND_ATTACK) + && get_unit_type(i)->transport_capacity < 8); + } unit_type_iterate_end; + free(sec); section_file_check_unused(file, filename); section_file_free(file);