import CommandMapping
import BigWorld, Math
import Vehicle
import uuid
import BattleReplay
import math
from AvatarInputHandler.control_modes import ArcadeControlMode, SniperControlMode, StrategicControlMode
from debug_utils import LOG_NOTE
from functools import partial
from constants import SERVER_TICK_LENGTH, SHELL_TRAJECTORY_EPSILON_CLIENT
from ModelHitTester import segmentMayHitVehicle
from math import pi, sin, cos, atan, atan2, sqrt, fmod, asin, tan
from projectile_trajectory import computeProjectileTrajectory
from projectile_trajectory import getShotAngles
from ProjectileMover import collideDynamicAndStatic, collideVehiclesAndStaticScene
OO0o = (SERVER_TICK_LENGTH / 10)
class ii11i:
__ROTATION_TICK_LENGTH = SERVER_TICK_LENGTH
__INSUFFICIENT_TIME_DIFF = 0.2
__MAX_TIME_DIFF = 0.2
def __init__(self, target):
self.id = uuid.uuid4()
self.target = target
self.__time = BigWorld.time()
self.__targetLastShotPoint = None
if (not isinstance(self.target, Vehicle.Vehicle)):
LOG_NOTE('class = ', self.target.__class__.__name__)
raise TypeError('target must be a Vehicle instance')
def update(self):
O00ooOO = Math.Vector3(self.target.position)
o0oO0 = BigWorld.player()
oo00 = o0oO0.gunRotator
o00 = o0oO0.inputHandler
Oo0oO0ooo = o0oO0.vehicleTypeDescriptor
if (O00ooOO is None):
LOG_NOTE('shotPos none')
return
if (self.__targetLastShotPoint is None):
o00oOoo = O00ooOO
else:
o00oOoo = self.__targetLastShotPoint
self.__targetLastShotPoint = O00ooOO
OOooo0000ooo = (o0oO0.getOwnVehiclePosition() - self.target.position).length
OOo000 = Oo0oO0ooo.shot['speed']
O0 = Oo0oO0ooo.shot['gravity']
I11i1i11i1I = ((OOo000 * OOo000) / O0)
if (OOooo0000ooo <= I11i1i11i1I):
Iiii = (math.asin(((OOooo0000ooo * O0) / (OOo000 * OOo000))) * 0.5)
else:
Iiii = 0.785398163
OOO0O = ((math.sin(Iiii) * OOo000) / (O0 * 2))
IiI1i = ((O00ooOO.x - o00oOoo.x) / OO0o)
OOo0o0 = ((O00ooOO.y - o00oOoo.y) / OO0o)
O0OoOoo00o = ((O00ooOO.z - o00oOoo.z) / OO0o)
OoOooOOOO = (O00ooOO.x + (IiI1i * OOO0O))
i11iiII = (O00ooOO.y + (OOo0o0 * OOO0O))
I1iiiiI1iII = (O00ooOO.z + (O0OoOoo00o * OOO0O))
Ooo00O00O0O0O = Math.Vector3(OoOooOOOO, i11iiII, I1iiiiI1iII)
Ooo00O00O0O0O.y += (self.target.typeDescriptor.chassis['hullPosition'].y + self.target.typeDescriptor.hull['turretPositions'][0].y)
oo00._VehicleGunRotator__updateShotPointOnServer(Ooo00O00O0O0O)
II = self.__getTimeDiff()
if (II is None):
return
self.__time = BigWorld.time()
oo00._VehicleGunRotator__rotate(Ooo00O00O0O0O, II)
oo00._VehicleGunRotator__updateGunMarker()
def __getTimeDiff(self):
II = (BigWorld.time() - self.__time)
if (II < self.__INSUFFICIENT_TIME_DIFF):
return None
else:
if (II > self.__MAX_TIME_DIFF):
II = self.__MAX_TIME_DIFF
return II
def isTankMarked(self):
o0o00ooo0 = BigWorld.target()
return (isinstance(o0o00ooo0, Vehicle.Vehicle) and (o0o00ooo0.id != self.target.id))
def getId(self):
return self.id
class oOOo0oo:
autoaim = None
@staticmethod
def add(autoaim):
oOOo0oo.remove()
oOOo0oo.autoaim = autoaim
o0oO0 = BigWorld.player()
o0oO0.soundNotifications.play('target_captured')
o0oO0.gunRotator.clientMode = False
oOOo0oo.update(autoaim.getId())
@staticmethod
def remove():
if (oOOo0oo.autoaim is None):
return
o0oO0 = BigWorld.player()
oOOo0oo.autoaim = None
o0oO0.gunRotator.clientMode = True
o0oO0.soundNotifications.play('target_unlocked')
@staticmethod
def hasAutoAim():
return (oOOo0oo.autoaim is not None)
@staticmethod
def update(id):
if (oOOo0oo.hasAutoAim() and (oOOo0oo.autoaim.getId() == id)):
oOOo0oo.autoaim.update()
BigWorld.callback(OO0o, partial(oOOo0oo.update, id))
def oO(self, isDown, key, mods, event=None):
ii1i1I1i = CommandMapping.g_instance
if (ii1i1I1i.isFired(CommandMapping.CMD_CM_LOCK_TARGET, key) and isDown):
o00O = BigWorld.target()
if ((o00O is None) or oOOo0oo.hasAutoAim()):
oOOo0oo.remove()
return OOO0OOO00oo(self, isDown, key, mods, event)
oOOo0oo.add(ii11i(o00O))
return
if (ii1i1I1i.isFired(CommandMapping.CMD_CM_LOCK_TARGET_OFF, key) and isDown):
oOOo0oo.remove()
return OOO0OOO00oo(self, isDown, key, mods, event)
def O0oo0OO0oOOOo(self, isDown, key, mods, event=None):
ii1i1I1i = CommandMapping.g_instance
if (ii1i1I1i.isFired(CommandMapping.CMD_CM_LOCK_TARGET, key) and isDown):
o00O = BigWorld.target()
if (o00O is None):
oOOo0oo.remove()
return i1II1(self, isDown, key, mods, event)
oOOo0oo.add(ii11i(o00O))
return
if (ii1i1I1i.isFired(CommandMapping.CMD_CM_LOCK_TARGET_OFF, key) and isDown):
oOOo0oo.remove()
return i1II1(self, isDown, key, mods, event)
def O0o0Ooo(self, isDown, key, mods, event=None):
ii1i1I1i = CommandMapping.g_instance
if (ii1i1I1i.isFired(CommandMapping.CMD_CM_LOCK_TARGET, key) and isDown):
o00O = BigWorld.target()
if (o00O is None):
oOOo0oo.remove()
return Oo0O0O0ooO0O(self, isDown, key, mods, event)
oOOo0oo.add(ii11i(o00O))
return
if (ii1i1I1i.isFired(CommandMapping.CMD_CM_LOCK_TARGET_OFF, key) and isDown):
oOOo0oo.remove()
return Oo0O0O0ooO0O(self, isDown, key, mods, event)
OOO0OOO00oo = ArcadeControlMode.handleKeyEvent
i1II1 = SniperControlMode.handleKeyEvent
Oo0O0O0ooO0O = StrategicControlMode.handleKeyEvent
ArcadeControlMode.handleKeyEvent = oO
SniperControlMode.handleKeyEvent = O0oo0OO0oOOOo
StrategicControlMode.handleKeyEvent = O0o0Ooo