Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.17 KB | None | 0 0
  1. import random, math
  2. import time as emit
  3.  
  4. # Approximate target size - target relative to ground and approximate middle; all xyz from here on in meters
  5. sidehead = [[-0.047, 1.8], [0.166, 1.8], [0.166, 1.562], [0.036, 1.562], [-0.047, 1.645], 2.0]
  6. sidebody = [[-0.032, 1.63], [0.036, 1.562], [0.083, 1.562], [0.133, 1.367], [0.209, 1.299], [0.137, 1.223], [0.426, 1.151], [0.386, 1.079], [0.076, 1.136], [0.087, 0.963], [-0.173, 0.963], [-0.126, 1.104], [-0.198, 1.288], [-0.191, 1.504], [-0.032, 1.584], 1.0]
  7. sidelegs = [[-0.173, 0.963], [0.087, 0.963], [0.173, 0.66], [0.076, 0.357], [0.17, 0.278], [0.245, 0.278], [0.245, 0.213], [-0.014, 0.213], [-0.014, 0.548], [0.029, 0.628], [0.018, 0.667], [-0.011, 0.563], [-0.195, 0.227], [-0.162, 0.119], [-0.083, 0.069], [-0.083, 0.025], [-0.17, 0.004], [-0.314, 0.072], [-0.314, 0.249], [-0.137, 0.61], 0.9]
  8. fronthead = [[-0.095, 1.8], [0.07, 1.8], [0.07, 1.573], [-0.095, 1.573], 2.0]
  9. frontbody = [[-0.062, 1.573], [0.07, 1.573], [0.227, 1.477], [0.301, 1.147], [0.147, 1.103], [0.154, 1.224], [0.132, 1.356], [0.198, 1.228], [0.154, 1.224], [0.147, 1.103], [0.172, 0.946], [-0.132, 0.946], [-0.125, 1.254], [-0.194, 1.202], [-0.224, 1.257], [-0.29, 1.21], [-0.345, 1.276], [-0.062, 1.51], 1.0]
  10. frontlegs = [[-0.132, 0.946], [0.172, 0.946], [0.187, 0.583], [0.286, 0.319], [0.286, 0.004], [0.180, 0.004], [0.187, 0.268], [0.048, 0.594], [0.022, 0.851], [-0.066, 0.583], [-0.066, 0.213], [-0.293, 0.176], [-0.315, 0.246], [-0.158, 0.304], [-0.187, 0.781], 0.9]
  11.  
  12. mite = emit.time()
  13.  
  14. for acc in range(0, 101, 10): # Accuracy skill
  15.     for z in range(1, 101, 9): # Range
  16.         fail = open('acc' + str(acc) + ' z' + str(z) + '.txt', 'w')
  17.         for tary in range(20, -1, -1):
  18.             for tarx in range(11):
  19.                 tarx, tary = tarx / 10.0 - 0.5, tary / 10.0
  20.                 ytar = tary + 5.625 * (z / 600.0) ** 2
  21.                 xaim, yaim = 0.0, math.atan((ytar - 1.6) / z) # Aim angle
  22.                 xrec, yrec, cof = 0.0, 0.0, 0.1 # Recoil and CoF
  23.                 aimt, dmg = 0.08, 0
  24.                 for x in range(3):
  25.                    
  26.                     # Hit location
  27.                     angle = random.uniform(0, 2 * math.pi)
  28.                     rad = cof * random.random() ** 0.5
  29.                     xang = math.tan((rad * math.sin(angle) + xrec + xaim) / 180 * math.pi)
  30.                     yang = math.tan((rad * math.cos(angle) + yrec + yaim) / 180 * math.pi)
  31.                     px = x * xang
  32.                     py = x * yang + 1.6
  33.                     l = (z ** 2 * (1 + xang ** 2 + yang ** 2)) ** 0.5
  34.                     py -= 5.625 * (l / 600) ** 2
  35.                    
  36.                     # Hit detection
  37.                     hit = False
  38.                     for target in [fronthead, frontbody, frontlegs]:
  39.                         p1x = target[-2][0] + tarx
  40.                         p1y = target[-2][1]
  41.                         for p2x, p2y in target[:-1]:
  42.                             p2x += tarx
  43.                             if py >= min(p1y, p2y) and py <= max(p1y, p2y) and px >= min(p1x, p2x):
  44.                                 if p1y != p2y:
  45.                                     xinter = (py - p1y) * (p2x - p1x) / (p2y - p1y) + p1x
  46.                                 if p1x == p2x or px >= xinter:
  47.                                     hit = not hit
  48.                             p1x, p1y = p2x, p2y
  49.                         if hit:
  50.                             dmg += 10 * target[-1]
  51.                             break
  52.  
  53.                     # Recoil
  54.                     if xrec >= 0.5:
  55.                         direct = -1
  56.                     elif xrec <= -0.5:
  57.                         direct = 1
  58.                     else:
  59.                         direct = (-1) ** random.randint(1, 2)
  60.                     angle = random.uniform(-2, 2) / 180 * math.pi
  61.                     horiz = random.uniform(0.2, 0.2) * direct
  62.                     verti = 0.4
  63.                     if x == 0:
  64.                         verti *= 2
  65.                     xrec += verti * math.sin(angle) + horiz * math.cos(angle)
  66.                     yrec += verti * math.cos(angle) - horiz * math.sin(angle)
  67.                     if cof <= 29.95:
  68.                         cof += 0.05
  69.                     else:
  70.                         cof = 3
  71.                    
  72.                     # Recoil compensation
  73.                     verti = 0.4 * acc / 100
  74.                     verti = random.uniform(verti, 0.8 - verti)
  75.                     if x == 0 and acc > 75:
  76.                         verti += 0.4 * (acc - 75) / 25
  77.                     yaim -= verti
  78.                     aimt += 0.08
  79.                     if aimt >= 0.25:
  80.                         angle = (-xaim - xrec) * acc / 100
  81.                         xaim += random.uniform(angle, 2 * (-xaim - xrec) - angle)
  82.                         angle = math.atan((ytar - 1.6) / z) - yaim - yrec
  83.                         yaim += random.uniform(angle * acc / 100, 2 * angle - angle * acc / 100)
  84.                         aimt -= 0.25
  85.                     # Lead moving targets by 0 - 2x with 0 acc, and x with 100 acc
  86.  
  87.                 fail.write(str(int(dmg)).rjust(3) + ' ')
  88.             fail.write('\n')
  89.         fail.close()
  90.  
  91. print emit.time() - mite
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement