[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: 107
Joined: Sat, 13. Aug 11, 14:30
x4

[MOD] BetterTurrets. Updated 20.12.2014

Post by cicero111 » Thu, 30. Oct 14, 23: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 Sun, 21. Dec 14, 00:33, edited 33 times in total.

User avatar
Litauen
Posts: 189
Joined: Fri, 22. Nov 13, 22:09

Post by Litauen » Fri, 31. Oct 14, 00: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: 107
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Fri, 31. Oct 14, 00: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, 03: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, 09: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: 7513
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Fri, 31. Oct 14, 09: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, 13: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: 107
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Fri, 31. Oct 14, 16: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, 16: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: 107
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Fri, 31. Oct 14, 21: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: 7513
Joined: Tue, 30. Mar 04, 12:28
x4

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

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

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

Post by UniTrader » Sat, 1. Nov 14, 01: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: 107
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sat, 1. Nov 14, 12: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: 107
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sat, 1. Nov 14, 16: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: 7513
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Sat, 1. Nov 14, 20: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

Post Reply

Return to “X Rebirth - Scripts and Modding”