Modding, Mission Design, and Coding > FS2 Open Coding - The Source Code Project (SCP)

AI using the maxim on fighters

(1/3) > >>

##UnknownPlayer##:
I've successfully fixed the problem with the AI using the maxim on fighters. If possible now, the AI will switch to a different weapon to attack any shielded target, and switch back to the maxim (if possible) to hit an unshielded target.

I've uploaded the changes to the CVS, they're all in aicode.cpp under ai_select_primary_weapon or search for 'unknownplayer',

Bobboau:
could you post a snipet
or explain how it works

##UnknownPlayer##:
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

--- Code: ---
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
}
}
}


--- End code ---


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):


--- Code: ---
if (other_objp->flags & OF_NO_SHIELDS)
{
      ...
}

--- End code ---


...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]

IceFire:
Shudder shouldn't be taken for granted seeing as other MODs may make use of that code and have a shield breaking weapon as that weapon.

Maybe we should specify "low shield" or something like that.

##UnknownPlayer##:
I'm aware of the problems using shudder, it's just for the time being I didn't want to mess with adding in a new tag. Once we do add a separate tag, it'll be easy to change this to use that as the test.

On that note, what should the tag be?

[EDIT] The other advantage is that modded table files aren't needed for this to work

The other way I could change it is by making it look for the highest shield factor weapon. [/EDIT]

Navigation

[0] Message Index

[#] Next page

Go to full version