[SCRIPT][AP][TC] Advanced Fight Scripts - v. 3.1, 19.01.2014

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
Cronos988
Posts: 691
Joined: Mon, 27. Aug 07, 12:34
x3tc

[SCRIPT][AP][TC] Advanced Fight Scripts - v. 3.1, 19.01.2014

Post by Cronos988 » Sun, 14. Oct 12, 18:22

Name: Cronos' Advanced Fight Scripts

Current Version: 3.1

Warning! When Updating from version 2.2, make backups of your saves. There have been significant changes to script flow. The scripts appear stable, but rare lockups may occur

Short Description:
These scripts are aimed at improving combat, mainly fighter combat, by changing the standard fight scripts.

The Scripts consist of two parts: A target picking routine and an overhaul of the Vanilla in Sector fighter combat AI.

The picking routine replaces the stock behavior for all ships with the commands: Protect, attack same, attack nearest and kill all enemies, as well as any reaction (like signal_attacked) that calls fight scripts
The Vanilla target picking routine consists of just having every ship in the formation attack one target, e.g. the first attacker for ships under a protect command.
With these scripts, ships will instead analyze the entire enemy formation and pick the "best" target for themselves. They do this by calculating the offensive and defensive values for each enemy ship and then attacking the ship that has the highest damage to defense ratio. As of Version 2.3, ships will take enemy speed into account and prefer slower targets, as well as targets that are attacking them.

The new fight scripts uses the local variables introduced by the picking script to check who is attacking and how to react. By using local variables, the script can tell whether it is in firing range of any attacker and if the attacker is actually firing on it. It will then calculate hit chance and damage and will react accordingly. Ships will only evade when they are in danger and will otherwise try to maximize their damage output.

Downloads:

Below are the download links for the AP and TC versions. The TC version should work with Vanilla turret scripts as well as MARS fire control. Since TC lacks a couple of weapon info commands, the scripts are less accurate in this version, but should work.

TC Version has only been tested for basic functionality! I unfortunately don't have the time to thoroughly test both script versions, so bugs may occur more frequently here. Use with caution!

I recommend installing the player only version first to test things. The scripts make fighters very deadly and will probably seriously impact balance. Especially slow ships like Corvettes get ripped to shreds by 2-3 m3 craft. Since fighters will evade a lot less, the initial damage of fighter groups is very high and can kill even medium craft quickly.

Albion Prelude Version:
[ external image ]

Terran Conflict Version:
[ external image ]

Compatibility Patch
This is an AP Only Compatibility patch for use with the AI-enabled version (which is also AP only) of Gazz's Missile safety script.
[ external image ]

To install both scripts, do the following:
Install the advanced fight scipts
Install Gazz' Missile Safety, AI version,
Copy the files from the compatibility patch to your scripts folder, overwrite existing files.

Installation Instructions

For versions prior to 3.0:
Each archive contains 3 folders: All Ships, Enemy only, and Player only. Choose which version you want to install and open the corresponding folder.

Inside are 2 folders each: The "Cap AI ON" version will make capital ships hold still in space upon reaching fighting range. This is currently only very basic behavior. "Cap AI OFF" leaves capital ships with vanilla behavior.

When you have chosen your version, continue with the below instructions for 3.0

For version 3.0 and upwards:
navigate to the folder X3Terran Conflict/addon/scripts; Con
Backup the following scripts:

- !ship.signal.attacked
- !fight.attack.object
- !fight.targeting
- !move.follow.template
- !plugin.gz.missile.def.mk3

For the TC Version, also back up all !turret scripts.

Extract all files from the chosen version folder within the archive into the scripts folder, overwriting the vanilla files.

To disable parts of the script, you can exclude certain scripts:

- Not installing !move.follow.template will make all protect, attack same and attack nearest ships behave as in vanilla
- Not installing !fight.targeting will remove the pick functions for commands like attack all enemies and protect sector
- Not installing plugin.cro.fight.attack.object will not install the fighter combat AI and only change target picking.
- Not installing !ship.signal.attacked will make ships react to attacks as in vanilla.

Script configuration (available from v. 3.0)
From version 3.0 onwards, the scripts install an artificial life plugin that allows you to configure various aspects of the script.

To access the config menu, simply navigate to artificial life settings, select Cronos Advanced Fight Scripts from the list and press ENTER or the right/left arrow keys.

This will open a config menu with three sections. Note that in order to save the changes you made, you must press the save button before closing the menu.

Top Section: Base settings
Script Mode:
Lets you choose between All ships, Player Only, or Enemy Only modes, or select none to disable the advanced fight scripts (Note that as of V. 3.0 this will only affect the fighter AI, not the target picking)
Capital ship AI:
Allows you to turn this script's AI for ships bigger than M6 on or off
Debug Mode:
Display various debugging information subtitles

Middle Section: Behavior Values
This section allows you to tweak the decision making of ships
Base reaction time:
The base reaction time is the time that must elapse before the fighter reacts to a change in the situation. If you have Fightskill effects activated, this should be set to 0.
Random move repitition:
Activating this will make ships sometimes repeat their last move irrespective of the current situation
Fightskill effects for NPC/Player ships:
Turning this one will set a reaction time (see base reaction time) based on fight skill. For Fightskill < 6, the reaction time will be 3 seconds, and be reduced by 1 second for every 10 levels. At level 26 and above, reaction time is 0. Note that base reaction time, if set, will be added to this reaction time
Aggression and Morale Effects:
Currently without function
Consider laser energy when deciding:
If activated, laser energy will influence fighter decision making. Fighters with full energy will ignore more damage.
More aggressive decision making:
If activated, fighters will take more damage before evading as long as they deal more damage than they receive.
Ship hull regeneration:
Turn this on only if you have regenerating ship hulls. This will NOT cause ship hulls to regenerate.

Bottom section: Thresholds
In this section, you can set various thresholds. Ships will do an evasive move if the receive damage equaling X% of their current shields (the shield threshold) or hull (Hull and pierce thresholds).

Note that Hullthreshold only starts to matter when the respective ship has no shields left, and therefore is only actually necessary to tweak if you disable the shield threshold.

You can disable any threshold by setting it to 0. Disabling a threshold means a ship will ignore any damage of the associated type.

Bug Reports:
If you encounter any game freezes or other bugs, please take a look into your Egosoft save folder (usually documents/Egosoft/X3AP) and look for any logfiles beginning with "119.." e.g. "11988". They might tell me if something went wrong.

Technical Description:

The script works by making non-invasive changes to a few vanilla scripts:
!fight.attack.object and !plugin.gz.missile.def.mk3 are modified to write local variables on the targeted ship, telling it who is attacking and with what.

When a formation is attacked, the !move.follow.template script then calls the new pick script. Every ship loops through the attacking formation and selects a target. Ships will select targets consecutively, not simultaneously. If a target is already engaged by sufficient (not necessarily own) forces, it is ignored.

The best target is chosen by comparing the time the target needs to kill me (or my formation leader) with the time I need to kill the target. If the target does a lot of damage and dies quickly, it gets high priority. If it does little damage and is hard to kill, it gets low priority. However, ships will try to stay within their "weight class" if possible.

Some ships, like Khaak scouts and Fighter drones, are excluded from this and default to vanialla behaviour to save processor load.

The Fighter AI

My AI script is a rewrite of the stock plugin.acp.fight.attack.object. The main part is a check that loops through all registered attackers and then checks whether any turret of the attacker can fire on me.

If it detects a turret that can fire, it will check the local variable "ACP.action" (a vanilla local) for turret 0 and a newly added turretstate local for any turrets to see if the turret is actually trying to fire.

If that is the case, the damage from this turret is calculated using bullet speed, distance and size. Using all damage values, the ship then decides whether to do an evasive move or to attack.

When attacking. ships will also asses the orientation of the targeted ship, and will adjust their speed to that of the target to keep a steady distance. This distance is calculated to give maximum hit chance by staying as far away as possible. Any unnecessary evasive moves have been removed. Ships will only evade if they are being shot at and otherwise keep pounding the target.

Version Histroy:
14.10.2012 - V.1.0 - Initial Release



15.10.2012 - V.1.01:
- Added Enemy-only-Version.
- Removed hit chance calculations for OOS battles
- Fixed ships not registering attacks correctly when attackers are only running simple fight script
- Fixed ships registering turret attacks too late
- Fixed ships not registering correctly when a turret stops firing
- Fixed faulty hitchance calculation when attacked by turrets.



25.11.2013 - V. 2.00
- Added: TC-Version
- Added: Basic capital ship AI
- Made missile bombers behave according to the script (with a target range of 10.000 for every enemy).
- Completely rewrote the targeting portion: Ships now calculate the best range for their equipped weapon and try to reach that range. Extensive testing with different battle scenarios has revealed that in a dogfight, being at the right range to hit - that is a bullet flight time of 2 seconds or less - is key. Ships now seek to achieve that. Version 2.0 Fighters appear superior to v. 1.1 Fighters in testing.
- fixed a possible bug with ships not attacking stations when using "attack all enemies" type commands
- fixed various small bugs and inconsistencies
- The Scripts are now delivered in one package, with subfolders corresponding to different verisons (enemy only/player only).



28.11.13: V. 2.10
Added: Additional defensive moves:
Ships now have 2 defensive moves:
- Evasive attack: When attacked by the main guns of a smaller ship, ships will sometimes turn to attack - and thereby dislodge - their attacker instead of trying to dodge. This triggers against close enemies against which evading is less efficient
- Moving out of range: When attacked by turrets, ships will try to move out of range of the turret. This is especially efficient against flak.

Changes:
- increased target acquisition range when in protect mode from 8000 to 16000m
- adjusted values to make fighters more aggressive in dogfights
- enabled some evasive moves for capital ships

Bugfixes:
- added failsafe to prevent null returns by missile turrets
- disabled standard missile firing for bombers.



02.12.2013: v. 2.2
Added:
- Support for SMART turret scripts (TC and AP)
- Support for MARS AP (also updated the TC version)

Changes:
- Fighter drones no longer use the advanced fight scripts
- Ships now take current laser energy into account
- Ships stay out of range when below 25% shield

Bugfixes:
- Fixed major bug with target speed calculation
- Fixed targeting starting fight scripts on tasks other than 0
- Added failsafe for Khaak Clusters


12.01.2014: v. 2.3
Added:
- Support for "signal_attacked"

Changes:
- Made M6 more responsive
- Rewrote speed finding algorithm to get ships into range more efficiently
- Optimized defensive move choosing to be faster and cover more scenarios.
- Significant changes to target pick scripts to make it more accurate and less prone to attack small targets
- Streamlined Retargeting after initial enemy is dispatched
- Improved ships situation awareness by always considering full enemy formation.
- Increased target acquisition range slightly
- Disabled Vanilla pilot skills (to have clearly reproducible behavior)
- Reduced target range for missile bomber slightly.
- Reduced range buffer

Bugfixes:
- Fixed Target picking not properly accounting for piercing weapons
- Fixed Target picking not accounting for speed
- Removed some inconsistencies in calculating hit chance
- Fixed non-fighter ships calling vanilla fighter scripts in Player-/Enemy- only versions
- Fixed target picking not properly registering the player ship
- Removed defensive move that would sometimes disable ship collisions
- Fixed Ships immediately docking at any range and with any target

15.01.2014, V. 2.4:
Added:
- Optimization against fighter drones
- Support for implementation of fight skill and pilot morale/aggresion (disabled by default)
- support for random move repitition for less predictable behavior (enabled)

Changes:
- Changes to !move.follow.template to make protect commands more useful (ships on protect duty now help their protect target even if there hasn't been a counterattack yet).
- Switched plugin.cro.advf.pick back to .pck format.
- Ships that are staying back to regenerate now evade even if they wouldn't normally consider the damage serious enough

Bugfixes:
- Fixed ships being unable to navigate around obstacles and getting stuck in certain situations.
- Fixed defensive moves overriding basic attack/defense decision making
- Fixed script assuming hulls can regenerate
- Fixed ships searching for new targets after being attacked and defeating the attacker.


18.01.2014, V. 3.0:
Added:
- Menu system. No more different folders for different modes!
- Various configuration options are now accessible (most changes take effect immediately).
- Fightskill effects are now available
- More aggressive decision making available to make fighters less scared of small turrets

Changes:
- Changed pick script behavior after a fight has finished to check the initial enemy formation again for valid targets
- Various little code changes to implement config values

Bugfixes:
- Fixed some errors in !Fight.targeting
- Fixed "Ram attack" evasive move, should hopefully fix ships getting stuck at 0m/s

19.01.2014, V. 3.1:
Added:
- "Reset to defaults" Button to menu

Bugfixes:
- Fixed settings reverting to default every startup


Edit [1st Dec 2015]: replaced outdated download links with working ones. X2-Illuminatus
Last edited by Cronos988 on Sun, 19. Jan 14, 10:45, edited 15 times in total.

Cronos988
Posts: 691
Joined: Mon, 27. Aug 07, 12:34
x3tc

Post by Cronos988 » Sun, 14. Oct 12, 18:23

Please report your findings on how well these scripts work, especially if the situation awareness of the fighters is accurate and how well targets are picked. This is difficult to asses in a testing environment as there are just to many possible combat scenarios.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Sun, 14. Oct 12, 19:17

Sounds like a great idea, Cronos.

How about an enemy-only version? The player is already overpowered.

User avatar
joelR
Posts: 2008
Joined: Mon, 9. Jul 07, 23:33
x3tc

Post by joelR » Sun, 14. Oct 12, 19:55

DrBullwinkle wrote:Sounds like a great idea, Cronos.

How about an enemy-only version? The player is already overpowered.
First off I want to say awesome job. This is some really quality work here. I assume the scripts only effect in sector ships?

I will also second Drbullwinkles request. Thats would be a nice option.

Im really looking forward to seeing how this does with XRM. Will be fun. It amazes me that after all these years scripters are still doing amazing stuff like this.

Cronos988
Posts: 691
Joined: Mon, 27. Aug 07, 12:34
x3tc

Post by Cronos988 » Sun, 14. Oct 12, 22:05

joelR wrote:
DrBullwinkle wrote:Sounds like a great idea, Cronos.

How about an enemy-only version? The player is already overpowered.
First off I want to say awesome job. This is some really quality work here. I assume the scripts only effect in sector ships?

I will also second Drbullwinkles request. Thats would be a nice option.

Im really looking forward to seeing how this does with XRM. Will be fun. It amazes me that after all these years scripters are still doing amazing stuff like this.
Thanks,

The fight script is started in place of the vanilla "advanced" fight script, which is started in any sector that the player could potentially see.

The pick scripts run OOS as well as IS. Since all scripts run on task 0, the load should not be significantly higher, I have a pretty old machine and it is stable. But if there are issues I can make the scripts only run IS.

Btw the reason for having the target pick script run OOS is to make OOS battles more believable. With the vanilla scripts, fighter wing leaders have to be extremely sturdy because they recieve the entire damage. One of the reasons I made this was to spread the damage across the formation in a realistic way.


I can definetly make an "enemies only" version. It's pretty much only reversing the race check I do in the player only version.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Sun, 14. Oct 12, 22:11

Cronos988 wrote:I can definetly make an "enemies only" version. It's pretty much only reversing the race check I do in the player only version.
That would be great, Cronos. Enemies need the help more than the player.

You could make a single version with an option in a t file to control which behavior the player desires. That would simplify your maintenance.

User avatar
Sorkvild
Posts: 3432
Joined: Thu, 8. Jun 06, 14:07
x3tc

Post by Sorkvild » Sun, 14. Oct 12, 22:49

Sounds interesting, is this player only script?
Elite Dangerous| I survived the Dragon Incident ... then I took an arrow to the knee
We want the Boron back!

Teronredoran
Posts: 47
Joined: Thu, 22. Mar 12, 21:04
x3tc

Post by Teronredoran » Mon, 15. Oct 12, 07:21

Might be a stupid question, but does this work with Litcube's Bounce?

Cronos988
Posts: 691
Joined: Mon, 27. Aug 07, 12:34
x3tc

Post by Cronos988 » Mon, 15. Oct 12, 08:46

Sorkvild wrote:Sounds interesting, is this player only script?
When you install the basic version, all ships will get the new behaviour, not just player ships. It is mostly geared towards fighters, capitals probably won't behave much different.
Might be a stupid question, but does this work with Litcube's Bounce?
I am pretty sure it does, I am running both scripts and Bounce still works.
You will, however, notice that fighters will no longer "slam" into capital ships. They will instead stop at the maximum range of their front guns and only move to keep the capital in range or to evade turret fire.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 15. Oct 12, 08:50

Cronos988 wrote:fighters will no longer "slam" into capital ships. They will instead stop at the maximum range of their front guns and only move to keep the capital in range or to evade turret fire.
Does that make fighters less effective when attacking capital ships? How effective are guns at maximum range?

Cronos988
Posts: 691
Joined: Mon, 27. Aug 07, 12:34
x3tc

Post by Cronos988 » Mon, 15. Oct 12, 08:57

DrBullwinkle wrote:
Cronos988 wrote:fighters will no longer "slam" into capital ships. They will instead stop at the maximum range of their front guns and only move to keep the capital in range or to evade turret fire.
Does that make fighters less effective when attacking capital ships? How effective are guns at maximum range?
They should actually be more effective. Capitals are huge, and a fighter can easily hit them from 2 km away.
On the other hand, Flak weapons have limited range so when the capital starts to shoot back, the fighter can quickly leave the range.

Mad_CatMk2
Posts: 518
Joined: Sun, 22. Feb 09, 20:13
x4

Post by Mad_CatMk2 » Mon, 15. Oct 12, 09:00

Wow Cronos this looks to be an awesome script! Feels like a Fight MK3 'lite' from X3R days.

Question is, can this script also be adapted to modify capital combat behavior? Or would it be too cumbersome to deal with turret layouts and such?

Otherwise keep this up man, can't wait to try this 8)
I fly an OWP. What about you?

Cronos988
Posts: 691
Joined: Mon, 27. Aug 07, 12:34
x3tc

Post by Cronos988 » Mon, 15. Oct 12, 09:47

Mad_CatMk2 wrote:Wow Cronos this looks to be an awesome script! Feels like a Fight MK3 'lite' from X3R days.

Question is, can this script also be adapted to modify capital combat behavior? Or would it be too cumbersome to deal with turret layouts and such?

Otherwise keep this up man, can't wait to try this 8)
I am actually planning to do this. The Problem is, as you said, that there is no way to know turret layout.

My current plan is to have Capital ships "circle" each other, trying to get the front towards the target while staying at optimal range. The optimal range would be based on ship strengths: Either being able to hit the enemy while he cannot shoot back or getting really close to the enemy if the ship's defense is significantly higher than that of the opponent.

I am currently fixing some issues with anti-capital behaviour, turns out fighters think they are under attack even when the turret has stopped shooting but hasn' picked a new target.

Jumee
Posts: 2893
Joined: Sat, 29. Oct 11, 20:19
x3tc

Post by Jumee » Mon, 15. Oct 12, 10:41

this sounds... awesome! if there is one thing X lacks thats difficulty, might even start playing again :)

Mad_CatMk2
Posts: 518
Joined: Sun, 22. Feb 09, 20:13
x4

Post by Mad_CatMk2 » Mon, 15. Oct 12, 10:54

Cronos988 wrote:I am actually planning to do this. The Problem is, as you said, that there is no way to know turret layout.

My current plan is to have Capital ships "circle" each other, trying to get the front towards the target while staying at optimal range. The optimal range would be based on ship strengths: Either being able to hit the enemy while he cannot shoot back or getting really close to the enemy if the ship's defense is significantly higher than that of the opponent.

I am currently fixing some issues with anti-capital behaviour, turns out fighters think they are under attack even when the turret has stopped shooting but hasn' picked a new target.
Thanks for the quick answer, this REALLY is getting me super hyped. I'm sick and tired of watching my huge ships just headbutting fighters (I mean it works...really, just silly :roll: )

Well that and having Bounce makes the ramming slightly more tolerable.
Side note: Wouldn't Bounce affect the fight script? Or would both coexist happily ever after?
I fly an OWP. What about you?

Cronos988
Posts: 691
Joined: Mon, 27. Aug 07, 12:34
x3tc

Post by Cronos988 » Mon, 15. Oct 12, 11:13

Again I am Pretty sure bounce will not be affected by changes to fighter AI, as bounce checks the position of the fighter, not it's script commands.

Update: V. 1.01:

- Added Enemy-only-Version.
- Removed hit chance calculations for OOS battles
- Fixed ships not registering attacks correctly when attackers are only running simple fight script
- Fixed ships registering turret attacks too late
- Fixed ships not registering correctly when a turret stops firing
- Fixed faulty hitchance calculation when attacked by turrets.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Mon, 15. Oct 12, 12:07

Cronos988 wrote:- Added Enemy-only-Version.


Nice!


Cronos988 wrote:They should actually be more effective. Capitals are huge, and a fighter can easily hit them from 2 km away.
Have you tested that? My experience is that guns do much more damage at half of their maximum range than they do at full range. It does not appear to be related to hitting the target -- it seems to be a difference in damage per second.

I always assumed that the standard vanilla attack runs (which sometimes end in crashing into large targets) were necessary in order for the fighter to effectively damage its target.

I have not tried to test it thoroughly; it is just an anecdotal observation. I was just wondering whether you had tested your wait-at-full-range idea to make sure that it works as well as you expect?

Cronos988
Posts: 691
Joined: Mon, 27. Aug 07, 12:34
x3tc

Post by Cronos988 » Mon, 15. Oct 12, 12:45

DrBullwinkle wrote:
Have you tested that? My experience is that guns do much more damage at half of their maximum range than they do at full range. It does not appear to be related to hitting the target -- it seems to be a difference in damage per second.

I always assumed that the standard vanilla attack runs (which sometimes end in crashing into large targets) were necessary in order for the fighter to effectively damage its target.

I have not tried to test it thoroughly; it is just an anecdotal observation. I was just wondering whether you had tested your wait-at-full-range idea to make sure that it works as well as you expect?
My tests suggest that my scripts do superior total damage compared to vanilla. That could of course be due to the fact that the fighters just survive longer.

I should probably specify that ships do not just stop, they still do attack runs, just at speed0 . That means they'll still turn. Since all bullets reliably hit, damage should be maximal. RoF should not be affected by distance.

However, I can test some different distances. The Problem with going closer is the flak. Evasive moves aren't terribly efficient and the longer it takes to get out of Flak range, the more damage the fighter takes.

Cronos988
Posts: 691
Joined: Mon, 27. Aug 07, 12:34
x3tc

Post by Cronos988 » Mon, 15. Oct 12, 13:02

DrBullwinkle wrote:
Have you tested that? My experience is that guns do much more damage at half of their maximum range than they do at full range. It does not appear to be related to hitting the target -- it seems to be a difference in damage per second.

I always assumed that the standard vanilla attack runs (which sometimes end in crashing into large targets) were necessary in order for the fighter to effectively damage its target.

I have not tried to test it thoroughly; it is just an anecdotal observation. I was just wondering whether you had tested your wait-at-full-range idea to make sure that it works as well as you expect?
My tests suggest that my scripts do superior total damage compared to vanilla. That could of course be due to the fact that the fighters just survive longer.

I should probably specify that ships do not just stop, they still do attack runs, just at speed0 . That means they'll still turn. Since all bullets reliably hit, damage should be maximal. RoF should not be affected by distance.

However, I can test some different distances. The Problem with going closer is the flak. Evasive moves aren't terribly efficient and the longer it takes to get out of Flak range, the more damage the fighter takes.

AshToDust
Posts: 166
Joined: Thu, 5. Jan 12, 11:12
x3tc

Post by AshToDust » Mon, 15. Oct 12, 17:48

This sounds awesome and I m going to test it first thing in my next gaming session ^^

But, on theory, I won't make fighter match target speed but just make them a bit faster. Like target speed + 20% (in range of max speed of course). It's just plain error for fighter to be sitting duck ;)

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”