[Info wanted] : Ship/object zone/sector from Save Game file ?

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
exogenesis
Posts: 2718
Joined: Sun, 9. Sep 07, 15:39
x4

[Info wanted] : Ship/object zone/sector from Save Game file ?

Post by exogenesis » Mon, 9. Dec 19, 23:56

Sorry to be so dim, this should be simple:

Can anyone tell me how to determine which zone/sector or whatever a ship/object is in,
as defined in the game save xml file?

I just want to plot out all the ships everywhere (to see where the faction conflict action is),
but the format has changed since I last did something like this (X3)

I guess it's got something to do with

<connection connection="ships">
...connection="space"...
.
.
<read space="[0xc0b1]"
.
<position x="-34144.773" y="22957.049" z="22670.859"/> (I get this bit, in-sector coords)
.


Does 0xc0b1 define the zone/sector, if so how (is it a link to one of the galaxy xml .cat files) ?

(I remember in the old X2/X3 format it was 'sector x, y', but that was for sectors in a 'cartesian' map format)

Or maybe there's a forum link to a more involved save-game format ?

Thanks for any info...

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Re: [Info wanted] : Ship/object zone/sector from Save Game file ?

Post by UniTrader » Wed, 11. Dec 19, 18:31

here is a hierarchy in the galaxy which goes like
Galaxy
Cluster
Sector
Zone

you should look into the parent nodes of the ship connection, its connections all the way up to galaxy.

and everything happens in the Zones. Some of them are pre-defined in the map (see xmls in the maps folder in the extracted game files), others are created dynamically as needed.

How detailed do you want your output? exact position in each sector or just rough amounts per sector or Zone?


PS sorry for the a bit confused post, but i restructured it after writing the most..
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

exogenesis
Posts: 2718
Joined: Sun, 9. Sep 07, 15:39
x4

Re: [Info wanted] : Ship/object zone/sector from Save Game file ?

Post by exogenesis » Wed, 11. Dec 19, 23:02

OK, thanks, I didn't realise it was so fully 'nested' (c.f X3, if I remember right)

So :

save_001.xml has

<universe>
.
.

and

<connection connection="cluster_43_connection">
<component class="cluster" macro="cluster_43_macro" connection="galaxy" code="BJW-669" knownto="player" known="1" read="0" id="[0xbe7b]">
.
.

and

<connection connection="zone003_cluster_43_sector001_connection">
<component class="zone" macro="zone003_cluster_43_sector001_macro" connection="sector" code="XHQ-444" knownto="player" id="[0xc0b1]">
.
.

and

<connection connection="ships">
<component class="ship_s" macro="ship_tel_s_fighter_01_a_macro" connection="space" ...
.
.
<position>
<read space="[0xc0b1]" numpathpoints="1" avoidbigobjects="1" avoidsmallobjects="1">
<offset>
<position x="-34144.773" y="22957.049" z="22670.859"/> (= in-



So along with other below files, I guess I can figure out the overall plot position for a ship/object.


maps\XU_ep2_universe\sectors.xml has:

<macro name="Cluster_43_Sector001_macro" class="sector">
.
.
<connection name="Zone003_Cluster_43_Sector001_connection" ref="zones">
<offset>
<position x="33098.4765625" y="0" z="-121434.3046875" />


maps\XU_ep2_universe\zones.xml has:

<macro name="Zone003_Cluster_43_Sector001_macro" class="zone">
.
.
<position x="-4845.052734375" y="500" z="-17207.908203125" />



I'm just wanting to plot reasonably exact position/orientation for all ships,
with faction colours, so I can see where the 'action is' for a snapshot save-game.
(mainly since the game map doesn't draw ships in different colours (according to faction).

The overall faction ship stats seems relatively easy e.g. Argon has a total of 1067 ships, with 64 of the 641 'L' ships of in the universe:

[ external image ]


Although I'm still not sure what the difference is between e.g. <ship> entry & <connection connection="ships"> entry is :

<ship>
<component class="ship_l" macro="ship_arg_l_trans_container_04_a_macro" code="AXQ-493" owner="argon" level="0.379387" spawntime="1949735.083" thruster="thruster_gen_l_allround_01_mk1_macro" id="[0x95543]">

versus:

<connection connection="ships">
<component class="ship_m" macro="ship_tel_m_frigate_01_a_macro" connection="space" code="SZL-664" owner="ownerless" knownto="player" capturable="0" thruster="thruster_gen_m_combat_01_mk2_macro" id="[0xbef7]">


Anyway, thanks for the 'kick start' :)

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Re: [Info wanted] : Ship/object zone/sector from Save Game file ?

Post by UniTrader » Mon, 16. Dec 19, 03:07

Although I'm still not sure what the difference is between e.g. <ship> entry & <connection connection="ships"> entry is :

<ship>
<component class="ship_l" macro="ship_arg_l_trans_container_04_a_macro" code="AXQ-493" owner="argon" level="0.379387" spawntime="1949735.083" thruster="thruster_gen_l_allround_01_mk1_macro" id="[0x95543]">

versus:

<connection connection="ships">
<component class="ship_m" macro="ship_tel_m_frigate_01_a_macro" connection="space" code="SZL-664" owner="ownerless" knownto="player" capturable="0" thruster="thruster_gen_m_combat_01_mk2_macro" id="[0xbef7]">
i assume one of them is docked somewhere, and the other is not


Also regarding the Offset Values for highways: might be confusing: X and Y are always 0 iirc and Z is at which position in the tube the ship is (from 0.0 to 1.0)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

exogenesis
Posts: 2718
Joined: Sun, 9. Sep 07, 15:39
x4

Re: [Info wanted] : Ship/object zone/sector from Save Game file ?

Post by exogenesis » Mon, 16. Dec 19, 22:36

Thanks for the reply,
I realised that the first ship is in the "jobs" section & has no x,y,z coords,
rather too many of them to be just a set of docked ships ?, so maybe that first one defines some sort of job.

Anyway I got a reasonable start coding with rapidxml to parse the save file,
but now that X4 v3.0 beta 4 allows toggling of object faction colours on the map (yay! :thumb_up: :), looks excellent),
I guess my reason for doing this has dropped off somewhat, but might still carry on just for the satisfaction of it...

Jeremy
Posts: 24
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [Info wanted] : Ship/object zone/sector from Save Game file ?

Post by Jeremy » Sun, 23. Feb 20, 00:05

Don't know if this will help you, but this is the xpath query I use to extract the 'universe'. It will get all stations, ships, sectors and clusters in the order in which they appear in the hierarchy. I.e. a station or ship is always in the last returned sector, and a sector is always part of the last returned cluster:

"/savegame/universe//component[@class='station' or contains(@class,'ship') or @class='sector' or @class='cluster']"

The first section of the returned components are a whole lot of NPC ships that have no connection attribute. Since they are the first set returned these are not 'in' any sector (or the galaxy for that matter). I believe that these are some sort of cache from which the game pulls newly created NPC ships. Once a ship is actually in the galaxy, it should always appear lower in the hierarchy than the sector it is in. You could probably slightly change the xpath query (add the 'galaxy' node in the path) to exclude these from the xpath result directly. I just filter them from the result set.

I do this in R script, which is fairly hard to follow if you don't know it but perhaps it helps you. This is the piece of code I use to extract the attributes of the above nodes into one big table, after which I can quickly extract the various objects by filtering on the 'class' and 'owner' attributes. The fillNAs function basically takes a column, goes through it from first to last row, and fills any missing values (called NA in R script) with the last occurring value. I use this to add cluster and sector ID columns so I can quickly extract all the objects from a single sector:

Code: Select all

require(XML)
require(plyr)

fillNAs <- function(values) {
  idx <- !is.na(values)
  return(c(NA, values[idx])[cumsum(idx)+1])
}

message(paste(format(Sys.time(), "%H:%M:%OS3"), "Reading most recent save:", save.filename))
result <- xmlParse(file = paste0(save.path, save.filename), addFinalizer = TRUE)

message(paste(format(Sys.time(), "%H:%M:%OS3"), "Parsing Universe"))
df.universe <- ldply(xpathSApply(result, "/savegame/universe//component[@class='station' or contains(@class,'ship') or @class='sector' or @class='cluster']", xmlAttrs, addFinalizer = TRUE), "rbind", .id = NULL)

# remove objects without connection and reset row counter
df.universe <- df.universe[-which(is.na(df.universe$connection)),]
row.names(df.universe) <- NULL

# find clusters & add id and macro
idx.clusters <- which(df.universe$class == "cluster")
df.universe[idx.clusters, "cluster.id"] <- df.universe$id[idx.clusters]
df.universe[idx.clusters, "cluster.macro"] <- df.universe$macro[idx.clusters]

# find sectors & add id and macro
idx.sectors <- which(df.universe$class == "sector")
df.universe[idx.sectors, "sector.id"] <- df.universe$id[idx.sectors]
df.universe[idx.sectors, "sector.macro"] <- df.universe$macro[idx.sectors]

# add cluster/sector id & macro to ships and stations
df.universe$cluster.id <- fillNAs(df.universe$cluster.id)
df.universe$cluster.macro <- fillNAs(df.universe$cluster.macro)
df.universe$sector.id <- fillNAs(df.universe$sector.id)
df.universe$sector.macro <- fillNAs(df.universe$sector.macro)
For ships, if it is flying, then the connection attribute of the component node is 'space', in which case the offset within the sector will be in the x, y, and z attributes of the movement/position/read/offset/position sub-node of the component. For a docked ship, @connection=='dock' and it will appear in the hierarchy within the component record of the ship or station it is docked to. I haven't bothered extracting those as I just use this to check my fleets to replace destroyed ships, not for determining the actual position within a sector.

Figuring out the way commanders and sub-ordinates are stitched together so I could see my fleet hierarchies was a lot harder and probably wouldn't be understandable unless you're versed in the R language so I'll refrain from posting that unless you really want to see it.

Good luck, for me it started with parsing the log entries so I could see my sales over time but as you can see one can get lost in the complexity of these files and the amount of useful information you can extract from it :)

exogenesis
Posts: 2718
Joined: Sun, 9. Sep 07, 15:39
x4

Re: [Info wanted] : Ship/object zone/sector from Save Game file ?

Post by exogenesis » Sun, 23. Feb 20, 11:45

Looks like you've got a useful method, not familiar with R myself.
Agree that the 1st 'section' of ships are significantly different from the main 2nd set of ships.

Doubt if I'll have a need to do anything more on this myself (famous last words)
since now the in-game features are mostly enough...

Post Reply

Return to “X4: Foundations - Scripts and Modding”