Advertisement
nanogyth

u3_map_rng.py

Mar 24th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.56 KB | None | 0 0
  1. # support files ["asc_map.txt","sos.png","mobs2.png"]
  2. # https://www.mediafire.com/?iib1yemym7k8k71
  3.  
  4. from PIL import Image, ImageDraw
  5.  
  6. def mob_ok():
  7.     with open("asc_map.txt") as f:
  8.         for l in f.readlines():
  9.             for c in l:
  10.                 if c == ".": #plains
  11.                     yield 0
  12.                 elif c == "-": #shrub
  13.                     yield 0
  14.                 elif c == "|": #tree
  15.                     yield 0
  16.                 elif c == "^": #water
  17.                     yield 1
  18.                 elif c == "%": #lava
  19.                     yield 2
  20.                 elif c == "#": #mountains
  21.                     yield 2
  22.                 elif c == "T": #town
  23.                     yield 2
  24.                 elif c == "C": #castle
  25.                     yield 2
  26.                 elif c == "D": #dungeon
  27.                     yield 2
  28.                 else: #if c == "\n":
  29.                     pass
  30.  
  31. def shift_mob(x, y, type, ok_map=list(mob_ok())):
  32.     i = x + 64*y
  33.     while ok_map[i] != type:
  34.         i += 1
  35.     y,x = divmod(i,64)
  36.     return x,y
  37.    
  38. def pos_gen(start=0x0e,level=5):
  39.     rng = start
  40.     lvl_chart = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
  41.                  [0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,4,4,4,4,4,4,3,3,3,5,1],]
  42.     for i,t in enumerate(lvl_chart[level//5]):
  43.         rng = (185*rng-6)%256
  44.         x = rng//4
  45.         rng = (185*rng-6)%256
  46.         y = rng//4
  47.         x,y = shift_mob(x,y,t%2)
  48.         yield i,t,x,y,rng
  49.        
  50. world = Image.open("sos.png")
  51. d = ImageDraw.Draw(world)
  52.  
  53. def add_mob(x, y, t, i, border=False, mobs=Image.open("mobs2.png")):
  54.     mob = mobs.crop((16*t, 0, 16*(t+1), 16))
  55.     source = mob.split()
  56.     mask = source[1].point(lambda i: i != 0x80 and 255)
  57.     rect = (16*x,16*y,16*(x+1),16*(y+1))
  58.     if border is True:
  59.         if i < 27:
  60.             rg,b = divmod(i,3)
  61.             r,g = divmod(rg,3)
  62.             color = (r*128,g*128,b*128)
  63.             d.rectangle(rect, outline=color)
  64.     world.paste(mob, rect, mask)
  65.    
  66. def rng_gen(seed=0, stop=None):
  67.     if stop is None:
  68.         stop = seed
  69.     a = seed
  70.     while True:
  71.         yield a
  72.         a = (17*a + 23)%256
  73.         if a == stop:
  74.             break
  75.  
  76. rng_map = {n:i for i,n in enumerate(rng_gen())}
  77.  
  78. for index_in,rng_in in enumerate(rng_gen()):
  79.     world = Image.open("sos.png")
  80.     for i,t,x,y,rng_out in pos_gen(rng_in):
  81.         add_mob(x,y,t,i)    
  82.     index_out = rng_map[rng_out]
  83.     out_name = "L5\{:02x}_{:02x}_{:02x}_{:02x}.png".format(index_in,rng_in,rng_out,index_out,)
  84.     world.save(out_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement