It's a pretty long piece of code, so I won't post it here, but I'll describe the basic process.
The heart of it depends upon this snippet here - which searches the banks of an AI ship and finds a weapon with a given flag - in this case WIF_SHUDDER
for (int i = 0; i < swp->num_primary_banks; i++)
{
if (swp->primary_bank_weapons[i] > -1) // Make sure there is a weapon
{
if (!(Weapon_info[swp->primary_bank_weapons[i]].wi_flags & WIF_SHUDDER & WIF_PUNCTURE))
{
swp->current_primary_bank = i; // Found a match, arm it
return i; // Exit function
}
}
}
Using this code, we can use it to search for different properties. However since the Maxim is the only gun that uses WIF_SHUDDER it is appropriate to use that as a search criteria.
If a match is found, the function arms that weapon and then returns. If no match is found, it will continue to the next if or for statement.
All I've done is put in a simple check to see if the target has a shield system (via the OF_NO_SHIELDS flag):
if (other_objp->flags & OF_NO_SHIELDS)
{
...
}
...and if so then we search for and try and arm the maxim.
In the actual code there is quite a few more conditions of course to try and not arm the maxim otherwise, and to try and not arm puncture weapons (disrupters - original use of the code) otherwise, but in essence this is it's functioning.
[EDIT] It's important to note that other_objp is a object structure that points to the ai's target.[/EDIT]