Hard Light Productions Forums
Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: The E on February 01, 2010, 05:26:50 pm
-
As per the BP teams' request, I have gone forth and implemented a new flag for primary weapons. It is called "capital+", and it causes the AI to use the flagged weapon against capships only.
Patch: http://www.mediafire.com/?lmzgjgm2iww
Test builds: (Inferno SSE2 only) http://www.mediafire.com/?jnlmonm0vwt
-
cool, now i can make the maelstrom not fire its 105mm gatling-howitzers at fighters.
-
Capital meaning destroyer and up?
-
Ships tagged as Cruiser, Capital or Supercap.
EDIT: Just realized that that was a stupid idea. The patch has been altered to use the SIF_BIG_SHIP and SIF_HUGE_SHIP tags.
http://www.mediafire.com/?lmzgjgm2iww
-
Ehh ... doesn't the "huge" flag do more or less the same thing?
-
Huge is for secondaries. It has no effect on primary weapon selection.
A bit of background: WiH has a few fighter-mounted primaries that are intended to be used against big ships, and which are rather ineffective against fighters and bombers. The AI didn't know this, and based on the weapon stats, thought that it was a mighty fine idea to use these weapons on small targets anyway. In other words, they were not behaving as smartly as a human would in the same situation.
With this flag, they use their dogfight weapons, making them much more effective.
-
Ehh ... doesn't the "huge" flag do more or less the same thing?
"huge" flag as far as targeting goes, only affects turrets and secondaries. Like The E explained, AI still attempts to use "huge" fighter primaries against other fighters/bombers.
-
Ehh ... doesn't the "huge" flag do more or less the same thing?
"huge" flag as far as targeting goes, only affects turrets and secondaries. Like The E explained, AI still attempts to use "huge" fighter primaries against other fighters/bombers.
So, the reason why we use a new flag (capital+) instead of modifying the behavior of the existing one (huge) is for backwards compatibility?
Maybe it would be simpler for modders to just have the huge flag, and add an AI Profiles option that makes the AI respect it for primaries (defaulted to NO)?
-
FUBAR wanted to control it per-weapon.
-
I think you mean The E, unless it was originally FUBAR's idea and The E just happened to implement it.
-
Like The E explained, AI still attempts to use "huge" fighter primaries against other fighters/bombers.
I thought this had to do with "$Smart Secondary Weapon Selection:" ...
-
Yes, it does. HOWEVER, as mentioned already, the "huge" flag HAS NO EFFECT when the AI tries to choose which _primary_ to use on an enemy.
-
I think you mean The E, unless it was originally FUBAR's idea and The E just happened to implement it.
No, I mean FUBAR. He took part in discussion on irc.
-
Committed 5894.
-
Oww...YES. I needed this. I was getting sick of Claymores using wasting Redeemer ammo on fighters.
-
So...is this now in the 3.6.12 RC?
-
Yes
-
:bump:
Expanded capital+ to cover secondaries as well. Yes, this might seem redundant. Still, I think it can be useful.
Index: code/ai/aicode.cpp
===================================================================
--- code/ai/aicode.cpp (revision 6005)
+++ code/ai/aicode.cpp (working copy)
@@ -5849,7 +5849,7 @@
// Favor aspect seekers when attacking small ships faraway.
// Favor rapid fire dumbfire when attacking a large ship.
// Ignore heat seekers because we're not sure how they'll work.
-void ai_select_secondary_weapon(object *objp, ship_weapon *swp, int priority1 = -1, int priority2 = -1)
+void ai_select_secondary_weapon(object *objp, ship_weapon *swp, int priority1 = -1, int priority2 = -1, int wif2_priority1 = -1, int wif2_priority2 = -1)
{
int num_weapon_types;
int weapon_id_list[MAX_WEAPON_TYPES], weapon_bank_list[MAX_WEAPON_TYPES];
@@ -5869,6 +5869,11 @@
ignore_mask |= WIF_HUGE;
}
+ // Ignore capital+ unless one of the priorities asks for it.
+ if (!(WIF2_CAPITAL_PLUS & (wif2_priority1 | wif2_priority2))) {
+ ignore_mask |= WIF2_CAPITAL_PLUS;
+ }
+
// Ignore bomber+ unless one of the priorities asks for them to be selected
if (!(WIF_BOMBER_PLUS & (priority1 | priority2))) {
ignore_mask |= WIF_BOMBER_PLUS;
@@ -5895,6 +5900,7 @@
for (i=0; i<num_weapon_types; i++) {
int wi_flags = Weapon_info[swp->secondary_bank_weapons[weapon_bank_list[i]]].wi_flags;
+ int wi_flags2 = Weapon_info[swp->secondary_bank_weapons[weapon_bank_list[i]]].wi_flags2;
int ignore_mask_to_use = ((aip->ai_profile_flags & AIPF_SMART_SECONDARY_WEAPON_SELECTION) && (wi_flags & WIF_BOMBER_PLUS)) ? ignore_mask_without_huge : ignore_mask;
if (!(wi_flags & ignore_mask_to_use)) { // Maybe bombs are illegal.
@@ -5904,6 +5910,13 @@
} else if (wi_flags & priority2)
priority2_index = weapon_bank_list[i]; // Found second priority, but might still find first priority.
}
+ if (!(wi_flags2 & ignore_mask_to_use)) { // Maybe bombs are illegal.
+ if (wi_flags2 & wif2_priority1) {
+ swp->current_secondary_bank = weapon_bank_list[i]; // Found first priority, return it.
+ break;
+ } else if (wi_flags2 & wif2_priority2)
+ priority2_index = weapon_bank_list[i]; // Found second priority, but might still find first priority.
+ }
}
// Ignore homing weapons if we didn't specify a flag - for priority 2
@@ -7719,7 +7732,7 @@
void ai_choose_secondary_weapon(object *objp, ai_info *aip, object *en_objp)
{
float subsystem_strength = 0.0f;
- int is_big_ship, priority1, priority2;
+ int is_big_ship, wif_priority1, wif_priority2, wif2_priority1, wif2_priority2;
ship_weapon *swp;
ship_info *esip;
@@ -7761,31 +7774,41 @@
if (is_big_ship)
{
- priority1 = WIF_HUGE;
- priority2 = (aip->ai_profile_flags & AIPF_SMART_SECONDARY_WEAPON_SELECTION) ? WIF_BOMBER_PLUS : WIF_HOMING;
+ wif_priority1 = WIF_HUGE;
+ wif_priority2 = (aip->ai_profile_flags & AIPF_SMART_SECONDARY_WEAPON_SELECTION) ? WIF_BOMBER_PLUS : WIF_HOMING;
+ wif2_priority1 = WIF2_CAPITAL_PLUS;
+ wif2_priority2 = 0;
}
else if ( (esip != NULL) && (esip->flags & SIF_BOMBER) )
{
- priority1 = WIF_BOMBER_PLUS;
- priority2 = WIF_HOMING;
+ wif_priority1 = WIF_BOMBER_PLUS;
+ wif_priority2 = WIF_HOMING;
+ wif2_priority1 = 0;
+ wif2_priority2 = 0;
}
else if (subsystem_strength > 100.0f)
{
- priority1 = WIF_PUNCTURE;
- priority2 = WIF_HOMING;
+ wif_priority1 = WIF_PUNCTURE;
+ wif_priority2 = WIF_HOMING;
+ wif2_priority1 = 0;
+ wif2_priority2 = 0;
}
else if ((aip->ai_profile_flags & AIPF_SMART_SECONDARY_WEAPON_SELECTION) && (en_objp->type == OBJ_ASTEROID)) //prefer dumbfires if its an asteroid
{
- priority1 = 0;
- priority2 = 0;
+ wif_priority1 = 0;
+ wif_priority2 = 0;
+ wif2_priority1 = 0;
+ wif2_priority2 = 0;
}
else
{
- priority1 = WIF_HOMING;
- priority2 = 0;
+ wif_priority1 = WIF_HOMING;
+ wif_priority2 = 0;
+ wif2_priority1 = 0;
+ wif2_priority2 = 0;
}
- ai_select_secondary_weapon(objp, swp, priority1, priority2);
+ ai_select_secondary_weapon(objp, swp, wif_priority1, wif_priority2, wif2_priority1, wif2_priority2);
}
// nprintf(("AI", "Frame %i: Chose secondary %s\n", Framecount, Weapon_info[swp->secondary_bank_weapons[swp->current_secondary_bank]].name));
-
Patch looks good.