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

Title: capital+ flag for primary weapons
Post 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
Title: Re: capital+ flag for primary weapons
Post by: Nuke on February 01, 2010, 08:00:05 pm
cool, now i can make the maelstrom not fire its 105mm gatling-howitzers at fighters.
Title: Re: capital+ flag for primary weapons
Post by: blowfish on February 01, 2010, 10:51:30 pm
Capital meaning destroyer and up?
Title: Re: capital+ flag for primary weapons
Post by: The E on February 02, 2010, 05:36:25 am
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
Title: Re: capital+ flag for primary weapons
Post by: blowfish on February 02, 2010, 08:53:08 am
Ehh ... doesn't the "huge" flag do more or less the same thing?
Title: Re: capital+ flag for primary weapons
Post by: The E on February 02, 2010, 09:01:46 am
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.
Title: Re: capital+ flag for primary weapons
Post by: Fury on February 02, 2010, 09:09:19 am
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.
Title: Re: capital+ flag for primary weapons
Post by: Sushi on February 02, 2010, 01:31:11 pm
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)?
Title: Re: capital+ flag for primary weapons
Post by: Fury on February 02, 2010, 01:32:56 pm
FUBAR wanted to control it per-weapon.
Title: Re: capital+ flag for primary weapons
Post by: Zacam on February 02, 2010, 03:28:13 pm
I think you mean The E, unless it was originally FUBAR's idea and The E just happened to implement it.
Title: Re: capital+ flag for primary weapons
Post by: blowfish on February 02, 2010, 05:04:45 pm
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:" ...
Title: Re: capital+ flag for primary weapons
Post by: The E on February 02, 2010, 05:20:08 pm
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.
Title: Re: capital+ flag for primary weapons
Post by: Fury on February 02, 2010, 11:12:47 pm
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.
Title: Re: capital+ flag for primary weapons
Post by: Zacam on February 09, 2010, 02:28:59 pm
Committed 5894.
Title: Re: capital+ flag for primary weapons
Post by: TrashMan on February 12, 2010, 01:42:53 am
Oww...YES. I needed this. I was getting sick of Claymores using wasting Redeemer ammo on fighters.
Title: Re: capital+ flag for primary weapons
Post by: TrashMan on February 21, 2010, 08:53:08 am
So...is this now in the 3.6.12 RC?
Title: Re: capital+ flag for primary weapons
Post by: Fury on February 21, 2010, 08:53:32 am
Yes
Title: Re: capital+ flag for primary weapons
Post by: The E on March 14, 2010, 04:00:33 pm
 :bump:

Expanded capital+ to cover secondaries as well. Yes, this might seem redundant. Still, I think it can be useful.

Code: [Select]
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));
Title: Re: capital+ flag for primary weapons
Post by: Goober5000 on March 14, 2010, 09:01:36 pm
Patch looks good.