/******************************************************************* Chooses the best available and usable air unit and records it in choice, if it's better than previous choice The interface is somewhat different from other ai_choose, but that's what it should be like, I believe -- GB ******************************************************************/ bool dai_choose_attacker_air(struct ai_type *ait, struct player *pplayer, struct city *pcity, struct adv_choice *choice) { bool want_something = FALSE; /* This AI doesn't know to build planes */ if (ai_handicap(pplayer, H_NOPLANES)) { return FALSE; } /* military_advisor_choose_build does something idiotic, * this function should not be called if there is danger... */ if (choice->want >= 100 && choice->type != CT_ATTACKER) { return FALSE; } if (!player_knows_techs_with_flag(pplayer, TF_BUILD_AIRBORNE)) { return FALSE; } unit_type_iterate(punittype) { struct unit_class *pclass = utype_class(punittype); if (pclass->adv.land_move == MOVE_NONE || pclass->adv.sea_move == MOVE_NONE || uclass_has_flag(pclass, UCF_TERRAIN_SPEED) || unit_type_is_losing_hp(pplayer, punittype)) { /* We don't consider this a plane */ continue; } if (can_city_build_unit_now(pcity, punittype)) { struct unit *virtual_unit = unit_virtual_create(pplayer, pcity, punittype, do_make_unit_veteran(pcity, punittype)); int profit = find_something_to_bomb(ait, virtual_unit, NULL, NULL); if (profit > choice->want){ /* Update choice */ choice->want = profit; choice->value.utype = punittype; choice->type = CT_ATTACKER; choice->need_boat = FALSE; want_something = TRUE; log_debug("%s wants to build %s (want=%d)", city_name(pcity), utype_rule_name(punittype), profit); } else { log_debug("%s doesn't want to build %s (want=%d)", city_name(pcity), utype_rule_name(punittype), profit); } unit_virtual_destroy(virtual_unit); } } unit_type_iterate_end; return want_something; }
/**************************************************************************** Is base native to unit type? ****************************************************************************/ bool is_native_base_to_utype(const struct base_type *pbase, const struct unit_type *punittype) { return is_native_base_to_uclass(pbase, utype_class(punittype)); }