Planing a conflict avoidace script - questions

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
Nicoman35
Posts: 681
Joined: Thu, 17. Nov 05, 13:12
x3tc

Planing a conflict avoidace script - questions

Post by Nicoman35 » Fri, 2. Dec 11, 10:40

Hi guys,

I am planing to make a conflict avoidance script. This is what I want:

Ship Ex1 has a ceartain target and flies to this target. A zone with a radius of - say 25km around Ex1 is monitored for enemies.
If an enemy ship enters this zone, Ex1 is starting an evasive maneuver. Now here my problem begins. I need to have vectors from all relevant factors, and I need to know the ancles between them.
IMHO this is important for an intelligent behaviour, especially in foe sectors, where multiple contacts are to be avoided.
I looked through the MSCI command reference, but could not find especially the needed math operations.

My questions:
1. Is there a way for me to achieve what I have in mind, or does this exeed the possiblities of the game engine?

2. Is there an easier way of writing such an avoidance script?

Bye

User avatar
Nividium
Posts: 800
Joined: Tue, 21. Aug 07, 01:31

Post by Nividium » Fri, 2. Dec 11, 14:37

I wrote a script for conflict avoidance as part of another script package in X3 Reunion. I used the simple approach, no math required. I used the ship's radar scanner range to check for enemies, so the greater the scanner the greater the afforded protection. Then the script would simply scan this range every second to see if other ships were "targeting" the ship, if yes, then jump or dock at local station if jumpdrive was not equiped. Given that an enemy ship would target it's victom first and give numerous seconds before actually shooting, it provided enough time for the targeted ship to count down it's jumpdrive for a jump, which would just be 1 or 2 sectors away. Worked perfectly. Never lost a ship when using this script.

jlehtone
Posts: 21801
Joined: Sat, 23. Apr 05, 21:42
x4

Post by jlehtone » Fri, 2. Dec 11, 16:40

[url=http://forum.egosoft.com/viewtopic.php?t=216690]TC Download Library[/url] section "Utility and Library Scripts" might help.

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

Post by Litcube » Fri, 2. Dec 11, 17:09

This won't be easy, and you will need to use trig. Trig in MSCI isn't fun.

Nicoman35
Posts: 681
Joined: Thu, 17. Nov 05, 13:12
x3tc

Post by Nicoman35 » Fri, 2. Dec 11, 18:55

@ Litcube & jlehtone
Uh oh, just made a little plan....it´s going to be almost impossible. I wanted the ship to behave like if it would be stirred by a real human being. But unless no fussy logic or something similar is implemented, I don't think I'll manage to script this.

@Nividium
Ok, your approach does not sound bad, do you have a link to your skript?

User avatar
Nividium
Posts: 800
Joined: Tue, 21. Aug 07, 01:31

Post by Nividium » Fri, 2. Dec 11, 19:41

[quote="Nicoman35 @Nividium
Ok, your approach does not sound bad, do you have a link to your skript?[/quote]

The original script was written for Reunion, then changed ie I took out the dock at station part because for the package, the only ships that would be using it would have jumpdrives. You can add the dock at station back in if you want. So, this script will check for enemies and if they target the ship, it will jump out 2 sectors away. You would need to create a button menu option to activate the script and have it run on a particular ship:

Code: Select all

Description
Task Script. Monitors enemies in scanner range and Jumps 
Arguments
1: ship , Var/Ship owned by Player , 'select ship' 
Source Text

001   * This is a task script runs on Task.ID 300 and Prio 300
002   $withfollowers = [TRUE]
003   $flags = [Find.Nearest] | [Find.Enemy]
004   $range = $ship -> get scanner range
005   
006   while $ship -> exists
007    
008    $current.sector = $ship -> get sector
009    $enemy = null
010    $enemy.is.targeting = null
011    $enemy =  find ship: sector=$current.sector class or type=Fighter race=null flags=$flags refobj=$ship maxdist=$range maxnum=1 refpos=null
012    $enemy.is.targeting = $enemy -> get attack target
013    if $enemy.is.targeting == $ship
014     
015     
016     if is script with prio 100 on stack
017      goto label LABEL.Jump.Out
018     else if is script with prio 99 on stack
019      goto label LABEL.Jump.Out
020     else if is script with prio 50 on stack
021      goto label LABEL.Jump.Out
022     end
023     
024   LABEL.Jump.Out:
025     $energy.available = $ship -> get amount of ware Energy Cells in cargo bay
026     $jumpdrive = $ship -> get true amount of ware Jumpdrive in cargo bay
027     if $jumpdrive >= 1 AND $energy.available >= 15
028   LABEL.Find.Random.Sector:
029      $random.sector =  find a random sector: startsector=$current.sector, jumps=2, owner=null
030      skip if not $random.sector == $current.sector
031       goto label LABEL.Find.Random.Sector
032      $ship -> set command: COMMAND_JUMP_SECTOR
033      $ship -> set command target: $random.sector
034      $ship -> set destination to $random.sector
035      $ship -> start task 400 with script '!ship.cmd.jump.std' and prio 2: arg1=$random.sector arg2=$withfollowers arg3=null arg4=null arg5=null
036     end
037     $ship -> set command: COMMAND_IDLE
038     $ship -> set command target: null
039     $ship -> set destination to null
040 @   = $ship -> move around 120000 ms
041    end
042 @  = wait 2000 ms
043   end
044   return null

Nicoman35
Posts: 681
Joined: Thu, 17. Nov 05, 13:12
x3tc

Post by Nicoman35 » Fri, 2. Dec 11, 19:46

Thank you very much, Nividium. :) . I'll try to implement it in my project.

User avatar
Automatic Jack
Posts: 167
Joined: Fri, 15. Jul 11, 10:27
x3tc

Post by Automatic Jack » Fri, 2. Dec 11, 20:14

How does something like that affect performance Nividium? I assume it's running all the time on every freighter?

User avatar
Nividium
Posts: 800
Joined: Tue, 21. Aug 07, 01:31

Post by Nividium » Fri, 2. Dec 11, 20:29

Performance. Well, it runs in the background and only uses 8 lines of code before it executes a 2 second wait. Also it is only run on your own ships if you select it to. Most of the time you are not being targeted so only a few lines of code are run. You could even make this script smaller by taking out the if script running is task 50, 99 etc and just have it purely jump if you are targeted. I added the if task 50 script checks so the ship would at least get attacked before it jumped. But if this is too much ie the ships shields cannot take a 10 second attack run, then I would remove those lines of code and jump solely on being targeted rather than being attacked. The script is meant as a starting point for OP to play with and he can customize and experiment as he sees fit.

Post Reply

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