Author Topic: Setting the target of AI ships.  (Read 2192 times)

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Setting the target of AI ships.
« on: July 17, 2008, 10:32:01 PM »
I made an AI for ships to organize and "act" as a fleet, being led by a "lead ship".
One of the things these ships (non lead-ships) should do is target and fire at the same target the lead ship of her fleet is firing at, thus concentrating fire on one target.

However I already tried:
A) overriding the method FindGoodTarget of the SelectTarget preprocessor, so that it selects the same target as the lead ship.
B) adding a preprocessor before the attack AI (FedAttack, NonFedAttack, BorgAttack, BasicAttack, etc), to set the ship target as the lead ship target (using "ShipClass.SetTarget()")
C) both A and B at the same time.

And it didn't work... Ships continued to select their own targets. In some cases, using "ShipClass.GetTarget()" was telling me that the ship was firing at the target I wanted it to fire, while actually it was firing at her own target...

So my question is, what can I do/change/add in the AI (or elsewhere) to make these fleet ships concentrate fire on the target of the lead ship??
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: Setting the target of AI ships.
« Reply #1 on: July 18, 2008, 07:41:50 AM »
ok i can't help you there eigther, but i have a question perfectly fitting into this topic:

is it possible to tell the AI to target anyone. meaning it fires on friends, enemys, neutrals, non identifiable - simply everything targetable in the system; i'd need that for a mod.

just posted this here because i'll have no internet for a while now, maybe anyone comes up with something in the meantime.

Offline KrrKs

  • Posts: 461
  • Cookies: 25
Re: Setting the target of AI ships.
« Reply #2 on: July 18, 2008, 09:54:16 AM »
I made an AI for ships to organize and "act" as a fleet, being led by a "lead ship".
One of the things these ships (non lead-ships) should do is target and fire at the same target the lead ship of her fleet is firing at, thus concentrating fire on one target.

However I already tried:
A) overriding the method FindGoodTarget of the SelectTarget preprocessor, so that it selects the same target as the lead ship.
B) adding a preprocessor before the attack AI (FedAttack, NonFedAttack, BorgAttack, BasicAttack, etc), to set the ship target as the lead ship target (using "ShipClass.SetTarget()")
C) both A and B at the same time.

And it didn't work... Ships continued to select their own targets. In some cases, using "ShipClass.GetTarget()" was telling me that the ship was firing at the target I wanted it to fire, while actually it was firing at her own target...

So my question is, what can I do/change/add in the AI (or elsewhere) to make these fleet ships concentrate fire on the target of the lead ship??

I don't know how to script AIs, but you could do something like the Fleet Orders Mod (or however it is named). I mean building a button somewhere in the command menu witch would switch the Ai used by allied ships and at the same time setting their target to yours. i think something similar is also included in the last BC missions where you command a few ships per hail menu.

Offline USS Frontier

  • Posts: 176
  • Cookies: 562
Re: Setting the target of AI ships.
« Reply #3 on: July 18, 2008, 01:28:06 PM »
is it possible to tell the AI to target anyone. meaning it fires on friends, enemys, neutrals, non identifiable - simply everything targetable in the system; i'd need that for a mod.
It isn't exactly fitting into this topic, but whatever...
Yes you can do that. Before creating the AI, create a App.ObjectGroup object, and add to it the names of all targeteable objects. Then pass this ObjectGroup instance to the AI when you create it. The ObjectGroup instance is basically a list of ships. When passing it to a AI, the AI uses it as the list of enemy ships to target and fire. Dunno if this will get updated correctly tho, when ships exit the game and new ships come in...
Or you could do something like i'm trying to do: add a preprocessor before the Compound Attack AIs, and make it select a target for the ship. So you could make it choose targets kinda like how the SelectTarget preprocessor does, but choosing a target from all targetable ships available. Just remember to make it NOT target itself lol

And nope can't do something like the Fleet Orders mod does because all that it does is overwrite the ship's AI with a NEW attack AI, and passing in a ObjectGroup with a single name in the list: your target.
And that also doesn't get updated corretly. When the target ship is destroyed/exits the set/etc, the override AI is cancelled, and the old AI is restored to the ship so it resumes doing what it was doing.


BTW, I was "studying" the SelectTarget preprocess today, to see what it did that mine wasn't doing to work. After that I made my "ConcentrateFire" preprocess to call all externally registered SetTarget functions in the AIs beneath it, just like the SelectTarget preprocess does.
And it worked =P Ships finally concentrated fire on my target.
However sometimes they acted a little weird, like they didn't updated correctly. For example for the attack AI in these ships to be active, the ship needs to be at least 70km away from the lead ship, otherwise they shall intercept the lead ship. But sometimes the ships seemed to get "stuck" in the attack AIs, and even more than 70km away from the lead ship they continued in the attack AI instead of intercepting the lead ship.
When I noticed this happened, I called "Ship.GetAI().Reset()" from the console and the ships updated correctly, intercepted me and when they got close they resumed attack procedures.
So I still gotta test this more to see if it is working correctly... I can, but I don't want to make something to keep caling .Reset() in these AIs...
"Revenge is a dish best served cold"
                    -Old Klingon Proverb
GravityFX Download
Galaxy Charts Download

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Re: Setting the target of AI ships.
« Reply #4 on: July 21, 2008, 08:38:03 AM »
First of all @CNotsch, no need to hijack someone elses topic, it's simply not nice.

Anyway...

I believe a single weapon system can have it's own target. For example, the StartFiring method a system takes in a target and a location, both are used for InaccurateWeapons.
So that could be why ships continue firing.

What you can try is to attach an event handler for ET_TARGET_CHANGED to the fleet commander and issue a "New Target List" event that triggers TargetListChanged, and only include the ship that the fleet commander is targgeting.

[EDIT] The initial event would be either ET_TARGET_WAS_CHANGED, ET_SET_TARGET or ET_TARGETED_SUBSYSTEM_CHANGED
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline cnotsch

  • Posts: 85
  • Cookies: 3
Re: Setting the target of AI ships.
« Reply #5 on: August 01, 2008, 05:29:22 AM »
First of all @CNotsch, no need to hijack someone elses topic, it's simply not nice.

sorry about that, i was in a hurry and i had no time to read the question, i only thaught that would fit in here because of the headline.

Thanks for your advice, and of course USS Fontier for the help.