Author Topic: AI using the maxim on fighters  (Read 3527 times)

0 Members and 1 Guest are viewing this topic.

AI using the maxim on fighters
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',

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
AI using the maxim on fighters
could you post a snipet
or explain how it works
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 
AI using the maxim on fighters
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: [Select]

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

Code: [Select]

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]

 

Offline IceFire

  • GTVI Section 3
  • 212
    • http://www.3dap.com/hlp/hosted/ce
AI using the maxim on fighters
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.
- IceFire
BlackWater Ops, Cold Element
"Burn the land, boil the sea, you can't take the sky from me..."

 
AI using the maxim on fighters
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]

 

Offline Kazan

  • PCS2 Wizard
  • 212
  • Soul lives in the Mountains
    • http://alliance.sourceforge.net
AI using the maxim on fighters
how about searching based upon the weapons shield-effectiveness coefficient
PCS2 2.0.3 | POF CS2 wiki page | Important PCS2 Threads | PCS2 Mantis

"The Mountains are calling, and I must go" - John Muir

 
AI using the maxim on fighters
I just considered doing that, but it quickly becomes hard to account for all the possibilities. I've recoded it so that it will now work off the best hull damaging weapon if the target has no shield system. If it does, it just picks a non-puncture (i.e. non disrupter) weapon and if that fails it just picks the first weapon.

In the game, so long as it attacks ships without shields with the Maxim I'll be happy, but to make this a happy coding experience I'd tear the whole thing out and rewrite it to do a huge equation to calculate weapon effecitveness (something like energy consumption per shot * rof / etc. etc. etc.)

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
AI using the maxim on fighters
like this

Code: [Select]

if (swp->num_primary_banks > 1){ // if there is more than one bank

swp->current_primary_bank = 0;
for (int i = 0; i < swp->num_primary_banks; i++){

if (swp->primary_bank_weapons[i] > -1){  //if there is a weapon

if (Weapon_info[swp->primary_bank_weapons[i]].shield_factor > Weapon_info[swp->primary_bank_weapons[swp->current_primary_bank]].shield_factor) //if this weapon has a better shield factor use it
{
swp->current_primary_bank = i; //arm it
}
}
}
return i;
}else{
return 0;
}
}
« Last Edit: July 18, 2002, 12:08:07 am by 57 »
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 
AI using the maxim on fighters
But that has problems - the fighter would always use a Circe if one is loaded because it only checks for a shield system, not shield energy. You have to strike a balance, though in the code I just uploaded to the CVS there's plenty of room for a better shielded weapon choice (just edit the else part of the if statement)

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
AI using the maxim on fighters
well I was just mentioning code, for selecting weapons that would be better at damageing sheilds, all you have to do to that would be add an
if(target has sheilds and those sheilds are still fairly strong)
to the start of it
note the still fairly strong as oposed to completly dead becase prety much all weapons do some sheild damage and the sheolds will probly always have some degree of power in them
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 
AI using the maxim on fighters
As far as I can tell that's more complex then you'd think. I don't fully understand how shields get calculated, but no where do they store an average, and there's no easy way to grab what side of the ship the AI is on without resorting to 3D maths - which I don't want to do yet.

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
AI using the maxim on fighters
get_shield_strength(shipp->objnum)
:)
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 
AI using the maxim on fighters
I love it!

[EDIT]
I've rewritten the primary weapon select code again so that the fighter now 'intelligently' chooses which gun to use.

Above 50% shield integrity it'll use its better anti-shield guns,
below 50% it'll try and use more balanced guns and below 5% it'll go for hull destroying guns.
« Last Edit: July 18, 2002, 07:28:24 am by 383 »

 

Offline Inquisitor

AI using the maxim on fighters
Just make sure it's all commented.

By the way, all anyone has to do to see the code is browser the web based CVS here:
http://fs2source.warpcore.org/cgi-bin/cvsweb/cvsweb.cgi/

And this specific code is:
http://fs2source.warpcore.org/cgi-bin/cvsweb/cvsweb.cgi/fs2_open/code/Ship/aicode.cpp?annotate=2.5

Original documentation on this code is:
http://fs2source.warpcore.org/dox/AiCode_8cpp.html
No signature.