@@ -6191,19 +6191,20 @@ int num_nearby_fighters(int enemy_team_mask, vec3d *pos, float threshold)
61916191// set, that weapon will be selected. If not, apply to priority2. If neither, return -1, meaning no weapon selected.
61926192// Note, priorityX have default values of -1, meaning if not set, they will match any weapon.
61936193// Return value:
6194- // bank index
6194+ // true if an appropriate weapon was found and switched to, false if no valid weapons, and should not fire
61956195// Should do this:
61966196// Favor aspect seekers when attacking small ships faraway.
61976197// Favor rapid fire dumbfire when attacking a large ship.
61986198// Ignore heat seekers because we're not sure how they'll work.
6199- void ai_select_secondary_weapon(object *objp, ship_weapon *swp, flagset<Weapon::Info_Flags>* priority1 = NULL, flagset<Weapon::Info_Flags>* priority2 = NULL)
6199+ bool ai_select_secondary_weapon(object *objp, ship_weapon *swp, flagset<Weapon::Info_Flags>* priority1 = NULL, flagset<Weapon::Info_Flags>* priority2 = NULL)
62006200{
62016201 int num_weapon_types;
62026202 int weapon_id_list[MAX_WEAPON_TYPES], weapon_bank_list[MAX_WEAPON_TYPES];
62036203 int i;
62046204 flagset<Weapon::Info_Flags> ignore_mask, ignore_mask_without_huge, prio1, prio2;
62056205 int initial_bank;
62066206 ai_info *aip = &Ai_info[Ships[objp->instance].ai_index];
6207+ bool rval = false;
62076208
62086209 initial_bank = swp->current_secondary_bank;
62096210
@@ -6243,7 +6244,7 @@ void ai_select_secondary_weapon(object *objp, ship_weapon *swp, flagset<Weapon::
62436244
62446245 // If there are no valid choices, bail
62456246 if (num_weapon_types == 0)
6246- return;
6247+ return false ;
62476248
62486249 // Ignore homing weapons if we didn't specify a flag - for priority 1
62496250 if ((aip->ai_profile_flags[AI::Profile_Flags::Smart_secondary_weapon_selection]) && (prio1.none_set())) {
@@ -6262,6 +6263,7 @@ void ai_select_secondary_weapon(object *objp, ship_weapon *swp, flagset<Weapon::
62626263 if (!(wi_flags & ignore_mask_to_use).any_set()) { // Maybe bombs are illegal.
62636264 if ((wi_flags & prio1).any_set()) {
62646265 swp->current_secondary_bank = weapon_bank_list[i]; // Found first priority, return it.
6266+ rval = true;
62656267 break;
62666268 } else if ((wi_flags & prio2).any_set())
62676269 priority2_index = weapon_bank_list[i]; // Found second priority, but might still find first priority.
@@ -6292,14 +6294,15 @@ void ai_select_secondary_weapon(object *objp, ship_weapon *swp, flagset<Weapon::
62926294 // if we have a valid priority2, use that
62936295 if (priority2_index >= 0) {
62946296 swp->current_secondary_bank = priority2_index;
6297+ rval = true;
62956298 }
62966299 }
62976300
62986301 Assertion(swp->current_secondary_bank >= 0, "ai_select_secondary_weapon assigned a -1 secondary bank to %s", Ships[objp->instance].ship_name);
62996302 // if we got an invalid bank somehow, just put it back and bail
63006303 if (swp->current_secondary_bank < 0) {
63016304 swp->current_secondary_bank = initial_bank;
6302- return;
6305+ return false ;
63036306 }
63046307
63056308 // If switched banks, force reacquisition of aspect lock.
@@ -6320,6 +6323,7 @@ void ai_select_secondary_weapon(object *objp, ship_weapon *swp, flagset<Weapon::
63206323 }
63216324
63226325 ship_secondary_changed(&Ships[objp->instance]); // AL: let multiplayer know if secondary bank has changed
6326+ return rval;
63236327}
63246328
63256329/**
@@ -8178,7 +8182,8 @@ int has_preferred_secondary(object *objp, object *en_objp, ship_weapon *swp)
81788182// Note, this is not like ai_select_secondary_weapon(). "choose" means make a choice.
81798183// "select" means execute an order. Get it?
81808184// This function calls ai_select_secondary_weapon() with the characteristics it should search for.
8181- void ai_choose_secondary_weapon(object *objp, ai_info *aip, object *en_objp)
8185+ // return true if an appropriate weapon was found and switched to, false if no valid weapons, and should not fire
8186+ bool ai_choose_secondary_weapon(object *objp, ai_info *aip, object *en_objp)
81828187{
81838188 float subsystem_strength = 0.0f;
81848189 bool is_big_ship;
@@ -8197,7 +8202,7 @@ void ai_choose_secondary_weapon(object *objp, ai_info *aip, object *en_objp)
81978202 // AL 3-5-98: do a quick out if the ship has no secondaries
81988203 if ( swp->num_secondary_banks <= 0 ) {
81998204 swp->current_secondary_bank = -1;
8200- return;
8205+ return false ;
82018206 }
82028207
82038208 int preferred_secondary = has_preferred_secondary(objp, en_objp, swp);
@@ -8209,6 +8214,7 @@ void ai_choose_secondary_weapon(object *objp, ai_info *aip, object *en_objp)
82098214 swp->current_secondary_bank = preferred_secondary;
82108215 }
82118216 aip->ai_flags.set(AI::AI_Flags::Unload_secondaries);
8217+ return true;
82128218 } else {
82138219 aip->ai_flags.remove(AI::AI_Flags::Unload_secondaries);
82148220 if (aip->targeted_subsys) {
@@ -8252,7 +8258,7 @@ void ai_choose_secondary_weapon(object *objp, ai_info *aip, object *en_objp)
82528258 wif_priority2.reset();
82538259 }
82548260
8255- ai_select_secondary_weapon(objp, swp, &wif_priority1, &wif_priority2);
8261+ return ai_select_secondary_weapon(objp, swp, &wif_priority1, &wif_priority2);
82568262 }
82578263}
82588264
@@ -9328,10 +9334,10 @@ void ai_chase()
93289334
93299335 // Don't fire secondaries at a protected ship.
93309336 if (!(En_objp->flags[Object::Object_Flags::Protected])) {
9331- ai_choose_secondary_weapon(Pl_objp, aip, En_objp);
9337+ bool valid_secondary = ai_choose_secondary_weapon(Pl_objp, aip, En_objp);
93329338 int current_bank = tswp->current_secondary_bank;
93339339
9334- if (current_bank > -1) {
9340+ if (current_bank > -1 && valid_secondary ) {
93359341 weapon_info *swip = &Weapon_info[tswp->secondary_bank_weapons[current_bank]];
93369342 if (aip->ai_flags[AI::AI_Flags::Unload_secondaries]) {
93379343 if (timestamp_until(swp->next_secondary_fire_stamp[current_bank]) > swip->fire_wait*1000.0f) {
0 commit comments