Benutzer:Schnobs/Skripte: Unterschied zwischen den Versionen

Aus X-Lexikon
Zur Navigation springenZur Suche springen
Schnobs (Diskussion | Beiträge)
Schnobs (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Zeile 31: Zeile 31:
==Ablauf (hier brauche ich Hilfe)==
==Ablauf (hier brauche ich Hilfe)==


===Start===
===setup.plugin.satdrop===


  Script plugin.satdrop.start
  001  $textID = 1312
  Version: 0
002  $pageID = 1002
  for Script Engine Version: 25
003  load text: id=$textID
  Description
004 
Asks for relevant values, starts Sat deployment loop
005  * link command to equipment
  Arguments                                                                                                                
006  set script command upgrade: command=COMMAND_DEPLOY_SATELLITE  upgrade=Spezialsoftware MK1
007 
008  * link command to actual script
009  global script map: set: key=COMMAND_DEPLOY_SATELLITE, class=Light Fighter M5, race=Player, script='plugin.satdrop.start', prio=0
  010 
011  set global variable: name=$pageID.satdrop value=$pageID
  012  set global variable: name=$textID.satdrop value=$textID
  013  return null
 
 
===plugin.satdrop.start===
 
Funktion: übernimmt die Benutzereingabe.
Klappert alle Sektoren ab und schreibt sie in ein array
Schickt das Schiff zum Basislager
exportiert die notwendigen variablen
startet das eigentliche Skript
 
  Arguments
   
   
     * 1: Camp , Var/Station , 'Select Base Camp'
     * 1: Camp , Var/Station , 'Select Base Camp'
Zeile 46: Zeile 64:
  Source Text
  Source Text
   
   
  001  $PageID = get global variable: name=$pageID.satdrop
  001  $textID = get global variable: name=$textID.satdrop
  002   
  002  $PageID = get global variable: name=$pageID.satdrop
  003  * Created by Schnobs, July 2007
  003  load text: id=$textID
  004  * Automatic Satellite Deployment, startup script
 
An dieser Stelle gibt es ein Problem: $PageID bekommt den Wert 1312, obwohl ich oben 1002 gesetzt und exportiert habe. Huch?
 
  004  $PageID = 1002
  005   
  005   
  006  if $SatType == 0
  006   * Created by Schnobs, July 2007
  007   $SatType = Navigationssatellit
007  * Automatic Satellite Deployment, startup script
  008   else
008 
  009   $SatType = Erweiterter Satellit
009   if $SatType == 0
  010   end
  010   $SatType = Navigationssatellit
  011    
  011   else
  012   * Andockerlaubnis am Basislager
  012   $SatType = Erweiterter Satellit
  013    
  013   end
  014   if not [THIS] -> is docking allowed at $Camp
  014    
  015   play sample 1248
  015   * Andockerlaubnis am Basislager
  016   write to player logbook: printf: pageid=$PageID textid=1, $Camp, null, null, null, null
  016    
  017   return null
  017   if not [THIS] -> is docking allowed at $Camp
  018   end
  018   play sample 1248
  019    
  019   write to player logbook: printf: pageid=$PageID textid=1, $Camp, null, null, null, null
  020   * sind schon Satelliten im Kofferraum
  020   return null
  021   if not [THIS] -> get amount of ware $SatType in cargo bay
  021   end
  022   * aha. Ist denn wenigstens genug Platz
  022    
  023   if not [THIS] -> get free amount of ware $SatType in cargo bay
  023   * sind schon Satelliten im Kofferraum
  024     play sample 1253
  024   if not [THIS] -> get amount of ware $SatType in cargo bay
  025     write to player logbook: printf: pageid=$PageID textid=2, $SatType, null, null, null, null
  025   * aha. Ist denn wenigstens genug Platz
  026     return null
  026   if not [THIS] -> get free amount of ware $SatType in cargo bay
  027   end
  027     play sample 1253
  028   end
  028     write to player logbook: printf: pageid=$PageID textid=2, $SatType, null, null, null, null
  029    
  029     return null
  030   * ----ab hier werden die Sektoren durchgegangen----
  030   end
  031   * erstmal ein paar variablen
  031   end
  032   * wie gross ist das Universum
  032    
  033   $uniX = get max sectors in x direction
  033   * ----ab hier werden die Sektoren durchgegangen----
  034   $uniY = get max sectors in y direction
  034   * erstmal ein paar variablen
  035    
  035   * wie gross ist das Universum
  036   * und wo bin ich gerade
  036   $uniX = get max sectors in x direction
  037   $CampSector = $Camp -> get sector
  037   $uniY = get max sectors in y direction
  038   $homeX = $CampSector -> get universe x index
  038    
  039   $homeY = $CampSector -> get universe y index
  039   * und wo bin ich gerade
  040   $SectorList =  array alloc: size=0
  040   $CampSector = $Camp -> get sector
041 
  041   $homeX = $CampSector -> get universe x index
042 
  042   $homeY = $CampSector -> get universe y index
043  * kleineren bereich abstecken...
  043   $SectorList =  array alloc: size=0
  044   
  044   
  045  $minX = $homeX - $Range
  045  
  046   skip if $minX >= 0
046  * kleineren bereich abstecken...
  047   $minX = 0
047 
  048   $maxX = $homeX + $Range
048   $minX = $homeX - $Range
  049   skip if $maxX <= $uniX
  049   skip if $minX >= 0
  050   $maxX = $uniX
  050   $minX = 0
  051    
  051   $maxX = $homeX + $Range
  052   $minY = $homeY - $Range
  052   skip if $maxX <= $uniX
  053   skip if $minY >= 0
  053   $maxX = $uniX
  054   $minY = 0
  054    
  055   $maxY = $homeY + $Range
  055   $minY = $homeY - $Range
  056   skip if $maxY <= $uniY
  056   skip if $minY >= 0
  057   $maxY = $uniY
  057   $minY = 0
  058    
  058   $maxY = $homeY + $Range
  059   * und jetzt fuer min max XY pruefen...
  059   skip if $maxY <= $uniY
  060    
  060   $maxY = $uniY
  061   $x = $minX
  061    
  062   while $x <= $maxX
  062   * und jetzt fuer min max XY pruefen...
  063   $y = $minY
  063    
  064   while $y <= $maxY
  064   $x = $minX
  065     $tempSec = get sector from universe index: x=$x, y=$y
  065   while $x <= $maxX
  066     $tempdist = get jumps from sector $CampSector to sector $tempSec
  066   $y = $minY
  067     $known = $tempSec -> is sector known by the player
  067   while $y <= $maxY
  068     $nmy = [THIS] -> is $tempSec a enemy
  068     $tempSec = get sector from universe index: x=$x, y=$y
  069     if $tempdist <= $Range AND $known == [TRUE] AND $nmy == [FALSE]
  069     $tempdist = get jumps from sector $CampSector to sector $tempSec
070     
  070     $known = $tempSec -> is sector known by the player
071  * Sektor dem Array hinzufuegen
  071     $nmy = [THIS] -> is $tempSec a enemy
072      append $tempSec to array $SectorList
  072     if $tempdist <= $Range AND $known == [TRUE] AND $nmy == [FALSE]
  073       
  073       
  074  * ende der eigentlichen tests
  074   * Sektor dem Array hinzufuegen
  075     end
075      skip if not  is datatyp[ $tempSec ] == DATATYP_SECTOR
  076      
076      append $tempSec to array $SectorList
  077   * y hochsetzen, y-Schleife beenden
077     
  078     inc $y =  
078   * ende der eigentlichen tests
  079   end
  079     end
  080    
  080      
  081   * Ende der x-Schleife
  081   * y hochsetzen, y-Schleife beenden
  082   inc $x =  
  082     inc $y =  
  083   end
  083   end
084 
  084    
085  * an dieser Stelle sollte eine Sektorenliste vorliege
  085   * Ende der x-Schleife
086  * nun die Liste ins Log schreiben
  086   inc $x =  
087 
  087   end
  088   
  088   
  089  $i = 1
  089   * an dieser Stelle sollte eine Sektorenliste vorliege
  090   $numSectors =  size of array $SectorList
090  * nun die Liste ins Log schreiben
  091   $tempSec = $SectorList[0]
091 
  092   $msg = $tempSec
092 
  093   while $i < $numSectors
093   $i = 1
  094   $tempSec = $SectorList[$i]
  094   $numSectors =  size of array $SectorList
  095   $msg = $msg + ', ' + $tempSec
  095   $tempSec = $SectorList[0]
  096   inc $i =  
  096   $msg = $tempSec
  097   end
  097   while $i < $numSectors
  098    
  098   $tempSec = $SectorList[$i]
  099   write to player logbook: printf: pageid=$PageID textid=3, $SatType, $Camp, $msg, null, null
  099   $msg = $msg + ', ' + $tempSec
  100    
  100   inc $i =  
  101    
  101   end
  102   * variablen exportieren un das eigentliche skript aufrufen.
  102    
  103   [THIS] -> set local variable: name=$SectorList value=$SectorList
  103   write to player logbook: printf: pageid=$PageID textid=3, $SatType, $Camp, $msg, null, null
  104   [THIS] -> set local variable: name=$SatType value=$SatType
  104 
  105 @ = [THIS] -> call script 'plugin.satdrop.main' :  Basislager=$Camp  Nav. oder Erw. satellit=$SatType
105   * erstmal zum Basislager
  106   * callscript
  106 @ = [THIS] -> call script 'lib.xi.nav' :  Target=$Camp  Range=null  Sector Position=null
  107  return null
107    
  108   * variablen exportieren un das eigentliche skript aufrufen.
  109   [THIS] -> set local variable: name=$SectorList value=$SectorList
  110   [THIS] -> set local variable: name=$SatType value=$SatType
  111 @ = [THIS] -> call script 'plugin.satdrop.main' :  Basislager=$Camp  Nav. oder Erw. satellit=$SatType
  112   return null
   
 
===plugin.satdrop.main===
 
Klappert die Sektoren im Array ab und sucht nach Satelliten. Falls keiner da ist, fliegt es los und stellt einen auf. Falls keine Satelliten (mehr) an Bord sind, wird das Nachschub-Skript aufgerufen.


'''Ich hatte bei den bisherigen Tests noch nie Satelliten an Bord. Ich kann bisher nur sagen, daß dieses Skript erfolgreich das Nachschub-Skript aufruft -- und dort ist was faul.'''


===Sektoren überprüfen===


Script plugin.satdrop.main
Version: 0
for Script Engine Version: 25
Description
Satellite Deployment, main program loop
Arguments
   
   
     * 1: Camp , Var/Station , 'Basislager'
     * 1: Camp , Var/Station , 'Basislager'
Zeile 169: Zeile 194:
  Source Text
  Source Text
   
   
  001   
  001  $textID = get global variable: name=$textID.satdrop
  002   
  002  $pageID = get global variable: name=$pageID.satdrop
  003   
  003  load text: id=$textID
  004   
  004  $pageID = 1002
  005  * dies ist eine Endlos-Schleife
  005  
  006   while [TRUE]
006   * dies ist eine Endlos-Schleife
  007   START:
  007   while [TRUE]
  008   * Sektorenliste aktualisieren
  008   START:
  009   $SectorList = [THIS] -> get local variable: name=$SectorList
  009   * Sektorenliste aktualisieren
  010    
  010   $SectorList = [THIS] -> get local variable: name=$SectorList
  011   * sind ueberhaupt Satelliten an Bord
  011    
  012   * nicht vergessen, alles ausser 0 ist wahr...
  012   * sind ueberhaupt Satelliten an Bord
  013   skip if [THIS] -> get amount of ware $SatType in cargo bay
  013   * nicht vergessen, alles ausser 0 ist wahr...
014  * FEHLT einkaufskript starten
  014   while [THIS] -> get amount of ware $SatType in cargo bay
  015  
  015    
  016  
  016    
  017   $i.sec = 0
  017     $i.sec = 0
  018   $sector.count =  size of array $SectorList
  018     $sector.count =  size of array $SectorList
  019   while $i.sec < $sector.count
  019     while $i.sec < $sector.count
  020     $tempSec = $SectorList[$i.sec]
  020     $tempSec = $SectorList[$i.sec]
  021    
  021    
  022  * falls wir keinen Nav.Sat finden...
  022  * falls wir keinen Nav.Sat finden...
  023     skip if  find ship: sector=$tempSec class or type=Navigationssatellit race=Player flags=null refobj=null maxdist=null maxnum=null refpos=null
  023     skip if  find ship: sector=$tempSec class or type=Navigationssatellit race=Player flags=null refobj=null maxdist=null maxnum=null refpos=null
  024  * und auch keinen Erw.Sat...
  024  * und auch keinen Erw.Sat...
  025     skip if  find ship: sector=$tempSec class or type=Erweiterter Satellit race=Player flags=null refobj=null maxdist=null maxnum=null refpos=null
  025     skip if  find ship: sector=$tempSec class or type=Erweiterter Satellit race=Player flags=null refobj=null maxdist=null maxnum=null refpos=null
  026  * sofort aus der Schleife ausbrechen.
  026  * sofort aus der Schleife ausbrechen.
  027     break
  027     break
  028    
  028    
  029    
  029    
  030  * wenn wir bis hier kommen, ist ein Satellit vorhanden.
  030  * wenn wir bis hier kommen, ist ein Satellit vorhanden.
  031  * deshalb wird tempSec geloescht, i hochgesetzt, naechster Sektor bitte.
  031  * deshalb wird tempSec geloescht, i hochgesetzt, naechster Sektor bitte.
  032     $tempSec = null
  032     $tempSec = null
  033     inc $i.sec =  
  033     inc $i.sec =  
  034    end
  034 @   = wait randomly from 0 to 500 ms
  035  
  035     end
  036  
  036    
  037  * wenn tempSec einen Wert hat, wurde oben kein Sat gefunden...
  037    
  038    if  is datatyp[ $tempSec ] == [SECTOR]
038   * wenn tempSec einen Wert hat, wurde oben kein Sat gefunden...
  039   * FEHLT script hingehen und satellit aussetzen
  039    if  is datatyp[ $tempSec ] == [SECTOR]
  040   
  040     
  041   * und zurueck auf los. Wir schauen uns die restlichen
041  * lib.xi.nav erwartet ein array x,y,z,sektor
  042   * Sektoren an, noch bevor wir nach hause fliegen.
042   * range ist keine sprungweite, sondern die abweichungvon xyz
  043 @   = wait randomly from 0 to 5000 ms
043      $sat.x = 0
  044    goto label START
044      $sat.y = 30000
  045    end
045      $sat.z = 0
  046   
046      $secpos =  array alloc: size=4
  047   
047      $secpos[0] = $sat.x
  048   * wenn wir hier ankommen, gibt es derzeit nichts weiter zu tun.
048      $secpos[1] = $sat.y
  049   * aber wenn wir im raum sind, gab es was zu tun.
049      $secpos[2] = $sat.z
  050  * brauchen wir nachschub an satelliten
050      $secpos[3] = $tempSec
051    if not [THIS] -> is docked
051 @    = [THIS] -> call script 'lib.xi.nav' :  Target=null  Range=300  Sector Position=$secpos
  052    $sat.count = [THIS] -> get amount of ware $SatType in cargo bay
052     
  053     skip if $sat.count > 1
053  * warentyp - schiffstyp
  054   * FEHLT einkaufscript aufrufen
054      $sat.shiptype = Erweiterter Satellit
  055 @  = wait randomly from 0 to 5000 ms
055      skip if $SatType == Erweiterter Satellit
  056    goto label START
056      $sat.shiptype = Navigationssatellit
057   end
057     
  058   
058  * sat im laderaum vernichten
059    
059      = [THIS] -> add -1 units of $SatType
  060   * wenn wir hier ankommen, wars ein nullrunde
060  * sat im weltall erzeugen
  061  * machen wir halt 5 Mizuras Pause...
061      $whats.this =  create ship: type=$sat.shiptype owner=Player addto=$tempSec x=$sat.x y=$sat.y z=$sat.z
062 @  = wait 300000 ms
  062     
063  * ...plus zusatzzahl
  063   * und zurueck auf los. Wir schauen uns die restlichen
  064 @ = wait randomly from 0 to 5000 ms
  064   * Sektoren an, noch bevor wir nach hause fliegen.
  065   end
  065 @   = wait randomly from 0 to 500 ms
  066   return null
  066      goto label START
  067    end
  068   
  069   
  070   * wenn wir hier ankommen, sind alle Sektoren geprueft
071  * und es fehlt nirgends ein Satellit.
  072   * wenn wir im Raum sind, ab nach Hause
  073    if not [THIS] -> is docked
  074 @    = [THIS] -> call script 'lib.xi.nav' :  Target=$Camp  Range=null  Sector Position=null
075  * andernfalls 5min aussetzen
076    else
077 @    = wait 300000 ms
  078     end
  079   * In jedem fall machen wir eine kurze Pause
  080 @  = wait randomly from 0 to 500 ms
  081   end
  082    
  083   * wenn wir diesen punkt erreichen, sind die Satelliten alle
  084 @  = [THIS] -> call script 'plugin.satdrop.buy' :  Ware=$SatType maxprice=null Basislager=$Camp
  085   end
  086   return null
===plugin.satdrop.buy===


Soll Satelliten nachkaufen. Klappt nicht.


===Satelliten einkaufen===
Dieses Skript ist zu 90% von den "Manuellen Handelsbefehlen" der Xai Corporation abgekupfert.
Dazu würde ich gerne auf die "Manuellen Handelsbefehle" (Skript im Bonuspack) zurückgreifen. Die Sprungweite würde dann von der Einstellung des Einsatzbereiches übernommen. Ein potentielles Problem besteht darin, daß für ein vernünftiges Einkaufsverhalten bereits einige Satelliten verteilt sein sollten...
 
    * 1: Arg1 , Value , 'Ware'
    * 2: Arg2 , Value , 'maxprice'
    * 3: Camp , Var/Station , 'Basislager'
Source Text
001  * Created by Xai Corporation
002  *
003  * ---------------------------------------
004  * Find best buy
005  * - Arg1-Ware, Arg2-MaxPrice, Arg3-Max-Jumps
006  *  -  set defaults if not already set
007  $textID = get global variable: name=$textID.satdrop
008  load text: id=$textID
009  $pageID = 1002
010 
011 
012 
013  if not $Arg1
014    return null
015  else if not  is datatyp[ $Arg1 ] == DATATYP_WARE
016    return null
017  end
018  if not $Arg2
019    $Arg2 = get max price of ware $Arg1
020  else if not  is datatyp[ $Arg2 ] == DATATYP_INT
021    $Arg2 = get max price of ware $Arg1
022  end
023 
024  $price.avg = get average price of ware $Arg1
025 
026  $in.cargo = [THIS] -> get amount of ware $Arg1 in cargo bay
027  $failed.attempt = 0
028  $gametime.start = playing time
029 
030  while $in.cargo == 0
031   
032  *  -  get  sectors in range
033    enable signal/interrupt handling: [FALSE]
034    $sector.list = [THIS] -> get local variable: name=$SectorList


XI berechnet hier eine Sektorenliste (array) nach ihren eigenen Regeln. Den ganzen Plumquatsch habe ich abgeschnitten und will stattdessen mein eigenes Array nachladen. Wenn ich den Debugger über dieses Skript laufen lasse, zeigt er mir für $sector.list ''DATATYP_NULL, null, (0)'' -- ich habe jetzt schon ein dutzend mal geprüft, das Start-Skript exportiert das Array und im main-Skript wird es auch erfolgreich geladen.


===Der Rest===
035    $sector.list.num =  size of array $sector.list
Ziel Anfliegen, Satellit erzeugen, ggf zurück zum Parkplatz. Nichts davon sollte ein Problem sein.
036  *  -  get best price from sectors in range
037    $best.price = get max price of ware $Arg1
038    while $sector.list.num
039    dec $sector.list.num =
040    $sector = $sector.list[$sector.list.num]
041    if $Arg2 > $price.avg
042      $station = find station: product $Arg1 with best price:  max.price=$price.avg, amount=null, max.jumps=0, startsector=$sector, trader=[THIS]
043      skip if $station
044      $station =  find station sells: resource $Arg1 with best price: max.price=$Arg2, amount=null, max.jumps=0, startsector=$sector, trader=[THIS]
045    end
046    skip if $station
047      $station =  find station: product $Arg1 with best price:  max.price=$Arg2, amount=null, max.jumps=0, startsector=$sector, trader=[THIS]
048  *  -  set station as best if price is lowest
049    if $station
050      $station.isEnemy = [THIS] -> is $station a enemy
051      if $Arg3 < 3 OR ! $station.isEnemy
052      $range = get jumps from sector [SECTOR] to sector $sector
053      $price = $station -> get price of ware $Arg1
054      if $best.range > $range OR $price < $best.price
055        $best.price = $price
056        $Arg2 = $best.price
057        $best.station = $station
058        $best.range = $range
059      end
060  * trust me this is needed for line 59
061      $station = null
062      end
063    end
064   
065    end
066    $station = $best.station
067    $ware = $Arg1
068   
069  * set Display
070    [THIS] -> set destination to $station
071    [THIS] -> set wanted ware to $ware
072    [THIS] -> set command: COMMAND_GET_WARE  target=$ware target2=null par1=null par2=null
073    set script command: COMMAND_SIGN_MTC_BEST_BUY
074   
075  * fly to station
076    $station.name = sprintf: fmt='%s', $station, null, null, null, null
077    while not $arrived
078 @  $arrived = [THIS] -> call script 'lib.xi.nav' :  Target=$station  Range=null  Sector Position=null
079 @  = wait 300 ms
080    end
081   
082  * check we have arrived
083    if [DOCKEDAT] == $station
084 @  = [THIS] -> call script 'lib.xi.trade' :  Command='buy'  Ware=$ware  Quantity=null
085    end
086   
087  * .........................................
088  * an dieser Stelle sollten wir wieder Satelliten haben
089  * .........................................
090   
091  * nirgends angedockt bedeutet Probleme
092    skip if [THIS] -> is docked
093 @  = [THIS] -> call script 'lib.xi.nav' :  Target=$Camp  Range=null  Sector Position=null
094   
095   
096    $in.cargo = [THIS] -> get amount of ware $Arg1 in cargo bay
097   
098   
099  * doch noch keine satelliten bekommen...
100  * alle stunde nachricht an den spieler und weiter versuchen
101    if $in.cargo == 0
102    inc $failed.attempt =
103    if $failed.attempt >= 12
104      $gametime.now = playing time
105      $gametime.passed = ( $gametime.now - $gametime.start ) mod 60
106      write to player logbook: printf: pageid=1002 textid=4, $gametime.passed, $ware, null, null, null
107      $failed.attempt = 0
108    end
109 @  = wait 300000 ms
110    end
111  end
112  return null

Version vom 24. Juni 2007, 19:18 Uhr

Jawoll, ich will's versuchen. Mal sehen, was dabei rauskommt. Als erstes Projekt habe ich mir ein Skript vorgenommen, daß automatisch Satelliten aufstellt (und zerstörte Satelliten ersetzt).

Hier der Plan. Kommentare sind herzlich willkommen.


Funktionsumfang

oder
Was geht und was nicht geht

Dies ist ein sehr schlichtes Skript, um in einem bestimmten Bereich Satelliten aufzustellen. Das Schiff plaziert Satelliten in allen Sektoren des Einsatzgebietes, und ersetzt verloren gegangene. Die erforderlichen Satelliten werden (ebenfalls innerhalb des Einsatzgebietes) günstigst eingekauft.

Dieses Skript richtet sich an den aufstrebenden Jungunternehmer: der Funktionsumfang ist bescheiden, mit Problemen kann es nicht umgehen. Dafür entstehen auch keine weiteren Kosten, keine Gebühr pro aufgestelltem Satellit oder sowas. Die Satelliten und das Schiff sind schon teuer genug.


Bedienung:
Bei Start wird man gebeten, eine Station auszuwählen: das Basislager. Dies ist keine Heimatbasis im eigentlichen Sinne, sondern lediglich der Parkplatz, den das Schiff anfliegt, wenn es sonst nichts zu tun hat. Insofern tut es jede Station, auf der man andocken kann.

Weiterhin wird man gefragt, welche Art von Satellit man verteilen will: E = Erweitert, alle anderen Eingaben = Navigationssatellit.

Zu guter letzt soll man noch eine Sprungweite angeben. Der Ausgangspunkt ist der Sektor, in dem sich das Basislager befindet. Das Einsatzgebiet wird aus der Sprungweite in Verbindung mit den Freund/Feind-Einstellungen berechnet. Beispiel: Basislager ist die Handelsstation in Argon Prime, Sprungweite ist 7, alle außer den Argonen sind Feinde. Ergebins: das Einsatzgebiet sind die sog. "Argonischen Kernsektoren".

Die Einbeziehung der Freund/Feind-Einstellungen ermöglicht eine recht sinnvolle Abgrenzung des Einsatzgebietes. Es wird einmal berechnet und dann als Liste gespeichert; es ließe sich also mit relativ wenig Aufwand ein Skript basteln, das einzelne Sektoren zur Liste hinzufügt oder daraus entfernt. Wenn man die F/F-Einstellungen später ändert, hat das KEINE Auswirkungen auf den Einsatzbereich!

Was geschieht:
Alle fünf Mizuras werden die Sektoren im Einsatzbereich abgeklopft. Wenn sich in einem Sektor kein Spieler-Satellit befindet, fliegt das Schiff hin und plaziert einen Satelliten in der Mitte des Sektors deutlich oberhalb der Ekliptik. Es kann mehrere Satelliten hintereinander aufstellen, ohne jedesmal zum Basislager zurückzukehren.

Wenn ihm die Satelliten ausgehen, versucht es innerhalb des Einsatzgebietes neue zu beschaffen. So billig wie möglich zwar, aber erforderlichenfalls werden Spitzenpreise gezahlt. Falls das aus welchem Grund auch immer nicht klappt: Kein Geld auf dem Spielerkonto? Keine Station im Einsatzgebiet handelt mit den erforderlichen Satelliten? Keine Andockerlaubnis irgendwo? Das Skript kennt das alles nicht. Es weiß nur daß immer noch keine Satelliten geladen hat, wartet ein paar Mizuras und versucht es erneut. Wenn es über längere Zeit keine Satelliten einkaufen kann, wird ca. einmal pro Stunde eine Nachricht an den Spieler geschickt, während das Schiff es einfach immer weiter versucht.

Also, nochmal zum mitschreiben: das Skript ist schlau genug, ohne Satelliten gar nicht erst zu starten. Und das ist die einzige Intelligenz, die es hat. Andere Probleme werden nicht einmal erkannt.

Ablauf (hier brauche ich Hilfe)

setup.plugin.satdrop

001   $textID = 1312
002   $pageID = 1002
003   load text: id=$textID
004   
005   * link command to equipment
006   set script command upgrade: command=COMMAND_DEPLOY_SATELLITE  upgrade=Spezialsoftware MK1
007   
008   * link command to actual script
009   global script map: set: key=COMMAND_DEPLOY_SATELLITE, class=Light Fighter M5, race=Player, script='plugin.satdrop.start', prio=0
010   
011   set global variable: name=$pageID.satdrop value=$pageID
012   set global variable: name=$textID.satdrop value=$textID
013   return null


plugin.satdrop.start

Funktion: übernimmt die Benutzereingabe. Klappert alle Sektoren ab und schreibt sie in ein array Schickt das Schiff zum Basislager exportiert die notwendigen variablen startet das eigentliche Skript

Arguments

    * 1: Camp , Var/Station , 'Select Base Camp'
    * 2: SatType , Var/Number , '0 NavSat, alles andere Erw.Sat'
    * 3: Range , Var/Number , 'max. Jump Range'

Source Text

001   $textID = get global variable: name=$textID.satdrop
002   $PageID = get global variable: name=$pageID.satdrop
003   load text: id=$textID

An dieser Stelle gibt es ein Problem: $PageID bekommt den Wert 1312, obwohl ich oben 1002 gesetzt und exportiert habe. Huch?

004   $PageID = 1002
005   
006   * Created by Schnobs, July 2007
007   * Automatic Satellite Deployment, startup script
008   
009   if $SatType == 0
010    $SatType = Navigationssatellit
011   else
012    $SatType = Erweiterter Satellit
013   end
014   
015   * Andockerlaubnis am Basislager
016   
017   if not [THIS] -> is docking allowed at $Camp
018    play sample 1248
019    write to player logbook: printf: pageid=$PageID textid=1, $Camp, null, null, null, null
020    return null
021   end
022   
023   * sind schon Satelliten im Kofferraum
024   if not [THIS] -> get amount of ware $SatType in cargo bay
025   * aha. Ist denn wenigstens genug Platz
026    if not [THIS] -> get free amount of ware $SatType in cargo bay
027     play sample 1253
028     write to player logbook: printf: pageid=$PageID textid=2, $SatType, null, null, null, null
029     return null
030    end
031   end
032   
033   * ----ab hier werden die Sektoren durchgegangen----
034   * erstmal ein paar variablen
035   * wie gross ist das Universum
036   $uniX = get max sectors in x direction
037   $uniY = get max sectors in y direction
038   
039   * und wo bin ich gerade
040   $CampSector = $Camp -> get sector
041   $homeX = $CampSector -> get universe x index
042   $homeY = $CampSector -> get universe y index
043   $SectorList =  array alloc: size=0
044   
045   
046   * kleineren bereich abstecken...
047   
048   $minX = $homeX - $Range
049   skip if $minX >= 0
050    $minX = 0
051   $maxX = $homeX + $Range
052   skip if $maxX <= $uniX
053    $maxX = $uniX
054   
055   $minY = $homeY - $Range
056   skip if $minY >= 0
057    $minY = 0
058   $maxY = $homeY + $Range
059   skip if $maxY <= $uniY
060    $maxY = $uniY
061   
062   * und jetzt fuer min max XY pruefen...
063   
064   $x = $minX
065   while $x <= $maxX
066    $y = $minY
067    while $y <= $maxY
068     $tempSec = get sector from universe index: x=$x, y=$y
069     $tempdist = get jumps from sector $CampSector to sector $tempSec
070     $known = $tempSec -> is sector known by the player
071     $nmy = [THIS] -> is $tempSec a enemy
072     if $tempdist <= $Range AND $known == [TRUE] AND $nmy == [FALSE]
073      
074   * Sektor dem Array hinzufuegen
075      skip if not  is datatyp[ $tempSec ] == DATATYP_SECTOR
076       append $tempSec to array $SectorList
077      
078   * ende der eigentlichen tests
079     end
080     
081   * y hochsetzen, y-Schleife beenden
082     inc $y = 
083    end
084    
085   * Ende der x-Schleife
086    inc $x = 
087   end
088   
089   * an dieser Stelle sollte eine Sektorenliste vorliege
090   * nun die Liste ins Log schreiben
091   
092   
093   $i = 1
094   $numSectors =  size of array $SectorList
095   $tempSec = $SectorList[0]
096   $msg = $tempSec
097   while $i < $numSectors
098    $tempSec = $SectorList[$i]
099    $msg = $msg + ', ' + $tempSec
100    inc $i = 
101   end
102   
103   write to player logbook: printf: pageid=$PageID textid=3, $SatType, $Camp, $msg, null, null
104   
105   * erstmal zum Basislager
106 @ = [THIS] -> call script 'lib.xi.nav' :  Target=$Camp  Range=null  Sector Position=null
107   
108   * variablen exportieren un das eigentliche skript aufrufen.
109   [THIS] -> set local variable: name=$SectorList value=$SectorList
110   [THIS] -> set local variable: name=$SatType value=$SatType
111 @ = [THIS] -> call script 'plugin.satdrop.main' :  Basislager=$Camp  Nav. oder Erw. satellit=$SatType
112   return null

plugin.satdrop.main

Klappert die Sektoren im Array ab und sucht nach Satelliten. Falls keiner da ist, fliegt es los und stellt einen auf. Falls keine Satelliten (mehr) an Bord sind, wird das Nachschub-Skript aufgerufen.

Ich hatte bei den bisherigen Tests noch nie Satelliten an Bord. Ich kann bisher nur sagen, daß dieses Skript erfolgreich das Nachschub-Skript aufruft -- und dort ist was faul.


    * 1: Camp , Var/Station , 'Basislager'
    * 2: SatType , Var/Ware , 'Nav. oder Erw. satellit'

Source Text

001   $textID = get global variable: name=$textID.satdrop
002   $pageID = get global variable: name=$pageID.satdrop
003   load text: id=$textID
004   $pageID = 1002
005   
006   * dies ist eine Endlos-Schleife
007   while [TRUE]
008   START:
009   * Sektorenliste aktualisieren
010    $SectorList = [THIS] -> get local variable: name=$SectorList
011    
012   * sind ueberhaupt Satelliten an Bord
013   * nicht vergessen, alles ausser 0 ist wahr...
014    while [THIS] -> get amount of ware $SatType in cargo bay
015     
016     
017     $i.sec = 0
018     $sector.count =  size of array $SectorList
019     while $i.sec < $sector.count
020      $tempSec = $SectorList[$i.sec]
021      
022   * falls wir keinen Nav.Sat finden...
023      skip if  find ship: sector=$tempSec class or type=Navigationssatellit race=Player flags=null refobj=null maxdist=null maxnum=null refpos=null
024   * und auch keinen Erw.Sat...
025      skip if  find ship: sector=$tempSec class or type=Erweiterter Satellit race=Player flags=null refobj=null maxdist=null maxnum=null refpos=null
026   * sofort aus der Schleife ausbrechen.
027      break
028      
029      
030   * wenn wir bis hier kommen, ist ein Satellit vorhanden.
031   * deshalb wird tempSec geloescht, i hochgesetzt, naechster Sektor bitte.
032      $tempSec = null
033      inc $i.sec = 
034 @    = wait randomly from 0 to 500 ms
035     end
036     
037     
038   * wenn tempSec einen Wert hat, wurde oben kein Sat gefunden...
039     if  is datatyp[ $tempSec ] == [SECTOR]
040      
041   * lib.xi.nav erwartet ein array x,y,z,sektor
042   * range ist keine sprungweite, sondern die abweichungvon xyz
043      $sat.x = 0
044      $sat.y = 30000
045      $sat.z = 0
046      $secpos =  array alloc: size=4
047      $secpos[0] = $sat.x
048      $secpos[1] = $sat.y
049      $secpos[2] = $sat.z
050      $secpos[3] = $tempSec
051 @    = [THIS] -> call script 'lib.xi.nav' :  Target=null  Range=300  Sector Position=$secpos
052      
053   * warentyp - schiffstyp
054      $sat.shiptype = Erweiterter Satellit
055      skip if $SatType == Erweiterter Satellit
056       $sat.shiptype = Navigationssatellit
057      
058   * sat im laderaum vernichten
059      = [THIS] -> add -1 units of $SatType
060   * sat im weltall erzeugen
061      $whats.this =  create ship: type=$sat.shiptype owner=Player addto=$tempSec x=$sat.x y=$sat.y z=$sat.z
062      
063   * und zurueck auf los. Wir schauen uns die restlichen
064   * Sektoren an, noch bevor wir nach hause fliegen.
065 @    = wait randomly from 0 to 500 ms
066      goto label START
067     end
068     
069     
070   * wenn wir hier ankommen, sind alle Sektoren geprueft
071   * und es fehlt nirgends ein Satellit.
072   * wenn wir im Raum sind, ab nach Hause
073     if not [THIS] -> is docked
074 @    = [THIS] -> call script 'lib.xi.nav' :  Target=$Camp  Range=null  Sector Position=null
075   * andernfalls 5min aussetzen
076     else
077 @    = wait 300000 ms
078     end
079   * In jedem fall machen wir eine kurze Pause
080 @   = wait randomly from 0 to 500 ms
081    end
082    
083   * wenn wir diesen punkt erreichen, sind die Satelliten alle
084 @  = [THIS] -> call script 'plugin.satdrop.buy' :  Ware=$SatType  maxprice=null  Basislager=$Camp
085   end
086   return null

plugin.satdrop.buy

Soll Satelliten nachkaufen. Klappt nicht.

Dieses Skript ist zu 90% von den "Manuellen Handelsbefehlen" der Xai Corporation abgekupfert.

    * 1: Arg1 , Value , 'Ware'
    * 2: Arg2 , Value , 'maxprice'
    * 3: Camp , Var/Station , 'Basislager'

Source Text

001   * Created by Xai Corporation
002   * 
003   * ---------------------------------------
004   * Find best buy
005   * - Arg1-Ware, Arg2-MaxPrice, Arg3-Max-Jumps
006   *  -  set defaults if not already set
007   $textID = get global variable: name=$textID.satdrop
008   load text: id=$textID
009   $pageID = 1002
010   
011   
012   
013   if not $Arg1
014    return null
015   else if not  is datatyp[ $Arg1 ] == DATATYP_WARE
016    return null
017   end
018   if not $Arg2
019    $Arg2 = get max price of ware $Arg1
020   else if not  is datatyp[ $Arg2 ] == DATATYP_INT
021    $Arg2 = get max price of ware $Arg1
022   end
023   
024   $price.avg = get average price of ware $Arg1
025   
026   $in.cargo = [THIS] -> get amount of ware $Arg1 in cargo bay
027   $failed.attempt = 0
028   $gametime.start = playing time
029   
030   while $in.cargo == 0
031    
032   *   -  get  sectors in range
033    enable signal/interrupt handling: [FALSE]
034    $sector.list = [THIS] -> get local variable: name=$SectorList

XI berechnet hier eine Sektorenliste (array) nach ihren eigenen Regeln. Den ganzen Plumquatsch habe ich abgeschnitten und will stattdessen mein eigenes Array nachladen. Wenn ich den Debugger über dieses Skript laufen lasse, zeigt er mir für $sector.list DATATYP_NULL, null, (0) -- ich habe jetzt schon ein dutzend mal geprüft, das Start-Skript exportiert das Array und im main-Skript wird es auch erfolgreich geladen.

035    $sector.list.num =  size of array $sector.list
036   *   -  get best price from sectors in range
037    $best.price = get max price of ware $Arg1
038    while $sector.list.num
039     dec $sector.list.num = 
040     $sector = $sector.list[$sector.list.num]
041     if $Arg2 > $price.avg
042      $station =  find station: product $Arg1 with best price:  max.price=$price.avg, amount=null, max.jumps=0, startsector=$sector, trader=[THIS]
043      skip if $station
044       $station =  find station sells: resource $Arg1 with best price: max.price=$Arg2, amount=null, max.jumps=0, startsector=$sector, trader=[THIS]
045     end
046     skip if $station
047      $station =  find station: product $Arg1 with best price:  max.price=$Arg2, amount=null, max.jumps=0, startsector=$sector, trader=[THIS]
048   *   -  set station as best if price is lowest
049     if $station
050      $station.isEnemy = [THIS] -> is $station a enemy
051      if $Arg3 < 3 OR ! $station.isEnemy
052       $range = get jumps from sector [SECTOR] to sector $sector
053       $price = $station -> get price of ware $Arg1
054       if $best.range > $range OR $price < $best.price
055        $best.price = $price
056        $Arg2 = $best.price
057        $best.station = $station
058        $best.range = $range
059       end
060   * trust me this is needed for line 59
061       $station = null
062      end
063     end
064     
065    end
066    $station = $best.station
067    $ware = $Arg1
068    
069   * set Display
070    [THIS] -> set destination to $station
071    [THIS] -> set wanted ware to $ware
072    [THIS] -> set command: COMMAND_GET_WARE  target=$ware target2=null par1=null par2=null
073    set script command: COMMAND_SIGN_MTC_BEST_BUY
074    
075   * fly to station
076    $station.name = sprintf: fmt='%s', $station, null, null, null, null
077    while not $arrived
078 @   $arrived = [THIS] -> call script 'lib.xi.nav' :  Target=$station  Range=null  Sector Position=null
079 @   = wait 300 ms
080    end
081    
082   * check we have arrived
083    if [DOCKEDAT] == $station
084 @   = [THIS] -> call script 'lib.xi.trade' :  Command='buy'  Ware=$ware  Quantity=null
085    end
086    
087   * .........................................
088   * an dieser Stelle sollten wir wieder Satelliten haben
089   * .........................................
090    
091   * nirgends angedockt bedeutet Probleme
092    skip if [THIS] -> is docked
093 @   = [THIS] -> call script 'lib.xi.nav' :  Target=$Camp  Range=null  Sector Position=null
094    
095    
096    $in.cargo = [THIS] -> get amount of ware $Arg1 in cargo bay
097    
098    
099   * doch noch keine satelliten bekommen...
100   * alle stunde nachricht an den spieler und weiter versuchen
101    if $in.cargo == 0
102     inc $failed.attempt = 
103     if $failed.attempt >= 12
104      $gametime.now = playing time
105      $gametime.passed = ( $gametime.now - $gametime.start ) mod 60
106      write to player logbook: printf: pageid=1002 textid=4, $gametime.passed, $ware, null, null, null
107      $failed.attempt = 0
108     end
109 @   = wait 300000 ms
110    end
111   end
112   return null