Advertisement
Guest User

MS

a guest
Apr 23rd, 2014
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.99 KB | None | 0 0
  1. """
  2. (c) Dellux 2014
  3. """
  4. import BigWorld, GUI, Math, math
  5. import ResMgr
  6. import BattleReplay
  7. import AvatarInputHandler.control_modes
  8. from math import degrees
  9. from AvatarInputHandler.aims import Aim
  10. from AvatarInputHandler.aims import StrategicAim
  11. from AvatarInputHandler.aims import ArcadeAim
  12. from AvatarInputHandler.control_modes import _FlashGunMarker, _calcScale
  13. from gui.IngameSoundNotifications import ComplexSoundNotifications
  14. from debug_utils import *
  15. isAimingEnded = False
  16.  
  17. def new_update(self):
  18.     global isAimingEnded
  19.     from AvatarInputHandler.aims import _g_aimState
  20.     targetID = _g_aimState['target']['id']
  21.     if targetID is not None:
  22.         targ = BigWorld.entity(targetID)
  23.         if targ is None:
  24.             self.clearTarget()
  25.             LOG_ERROR('Invalid target ID')
  26.         else:
  27.             state = _g_aimState['target']
  28.             state['dist'] = (targ.position - BigWorld.player().getOwnVehiclePosition()).length
  29.             state['health'] = math.ceil(100.0 * max(0, targ.health) / targ.typeDescriptor.maxHealth)
  30.     reload = _g_aimState['reload']
  31.     correction = reload['correction']
  32.     if reload['isReloading']:
  33.         if correction is not None:
  34.             reloadTimer = correction['startTime'] + correction['timeRemaining'] - BigWorld.time()
  35.         else:
  36.             reloadTimer = reload['startTime'] + reload['duration'] - BigWorld.time()
  37.     else:
  38.         reloadTimer = 0
  39.     gunPitch = degrees(Math.Matrix(BigWorld.player().gunRotator.gunMatrix).pitch)
  40.     self._flashCall('reloadTimer', [reloadTimer, gunPitch])
  41.     aimMode = BigWorld.player().inputHandler.aim.mode
  42.     if aimMode == 'sniper':
  43.         fov = BigWorld.projection().fov
  44.         zoom = 1.04719758034 / fov
  45.         self._flashCall('sniperZoom', [zoom])
  46.     if BigWorld.target() != None:
  47.         typeDescr = BigWorld.target().typeDescriptor
  48.         speed = [typeDescr.physics['speedLimits'][0], typeDescr.physics['speedLimits'][1]]
  49.         self._flashCall('vehicleSpeed', [speed[0], speed[1]])
  50.     if aimMode == 'strategic':
  51.         height = BigWorld.camera().position.y - AvatarInputHandler.control_modes.getFocalPoint()[1]
  52.         self._flashCall('heightSight', [height])
  53.     if BigWorld.player().isOnArena:
  54.         if aimMode == 'arcade' or aimMode == 'sniper':
  55.             x, y, z = BigWorld.player().gunRotator.markerInfo[0]
  56.             v = BigWorld.player().getOwnVehiclePosition() - Math.Vector3(x, y, z)
  57.             self._flashCall('markerDistance', [v.length])
  58.     self._flashCall('aimingEnded', [isAimingEnded])
  59.     return
  60.  
  61.  
  62. Aim._update = new_update
  63. saved_setReloading = Aim._setReloading
  64.  
  65. def new_setReloading(self, duration, startTime = None, isReloading = True, correction = None, baseTime = None):
  66.     saved_setReloading(self, duration, startTime, isReloading, correction)
  67.     replayCtrl = BattleReplay.g_replayCtrl
  68.     if replayCtrl.isPlaying and replayCtrl.replayContainsGunReloads:
  69.         replayCtrl.setGunReloadTime(startTime, duration)
  70.     if replayCtrl.isRecording:
  71.         replayCtrl.setGunReloadTime(startTime, duration)
  72.     if correction is not None:
  73.         params = self._getCorrectionReloadingParams(correction)
  74.         if params is not None:
  75.             self._flashCall('setReloading', params)
  76.     else:
  77.         self._flashCall('setReloading', [duration,
  78.          startTime,
  79.          isReloading,
  80.          None,
  81.          baseTime])
  82.     vTypeDesc = BigWorld.player().vehicleTypeDescriptor
  83.     gunName = vTypeDesc.gun['shortUserString']
  84.     shellSpeed = vTypeDesc.shot['speed']
  85.     shellGravity = vTypeDesc.shot['gravity']
  86.     shellName = vTypeDesc.shot['shell']['userString']
  87.     if vTypeDesc.shot['shell']['kind'] == 'ARMOR_PIERCING':
  88.         shellType = vTypeDesc.shot['shell']['kind'].replace('ARMOR_PIERCING', 'AP')
  89.     elif vTypeDesc.shot['shell']['kind'] == 'HIGH_EXPLOSIVE':
  90.         shellType = vTypeDesc.shot['shell']['kind'].replace('HIGH_EXPLOSIVE', 'HE')
  91.     elif vTypeDesc.shot['shell']['kind'] == 'ARMOR_PIERCING_CR':
  92.         shellType = vTypeDesc.shot['shell']['kind'].replace('ARMOR_PIERCING_CR', 'CR')
  93.     else:
  94.         shellType = vTypeDesc.shot['shell']['kind'].replace('HOLLOW_CHARGE', 'HC')
  95.     vehicleName = vTypeDesc.type.userString
  96.     try:
  97.         shellSplash = vTypeDesc.shot['shell']['explosionRadius']
  98.     except:
  99.         shellSplash = 0
  100.  
  101.     self._flashCall('vehicleParams', [gunName,
  102.      shellSpeed,
  103.      shellGravity,
  104.      shellName,
  105.      shellSplash,
  106.      vehicleName,
  107.      shellType])
  108.     return
  109.  
  110.  
  111. Aim._setReloading = new_setReloading
  112.  
  113. def new_setHealth(self, cur, max):
  114.     if cur is not None and max is not None:
  115.         self._flashCall('setHealth', [cur / max, cur, max])
  116.     return
  117.  
  118.  
  119. Aim._setHealth = new_setHealth
  120.  
  121. def new_setTarget(self, name, vType, isFriend):
  122.     self._flashCall('setTarget', [name,
  123.      vType,
  124.      self.getTargetColor(isFriend),
  125.      isFriend])
  126.  
  127.  
  128. Aim._setTarget = new_setTarget
  129. saved_strategic_enable = StrategicAim._enable
  130.  
  131. def new_strategic_enable(self, state, isFirstInit):
  132.     saved_strategic_enable(self, state, isFirstInit)
  133.     Aim._flashCall(self, 'updateDistanceMS', [self._getAimDistanceMS()])
  134.  
  135.  
  136. StrategicAim._enable = new_strategic_enable
  137. saved_strategic_update = StrategicAim._update
  138.  
  139. def new_strategic_update(self):
  140.     saved_strategic_update(self)
  141.     Aim._flashCall(self, 'updateDistanceMS', [self._getAimDistanceMS()])
  142.  
  143.  
  144. StrategicAim._update = new_strategic_update
  145.  
  146. def _getAimDistanceMS(self):
  147.     x, y, z = BigWorld.player().gunRotator.markerInfo[0]
  148.     v = BigWorld.player().getOwnVehiclePosition() - Math.Vector3(x, y, z)
  149.     return v.length
  150.  
  151.  
  152. StrategicAim._getAimDistanceMS = _getAimDistanceMS
  153. saved_arcade_enable = ArcadeAim._enable
  154.  
  155. def new_arcade_enable(self, state, isFirstInit):
  156.     saved_arcade_enable(self, state, isFirstInit)
  157.     ts = state['target']
  158.     if ts['startTime'] is not None:
  159.         Aim._flashCall(self, 'updateTarget', [int(ts['dist'])])
  160.         Aim._flashCall(self, 'updateTargetMS', [ts['dist']])
  161.     return
  162.  
  163.  
  164. ArcadeAim._enable = new_arcade_enable
  165.  
  166. def new_arcade_update(self):
  167.     Aim._update(self)
  168.     from AvatarInputHandler.aims import _g_aimState
  169.     Aim._flashCall(self, 'updateTarget', [int(_g_aimState['target']['dist'])])
  170.     Aim._flashCall(self, 'updateTargetMS', [_g_aimState['target']['dist']])
  171.  
  172.  
  173. ArcadeAim._update = new_arcade_update
  174. saved_setAimingEnded = ComplexSoundNotifications.setAimingEnded
  175.  
  176. def new_setAimingEnded(self, isEnded, isReloading):
  177.     global isAimingEnded
  178.     saved_setAimingEnded(self, isEnded, isReloading)
  179.     isAimingEnded = isEnded
  180.  
  181.  
  182. ComplexSoundNotifications.setAimingEnded = new_setAimingEnded
  183. saved_changeColor = _FlashGunMarker._changeColor
  184.  
  185. def new_changeColor(self, hitPoint, armor):
  186.     vDesc = BigWorld.player().vehicleTypeDescriptor
  187.     ppDesc = vDesc.shot['piercingPower']
  188.     maxDist = vDesc.shot['maxDistance']
  189.     dist = (hitPoint - BigWorld.player().getOwnVehiclePosition()).length
  190.     if dist <= 100.0:
  191.         piercingPower = ppDesc[0]
  192.     elif maxDist > dist:
  193.         p100, p500 = ppDesc
  194.         piercingPower = p100 + (p500 - p100) * (dist - 100.0) / 400.0
  195.         if piercingPower < 0.0:
  196.             piercingPower = 0.0
  197.     else:
  198.         piercingPower = 0.0
  199.     piercingPercent = 1000.0
  200.     if piercingPower > 0.0:
  201.         piercingPercent = 100.0 + (armor - piercingPower) / piercingPower * 100.0
  202.     type = 'great_pierced'
  203.     if piercingPercent >= 150:
  204.         type = 'not_pierced'
  205.     elif 90 < piercingPercent < 150:
  206.         type = 'little_pierced'
  207.     self.call('Crosshair.setMarkerType', [self._curColors[type], armor, piercingPower])
  208.  
  209.  
  210. _FlashGunMarker._changeColor = new_changeColor
  211. mscfg = ResMgr.openSection('scripts/client/mods/MS.xml')
  212. if mscfg:
  213.     curSize = mscfg.readFloat('curSize')
  214. else:
  215.     curSize = 1.0
  216.  
  217. def new_gm_update(self, pos, dir, size, relaxTime, collData):
  218.     m = Math.Matrix()
  219.     m.setTranslate(pos)
  220.     self._FlashGunMarker__setupMatrixAnimation()
  221.     self._FlashGunMarker__animMat.keyframes = ((0.0, Math.Matrix(self._FlashGunMarker__animMat)), (relaxTime, m))
  222.     self._FlashGunMarker__animMat.time = 0.0
  223.     self._FlashGunMarker__curSize = _calcScale(m, size) * (GUI.screenResolution()[0] * 0.5)
  224.     replayCtrl = BattleReplay.g_replayCtrl
  225.     if replayCtrl.isPlaying and replayCtrl.isClientReady:
  226.         s = replayCtrl.getArcadeGunMarkerSize()
  227.         if s != -1.0:
  228.             self._FlashGunMarker__curSize = s
  229.     elif replayCtrl.isRecording:
  230.         replayCtrl.setArcadeGunMarkerSize(self._FlashGunMarker__curSize)
  231.     if collData is None or collData[0].health <= 0 or collData[0].publicInfo['team'] == BigWorld.player().team:
  232.         self.call('Crosshair.setMarkerType', ['normal'])
  233.     else:
  234.         self._changeColor(pos, collData[2])
  235.     self.component.wg_updateSize(self._FlashGunMarker__curSize / curSize, relaxTime)
  236.     if BigWorld.player().inputHandler.aim != None:
  237.         aimMode = BigWorld.player().inputHandler.aim.mode
  238.         self.call('Crosshair.AimMode', [aimMode])
  239.     return
  240.  
  241.  
  242. _FlashGunMarker.update = new_gm_update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement