Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ! usr/bin/env python
- from random import randint
- # Very Basic Not-quite-literal representation:
- # M = Marsh
- # S = Swamp
- # F = Flat
- # L = Low mountain
- # P = Peak
- # H = Hill
- """
- 1 equal:
- 2-12 == Different type -> flipcoin when 0 = Lower; 1 = Higher
- 1 == Different type -> flipcoin when 0 = Lower*2; 1 = Higer*2
- 13-100 == Same type
- """
- class ClimTile(object):
- def __init__(self, pos_x, pos_y, kind):
- self.pos_x = pos_x
- self.pos_y = pos_y
- self.kind = kind
- class HeightTile(object):
- def __init__(self, pos_x, pos_y, kind):
- self.pos_x = pos_x
- self.pos_y = pos_y
- self.kind = kind
- class GeoTile(object):
- def __init__(self, pos_x, pos_y, kind):
- self.pos_x = pos_x
- self.pos_y = pos_y
- self.kind = kind
- class Map(object):
- def __init__(self):
- self.size_x = 1
- self.size_y = 1
- self.tile_list = []
- self.height_list = []
- self.clim_list = []
- def create_null_map(self):
- for collumn in range(0, self.size_y):
- a_row = []
- for row in range(0, self.size_x):
- a_row.append('x')
- self.tile_list.append(a_row)
- self.height_list.append(a_row)
- self.clim_list.append(a_row)
- def print_map(self):
- for each in self.tile_list:
- print ' '.join(each)
- def full_random(object):
- # Randomizes the Map without half a care in the world
- for collumn in range(len(object.tile_list[stufr_list[countp]])):
- for row in range(len(object.tile_list[stufc_list[countp]])):
- randtile = randint(0, 99)
- if randtile <= 4:
- randtile = 0
- elif randtile <= 50 and randtile > 4:
- randtile = 1
- elif randtile <= 84 and randtile > 50:
- randtile = 2
- elif randtile <= 94 and randtile > 84:
- randtile = 3
- else:
- randtile = 4
- land_type = str(randtile)
- object.tile_list[stufc_list[countp]][stufr_list[countp]] = land_type
- def get_tile(object, cord_x, cord_y):
- # Return a specific tile in tile_list based on x,y coords.
- try:
- return object.tile_list[cord_y][cord_x]
- except:
- return 'x'
- def random_tile():
- randtile = randint(0, 99)
- if randtile <=4:
- return str(0)
- elif randtile <= 50 and randtile > 4:
- return str(1)
- elif randtile <= 84 and randtile > 50:
- return str(2)
- elif randtile <= 94 and randtile > 84:
- return str(3)
- else:
- return str(4)
- def half_random(object):
- pass
- def procedural(object):
- print object
- countp = 0
- baba=0
- while countp <= ((RPMap.size_x * RPMap.size_x) -1):
- tendencies = []
- if stufc_list[countp] - 1 <0:
- coord_up = 'gagaga'
- else:
- coord_up = get_tile(object, stufc_list[countp] - 1, stufr_list[countp])
- if coord_up == 'x':
- stufr_list.append(stufr_list[countp])
- stufc_list.append(stufc_list[countp] - 1)
- object.tile_list[stufr_list[countp]][stufc_list[countp] -1] = 'z'
- coord_up= 'z'
- if stufc_list[countp] +1 >= size_x:
- coord_down = 'gagaga'
- else:
- coord_down = get_tile(object, stufc_list[countp] + 1, stufr_list[countp])
- if coord_down== 'x':
- stufr_list.append(stufr_list[countp])
- stufc_list.append(stufc_list[countp] + 1)
- object.tile_list[stufr_list[countp]][stufc_list[countp] + 1] = 'z'
- coord_down= 'z'
- if stufr_list[countp] -1 < 0:
- coord_down = 'gagaga'
- else:
- coord_left = get_tile(object, stufc_list[countp], stufr_list[countp] - 1)
- if coord_left== 'x':
- stufr_list.append(stufr_list[countp] -1)
- stufc_list.append(stufc_list[countp])
- object.tile_list[stufr_list[countp]-1][stufc_list[countp]] = 'z'
- coord_left= 'z'
- if stufr_list[countp] +1 >= size_x:
- coord_right = 'gagaga'
- else:
- coord_right = get_tile(object, stufc_list[countp], stufr_list[countp] + 1)
- if coord_right== 'x':
- stufr_list.append(stufr_list[countp] +1)
- stufc_list.append(stufc_list[countp])
- object.tile_list[stufr_list[countp] +1][stufc_list[countp]] = 'z'
- coord_right= 'z'
- coord_list = [coord_up, coord_down, coord_left, coord_right]
- zzz = 4
- while zzz >0:
- if coord_list[(zzz-1)] != 'z' and coord_list[(zzz-1)] != 'gagaga' and coord_list[(zzz-1)] != None:
- tendencies.append(coord_list[zzz-1])
- zzz = zzz -1
- if tendencies == []:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = random_tile()
- else:
- ovt = 1000
- if len(tendencies) == 1:
- choice_tween = int(tendencies[0])
- ovt = 100
- elif len(tendencies) == 2:
- if int(tendencies[0]) == int(tendencies[1]):
- choice_tween = int(tendencies[0])
- ovt=100
- elif int(tendencies[0]) == 0 and int(tendencies[1]) == 1:
- d100 = randint(1, 29)
- if d100 > 3:
- choice_tween = int(tendencies[1])
- ovt=0
- else:
- choice_tween = int(tendencies[0])
- ovt=0
- elif int(tendencies[0]) == 1 and int(tendencies[0]) == 0:
- d100 = randint(1, 29)
- if d100 > 3:
- choice_tween = int(tendencies[0])
- ovt=0
- else:
- choice_tween = int(tendencies[1])
- ovt=0
- elif int(tendencies[0]) == 1 and int(tendencies[1]) == 2:
- d100 = randint(1, 31)
- if d100 > 15:
- choice_tween = int(tendencies[1])
- ovt=0
- else:
- choice_tween = int(tendencies[0])
- ovt=0
- elif int(tendencies[0]) == 2 and int(tendencies[0]) == 1:
- d100 = randint(1, 31)
- if d100 > 15:
- choice_tween = int(tendencies[0])
- ovt=0
- else:
- choice_tween = int(tendencies[1])
- ovt=0
- elif int(tendencies[0]) == 2 and int(tendencies[1]) == 3:
- d100 = randint(1, 147)
- if d100 > 25:
- choice_tween = int(tendencies[1])
- ovt=0
- else:
- choice_tween = int(tendencies[0])
- ovt=0
- elif int(tendencies[0]) == 3 and int(tendencies[0]) == 2:
- d100 = randint(1, 147)
- if d100 > 25:
- choice_tween = int(tendencies[0])
- ovt=0
- else:
- choice_tween = int(tendencies[1])
- ovt=0
- elif int(tendencies[0]) == 4 and int(tendencies[1]) == 3:
- d100 = randint(1, 39)
- if d100 > 5:
- choice_tween = int(tendencies[1])
- ovt=0
- else:
- choice_tween = int(tendencies[0])
- ovt=0
- elif int(tendencies[1]) == 3 and int(tendencies[0]) == 4:
- d100 = randint(1, 39)
- if d100 > 5:
- choice_tween = int(tendencies[0])
- ovt=0
- else:
- choice_tween = int(tendencies[1])
- ovt=0
- elif int(tendencies[0]) - int(tendencies[1]) == 2:
- choice_tween = int(tendencies[0]) -1
- ovt=0
- elif int(tendencies[1]) - int(tendencies[0]) == 2:
- choice_tween = int(tendencies[1]) -1
- ovt=0
- elif int(tendencies[0]) - int(tendencies[1]) == 4:
- choice_tween = int(tendencies[0]) -2
- ovt=0
- elif int(tendencies[1]) - int(tendencies[0]) == 4:
- choice_tween = int(tendencies[1]) -2
- ovt=0
- elif int(tendencies[0]) - int(tendencies[1]) == 3:
- coin = randint(0, 1)
- if coin == 0:
- choice_tween = int(tendencies[0]) -1
- ovt=0
- else:
- choice_tween = int(tendencies[1]) +1
- ovt=0
- elif int(tendencies[0]) - int(tendencies[1]) == -3:
- coin = randint(0, 1)
- if coin == 0:
- choice_tween = int(tendencies[0]) +1
- ovt=0
- else:
- choice_tween = int(tendencies[1]) -1
- ovt=0
- else:
- choice_tween = int(tendencies[randint(0,len(tendencies) -1)])
- elif len(tendencies) == 3:
- if int(tendencies[0]) == int(tendencies[1]) and int(tendencies[0]) == int(tendencies[2]):
- choice_tween = int(tendencies[0])
- ovt=100
- else:
- ovt=1
- choice_tween = int(tendencies[randint(0,len(tendencies) -1)])
- else:
- ovt=1
- choice_tween = int(tendencies[randint(0,len(tendencies) -1)])
- dominant = choice_tween
- d100 = randint(1, 1000)
- coin = randint(0, 1)
- do1 = randint(1, 39)
- do2 = randint(1, 28)
- do3 = randint(1, 39)
- #print tendencies, 'index', choice_tween, 'resulting', dominant, 'rolling', d100, 'side', coin
- if d100 > ovt:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant)
- else:
- if dominant == 0:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
- elif dominant == 4:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)
- elif dominant == 1:
- if do1 <= 5:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
- else:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)
- elif dominant == 3:
- if do2 <= 5:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
- else:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)
- elif dominant == 2:
- if do3 <= 5:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
- else:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)
- else:
- if coin == 0:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
- else:
- object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)
- countp += 1
- #print coord_list, tendencies, 'in>', row, collumn
- def make_purty(object):
- for row in range(len(object.tile_list)):
- # in each of the rows
- for collumn in range(len(object.tile_list[row])):
- # in each of the collumns of the given row
- if object.tile_list[row][collumn] == '0':
- g1 = randint(0, 99)
- if g1 <= 40:
- object.tile_list[row][collumn] = 'S'
- else:
- object.tile_list[row][collumn] = 'M'
- elif object.tile_list[row][collumn] == '1':
- object.tile_list[row][collumn] = 'F'
- elif object.tile_list[row][collumn] == '2':
- object.tile_list[row][collumn] = 'H'
- elif object.tile_list[row][collumn] == '3':
- object.tile_list[row][collumn] = 'L'
- elif object.tile_list[row][collumn] == '4':
- object.tile_list[row][collumn] = 'P'
- def soothe(object):
- pass
- def math_adjust(object, amt, param):
- ammount = int(amt)
- for row in range(len(object.tile_list)):
- # in each of the rows
- for collumn in range(len(object.tile_list[row])):
- if param == 'add':
- object.tile_list[row][collumn] = str(int(object.tile_list[row][collumn]) + ammount)
- else:
- object.tile_list[row][collumn] = str(int(object.tile_list[row][collumn]) - ammount)
- def adjust(object, cord_x, cord_y, tile):
- pass
- def take_virginity(object, tile):
- # Cerimonial Function
- object.tile_list[0][0] = tile
- RPMap = Map()
- #take_virginity(RPMap, '1')
- #RPMap.print_map()
- #
- ## Please forgive my mess and desorganization, pretty please?
- ###
- print "The ideal size in Notebook, for me, is 51x51. Only square maps with odd size x and y, at least for now, sorry. Each square is suposed to be 60.554 square km. Map with earth area is almost 2903*2903"
- size_x = int(raw_input('X and Y axis size for map> '))
- if int(size_x) % 2 == 0:
- RPMap.size_x = int(size_x) + 1
- RPMap.size_y = int(size_x) + 1
- else:
- RPMap.size_x = int(size_x)
- RPMap.size_y = int(size_x)
- RPMap.create_null_map()
- countp = 0
- stufr_list =[]
- stufc_list =[]
- stufr_list.append((int(size_x) -1) /2 )
- stufc_list.append((int(size_x) -1) /2 )
- while True:
- print "-[randomize] creates a entirely random map."
- print "-[procedural] is a self important name for a command that does what"
- print "anon suggested, using d100 rolls"
- print "-[adjust] prompts you for an INTEGER first, then asking for whether"
- print " you wish to [add] a number or else. This adjustment are then going"
- print " to be applied to the whole map"
- print "-[print] lets you look at the current mess"
- print "-[purty] exchanges the numbers for their letter-equivalents. Keep in mind"
- print " that I'm sleepdrunk and not an ASCII artist by any means, so it can be"
- print " made a LOT better. Also, keep in mind that after purtyfying, no other"
- print " functions will work."
- print "-[quick] does a fast batch of procedural generation, correcting, purtyfying"
- print " and dumping to file (mapdata.txt)"
- print "-[readj] lets you readjust the X and Y of the map"
- print "-[dump] just writes whatever you current map is to file"
- print " *your mileage may vary. Like, a lot."
- inpt = raw_input('> ')
- if inpt == 'randomize':
- full_random(RPMap)
- RPMap.print_map()
- print ''
- elif inpt == 'procedural':
- procedural(RPMap)
- RPMap.print_map()
- print ''
- elif inpt == 'adjust':
- amt = raw_input('How much> ')
- pram = raw_input('[add] or Else> ')
- math_adjust(RPMap, amt, pram)
- RPMap.print_map()
- print ''
- elif inpt == 'print':
- RPMap.print_map()
- print ''
- elif inpt == 'purty':
- make_purty(RPMap)
- RPMap.print_map()
- print ''
- elif inpt == 'quick':
- procedural(RPMap)
- make_purty(RPMap)
- RPMap.print_map()
- mapdata = open("mapdata.txt", 'w')
- for dataline in RPMap.tile_list:
- linewrite = ''.join(dataline)
- linewrite += '\n'
- mapdata.write(linewrite)
- mapdata.close()
- elif inpt == 'readj':
- size_x = int(raw_input('X axis size for map> '))
- size_y = int(raw_input('Y axis size for map> '))
- RPMap.size_x = size_x
- RPMap.size_y = size_y
- RPMap.create_null_map()
- elif inpt == 'dump':
- mapdata = open("mapdata.txt", 'w')
- for dataline in RPMap.tile_list:
- linewrite = ' '.join(dataline)
- linewrite += '\n'
- mapdata.write(linewrite)
- mapdata.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement