Author Topic: Perspectives from a lazy modder: Capship AI  (Read 6854 times)

0 Members and 1 Guest are viewing this topic.

Offline Zarax

  • 210
Perspectives from a lazy modder: Capship AI
This will probably stir some controversy, especially as I know AI programming is something extremely difficult to touch.
From the lazy FREDer point of view capital ship to capital ship combat is like having to shoot a movie: every movement has to be planned carefully and ships needs to be strictly guided to obtain good results.

Using the attack command is a guarantee for hilarious consequences and ultimately ship collision most of the time as ships will try to waltz around each other ignoring their strong points.
"Use waypoints and sexps, you dummy!" has always been the standard solution but is that the only possible solution?

Rewriting AI is extremely hard indeed, but are we sure we need the same AI complexity as fighters and bombers?

Let's review for a moment the closest thing we have in reality, battleships engagements.
Without going into tactical subtleties, we could define a ship to ship engagement like this:

1) Get into optimal range for your biggest guns
2) position yourself for a broadside
3) shoot
4) if your guns are out of commission turn to fire your other batteries or try to flee

Of course this is a very simplified summary of a real battle but at the same time complexity is something we want to avoid in AI coding.

So, to translate this into something that could be coded we need to create a set of routines that AI could follow.
How could that work?
IMHO this could be coded in a series of steps (under the assumption the ship is on beam-free-all):

Phase 1, on mission start: ship fire-power assessment

1) define 6 90° ship quadrants (front, left, right, rear, top, bottom)

2) calculate main weapons position (main is defined as weapons with the "huge" and similar flags in weapons.tbl)

This could be a bit tricky and imho there are two ways to do that: either we use turret FOV from the model to auto assign them to one field or the other (difficulty: unknown) or define the quadrant(s) manually for each turret in ships.tbl (likely easier to code but a PITA to redo ship tables).

3) calculate quadrant strength (easy enough, sum the weapon damage)

4) calculate quadrant maximum range (pick the longest ranged weapon in the quadrant, which usually is the strongest at least in vanilla FS2)

Phase 2, upon attack order: Ship positioning

1) Pick strongest quadrant

2) Pick quadrant maximum range

3) Pick target distance

4) turn ship towards target

5) move ship to firing range, which can be defined as a % of quadrant maximum range (80-90% to ensure the ship can properly hit its target)

6) stop ship

7) rotate strongest quadrant towards target

Phase 3, upon receiving hit: Fighting

1) check turret subsystem health

2) for each destroyed turret recalculate quadrant strength by subtracting destroyed turret weapon damage

3) compare quadrant strength

4) if current engaged quadrant strength falls below a % of next strongest quadrant maximum strength, rotate ship to engage with the current strongest quadrant

The difficulty of coding this is unknown to me and would likely need to be seriously assessed by coders, but imho the principles are simple enough to be tied into the current code without creating a revolution.

Advantages:

- capships behaves in a realistic way by default
- reduced need for sexps
- more predictable capship behaviour

Disadvantages:

- Someone has to code it
- it could influence vanilla FS2 (although imho to a very minor extent)
- is in need of further refinements (it assumes targeted ship is static and that ship has at least one anticap weapon)
- could increase system requirements

What do you guys think?
The Best is Yet to Come

 
Re: Perspectives from a lazy modder: Capship AI
You should check out the RTS mod thread in the FSO modding subforum.

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Perspectives from a lazy modder: Capship AI
Well, this sort of mirrors my thinking on the subject. Regarding your disadvantages though:

Quote
- it could influence vanilla FS2 (although imho to a very minor extent)

No, it wouldn't. Any such change would be hidden behind an ai_profiles or FRED flag that has to be set explicitly by a modder; One of the big SCP rules is that retail FS2 gameplay must remain unaltered (And assumptions made by modders of ages past may not be broken without a very good reason to do so), so this is not a concern.

Quote
- could increase system requirements

Physics (excluding collision detection), AI and sexps barely register on our frame profiling. The calculations needed to enable this smarter capship behaviour wouldn't be increasing the AI load in a measurable way, I would think.

There is also an easier solution to the whole issue of computing the optimal position for a capship, and that is to provide the information in the ships' table entry. You could add a field to the turret definition that defines which quadrant(s) this turret can fire into; this could be used by the code to quickly go through the subsystems and add up the firepower the ship can project into a quadrant. This is something that can be done quickly each frame; once the ship has determined which of its quadrants is strongest, it can go through a more detailed process to determine which precise position it wants to take relative to the target by taking into account rotation times and field-of-view values for each turret that can range on the target.

In pseudocode, the algorithm would be:

Code: [Select]
define quadrants up, down, left, right, forward, back

for each turret on the ship
    add turret to all quadrants turret can fire into

determine strongest quadrant, given range to target, sustained damage, and orders

Maneuver to bring quadrant to bear on target
Rotate turrets to fire into quadrant

Fire on target

If the ship has quadrants that could deliver more firepower than the current strongest at shorter ranges, close the range
else keep range open
« Last Edit: October 08, 2013, 04:00:41 am by The E »
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Zarax

  • 210
Re: Perspectives from a lazy modder: Capship AI
I'm sure that you have a lot more experience than me on the issue so I pretty much agree with your opinion.

I defined target as % of the longest fire range as many vanilla capships have 1-2 long range main beams plus a few smaller beams/fusion torpedo/terran huge turrets.
Those aren't usually very influential on the outcome of a capship fight (and in real life it led to the deletion of secondary batteries in favour of fewer but bigger guns) so I'd rather have a ship travel less and bring the biggest guns to bear ASAP (think terran VS shivan at long range) than wait a minute longer and suffer under fire without retaliation plus it would favour ships that have a range advantage.

The real question though is still "how much coding would that take?"
The Best is Yet to Come

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Perspectives from a lazy modder: Capship AI
See, this is where we have to look beyond the FS2 (and FS2-based) weapons mixes and combat paradigms. We have to look at this and make something that works just as well for Diaspora, TBP, Wings of Dawn, and all the other universes that people have invented.

The actual behaviour we want is rather complex, and has to be modelled and gamed out in some detail before coding starts.
There is also a question of how to give mission designers ways to influence the behaviour in order to fit the story they want to tell; Capital ships in FS will always require a certain degree of handholding in order to get them to work correctly within the confines of a story.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline m!m

  • 211
Re: Perspectives from a lazy modder: Capship AI
I don't think hard-coding this type of new capship AI into the engine code would be a good solution. As The E already pointed out the new code would have to be very customizable so a mod could change the behavior as it needs it and doing that most times ends in code which is hard to maintain.

Instead we could just expose the necessary points to code an AI to the scripting interface and do the rest in the lua code. That would leave the actual AI implementation in the hands of the modder who could then use this interface to change the way the AI works or could just use an existing AI written by someone else.

By extending this interface to all AIs we could provide entirely new capabilities, not only for capships but for all AI controlled ships.
« Last Edit: October 08, 2013, 04:40:44 am by m!m »

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Perspectives from a lazy modder: Capship AI
Absolutely. There are things we can do in the engine (like the whole quadrant assignment and determination thing), but beyond that, I think that scripting should take over the heavy lifting of determining what to do with that data.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline MatthTheGeek

  • Captain Obvious
  • 212
  • Frenchie McFrenchface
Re: Perspectives from a lazy modder: Capship AI
This is where I bring in my HW2 experience about ship AI behaviours. I don't have the HW2 files in front of my right now cause I'm at work, but basically you have a list of preset behaviours like :

  • JustShoot (don't move nor orient at all and just fire weapons at target of opportunity: that's the current default FS behaviour for capships with no orders)
  • MoveToTargetAndShoot (just move into range and shoot, don't try to orient yourself)
  • Broadside
  • Frontal
  • FlyBy (pass close to the target in a line until you're out of firing range, then turn around and pass again)
  • FlyAround (circle around the target while in firing range)
  • Dogfight (that would be what capships in FS try to do right now when you give them an attack order)

etc, with a few variants.

If the necessary hooks are made available for scripting, setting up a standard script library with this kind of preset behaviour could become very interesting. If we add the whole quadrant system proposed above (which is something HW2 doesn't have at all), we could add stuff like, let's say:

  • Sit in weak quadrant : the ship tries to position itself in the weakest quadrant of the target ship.
  • Sit in quandrant X: for example if you want to sit your cruiser behind the target destroyer and shoot at its engines, or on top of it and shoot at its weapon subsystem, or in front of it to prevent it from jumping out, or on its port side to fire at its figtherbay... all while the target ship is maneuvering

Ideally most of this could be simplified to:
  • Where to try moving in relation to the target ship
  • What quadrant to try pointing at the target ship
People are stupid, therefore anything popular is at best suspicious.

Mod management tools     -     Wiki stuff!     -     Help us help you

666maslo666: Releasing a finished product is not a good thing! It is a modern fad.

SpardaSon21: it seems like you exist in a permanent state of half-joking misanthropy

Axem: when you put it like that, i sound like an insane person

bigchunk1: it's not retarded it's american!
bigchunk1: ...

batwota: steele's maneuvering for the coup de gras
MatthTheGeek: you mispelled grâce
Awaesaar: grace
batwota: oh right :P
Darius: ah!
Darius: yes, i like that
MatthTheGeek: the way you just spelled it it means fat
Awaesaar: +accent I forgot how to keyboard
MatthTheGeek: or grease
Darius: the killing fat!
Axem: jabba does the coup de gras
MatthTheGeek: XD
Axem: bring me solo and a cookie

 

Offline mjn.mixael

  • Cutscene Master
  • 212
  • Chopped liver
    • Steam
    • Twitter
Re: Perspectives from a lazy modder: Capship AI
As already mentioned, Ams did this with the RTS script already. Note that his RTS script currently requires a custom build because he added scripting hooks not available in trunk, (because no one bothered to review and commit it, iirc). If such a project were to actually begin, Admiral MS would be one to definitely bring in on it.
Cutscene Upgrade Project - Mainhall Remakes - Between the Ashes
Youtube Channel - P3D Model Box
Between the Ashes is looking for committed testers, PM me for details.
Freespace Upgrade Project See what's happening.

 

Offline Zarax

  • 210
Re: Perspectives from a lazy modder: Capship AI
As already mentioned, Ams did this with the RTS script already. Note that his RTS script currently requires a custom build because he added scripting hooks not available in trunk, (because no one bothered to review and commit it, iirc). If such a project were to actually begin, Admiral MS would be one to definitely bring in on it.

It would be of great help... Sexping a mission where the Colossus does what it's supposed to do best (slaughtering a fleet of smaller ships) is hell as beam-free-all doesn't work that well when the ship is moving and attack order results in huge collisions.
The Best is Yet to Come

 
Re: Perspectives from a lazy modder: Capship AI
As a lazy modder myself, I also am very interested in this.

I was even designing (in my head, a long time ago) a rudimentary SEXP-based AI using universal waypoints and HP checks and junk.

 

Offline z64555

  • 210
  • Self-proclaimed controls expert
    • Steam
Re: Perspectives from a lazy modder: Capship AI
Achillion and I had touched on this idea not too long ago, but we couldn't get much headway done on it. My idea was to try to use a fuzzy logic algorithm to control the desired angles of the cap ship so that it would smoothly turn itself to optimize the firing arcs of its weapons (specifically, the weapons that would do the most damage against the target).
Secure the Source, Contain the Code, Protect the Project
chief1983

------------
funtapaz: Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Juche.
z64555: s/J/Do
BotenAlfred: <funtapaz> Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Douche.

 

Offline mjn.mixael

  • Cutscene Master
  • 212
  • Chopped liver
    • Steam
    • Twitter
Re: Perspectives from a lazy modder: Capship AI
Here are the patches that Admiral MS wrote to be able to script most of the functionality being discussed in this thread. AFAIK, none of these have made it to trunk.
Cutscene Upgrade Project - Mainhall Remakes - Between the Ashes
Youtube Channel - P3D Model Box
Between the Ashes is looking for committed testers, PM me for details.
Freespace Upgrade Project See what's happening.

 
Re: Perspectives from a lazy modder: Capship AI
1) Get into optimal range for your biggest guns
2) position yourself for a broadside
3) shoot
4) if your guns are out of commission turn to fire your other batteries or try to flee

Phase 1, on mission start: ship fire-power assessment

1) define 6 90° ship quadrants (front, left, right, rear, top, bottom)

2) calculate main weapons position (main is defined as weapons with the "huge" and similar flags in weapons.tbl)

This could be a bit tricky and imho there are two ways to do that: either we use turret FOV from the model to auto assign them to one field or the other (difficulty: unknown) or define the quadrant(s) manually for each turret in ships.tbl (likely easier to code but a PITA to redo ship tables).

3) calculate quadrant strength (easy enough, sum the weapon damage)

4) calculate quadrant maximum range (pick the longest ranged weapon in the quadrant, which usually is the strongest at least in vanilla FS2)

Phase 2, upon attack order: Ship positioning

1) Pick strongest quadrant

2) Pick quadrant maximum range

3) Pick target distance

4) turn ship towards target

5) move ship to firing range, which can be defined as a % of quadrant maximum range (80-90% to ensure the ship can properly hit its target)

6) stop ship

7) rotate strongest quadrant towards target

Phase 3, upon receiving hit: Fighting

1) check turret subsystem health

2) for each destroyed turret recalculate quadrant strength by subtracting destroyed turret weapon damage

3) compare quadrant strength

4) if current engaged quadrant strength falls below a % of next strongest quadrant maximum strength, rotate ship to engage with the current strongest quadrant

As already mentioned this is effectively what the capship AI part of the RTS script is doing. Just make like 20 different specific angles in 3D space instead of 6 quadrants (the 6 qudrants are in now way enough for getting the optimal firing orientation of several vanilla ships). Besides some of the range settings the script follows your steps.

Also this:
Instead we could just expose the necessary points to code an AI to the scripting interface and do the rest in the lua code. That would leave the actual AI implementation in the hands of the modder who could then use this interface to change the way the AI works or could just use an existing AI written by someone else.

By extending this interface to all AIs we could provide entirely new capabilities, not only for capships but for all AI controlled ships.
A script can be extended easily and is much more open for changes. It only needs a better interface with the current AI and maybe some help with turret orientation, FOV and collision detection.
Here goes scripting and copy paste coding
Freespace RTS Mod
Checkpoint/Shipsaveload script

 

Offline Zarax

  • 210
Re: Perspectives from a lazy modder: Capship AI
Sounds great!
Any hope of seeing this integrated in FSO?
The Best is Yet to Come

 
Re: Perspectives from a lazy modder: Capship AI
Is there further interest in this from the SCP Code Gods?

Personally,  the Capship AI is a massive embarrassment. Sure,  it's great to have total control over them via sexps, but it's also wasteful in Freddies time -  I have to script every Damn action.

My personal priority would be that the AI at least recognises it can hit an opponent from a distance.  This would solve a lot of stupidity. 

BH


 

Offline niffiwan

  • 211
  • Eluder Class
Re: Perspectives from a lazy modder: Capship AI
well yeah, I'm interested, although there's no way I can be considered a code god! :)  I have given Admiral MS's patches a review, I'm just waiting on his reply to my questions.  But AFAIK he's moved countries recently, so I can only imagine that he's a bit short on free time.  I'm sure it'll get into trunk at some point.
Creating a fs2_open.log | Red Alert Bug = Hex Edit | MediaVPs 2014: Bigger HUD gauges | 32bit libs for 64bit Ubuntu
----
Debian Packages (testing/unstable): Freespace2 | wxLauncher
----
m|m: I think I'm suffering from Stockholm syndrome. Bmpman is starting to make sense and it's actually written reasonably well...

 

Offline headdie

  • i don't use punctuation lol
  • 212
  • Lawful Neutral with a Chaotic outook
    • Skype
    • Twitter
    • Headdie on Deviant Art
Re: Perspectives from a lazy modder: Capship AI
But AFAIK he's moved countries recently, so I can only imagine that he's a bit short on free time. 

yer i can certainly believe that this would be a massive time sink lol
Minister of Interstellar Affairs Sol Union - Retired
quote General Battuta - "FRED is canon!"
Contact me at [email protected]
My Release Thread, Old Release Thread, Celestial Objects Thread, My rubbish attempts at art