OpenXcom Forum

Contributions => Programming => Topic started by: grrussel on November 16, 2012, 11:56:56 pm

Title: Messing with yaml save games
Post 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")
Title: Re: Messing with yaml save games
Post by: Volutar on November 17, 2012, 09:19:45 am
what is it?
Title: Re: Messing with yaml save games
Post by: luke83 on November 17, 2012, 12:19:04 pm
I think its a battle scape maps unit locations shown with pixels.
Title: Re: Messing with yaml save games
Post by: Volutar on November 17, 2012, 01:22:23 pm
no i mean language, where i suppose to input this?
Title: Re: Messing with yaml save games
Post by: karvanit on November 17, 2012, 01:43:57 pm
This seems to be a Python file.

So save it as whatever.py and run it by
Code: [Select]
python whatever.py
Title: Re: Messing with yaml save games
Post by: grrussel on November 18, 2012, 12:43:56 am
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.
Title: Re: Messing with yaml save games
Post by: Warboy1982 on November 19, 2012, 08:54:06 am
@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.
Title: Re: Messing with yaml save games
Post by: grrussel on November 19, 2012, 07:51:38 pm
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.
Title: Re: Messing with yaml save games
Post by: kkmic on November 20, 2012, 12:18:58 pm
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