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)) { if (ai.MIds[(int)packet.PType] < packet.MId) { ai.MIds[(int)packet.PType] = packet.MId; var rootConstruct = ai.Construct.RootAi.Construct; rootConstruct.Data.Repo.FocusData.Sync(ai, fociPacket.Data); } else { Log.Line($"ClientConstructFoci 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 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)) { var rootConstruct = ai.Construct.RootAi.Construct; if (rootConstruct.Data.Repo.FocusData.Revision < cgPacket.Data.FocusData.Revision) { rootConstruct.Data.Repo.Sync(rootConstruct, cgPacket.Data); rootConstruct.UpdateLeafs(); } else { Log.Line($"ClientConstructGroups Version failure - Version:{rootConstruct.Data.Repo.Version}({cgPacket.Data.Version})"); } 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 ClientQueueShot(PacketObj data) { var packet = data.Packet; var ent = MyEntities.GetEntityByIdOrDefault(packet.EntityId); var queueShot = (QueuedShotPacket)packet; var comp = ent?.Components.Get <WeaponComponent>(); if (comp?.Ai == null || comp.Platform.State != MyWeaponPlatform.PlatformState.Ready) { return(Error(data, Msg($"CompId: {packet.EntityId}", comp != null), Msg("Ai", comp?.Ai != null), Msg("Ai", comp?.Platform.State == MyWeaponPlatform.PlatformState.Ready))); } var w = comp.Platform.Weapons[queueShot.WeaponId]; w.ShootOnce = true; if (PlayerId == queueShot.PlayerId) { w.ClientStaticShot = true; } data.Report.PacketValid = true; 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); }
public override bool IsOverlapOverThreshold(BoundingBoxD worldAabb, float thresholdPercentage) { if (m_storage == null) { if (MyEntities.GetEntityByIdOrDefault(this.EntityId) != this) { MyDebug.FailRelease("Voxel map was deleted!"); } else { MyDebug.FailRelease("Voxel map is still in world but has null storage!"); } return(false); } //Debug.Assert( // worldAabb.Size.X > MyVoxelConstants.VOXEL_SIZE_IN_METRES && // worldAabb.Size.Y > MyVoxelConstants.VOXEL_SIZE_IN_METRES && // worldAabb.Size.Z > MyVoxelConstants.VOXEL_SIZE_IN_METRES, // "One of the sides of queried AABB is too small compared to voxel size. Results will be unreliable."); Vector3I minCorner, maxCorner; MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref worldAabb.Min, out minCorner); MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref worldAabb.Max, out maxCorner); minCorner += StorageMin; maxCorner += StorageMin; Storage.ClampVoxelCoord(ref minCorner); Storage.ClampVoxelCoord(ref maxCorner); m_tempStorage.Resize(minCorner, maxCorner); Storage.ReadRange(m_tempStorage, MyStorageDataTypeFlags.Content, 0, ref minCorner, ref maxCorner); BoundingBoxD voxelBox; //MyRenderProxy.DebugDrawAABB(worldAabb, Color.White, 1f, 1f, true); var invFullVoxel = 1.0 / (double)MyVoxelConstants.VOXEL_CONTENT_FULL_FLOAT; var voxelVolume = 1.0 / (double)MyVoxelConstants.VOXEL_VOLUME_IN_METERS; double overlapContentVolume = 0.0; var queryVolume = worldAabb.Volume; //using (var batch = MyRenderProxy.DebugDrawBatchAABB(Matrix.Identity, new Color(Color.Green, 0.1f), true, true)) { Vector3I coord, cache; for (coord.Z = minCorner.Z, cache.Z = 0; coord.Z <= maxCorner.Z; coord.Z++, cache.Z++) { for (coord.Y = minCorner.Y, cache.Y = 0; coord.Y <= maxCorner.Y; coord.Y++, cache.Y++) { for (coord.X = minCorner.X, cache.X = 0; coord.X <= maxCorner.X; coord.X++, cache.X++) { MyVoxelCoordSystems.VoxelCoordToWorldAABB(PositionLeftBottomCorner, ref coord, out voxelBox); if (worldAabb.Intersects(voxelBox)) { var contentVolume = m_tempStorage.Content(ref cache) * invFullVoxel * voxelVolume; var overlapVolume = worldAabb.Intersect(voxelBox).Volume; overlapContentVolume += contentVolume * overlapVolume; //batch.Add(ref voxelBox); } } } } } var overlapVolumePercentage = overlapContentVolume / queryVolume; //MyRenderProxy.DebugDrawText3D(worldAabb.Center, overlapVolumePercentage.ToString("0.000"), Color.White, 1f, false); return(overlapVolumePercentage >= thresholdPercentage); }
private void ChangeControlledClient(long entity, string slot, float randSeed) { ChangeSlotInternal(MyEntities.GetEntityByIdOrDefault(entity)?.Components.Get <EquiPlayerAttachmentComponent>()?.GetSlotOrDefault(slot), randSeed); }