[MOD] BetterTurrets. Updated 20.12.2014

The place to discuss scripting and game modifications for X Rebirth.

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

Post Reply
cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

[MOD] BetterTurrets. Updated 20.12.2014

Post by cicero111 » Thu, 30. Oct 14, 22:23

Better Turrets
=========

What it does:
- It changes targeting logic for the defense officer AI on all capital ships.
- Skill checks for detecting targets. Combat is the most important one, but leadership and morale are also used in the calculation.
- Line of sight check for all targets to minimize damage from friendly fire when flying in formation.
- Target priority logic for turrets (fighters -> cap surface elements -> hull). Similar logic when atacking stations.
- Separate target priority logic for "Big guns" (i.e. IHC and torpedo launchers).
- Capital boarding support mode when the defense officer is in defensive mode.
- Station supression mode. When DO in defensive mode, only attack weapons (also valid with attack object). Might be useful for station hacking/piracy.
- Limits the drone targets to be within 3KM to avoid drones wandering off.
- Drone wing size and launch delay based on DO skill and ship type.
- "Big gun" control (Balor/Sucellus). A defensive DO will not fire the "big guns" except on station hull/surface targets. In offensive no DO will fire those at fighters anymore, except skunk for NPC's.
- Capship wingmen wil "inherit" their leader DO offensive/defnesive (might take some seconds before they get the memo).
- Beta 2.1: Drone leaders will if their target is destroyed check with their DO for a new one before returning home.
- Beta 2.1: Player caps and friendly cap NPC's will stop shooting at target if it's is boarded by the player and hull gets below 50%. (NB: stations and fighters will still shoot at it).

How it works:
- I'm using the check_line_of_sight function to verify target is possible to hit before adding to target list (uses ray cast).
- For caps, the DO will prioritize targeting weapons, jumpdrive and engines. If the DO is in offensive mode (attack enemies) they add dronelauncher, radar and hull to the target list. Shieldgens are intentionally omitted since is a waste of time (the capital ship field generators have an insane amount of HP).
- NPC's will always use offensive target logic, no matter their DO defensive/offensive state.
- Switching DO modes while in combat will change their targeting behavior, but it but might not happen immediately (depends where the script are in a target check pause, maximum 20s)
- Skill check+random bonus are done for every target/surface element.
- The better DO skill the more drones will be launced (max 10). Launch delay is lowered for good DO's as well. L ships (except the suls) will launch half the number of drones as XL ships.

Installation:
Extract in extensions dir as pr. usual.
Download link:
2.5x version: https://dl.dropboxusercontent.com/u/652 ... s_beta.zip
3.0 version: https://dl.dropboxusercontent.com/u/652 ... eta2.1.zip

Savegame safe?
Probably, I don't move any of the wait blocking parts.
Will recommend adding and removing the mod on a save with no caps in the same zone as the skunk (caps need to be OOZ to cycle/load and unload the new AI code). Leaving and reentering the zone will also work (not by traveling on a cap of course).

Caveats:
The game engine allows to do LOS check from each turret, but does not allow a script to directly control each turret.
To avoid resource intensive LOS recursive loops the mod only do the LOS checks from the ship centerpoint.
The consequence mainly are for long ships, where some of the turrets can still try to shoot through their wingman etc.

Compability with other mods:
The mod replaces the entire in-sector section of the fight.attack.object.capital.xml script.
Mods that don't change anything with the Defense Officer, i.e. don't touch that script will work fine.

Todo/ideas:
- Code optimizing and cleanup, and I suspect some bugfixing.
- Put it on Steam WS when verified in release state.
- Add some mod compatibility stuff if it's wanted.
- Make the mod more user friendly (add a couple info popups on first run and maybe other GUI stuff).

The mod is based with permission on some of the targeting AI code in iforgotmysocs SkunkTurret mod, adapted for caps and extended with additional features.

Any feedback, tips and ideas would be most appreciated.
My code in this mod will be released with WTFPL when it's done, so if some stuff should be added to complement other mods, just give me a hint and I'll se what can be done.
Last edited by cicero111 on Sat, 20. Dec 14, 23:33, edited 33 times in total.

User avatar
Litauen
Posts: 193
Joined: Fri, 22. Nov 13, 21:09
xr

Post by Litauen » Thu, 30. Oct 14, 23:22

Great mod! Will try it with my Fulmekron+Taranis vs Xenon K.

Can you recommend something to look for when I will watch the battle from the safe place? Any signs of improved behavior?

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Thu, 30. Oct 14, 23:37

Thanks :)
When in offensive mode it might not be immediately visible since it has a lot of targets including the hull. But at closer range you should see a priority to fire on certain surface elements.

When switching to defensive mode it will be very visible - will only be focused fire on turrets/JD and if not in too steep angle they will shoot at the engines. If no allowed target is in sight, the turrets will stop firing/find another enemy from the general targets list.

If wingman or other object gets in the way between this.ship centerpoint and target, the firing should also stop. LOS recheck happens every 10-20s (random).

denison10
Posts: 27
Joined: Sun, 12. Oct 14, 01:57

Post by denison10 » Fri, 31. Oct 14, 02:32

Code: Select all

["message"]="Error: LookupKeyName::LookupName(): The key name \"if\" is not recognized in lookup 'ScriptXML'. Originated from: \"aiscripts\\fight.attack.object.capital.xml.(pck|xml)\"",
["timestamp"]=1414718182.000000,},
I think the problem here
195 <!--if no priotarget fighter and no cap surface element objects just add list (cap hull not added to valid targets when DO passive in find enemies part) -->
196 <set_turret_targets object="this.ship" target="$targets.list" />
197 <if value="$target.isclass.station">
198 <set_value name="$targetisstation" exact="true"/>
199 </if>

DaveDee
Posts: 285
Joined: Sat, 18. Oct 14, 13:10
x4

Post by DaveDee » Fri, 31. Oct 14, 08:20

Sounds like first attempt to replace broken CDOAIO.

Adding skills to calculations would be very nice, but in my opinion, such behavior would be overpowered, if npc can't use the same logic.

Also, dronebay destroing is just a waste of tons of drons in capped ship. Don't whink you need to add it in defensive mode.

Sparky Sparkycorp
Moderator (English)
Moderator (English)
Posts: 8074
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Fri, 31. Oct 14, 08:50

Nice one :)

With regards CDOAIO, if we're using that mod for the improved Balor and Sucellus move code but without using it's fight.attack.object.capital.xml (to avoid the drone cross side effect), might it be compatible?

bm01
Posts: 421
Joined: Wed, 22. Jul 09, 22:31
x4

Post by bm01 » Fri, 31. Oct 14, 12:30

About compatibility, changes brought by Automated Emergency Jump might be completely ignored, depending on the loading order (which can't be controlled as far as I know). Could work fine too.

But I noticed that there's a lot of copy past from the vanilla script to yours. I don't think you need to replace the whole attention node, three or four well placed <add.../> would have done the work and limited some incompatibilities.

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Fri, 31. Oct 14, 15:14

@denison10
Thanks for reporting :) I'll add some input validation on that section.
The targetisstation part will be removed btw - was just some experimenting "what will happen if i add this" - the shoot_at largetarget="$targetsstation" where it's used are for fighters really :P

@DaveDee
I agree - balancing is important. Added in todo list. NPC/playerownerd should be roughly equal.
Dronebay/radar/hull targeting should only be done when in offensive mode. When defensive only weapons, jumpdrive and engines are added to allowed targets - please report if they still shoot out the dronebay when in defensive though, some bugs in the code are close to guaranteed :)

@Sparky
Yea, was thinking about CDOAIO mod with the "mod compatibility" in the todo list. Have been reading through those scripts a few times - a lot of clever code in there. If the patch load order can be controlled to secure that my patch is loaded last it is doable.
Was thinking about either patching out the OOS zombie dronespam code or replacing the entire OOS section in that mod with vanilla.
If you remove fight.attack.object.capital.xml from CDOAIO my mod wil be compatible.

@bm01
I replace the entire <attention min="visible"> section cause xpath is hard :P The plan is to do it right and only patch only the diff and not have all that vanilla stuff in there (therefore those marked sections in the code).

Load order with AEJ should not matter if i understand the patching process correctly since it only touches the OOS part of the code which I don't change. It's a theory why that one still worked anyway...



I'll probably release a new version later today, planned:
Optimization: Stop LOS and range checking mass traffic (doh...)

New feature: "Disarm station mode" when DO in defensive (i.e. only target weapons) - might be nice for piracy/station hacking stuff.

bm01
Posts: 421
Joined: Wed, 22. Jul 09, 22:31
x4

Post by bm01 » Fri, 31. Oct 14, 15:55

cicero111 wrote:I replace the entire <attention min="visible"> section cause xpath is hard :P The plan is to do it right and only patch only the diff and not have all that vanilla stuff in there (therefore those marked sections in the code).
Don't hesitate to ask for help, much better than spending hours alone trying to make it work :p
I guess it would (could) look like this (example with the first modified section):

Code: Select all

<add sel="\\attention[@min='visible']\actions\do_if[@value='$enemies.count'][@min='1']" pos="before">...</add>

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Fri, 31. Oct 14, 20:38

@bm01
Part of the fun is struggling a bit before discovering the solution, but that double bracket ting really eluded me. Thanks for the tip, saved me a lot of time :)

Any tip for a good way to test patches btw.? Preferrably a simple shell command type $/command inputfile.xls patch.xls -o output.xls. Been looking, but my limited google-fu have not been successful yet.


Anywho, have published alpha2.
Fixes:
- bugfix for issue reported by denison10
- LOS/range check and range priority removed for mass traffic. Are now just added as targets of opportunity.

Added:
Station supression mode.
LOS target only weapons when DO in defensive. When in offensive will be similar to vanilla but prioritize weapons over station hull, and ignore shieldgens and other surface elements to avoid wasting shots.
Tested with my fulmecron+taranis/sucellus wingmen, but my vanilla captains move like molasses close to stations so did not have the patience to completely kill it. Seems to work as planned though.

Sparky Sparkycorp
Moderator (English)
Moderator (English)
Posts: 8074
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Fri, 31. Oct 14, 22:48

Nice changes. I'll give it a trial run over the weekend, thanks.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sat, 1. Nov 14, 00:00

cicero111 wrote:@bm01
Part of the fun is struggling a bit before discovering the solution, but that double bracket ting really eluded me. Thanks for the tip, saved me a lot of time :)

Any tip for a good way to test patches btw.? Preferrably a simple shell command type $/command inputfile.xls patch.xls -o output.xls. Been looking, but my limited google-fu have not been successful yet.
thats something i can use my 10.000th Post for :)

got such a program for quite a while now, i planned to use it as compatibility tool for Savegame patching (bat for that purpose is included ;) it should give you all info necesary ;) )

DL here ;)

and regarding xml patching: you can ask me too if you have problems ;) it may take a bit time though since i have a hang to immerse me too much in my own stuff and forget other things i wanted to look into ^^
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sat, 1. Nov 14, 11:51

Thankyouthankyouthankyou! :D
That one should be added to the XML patch guide. No more "i think maybe perhaps this should work in theory..." and test if the game complains - which it usually does :P

And congrats for the 10000 post {me bows} :D
My scientific calculator tells me i've only got 9971 posts to go.

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sat, 1. Nov 14, 15:33

New version is up, alpha 3:
Bugfix: Added another input validation to avoid a potential null check error.

Changes:
NPC's now use the same code as player ships. Their DO combat state is ignored (will always use same as playerowned offensive).

Skill checks added. This works as follows:
Calculated skill value: 10 + combat*2 + leadership + morale
Max for a 3*5 star defence officer is then ofc.: 10+10+5+5 = 30

The first base 10 value are added to implement some penalties at a later stage (planning something similar as CDOAIO battle outlook/panic checks)

For each check there are added a random 0-10 bonus.

The skill checks are done when searching for targets:
1: Must be a total of 20 or higher to detect an enemy at all.
2: Capship and station module targetting have to be above 30.

This means a 5*5*5 DO will always find all potential targets, while an 0*0*0 will not be able to even detect an enemy station unless really lucky (sleeping off some spacefuel fun somewhere I guess).

If interested - uncomment debug entry in line 64 to get some logspam in the debug log about what the enemy stats are.


Might have to give the NPC's some extra bonuses since they have often some really crappy DO's... Need some feedback on that one.

And also - please report if the mod now makes the game laggy. Works fine at my end but i have a quite beefy machine. I can reduce some of the LOS checks to reduce load if necessary.

Sparky Sparkycorp
Moderator (English)
Moderator (English)
Posts: 8074
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Sat, 1. Nov 14, 19:47

Hello, and a couple questions :)

1. What is the interval between skill checks?
2. After a successful skill check, do the rolls stop until combat is over?
3. What happens if the ship is getting shot and the DO fails the check?

Thanks,
Sparks

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sat, 1. Nov 14, 21:21

The script loops every 10-20 seconds if enemies are in range.
For each loop the script recheck everything - i.e.
1: Do the DO detect enemy x at all? (easy skillcheck + random bonus pr. target)
2: If the target has surface elements (cap/station) - Can DO find surface element x (harder skillcheck + random bonus pr. element).
At stage 2 the hull is always added in the end as a valid target here for offensive DO + all NPC's since sucessful in step 1.

All targets are added to a general targets list + prioritized targets. I then assign those to the turrets who do their own thing after that.

So If the DO fails the check already at step 1 when for example attacked by a cap (low posibility unless the DO is completely incompetent) the attacker will not be shot at at all.
If the DO is succesful at step 1, but fails all all surface element checks at step 2 they will just shoot at the hull.

And have to mention when the priority target is destroyed the turrets will switch to shooting at targets in the general targets list - quite a nice function in the turret code there (exe based afaik).

There is no priority of targets who shoot the cap (not in vanilla either) - they are mostly based on range checks and target types. I have seen a function available to check for that - will see if can implement some prioritisation for threat level, I'll add it to the todo list :)

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sun, 2. Nov 14, 19:35

New version is up, alpha 4.
Bugfix:
Proper targeting of dronebay and radar for offensive DOs/NPCs (regression error after changes in alpha3).

Added:
Drone targeting of cap ships for offensive DO's and NPCs. Wing size and launch delay are based on DO skill and works as follows:
Wing size is set to DO "baseskill" (min 10 max 30) divided by 3. For comparison vanilla=5
Launch delay (to replenish lost drones) is 75-DO baseskill. i.e. will vary between 45-65s. Vanilla is 60s.
Might have to nerf it a bit, we'll see <- please leave a comment aye/nay.

Had a plan to make drones attack surface elements out of sight only, but will have to rewrite the drone scripts for that (only allows ship object as input) - have to think a bit about that one..

Anywho, getting close to feature complete. Probably last alpha on this mod.

swatti
Posts: 1278
Joined: Sun, 7. Dec 03, 12:03
x4

Post by swatti » Sun, 2. Nov 14, 19:54

Can this mod change what MINING-turrets target?
Right now they target large asteroids first, once they go pop, the ship itself moves on as the roid went boom...

If it were to target SMALLEST target first, the drones would have something to carry back home before the ship itself moves on.

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sun, 2. Nov 14, 20:21

Heh - I have actually started looking a bit at the mining script to see if zapping of miner drones can be avoided, and to see of roid selection could be improved. That script is a bit related to the one i've been modding here when it comes to the targeting/shooting logic for the mining lasers.

It's on the "maybe mod this thing?" list at the moment - will be a separate mod probably.

swatti
Posts: 1278
Joined: Sun, 7. Dec 03, 12:03
x4

Post by swatti » Wed, 5. Nov 14, 18:15

QUESTION: will this improve Sucellus IHC firing more often and Balors using torpedoes?

Kinda silly, Sucellus will try to fire at fighters but wont do so against cap-ships. I cant seem to make my balor fire torpedoes no matter what but against some enemies NPCs do fire torps.

Post Reply

Return to “X Rebirth - Scripts and Modding”