aliens

Author Topic: Messing with yaml save games  (Read 5516 times)

Offline grrussel

  • Captain
  • ***
  • Posts: 72
    • View Profile
Messing with yaml save games
« 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")

Volutar

  • Guest
Re: Messing with yaml save games
« Reply #1 on: November 17, 2012, 09:19:45 am »
what is it?

Offline luke83

  • Commander
  • *****
  • Posts: 1558
    • View Profile
    • openxcommods
Re: Messing with yaml save games
« Reply #2 on: November 17, 2012, 12:19:04 pm »
I think its a battle scape maps unit locations shown with pixels.

Volutar

  • Guest
Re: Messing with yaml save games
« Reply #3 on: November 17, 2012, 01:22:23 pm »
no i mean language, where i suppose to input this?

Offline karvanit

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Messing with yaml save games
« Reply #4 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

Offline grrussel

  • Captain
  • ***
  • Posts: 72
    • View Profile
Re: Messing with yaml save games
« Reply #5 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.

Offline Warboy1982

  • Administrator
  • Commander
  • *****
  • Posts: 2333
  • Developer
    • View Profile
Re: Messing with yaml save games
« Reply #6 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.

Offline grrussel

  • Captain
  • ***
  • Posts: 72
    • View Profile
Re: Messing with yaml save games
« Reply #7 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.

Offline kkmic

  • Commander
  • *****
  • Posts: 582
  • Undefined
    • View Profile
Re: Messing with yaml save games
« Reply #8 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