#!/usr/bin/env python # This script handles part of converting a Freeciv map in to an isometric # map to use in C-evo. It makes a "flat grid" map isometric (by turning it # 45 degrees) and randomly adds resources, as well as converting the file # format from Freeciv to C-evo. # Note that this script does not set up player starts nor spaceship resources; # those will need to be set up by hand after running this script. # NE here -> Top of map in C-evo conversion # \: Northwest corner of map in C-evo # /: Southeast corner of map in C-evo # : is ocean, space is coast, * is void, f is forest, h is hills # m is mountains, g is grassland, d is desert, j is jungle import sys from random import randint, seed seed(201205141) t = [] # Terrain n = [] # Rivers # Initialize the arrays for a in range(88): t.append( "***********************************************************************") n.append( "00000000000000000000000000000000000000000000000000000000000000000000000") out = [] for x in range(100): out.append([]) for x in range(100): for y in range(96): out[x].append(-1) # As per http://www.c-evo.org/mapspec.html def cmap(square,river): if river == "2": mask = 0x80 # River here else: mask = 0 nobonus = 0 if square == ":": nobonus = 1 # Never any bonus if square == "g" or square == "a": nobonus = 2 # No trade bonus b = randint(1,100) if(b<=3 and nobonus == 0): mask |= 0x40 # Trade bonus elif(b<=10 and nobonus != 1): mask |= 0x20 # Food bonus if square == ":": return mask if square == " ": return mask | 0x01 if square == "g": return mask | 0x02 if square == "d": return mask | 0x03 if square == "p": return mask | 0x04 if square == "t": return mask | 0x05 if square == "a": return mask | 0x06 if square == "s": # Civ4 doesn't have swamp, mind you... return mask | 0x07 if square == "f": return mask | 0x09 if square == "j": # C-evo has jungle tiles but it's just forest return mask | 0x09 if square == "h": return mask | 0x0a if square == "m": return mask | 0x0b return mask # Default to ocean # C-evo uses binary 32-bit non-negative integers def nummap(inx): b = "" for a in range(4): b += "%c" % (inx & 0xff) inx >>= 8 return b def showmap(out,sizex,sizey): sys.stdout.write("cEvoMap\0") # Magic header sys.stdout.write(nummap(0)) # Format (0) sys.stdout.write(nummap(0)) # MaxTurn (0) sys.stdout.write(nummap(sizex)) sys.stdout.write(nummap(sizey)) for oy in range(sizey): for ox in range(sizex): if(out[ox][oy] != -1): sys.stdout.write(nummap(out[ox][oy])) else: sys.stdout.write(nummap(0)) # Here is the map we are converting...(code follows it) t[0]="*********************************************\*************************" t[1]="********************************************:::************************" t[2]="*******************************************:::::***********************" t[3]="******************************************:::::::**********************" t[4]="*****************************************:::::::::*********************" t[5]="****************************************:::::::::::********************" t[6]="***************************************:::::::::::::*******************" t[7]="**************************************:::::::::::::::******************" t[8]="*************************************:::::::::::::::::*****************" t[9]="************************************:::::::::::::::::::****************" t[10]="***********************************:::::::::::::::::::::***************" t[11]="**********************************:::::::::::::::::::::::**************" t[12]="*********************************:::::::::::::::::::::::::*************" t[13]="********************************:::::::::::::::::::::::::::************" t[14]="*******************************:::::::::::::::::::::::::::::***********" t[15]="******************************:::::::::::::::::::::: ::::**********" t[16]="*****************************:::::::::: :::::::: fhm :::::*********" t[17]="****************************::::: g fhhm ::::::********" t[18]="***************************::: f mf pffghfffffffhmm ::::::::*******" t[19]="**************************:: ff ffhffphhgffhggffhfm :::::::::******" t[20]="*************************::: fm fffffhhhhfffmfhfgffm :::::::::::*****" t[21]="************************:::: hffffhhfhfhhhpfg mhhhfhhm ::::::::::::****" t[22]="***********************::::: hfghhhhfffhhmmhp hpffffm :::::::::::::***" t[23]="**********************::: h fhhhhhghhhhmmmh mppdfpm ::::::::::::::**" t[24]="*********************: f f phhhfmpphddhhmm hmppdfm ::::::::::::::*" t[25]="********************:: ff ffhhhpmpddddmhm mhddhpmm :::::::::::::::" t[26]="*******************::: fhj jhfhphhppddmdhmhdmhhddpphm ::::::::::::::" t[27]="******************:::: jh jjjjfpppmhhdddddhdhhhhhddphfmm ::::::::::::::" t[28]="*****************:: h jjjjffffddhhdddhhhhddhmddddfhm :::::::::::::" t[29]="****************:: j jjfggppppphddhdmddddmhdhpphmm :::::::::::::" t[30]="***************::: fhf :::: jhffppfppdddhdhddhdhmddhpphm :::::::::::::" t[31]="**************:::: f :::: fgphpfpphddddhdddhhmdddphm :::::::::::::" t[32]="*************::::: h :: jj fhhhpfhhhdddddddhhdmdhdhph :::::::::::::" t[33]="************:::::: ffm jjjh hhhfpgphhdhdddddmdhmdddpfm :::::::::::::" t[34]="***********::::::: ffgf hhjhhh hffmffpphdddddddddmmddddhm ::::::::::::" t[35]="**********:::::::: f mhjhhmhff f pppddd ddddmdhhhhmh :::::::::::" t[36]="*********:::::::::::: mhhmhfhff j ddddmhhmmhfhh ::::::::::" t[37]="********::::::::::::::: hhmmhfff dd dhdhmpffhh :::::::::" t[38]="*******::::::::::::::: jgfffmfffffffgpppphd d dddmhmfpmm :::::::::" t[39]="******::::::::::::::: jhfmmfffffgmfffpfpphhfp ffhphhhhhm :::::::::" t[40]="*****::::::::::::::: jjhfmmffffhffffffffhmjjj g fffgphmmmh :::::::::" t[41]="****:::::::::::::::: jjjjfffmmgfpfpphpgffhhjmjh gjjjffhgpphhf :::::::::" t[42]="***::::::::::::::::: jjjjfhgmmfppfpfmgjjhhjjhhh h hhfgfpffphf :::::::::" t[43]="**::::::::::: jjjmjfggfpfppfpfghjhhhjjhhhh hhmhfpppfhh :::::::::" t[44]="*::::::::::: j jjjjjjjjjjffmhhfhhpmhhmjjhmhmhhhh mfhhhhpphhm ::::::::" t[45]="**:::::::::: jjjjjhjjjjjjjjfhgfffhmm hhhmhhhf fffppmpfhmm ::::::::" t[46]="***::::::::: jhjjjjjjjjjjjfgfffmfmm ::: mmhff ffffppdppfpm :::::::" t[47]="****:::::::: hmjjjjjjjjhfjffpppffm ::::: mmffmhfffphdddhdppmm ::::::" t[48]="*****:::::: hhjjjjjjjjhffffpphmh ::::::: mmffffhpfpdddddpdhmm ::::" t[49]="******:::: ggjgjjjjhjfjffffmphm ::::::::: mffggppphdddhhdddhmmm :" t[50]="*******::: gggjg jjjhjfhffpppfhh ::::::::::: mffhhpdddddddddhdddpmmhg :" t[51]="********:: j j jjhjjgffppfphj ::::::::::: mhfhpdpdddddmddddddpdphh :" t[52]="*********: :: jjfffppdpph ::::::::::: mfphddddddhhdddddddddphh :" t[53]="**********::::::::: jfffphpphf :::::::::::: mpdhddddddhddddddddddphg :" t[54]="***********::::::::: jhffppphf ::::::::::: mpdhddddddhdddddhddddphf " t[55]="************:::::::: fhhghhh ::::::::::: mhppddddpd ddhddddpdhhhj " t[56]="*************:::::::: fhhmhhf ::::::::::: mmpffpppppdpdddhppdphpphhf " t[57]="**************::::::: fhf :::::::::: ffhfhhhppppppfpfffhpmpfhhh :" t[58]="***************::::::: ::::::::::::: h hgggfhhhghpfhfmmhhppfmhf ::" t[59]="****************:::::::::::::::::::::::: f hmm mmhhgmhmmfgffhhhmff ::" t[60]="*****************::::::::::::::::::::::::: g fhmmhmffmfmfphhmh :*" t[61]="******************:::::::::::::::::::::::::: : mhf gf mffghmmmf ::**" t[62]="*******************:::::::::::::::::::::::::::::: m f fffhmmmf :***" t[63]="********************::::::::::::::::::::::::::::: : f f :****" t[64]="*********************::::::::::::::::::::::::::::::::::::::: :*****" t[65]="**********************::::::: :::::::::::::::::::::::::::::::::******" t[66]="***********************::::: :::::::::::::::::::::::::::::::*******" t[67]="************************:::: f ::::::::::::::::::::::::::::::********" t[68]="*************************::: f :::::::::::::::::::::::::::::*********" t[69]="**************************:: ::::::::::::::::::::::::::::**********" t[70]="***************************:: ::::::::::::::::::::::::::::***********" t[71]="****************************:::::::::::::::::::::::::::::::************" t[72]="*****************************:::::::::::::::::::::::::::::*************" t[73]="******************************:::::::::::::::::::::::::::**************" t[74]="*******************************:::::::::::::::::::::::::***************" t[75]="********************************:::::::::::::::::::::::****************" t[76]="*********************************:::::::::::::::::::::*****************" t[77]="**********************************:::::::::::::::::::******************" t[78]="***********************************:::::::::::::::::*******************" t[79]="************************************:::::::::::::::********************" t[80]="*************************************:::::::::::::*********************" t[81]="**************************************:::::::::::**********************" t[82]="***************************************:::::::::***********************" t[83]="****************************************:::::::************************" t[84]="*****************************************:::::*************************" t[85]="******************************************:::**************************" t[86]="*******************************************/***************************" t[87]="***********************************************************************" n[0]="00000000000000000000000000000000000000000000000000000000000000000000000" n[1]="00000000000000000000000000000000000000000000000000000000000000000000000" n[2]="00000000000000000000000000000000000000000000000000000000000000000000000" n[3]="00000000000000000000000000000000000000000000000000000000000000000000000" n[4]="00000000000000000000000000000000000000000000000000000000000000000000000" n[5]="00000000000000000000000000000000000000000000000000000000000000000000000" n[6]="00000000000000000000000000000000000000000000000000000000000000000000000" n[7]="00000000000000000000000000000000000000000000000000000000000000000000000" n[8]="00000000000000000000000000000000000000000000000000000000000000000000000" n[9]="00000000000000000000000000000000000000000000000000000000000000000000000" n[10]="00000000000000000000000000000000000000000000000000000000000000000000000" n[11]="00000000000000000000000000000000000000000000000000000000000000000000000" n[12]="00000000000000000000000000000000000000000000000000000000000000000000000" n[13]="00000000000000000000000000000000000000000000000000000000000000000000000" n[14]="00000000000000000000000000000000000000000000000000000000000000000000000" n[15]="00000000000000000000000000000000000000000000000000000000000000000000000" n[16]="00000000000000000000000000000000000000000000000000000000000000000000000" n[17]="00000000000000000000000000000000000000000000000000000000000000000000000" n[18]="00000000000000000000000000000000000000000000200002220000000000000000000" n[19]="00000000000000000000000000000000000000200000200002222000000000000000000" n[20]="00000000000000000000000000000000002220200000200220200000000000000000000" n[21]="00000000000000000000000000000000000020200000000022220000000000000000000" n[22]="00000000000000000000000000000000000022000000000000020000000000000000000" n[23]="00000000000000000000000000000000000002000000000000020000000000000000000" n[24]="00000000000000000000000000000000000000000000000000220000000000000000000" n[25]="00000000000000000000000000000000000000000000000000000000000000000000000" n[26]="00000000000000000000000000000000000000000000002000000000000000000000000" n[27]="00000000000000000000000000000000000000000000022220000000000000000000000" n[28]="00000000000000000000000000000000000000000000022222200000000000000000000" n[29]="00000000000000000000000000000222000000000000000002220000000000000000000" n[30]="00000000000000000000000000000020000000000000000000000000000000000000000" n[31]="00000000000000000000000000000002000000000000000000000000000000000000000" n[32]="00000000000000000000000000000000000000000000000000000002200000000000000" n[33]="00000000000000000000000000020000000000000000000000000000000000000000000" n[34]="00000000000000000000000000220002200000000000000000000000000000000000000" n[35]="00000000000000000000000000020000200000000000000000000000000000000000000" n[36]="00000000000000000000000000222000000000000000000000000000002000000000000" n[37]="00000000000000000000000022000222000000000000000000002000220000000000000" n[38]="00000000000000000000000000000000020000000000000000002000000000000000000" n[39]="00000000000000000000000220022222200222222220000000002000000000000000000" n[40]="00000000000000000000002220000022000022222000000000022200000000000000000" n[41]="00000000000000000000022000020000000020200002020000022200200000000000000" n[42]="00000000000000000000000000020000002222222222220000222222222220000000000" n[43]="00000000000000000000022222020002222220222000220200022222220200000000000" n[44]="00000000000000000000020222202000000020002200022000000000202200000000000" n[45]="00000000000000222200222220002000000000000222000000000000200000000000000" n[46]="00000000000000000200222222222200000000000000022000002000000000000000000" n[47]="00000000000000000202222000000200000000000000000000220000000000000000000" n[48]="00000000000000002200020000000200000000000000000222220000000000000000000" n[49]="00000000000000000002000000000200000000000000000200220000000000000000000" n[50]="00000000000000000002000000000200000000000000000202220000000000000000000" n[51]="00000000000000000002000020000200000000000000002222020000000000000000000" n[52]="00000000000000000000022200222200000000000000000022220000000000000000000" n[53]="00000000000000000000022200000200000000000000000002200000000000000000000" n[54]="00000000000000000000000000002200000000000000000002222000000000222222200" n[55]="00000000000000000000000000000000000000000000000002200000000000020000000" n[56]="00000000000000000000000000000000000000000000000002222000020000020000000" n[57]="00000000000000000000000000000000000000000000000222222220220000020000000" n[58]="00000000000000000000000000000000000000000000200002000020000002200000000" n[59]="00000000000000000000000000000000000000000000000000000222200000000000000" n[60]="00000000000000000000000000000000000000000000000000000000000000002200000" n[61]="00000000000000000000000000000000000000000000000000000000000000000000000" n[62]="00000000000000000000000000000000000000000000000000000000000000000000000" n[63]="00000000000000000000000000000000000000000000000000000000000000000000000" n[64]="00000000000000000000000000000000000000000000000000000000000000000000000" n[65]="00000000000000000000000000000000000000000000000000000000000000000000000" n[66]="00000000000000000000000000000000000000000000000000000000000000000000000" n[67]="00000000000000000000000000000000000000000000000000000000000000000000000" n[68]="00000000000000000000000000000000000000000000000000000000000000000000000" n[69]="00000000000000000000000000000000000000000000000000000000000000000000000" n[70]="00000000000000000000000000000000000000000000000000000000000000000000000" n[71]="00000000000000000000000000000000000000000000000000000000000000000000000" n[72]="00000000000000000000000000000000000000000000000000000000000000000000000" n[73]="00000000000000000000000000000000000000000000000000000000000000000000000" n[74]="00000000000000000000000000000000000000000000000000000000000000000000000" # Find northwest and southeast corner; remove ocean close to coase z = [] for y in range(88): z.append([]) for x in range(71): z[y].append("*") if t[y][x]=="\\": nwx = x nwy = y if t[y][x]=="/": sex = x sey = y # Convert void and slashes in to ocean; make sure all ocean # squares are not near cities z[y][x] = t[y][x] if(t[y][x] == ":" or t[y][x] == "\\" or t[y][x] == "*" or t[y][x] == "*" or t[y][x] == "/"): z[y][x] = ":" ox = x - 2 oy = y - 2 for a in range(5): for b in range(5): try: q = t[oy + a][ox + b] except: q = ":" if(q != ":" and q != "\\" and q != "*" and q != "/" and q != " "): z[y][x] = " " # Fudge factor: Put some water around the international date line (wrap point) nwx -= 4 nwy -= 4 sex += 4 sey += 4 # Some algebra to find the other corners swx = (nwx + nwy + sex - sey) if (swx & 1) != 0: print "Invalid rhombus swx is %d" % (swx) sys.exit(0) swx /= 2 swy = nwx + nwy - swx nex = sex + sey + nwx - nwy if (nex & 1) != 0: print "Invalid rhombus nex is %d" % (nex) sys.exit(0) nex /= 2 ney = sex + sey - nex # Now that we have the corners, traverse the rhombus ixl = nwx iyl = nwy oy = 0 while iyl <= swy: ix = ixl iy = iyl ox = 0 for a in range(ney - nwy): try: square = z[iy][ix] except: square = ":" # Ocean try: river = n[iy][ix] except: river = "0" # No river out[ox][oy] = cmap(square,river) ix += 1 iy += 1 ox += 1 iyl += 1 iy = iyl ix = ixl ox = 0 oy += 1 for a in range(ney - nwy): try: square = z[iy][ix] except: square = ":" # Ocean try: river = n[iy][ix] except: river = "0" # No river out[ox][oy] = cmap(square,river) ix += 1 iy += 1 ox += 1 ixl -= 1 oy += 1 sizex = ox sizey = oy showmap(out,sizex,sizey)