[SCR] Smart Turrets v4.7.2 (AP, 05-04-14), v2.6 (TC, 21-08-13)

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

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

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

From what I read its intended to make enemy missile boats more deadly, so still handy crash issue aside. But I've noticed in XRM the missile boats tend to be pretty deadly without extra help compared to vanilla where they don't do much.
garrry34
Posts: 911
Joined: Sun, 17. Jul 05, 14:43
x3tc

Post by garrry34 »

well good news I removed the addon and no crash, so next test shall be with enemies mars enabled...
PhenomII X4 940 black edition
8GB DDR2
ATI HD4890
Windows 7 64bit
User avatar
Drewgamer
Posts: 536
Joined: Fri, 27. Aug 10, 08:39
x4

Post by Drewgamer »

Sorry if this has been discussed already (I'm too lazy to go back and read the whole thread xD); How does this compare to MARS? In terms of performance and efficiency. I've been using MARS for a long time now, but I dont use half the features (I'm looking at you, Goblin). I know I'm probably missing out or something but what can ya do, eh? So if I can get an alternative that works just as well (and using less computer resources is a nice plus) then I'd be all over it.

One other question, which pertains slightly to x3 itself; How does the whole "missile turret" thing work? I've never had m7m in my fleets and have never flown them myself. Can't I get the same effect by loading my m2 with missiles; or does the "missile turret" actually do something on the m7m? If so, how does you script affect that?

Thanks in advance for your patience with this lowly newb ^_^
Check out my mod Crystal Rarities
Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang »

Missile turrets basically auto fire missiles at enemy ships, like if you are using MEFOS < script I use the most. And your Ships cargo hold has a bunch of missiles of a certain type they are auto fired periodically, if under the command of a turret command.

Of course there is then also the M key which adds missiles into the loader, the tiny bar below your current laser fittings (lower left corner) With missiles now loaded/chosen, seeing as we're talking M7M you pretty much and continusly press the L key to launch salvo's upon salvos of missiles at enemy ships/stations.

sorry for hijacking your thread Shimrod but I thought I should explain the functions to Hektos about the M7M.

As for the functions of the script I'll leave that up to the creator of it, as I haven't tested this enough to give any insight.
Kadatherion
Posts: 1021
Joined: Fri, 25. Nov 05, 16:05
x4

Post by Kadatherion »

A little issue I keep having with Smart is that it seems to recognize your commands only IS. AKA, I have to be in the same sector as the ship I want to enable Smart on for it to take effect. Once the command is given it sticks, of course, so it's not much of a problem, just a little annoying sometimes as I always have to jump to my HQ sector whenever I have a new ship ready to begin a patrol, if I want to initialize Smart on her turrets.



Also, something very collateral you might be interested looking into, Shimrod: Smart works fine on orbital weapons platforms, as with any ship. However, the OWPs don't work OOS - it's a vanilla bug - so they are of no use at all even in those mods, like XRM, which offer them for sale.
As such I replaced the vanilla !fight.attack.object.owp script with the one made by gazz in his OOS rebalance mod, which works as a standalone too fixing them.

Doing that I noticed that script seems to conflict with Smart: with it instead of the vanilla one, OWPs with Smart running on their turrets keep unequipping their weapons, leaving the turrets empty and the platform a sitting duck.
My mix and match of scripts is an unusual combination, of course, however should the same happen also with normal ships when one's using that mod by Gazz (as it replaces also the common attack.object script used by normal ships) you might want to check if you can make Smart able to adapt to it.
Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

Hektos wrote:How does this compare to MARS? In terms of performance and efficiency.
I've not drawn a performance comparison but in often I regularly pit 20 Smart M6/M7 vs 20 MARS M6/M7 and found neither to be CPU hogs. Smart uses caches to improve performance. In terms efficieny at killing, Smart came out on top vs MARS in all my M7 and M6 20 vs 20 tests on 1.6. In general it can go either way though.

In theory MARS should always pick optimal lasers as it uses hardcoded laser data per mod with direct hints as to which laser is preferable for a given target. Smart uses heuristics so may pick less optimally, particularly where special lasers are concerned (AE, frag, ignore shield, beam etc) as their special properties cannot be detected.
Hektos wrote:How does the whole "missile turret" thing work?
Each missile turret running Smart operates independently, picking its own targets. Since they all share the same targetting priorities they will generally cooperate on a given target if that target requires more than 1 volley.

Smart's configuration controls how active they're going to be in terms of defending friendlies or actively looking for trouble, and how much overkill missile damage will be launched to a given target.

Volleys up to number of guns in the missile turret are fired at a given target. Next time round it may continue to shoot at the same target or pick a new one, say if the target already has sufficient DPS incoming.

@Kadatherion I'll look into that today.
garrry34
Posts: 911
Joined: Sun, 17. Jul 05, 14:43
x3tc

Post by garrry34 »

with the missile turrets not targeting stations, you say you want to change that may I suggest making it user configurable...
PhenomII X4 940 black edition
8GB DDR2
ATI HD4890
Windows 7 64bit
Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

RE: starting Smart OOS

This is a tricky one. The game isn't even running the turret script when starting it OOS, not even the first line of it that sets the command ID. So it shows as None. It'll run MARS ok and builtin turret commands though.

The weird thing is when the ship jumps into the active sector the turret command started earlier that didn't seem to be working then gets started and shows up in the turret commands list. The mainguns additional ship command works fine, its just the turret script.

As far as I can tell my initialization is identical to MARS, yet the game starts MARS up OOS but not Smart. I've tried a separate setup script and applying a check script in 'set ship command upgrade'. Also tried creating a turret command ID with a number lower than the MARS ones, re-ordering statements in the setup script.

Script debugger shows nothing is executed on the OOS ship. The check script is executing globally and returning [CmdConCheck.Available], then nothing happens.

As a last resort I might be able to abuse a preload script to make this start the tasks. Will try that if I reach a complete dead end. Going to try giving my scripts shorter filenames, and other random guesswork first till I'm completely out of ideas.

Using Smart's broadcast command starts the turret scripts OK OOS as a workaround in the meantime.
Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang »

Maybe asking for advice to the Gazz man himself might help in that area?
Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

I just got back from posting a PM to gazz there when I read that :)

I think I've figured it what's going on, mainly looking for confirmation. Its not actually a bug in Smart but a quirk of the game.

The game terminates turret scripts when ships go OOS. The top level script shows on the stack of the turret task but its not running. When starting turret scripts OOS its similarly putting the task on the stack but its not running, so it never gets a chance to set its command ID and still shows as None. Soon as a ship goes IS, that paused script starts fresh.

I don't know why the vanilla turret commands show up, but I think I see how MARS gets around the issue. In the command check script it saves off $Ship into a global, starts a task on the playership which then goes and manually starts the turret tasks on $Ship.

I should be able to follow a similar pattern for fixing, though seems maybe starting a task on $Ship itself to do a delayed reset might fit better for Smart. I suspect MARS' solution might be addressing multiple design goals.

As you say I'm hoping the man himself can help confirm what's going on :)
Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

Right, Gazz came through, here's the deal.

There's a simple 'Script Command' field on scripts that you can assign the command name to, making it show the name up automatically. This fixes the visual problem and I'll have this in 1.7.

There's another issue in that, because the turret scripts don't get a chance to run OOS, the OOS laser code won't kick in and swap the lasers round to best shield dmg per shot. I'll put this on the TODO list, and might get it done in 1.7, but I've got big changes in the works already and it might not fit.
User avatar
Drewgamer
Posts: 536
Joined: Fri, 27. Aug 10, 08:39
x4

Post by Drewgamer »

@requiemfang & shimrod - thanks for all the infos, was very enlightening. Might have to give this script a try, gives me an excuse to try out some m7m's too :P

Another question, how does the whole "cache" thing work? Sounds like the script is storing laser data somehow. Does this persist throughout a save? Does it persist through different saves or does each save keep it's own data? What's the best way to collect data (spawning a bunch of fodder with the cheat script and letting the turrets go to town)? Lastly, does only the playership collect data and if not, is data shared between ships?

Ok so that was more than just "another" question xD Feel free not to answer something if you don't want to "give away your secrets".
Check out my mod Crystal Rarities
Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

how does the whole "cache" thing work?
These are the different caches and how they're populated. Code comments detail cache contents in the relevant files (glen.turret.smart.cache.*)

Global ship cache
An array based on number of ship subtypes. If at load time the number of ships is found to have changed, the cache is invalidated.

When Smart is first activated on a given ship type it gets a global cache entry. This includes count of turrets, guns, whether it's a missile turret etc. If this is found to differ at load time from game data (e.g. modded) the entry is invalidated.

Each ship entry contains turret entries, containing the compatible laser list and derived lists ordered by range, DPS, speed etc and factoring in disallowed lasers. At load time the compatible laser list of each turret is checked and if the data has been modded, this invalidates the ship cache entry.

Two kinds of laser data is cached here:
1. Fixed laser data derived from game statistics and factoring in disallowed lasers. Invalidated if the disallowed and collateral damage laser lists are edited, or if the game laser data has been modified (checked at load time in DPS cache).
2. 'Cache-sensitive' laser data dependent on the fixed laser list and also the delays/DPS values from the DPS cache. Invalidated whenever a new sample is added to the DPS cache or if fixed laser data changes.

Local ship cache
A local ship cache is created on the ship the first time Smart is enabled on it.

Is is used for 2 purposes:
1. By the central ship task for sharing targetting data to turrets
2. Cached lasers

One example of shared data is the central task does a simple scan for targets in 'alert range' and flags this via the ship cache to individual turrets, which then sit idle if they're laser turrets and nothing is in range (missile turrets ignore this).

The lasers cached in here are referred as transient. The lists are based on the actual lasers available in cargobay, and there are separate lists for collateral damage and non collateral lasers.

The transient laser cache is invalidated if the cache-sensitive data changes and if the total cost of lasers in cargobay changes (i.e lasers sold/ejected). A recache is performed by a given ship if 15 seconds have elapsed since last check, and if enemies are in alert range.

DPS cache
Entries are maintained for each type of laser to track laser delays and derived DPS values.

This also stores normal laser stats (e.g. hull dmg per shot) and on game load these are compared to see if the game data has been modified. If so then this invalidates the whole cache as well as triggering invalidation of all ships laser data.

When a turret fires a laser if there are less than 10 samples in the cache it will measure the laser delay in a special firing loop and push in a new cache sample. A new cached sample invalidates the cache-sensitive and transient laser data.

This cache can be viewed, edited and cleared via Smart's menu system.

Sector Cache
This is new in 1.6, and currently contains only the list of missiles incoming to player/protected ships in the active sector. An elected master Smart ship of the player race performs the scan. The data isn't invalidated, simply overwritten each time the master checks.

This data is read by Smart's central ship task in alert range checks and in target evaluation.
Does this persist throughout a save? Does it persist through different saves or does each save keep it's own data
Yes, data persists between save games until it meets cache invalidation conditions. Local ship data persists between smart being disabled and re-enabled.

Data referred to as local is stored as a local variable on that ship. Global data is stored as part of Smart's global settings which is a single global array.

Cached local ship data and tasks can be cleaned by broadcasting Terminate from the Smart menu. The Uninstall function will remove all local and global data and stop Smart tasks.

The primary data structures are versioned and upgrade from any previous version of smart is supported. Downgrade is not supported.
What's the best way to collect data (spawning a bunch of fodder with the cheat script and letting the turrets go to town)?
Letting it train up naturally works fine. It just needs 1 sample of each laser to get a sensible DPS then it'll try others. But note that ships will only recache their cache sensitive laser data every 15 seconds (and only when enemies in alert range, to save cpu), so it'll not immediately swap to trying a new laser.

In 1.7 another good way to train the cache will be to enable Smart on NPC ships =)

Delay measurements are only collected in sector as out of sector combat is resolved algorithmically by the game.

There is one scenario which is problematic, where you want to use Smart on the main guns but the lasers don't have cached delay values yet. Delay samples aren't collected on the main guns as these are shot manually, so this can pick odd lasers unless the cache has samples for all the lasers the mainguns support.

As a fallback option you can set delay values into the DPS cache manually via the menu. These are millisecond refire delays between shots.
Lastly, does only the playership collect data and if not, is data shared between ships?
Every ship contributes DPS cache samples until there are at least 10 of a given laser.

Global ship cache data is recached by the first ship of that type that goes in there and does a check. The cooperative multitasking of scripts mitigates race conditions.
Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

I've uploaded 1.7.

The primary feature is Smart can be enabled on NPC ships of friendly, enemy or any disposition towards the player. This can be configured via the Smart menu or trivially toggled on or off via the AL plugin menu.

When enabled the AL plugin will periodically scan and enable Smart on NPCs in the active sector if they have any turrets and meet the configuration requirements. Smart will terminate when the ships leave the active sector or if the settings are changed to exclude that ship type.

Enemy M7M can be particularly difficult to survive so I've added an option to exclude missile boats if desired. One tactic that works is overwhelming them with large numbers of M3's, most ideally ones with some turrets so they can defend themselves and their friends against the flails. Big ships die hard and fast to torpedoes though.

Also some performance optimizations and fixed a bunch of bugs. Didn't get to checking the OWP running Gazz's replacement attack script empty laser bay issue though. The script says its for vanilla and I'm running XRM right now.

Full changelist in the 2nd post of the topic.
User avatar
Drewgamer
Posts: 536
Joined: Fri, 27. Aug 10, 08:39
x4

Post by Drewgamer »

Thanks for answering all my questions. I'll have the script a go this weekend when I get some playtime in.
Check out my mod Crystal Rarities
Kadatherion
Posts: 1021
Joined: Fri, 25. Nov 05, 16:05
x4

Post by Kadatherion »

Shimrod wrote:Didn't get to checking the OWP running Gazz's replacement attack script empty laser bay issue though. The script says its for vanilla and I'm running XRM right now.
The core mod/script is only compatible with vanilla, yes, since it's based on the vanilla weapons to create far less powerful duplicates when the ships are OOS, but the attack script replacements (OWPs and common ships) can be used by themselves with most mods (apart from those that rewrite those scripts too. X-tended is probably the only one doing that atm).
However there's definitely no rush: as the OOS rebalance mod is still in development and testing and still without any compatibility versions for popular mods, it isn't very widely used. With Rebirth getting closer, it could even never really take off.

I mostly mentioned the issue I noticed should anyone stumble on it without realizing that mod was the cause.

And kudos for the new version, I'll have very little time to play in the next few days, but I'm eager to see the AI ships running Smart :thumb_up:
Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

With Smart 1.7 and XRM I've:

1. Replaced !fight.attack.object.owp.pck with that from gz_oos_rebalance_v2
2. Spawned a loaded medium argon OWP, enabled Smart on turrets and set the OWP to attack all enemies
3. Jumped OOS then spawned 10 xenon M3 at the OWP location.

Observations:
a. Periodically the xenon M3 are being killed
b. At all times the OWP turrets are fully loaded with ion cannon
c. Script debugging shows the modified !fight.attack.object.owp code (if $dist < 7000 ...) is executing. Also the Smart coordinator task is occasionally running and refreshing the turret OOS lasers.

It looks aok to me. Could be that the 1.7 changes inadvertently fixed the issue, unless I'm missing a repro step.

And thanks for trying 1.7 :) I'd be interested in hearing both positive and negative experiences. I've completed the requested feature wishlist, at least the ones I'm sold on, and my focus now will be with fixes, performance and usability. On a more sedate release schedule, unless bugs come to light - I'm toying with new project ideas.
Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

I've uploaded 1.8.

The main feature is a training option added to the Smart menu. This can be applied to a ship, a wing or broadcast to make Smart enabled turrets and main guns train up on laser delays. Be careful as shots will be fired when training. Also avoid using SETA during training as the delay samples will be way off.

I added a check for heavy beam lasers and made them less preferred for shooting fighters with. They can still get picked, generally if the target is far off and there's no fast bullet speed alternative.

I've been playtesting Smart on XRM over a few ship classes and races (currently I'm a Xenon =), and I've found and fixed several bugs in this release.

Full release notes in 2nd post.
garrry34
Posts: 911
Joined: Sun, 17. Jul 05, 14:43
x3tc

Post by garrry34 »

sorry I've been distracted by other matter lately, Shimrod did you remove the turret slot filler in 1.7?
PhenomII X4 940 black edition
8GB DDR2
ATI HD4890
Windows 7 64bit
Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod »

Yes that option was removed. Turrets are now filled with no enemies in range and when shooting at stuff. Its usefulness was really reduced to improving visuals for heavy antimissile sessions with multiple drone targets, and I felt it wasn't worth the effort in ongoing regression testing and cluttering the menu with.

I had enabled it in 1.7 to test it and couldn't honestly tell if it was making any difference. At that point I considered it not worthwhile to worry about debugging.

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