structureDeployment.py (10730B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\structure\structureDeployment.py 2 import evetypes 3 import localization 4 import inventorycommon 5 import inventorycommon.util 6 import eve.client.script.ui.structure.deployment.deploymentContUtil as dUtil 7 from caching.memoize import Memoize 8 from carbon.common.lib.const import SEC 9 from carbon.common.script.sys.service import Service 10 from carbonui import uiconst 11 from eve.common.lib.appConst import corpRoleStationManager, factionTriglavian 12 from eve.client.script.ui.structure.deployment.miningBeaconEntity import MiningBeaconEntity 13 from eve.common.script.sys.eveCfg import InShipInSpace 14 from eve.client.script.ui.structure.deployment.deploymentCont import StructureDeploymentWnd 15 from eve.client.script.ui.structure.deployment.deploymentEntity import StructurePlacementEntity 16 from eve.common.script.sys.idCheckers import IsWormholeSystem, IsTriglavianSystem 17 from eveexceptions import UserError 18 from eveuniverse.security import is_high_sec_or_higher_solar_system 19 from eveuniverse.solar_systems import GetNonNpcNullSecSystemsInLightYearDistanceDict, GetAlignmentYawPitchRadians, get_disallowed_categories 20 from inventorycommon.const import categoryStructure 21 from moonmining.miningBeacons import GetMiningBeaconPositionsForSolarsystem 22 from player_messaging.client.ui_message import prompt_player_fsd_dialog 23 from structures import IsDrillingPlatform, MAX_JUMPBRIDGE_RANGE_LIGHTYEARS, STATE_UNKNOWN, STATE_UNANCHORED 24 from structures.deployment import GROUPS_REQUIRING_CONQUERABLE_SYSTEM, MAX_GROUP_PER_SOLARSYSTEM 25 from structures.types import IsFlexStructure, GetUnanchoringDuration 26 from utillib import KeyVal 27 28 class StructureDeployment(Service): 29 __guid__ = 'svc.structureDeployment' 30 __dependencies__ = ['machoNet', 31 'viewState', 32 'michelle', 33 'faction', 34 'sov', 35 'tactical'] 36 __notifyevents__ = ['OnSessionChanged', 37 'OnViewStateChanged', 38 'OnClientEvent_WarpStarted', 39 'OnItemChange', 40 'DoBallClear'] 41 42 def Run(self, *args): 43 self.isDeploying = False 44 self.isMovingStrucuture = False 45 self.tacticalOverlayWasOpen = None 46 self.invItem = None 47 self.wnd = None 48 self.entity = None 49 self.deploymentBeacons = [] 50 self.destinationSolarsystemID = None 51 52 def Unanchor(self, structureID, typeID): 53 unanchorDuration = GetUnanchoringDuration(typeID) 54 msgArgs = {'item': typeID, 55 'unanchorDuration': unanchorDuration * SEC} 56 questionName = 'ConfirmDecommissionStructure' 57 structureInfo = sm.GetService('structureDirectory').GetStructureInfo(structureID) 58 numWars = len(structureInfo.wars) 59 if numWars: 60 msgArgs['numWars'] = numWars 61 questionName = 'ConfirmDecommissionWarHq' 62 if prompt_player_fsd_dialog(questionName, msgArgs, uiconst.YESNO, suppress=uiconst.ID_YES) == uiconst.ID_YES: 63 sm.RemoteSvc('structureDeployment').Unanchor(structureID) 64 65 def CancelUnanchor(self, structureID, typeID): 66 sm.RemoteSvc('structureDeployment').CancelUnanchor(structureID) 67 68 def IsStructureDeploymentBlocked(self, solarSystemID, typeID): 69 disallowedAnchorCategories = get_disallowed_categories(solarSystemID) 70 if categoryStructure in disallowedAnchorCategories: 71 return True 72 if is_high_sec_or_higher_solar_system(solarSystemID): 73 disallowedInHighSec = sm.GetService('clientDogmaStaticSvc').GetTypeAttribute(typeID, const.attributeDisallowInHighSec, False) 74 if disallowedInHighSec: 75 return True 76 return False 77 78 def Deploy(self, invItem): 79 if self.isDeploying: 80 return 81 if not self.viewState.IsViewActive('inflight'): 82 return 83 if not InShipInSpace(): 84 return 85 if self.michelle.InWarp(): 86 raise UserError('ShipInWarp') 87 if inventorycommon.util.IsNPC(session.corpid): 88 raise UserError('DropNeedsPlayerCorp', {'item': invItem.typeID}) 89 if not session.corprole & corpRoleStationManager: 90 raise UserError('CrpAccessDenied', {'reason': localization.GetByLabel('UI/Corporations/AccessRestrictions/InsufficientRoles')}) 91 if self.IsStructureDeploymentBlocked(session.solarsystemid, invItem.typeID): 92 raise UserError('CantDeployBlocked', {'typeID': invItem.typeID}) 93 if IsTriglavianSystem(session.solarsystemid): 94 raise UserError('CannotBeDeployedInSystemOwnedByFaction', {'deployTypeID': invItem.typeID, 95 'factionID': factionTriglavian}) 96 if invItem.groupID in MAX_GROUP_PER_SOLARSYSTEM: 97 bp = sm.GetService('michelle').GetBallpark() 98 if bp: 99 currentlyInSystem = {x for x in bp.slimItems.itervalues() if x.groupID == invItem.groupID and x.state not in (STATE_UNKNOWN, STATE_UNANCHORED)} 100 maxStructureGroupPerSolarsystem = MAX_GROUP_PER_SOLARSYSTEM[invItem.groupID] 101 if len(currentlyInSystem) >= maxStructureGroupPerSolarsystem: 102 raise UserError('CantDeployStructureGroupMaxAlreadyInSystem', {'type': invItem.typeID, 103 'maxStructureGroupPerSolarsystem': maxStructureGroupPerSolarsystem}) 104 if invItem.groupID in GROUPS_REQUIRING_CONQUERABLE_SYSTEM: 105 if IsWormholeSystem(session.solarsystemid2): 106 raise UserError('CantDeployBlocked', {'typeID': invItem.typeID}) 107 if self.faction.GetFactionOfSolarSystem(session.solarsystemid) is not None: 108 raise UserError('CanOnlyBeDeployedInNonEmpireSpace', {'deployTypeID': invItem.typeID}) 109 if self.sov.GetInfrastructureHubInfo(session.solarsystemid) is None: 110 if prompt_player_fsd_dialog('ConfirmAnchorSovStructureWithoutIHub', {'typeID': invItem.typeID}, uiconst.OKCANCEL) != uiconst.ID_OK: 111 return 112 try: 113 self.invItem = invItem 114 self.isDeploying = True 115 self.entity = StructurePlacementEntity(invItem.typeID) 116 self._SetupDeploymentBeacons(invItem.typeID) 117 self.wnd = StructureDeploymentWnd.Open(controller=self, useDefaultPos=True, typeID=invItem.typeID) 118 tacticalOverlayOpen = self.tactical.IsTacticalOverlayActive() 119 self.tacticalOverlayWasOpen = tacticalOverlayOpen 120 if not tacticalOverlayOpen: 121 self.tactical.ShowTacticalOverlay() 122 except Exception: 123 self._Cleanup() 124 raise 125 126 def _SetupDeploymentBeacons(self, structureTypeID): 127 if not IsDrillingPlatform(structureTypeID): 128 return 129 miningBeaconPositions = GetMiningBeaconPositionsForSolarsystem(session.solarsystemid) 130 for moonID, beaconPosition in miningBeaconPositions.iteritems(): 131 beacon = MiningBeaconEntity(beaconPosition) 132 self.deploymentBeacons.append(beacon) 133 134 def IsDeploying(self): 135 return self.isDeploying 136 137 def _Cleanup(self): 138 if self.wnd: 139 self.wnd.Close() 140 self.wnd = None 141 if self.tacticalOverlayWasOpen is False: 142 self.tactical.HideTacticalOverlay() 143 self.tacticalOverlayWasOpen = None 144 self.isDeploying = False 145 if self.entity: 146 self.entity.Close() 147 self.entity = None 148 self.destinationSolarsystemID = None 149 self._CleanupDeploymentBeacons() 150 151 def _CleanupDeploymentBeacons(self): 152 while self.deploymentBeacons: 153 beacon = self.deploymentBeacons.pop() 154 beacon.Close() 155 156 def ConfirmDeployment(self, reinforceWeekday, reinforceHour, profileID = None, structureName = '', bio = '', extraVariables = {}): 157 pos = self.entity.GetPosition() 158 rotation = self.entity.GetRotation() 159 extraConfig = KeyVal() 160 if evetypes.IsUpwellStargate(self.invItem.typeID): 161 destinationSolarsystemID = extraVariables['destinationSolarsystemID'] 162 extraConfig.destinationSolarsystemID = destinationSolarsystemID 163 sm.RemoteSvc('structureDeployment').Anchor(self.invItem.itemID, pos[0], pos[2], rotation[0], profileID, structureName, bio, reinforceWeekday, reinforceHour, extraConfig) 164 self._Cleanup() 165 sm.GetService('structureDirectory').Reload() 166 167 def CancelDeployment(self): 168 self._Cleanup() 169 170 def IsOnPositionStep(self): 171 if not self.wnd: 172 return False 173 return self.wnd.step == dUtil.STEP_POSITION 174 175 def StartMovingStructure(self): 176 self.isMovingStrucuture = True 177 self.entity.StartMoving() 178 179 def EndMovingStructure(self): 180 self.isMovingStrucuture = False 181 if self.entity: 182 self.entity.EndMoving() 183 184 def IsMovingStructure(self): 185 return self.isMovingStrucuture 186 187 def GetCaption(self): 188 return evetypes.GetName(self.invItem.typeID) 189 190 def GetSubCaption(self): 191 return 'Drag structure gantry with left mouse button and rotate with right' 192 193 def OnSessionChanged(self, *args): 194 self.CancelDeployment() 195 196 def OnItemChange(self, item, change, location): 197 if self.invItem and self.invItem.itemID == item.itemID: 198 self.CancelDeployment() 199 200 def OnViewStateChanged(self, *args): 201 self.CancelDeployment() 202 203 def OnClientEvent_WarpStarted(self, *args): 204 self.CancelDeployment() 205 206 def DoBallClear(self, *args): 207 self.CancelDeployment() 208 209 def MoveDragObject(self): 210 if self.entity: 211 self.entity.MoveDragObject() 212 213 def RotateDragObject(self): 214 if self.entity: 215 self.entity.RotateDragObject() 216 217 def GetEntity(self): 218 return self.entity 219 220 def GetDestinationSolarsystemID(self): 221 return self.destinationSolarsystemID 222 223 def SetDestinationSolarsystemID(self, solarSystemID): 224 self.destinationSolarsystemID = solarSystemID 225 yaw, pitch = GetAlignmentYawPitchRadians(session.solarsystemid, solarSystemID) 226 self.entity.SetModelRotation(yaw, pitch, 0) 227 sm.ScatterEvent('OnExtraDeploymentInfoChanged', {'destinationSolarsystemID': solarSystemID}) 228 229 def GetNearbyJumpBridges(self): 230 return self._GetNearbyJumpBridges(session.solarsystemid) 231 232 @Memoize(1) 233 def _GetNearbyJumpBridges(self, solarSystemID): 234 nearbyJumpBridges = sm.RemoteSvc('structureDirectory').GetNearbyJumpBridges() 235 return {x.solarSystemID:x for x in nearbyJumpBridges} 236 237 @Memoize 238 def GetSystemsInLightYearDistanceForJumpGateDict(self, solarSystemID): 239 return GetNonNpcNullSecSystemsInLightYearDistanceDict(solarSystemID, MAX_JUMPBRIDGE_RANGE_LIGHTYEARS)