[Script] Litcube's Bounce V1.7: Player Owned Autopilot Fix

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
User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

[Script] Litcube's Bounce V1.7: Player Owned Autopilot Fix

Post by Litcube » Wed, 19. Jan 11, 08:17

FOR THE MOTHER OF GOD, YOU DO NOT NEED THE CAT/DAT IF YOU ARE NOT MAKING A WALL FILE. PLEASE FOR THE LOVE OF CHRIST, READ THIS. PLEASE UNDERSTAND THAT YOU ONLY NEED THE SCRIPT TO RUN BOUNCE. FOR ALL THAT IS HOLY; PLEASE.


Litcube's Bounce V1.7
Release Version

Player Owned Autopilot Controlled Ship Collision Avoidance
This post has changed since the alpha release.
Included support for AP

Youtube vid (not a single Jaguar was harmed in the making of this film):
http://www.youtube.com/watch?v=0s9afUiS4LY


Download Bounce:
Image

Thank You

- Sincere thanks to alpha testers Requiemfang, Katorone, Ikaruga, Firewrath.
- Timelines crew, for technical support, and especially sms_747 for her emotional support and having the Node idea from the get go (as I continuously ran into brick wall after brick wall with other methods). Sms_747: :star:


Installation & Tech Details

If you're running vanilla:

- Dump script files into your script directory.
- Dump t/Vanilla/8389-L044.xml into your t directory (just that one file, no sub-directories). Use the AP or the TC one.
- Run the game.
- Setup your hotkeys (Controls -> Interface -> Bounce: on and Bounce: Off).

If you're running a mod that changes TShips models or add ships:

- 8389-L044.xml is what's called a Wall file and is required to run Bounce. As long as you have the proper Wall file, Bounce will be compatible with that mod. The Wall file is specific to the TShips file, and the Wall file included in the t/vanilla folder is for vanilla only. Within the t directory of this package, you'll find sub directories on popular mods. If you find the mod you're using there, use that Wall file instead. It matches the name of the vanilla Wall file. If you do not find your mod's Wall file, or you have your own customized ship altering mod, you can generate your own Wall file automatically using the built in Z.Bounce.Wall script. See the bottom of this post for instructions on how to do that (it's easy).
- Run the game.
- Setup your hotkey (Controls -> Interface -> Bounce: Toggle).

Other notes:
- If you're not generating your own Wall file as mentioned in the previous step, ignore BounceWallXX.cat and BounceWallXX.dat. You do not need these 2 files to run Bounce. They are only used to generate the Wall file (8389-L044.xml)
- I don't mind installation questions on this one, provided you give me the password: Chicken Poop.
- Instructions on generating your own Wall file are below under Generating Your Own Wall File.
- Wall files included: X-Tended, SRM, X-Tra Ship/Station pack. I believe Timelines uses SRM. Versions listed in the sub-folders of t contained within the downloadable package.


What Is It?

As everyone knows, the AI autopilot is absolutely horrible. Spend 30 mins outfitting your shiny new Asps and send them off to take out that Titan. Result: Most of them will collide with the side of the ship. With an almost certainty, they will all die by collision. Seriously, it looks like kamikaze. It's so bad, it almost looks as though Egosoft intended this. This plugin is an attempt to remedy this via scripts. It's a simple, but so far effective package. Once Bounce is engaged via hotkey, as a ship nears its target (ship or station), a collision avoidance routine is engaged to avoid the enemy ship or station. Also, when an enemy ship is not detected within 10 KM, AND there are no missiles currently locked onto a ship, your ships will ignore collisions. So you can have your formation without experiencing collisions with your other ships, neutral ships, asteroids, gates, or stations. Once an enemy is detected in 10 km, this feature is skipped, and Bounce avoidance checks are engaged. The player ship is not effected. Only player owned ships of all sizes.

I didn't detect any performance difference in large scale battles (300+ ships). Turning Bounce on, or off, didn't change frame rates or performance on a 6 capital versus 300 fighter battle. There was no 0 m/s glitches.

I have decided that I'm not a fan of collision spheres, or collision bounding boxes, or "safety nets" in a scene file. Some of you know what I'm talking about, but for those that don't, it's basically a model that is larger than the ship. This model is transparent so the player can't see it. But because it's there, and it's large, the idea is that ships will avoid sooner, thus avoiding the embarrassing collisions. Some mods in this forum include them (SRM, XTC). The problem with this, is that missiles, in particular, will miss a ship with such an object. The degree of waste is based on how far the collision object extends outside the ship, but if you want to test this, load up XTC and launch a poop load of mosquito missiles at a titan. See them circle the ship in confusion. No thanks. Just my opinion, though, folks.

Also included in this package is the test script "a.....SimpleTest" script. Run it to see what Bounce can do. There are no parameters, but you can change them by opening the script up and changing the one and only line. It's a one line script, and self explanatory. Don't save your game after running the "a....SimpleTest" script.


Results and tests I ran
Here's some test results from only some of the countless tests I ran. Enemy ships with no weapons.

6 Phoenix Vs. 300 Jaguar
Bounce off: 300 losses
Bounce on: 1 loss (one to a North Gate, and one to a Jaguar)

2 Titan Vs. 30 Hydra
Bounce off: 4 losses
Bounce on: 0 losses

1 Megalodon Vs. 200 Buster
Bounce off: 123 losses
Bounce on: 0 losses

30 Panther Vs. 30 Shrike
Bounce off: 1 loss
Bounce on: 0 losses

30 Titan Vs. 30 Titan
Bounce off: 0 loss (Oddly)
Bounce on: 0 losses

30 Shark Vs. 160 Mamba
Bounce off: 92 losses
Bounce on: 0 losses

30 Shark Vs. 160 Elite
Bounce off: 34 losses
Bounce on: 0 losses


I ran extensive frame rate testing. I could not detect a difference in frame rate between when Bounce was enabled and when Bounce was not enabled.


How to use Bounce

During alpha, Bounce was an AL plugin. This is no longer the case, as I felt that hotkeys offered a) more control and b) better performance. Bounce now installs one toggle hotkey. Once enabled, you will see the message "Bounce has been enabled". Toggling it back off tells you "Bounce has been disabled". While enabled, all player owned ships will automatically know when bounce should be enabled, and functionality is automatic.

If Bounce is not engaged, there are NO scripts related to this package running on the Universe at anytime. Also note that the Bounce script automatically stops running on ships once they are not in the active sector. The active sector is the one that you, the playership, are currently in. If the ships aren't being rendered, Bounce does not run on them.

Please post your results, comments, etc.



Generating Your Own Wall File

If you don't find your mod in the list of text file folders, or you have changed, added, or removed ships from the ones included, you will have to generate your own Wall file. The wall file is an xml file used to tell Bounce the dimensions of ships. Instructions are as follows:

- Install the BounceWall.cat and BounceWall.dat as a false patch. Do not use as a mod in the mod's folder.
- If you are currently using a mod that is in the mod folder, ensure that it does not contain a TFactories file. If it does, temporarily remove it. You can put it back once the Wall file is generated. As an alternative to removing the Tfactories file, you can make the mod a false patch, as long as it comes before (a number less than) the BounceWall.cat (which will of course be renamed as a number because you've changed it to a false patch, right?).
- Run the game
- While not necessary, finding a sector that isn't very busy makes the Wall file generate faster.
- While not necessary, turning off your HUD will make the Wall file generate faster.
- Run the Z.Bounce.Wall script by selecting it in the scripts list and hitting "r", and then "Enter".
- Everything in the sector is destroyed, except you.
- You should see periodic messages telling you what ship is currently being dimensioned.
- Don't do anything during this time.
- Depending on your frame rate, this whole process might take up to 3 minutes. My frame rate was 300 - 500, and it took 2 minutes 37 seconds to generate the vanilla ships Wall file. Could take longer, could be shorter. You only have to do this once, folks.
- Once finished, you'll see the message "Finished the Wall!"
- In your output folder, which is in your documents/Egosoft/X3TC (same folder your screenshots come out of), you'll see a log08389.txt.
- Rename it to 8389-L044.xml and copy it into your t folder of your X3 Terran Conflict installation directory.
- You now don't need the false patch; you can delete it.
- You're done!
- If you'd like me to include Wall files in this package, e-mail me at jkossowan at gmail dot com.


Notes on How it Works, If You're Interested!

- Two main scripts are involved in Bounce, and this is how they work:
- All player ships in sector start a looped check script on task 323.
- If a Bounce enabled player owned ship comes within $danger.range (derived from a formula based on the 8389-L044.xml Wall file) meters of an enemy, friendly, or neutral Huge Ship (TL, M7, M1, M2), the Huge Ship will start the looped Node script on task 324.
- The Node script generates 5 nodes along the spine of the ship with radius and length of the spine derived from the 8389-L044.xml Wall file.
- The Node data is obviously only good as long as it's updated to the ship's changing position. This is done frequently, based on how fast the ship moves. If it's not a fast ship, we don't need to update very often.
- If there's no ships within $danger.range meters, the looped node script goes into idle mode, and stops generating nodes to save performance.
- This data is snatched from the player owned ship's Bounce check script.
- Based on the node data that the player owned ship gets, it decides if a collision is imminent. This is derived from speed of the ship, and the distance to all nodes.
- If there's no enemies within 10 km, the player check script goes into safe-mode, turning off collisions completely (no more formation losses), and slows down the checks considerably to save performance.
- If it is determined that during idle mode, collision should be turned off, to avoid destruction if the player ship happens to be within or intersecting an object, the ship is moved outside the bounding sphere of the object before turning collision checks back on.
- If it is determined that a player owned ship *is* in need of action because it's about to collide with a huge ship, it runs Evade, but only if not in idle mode.
- Evade turns off collision detection for a maximum of 1 second while the ship launches in the opposite direction. During this time, no bullets can hit the ship. To compensate in regards to balance, fairness, and all that crap, the ship is unable to fire back (through ANY turret).
- Evade continues until the player owned ship is safely away from the ship, and then continues on normally, susceptible to enemy fire.
- If any ship (player or enemy, Bounce Check script or Node script) is suddenly not in an active sector, scripts are exited.



Versions


1.7:
- Less evading, more firing. Evasion now checks against original collision nodes, as opposed to a sphere. Result is tighter collision checking, less evasion triggers.
- Fixed a bug where ships would sometimes remain invincible even after detecting enemies near by.

1.645:
- Added wall file for XRM 1.19f (thanks Skite!)

1.644:
- Added wall file for Apricot Mapping Service 1.05

1.643:
- Added support for the Albion Prelude platform
- Included the wall file for XRM 1.14c (thanks JoelR)
- Included the wall file for Vanilla Albion prelude 1.0

1.642:
- Included the wall file for XRM 1.02 (thanks Mizuchi).

1.641:
- Forgot to remove the debug write to logbook before I packed it.

1.64:
- Bounce waits until a ship has finished launching from carrier/station before starting to avoid collisions by players ship and weird behaviour.
- Nodes no longer run on player ships, as collisions between AI ships of the same race don't occur. Save a little on performance.

1.63:
- While I had rendered Bounce turned off when you switch to a player ship in v1.5, it turns out that in some situations, the ignore collisions was still turned on, even if Bounce wasn't. One line fix.

1.62:
- Thanks to builder680, SRM 1.06 wall file now included.

1.61:
- Thanks to builder680, SRM 1.04 wall file now included.

1.6:
- Fixed node positioning to centre on model's tangible borders, as opposed to the pivot. This will have little noticeable difference on most ships, but will eliminate a problem with those ships that do not have the pivot centred near the model centre (Panther, Osaka, etc.).
- Fixed wall generation script to detect if a ship is too small to be a huge ship. For example, there's a ship out there in a mod that has no business at being an M7 at roughly 300 m long. I had to implement a check for these silly things. The script will now function even if you implement a ship 2 meters long.
- Slightly optimized node script.
- Re-generated all wall files. New versions are now included in the respective package folders. New wall file format required for new node generation routine. If you were using a custom wall file, you will have to regenerate your wall file from scratch.
- The Tfile for the wall writer (8389-L044) is now just included in the .cat, as that's the only time you'll really use it. Directions have been updated to reflect this change.

1.5:
- Thanks to Bléral for pointing out that switching ships bypasses the playership check, rendering you invincible (until you toggle). This has been fixed.
- Added an action check. AI ships affected by Bounce that are intending to pass through warp gates should now do so normally.

1.4:
- Many thanks to Black147 for pointing out that Bounce was actually running on playerships (causing odd issues) when it was not supposed to. This has been fixed.

1.3:
- Bounce now only requires a toggle, and is on perpetually afterword, until turned off. Regardless of new ships in sector, or if playership changes sector. You will have to setup your toggle hotkey again. Essentially, it's turn on and forget, but you can turn it off at any time.
- setup.Bounce.UnregisterOldKeys script included to unregister the 1.2 and prior hotkeys. Once you save your game after the keys have been removed, you can delete this script.
- Optimized collision detection significantly
- There was a bad speed check that was causing partial error collision losses (3 - 5 in a fleet of about 300), but this has been eliminated.
- Optimized node code to improve performance
- Included check for idle mode intersections, avoids ships popping due to being within an object when collision detection is suddenly resumed.
- Wall file generation has been optimized. My test ran at 2:37 minutes.

1.2:
- Optimized station versus ship code.
- There was an error calculating the wait times in relation to ship speed. Collisions could have happened more frequently as a result.

1.1:
- Test script destroy everything in sector, commented out
- Fixed an oops bug in check script.

1.0: Release Version

0.12a:
- CSG only: Enemy weapon spawn option wasn't working right.

0.11a:
- Packing issue.

0.09a:
- First release. Test phase.
Last edited by Litcube on Thu, 24. May 12, 05:23, edited 55 times in total.

Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang » Wed, 19. Jan 11, 08:33

Hmmm might give this a look and post results if I get time, sounds like something similar to what TrixX was working on a short while ago with the autopilot with mass amount of fighters

User avatar
Ikaruga
Posts: 376
Joined: Fri, 30. Jan 04, 14:26
x4

Post by Ikaruga » Wed, 19. Jan 11, 08:33

I'm not home so I can't test it, but if it really works, it's truly awesome ! 8)
If brute force doesn't solve your problems, then you aren't using enough

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Wed, 19. Jan 11, 08:34

Requiemfang wrote:Hmmm might give this a look and post results if I get time, sounds like something similar to what TrixX was working on a short while ago with the autopilot with mass amount of fighters
I believe TrixX was using collision spheres. There's a thread he made a while ago with a modder's resource. Unless you're referring to something I haven't noticed yet.

User avatar
Ikaruga
Posts: 376
Joined: Fri, 30. Jan 04, 14:26
x4

Post by Ikaruga » Wed, 19. Jan 11, 08:36

By the way, it works with any class of ships and not only fighters, doesn't it ?

Because I lost a crapton of M6s by packing them against an enemy. They either crashed against the enemy or themselves.

Finally, does this prevent collisions between player ships ?
If brute force doesn't solve your problems, then you aren't using enough

Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang » Wed, 19. Jan 11, 08:36

Yeah that's the one I was talking about, the resource. I remember him giving me a test copy of it to try it out, I never got around to testing it though :oops:

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Wed, 19. Jan 11, 08:38

Requiemfang wrote:Yeah that's the one I was talking about, the resource. I remember him giving me a test copy of it to try it out, I never got around to testing it though :oops:
Yeah, these were collision spheres, which aren't script related. They're model related. This is totally different.

Well, Requiemfang, here's your chance to contribute!

Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang » Wed, 19. Jan 11, 08:48

hmmm I'll give it a go

101010
Posts: 37
Joined: Mon, 7. Jan 08, 23:57
x3tc

Post by 101010 » Wed, 19. Jan 11, 10:22

How would this effect the collision boxes that mods like XTC use? Would there be any sort of conflict or dose Bounce override the various methods of collision avoidance? Can it be used with mods and custom models or is it restricted to vanilla at this time?

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Wed, 19. Jan 11, 10:24

There won't be any problem with the collision boxes. If the ships don't get close enough to trigger the Evade script, it'll be like Bounce isn't even running. However, if the collision boxes fail from preventing a collision, Bounce will kick in.

One other side effect of collision boxes, is that attack runs are shorter.

Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang » Thu, 20. Jan 11, 00:49

Hey litcube, I just ran a test and hit a snag, when I try to run the script with bounce on, the M5's I choose spawn but the enemy M2 doesn't. When I ran the script without bounce on it spawned normally.

As you said the shit hit the fan and 90% of them died.

EDIT:

I chose the destroy all option after that test and it killed all the ships that spawned green, after that the enemy M2 spawned. Think there's a bug there with the spawn as both my ships and the enemy ship is suppose to spawn at the same time. (THIS IS WITH BOUNCE OPTION ON)
Last edited by Requiemfang on Thu, 20. Jan 11, 00:56, edited 1 time in total.

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Thu, 20. Jan 11, 00:52

With bounce on, it doesn't happen right away. Watch the M5 names. They should be changing to "(name) - Bounce".

Once they're all changed, the enemies will spawn. Hit SETA for a time. Roughly 30 seconds or so.

Let me know if this isn't working, and I'll investigate. If this works for you, I'll also update the documentation, as I suppose I wasn't clear enough.

Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang » Thu, 20. Jan 11, 00:58

Ah... yeah... you should post that in big bold red letters :P I'll try that again

Edit: ran it again same set up, put seta on for 30 and more and no change, names didn't change no spawn.

Think you got a monkey wrench stuck in the gears :lol:
Last edited by Requiemfang on Thu, 20. Jan 11, 01:04, edited 1 time in total.

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Thu, 20. Jan 11, 01:03

Documentation updated!

Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang » Thu, 20. Jan 11, 01:07

Check my last post, I edited it just as you posted that.

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Thu, 20. Jan 11, 01:09

Did you turn the plugin on in the AL plugins?

Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang » Thu, 20. Jan 11, 01:11

Course I did, also put a warning up in the OP that if you have gazz's MARS script on to turn the AL off because the enemy or enemy ships will spawn with fighter drones.

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Thu, 20. Jan 11, 01:13

There's a wrench. Let me unwrench it. Be back in 5 mins.

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Thu, 20. Jan 11, 01:22

Fixed. It was a packing issue. I'd fixed this glitch before I even made the first post, but forgot to throw the file in the rar.

Ikaruga wrote:By the way, it works with any class of ships and not only fighters, doesn't it ?

Because I lost a crapton of M6s by packing them against an enemy. They either crashed against the enemy or themselves.

Finally, does this prevent collisions between player ships ?
Effects all classes of ships between enemies and player ships. For now.
Last edited by Litcube on Thu, 20. Jan 11, 01:25, edited 1 time in total.

Requiemfang
Posts: 3206
Joined: Thu, 16. Jul 09, 12:24
x4

Post by Requiemfang » Thu, 20. Jan 11, 01:24

:lol: rushy rushy "oops I forgot the file!" :D

glad I spotted that... good to know I still got the touch to find bugs and glitches :twisted:

Post Reply

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