Advertisement
Guest User

Untitled

a guest
Jul 25th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 15.86 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[stufr_list[countp]])):
  83.  
  84.         for row in range(len(object.tile_list[stufc_list[countp]])):
  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[stufc_list[countp]][stufr_list[countp]] = 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.     countp = 0
  136.     baba=0
  137.     while countp <= ((RPMap.size_x  * RPMap.size_x) -1):
  138.     tendencies = []
  139.     if stufc_list[countp] - 1 <0:
  140.         coord_up = 'gagaga'
  141.     else:
  142.             coord_up = get_tile(object, stufc_list[countp] - 1, stufr_list[countp])
  143.         if coord_up == 'x':
  144.             stufr_list.append(stufr_list[countp])
  145.             stufc_list.append(stufc_list[countp] - 1)
  146.             object.tile_list[stufr_list[countp]][stufc_list[countp] -1] = 'z'
  147.             coord_up= 'z'
  148.     if stufc_list[countp] +1 >= size_x:
  149.         coord_down = 'gagaga'
  150.     else:
  151.        
  152.             coord_down = get_tile(object, stufc_list[countp] + 1, stufr_list[countp])
  153.         if coord_down== 'x':
  154.             stufr_list.append(stufr_list[countp])
  155.             stufc_list.append(stufc_list[countp] + 1)
  156.             object.tile_list[stufr_list[countp]][stufc_list[countp] + 1] = 'z'
  157.             coord_down= 'z'
  158.     if stufr_list[countp] -1 < 0:
  159.         coord_down = 'gagaga'
  160.     else:
  161.             coord_left = get_tile(object, stufc_list[countp], stufr_list[countp] - 1)
  162.         if coord_left== 'x':
  163.             stufr_list.append(stufr_list[countp] -1)
  164.             stufc_list.append(stufc_list[countp])
  165.             object.tile_list[stufr_list[countp]-1][stufc_list[countp]] = 'z'
  166.             coord_left= 'z'
  167.     if stufr_list[countp] +1 >= size_x:
  168.         coord_right = 'gagaga'
  169.     else:
  170.             coord_right = get_tile(object, stufc_list[countp], stufr_list[countp] + 1)
  171.         if coord_right== 'x':
  172.             stufr_list.append(stufr_list[countp] +1)
  173.             stufc_list.append(stufc_list[countp])
  174.             object.tile_list[stufr_list[countp] +1][stufc_list[countp]] = 'z'
  175.             coord_right= 'z'
  176.     coord_list = [coord_up, coord_down, coord_left, coord_right]
  177.     zzz = 4
  178.         while zzz >0:
  179.         if coord_list[(zzz-1)] != 'z' and coord_list[(zzz-1)] != 'gagaga' and  coord_list[(zzz-1)] != None:
  180.             tendencies.append(coord_list[zzz-1])
  181.         zzz = zzz -1
  182.         if tendencies == []:
  183.         object.tile_list[stufr_list[countp]][stufc_list[countp]] = random_tile()
  184.        
  185.     else:
  186.             ovt = 1000
  187.             if len(tendencies) == 1:
  188.                 choice_tween = int(tendencies[0])
  189.                 ovt = 100
  190.             elif len(tendencies) == 2:
  191.                 if int(tendencies[0]) == int(tendencies[1]):
  192.                     choice_tween = int(tendencies[0])
  193.                         ovt=100
  194.                     elif int(tendencies[0]) == 0 and int(tendencies[1]) == 1:
  195.                 d100 = randint(1, 29)
  196.                 if d100 > 3:
  197.                                 choice_tween = int(tendencies[1])
  198.                             ovt=0
  199.                         else:
  200.                                 choice_tween = int(tendencies[0])
  201.                             ovt=0
  202.                     elif int(tendencies[0]) == 1 and int(tendencies[0]) == 0:
  203.                 d100 = randint(1, 29)
  204.                 if d100 > 3:
  205.                                 choice_tween = int(tendencies[0])
  206.                             ovt=0
  207.                         else:
  208.                                 choice_tween = int(tendencies[1])
  209.                             ovt=0
  210.                     elif int(tendencies[0]) == 1 and int(tendencies[1]) == 2:
  211.                 d100 = randint(1, 31)
  212.                 if d100 > 15:
  213.                                 choice_tween = int(tendencies[1])
  214.                             ovt=0
  215.                         else:
  216.                                 choice_tween = int(tendencies[0])
  217.                             ovt=0
  218.                     elif int(tendencies[0]) == 2 and int(tendencies[0]) == 1:
  219.                 d100 = randint(1, 31)
  220.                 if d100 > 15:
  221.                                 choice_tween = int(tendencies[0])
  222.                             ovt=0
  223.                             else:
  224.                                 choice_tween = int(tendencies[1])
  225.                             ovt=0
  226.                     elif int(tendencies[0]) == 2 and int(tendencies[1]) == 3:
  227.                 d100 = randint(1, 147)
  228.                 if d100 > 25:
  229.                                 choice_tween = int(tendencies[1])
  230.                             ovt=0
  231.                             else:
  232.                                 choice_tween = int(tendencies[0])
  233.                             ovt=0
  234.                     elif int(tendencies[0]) == 3 and int(tendencies[0]) == 2:
  235.                 d100 = randint(1, 147)
  236.                 if d100 > 25:
  237.                                 choice_tween = int(tendencies[0])
  238.                             ovt=0
  239.                             else:
  240.                                 choice_tween = int(tendencies[1])
  241.                             ovt=0
  242.                     elif int(tendencies[0]) == 4 and int(tendencies[1]) == 3:
  243.                 d100 = randint(1, 39)
  244.                 if d100 > 5:
  245.                                 choice_tween = int(tendencies[1])
  246.                             ovt=0
  247.                             else:
  248.                                 choice_tween = int(tendencies[0])
  249.                             ovt=0
  250.                     elif int(tendencies[1]) == 3 and int(tendencies[0]) == 4:
  251.                 d100 = randint(1, 39)
  252.                 if d100 > 5:
  253.                                 choice_tween = int(tendencies[0])
  254.                             ovt=0
  255.                             else:
  256.                                 choice_tween = int(tendencies[1])
  257.                             ovt=0
  258.                     elif int(tendencies[0]) - int(tendencies[1]) == 2:
  259.                         choice_tween = int(tendencies[0])  -1
  260.                         ovt=0
  261.                     elif int(tendencies[1]) - int(tendencies[0]) == 2:
  262.                         choice_tween = int(tendencies[1]) -1
  263.                         ovt=0
  264.                     elif int(tendencies[0]) - int(tendencies[1]) == 4:
  265.                         choice_tween = int(tendencies[0]) -2
  266.                         ovt=0
  267.                     elif int(tendencies[1]) - int(tendencies[0]) == 4:
  268.                         choice_tween = int(tendencies[1]) -2
  269.                         ovt=0
  270.                     elif int(tendencies[0]) - int(tendencies[1]) == 3:
  271.                 coin = randint(0, 1)
  272.                 if coin == 0:
  273.                                 choice_tween = int(tendencies[0]) -1
  274.                             ovt=0
  275.                         else:
  276.                                 choice_tween = int(tendencies[1]) +1
  277.                             ovt=0
  278.                     elif int(tendencies[0]) - int(tendencies[1]) == -3:
  279.                 coin = randint(0, 1)
  280.                 if coin == 0:
  281.                                 choice_tween = int(tendencies[0]) +1
  282.                             ovt=0
  283.                             else:
  284.                                 choice_tween = int(tendencies[1]) -1
  285.                             ovt=0
  286.             else:
  287.                             choice_tween = int(tendencies[randint(0,len(tendencies) -1)])
  288.         elif len(tendencies) == 3:
  289.                     if int(tendencies[0]) == int(tendencies[1]) and int(tendencies[0]) == int(tendencies[2]):
  290.                         choice_tween = int(tendencies[0])
  291.                         ovt=100
  292.             else:
  293.                 ovt=1
  294.                 choice_tween = int(tendencies[randint(0,len(tendencies) -1)])
  295.         else:
  296.             ovt=1
  297.                     choice_tween = int(tendencies[randint(0,len(tendencies) -1)])
  298.             dominant = choice_tween
  299.                    
  300.  
  301.             d100 = randint(1, 1000)
  302.             coin = randint(0, 1)
  303.             do1 = randint(1, 39)
  304.             do2 = randint(1, 28)
  305.             do3 = randint(1, 39)
  306.             #print tendencies, 'index', choice_tween, 'resulting', dominant, 'rolling', d100, 'side', coin
  307.    
  308.             if d100 > ovt:
  309.                 object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant)
  310.                        
  311.             else:
  312.                 if dominant == 0:
  313.                     object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
  314.                 elif dominant == 4:
  315.                     object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)
  316.                 elif dominant == 1:
  317.                     if do1 <= 5:
  318.                         object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
  319.    
  320.                     else:
  321.                         object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)
  322.  
  323.                 elif dominant == 3:
  324.                     if do2 <= 5:
  325.                         object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
  326.  
  327.                     else:
  328.  
  329.                         object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)
  330.                 elif dominant == 2:
  331.                     if do3 <= 5:
  332.  
  333.                         object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
  334.    
  335.                     else:
  336.  
  337.                         object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)
  338.                 else:
  339.                     if coin == 0:
  340.  
  341.                         object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant + 1)
  342.  
  343.                     else:
  344.  
  345.                         object.tile_list[stufr_list[countp]][stufc_list[countp]] = str(dominant - 1)          
  346.    
  347.     countp += 1
  348.         #print coord_list, tendencies, 'in>', row, collumn
  349.            
  350.  
  351.  
  352.  
  353. def make_purty(object):
  354.  
  355.     for row in range(len(object.tile_list)):
  356.     # in each of the rows
  357.  
  358.         for collumn in range(len(object.tile_list[row])):
  359.         # in each of the collumns of the given row
  360.             if object.tile_list[row][collumn] == '0':
  361.             g1 = randint(0, 99)
  362.         if g1 <= 40:
  363.                     object.tile_list[row][collumn] = 'S'
  364.         else:
  365.             object.tile_list[row][collumn] = 'M'
  366.             elif object.tile_list[row][collumn] == '1':
  367.  
  368.                 object.tile_list[row][collumn] = 'F'
  369.  
  370.             elif object.tile_list[row][collumn] == '2':
  371.  
  372.                 object.tile_list[row][collumn] = 'H'
  373.  
  374.             elif object.tile_list[row][collumn] == '3':
  375.  
  376.                 object.tile_list[row][collumn] = 'L'
  377.  
  378.             elif object.tile_list[row][collumn] == '4':
  379.  
  380.                 object.tile_list[row][collumn] = 'P'
  381.                  
  382.                                          
  383. def soothe(object):
  384.     pass
  385.  
  386. def math_adjust(object, amt, param):
  387.  
  388.     ammount = int(amt)
  389.  
  390.     for row in range(len(object.tile_list)):
  391.     # in each of the rows
  392.  
  393.         for collumn in range(len(object.tile_list[row])):
  394.  
  395.             if param == 'add':
  396.  
  397.                 object.tile_list[row][collumn] = str(int(object.tile_list[row][collumn]) + ammount)
  398.                
  399.             else:
  400.  
  401.                 object.tile_list[row][collumn] = str(int(object.tile_list[row][collumn]) - ammount)            
  402.  
  403.  
  404. def adjust(object, cord_x, cord_y, tile):
  405.     pass
  406.  
  407. def take_virginity(object, tile):
  408.     # Cerimonial Function
  409.    
  410.     object.tile_list[0][0] = tile
  411.                    
  412. RPMap = Map()
  413.  
  414.  
  415. #take_virginity(RPMap, '1')
  416. #RPMap.print_map()
  417.  
  418. #
  419. ## Please forgive my mess and desorganization, pretty please?
  420. ###
  421.  
  422. 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"
  423. size_x = int(raw_input('X and Y axis size for map> '))
  424.  
  425. if int(size_x) % 2 == 0:
  426.     RPMap.size_x = int(size_x) + 1
  427.     RPMap.size_y = int(size_x) + 1
  428. else:
  429.     RPMap.size_x = int(size_x)
  430.     RPMap.size_y = int(size_x)
  431. RPMap.create_null_map()
  432. countp = 0
  433. stufr_list =[]
  434. stufc_list =[]
  435. stufr_list.append((int(size_x) -1) /2 )
  436. stufc_list.append((int(size_x) -1) /2 )
  437. while True:
  438.  
  439.     print "-[randomize] creates a entirely random map."
  440.     print "-[procedural] is a self important name for a command that does what"
  441.     print "anon suggested, using d100 rolls"
  442.     print "-[adjust] prompts you for an INTEGER first, then asking for whether"
  443.     print "    you wish to [add] a number or else. This adjustment are then going"
  444.     print "    to be applied to the whole map"
  445.     print "-[print] lets you look at the current mess"
  446.     print "-[purty] exchanges the numbers for their letter-equivalents. Keep in mind"
  447.     print "    that I'm sleepdrunk and not an ASCII artist by any means, so it can be"
  448.     print "    made a LOT better. Also, keep in mind that after purtyfying, no other"
  449.     print "    functions will work."
  450.     print "-[quick] does a fast batch of procedural generation, correcting, purtyfying"
  451.     print "    and dumping to file (mapdata.txt)"
  452.     print "-[readj] lets you readjust the X and Y of the map"
  453.     print "-[dump] just writes whatever you current map is to file"
  454.     print "        *your mileage may vary. Like, a lot."
  455.     inpt = raw_input('> ')
  456.  
  457.     if inpt == 'randomize':
  458.  
  459.         full_random(RPMap)
  460.         RPMap.print_map()
  461.         print ''
  462.  
  463.     elif inpt == 'procedural':
  464.  
  465.         procedural(RPMap)
  466.         RPMap.print_map()
  467.         print ''
  468.  
  469.     elif inpt == 'adjust':
  470.  
  471.         amt = raw_input('How much> ')
  472.         pram = raw_input('[add] or Else> ')
  473.  
  474.         math_adjust(RPMap, amt, pram)
  475.         RPMap.print_map()
  476.         print ''
  477.  
  478.     elif inpt == 'print':
  479.  
  480.         RPMap.print_map()
  481.         print ''
  482.  
  483.     elif inpt == 'purty':
  484.  
  485.         make_purty(RPMap)
  486.         RPMap.print_map()
  487.         print ''
  488.  
  489.     elif inpt == 'quick':
  490.         procedural(RPMap)
  491.         make_purty(RPMap)
  492.         RPMap.print_map()
  493.         mapdata = open("mapdata.txt", 'w')
  494.  
  495.         for dataline in RPMap.tile_list:
  496.  
  497.             linewrite = ''.join(dataline)
  498.             linewrite += '\n'
  499.            
  500.             mapdata.write(linewrite)
  501.  
  502.         mapdata.close()
  503.        
  504.     elif inpt == 'readj':
  505.  
  506.         size_x = int(raw_input('X axis size for map> '))
  507.         size_y = int(raw_input('Y axis size for map> '))
  508.  
  509.         RPMap.size_x = size_x
  510.         RPMap.size_y = size_y
  511.         RPMap.create_null_map()
  512.    
  513.     elif inpt == 'dump':
  514.  
  515.         mapdata = open("mapdata.txt", 'w')
  516.  
  517.         for dataline in RPMap.tile_list:
  518.  
  519.             linewrite = ' '.join(dataline)
  520.             linewrite += '\n'
  521.            
  522.             mapdata.write(linewrite)
  523.  
  524.         mapdata.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement