OpenXcom Forum
Contributions => Programming => Topic started by: grrussel on November 16, 2012, 11:56:56 pm
-
Given a save file on the battlescape, generates a PNG map showing live + dead units, colour coded.
Fun parsing YAML! (slow on big save files)
def load():
f = open("/Users/grrussel/Library/Application Support/OpenXcom/boom3.sav")
import yaml
dd = []
for data in yaml.load_all(f):
dd.append(data)
bg = dd[1]["battleGame"]
return bg
b = load()
w = b["width"]
h = b["height"]
l = b["length"]
from PIL import Image
im = Image.new('RGB',(w,l))
tiles = b["tiles"]
units = b["units"]
for u in units:
pos = u["position"]
x,y = pos[0],pos[1]
faction = u["faction"]
health = u["health"]
col = (255,0,0) if faction == 0 else (0,0,255)
col = (255,255,255) if health == 0 else col
im.putpixel((x,y), col)
im.save("xxx.png")
-
what is it?
-
I think its a battle scape maps unit locations shown with pixels.
-
no i mean language, where i suppose to input this?
-
This seems to be a Python file.
So save it as whatever.py and run it by python whatever.py
-
This is a python script, indeed. It needs the pyaml and PIL libraries installed, too.
It loads a battlescape save game (change the path in the script, not elegant but meh) and makes a map of unit positions - showing red (xcom), white (dead), and blue (alien) as a png image.
-
@grrussel any chance you could whip up a script (or something more... generic? seems like nobody knows wtf to do with python) to bring saved games up-to-date with the more recent builds?
i'm sure it'd earn you some diamond-level street cred round here.
-
Its probably not possible to convert arbitrary save games between versions. It is possible to add features with load/save code that can default in missing values - and thats good to reduce game save changes. It won't always be possible, or sensible, I expect.
I changed the save and load code to get my changed save games; let the game load + verify, and then omit unneeded in saving, or add new content in saving.
-
While it should not be too hard to have a savegame migration feature, is it worth it? As Warboy said in another thread, this is a in-developlment project... savegame breakage between versions are of least concern.
Furthermore, most of the stuff seems to be already at (or near) 100% implementation, so the savegame issue should "dissapear" by itself in the near future.
But if you have the time, go ahead and do a migration script :D