[IDEA] Do the experimental weapons actually exist? (Find em!)

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
Aro
Posts: 2766
Joined: Tue, 15. Jul 03, 00:35
x4

[IDEA] Do the experimental weapons actually exist? (Find em!)

Post by Aro » Wed, 28. Jan 09, 08:05

Would something like this be possible? No clue on what the code would actually be, something similar (and longer) perhaps. Maybe it could be changed to find any ware one is looking for? Unless something like this already exists, if so what are the results?

Code: Select all

for each sector
  get list of ships
  for each ship in list
    check contained weapons (cargo+equipped?)
    if experimental weapon found
      write to log; Sector [coord]: shipname(id) - (experimental weapon found)
    end if experimental weapon found
  end for each ship in list
end for each sector
[ external image ]
The end of a trilogy does not mean an end to a series.
| Vanilla with strawberries? [List of Vanilla safe mods.] | Tired of the plots? [Plot Skipper Tool v0.5] |
| X3: R & TC Minimaps |

fud
Posts: 9837
Joined: Wed, 25. Jan 06, 14:26
x3

Post by fud » Wed, 28. Jan 09, 15:02

Looks like a great way to tax your cpu. ;)

User avatar
MegaJohnny
Posts: 2195
Joined: Wed, 4. Jun 08, 22:30
x4

Post by MegaJohnny » Wed, 28. Jan 09, 16:12

http://eng.x3tc.ru/x3_tc_weapons/laser-list.php

Tribeam Cannon's there but the only ship that mounts it is the Truelight Seeker

WindsOfBoreas
Posts: 283
Joined: Sun, 3. Aug 08, 20:30

Post by WindsOfBoreas » Wed, 28. Jan 09, 16:19

Your script would look more like:

Code: Select all

1: w.Ware, Var/Ware, 'Ware'
_________________________________________

$n.PageID = 3800
load text: id=$n.PageID

$n.MaxSectors.X = get max sectors in x direction
$n.MaxSectors.Y = get max sectors in y direction

$a.Ships =  array alloc: size=0
$n.Counter.01 = 0
while $n.Counter.01 < $n.MaxSectors.X
|$n.Counter.02 = 0
|while $n.Counter.02 < $n.MaxSectors.Y
||$sec.Sector = get sector from universe index: x=$n.Counter.01, y=$n.Counter.02
||$a.Objects =  find ship: sector=$sec.Sector class or type=Ship race=null flags=[Find.Multiple] refobj=null maxdist=null maxnum=200 refopos=null
||$n.Array.Size.01 =  size of array $a.Ships
||$n.Array.Size.02 =  size of array $a.Objects
||copy array $a.Objecs index 0 ... $n.Array.Size.02 into array $a.Ships at index $n.Array.Size
||inc $n.Counter.02 =
|end
|inc $n.Counter.01 =
end

$n.Array.Size.01 =  size of array $a.Ships
$n.Counter.01 = 0
while $n.Counter.01 < $n.Array.Size.01
|$sh.Ship = $a.Ships[$n.Counter.01]
|$sec.Sector = $sh.Ship -> get sector
|if not $sh.Ship -> get amount of ware $w.Ware in cargo bay
||remove element from array $a.Ships at index $n.Counter.01
||$n.Array.Size.01 =  size of array $a.Ships
||continue
|else
||$s.Text.02 = sprintf: pageid=$n.PageID textid=2, $sh.Ship, $sec.Sector, null, null, null
||skip if $s.Text.03 != null
|||$s.Text.03 = $s.Text.02
||skip if $s.Text.03 == null
|||$s.Text.03 = $s.Text.03 + $s.Text.02
|end
|inc $n.Counter.01
end

$s.Text.01 = springf: pageid=$n.PageID textid=1, $w.Ware, $s.Text.03, null, null, null

send incoming message $s.Text.01 to player: display it=[TRUE]
write to player logbook $s.Text.01
Your text file would be:

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<language id="44">
<page id="3800">
 <t id="1">[author]Ship Computer[/author][text]List of ships containing the ware [cyan]%s[/cyan]\n\n%s[/text]</t>
 <t id="2">Ship: [green]%s[/green] :: Sector: [yellow]%s[/yellow]\n</t>
</page>
</language>
Last edited by WindsOfBoreas on Wed, 28. Jan 09, 21:09, edited 1 time in total.
"Humanity has the stars in its future, and that future is too important to be lost under the burden of juvenile folly and ignorant superstition." - Isaac Asimov

User avatar
Carlo the Curious
Posts: 16999
Joined: Mon, 5. Mar 07, 22:03
x4

Post by Carlo the Curious » Wed, 28. Jan 09, 17:50

Code: Select all

while $n.Counter.01 < $n.MaxSectors.X 
|$n.Counter.02 = 0 
|while $n.Counter.02 < $n.MaxSectors.Y 
||$sec.Sector = get sector from universe index: x=$n.Counter.01, y=$n.Counter.02 
||$a.Objects =  find ship: sector=$sec.Sector class or type=Ship race=null flags=[Find.Multiple] refobj=null maxdist=null maxnum=200 refopos=null 
||inc $n.Counter.02 = 
|end 
Wouldn't this overwrite $a.Objects so you only get the last sector in each column?


Some script I wrote for myself (to find abandoned ships in this case, but I copy and change it a lot, hence the generic names):

Code: Select all

001   $sectorX = 0
002   $sectorY = 0
003   $searchLimit = 25
004   
005   skip if not $logfile
006   |write to log file #$logfile  append=[FALSE]  printf: fmt=' ', null, null, null, null, null
007   
008   while $sectorY <= $searchLimit
009   |$sectorX = 0
010   |while $sectorX <= $searchLimit
011   ||
012   ||$currentSector = get sector from universe index: x=$sectorX, y=$sectorY
013   ||if $currentSector -> exists
014   |||
015   |||$objectArray =  find ship: sector=$currentSector class or type=null race=null flags=[Find.Multiple] refobj=null maxdist=null maxnum=9999 refpos=null
016   |||
017   |||$numObjects =  size of array $objectArray
018   |||while $numObjects > 0
019   ||||dec $numObjects = 
020   ||||$currentObject = $objectArray[$numObjects]
021   ||||
022   ||||$pilot = $currentObject -> get pilot name
023   ||||if $pilot == 'No Pilot'
024   |||||$objectX = $currentObject -> get x position
025   |||||$objectY = $currentObject -> get y position
026   |||||$objectZ = $currentObject -> get z position
027   |||||
028   |||||$sectorName = sprintf: fmt='%s (%s,%s)', $currentSector, $sectorX, $sectorY, null, null
029   |||||$objectPos = sprintf: fmt='X%s, Y%s, Z%s', $objectX, $objectY, $objectZ, null, null
030   |||||
031   |||||write to player logbook: printf: fmt='%s; %s: %s.', $sectorName, $objectPos, $currentObject, null, null
032   |||||skip if not $logfile
033   ||||||write to log file #$logfile  append=[TRUE]  printf: fmt='%s; %s: %s', $sectorName, $objectPos, $currentObject, null, null
034   |||||
035   ||||end
036   |||end
037   ||end
038   ||
039   ||inc $sectorX = 
040   |end
041   |
042   |inc $sectorY = 
043   end
044   
045   return null
fud wrote:Looks like a great way to tax your cpu. ;)
It doesn't actually take very long to check every ship in the universe (as long as you're not doing it every second or whatever :p).

WindsOfBoreas
Posts: 283
Joined: Sun, 3. Aug 08, 20:30

Post by WindsOfBoreas » Wed, 28. Jan 09, 18:42

Oops, you're right. The two array sizes and the copy array should be within the while $n.Counter.02 < $n.MaxSectors.Y block. Thank you Carlo.
"Humanity has the stars in its future, and that future is too important to be lost under the burden of juvenile folly and ignorant superstition." - Isaac Asimov

User avatar
Aro
Posts: 2766
Joined: Tue, 15. Jul 03, 00:35
x4

Post by Aro » Wed, 28. Jan 09, 21:45

Of course it would be taxing running that many loops, it was a thought to run it once and check the result.

So what is the result of running it hmm :?

WindsOfBoreas
Posts: 283
Joined: Sun, 3. Aug 08, 20:30

Post by WindsOfBoreas » Wed, 28. Jan 09, 22:00

Actually, it's not really as taxing as it seems; certainly not the second loop which makes the text. Now, to further it a bit, you could make it so that it only checks known sectors.

What you do end up with from my sample script is an array of all of the ships that contain the chosen ware from argument one. You could change each ship's name (assuming we have removed any ship belonging to the player) to a color so it's easier to find.
"Humanity has the stars in its future, and that future is too important to be lost under the burden of juvenile folly and ignorant superstition." - Isaac Asimov

User avatar
Aro
Posts: 2766
Joined: Tue, 15. Jul 03, 00:35
x4

Post by Aro » Fri, 30. Jan 09, 04:49

What I'm saying is: could someone run it checking for the experimental weapons and report the findings please? (Omit any lasertowers for sanity's sake :wink:.)

markmid
Posts: 149
Joined: Tue, 10. Feb 04, 21:03
x2

Post by markmid » Fri, 30. Jan 09, 10:37

Its currently the kind of loop my custom Many AIs and Factions mod runs so ships can move to engage each other before someone starts firing and I run it every 10 seconds with no real performance hit. As I cannot use the race variable to get an easy 'foe' check.

I had toyed with the idea of attaching a small script on all ships instead, if your using signals you could probably get the same kind of result. For your idea, however you do it, you should be able to set flags to all these ships once and thus need to run the check very sparringly, meaning you'll see no real slowdown to performance.

When I work out whether a small running script on each ship or a global x/y approach is more efficient i'll let you know. Hopefully i'll find a more efficient method as I go, as the x/y enemy check is the least efficient part of my code currently, although I have been optimizing it the last couple of days.

Post Reply

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