docking.py (5982B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\ballparkCommon\docking.py 2 import math 3 import random 4 from eve.common.lib.appConst import SMALL_UNDOCKPOINT_CATEGORY, LARGE_UNDOCKPOINT_CATEGORY, CAPITAL_UNDOCKPOINT_CATEGORY, SUPERCAPITAL_UNDOCKPOINT_CATEGORY 5 import evetypes 6 import collections 7 from inventorycommon import const as inventoryconst 8 from dogma import const as dogmaconst 9 from fsdBuiltData.common.graphicLocations import GetDirectionalLocators 10 from fsdBuiltData.common.graphicIDs import GetGraphicLocationID 11 from structures.types import IsFlexStructure 12 DEFAULT_DIRECTION = ((0.0, 0.0, 0.0), (0.0, 0.0, 1.0)) 13 DEFAULT_MAPPING = SMALL_UNDOCKPOINT_CATEGORY 14 GROUP_MAPPING = {inventoryconst.groupFreighter: LARGE_UNDOCKPOINT_CATEGORY, 15 inventoryconst.groupIndustrial: LARGE_UNDOCKPOINT_CATEGORY, 16 inventoryconst.groupTransportShip: LARGE_UNDOCKPOINT_CATEGORY, 17 inventoryconst.groupBlockadeRunner: LARGE_UNDOCKPOINT_CATEGORY, 18 inventoryconst.groupJumpFreighter: LARGE_UNDOCKPOINT_CATEGORY, 19 inventoryconst.groupBattleship: LARGE_UNDOCKPOINT_CATEGORY, 20 inventoryconst.groupEliteBattleship: LARGE_UNDOCKPOINT_CATEGORY, 21 inventoryconst.groupBlackOps: LARGE_UNDOCKPOINT_CATEGORY, 22 inventoryconst.groupMarauders: LARGE_UNDOCKPOINT_CATEGORY, 23 inventoryconst.groupIndustrialCommandShip: LARGE_UNDOCKPOINT_CATEGORY, 24 inventoryconst.groupCarrier: CAPITAL_UNDOCKPOINT_CATEGORY, 25 inventoryconst.groupCommandCarrier: CAPITAL_UNDOCKPOINT_CATEGORY, 26 inventoryconst.groupForceAux: CAPITAL_UNDOCKPOINT_CATEGORY, 27 inventoryconst.groupDreadnought: CAPITAL_UNDOCKPOINT_CATEGORY, 28 inventoryconst.groupLancerDreadnought: CAPITAL_UNDOCKPOINT_CATEGORY, 29 inventoryconst.groupCapitalIndustrialShip: CAPITAL_UNDOCKPOINT_CATEGORY, 30 inventoryconst.groupTitan: SUPERCAPITAL_UNDOCKPOINT_CATEGORY, 31 inventoryconst.groupSupercarrier: SUPERCAPITAL_UNDOCKPOINT_CATEGORY} 32 VELOCITY_MULTIPLIER = 1.75 33 VELOCITY_MAXIMUM = 700 34 ONE_WAY_UNDOCKS_BY_STRUCTURE_TYPE = {inventoryconst.typeEngineeringComplexRaitaru: [CAPITAL_UNDOCKPOINT_CATEGORY, SUPERCAPITAL_UNDOCKPOINT_CATEGORY], 35 inventoryconst.typeEngineeringComplexAzbel: [CAPITAL_UNDOCKPOINT_CATEGORY, SUPERCAPITAL_UNDOCKPOINT_CATEGORY], 36 inventoryconst.typeEngineeringComplexSotiyo: [SUPERCAPITAL_UNDOCKPOINT_CATEGORY]} 37 EXCLUDED_DOCKS_BY_STRUCTURE_TYPE = {inventoryconst.typeRefineryTatara: [inventoryconst.groupCarrier, 38 inventoryconst.groupCommandCarrier, 39 inventoryconst.groupForceAux, 40 inventoryconst.groupDreadnought, 41 inventoryconst.groupLancerDreadnought], 42 inventoryconst.typeInsurgencyFOBAngel: [inventoryconst.groupFreighter, inventoryconst.groupJumpFreighter], 43 inventoryconst.typeInsurgencyFOBGuristas: [inventoryconst.groupFreighter, inventoryconst.groupJumpFreighter]} 44 45 def GetUndockCategoryByType(typeID): 46 try: 47 return GROUP_MAPPING[evetypes.GetGroupID(typeID)] 48 except (KeyError, evetypes.TypeNotFoundException): 49 return DEFAULT_MAPPING 50 51 52 def LocationToTuples(location): 53 return ((location.position.x, location.position.y, location.position.z), (location.direction.x, location.direction.y, location.direction.z)) 54 55 56 def GetUndockDirections(typeID): 57 try: 58 graphicID = evetypes.GetGraphicID(typeID) 59 graphicLocationID = GetGraphicLocationID(graphicID) 60 except evetypes.TypeNotFoundException: 61 return {} 62 except KeyError: 63 return {} 64 65 directions = collections.defaultdict(list) 66 for location in GetDirectionalLocators(graphicLocationID, default=[]): 67 directions[location.category].append(LocationToTuples(location)) 68 directions[None].append(LocationToTuples(location)) 69 70 return dict(directions) 71 72 73 def GetUndockDirection(typeID, shipTypeID = None): 74 directions = GetUndockDirections(typeID) 75 try: 76 return random.choice(directions[GetUndockCategoryByType(shipTypeID)]) 77 except KeyError: 78 return random.choice(directions.get(None, [DEFAULT_DIRECTION])) 79 80 81 def CanDock(typeID, shipTypeID = None): 82 directions = GetUndockDirections(typeID) 83 undockCategory = GetUndockCategoryByType(shipTypeID) 84 if undockCategory not in directions: 85 return False 86 excludedDocks = EXCLUDED_DOCKS_BY_STRUCTURE_TYPE.get(typeID, []) 87 if evetypes.GetGroupID(shipTypeID) in excludedDocks: 88 return False 89 oneWayUndocks = ONE_WAY_UNDOCKS_BY_STRUCTURE_TYPE.get(typeID, []) 90 return undockCategory not in oneWayUndocks 91 92 93 def GetUndockVector(ballpark, ballID, typeID = None): 94 import geo2 95 ballTypeID = ballpark.GetBallType(ballID) 96 position, direction = GetUndockDirection(ballTypeID, typeID) 97 rotation = ballpark.GetSlimItemField(ballID, 'dunRotation') 98 if rotation: 99 rotation = map(math.radians, rotation) 100 quaternion = geo2.QuaternionRotationSetYawPitchRoll(*rotation) 101 position = geo2.QuaternionTransformVector(quaternion, position) 102 direction = geo2.QuaternionTransformVector(quaternion, direction) 103 ball = ballpark.CheckBalls(ballID) 104 position = [ball.x + position[0], ball.y + position[1], ball.z + position[2]] 105 direction = geo2.Vec3Normalize(direction) 106 if IsFlexStructure(ballTypeID): 107 position = geo2.Vec3AddD(position, geo2.Vec3ScaleD(direction, ball.radius)) 108 return (tuple(position), direction) 109 110 111 def ShipUndockDirection(direction, jitter = 0.25): 112 import geo2 113 yaw = random.uniform(-jitter, jitter) 114 pitch = random.uniform(-jitter, jitter) 115 roll = random.uniform(-jitter, jitter) 116 quaternion = geo2.QuaternionRotationSetYawPitchRoll(yaw, pitch, roll) 117 return geo2.QuaternionTransformVector(quaternion, direction) 118 119 120 def ShipUndockVelocity(direction, dogma, shipID): 121 import geo2 122 speed = min(VELOCITY_MULTIPLIER * dogma.GetAttributeValue(shipID, dogmaconst.attributeMaxVelocity), VELOCITY_MAXIMUM) 123 return geo2.Vec3ScaleD(geo2.Vec3Normalize(direction), speed)