Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.78 KB | None | 0 0
  1. # ! usr/bin/env python
  2.  
  3. from random import randint
  4.  
  5. # Very Basic Not-quite-literal representation:
  6. #  M = Marsh
  7. # S = Swamp
  8. # F = Flat
  9. # L = Low mountain
  10. # P = Peak
  11. # H = Hill
  12.  
  13.  
  14. """
  15. 1 equal:
  16.  
  17. 2-12 == Different type -> flipcoin when 0 = Lower; 1 = Higher
  18.  
  19. 1 == Different type -> flipcoin when 0 = Lower*2; 1 = Higer*2
  20.  
  21. 13-100 == Same type
  22. """
  23.  
  24. class ClimTile(object):
  25.  
  26.     def __init__(self, pos_x, pos_y, kind):
  27.  
  28.         self.pos_x = pos_x
  29.         self.pos_y = pos_y
  30.         self.kind = kind
  31.  
  32. class HeightTile(object):
  33.  
  34.     def __init__(self, pos_x, pos_y, kind):
  35.  
  36.         self.pos_x = pos_x
  37.         self.pos_y = pos_y
  38.         self.kind = kind
  39.  
  40. class GeoTile(object):
  41.  
  42.     def __init__(self, pos_x, pos_y, kind):
  43.  
  44.         self.pos_x = pos_x
  45.         self.pos_y = pos_y
  46.         self.kind = kind
  47.  
  48. class Map(object):
  49.  
  50.     def __init__(self):
  51.  
  52.         self.size_x = 1
  53.         self.size_y = 1
  54.        
  55.         self.tile_list = []
  56.         self.height_list = []
  57.         self.clim_list = []
  58.  
  59.     def create_null_map(self):
  60.    
  61.         for collumn in range(0, self.size_y):
  62.            
  63.             a_row = []
  64.            
  65.             for row in range(0, self.size_x):
  66.                
  67.                 a_row.append('x')
  68.                
  69.             self.tile_list.append(a_row)
  70.             self.height_list.append(a_row)
  71.             self.clim_list.append(a_row)
  72.  
  73.     def print_map(self):
  74.    
  75.         for each in self.tile_list:
  76.        
  77.             print ' '.join(each)
  78.  
  79. def full_random(object):
  80.     # Randomizes the Map without half a care in the world
  81.    
  82.     for collumn in range(len(object.tile_list)):
  83.  
  84.         for row in range(len(object.tile_list[collumn])):
  85.             randtile = randint(0, 99)
  86.    
  87.             if  randtile <= 4:
  88.             randtile = 0
  89.             elif randtile <= 50 and randtile > 4:
  90.             randtile = 1
  91.             elif randtile <= 84 and randtile > 50:
  92.             randtile = 2
  93.             elif randtile <= 94 and randtile > 84:
  94.             randtile = 3
  95.             else:
  96.             randtile = 4
  97.  
  98.             land_type = str(randtile)
  99.            
  100.             object.tile_list[collumn][row] = land_type
  101.  
  102. def get_tile(object, cord_x, cord_y):
  103.     # Return a specific tile in tile_list based on x,y coords.
  104.  
  105.     try:
  106.  
  107.         return object.tile_list[cord_y][cord_x]
  108.        
  109.     except:
  110.  
  111.         return 'x'
  112. def random_tile():
  113.     randtile = randint(0, 99)
  114.    
  115.     if  randtile <=4:
  116.  
  117.         return str(0)
  118.  
  119.     elif randtile <= 50 and randtile > 4:
  120.     return str(1)
  121.     elif randtile <= 84 and randtile > 50:
  122.     return str(2)
  123.     elif randtile <= 94 and randtile > 84:
  124.     return str(3)
  125.     else:
  126.  
  127.         return str(4)              
  128.    
  129. def half_random(object):
  130.     pass
  131.            
  132. def procedural(object):
  133.  
  134.     print object
  135.    
  136.    
  137.        
  138.     for row in range(len(object.tile_list)):
  139.     # in each of the rows
  140.          
  141.         for collumn in range(len(object.tile_list[row])):
  142.             coord_up = get_tile(object, collumn - 1, row)
  143.             coord_down = get_tile(object, collumn + 1, row)
  144.             coord_left = get_tile(object, collumn, row - 1)
  145.             coord_right = get_tile(object, collumn, row + 1)
  146.            
  147.             coord_list = [coord_up, coord_down, coord_left, coord_right]
  148.             tendencies = []
  149.  
  150.             for each in coord_list:
  151.  
  152.                 if each != 'x':
  153.    
  154.                     tendencies.append(each)
  155.  
  156.             if tendencies == []:
  157.  
  158.                 object.tile_list[row][collumn] = random_tile()
  159.  
  160.             else:
  161.                 ovt = 1000
  162.                 if len(tendencies) == 1:
  163.                     choice_tween = int(tendencies[0])
  164.                 elif len(tendencies) == 2:
  165.                     if int(tendencies[0]) == int(tendencies[1]):
  166.                         choice_tween = int(tendencies[0])
  167.                         ovt=100
  168.                     elif int(tendencies[0]) == 0 and int(tendencies[1]) == 1:
  169.                 d100 = randint(1, 29)
  170.                 if d100 > 3:
  171.                                 choice_tween = int(tendencies[1])
  172.                             ovt=0
  173.                             else:
  174.                                 choice_tween = int(tendencies[0])
  175.                             ovt=0
  176.                     elif int(tendencies[0]) == 1 and int(tendencies[0]) == 0:
  177.                 d100 = randint(1, 29)
  178.                 if d100 > 3:
  179.                                 choice_tween = int(tendencies[0])
  180.                             ovt=0
  181.                             else:
  182.                                 choice_tween = int(tendencies[1])
  183.                             ovt=0
  184.                     elif int(tendencies[0]) == 1 and int(tendencies[1]) == 2:
  185.                 d100 = randint(1, 31)
  186.                 if d100 > 15:
  187.                                 choice_tween = int(tendencies[1])
  188.                             ovt=0
  189.                             else:
  190.                                 choice_tween = int(tendencies[0])
  191.                             ovt=0
  192.                     elif int(tendencies[0]) == 2 and int(tendencies[0]) == 1:
  193.                 d100 = randint(1, 31)
  194.                 if d100 > 15:
  195.                                 choice_tween = int(tendencies[0])
  196.                             ovt=0
  197.                             else:
  198.                                 choice_tween = int(tendencies[1])
  199.                             ovt=0
  200.                     elif int(tendencies[0]) == 2 and int(tendencies[1]) == 3:
  201.                 d100 = randint(1, 147)
  202.                 if d100 > 25:
  203.                                 choice_tween = int(tendencies[1])
  204.                             ovt=0
  205.                             else:
  206.                                 choice_tween = int(tendencies[0])
  207.                             ovt=0
  208.                     elif int(tendencies[0]) == 3 and int(tendencies[0]) == 2:
  209.                 d100 = randint(1, 147)
  210.                 if d100 > 25:
  211.                                 choice_tween = int(tendencies[0])
  212.                             ovt=0
  213.                             else:
  214.                                 choice_tween = int(tendencies[1])
  215.                             ovt=0
  216.                     elif int(tendencies[0]) == 4 and int(tendencies[1]) == 3:
  217.                 d100 = randint(1, 39)
  218.                 if d100 > 5:
  219.                                 choice_tween = int(tendencies[1])
  220.                             ovt=0
  221.                             else:
  222.                                 choice_tween = int(tendencies[0])
  223.                             ovt=0
  224.                     elif int(tendencies[1]) == 3 and int(tendencies[0]) == 4:
  225.                 d100 = randint(1, 39)
  226.                 if d100 > 5:
  227.                                 choice_tween = int(tendencies[0])
  228.                             ovt=0
  229.                             else:
  230.                                 choice_tween = int(tendencies[1])
  231.                             ovt=0
  232.                     elif int(tendencies[0]) - int(tendencies[1]) == 2:
  233.                         choice_tween = int(tendencies[0])  -1
  234.                         ovt=0
  235.                     elif int(tendencies[1]) - int(tendencies[0]) == 2:
  236.                         choice_tween = int(tendencies[1]) -1
  237.                         ovt=0
  238.                     elif int(tendencies[0]) - int(tendencies[1]) == 4:
  239.                         choice_tween = int(tendencies[0]) -2
  240.                         ovt=0
  241.                     elif int(tendencies[1]) - int(tendencies[0]) == 4:
  242.                         choice_tween = int(tendencies[1]) -2
  243.                         ovt=0
  244.                     elif int(tendencies[0]) - int(tendencies[1]) == 3:
  245.                 coin = randint(0, 1)
  246.                 if coin == 0:
  247.                                 choice_tween = int(tendencies[0]) -1
  248.                             ovt=0
  249.                             else:
  250.                                 choice_tween = int(tendencies[1]) +1
  251.                             ovt=0
  252.                     elif int(tendencies[0]) - int(tendencies[1]) == -3:
  253.                 coin = randint(0, 1)
  254.                 if coin == 0:
  255.                                 choice_tween = int(tendencies[0]) +1
  256.                             ovt=0
  257.                             else:
  258.                                 choice_tween = int(tendencies[1]) -1
  259.                             ovt=0
  260.             else:
  261.                             choice_tween = int(tendencies[randint(0,len(tendencies) -1)])
  262.         elif len(tendencies) == 3:
  263.                     if int(tendencies[0]) == int(tendencies[1]) and int(tendencies[0]) == int(tendencies[2]):
  264.                         choice_tween = int(tendencies[0])
  265.                         ovt=100
  266.             else:
  267.                 ovt=1
  268.                 choice_tween = int(tendencies[randint(0,len(tendencies) -1)])
  269.                 else:
  270.             ovt=1
  271.                     choice_tween = int(tendencies[randint(0,len(tendencies) -1)])
  272.                 dominant = choice_tween
  273.                
  274.  
  275.                 d100 = randint(1, 1000)
  276.                 coin = randint(0, 1)
  277.         do1 = randint(1, 39)
  278.         do2 = randint(1, 28)
  279.         do3 = randint(1, 39)
  280.  
  281.                 #print tendencies, 'index', choice_tween, 'resulting', dominant, 'rolling', d100, 'side', coin
  282.  
  283.                 if d100 > ovt:
  284.  
  285.                     object.tile_list[row][collumn] = str(dominant)
  286.                    
  287.                 else:
  288.  
  289.             if dominant == 0:
  290.                 object.tile_list[row][collumn] = str(dominant + 1)
  291.             elif dominant == 4:
  292.                 object.tile_list[row][collumn] = str(dominant - 1)
  293.             elif dominant == 1:
  294.                 if do1 <= 5:
  295.  
  296.                     object.tile_list[row][collumn] = str(dominant + 1)
  297.  
  298.                 else:
  299.  
  300.                     object.tile_list[row][collumn] = str(dominant - 1)
  301.             elif dominant == 3:
  302.                 if do2 <= 5:
  303.  
  304.                     object.tile_list[row][collumn] = str(dominant + 1)
  305.  
  306.                 else:
  307.  
  308.                     object.tile_list[row][collumn] = str(dominant - 1)
  309.             elif dominant == 2:
  310.                 if do3 <= 5:
  311.  
  312.                     object.tile_list[row][collumn] = str(dominant + 1)
  313.  
  314.                 else:
  315.  
  316.                     object.tile_list[row][collumn] = str(dominant - 1)
  317.             else:
  318.                 if coin == 0:
  319.  
  320.                     object.tile_list[row][collumn] = str(dominant + 1)
  321.  
  322.                 else:
  323.  
  324.                     object.tile_list[row][collumn] = str(dominant - 1)            
  325.  
  326.             #print coord_list, tendencies, 'in>', row, collumn
  327.  
  328. def correct(object):
  329.  
  330.     for row in range(len(object.tile_list)):
  331.     # in each of the rows
  332.  
  333.         for collumn in range(len(object.tile_list[row])):
  334.         # in each of the collumns of the given row
  335.  
  336.             if int(object.tile_list[row][collumn]) < 0:
  337.  
  338.                 object.tile_list[row][collumn] = '0'
  339.  
  340.             elif int(object.tile_list[row][collumn]) > 4:
  341.  
  342.                 object.tile_list[row][collumn] = '4'
  343.  
  344. def make_purty(object):
  345.  
  346.     for row in range(len(object.tile_list)):
  347.     # in each of the rows
  348.  
  349.         for collumn in range(len(object.tile_list[row])):
  350.         # in each of the collumns of the given row
  351.             if object.tile_list[row][collumn] == '0':
  352.             g1 = randint(0, 99)
  353.         if g1 <= 40:
  354.                     object.tile_list[row][collumn] = 'S'
  355.         else:
  356.             object.tile_list[row][collumn] = 'M'
  357.             elif object.tile_list[row][collumn] == '1':
  358.  
  359.                 object.tile_list[row][collumn] = 'F'
  360.  
  361.             elif object.tile_list[row][collumn] == '2':
  362.  
  363.                 object.tile_list[row][collumn] = 'H'
  364.  
  365.             elif object.tile_list[row][collumn] == '3':
  366.  
  367.                 object.tile_list[row][collumn] = 'L'
  368.  
  369.             elif object.tile_list[row][collumn] == '4':
  370.  
  371.                 object.tile_list[row][collumn] = 'P'
  372.                  
  373.                                          
  374. def soothe(object):
  375.     pass
  376.  
  377. def math_adjust(object, amt, param):
  378.  
  379.     ammount = int(amt)
  380.  
  381.     for row in range(len(object.tile_list)):
  382.     # in each of the rows
  383.  
  384.         for collumn in range(len(object.tile_list[row])):
  385.  
  386.             if param == 'add':
  387.  
  388.                 object.tile_list[row][collumn] = str(int(object.tile_list[row][collumn]) + ammount)
  389.                
  390.             else:
  391.  
  392.                 object.tile_list[row][collumn] = str(int(object.tile_list[row][collumn]) - ammount)            
  393.  
  394.  
  395. def adjust(object, cord_x, cord_y, tile):
  396.     pass
  397.  
  398. def take_virginity(object, tile):
  399.     # Cerimonial Function
  400.    
  401.     object.tile_list[0][0] = tile
  402.                    
  403. RPMap = Map()
  404.  
  405.  
  406. #take_virginity(RPMap, '1')
  407. #RPMap.print_map()
  408.  
  409. #
  410. ## Please forgive my mess and desorganization, pretty please?
  411. ###
  412.  
  413. print "The ideal size in Notebook, for me, is 51x51. Only square maps with odd size x and y, at least for now, sorry."
  414. size_x = int(raw_input('X and Y axis size for map> '))
  415.  
  416. if int(size_x) % 2 == 0:
  417.     RPMap.size_x = int(size_x) + 1
  418.     RPMap.size_y = int(size_x) + 1
  419. else:
  420.     RPMap.size_x = int(size_x)
  421.     RPMap.size_y = int(size_x)
  422. RPMap.create_null_map()
  423.    
  424. while True:
  425.  
  426.     print "-[randomize] creates a entirely random map."
  427.     print "-[procedural] is a self important name for a command that does what"
  428.     print "anon suggested, using d100 rolls"
  429.     print "-[adjust] prompts you for an INTEGER first, then asking for whether"
  430.     print "    you wish to [add] a number or else. This adjustment are then going"
  431.     print "    to be applied to the whole map"
  432.     print "-[print] lets you look at the current mess"
  433.     print "-[purty] exchanges the numbers for their letter-equivalents. Keep in mind"
  434.     print "    that I'm sleepdrunk and not an ASCII artist by any means, so it can be"
  435.     print "    made a LOT better. Also, keep in mind that after purtyfying, no other"
  436.     print "    functions will work."
  437.     print "-[quick] does a fast batch of procedural generation, correcting, purtyfying"
  438.     print "    and dumping to file (mapdata.txt)"
  439.     print "-[readj] lets you readjust the X and Y of the map"
  440.     print "-[dump] just writes whatever you current map is to file"
  441.     print "        *your mileage may vary. Like, a lot."
  442.     inpt = raw_input('> ')
  443.  
  444.     if inpt == 'randomize':
  445.  
  446.         full_random(RPMap)
  447.         RPMap.print_map()
  448.         print ''
  449.  
  450.     elif inpt == 'procedural':
  451.  
  452.         procedural(RPMap)
  453.         RPMap.print_map()
  454.         print ''
  455.  
  456.     elif inpt == 'adjust':
  457.  
  458.         amt = raw_input('How much> ')
  459.         pram = raw_input('[add] or Else> ')
  460.  
  461.         math_adjust(RPMap, amt, pram)
  462.         RPMap.print_map()
  463.         print ''
  464.  
  465.     elif inpt == 'print':
  466.  
  467.         RPMap.print_map()
  468.         print ''
  469.  
  470.     elif inpt == 'correct':
  471.  
  472.         correct(RPMap)
  473.         RPMap.print_map()
  474.         print ''
  475.  
  476.     elif inpt == 'purty':
  477.  
  478.         make_purty(RPMap)
  479.         RPMap.print_map()
  480.         print ''
  481.  
  482.     elif inpt == 'quick':
  483.         procedural(RPMap)
  484.         correct(RPMap)
  485.         make_purty(RPMap)
  486.         RPMap.print_map()
  487.         mapdata = open("mapdata.txt", 'w')
  488.  
  489.         for dataline in RPMap.tile_list:
  490.  
  491.             linewrite = ''.join(dataline)
  492.             linewrite += '\n'
  493.            
  494.             mapdata.write(linewrite)
  495.  
  496.         mapdata.close()
  497.        
  498.     elif inpt == 'readj':
  499.  
  500.         size_x = int(raw_input('X axis size for map> '))
  501.         size_y = int(raw_input('Y axis size for map> '))
  502.  
  503.         RPMap.size_x = size_x
  504.         RPMap.size_y = size_y
  505.         RPMap.create_null_map()
  506.    
  507.     elif inpt == 'dump':
  508.  
  509.         mapdata = open("mapdata.txt", 'w')
  510.  
  511.         for dataline in RPMap.tile_list:
  512.  
  513.             linewrite = ' '.join(dataline)
  514.             linewrite += '\n'
  515.            
  516.             mapdata.write(linewrite)
  517.  
  518.         mapdata.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement