? stats ? diff ? embass.gz ? out4 ? auto.rc ? diff.safe ? simple_ai_unit_type_iterate1.diff ? defense_power3.diff ? bool_options1.diff ? bool_stdinhand1.diff.gz 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/08 17:29:48 @@ -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.109 diff -u -r1.109 aicity.c --- ai/aicity.c 2002/03/08 17:06:40 1.109 +++ ai/aicity.c 2002/03/08 17:29:49 @@ -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/08 17:29:51 @@ -60,6 +60,19 @@ static int unit_move_turns(struct unit *punit, int x, int y); static bool unit_can_defend(Unit_Type_id type); +/* + * Cached values. Updated by update_simple_ai_types. + * + * 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.) + * + * Terminated by U_LAST. + */ +Unit_Type_id simple_ai_types[U_LAST]; /************************************************************************** Similar to is_my_zoc(), but with some changes: @@ -2280,20 +2293,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 @@ -2557,4 +2556,24 @@ break; } } while (leader->moves_left > 0); +} + +/************************************************************************* + Updates the global array simple_ai_types. +**************************************************************************/ +void update_simple_ai_types(void) +{ + int i = 0; + + unit_type_iterate(id) { + if (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) { + simple_ai_types[i] = id; + i++; + } + } unit_type_iterate_end; + + simple_ai_types[i] = U_LAST; } 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/08 17:29:51 @@ -29,6 +29,8 @@ struct unit; struct ai_choice; +extern Unit_Type_id simple_ai_types[U_LAST]; + void ai_manage_units(struct player *pplayer); int could_unit_move_to_tile(struct unit *punit, int src_x, int src_y, int dest_x, int dest_y); @@ -53,11 +55,25 @@ 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); +void update_simple_ai_types(void); + +/* not dealing with planes yet */ +#define simple_ai_unit_type_iterate(m_i) \ +{ \ + int m_c; \ + for (m_c = 0;; m_c++) { \ + Unit_Type_id m_i = simple_ai_types[m_c]; \ + if (m_i == U_LAST) { \ + break; \ + } + +#define simple_ai_unit_type_iterate_end \ + } \ +} #endif /* FC__AIUNIT_H */ 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/08 17:29:54 @@ -36,6 +36,7 @@ #include "unit.h" #include "citytools.h" +#include "aiunit.h" /* update_simple_ai_types */ #include "ruleset.h" @@ -871,7 +872,9 @@ j = game.rtech.u_partisan = get_unit_type(j)->tech_requirement; freelog(LOG_DEBUG, "partisan tech is %s", advances[j].name); } - + + update_simple_ai_types(); + free(sec); section_file_check_unused(file, filename); section_file_free(file);