public void SetTargetTree(ref MyEnvironmentItems.ItemInfo targetTree, long treesId) { VRage.Game.Entity.MyEntity entity; if (Sandbox.Game.Entities.MyEntities.TryGetEntityById(treesId, out entity, false)) { this.UnsetTarget(); this.SetMTargetPosition(targetTree.Transform.Position); this.m_targetEntity = entity; this.m_targetTreeId = targetTree.LocalId; this.SetTargetEntity(entity); } }
void OnSectorItemRemoved(MyEnvironmentItems item, MyEnvironmentItems.ItemInfo value) { foreach (var spawner in m_spawners) { spawner.Value.EnvironmentItems.Save = true; } if (m_saved == false) { m_planet.OnEnviromentSectorItemRemoved(m_pos); m_saved = true; } }
public virtual bool SetTargetFromMemory(MyBBMemoryTarget memoryTarget) { if (memoryTarget.TargetType == MyAiTargetEnum.POSITION) { if (memoryTarget.Position == null) { return(false); } this.SetTargetPosition(memoryTarget.Position.Value); return(true); } if (memoryTarget.TargetType == MyAiTargetEnum.ENVIRONMENT_ITEM) { if (memoryTarget.TreeId == null) { return(false); } MyEnvironmentItems.ItemInfo targetTree = new MyEnvironmentItems.ItemInfo { LocalId = memoryTarget.TreeId.Value, Transform = { Position = memoryTarget.Position.Value } }; this.SetTargetTree(ref targetTree, memoryTarget.EntityId.Value); return(true); } if (memoryTarget.TargetType == MyAiTargetEnum.NO_TARGET) { if (memoryTarget.TargetType == MyAiTargetEnum.NO_TARGET) { this.UnsetTarget(); return(true); } this.UnsetTarget(); return(false); } if (memoryTarget.EntityId == null) { return(false); } VRage.Game.Entity.MyEntity entity = null; if (!Sandbox.Game.Entities.MyEntities.TryGetEntityById(memoryTarget.EntityId.Value, out entity, false)) { this.UnsetTarget(); return(false); } if ((memoryTarget.TargetType == MyAiTargetEnum.CUBE) || (memoryTarget.TargetType == MyAiTargetEnum.COMPOUND_BLOCK)) { MySlimBlock cubeBlock = (entity as MyCubeGrid).GetCubeBlock(memoryTarget.BlockPosition); if (cubeBlock == null) { return(false); } if (memoryTarget.TargetType == MyAiTargetEnum.COMPOUND_BLOCK) { MySlimBlock block = (cubeBlock.FatBlock as MyCompoundCubeBlock).GetBlock(memoryTarget.CompoundId.Value); if (block == null) { return(false); } cubeBlock = block; this.m_compoundId = memoryTarget.CompoundId; } ushort?compoundId = null; this.SetTargetBlock(cubeBlock, compoundId); } else if (memoryTarget.TargetType == MyAiTargetEnum.ENTITY) { if ((memoryTarget.Position == null) || !(entity is MyFracturedPiece)) { this.SetMTargetPosition(entity.PositionComp.GetPosition()); } else { this.SetMTargetPosition(memoryTarget.Position.Value); } this.SetTargetEntity(entity); this.m_targetEntity = entity; } else if (memoryTarget.TargetType != MyAiTargetEnum.VOXEL) { this.SetTargetEntity(entity); } else { MyVoxelMap voxelMap = entity as MyVoxelMap; if (memoryTarget.Position == null) { return(false); } if (voxelMap == null) { return(false); } this.SetTargetVoxel(memoryTarget.Position.Value, voxelMap); this.m_targetEntity = voxelMap; } return(true); }
public virtual bool SetTargetFromMemory(MyBBMemoryTarget memoryTarget) { if (memoryTarget.TargetType == MyAiTargetEnum.POSITION) { Debug.Assert(memoryTarget.Position.HasValue, "Position was not set correctly in memory."); if (!memoryTarget.Position.HasValue) { return(false); } SetTargetPosition(memoryTarget.Position.Value); return(true); } else if (memoryTarget.TargetType == MyAiTargetEnum.ENVIRONMENT_ITEM) { Debug.Assert(memoryTarget.TreeId.HasValue, "Tree id was not set correctly in memory."); if (!memoryTarget.TreeId.HasValue) { return(false); } var tree = new MyEnvironmentItems.ItemInfo(); tree.LocalId = memoryTarget.TreeId.Value; tree.Transform.Position = memoryTarget.Position.Value; SetTargetTree(ref tree, memoryTarget.EntityId.Value); return(true); } else if (memoryTarget.TargetType != MyAiTargetEnum.NO_TARGET) { Debug.Assert(memoryTarget.EntityId.HasValue, "Entity id was not set correctly in memory."); if (!memoryTarget.EntityId.HasValue) { return(false); } MyEntity entity = null; if (MyEntities.TryGetEntityById(memoryTarget.EntityId.Value, out entity)) { if (memoryTarget.TargetType == MyAiTargetEnum.CUBE || memoryTarget.TargetType == MyAiTargetEnum.COMPOUND_BLOCK) { var cubeGrid = entity as MyCubeGrid; var cubeBlock = cubeGrid.GetCubeBlock(memoryTarget.BlockPosition); Debug.Assert(cubeBlock != null, "Invalid position for a block"); if (cubeBlock != null) { if (memoryTarget.TargetType == MyAiTargetEnum.COMPOUND_BLOCK) { var realBlock = (cubeBlock.FatBlock as MyCompoundCubeBlock).GetBlock(memoryTarget.CompoundId.Value); Debug.Assert(realBlock != null, "Block does not exist in the compound block"); if (realBlock == null) { return(false); } cubeBlock = realBlock; m_compoundId = memoryTarget.CompoundId; } SetTargetBlock(cubeBlock); } else { return(false); } } else if (memoryTarget.TargetType == MyAiTargetEnum.ENTITY) { if (memoryTarget.Position.HasValue && entity is MyFracturedPiece) { m_targetPosition = memoryTarget.Position.Value; } else { m_targetPosition = entity.PositionComp.GetPosition(); } SetTargetEntity(entity); m_targetEntity = entity; } else if (memoryTarget.TargetType == MyAiTargetEnum.VOXEL) { var voxelMap = entity as MyVoxelMap; Debug.Assert(memoryTarget.Position.HasValue, "Tree id was not set correctly in memory."); if (!memoryTarget.Position.HasValue) { return(false); } Debug.Assert(voxelMap != null, "Voxel map hasn't been set."); if (voxelMap == null) { return(false); } SetTargetVoxel(memoryTarget.Position.Value, voxelMap); m_targetEntity = voxelMap; } else { SetTargetEntity(entity); } return(true); } else { UnsetTarget(); return(false); } } else if (memoryTarget.TargetType == MyAiTargetEnum.NO_TARGET) { UnsetTarget(); return(true); } else { Debug.Assert(false, "Unrecognized type of target!"); UnsetTarget(); return(false); } }