// no storge sync private bool ClientClientMouseEvent(PacketObj data) { var packet = data.Packet; var mousePacket = (InputPacket)packet; if (mousePacket.Data == null) { return(Error(data, Msg("Data"))); } var cube = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeBlock; if (cube == null) { return(Error(data, Msg($"CubeId: {packet.EntityId}"))); } GridAi ai; long playerId; if (GridToMasterAi.TryGetValue(cube.CubeGrid, out ai) && SteamToPlayer.TryGetValue(packet.SenderId, out playerId)) { PlayerMouseStates[playerId] = mousePacket.Data; data.Report.PacketValid = true; } else { return(Error(data, Msg("No PlayerId Found"))); } return(true); }
private bool ClientConstructFoci(PacketObj data) { var packet = data.Packet; var myGrid = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid; var fociPacket = (ConstructFociPacket)packet; if (myGrid == null) { return(Error(data, Msg($"Grid: {packet.EntityId}"))); } GridAi ai; if (GridToMasterAi.TryGetValue(myGrid, out ai)) { var rootConstruct = ai.Construct.RootAi.Construct; if (rootConstruct.Data.Repo.FocusData.Revision < fociPacket.Data.Revision) { rootConstruct.Data.Repo.FocusData.Sync(ai, fociPacket.Data); } else { Log.Line($"ClientConstructFoci Version failure - Version:{rootConstruct.Data.Repo.FocusData.Revision}({fociPacket.Data.Revision})"); } data.Report.PacketValid = true; } else { return(Error(data, Msg($"GridAi not found, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}"))); } return(true); }
internal bool UpdateLocalAiAndCockpit() { InGridAiBlock = false; ActiveControlBlock = ControlledEntity as MyCubeBlock; var cockPit = ControlledEntity as MyCockpit; if (cockPit != null && cockPit.EnableShipControl) { ActiveCockPit = cockPit; } else { ActiveCockPit = null; } long oldBlockId; var activeBlock = ActiveCockPit ?? ActiveControlBlock; if (activeBlock != null && ActiveControlBlock != null && GridToMasterAi.TryGetValue(activeBlock.CubeGrid, out TrackingAi)) { InGridAiBlock = true; TrackingAi.Data.Repo.ControllingPlayers.TryGetValue(PlayerId, out oldBlockId); if (IsServer) { TrackingAi.Construct.UpdateConstructsPlayers(ActiveControlBlock, PlayerId, true); } if (HandlesInput && oldBlockId != ActiveControlBlock.EntityId) { SendActiveControlUpdate(TrackingAi, activeBlock, true); } } else { if (TrackingAi != null) { TrackingAi.Construct.Focus.ClientIsFocused(TrackingAi); MyCubeBlock oldBlock; if (TrackingAi.Data.Repo.ControllingPlayers.TryGetValue(PlayerId, out oldBlockId) && MyEntities.TryGetEntityById(oldBlockId, out oldBlock, true)) { if (IsServer) { TrackingAi.Construct.UpdateConstructsPlayers(ActiveControlBlock, PlayerId, false); } if (HandlesInput) { SendActiveControlUpdate(TrackingAi, oldBlock, false); } } } TrackingAi = null; ActiveCockPit = null; ActiveControlBlock = null; } return(InGridAiBlock); }
internal void ProccessServerPacketsForClients() { if ((!IsServer || !MpActive)) { Log.Line($"trying to process server packets on a non-server"); return; } PacketsToClient.AddRange(PrunedPacketsToClient.Values); for (int i = 0; i < PacketsToClient.Count; i++) { var packetInfo = PacketsToClient[i]; var bytes = MyAPIGateway.Utilities.SerializeToBinary(packetInfo.Packet); if (packetInfo.SingleClient) { MyModAPIHelper.MyMultiplayer.Static.SendMessageTo(ClientPacketId, bytes, packetInfo.Packet.SenderId, true); } else { long entityId = packetInfo.Entity?.GetTopMostParent().EntityId ?? -1; foreach (var p in Players.Values) { var notSender = p.SteamUserId != packetInfo.Packet.SenderId; var sendPacket = notSender && packetInfo.Entity == null; if (!sendPacket && notSender) { if (PlayerEntityIdInRange.ContainsKey(p.SteamUserId)) { if (PlayerEntityIdInRange[p.SteamUserId].Contains(entityId)) { sendPacket = true; } else { GridAi rootAi; var grid = packetInfo.Entity.GetTopMostParent() as MyCubeGrid; if (grid != null && GridToMasterAi.TryGetValue(grid, out rootAi) && PlayerEntityIdInRange[p.SteamUserId].Contains(rootAi.MyGrid.EntityId)) { sendPacket = true; } } } } if (sendPacket) { MyModAPIHelper.MyMultiplayer.Static.SendMessageTo(ClientPacketId, bytes, p.SteamUserId, true); } } } } ServerPacketsForClientsClean(); }
private void MenuOpened(object obj) { try { InMenu = true; GridAi ai; if (ActiveControlBlock != null && GridToMasterAi.TryGetValue(ActiveControlBlock.CubeGrid, out ai)) { //Send updates? } } catch (Exception ex) { Log.Line($"Exception in MenuOpened: {ex}"); } }
private bool ServerFocusUpdate(PacketObj data) { var packet = data.Packet; var focusPacket = (FocusPacket)packet; var myGrid = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid; if (myGrid == null) { return(Error(data, Msg("Grid"))); } GridAi ai; uint[] mIds; if (GridToMasterAi.TryGetValue(myGrid, out ai) && PlayerMIds.TryGetValue(packet.SenderId, out mIds) && mIds[(int)packet.PType] < packet.MId) { mIds[(int)packet.PType] = packet.MId; var targetGrid = MyEntities.GetEntityByIdOrDefault(focusPacket.TargetId) as MyCubeGrid; switch (packet.PType) { case PacketType.FocusUpdate: if (targetGrid != null) { ai.Construct.Focus.ServerAddFocus(targetGrid, ai); } break; case PacketType.NextActiveUpdate: ai.Construct.Focus.ServerNextActive(focusPacket.AddSecondary, ai); break; case PacketType.ReleaseActiveUpdate: ai.Construct.Focus.RequestReleaseActive(ai); break; case PacketType.FocusLockUpdate: ai.Construct.Focus.ServerCycleLock(ai); break; } data.Report.PacketValid = true; } else { return(Error(data, Msg($"GridAi not found or mid failure: ai:{ai != null}, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}"))); } return(true); }
internal void SetTarget(MyEntity entity, GridAi ai, Dictionary <MyEntity, float> masterTargets) { TrackingAi = ai; ai.Construct.Focus.RequestAddFocus(entity, ai); GridAi gridAi; TargetArmed = false; var grid = entity as MyCubeGrid; if (grid != null && GridToMasterAi.TryGetValue(grid, out gridAi)) { TargetArmed = true; } else { float offenseRating; if (!masterTargets.TryGetValue(entity, out offenseRating)) { return; } ConcurrentDictionary <BlockTypes, ConcurrentCachingList <MyCubeBlock> > typeDict; var tGrid = entity as MyCubeGrid; if (tGrid != null && GridToBlockTypeMap.TryGetValue(tGrid, out typeDict)) { ConcurrentCachingList <MyCubeBlock> fatList; if (typeDict.TryGetValue(Offense, out fatList)) { TargetArmed = fatList.Count > 0; } else { TargetArmed = false; } } else { TargetArmed = false; } } }
private bool ClientConstruct(PacketObj data) { var packet = data.Packet; var myGrid = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid; var cgPacket = (ConstructPacket)packet; if (myGrid == null) { return(Error(data, Msg($"Grid: {packet.EntityId}"))); } GridAi ai; if (GridToMasterAi.TryGetValue(myGrid, out ai)) { if (ai.MIds[(int)packet.PType] < packet.MId) { ai.MIds[(int)packet.PType] = packet.MId; var rootConstruct = ai.Construct.RootAi.Construct; rootConstruct.Data.Repo.Sync(rootConstruct, cgPacket.Data); rootConstruct.UpdateLeafs(); } else { Log.Line($"ClientConstructGroups MID failure - mId:{packet.MId}"); } data.Report.PacketValid = true; } else { return(Error(data, Msg($"GridAi not found, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}"))); } return(true); }
private bool ServerActiveControlUpdate(PacketObj data) { var packet = data.Packet; var dPacket = (BoolUpdatePacket)packet; var cube = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeBlock; if (cube == null) { return(Error(data, Msg("Cube"))); } GridAi ai; long playerId = 0; if (GridToMasterAi.TryGetValue(cube.CubeGrid, out ai) && SteamToPlayer.TryGetValue(packet.SenderId, out playerId)) { uint[] mIds; if (PlayerMIds.TryGetValue(packet.SenderId, out mIds) && mIds[(int)packet.PType] < packet.MId) { mIds[(int)packet.PType] = packet.MId; ai.Construct.UpdateConstructsPlayers(cube, playerId, dPacket.Data); data.Report.PacketValid = true; } else { Log.Line($"ServerActiveControlUpdate: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}"); } } else { Log.Line($"ServerActiveControlUpdate: ai:{ai != null} - targetingAi:{GridTargetingAIs.ContainsKey(cube.CubeGrid)} - masterAi:{GridToMasterAi.ContainsKey(cube.CubeGrid)} - IdToComp:{IdToCompMap.ContainsKey(cube.EntityId)} - {cube.BlockDefinition.Id.SubtypeName} - playerId:{playerId}({packet.SenderId}) - marked:{cube.MarkedForClose}({cube.CubeGrid.MarkedForClose}) - active:{dPacket.Data}"); } return(true); }
internal void PurgeAll() { PurgedAll = true; FutureEvents.Purge((int)Tick); foreach (var comp in CompsToStart) { if (comp?.Platform != null) { CloseComps(comp.MyCube); } } foreach (var readd in CompReAdds) { if (!readd.Ai.Closed) { readd.Ai.AiForceClose(); } if (readd.Comp?.Platform != null) { CloseComps(readd.Comp.MyCube); } } foreach (var comp in CompsDelayed) { if (comp?.Platform != null) { CloseComps(comp.MyCube); } } foreach (var gridAi in DelayedAiClean) { if (!gridAi.Closed) { gridAi.AiForceClose(); } } PlatFormPool.Clean(); CompsToStart.ClearImmediate(); DelayedAiClean.ClearImmediate(); CompsDelayed.Clear(); CompReAdds.Clear(); GridAiPool.Clean(); PurgeTerminalSystem(this); HudUi.Purge(); TerminalMon.Purge(); foreach (var reports in Reporter.ReportData.Values) { foreach (var report in reports) { report.Clean(); Reporter.ReportPool.Return(report); } reports.Clear(); } Reporter.ReportData.Clear(); Reporter.ReportPool.Clean(); PacketsToClient.Clear(); PacketsToServer.Clear(); AcqManager.Clean(); CleanSounds(true); foreach (var e in Emitters) { e.StopSound(true); } foreach (var e in Av.HitEmitters) { e.StopSound(true); } foreach (var e in Av.FireEmitters) { e.StopSound(true); } foreach (var e in Av.TravelEmitters) { e.StopSound(true); } Emitters.Clear(); Av.HitEmitters.Clear(); Av.FireEmitters.Clear(); Av.TravelEmitters.Clear(); foreach (var item in EffectedCubes) { var cubeid = item.Key; var blockInfo = item.Value; var functBlock = blockInfo.FunctBlock; if (functBlock == null || functBlock.MarkedForClose) { _effectPurge.Enqueue(cubeid); continue; } functBlock.EnabledChanged -= ForceDisable; functBlock.Enabled = blockInfo.FirstState; functBlock.SetDamageEffect(false); if (HandlesInput) { functBlock.AppendingCustomInfo -= blockInfo.AppendCustomInfo; } _effectPurge.Enqueue(cubeid); } while (_effectPurge.Count != 0) { EffectedCubes.Remove(_effectPurge.Dequeue()); } Av.Glows.Clear(); Av.AvShotPool.Clean(); DeferedUpBlockTypeCleanUp(true); BlockTypeCleanUp.Clear(); foreach (var map in GridToInfoMap.Keys) { RemoveGridFromMap(map); } GridToInfoMap.Clear(); GridMapPool.Clean(); DirtyGridsTmp.Clear(); foreach (var structure in WeaponPlatforms.Values) { foreach (var system in structure.WeaponSystems) { system.Value.PreFirePairs.Clear(); system.Value.FireWhenDonePairs.Clear(); system.Value.FirePerShotPairs.Clear(); system.Value.RotatePairs.Clear(); system.Value.ReloadPairs.Clear(); foreach (var ammo in system.Value.AmmoTypes) { ammo.AmmoDef.Const.PrimeEntityPool?.Clean(); ammo.AmmoDef.Const.HitDefaultSoundPairs.Clear(); ammo.AmmoDef.Const.HitVoxelSoundPairs.Clear(); ammo.AmmoDef.Const.HitShieldSoundPairs.Clear(); ammo.AmmoDef.Const.HitFloatingSoundPairs.Clear(); ammo.AmmoDef.Const.HitPlayerSoundPairs.Clear(); ammo.AmmoDef.Const.TravelSoundPairs.Clear(); ammo.AmmoDef.Const.CustomSoundPairs.Clear(); } } structure.WeaponSystems.Clear(); } WeaponPlatforms.Clear(); foreach (var gridToMap in GridToBlockTypeMap) { foreach (var map in gridToMap.Value) { ConcurrentListPool.Return(map.Value); } gridToMap.Value.Clear(); BlockTypePool.Return(gridToMap.Value); } GridToBlockTypeMap.Clear(); foreach (var playerGrids in PlayerEntityIdInRange) { playerGrids.Value.Clear(); } PlayerEntityIdInRange.Clear(); DirtyGridInfos.Clear(); DsUtil.Purge(); DsUtil2.Purge(); ShootingWeapons.Clear(); WeaponToPullAmmo.Clear(); AmmoToPullQueue.Clear(); ChargingWeaponsIndexer.Clear(); WeaponsToRemoveAmmoIndexer.Clear(); ChargingWeapons.Clear(); Hits.Clear(); HomingWeapons.Clear(); GridToMasterAi.Clear(); Players.Clear(); IdToCompMap.Clear(); AllArmorBaseDefinitions.Clear(); HeavyArmorBaseDefinitions.Clear(); AllArmorBaseDefinitions.Clear(); AcquireTargets.Clear(); LargeBlockSphereDb.Clear(); SmallBlockSphereDb.Clear(); AnimationsToProcess.Clear(); _subTypeIdToWeaponDefs.Clear(); WeaponDefinitions.Clear(); SlimsSortedList.Clear(); _destroyedSlims.Clear(); _destroyedSlimsClient.Clear(); _slimHealthClient.Clear(); _slimsSet.Clear(); _turretDefinitions.Clear(); _tmpNearByBlocks.Clear(); foreach (var av in Av.AvShots) { av.GlowSteps.Clear(); Av.AvShotPool.Return(av); } Av.AvShotPool.Clean(); Av.AvBarrels1.Clear(); Av.AvBarrels2.Clear(); Av.AvShots.Clear(); Av.HitSounds.Clear(); foreach (var errorpkt in ClientSideErrorPkt) { errorpkt.Packet.CleanUp(); } ClientSideErrorPkt.Clear(); GridEffectPool.Clean(); GridEffectsPool.Clean(); BlockTypePool.Clean(); ConcurrentListPool.Clean(); TargetInfoPool.Clean(); PacketObjPool.Clean(); InventoryMoveRequestPool.Clean(); WeaponCoreBlockDefs.Clear(); VanillaIds.Clear(); VanillaCoreIds.Clear(); WeaponCoreFixedBlockDefs.Clear(); WeaponCoreTurretBlockDefs.Clear(); VoxelCaches.Clear(); ArmorCubes.Clear(); foreach (var p in Projectiles.ProjectilePool) { p.Info?.AvShot?.AmmoEffect?.Stop(); } Projectiles.ShrapnelToSpawn.Clear(); Projectiles.ShrapnelPool.Clean(); Projectiles.FragmentPool.Clean(); Projectiles.ActiveProjetiles.Clear(); Projectiles.ProjectilePool.Clear(); Projectiles.HitEntityPool.Clean(); Projectiles.VirtInfoPool.Clean(); DbsToUpdate.Clear(); GridTargetingAIs.Clear(); DsUtil = null; DsUtil2 = null; SlimsSortedList = null; Settings = null; StallReporter = null; TerminalMon = null; Physics = null; Camera = null; Projectiles = null; TrackingAi = null; UiInput = null; TargetUi = null; Placer = null; TargetGps = null; SApi.Unload(); SApi = null; Api = null; ApiServer = null; Reporter = null; WeaponDefinitions = null; AnimationsToProcess = null; ProjectileTree.Clear(); ProjectileTree = null; Av = null; HudUi = null; AllDefinitions = null; SoundDefinitions = null; ActiveCockPit = null; ActiveControlBlock = null; ControlledEntity = null; TmpStorage = null; }
private bool ClientAiDataUpdate(PacketObj data) { var packet = data.Packet; var myGrid = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid; var aiSyncPacket = (AiDataPacket)packet; if (myGrid == null) { return(Error(data, Msg($"Grid: {packet.EntityId}"))); } GridAi ai; if (GridTargetingAIs.TryGetValue(myGrid, out ai)) { if (ai.MIds[(int)packet.PType] < packet.MId) { ai.MIds[(int)packet.PType] = packet.MId; ai.Data.Repo.Sync(aiSyncPacket.Data); } else { Log.Line($"ClientAiDataUpdate: mid fail - senderId:{packet.SenderId} - mId:{ai.MIds[(int)packet.PType]} >= {packet.MId}"); } data.Report.PacketValid = true; } else { return(Error(data, Msg($"GridAi not found, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}"))); } return(true); }
private bool ServerMarkedTargetUpdate(PacketObj data) { var packet = data.Packet; var targetPacket = (FakeTargetPacket)packet; var myGrid = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeGrid; if (myGrid == null) { return(Error(data, Msg($"GridId:{packet.EntityId} - entityExists:{MyEntities.EntityExists(packet.EntityId)}"))); } GridAi ai; long playerId; if (GridTargetingAIs.TryGetValue(myGrid, out ai) && SteamToPlayer.TryGetValue(packet.SenderId, out playerId)) { GridAi.FakeTargets fakeTargets; uint[] mIds; if (PlayerMIds.TryGetValue(packet.SenderId, out mIds) && mIds[(int)packet.PType] < packet.MId && PlayerDummyTargets.TryGetValue(playerId, out fakeTargets)) { mIds[(int)packet.PType] = packet.MId; fakeTargets.PaintedTarget.Sync(targetPacket, ai); PacketsToClient.Add(new PacketInfo { Entity = myGrid, Packet = targetPacket }); data.Report.PacketValid = true; } else { Log.Line($"ServerFakeTargetUpdate: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}"); } } else { return(Error(data, Msg($"GridAi not found, is marked:{myGrid.MarkedForClose}, has root:{GridToMasterAi.ContainsKey(myGrid)}"))); } return(true); }
private void UpdatePlacer() { if (!Placer.Visible) { Placer = null; } if (!MyCubeBuilder.Static.DynamicMode && MyCubeBuilder.Static.HitInfo.HasValue) { var hit = MyCubeBuilder.Static.HitInfo.Value as IHitInfo; var grid = hit.HitEntity as MyCubeGrid; GridAi gridAi; if (grid != null && GridToMasterAi.TryGetValue(grid, out gridAi)) { if (MyCubeBuilder.Static.CurrentBlockDefinition != null) { var subtypeIdHash = MyCubeBuilder.Static.CurrentBlockDefinition.Id.SubtypeId; WeaponCount weaponCount; if (gridAi.WeaponCounter.TryGetValue(subtypeIdHash, out weaponCount)) { if (weaponCount.Max > 0 && gridAi.Construct.GetWeaponCount(subtypeIdHash) >= weaponCount.Max) { MyCubeBuilder.Static.NotifyPlacementUnable(); MyCubeBuilder.Static.Deactivate(); return; } } if (WeaponAreaRestrictions.ContainsKey(subtypeIdHash)) { MyOrientedBoundingBoxD restrictedBox; MyOrientedBoundingBoxD buildBox = MyCubeBuilder.Static.GetBuildBoundingBox(); BoundingSphereD restrictedSphere; if (IsWeaponAreaRestricted(subtypeIdHash, buildBox, grid, 0, null, out restrictedBox, out restrictedSphere)) { DsDebugDraw.DrawBox(buildBox, _uninitializedColor); } if (MyAPIGateway.Session.Config.HudState == 1) { if (restrictedBox.HalfExtent.AbsMax() > 0) { DsDebugDraw.DrawBox(restrictedBox, _restrictionAreaColor); } if (restrictedSphere.Radius > 0) { DsDebugDraw.DrawSphere(restrictedSphere, _restrictionAreaColor); } for (int i = 0; i < gridAi.Weapons.Count; i++) { MyOrientedBoundingBoxD b; BoundingSphereD s; CoreComponent Comp = gridAi.Weapons[i]; MyOrientedBoundingBoxD blockBox; SUtils.GetBlockOrientedBoundingBox(Comp.MyCube, out blockBox); CalculateRestrictedShapes(Comp.MyCube.BlockDefinition.Id.SubtypeId, blockBox, out b, out s); if (s.Radius > 0) { DsDebugDraw.DrawSphere(s, _restrictionAreaColor); } if (b.HalfExtent.AbsMax() > 0) { DsDebugDraw.DrawBox(b, _restrictionAreaColor); } } } } } } } }
public bool IsWeaponAreaRestricted(MyStringHash subtype, MyOrientedBoundingBoxD cubeBoundingBox, MyCubeGrid myGrid, long ignoredEntity, GridAi gridAi, out MyOrientedBoundingBoxD restrictedBox, out BoundingSphereD restrictedSphere) { _tmpNearByBlocks.Clear(); GridAi ai; if (gridAi == null) { if (!GridToMasterAi.ContainsKey(myGrid)) { restrictedSphere = new BoundingSphereD(); restrictedBox = new MyOrientedBoundingBoxD(); return(false); } ai = GridToMasterAi[myGrid]; } else { ai = gridAi; } CalculateRestrictedShapes(subtype, cubeBoundingBox, out restrictedBox, out restrictedSphere); var queryRadius = Math.Max(restrictedBox.HalfExtent.AbsMax(), restrictedSphere.Radius); if (queryRadius < 0.01) { return(false); } var restriction = WeaponAreaRestrictions[subtype]; var checkBox = restriction.RestrictionBoxInflation > 0; var checkSphere = restriction.RestrictionRadius > 0; var querySphere = new BoundingSphereD(cubeBoundingBox.Center, queryRadius); myGrid.Hierarchy.QuerySphere(ref querySphere, _tmpNearByBlocks); foreach (var grid in ai.SubGrids) { if (grid == myGrid || !GridTargetingAIs.ContainsKey(grid)) { continue; } grid.Hierarchy.QuerySphere(ref querySphere, _tmpNearByBlocks); } for (int l = 0; l < _tmpNearByBlocks.Count; l++) { var cube = _tmpNearByBlocks[l] as MyCubeBlock; if (cube == null || cube.EntityId == ignoredEntity || !WeaponCoreBlockDefs.ContainsKey(cube.BlockDefinition.Id.SubtypeId.String)) { continue; } if (!restriction.CheckForAnyWeapon && cube.BlockDefinition.Id.SubtypeId != subtype) { continue; } if (checkBox) { var cubeBox = new MyOrientedBoundingBoxD(cube.PositionComp.LocalAABB, cube.PositionComp.WorldMatrixRef); if (restrictedBox.Contains(ref cubeBox) != ContainmentType.Disjoint) { return(true); } } if (checkSphere && restrictedSphere.Contains(cube.PositionComp.WorldAABB) != ContainmentType.Disjoint) { return(true); } } return(false); }
internal bool UpdateLocalAiAndCockpit() { InGridAiBlock = false; ActiveControlBlock = ControlledEntity as MyCubeBlock; ActiveCockPit = ActiveControlBlock as MyCockpit; var activeBlock = ActiveCockPit ?? ActiveControlBlock; if (activeBlock != null && (GridTargetingAIs.TryGetValue(activeBlock.CubeGrid, out TrackingAi) || GridToMasterAi.TryGetValue(activeBlock.CubeGrid, out TrackingAi))) { InGridAiBlock = true; MyCubeBlock oldBlock; TrackingAi.ControllingPlayers.TryGetValue(PlayerId, out oldBlock); TrackingAi.ControllingPlayers[PlayerId] = ActiveControlBlock; TrackingAi.ControllingPlayers.ApplyAdditionsAndModifications(); if (HandlesInput && oldBlock != ActiveControlBlock) { SendActiveControlUpdate(activeBlock, true); } } else { if (TrackingAi != null) { TrackingAi.Focus.IsFocused(TrackingAi); MyCubeBlock oldBlock; if (HandlesInput && TrackingAi.ControllingPlayers.TryGetValue(PlayerId, out oldBlock)) { SendActiveControlUpdate(oldBlock, false); } TrackingAi.ControllingPlayers.Remove(PlayerId, true); TrackingAi.ControllingPlayers.ApplyRemovals(); } TrackingAi = null; ActiveCockPit = null; ActiveControlBlock = null; } return(InGridAiBlock); }
internal bool UpdateLocalAiAndCockpit() { InGridAiBlock = false; ActiveControlBlock = ControlledEntity as MyCubeBlock; var cockPit = ControlledEntity as MyCockpit; if (cockPit != null && cockPit.EnableShipControl) { ActiveCockPit = cockPit; } else { ActiveCockPit = null; } long oldBlockId; var activeBlock = ActiveCockPit ?? ActiveControlBlock; if (activeBlock != null && ActiveControlBlock != null && GridToMasterAi.TryGetValue(activeBlock.CubeGrid, out TrackingAi)) { var camera = Session.CameraController?.Entity as MyCameraBlock; if (camera == null || !GroupedCamera(camera)) { ActiveCameraBlock = null; } InGridAiBlock = true; TrackingAi.Data.Repo.ControllingPlayers.TryGetValue(PlayerId, out oldBlockId); if (IsServer) { TrackingAi.Construct.UpdateConstructsPlayers(ActiveControlBlock, PlayerId, true); } if (oldBlockId != ActiveControlBlock.EntityId) { SendActiveControlUpdate(TrackingAi, activeBlock, true); TargetLeadUpdate(); } else if (LeadGroupsDirty || !MyUtils.IsEqual(LastOptimalDps, TrackingAi.Construct.OptimalDps)) { TargetLeadUpdate(); } } else { if (TrackingAi != null) { TrackingAi.Construct.Focus.ClientIsFocused(TrackingAi); MyCubeBlock oldBlock; if (TrackingAi.Data.Repo.ControllingPlayers.TryGetValue(PlayerId, out oldBlockId) && MyEntities.TryGetEntityById(oldBlockId, out oldBlock, true)) { if (IsServer) { TrackingAi.Construct.UpdateConstructsPlayers(ActiveControlBlock, PlayerId, false); } SendActiveControlUpdate(TrackingAi, oldBlock, false); foreach (var list in LeadGroups) { list.Clear(); } LeadGroupActive = false; } } TrackingAi = null; ActiveCockPit = null; ActiveControlBlock = null; ActiveCameraBlock = null; } return(InGridAiBlock); }