Advertisement
Guest User

WoT UniversalAims.py

a guest
Apr 12th, 2014
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. WOT VERSION: 0.8.11
  3. WOT SERVER : EU/NA/RU
  4. Supported Crosshairs:
  5. -KT Mjolnir v2.x
  6. -Deegies Sights
  7. -Dikeys Taipan
  8. -Arty SAU
  9. -Melty Map's Math Mode
  10. ----------------------
  11. (c) P0LIR0ID 2014
  12. ----------------------
  13. Don't forget to delete
  14. Aims.pyc in your
  15. res_mods folder !
  16. """
  17. import BigWorld
  18. import GUI
  19. import Math, math
  20. import ResMgr
  21. import BattleReplay
  22. import AvatarInputHandler.control_modes
  23. from math import degrees
  24. from AvatarInputHandler.aims import Aim
  25. from AvatarInputHandler.aims import StrategicAim
  26. from AvatarInputHandler.aims import ArcadeAim
  27. from AvatarInputHandler.aims import clearState
  28. from AvatarInputHandler.aims import _DamageIndicator
  29. from AvatarInputHandler.control_modes import _FlashGunMarker, _calcScale
  30. from gui.Scaleform.Flash import Flash
  31. from gui.IngameSoundNotifications import ComplexSoundNotifications
  32. from debug_utils import *
  33. isAimingEnded = False
  34. isShown = False
  35.  
  36. class ZoomIndicator(object):
  37.  
  38.     def __init__(self):
  39.         self.Objects = {}
  40.         self.Objects['SniperCamera'] = None
  41.         self.isReplayPlaying = False
  42.         self.Inited = False
  43.         return
  44.  
  45.     def processBattleType(self):
  46.         if BattleReplay.g_replayCtrl.isPlaying is True:
  47.             self.isReplayPlaying = True
  48.         self.Inited = True
  49.         print BattleReplay.g_replayCtrl.isPlaying
  50.  
  51.     def isReplay(self):
  52.         return self.isReplayPlaying
  53.  
  54.     def getZoom(self):
  55.         if self.Objects['SniperCamera'] is None:
  56.             return 2.1
  57.         else:
  58.             return self.Objects['SniperCamera']._SniperCamera__zoom
  59.             return
  60. ZI = ZoomIndicator()
  61.  
  62. class _DamageIndicator(Flash):
  63.     __SWF_FILE_NAME = 'DamageIndicator.swf'
  64.     __FLASH_CLASS = 'WGHitIndicatorFlash'
  65.     __FLASH_MC_NAME = 'damageMC'
  66.     __FLASH_SIZE = (680, 680)
  67.     TOTAL_FRAMES = 360
  68.     FRAME_RATE = 24
  69.  
  70.     def __init__(self):
  71.         Flash.__init__(self, self.__SWF_FILE_NAME, self.__FLASH_CLASS, [self.__FLASH_MC_NAME])
  72.         self.component.wg_inputKeyMode = 2
  73.         self.component.position.z = DEPTH_OF_Aim
  74.         self.movie.backgroundAlpha = 0.0
  75.         self.component.focus = False
  76.         self.component.moveFocus = False
  77.         self.component.heightMode = 'PIXEL'
  78.         self.component.widthMode = 'PIXEL'
  79.         self.flashSize = self.__FLASH_SIZE
  80.  
  81.     def setup(self, gYaw, offset):
  82.         self.component.position.x = offset[0]
  83.         self.component.position.y = offset[1]
  84.         self.component.wg_globalYaw = gYaw
  85.  
  86.     def __del__(self):
  87.         pass
  88.  
  89. def new_update(self):
  90.     global isAimingEnded
  91.     if ZI.Inited is False:
  92.         ZI.processBattleType()
  93.     from AvatarInputHandler.aims import _g_aimState
  94.     targetID = _g_aimState['target']['id']
  95.     if targetID is not None:
  96.         targ = BigWorld.entity(targetID)
  97.         if targ is None:
  98.             self.clearTarget()
  99.             LOG_ERROR('Invalid target ID')
  100.         else:
  101.             state = _g_aimState['target']
  102.             state['dist'] = (targ.position - BigWorld.player().getOwnVehiclePosition()).length
  103.             state['health'] = math.ceil(100.0 * max(0, targ.health) / targ.typeDescriptor.maxHealth)
  104.     reload = _g_aimState['reload']
  105.     correction = reload['correction']
  106.     if reload['isReloading']:
  107.         if correction is not None:
  108.             reloadTimer = correction['startTime'] + correction['timeRemaining'] - BigWorld.time()
  109.         else:
  110.             reloadTimer = reload['startTime'] + reload['duration'] - BigWorld.time()
  111.     else:
  112.         reloadTimer = 0
  113.     gunPitch = degrees(Math.Matrix(BigWorld.player().gunRotator.gunMatrix).pitch)
  114.     self._flashCall('reloadTimer', [reloadTimer, gunPitch])
  115.     aimMode = BigWorld.player().inputHandler.aim.mode
  116.     if aimMode == 'sniper':
  117.         if ZI.isReplay() == False:
  118.             if hasattr(self, 'component'):
  119.                 self._flashCall('getZoomByMeltyMap', [1.0471 / ZI.getZoom()])
  120.             self._flashCall('sniperZoom', [ZI.getZoom()])
  121.         else:
  122.             if hasattr(self, 'component'):
  123.                 self._flashCall('getZoomByMeltyMap', [1.0471 / ZI.getZoom()])
  124.             self._flashCall('sniperZoom', [1.0675761419418335 / BigWorld.projection().fov])
  125.     if BigWorld.target() != None:
  126.         typeDescr = BigWorld.target().typeDescriptor
  127.         speed = [typeDescr.physics['speedLimits'][0], typeDescr.physics['speedLimits'][1]]
  128.         self._flashCall('vehicleSpeed', [speed[0], speed[1]])
  129.     if aimMode == 'strategic':
  130.         height = BigWorld.camera().position.y - AvatarInputHandler.control_modes.getFocalPoint()[1]
  131.         self._flashCall('heightSight', [height])
  132.     if BigWorld.player().isOnArena:
  133.         if aimMode == 'arcade' or aimMode == 'sniper':
  134.             x, y, z = BigWorld.player().gunRotator.markerInfo[0]
  135.             v = BigWorld.player().getOwnVehiclePosition() - Math.Vector3(x, y, z)
  136.             self._flashCall('markerDistance', [v.length])
  137.     self._flashCall('aimingEnded', [isAimingEnded])
  138.     return
  139.  
  140.  
  141. Aim._update = new_update
  142.  
  143. def new_setTarget(self, name, vType, isFriend):
  144.     self._flashCall('setTarget', [name,
  145.      vType,
  146.      self.getTargetColor(isFriend),
  147.      isFriend])
  148.  
  149.  
  150. Aim._setTarget = new_setTarget
  151. saved_strategic_enable = StrategicAim._enable
  152.  
  153. def new_strategic_enable(self, state, isFirstInit):
  154.     saved_strategic_enable(self, state, isFirstInit)
  155.     Aim._flashCall(self, 'updateDistanceMS', [self._getAimDistanceMS()])
  156.  
  157.  
  158. StrategicAim._enable = new_strategic_enable
  159. saved_strategic_update = StrategicAim._update
  160.  
  161. def new_strategic_update(self):
  162.     saved_strategic_update(self)
  163.     Aim._flashCall(self, 'updateDistanceMS', [self._getAimDistanceMS()])
  164.  
  165.  
  166. StrategicAim._update = new_strategic_update
  167.  
  168. def _getAimDistanceMS(self):
  169.     x, y, z = BigWorld.player().gunRotator.markerInfo[0]
  170.     v = BigWorld.player().getOwnVehiclePosition() - Math.Vector3(x, y, z)
  171.     return v.length
  172.  
  173.  
  174. StrategicAim._getAimDistanceMS = _getAimDistanceMS
  175.  
  176. def new_arcade_update(self):
  177.     Aim._update(self)
  178.     from AvatarInputHandler.aims import _g_aimState
  179.     Aim._flashCall(self, 'updateTarget', [int(_g_aimState['target']['dist'])])
  180.     Aim._flashCall(self, 'updateTargetMS', [_g_aimState['target']['dist']])
  181.  
  182.  
  183. ArcadeAim._update = new_arcade_update
  184. saved_arcade_enable = ArcadeAim._enable
  185.  
  186. def new_arcade_enable(self, state, isFirstInit):
  187.     saved_arcade_enable(self, state, isFirstInit)
  188.     ts = state['target']
  189.     if ts['startTime'] is not None:
  190.         Aim._flashCall(self, 'updateTarget', [int(ts['dist'])])
  191.         Aim._flashCall(self, 'updateTargetMS', [ts['dist']])
  192.     return
  193.  
  194.  
  195. ArcadeAim._enable = new_arcade_enable
  196.  
  197. def new_setHealth(self, cur, max):
  198.     if cur is not None and max is not None:
  199.         self._flashCall('setHealth', [cur / max, cur, max])
  200.     return
  201.  
  202.  
  203. Aim._setHealth = new_setHealth
  204. saved_setAimingEnded = ComplexSoundNotifications.setAimingEnded
  205.  
  206. def new_setAimingEnded(self, isEnded, isReloading):
  207.     global isAimingEnded
  208.     saved_setAimingEnded(self, isEnded, isReloading)
  209.     isAimingEnded = isEnded
  210.  
  211.  
  212. ComplexSoundNotifications.setAimingEnded = new_setAimingEnded
  213. saved_changeColor = _FlashGunMarker._changeColor
  214.  
  215. def new_changeColor(self, hitPoint, armor):
  216.     vDesc = BigWorld.player().vehicleTypeDescriptor
  217.     ppDesc = vDesc.shot['piercingPower']
  218.     maxDist = vDesc.shot['maxDistance']
  219.     dist = (hitPoint - BigWorld.player().getOwnVehiclePosition()).length
  220.     if dist <= 100.0:
  221.         piercingPower = ppDesc[0]
  222.     elif maxDist > dist:
  223.         p100, p500 = ppDesc
  224.         piercingPower = p100 + (p500 - p100) * (dist - 100.0) / 400.0
  225.         if piercingPower < 0.0:
  226.             piercingPower = 0.0
  227.     else:
  228.         piercingPower = 0.0
  229.     piercingPercent = 1000.0
  230.     if piercingPower > 0.0:
  231.         piercingPercent = 100.0 + (armor - piercingPower) / piercingPower * 100.0
  232.     type = 'great_pierced'
  233.     if piercingPercent >= 150:
  234.         type = 'not_pierced'
  235.     elif 90 < piercingPercent < 150:
  236.         type = 'little_pierced'
  237.     self.call('Crosshair.setMarkerType', [self._curColors[type], armor, piercingPower])
  238.  
  239.  
  240. _FlashGunMarker._changeColor = new_changeColor
  241.  
  242. def new_gm_update(self, pos, dir, size, relaxTime, collData):
  243.     m = Math.Matrix()
  244.     m.setTranslate(pos)
  245.     self._FlashGunMarker__setupMatrixAnimation()
  246.     self._FlashGunMarker__animMat.keyframes = ((0.0, Math.Matrix(self._FlashGunMarker__animMat)), (relaxTime, m))
  247.     self._FlashGunMarker__animMat.time = 0.0
  248.     self._FlashGunMarker__curSize = _calcScale(m, size) * (GUI.screenResolution()[0] * 0.5)
  249.     replayCtrl = BattleReplay.g_replayCtrl
  250.     if replayCtrl.isPlaying and replayCtrl.isClientReady:
  251.         s = replayCtrl.getArcadeGunMarkerSize()
  252.         if s != -1.0:
  253.             self._FlashGunMarker__curSize = s
  254.     elif replayCtrl.isRecording:
  255.         replayCtrl.setArcadeGunMarkerSize(self._FlashGunMarker__curSize)
  256.     if collData is None or collData[0].health <= 0 or collData[0].publicInfo['team'] == BigWorld.player().team:
  257.         self.call('Crosshair.setMarkerType', ['normal'])
  258.     else:
  259.         self._changeColor(pos, collData[2])
  260.     self.component.wg_updateSize(self._FlashGunMarker__curSize / 1.0, relaxTime)
  261.     if BigWorld.player().inputHandler.aim != None:
  262.         aimMode = BigWorld.player().inputHandler.aim.mode
  263.         self.call('Crosshair.AimMode', [aimMode])
  264.     return
  265.  
  266.  
  267. _FlashGunMarker.update = new_gm_update
  268.  
  269. def new_setReloading(self, duration, startTime = None, isReloading = True, correction = None, baseTime = None):
  270.     replayCtrl = BattleReplay.g_replayCtrl
  271.     if replayCtrl.isPlaying and replayCtrl.replayContainsGunReloads:
  272.         replayCtrl.setGunReloadTime(startTime, duration)
  273.     if replayCtrl.isRecording:
  274.         replayCtrl.setGunReloadTime(startTime, duration)
  275.     if correction is not None:
  276.         params = self._getCorrectionReloadingParams(correction)
  277.         if params is not None:
  278.             self._flashCall('setReloading', params)
  279.     else:
  280.         self._flashCall('setReloading', [duration,
  281.          startTime,
  282.          isReloading,
  283.          None,
  284.          baseTime])
  285.     shotDescr = BigWorld.player().vehicleTypeDescriptor.shot
  286.     gunDescr = BigWorld.player().vehicleTypeDescriptor.gun
  287.     vehicleName = BigWorld.player().vehicleTypeDescriptor.type.userString
  288.     try:
  289.         shellSplash = shotDescr['shell']['explosionRadius']
  290.     except:
  291.         shellSplash = 0
  292.  
  293.     if shotDescr['shell']['kind'] == 'ARMOR_PIERCING':
  294.         shellType = shotDescr['shell']['kind'].replace('ARMOR_PIERCING', 'AP')
  295.     elif shotDescr['shell']['kind'] == 'HIGH_EXPLOSIVE':
  296.         shellType = shotDescr['shell']['kind'].replace('HIGH_EXPLOSIVE', 'HE')
  297.     elif shotDescr['shell']['kind'] == 'ARMOR_PIERCING_CR':
  298.         shellType = shotDescr['shell']['kind'].replace('ARMOR_PIERCING_CR', 'CR')
  299.     else:
  300.         shellType = shotDescr['shell']['kind'].replace('HOLLOW_CHARGE', 'HC')
  301.     self._flashCall('setGunParams', [gunDescr['shortUserString'],
  302.      shotDescr['speed'],
  303.      shotDescr['gravity'],
  304.      shotDescr['shell']['userString'],
  305.      shellSplash])
  306.     self._flashCall('vehicleParams', [gunDescr['shortUserString'],
  307.      shotDescr['speed'],
  308.      shotDescr['gravity'],
  309.      shotDescr['shell']['userString'],
  310.      shellSplash,
  311.      vehicleName,
  312.      shellType])
  313.     return
  314.  
  315.  
  316. Aim._setReloading = new_setReloading
  317. saved_setTarget = Aim.setTarget
  318.  
  319. def new_setTarget(self, target):
  320.     typeDescr = target.typeDescriptor
  321.     speed = [typeDescr.physics['speedLimits'][0], typeDescr.physics['speedLimits'][1]]
  322.     hullArmor = [typeDescr.hull['primaryArmor'][0], typeDescr.hull['primaryArmor'][1], typeDescr.hull['primaryArmor'][2]]
  323.     turretArmor = [typeDescr.turret['primaryArmor'][0], typeDescr.turret['primaryArmor'][1], typeDescr.turret['primaryArmor'][2]]
  324.     gunName = typeDescr.gun['shortUserString']
  325.     gunReload = typeDescr.gun['reloadTime']
  326.     visionRadius = typeDescr.turret['circularVisionRadius']
  327.     iconName = typeDescr.name.replace(':', '-')
  328.     shellDamage = [0, 0, 0]
  329.     i = 0
  330.     for element in target.typeDescriptor.gun['shots']:
  331.         shellDamage[i] = element['shell']['damage'][0]
  332.         i = i + 1
  333.  
  334.     shellPower = [0, 0, 0]
  335.     j = 0
  336.     for element in target.typeDescriptor.gun['shots']:
  337.         shellPower[j] = element['piercingPower'][0]
  338.         j = j + 1
  339.  
  340.     shellType = ['', '', '']
  341.     k = 0
  342.     for element in target.typeDescriptor.gun['shots']:
  343.         if element['shell']['kind'] == 'ARMOR_PIERCING':
  344.             shellType[k] = element['shell']['kind'].replace('ARMOR_PIERCING', 'AP')
  345.         elif element['shell']['kind'] == 'HIGH_EXPLOSIVE':
  346.             shellType[k] = element['shell']['kind'].replace('HIGH_EXPLOSIVE', 'HE')
  347.         elif element['shell']['kind'] == 'ARMOR_PIERCING_CR':
  348.             shellType[k] = element['shell']['kind'].replace('ARMOR_PIERCING_CR', 'CR')
  349.         else:
  350.             shellType[k] = element['shell']['kind'].replace('HOLLOW_CHARGE', 'HC')
  351.         k = k + 1
  352.         saved_setTarget(self, target)
  353.         self._flashCall('setTargetParams', [BigWorld.target().typeDescriptor.gun['reloadTime'], BigWorld.target().typeDescriptor.turret['circularVisionRadius']])
  354.         self._flashCall('infoPanel', [speed[0],
  355.          speed[1],
  356.          gunName,
  357.          gunReload,
  358.          visionRadius,
  359.          iconName,
  360.          hullArmor[0],
  361.          hullArmor[1],
  362.          hullArmor[2],
  363.          turretArmor[0],
  364.          turretArmor[1],
  365.          turretArmor[2],
  366.          shellDamage[0],
  367.          shellDamage[1],
  368.          shellDamage[2],
  369.          shellPower[0],
  370.          shellPower[1],
  371.          shellPower[2],
  372.          shellType[0],
  373.          shellType[1],
  374.          shellType[2]])
  375.  
  376.  
  377. Aim.setTarget = new_setTarget
  378. from AvatarInputHandler.DynamicCameras.SniperCamera import SniperCamera
  379. link_SniperCamera_init = SniperCamera.__init__
  380.  
  381. def new_SniperCamera_init(self, dataSec, aim, binoculars):
  382.     link_SniperCamera_init(self, dataSec, aim, binoculars)
  383.     ZI.Objects['SniperCamera'] = self
  384.  
  385.  
  386. SniperCamera.__init__ = new_SniperCamera_init
  387. import gui.Scaleform.Flash, AvatarInputHandler.control_modes
  388.  
  389. def StrategyEraser():
  390.  
  391.     class MultiController:
  392.         target = None
  393.         prevSpeed = 0.0
  394.  
  395.         def control(self):
  396.             try:
  397.                 gui.Scaleform.Flash.GUI.roots()[1].movie.invoke(('call', ['Aim.updateHeight', int(round(BigWorld.camera().position.y - AvatarInputHandler.control_modes.getFocalPoint()[1]))]))
  398.                 if BigWorld.player().inputHandler._AvatarInputHandler__targeting.getTargetEntity() != None:
  399.                     self.target = BigWorld.player().inputHandler._AvatarInputHandler__targeting.getTargetEntity()
  400.                 if self.target != None:
  401.                     if self.target.isDestroyed == False:
  402.                         speed = self.target.getSpeed()
  403.                         gui.Scaleform.Flash.GUI.roots()[1].movie.invoke(('call', ['Aim.updateTargetSpeed', speed]))
  404.                     else:
  405.                         self.target = None
  406.             except:
  407.                 pass
  408.  
  409.             BigWorld.callback(0.05, lambda : self.control())
  410.             return
  411.  
  412.     mca1 = MultiController()
  413.     mca1.control()
  414.  
  415.  
  416. BigWorld.callback(10, lambda : StrategyEraser())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement