[Seeking Advice] Periodically dump market data to file.

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
ejk
Posts: 6
Joined: Mon, 1. Jan 07, 17:19
x3tc

[Seeking Advice] Periodically dump market data to file.

Post by ejk » Wed, 2. Jul 14, 09:26

I've spent a fair few hours in the X universe still don't feel like I've gotten more than an anecdotal idea of the flow of goods including shortages and surplus. I was looking for some sort of script to dump out market prices periodically for a bit of 'fun'.

i.e. can I do anything useful with the data? Can I make a heatmap over time? Will I see anything interesting? How long until things stabilize? Will it all just be too hard?

Rather than unnecessarily coding the export script on my own and having to get over the hump of learnembering how to script in x3, I thought I'd check to see if anyone has ever done similar?

e.g. what I'm looking for in pseudo code:

do
batchtime = now
foreach(system in systems)
foreach(station in system)
foreach(item in station)

writetocsv batchtime, {goodsname, isbought, issold, stationmaxstock, stationcurrstock, stationcurrprice, stationmaxprice, stationminprice}

next
next
next
sleep(300 seconds)
while(1=1)


Once it's on the file system I can ingest and process it elsewhere.


pointless? dumb? maybe, but it's an itch I'm going to scratch.


learnembering = learning crossed with remembering, there should be a real word for it.


I did a search but didn't find anything adequate, and I've normally got pretty good google-fu.


Any Advice? Thanks!

User avatar
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 24962
Joined: Sun, 2. Apr 06, 16:38
x4

Post by X2-Illuminatus » Wed, 2. Jul 14, 10:56

SymTec ltd. did something like this for X3R with his dynamic supply map ("Dynamische Versorgungskarte"). Unfortunately, it seems there's only a German topic. You could have a look at the script files. Maybe you can reuse some parts of his code.
Nun verfügbar! X3: Farnham's Legacy - Ein neues Kapitel für einen alten Favoriten

Die komplette X-Roman-Reihe jetzt als Kindle E-Books! (Farnhams Legende, Nopileos, X3: Yoshiko, X3: Hüter der Tore, X3: Wächter der Erde)

Neuauflage der fünf X-Romane als Taschenbuch

The official X-novels Farnham's Legend, Nopileos, X3: Yoshiko as Kindle e-books!

ejk
Posts: 6
Joined: Mon, 1. Jan 07, 17:19
x3tc

Post by ejk » Wed, 2. Jul 14, 18:17

Great, thanks. I borrowed heavily from that. It still cost me a few hours but wasn't so bad.

Outputs similar to

Code: Select all

batchtime, stationid, ware, isbght, issold, maxstock, currstock, currprice, maxprice, minprice
12263, Computer Plant alpha(Kingdom End), Computer Components, 0, 1, 416, 150, 1484, 1698, 998
12263, Computer Plant alpha(Kingdom End), Energy Cells, 1, 0, 5000, 970, 18, 20, 12
12263, Computer Plant alpha(Kingdom End), BoFu, 1, 0, 832, 86, 385, 394, 190

and the code ended up being.

Code: Select all

  while 1 == 1
    
    $batchtime = playing time
    
    if $batchtime < 99999
      $lognumber = $batchtime
    else
      $lognumber = $batchtime mod 99999
    end
    
    $csvhead = 'batchtime, stationid, ware, isbght, issold, maxstock, currstock, currprice'
    $csvhead1 = 'maxprice, minprice'
    $csvhead2 = sprintf: fmt='%s, %s', $csvhead, $csvhead1, null, null, null
    write to log file #$lognumber  append=[FALSE]  value=$csvhead2
    $maxx = get max sectors in x direction
    $maxy = get max sectors in y direction
    $y = 0
    while $y < $maxy
      $x = 0
      while $x < $maxx
        $currsect = get sector from universe index: x=$x, y=$y
        if $currsect -> exists
@         = wait 1 ms
          $stations = $currsect -> get station array from sector
          $stationcount = size of array $stations
          if $stationcount > 0
            $currstationcount = 0
            while $currstationcount < $stationcount
              $station = $stations[$currstationcount]
              $wares = $station -> get tradeable ware array from station
              $w = 0
              $warecount = size of array $wares
              while $w < $warecount
                $ware = $wares[$w]
                $isbuyable = 0
                if $station -> can buy ware $ware
                  $isbuyable = 1
                end
                $issellable = 0
                if $station -> can sell ware $ware
                  $issellable = 1
                end
                $waremaxstock = $station -> get max. store amount of ware $ware
                $warecurrstock = $station -> get amount of ware $ware in cargo bay
                $warecurrprice = $station -> get price of ware $ware
                $waremaxprice = get max price of ware $ware
                $wareminprice = get min price of ware $ware
                
                $build = sprintf: fmt='%s, %s', $batchtime, $station, null, null, null
                $build1 = sprintf: fmt='%s, %s, %s, %s, %s', $build, $ware, $isbuyable, $issellable, $waremaxstock
                $build2 = sprintf: fmt='%s, %s, %s, %s, %s', $build1, $warecurrstock, $warecurrprice, $waremaxprice, $wareminprice
                
                write to log file #$lognumber  append=[TRUE]  value=$build2
                
                inc $w = 
              end
              inc $currstationcount = 
            end
          end
        end
        inc $x = 
      end
      inc $y = 
    end
@   = wait 300000 ms
  end
  return null
ugly right!

I'd wanted to use AL to get it to fire automatically but to keep it simple for now I'll leave it firing manually.

Thanks again.

ejk
Posts: 6
Joined: Mon, 1. Jan 07, 17:19
x3tc

Post by ejk » Fri, 4. Jul 14, 16:30

and I came out with some fairly interesting images of the heatmap

e.g. sector stock of ecells relative to sector capacity based on stations that buy ware

https://vidd.me/u0f

if anything it's a validation of that the market flows like you'd expect.
I think the timeframe on that is 4 in game days. Green is well stocked, Red is low stocked(high demand).

I'll probably have a bit more of a play and look at other wares in relation to supply/demand but I'm pretty happy that I was able sate my curiosity.

I wonder what it would take to flood the entire universe with ecells (all green!)...

Post Reply

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