private long SpawnInventoryContainer(MyDefinitionId bagDefinition) { MyEntity builder = Character; var worldMatrix = Character.WorldMatrix; worldMatrix.Translation += worldMatrix.Up + worldMatrix.Forward; MyObjectBuilder_EntityBase bagBuilder = new MyObjectBuilder_EntityBase(); var position = new MyPositionAndOrientation(worldMatrix); bagBuilder.PositionAndOrientation = position; bagBuilder.EntityId = MyEntityIdentifier.AllocateId(); var entity = MyEntities.CreateAndAddFromDefinition(bagBuilder, bagDefinition); entity.Physics.ClearSpeed(); entity.Physics.ForceActivate(); entity.NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME; MyTimerComponent timerComponent = new MyTimerComponent(); timerComponent.SetRemoveEntityTimer(1440); entity.GameLogic = timerComponent; MySyncCreate.SendEntityCreated(entity.GetObjectBuilder(), bagDefinition); return(entity.EntityId); }
public static IMyVoxelMap SpawnAsteroid(MyPositionAndOrientation pos, CompositeShapeProviderBuilder provider) { var storage = new OctreeStorageBuilder(provider, MyVoxelCoordSystems.FindBestOctreeSize(provider.Size)); var storageName = $"proc_astr_{provider.Seed}_{provider.Size}_{(long) pos.Position.X}_{(long) pos.Position.Y}_{(long) pos.Position.Z}"; var entityID = GetAsteroidEntityId(storageName); IMyEntity currEntity; if (MyAPIGateway.Entities.TryGetEntityById(entityID, out currEntity)) { return(currEntity as IMyVoxelMap); } var data = storage.GetCompressedData(); var storageInstance = MyAPIGateway.Session.VoxelMaps.CreateStorage(data); var entity = MyAPIGateway.Session.VoxelMaps.CreateVoxelMap(storageName, storageInstance, pos.Position, entityID); entity.Save = false; var realEntity = entity as MyEntity; if (realEntity == null) { return(entity); } MyEntities.RaiseEntityCreated(realEntity); MyEntities.Add(realEntity); return(entity); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { if (objectBuilder != null) { if (objectBuilder.PositionAndOrientation != null) { MyPositionAndOrientation orientation = objectBuilder.PositionAndOrientation.Value; MatrixD worldMatrix = MatrixD.CreateWorld((Vector3D)orientation.Position, (Vector3)orientation.Forward, (Vector3)orientation.Up); base.Container.Entity.PositionComp.SetWorldMatrix(worldMatrix, null, false, true, true, false, false, false); } if (objectBuilder.EntityId != 0) { base.Container.Entity.EntityId = objectBuilder.EntityId; } base.Container.Entity.Name = objectBuilder.Name; base.Container.Entity.Render.PersistentFlags = objectBuilder.PersistentFlags; } this.AllocateEntityID(); base.Container.Entity.InScene = false; MyEntities.SetEntityName(this.m_entity, false); if (this.m_entity.SyncFlag) { this.m_entity.CreateSync(); } this.GameLogic.Init(objectBuilder); }
public BaseEntity(MyObjectBuilder_EntityBase baseEntity) : base(baseEntity) { if (baseEntity != null) { m_entityId = baseEntity.EntityId; if (baseEntity.PositionAndOrientation != null) { m_positionOrientation = baseEntity.PositionAndOrientation.GetValueOrDefault( ); } else { m_positionOrientation = new MyPositionAndOrientation( ); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3D(-500000, -500000, -500000), new Vector3D(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } } else { m_entityId = 0; m_positionOrientation = new MyPositionAndOrientation( ); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } m_linearVelocity = new Vector3(0, 0, 0); m_angularVelocity = new Vector3(0, 0, 0); m_maxLinearVelocity = (float)104.7; }
public void AddItemExecuted() { var model = new GenerateFloatingObjectModel(); var position = new MyPositionAndOrientation(Vector3D.Zero, Vector3.Forward, Vector3.Up); var settings = SpaceEngineersCore.WorldResource.Checkpoint.Settings; model.Load(position, settings.MaxFloatingObjects); var loadVm = new GenerateFloatingObjectViewModel(this, model); var result = _dialogService.ShowDialog <WindowGenerateFloatingObject>(this, loadVm); if (result == true) { var newEntities = loadVm.BuildEntities(); if (loadVm.IsValidItemToImport) { for (var i = 0; i < newEntities.Length; i++) { var item = ((MyObjectBuilder_FloatingObject)newEntities[i]).Item; _dataModel.Additem(item); } // TODO: need to bubble change up to MainViewModel.IsModified = true; } } }
private void removePilotToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Sector sector = (MyObjectBuilder_Sector)node.Parent.Parent.Tag; Console.WriteLine("in method"); if (node.Nodes.ContainsKey("Pilot")) { Console.WriteLine("Contains Pilot"); TreeNode pilotNode = node.Nodes[node.Nodes.IndexOfKey("Pilot")]; MyObjectBuilder_Cockpit cockpit = (MyObjectBuilder_Cockpit)pilotNode.Tag; long Pilot_id = 0; if (cockpit.Pilot != null) { DialogResult dialogResult = MessageBox.Show("Overwrite \"" + SectorTree.SelectedNode.Parent.Parent.Text + "\"?", "Save", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { MyObjectBuilder_Character pilot = (MyObjectBuilder_Character)cockpit.Pilot; MyObjectBuilder_Character newPilot = (MyObjectBuilder_Character)pilot.Clone(); MyPositionAndOrientation newpos = (MyPositionAndOrientation)newPilot.PositionAndOrientation; newpos.Position.X = 0; newpos.Position.Y = 0; newpos.Position.Z = 0; newPilot.PositionAndOrientation = newpos; newPilot.AutoenableJetpackDelay = 0; newPilot.JetpackEnabled = true; newPilot.Battery.ProducerEnabled = true; cockpit.Pilot = null; sector.SectorObjects.Add(newPilot); Pilot_id = newPilot.EntityId; string file = Path.Combine(this.saves_path, SectorTree.SelectedNode.Parent.Parent.Text, "SANDBOX_0_0_0_.sbs"); string backupfile = Path.Combine(this.saves_path, SectorTree.SelectedNode.Parent.Parent.Text, "SANDBOX_0_0_0_.BAK2"); if (File.Exists(backupfile)) { File.Delete(backupfile); } File.Move(file, backupfile); label1.Text = "Saving..."; MyObjectBuilder_Sector mySector = (MyObjectBuilder_Sector)SectorTree.SelectedNode.Parent.Parent.Tag; using (FileStream sr = File.Open(file, FileMode.Create)) { MyObjectBuilder_Base.SerializeXML(sr, mySector); sr.Dispose(); } //now update the sbc file String sbcfile = Path.Combine(this.saves_path, node.Parent.Parent.Text, "Sandbox.sbc"); XDocument sbcFile = XDocument.Load(sbcfile); sbcFile.Root.SetElementValue("ControlledObject", Pilot_id); sbcFile.Save(sbcfile); this.create_tree(node.Parent.Parent, mySector); label1.Text = ""; } else { return; } } } }
private long SpawnInventoryContainer(MyPhysicalItemDefinition bagDefinition) { MyEntity builder = Character; var worldMatrix = Character.WorldMatrix; worldMatrix.Translation += worldMatrix.Up + worldMatrix.Forward; MyObjectBuilder_EntityBase bagBuilder = new MyObjectBuilder_EntityBase(); bagBuilder.Name = bagDefinition.DisplayNameText; var position = new MyPositionAndOrientation(worldMatrix); bagBuilder.PositionAndOrientation = position; bagBuilder.EntityId = MyEntityIdentifier.AllocateId(); bagBuilder.SubtypeName = bagDefinition.Id.SubtypeName; var entity = MyEntities.CreateAndAddFromDefinition(bagBuilder, bagDefinition); entity.Physics.ForceActivate(); entity.Physics.ApplyImpulse(builder.Physics.LinearVelocity, Vector3.Zero); MySyncCreate.SendEntityCreated(entity.GetObjectBuilder(), bagDefinition.Id); return(entity.EntityId); }
public BaseEntity(MyObjectBuilder_EntityBase baseEntity) : base(baseEntity) { if (baseEntity != null) { m_entityId = baseEntity.EntityId; if (baseEntity.PositionAndOrientation != null) { m_positionOrientation = baseEntity.PositionAndOrientation.GetValueOrDefault(); } else { m_positionOrientation = new MyPositionAndOrientation(); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } } else { m_entityId = 0; m_positionOrientation = new MyPositionAndOrientation(); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } m_linearVelocity = new Vector3(0, 0, 0); m_angularVelocity = new Vector3(0, 0, 0); m_maxLinearVelocity = (float)104.7; }
public void SendPilotRelativeEntryUpdate(ref MyPositionAndOrientation relativeEntry) { UpdatePilotRelativeEntryMsg msg; msg.EntityId = m_shipController.EntityId; msg.RelativeEntry = relativeEntry; MySession.Static.SyncLayer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success); }
static void CreateNewPlaceArea(SerializableDefinitionId id, MyPositionAndOrientation positionAndOrientation) { MyObjectBuilder_AreaMarker objectBuilder = (MyObjectBuilder_AreaMarker)MyObjectBuilderSerializer.CreateNewObject(id); objectBuilder.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; objectBuilder.PositionAndOrientation = positionAndOrientation; MyEntities.CreateFromObjectBuilderAndAdd(objectBuilder); }
private void RaisePilotRelativeEntryUpdated(MyPositionAndOrientation relativeEntry) { var handler = PilotRelativeEntryUpdated; if (handler != null) { handler(relativeEntry); } }
public override void Init(MyObjectBuilder_WorldGeneratorOperation builder) { base.Init(builder); var ob = builder as MyObjectBuilder_WorldGeneratorOperation_AddShipPrefab; PrefabFile = ob.PrefabFile; Transform = ob.Transform; RandomRadius = ob.RandomRadius; }
public void Rotation() { var positionAndOrientation = new MyPositionAndOrientation( new SerializableVector3D(10.0d, -10.0d, -2.5d), new SerializableVector3(0.0f, 0.0f, -1.0f), new SerializableVector3(0.0f, 1.0f, 0.0f)); // -90 around Z var quaternion = Quaternion.CreateFromYawPitchRoll(0, 0, -VRageMath.MathHelper.PiOver2); var o = positionAndOrientation.ToQuaternion() * quaternion; var on = Quaternion.Normalize(o); Matrix m = on.ToMatrix(); m = Matrix.Round(ref m); var p = new MyPositionAndOrientation(m); var quaternion2 = QuaternionD.CreateFromYawPitchRoll(0, 0, -Math.PI / 2); var o2 = positionAndOrientation.ToQuaternionD() * quaternion2; var on2 = QuaternionD.Normalize(o2); var p2 = new MyPositionAndOrientation(on2.ToMatrixD()); var quaternion3 = new System.Windows.Media.Media3D.Quaternion(new System.Windows.Media.Media3D.Vector3D(0, 0, 1), -90d); var x3 = positionAndOrientation.ToQuaternionD(); var o3 = new System.Windows.Media.Media3D.Quaternion(x3.X, x3.Y, x3.Z, x3.W) * quaternion3; var on3 = o3; on3.Normalize(); double num = on3.X * on3.X; double num3 = on3.Z * on3.Z; double num4 = on3.X * on3.Y; double num5 = on3.Z * on3.W; double num8 = on3.Y * on3.Z; double num9 = on3.X * on3.W; var M21 = (2.0d * (num4 - num5)); var M22 = (1.0d - 2.0d * (num3 + num)); var M23 = (2.0d * (num8 + num9)); var up3 = new Vector3D(M21, M22, M23); var fwd = new SerializableVector3(0.0f, 0.0f, -1.0f); var up = new SerializableVector3(1.0f, 0.0f, 0.0f); Assert.AreEqual(fwd.X, p.Forward.X, "Forward.X Should Equal"); Assert.AreEqual(fwd.Y, p.Forward.Y, "Forward.Y Should Equal"); Assert.AreEqual(fwd.Z, p.Forward.Z, "Forward.Z Should Equal"); Assert.AreEqual(up.X, p.Up.X, "Up.X Should Equal"); Assert.AreEqual(up.Y, p.Up.Y, "Up.Y Should Equal"); Assert.AreEqual(up.Z, p.Up.Z, "Up.Z Should Equal"); }
private void cloneToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Base myBase = (MyObjectBuilder_Base)node.Tag; if (myBase.TypeId == MyObjectBuilderTypeEnum.CubeGrid) { MyObjectBuilder_CubeGrid myGrid = this.clone_grid((MyObjectBuilder_CubeGrid)myBase); MyPositionAndOrientation myGridPos = (MyPositionAndOrientation)myGrid.PositionAndOrientation; myGridPos.Position.X = myGridPos.Position.X + 100; node.Parent.Nodes.Add(newCubeGridNode(myGrid)); } }
private void Create(List <MyObjectBuilder_CubeGrid> grids) { Vector3D centerSum = new Vector3D(); MatrixD mRef = reference.WorldMatrix; MatrixD mRefNI = MatrixD.Normalize(MatrixD.Invert(mRef)); obbs = new List <MyOrientedBoundingBoxD>(grids.Count); orientation = new GridOrientation(reference); entityIds = new HashSet <long>(); foreach (MyObjectBuilder_CubeGrid grid in grids) { entityIds.Add(grid.EntityId); Vector3I min = Vector3I.MaxValue; Vector3I max = Vector3I.MinValue; foreach (MyObjectBuilder_CubeBlock cube in grid.CubeBlocks) { min = Vector3I.Min(min, cube.Min); max = Vector3I.Max(max, ComputeMax(cube)); } double cubeGridSize = grid.GridSizeEnum == MyCubeSize.Large ? 2.5 : 0.5; Vector3D pMin = min * cubeGridSize - (cubeGridSize * 0.5); Vector3D pMax = max * cubeGridSize + (cubeGridSize * 0.5); MyPositionAndOrientation pos = grid.PositionAndOrientation.Value; Vector3D center = Vector3D.Transform((pMin + pMax) * 0.5, pos.GetMatrix()); centerSum += center; MyOrientedBoundingBoxD box = new MyOrientedBoundingBoxD(center, (pMax - pMin) * 0.5, pos.Orientation); obbs.Add(box); orientation.Include(MatrixD.CreateWorld(center, pos.Forward, pos.Up)); } centerSum /= obbs.Count; relativeCenter = Vector3D.TransformNormal(centerSum - mRef.Translation, MatrixD.Transpose(mRef)); double radius2 = 0; foreach (MyOrientedBoundingBoxD obb in obbs) { double dist2 = Vector3D.DistanceSquared(centerSum, obb.Center) + obb.HalfExtent.LengthSquared(); if (dist2 > radius2) { radius2 = dist2; } } worldVolume = new BoundingSphereD(centerSum, Math.Sqrt(radius2)); }
public MyAreaMarker(MyPositionAndOrientation positionAndOrientation, MyAreaMarkerDefinition definition) { this.m_definition = definition; if (definition != null) { MatrixD worldMatrix = MatrixD.CreateWorld((Vector3D)positionAndOrientation.Position, (Vector3)positionAndOrientation.Forward, (Vector3)positionAndOrientation.Up); base.PositionComp.SetWorldMatrix(worldMatrix, null, false, true, true, false, false, false); if (MyPerGameSettings.LimitedWorld) { this.ClampToWorld(); } this.InitInternal(); } }
private void moveToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Base myBase = (MyObjectBuilder_Base)node.Tag; if (myBase.TypeId == MyObjectBuilderTypeEnum.CubeGrid) { MyObjectBuilder_CubeGrid myGrid = (MyObjectBuilder_CubeGrid)myBase; Form2 newform = new Form2(this); MyPositionAndOrientation pos = (MyPositionAndOrientation)myGrid.PositionAndOrientation; newform.Show(); newform.setVals(pos.Position.X, pos.Position.Y, pos.Position.Z); } }
public static MatrixD AsMatrixD(this MyPositionAndOrientation posAndOrient) { var matrix = MatrixD.CreateWorld(posAndOrient.Position, posAndOrient.Forward, posAndOrient.Up); const float offset = 100.0f; if (MyAPIGatewayShortcuts.GetWorldBoundaries == null) { return(matrix); } var bound = MyAPIGatewayShortcuts.GetWorldBoundaries(); matrix.Translation = Vector3D.Min(Vector3D.Max(matrix.Translation, bound.Min + offset), bound.Max - offset); return(matrix); }
public void setPosition(float x, float y, float z) { TreeNode node = SectorTree.SelectedNode; MyObjectBuilder_Base myBase = (MyObjectBuilder_Base)node.Tag; if (myBase.TypeId == MyObjectBuilderTypeEnum.CubeGrid) { MyObjectBuilder_CubeGrid myGrid = (MyObjectBuilder_CubeGrid)myBase; MyPositionAndOrientation pos = (MyPositionAndOrientation)myGrid.PositionAndOrientation; pos.Position.X = x; pos.Position.Y = y; pos.Position.Z = z; myGrid.PositionAndOrientation = pos; } }
public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false) { MyPositionAndOrientation orientation = new MyPositionAndOrientation { Position = base.Container.Entity.PositionComp.GetPosition(), Up = (SerializableVector3)base.Container.Entity.WorldMatrix.Up, Forward = (SerializableVector3)base.Container.Entity.WorldMatrix.Forward }; MyObjectBuilder_EntityBase base1 = MyEntityFactory.CreateObjectBuilder(base.Container.Entity as MyEntity); base1.PositionAndOrientation = new MyPositionAndOrientation?(orientation); base1.EntityId = base.Container.Entity.EntityId; base1.Name = base.Container.Entity.Name; base1.PersistentFlags = base.Container.Entity.Render.PersistentFlags; return(base1); }
public MyAreaMarker(MyPositionAndOrientation positionAndOrientation, MyAreaMarkerDefinition definition) { m_definition = definition; Debug.Assert(definition != null, "Area marker definition cannot be null!"); if (definition == null) return; MatrixD matrix = MatrixD.CreateWorld(positionAndOrientation.Position, positionAndOrientation.Forward, positionAndOrientation.Up); PositionComp.SetWorldMatrix((MatrixD)matrix); if (MyPerGameSettings.LimitedWorld) { ClampToWorld(); } InitInternal(); }
public void Load(MyPositionAndOrientation characterPosition) { CharacterPosition = characterPosition; var vms = SpaceEngineersCore.Resources.Definitions.VoxelMapStorages; var contentPath = ToolboxUpdater.GetApplicationContentPath(); foreach (var voxelMap in vms) { var fileName = SpaceEngineersCore.GetDataPathOrDefault(voxelMap.StorageFile, Path.Combine(contentPath, voxelMap.StorageFile)); if (!File.Exists(fileName)) { continue; } var voxel = new GenerateVoxelDetailModel { Name = Path.GetFileNameWithoutExtension(voxelMap.StorageFile), SourceFilename = fileName, FileSize = new FileInfo(fileName).Length, Size = MyVoxelMap.LoadVoxelSize(fileName) }; VoxelFileList.Add(voxel); } // Custom voxel files directory. List <string> files = new List <string>(); if (!string.IsNullOrEmpty(GlobalSettings.Default.CustomVoxelPath) && Directory.Exists(GlobalSettings.Default.CustomVoxelPath)) { files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V1FileExtension)); files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V2FileExtension)); } VoxelFileList.AddRange(files.Select(file => new GenerateVoxelDetailModel { Name = Path.GetFileNameWithoutExtension(file), SourceFilename = file, FileSize = new FileInfo(file).Length, Size = MyVoxelMap.LoadVoxelSize(file) })); VoxelFileList = VoxelFileList.OrderBy(s => s.Name).ToList(); }
public void SetFloatingObjectFromBuilder(MyObjectBuilder_FloatingObject floatingObject, Vector3D dragPointDelta, float dragVectorLength) { if (this.IsActive) { this.Deactivate(); } this.m_copiedFloatingObjects.Clear(); this.m_copiedFloatingObjectOffsets.Clear(); GetPasteMatrix(); this.m_dragPointToPositionLocal = dragPointDelta; this.m_dragDistance = dragVectorLength; MyPositionAndOrientation?positionAndOrientation = floatingObject.PositionAndOrientation; MyPositionAndOrientation orientation = (positionAndOrientation != null) ? positionAndOrientation.GetValueOrDefault() : MyPositionAndOrientation.Default; this.m_pasteDirUp = (Vector3)orientation.Up; this.m_pasteDirForward = (Vector3)orientation.Forward; this.SetFloatingObjectFromBuilderInternal(floatingObject, Vector3D.Zero); this.Activate(); }
public BaseEntity(MyObjectBuilder_EntityBase baseEntity, Object backingObject) : base(baseEntity, backingObject) { if (baseEntity != null) { m_entityId = baseEntity.EntityId; if (baseEntity.PositionAndOrientation != null) { m_positionOrientation = baseEntity.PositionAndOrientation.GetValueOrDefault( ); } else { m_positionOrientation = new MyPositionAndOrientation( ); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } } else { m_entityId = 0; m_positionOrientation = new MyPositionAndOrientation( ); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } m_networkManager = new BaseEntityNetworkManager(this, GetEntityNetworkManager(BackingObject)); m_linearVelocity = new Vector3(0, 0, 0); m_angularVelocity = new Vector3(0, 0, 0); m_maxLinearVelocity = (float)104.7; if (EntityId != 0) { GameEntityManager.AddEntity(EntityId, this); } Action action = InternalRegisterEntityMovedEvent; SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action); }
internal static void SendPrefabSpawned( String prefabName, MyPositionAndOrientation posAndOri, Vector3 linearV, Vector3 angularV, String beaconName, Sandbox.ModAPI.SpawningOptions options, int rngSeed) { Debug.Assert(Sync.IsServer, "Only server can spawn new prefabs"); var msg = new SpawnPrefabMsg(); msg.PrefabName = prefabName; msg.PositionAndOrientation = posAndOri; msg.LinearVelocity = linearV; msg.AngularVelocity = angularV; msg.BeaconName = beaconName; msg.SpawningOptions = options; msg.RngSeed = rngSeed; Sync.Layer.SendMessageToAll(ref msg); }
public static void SendEntityCreatedRelative(MyObjectBuilder_EntityBase entity, IMyCubeGrid grid, Vector3 relativeVelocity, ulong userId) { // Extract Type and Field Info Type sendCreateClassType = SandboxGameAssemblyWrapper.Instance.GetAssemblyType(MultiplayerNamespace, SendCreateClass); Type sendCreateRelativeCompressedMsgType = sendCreateClassType.GetNestedType(SendCreateRelativeCompressedMsg, BindingFlags.NonPublic); Type sendCreateCompressedMsgType = sendCreateClassType.GetNestedType(SendCreateCompressedMsg, BindingFlags.NonPublic); FieldInfo createMessageField = sendCreateRelativeCompressedMsgType.GetField(SendCreateRelativeCompressedMsgCreateMessage); FieldInfo createBaseEntity = sendCreateRelativeCompressedMsgType.GetField(SendCreateRelativeCompressedMsgBaseEntity); FieldInfo createRelativeVelocity = sendCreateRelativeCompressedMsgType.GetField(SendCreateRelativeCompressedMsgRelativeVelocity); FieldInfo createObjectBuilders = sendCreateCompressedMsgType.GetField(SendCreateCompressedMsgObjectBuilders); FieldInfo createBuilderLengths = sendCreateCompressedMsgType.GetField(SendCreateCompressedMsgBuilderLengths); // Run logic MemoryStream memoryStream = new MemoryStream( ); MyPositionAndOrientation value = entity.PositionAndOrientation.Value; Matrix matrix = value.GetMatrix( ) * grid.PositionComp.WorldMatrixNormalizedInv; entity.PositionAndOrientation = new MyPositionAndOrientation?(new MyPositionAndOrientation(matrix)); MyObjectBuilderSerializer.SerializeXML(memoryStream, entity, MyObjectBuilderSerializer.XmlCompression.Gzip, typeof(MyObjectBuilder_EntityBase)); if (memoryStream.Length > (long)2147483647) { return; } // SetValues object relativeMessage = Activator.CreateInstance(sendCreateRelativeCompressedMsgType); object createMessage = createMessageField.GetValue(relativeMessage); createObjectBuilders.SetValue(createMessage, memoryStream.ToArray( )); createBuilderLengths.SetValue(createMessage, new int[] { (int)memoryStream.Length }); createBaseEntity.SetValue(relativeMessage, entity.EntityId); createRelativeVelocity.SetValue(relativeMessage, relativeVelocity); SendMessage(relativeMessage, userId, sendCreateCompressedMsgType, 1); }
public void CubeRotate() { var positionOrientation = new MyPositionAndOrientation(new Vector3D(10, 10, 10), Vector3.Backward, Vector3.Up); var gridSizeEnum = MyCubeSize.Large; var cube = (MyObjectBuilder_CubeBlock)MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock"); //var cube = (MyObjectBuilder_CubeBlock)MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_Thrust), "LargeBlockLargeThrust"); cube.Min = new SerializableVector3I(10, 10, 10); cube.BlockOrientation = new SerializableBlockOrientation(Base6Directions.Direction.Forward, Base6Directions.Direction.Up); cube.BuildPercent = 1; var quaternion = positionOrientation.ToQuaternionD(); var definition = SpaceEngineersApi.GetCubeDefinition(cube.TypeId, gridSizeEnum, cube.SubtypeName); var orientSize = definition.Size.Transform(cube.BlockOrientation).Abs(); var min = cube.Min.ToVector3D() * gridSizeEnum.ToLength(); var max = (cube.Min + orientSize).ToVector3D() * gridSizeEnum.ToLength(); var p1 = min.Transform(quaternion) + positionOrientation.Position; var p2 = max.Transform(quaternion) + positionOrientation.Position; var nb = new BoundingBoxD(p1, p2); }
private long SpawnInventoryContainer(MyDefinitionId bagDefinition) { MyEntity builder = Character; var worldMatrix = Character.WorldMatrix; worldMatrix.Translation += worldMatrix.Up + worldMatrix.Forward; MyObjectBuilder_EntityBase bagBuilder = new MyObjectBuilder_EntityBase(); var position = new MyPositionAndOrientation(worldMatrix); bagBuilder.PositionAndOrientation = position; bagBuilder.EntityId = MyEntityIdentifier.AllocateId(); var entity = MyEntities.CreateAndAddFromDefinition(bagBuilder, bagDefinition); entity.Physics.ClearSpeed(); entity.Physics.ForceActivate(); entity.NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME; MyTimerComponent timerComponent = new MyTimerComponent(); timerComponent.SetRemoveEntityTimer(1440); entity.GameLogic = timerComponent; MySyncCreate.SendEntityCreated(entity.GetObjectBuilder(), bagDefinition); return entity.EntityId; }
protected virtual void sync_PilotRelativeEntryUpdated(MyPositionAndOrientation relativeEntry) { }
public void SpawnCargoShipGroup( Vector3 startPosition, Vector3 stopPosition, ulong remoteUserId = 0 ) { try { //Calculate lowest and highest frequencies double lowestFrequency = double.MaxValue; double highestFrequency = 0d; foreach ( MySpawnGroupDefinition entry in MyDefinitionManager.Static.GetSpawnGroupDefinitions( ) ) { if ( entry.Frequency < lowestFrequency ) lowestFrequency = entry.Frequency; if ( entry.Frequency > highestFrequency ) highestFrequency = entry.Frequency; } if ( lowestFrequency <= 0d ) lowestFrequency = 1d; //Get a list of which groups *could* spawn Random random = new Random( ); double randomChance = random.NextDouble( ); randomChance = randomChance * ( highestFrequency / lowestFrequency ); List<MySpawnGroupDefinition> possibleGroups = MyDefinitionManager.Static.GetSpawnGroupDefinitions( ).Where( entry => entry.Frequency >= randomChance ).ToList( ); //Determine which group *will* spawn randomChance = random.NextDouble( ); int randomShipIndex = Math.Max( 0, Math.Min( (int) Math.Round( randomChance * possibleGroups.Count, 0 ), possibleGroups.Count - 1 ) ); MySpawnGroupDefinition randomSpawnGroup = possibleGroups[ randomShipIndex ]; ChatManager.Instance.SendPrivateChatMessage( remoteUserId, string.Format( "Spawning cargo group '{0}' ...", randomSpawnGroup.DisplayNameText ) ); //Spawn the ships in the group Matrix orientation = Matrix.CreateLookAt( startPosition, stopPosition, new Vector3( 0, 1, 0 ) ); foreach ( MySpawnGroupDefinition.SpawnGroupPrefab entry in randomSpawnGroup.Prefabs ) { MyPrefabDefinition matchedPrefab = MyDefinitionManager.Static.GetPrefabDefinitions( ).Select( prefabEntry => prefabEntry.Value ).FirstOrDefault( prefabDefinition => prefabDefinition.Id.SubtypeId.ToString( ) == entry.SubtypeId ); if ( matchedPrefab == null ) continue; foreach ( MyObjectBuilder_CubeGrid objectBuilder in matchedPrefab.CubeGrids ) { //Create the ship CubeGridEntity cubeGrid = new CubeGridEntity( objectBuilder ); //Set the ship position and orientation Vector3 shipPosition = Vector3.Transform( entry.Position, orientation ) + startPosition; orientation.Translation = shipPosition; MyPositionAndOrientation newPositionOrientation = new MyPositionAndOrientation( orientation ); cubeGrid.PositionAndOrientation = newPositionOrientation; //Set the ship velocity //Speed is clamped between 1.0f and the max cube grid speed Vector3 travelVector = stopPosition - startPosition; travelVector.Normalize( ); Vector3 shipVelocity = travelVector * Math.Min( cubeGrid.MaxLinearVelocity, Math.Max( 1.0f, entry.Speed ) ); cubeGrid.LinearVelocity = shipVelocity; //cubeGrid.IsDampenersEnabled = false; foreach ( MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.BaseCubeBlocks ) { //Set the beacon names MyObjectBuilder_Beacon beacon = cubeBlock as MyObjectBuilder_Beacon; if ( beacon != null ) { beacon.CustomName = entry.BeaconText; } //Set the owner of every block //TODO - Find out if setting to an arbitrary non-zero works for this //cubeBlock.Owner = PlayerMap.Instance.GetServerVirtualPlayerId(); cubeBlock.Owner = 0; cubeBlock.ShareMode = MyOwnershipShareModeEnum.Faction; } //And add the ship to the world SectorObjectManager.Instance.AddEntity( cubeGrid ); } } ChatManager.Instance.SendPrivateChatMessage( remoteUserId, string.Format( "Cargo group '{0}' spawned with {1} ships at {2}", randomSpawnGroup.DisplayNameText, randomSpawnGroup.Prefabs.Count, startPosition ) ); } catch ( ArgumentOutOfRangeException ex ) { ApplicationLog.BaseLog.Error( ex ); } catch ( ArgumentNullException ex ) { ApplicationLog.BaseLog.Error( ex ); } catch ( FormatException ex ) { ApplicationLog.BaseLog.Error( ex ); } catch ( Exception ex ) { ApplicationLog.BaseLog.Error( ex ); } }
public void Rotation() { var positionAndOrientation = new MyPositionAndOrientation( new SerializableVector3D(10.0d, -10.0d, -2.5d), new SerializableVector3(0.0f, 0.0f, -1.0f), new SerializableVector3(0.0f, 1.0f, 0.0f)); // -90 around Z var quaternion = Quaternion.CreateFromYawPitchRoll(0, 0, -VRageMath.MathHelper.PiOver2); var o = positionAndOrientation.ToQuaternion() * quaternion; var on = Quaternion.Normalize(o); var p = new MyPositionAndOrientation(on.ToMatrix()); var quaternion2 = QuaternionD.CreateFromYawPitchRoll(0, 0, -Math.PI / 2); var o2 = positionAndOrientation.ToQuaternionD() * quaternion2; var on2 = QuaternionD.Normalize(o2); var p2 = new MyPositionAndOrientation(on2.ToMatrixD()); var quaternion3 = new System.Windows.Media.Media3D.Quaternion(new System.Windows.Media.Media3D.Vector3D(0, 0, 1), -90d); var x3 = positionAndOrientation.ToQuaternionD(); var o3 = new System.Windows.Media.Media3D.Quaternion(x3.X, x3.Y, x3.Z, x3.W)*quaternion3; var on3 = o3; on3.Normalize(); double num = on3.X * on3.X; double num3 = on3.Z * on3.Z; double num4 = on3.X * on3.Y; double num5 = on3.Z * on3.W; double num8 = on3.Y * on3.Z; double num9 = on3.X * on3.W; var M21 = (2.0d * (num4 - num5)); var M22 = (1.0d - 2.0d * (num3 + num)); var M23 = (2.0d * (num8 + num9)); var up3 = new Vector3D(M21, M22, M23); var fwd = new SerializableVector3(0.0f, 0.0f, -1.0f); var up = new SerializableVector3(1.0f, 0.0f, 0.0f); Assert.AreEqual(fwd.X, p.Forward.X, "Forward.X Should Equal"); Assert.AreEqual(fwd.Y, p.Forward.Y, "Forward.Y Should Equal"); Assert.AreEqual(fwd.Z, p.Forward.Z, "Forward.Z Should Equal"); Assert.AreEqual(up.X, p.Up.X, "Up.X Should Equal"); Assert.AreEqual(up.Y, p.Up.Y, "Up.Y Should Equal"); Assert.AreEqual(up.Z, p.Up.Z, "Up.Z Should Equal"); }
public void RotateStructure(VRageMath.Quaternion quaternion) { // Rotate the ship/station in specified direction. var o = CubeGrid.PositionAndOrientation.Value.ToQuaternion() * quaternion; o.Normalize(); var p = new MyPositionAndOrientation(o.ToMatrix()); CubeGrid.PositionAndOrientation = new MyPositionAndOrientation { Position = CubeGrid.PositionAndOrientation.Value.Position, Forward = p.Forward, Up = p.Up }; UpdateGeneralFromEntityBase(); }
public void RotateCubes(VRageMath.Quaternion quaternion) { foreach (var cube in CubeGrid.CubeBlocks) { var definition = SpaceEngineersApi.GetCubeDefinition(cube.TypeId, CubeGrid.GridSizeEnum, cube.SubtypeName); if (definition.Size.X == 1 && definition.Size.Y == 1 && definition.Size.z == 1) { // rotate position around origin. cube.Min = Vector3I.Transform(cube.Min.ToVector3I(), quaternion); } else { // resolve size of component, and transform to original orientation. var orientSize = definition.Size.Add(-1).Transform(cube.BlockOrientation).Abs(); var min = Vector3I.Transform(cube.Min.ToVector3I(), quaternion); var blockMax = new Vector3I(cube.Min.X + orientSize.X, cube.Min.Y + orientSize.Y, cube.Min.Z + orientSize.Z); var max = Vector3I.Transform(blockMax, quaternion); cube.Min = new SerializableVector3I(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y), Math.Min(min.Z, max.Z)); } // rotate BlockOrientation. var q = quaternion * cube.BlockOrientation.ToQuaternion(); q.Normalize(); cube.BlockOrientation = new SerializableBlockOrientation(ref q); } // Rotate Groupings. foreach (var group in CubeGrid.BlockGroups) { for (var i = 0; i < group.Blocks.Count; i++) { // The Group location is in the center of the cube. // It doesn't have to be exact though, as it appears SE is just doing a location test of whatever object is at that location. group.Blocks[i] = Vector3I.Transform(group.Blocks[i], quaternion); } } // TODO: Rotate Bones //if (CubeGrid.Skeleton != null) //{ // for (var i = 0; i < CubeGrid.Skeleton.Count; i++) // { // var bone = CubeGrid.Skeleton[i]; // bone.BonePosition = Vector3I.Transform(bone.BonePosition, quaternion); // bone.BoneOffset = bone.BoneOffset.Transform(VRageMath.Quaternion.Inverse(quaternion)); // } //} // TODO: Rotate ConveyorLines foreach (var conveyorLine in CubeGrid.ConveyorLines) { //conveyorLine.StartPosition = Vector3I.Transform(conveyorLine.StartPosition, quaternion); //conveyorLine.StartDirection = //conveyorLine.EndPosition = Vector3I.Transform(conveyorLine.EndPosition, quaternion); //conveyorLine.EndDirection = } // Rotate the ship also to maintain the appearance that it has not changed. var o = CubeGrid.PositionAndOrientation.Value.ToQuaternion() * VRageMath.Quaternion.Inverse(quaternion); o.Normalize(); var p = new MyPositionAndOrientation(o.ToMatrix()); CubeGrid.PositionAndOrientation = new MyPositionAndOrientation { Position = CubeGrid.PositionAndOrientation.Value.Position, Forward = p.Forward, Up = p.Up }; UpdateGeneralFromEntityBase(); }
private long SpawnInventoryContainer(MyPhysicalItemDefinition bagDefinition) { MyEntity builder = Character; var worldMatrix = Character.WorldMatrix; worldMatrix.Translation += worldMatrix.Up + worldMatrix.Forward; MyObjectBuilder_EntityBase bagBuilder = new MyObjectBuilder_EntityBase(); bagBuilder.Name = bagDefinition.DisplayNameText; var position = new MyPositionAndOrientation(worldMatrix); bagBuilder.PositionAndOrientation = position; bagBuilder.EntityId = MyEntityIdentifier.AllocateId(); bagBuilder.SubtypeName = bagDefinition.Id.SubtypeName; var entity = MyEntities.CreateAndAddFromDefinition(bagBuilder, bagDefinition); entity.Physics.ForceActivate(); entity.Physics.ApplyImpulse(builder.Physics.LinearVelocity, Vector3.Zero); MySyncCreate.SendEntityCreated(entity.GetObjectBuilder(), bagDefinition.Id); return entity.EntityId; }
public BaseEntity(MyObjectBuilder_EntityBase baseEntity, Object backingObject) : base(baseEntity, backingObject) { if (baseEntity != null) { m_entityId = baseEntity.EntityId; if (baseEntity.PositionAndOrientation != null) { m_positionOrientation = baseEntity.PositionAndOrientation.GetValueOrDefault(); } else { m_positionOrientation = new MyPositionAndOrientation(); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } } else { m_entityId = 0; m_positionOrientation = new MyPositionAndOrientation(); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } m_networkManager = new BaseEntityNetworkManager(this, GetEntityNetworkManager(BackingObject)); m_linearVelocity = new Vector3(0, 0, 0); m_angularVelocity = new Vector3(0, 0, 0); m_maxLinearVelocity = (float)104.7; Action action = InternalRegisterEntityMovedEvent; SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action); }
public void AttachPilot(MyCharacter pilot, bool storeOriginalPilotWorld = true, bool calledFromInit = false) { System.Diagnostics.Debug.Assert(pilot != null); System.Diagnostics.Debug.Assert(m_pilot == null); m_pilot = pilot; m_pilot.OnMarkForClose += m_pilotClosedHandler; m_pilot.IsUsing = this; //m_soundEmitter.OwnedBy = m_pilot; if (MyFakes.ENABLE_NEW_SOUNDS) { StartLoopSound(); } if (storeOriginalPilotWorld) { m_pilotRelativeWorld = (Matrix)MatrixD.Multiply(pilot.WorldMatrix, this.PositionComp.GetWorldMatrixNormalizedInv()); if (Sync.IsServer) { var relativeEntry = new MyPositionAndOrientation(m_pilotRelativeWorld.Value); SyncObject.SendPilotRelativeEntryUpdate(ref relativeEntry); } } if (pilot.InScene) { MyEntities.Remove(pilot); } m_pilot.Physics.Enabled = false; m_pilot.PositionComp.SetWorldMatrix(WorldMatrix); m_pilot.Physics.Clear(); //m_pilot.SetPosition(GetPosition() - WorldMatrix.Forward * 0.5f); Hierarchy.AddChild(m_pilot, true, true); var gunEntity = m_pilot.CurrentWeapon as MyEntity; if (gunEntity != null) { var ob = gunEntity.GetObjectBuilder(); m_pilotGunDefinition = ob.GetId(); } else { m_pilotGunDefinition = null; } MyAnimationDefinition animationDefinition; MyDefinitionId id = new MyDefinitionId(typeof(MyObjectBuilder_AnimationDefinition), BlockDefinition.CharacterAnimation); if (!MyDefinitionManager.Static.TryGetDefinition(id, out animationDefinition) && !MyFileSystem.FileExists(BlockDefinition.CharacterAnimation)) { BlockDefinition.CharacterAnimation = null; } PlacePilotInSeat(pilot); m_rechargeSocket.PlugIn(m_pilot.SuitBattery); // Control should be handled elsewhere if we initialize the grid in the Init(...) if (!calledFromInit) { GiveControlToPilot(); } m_pilot.SwitchToWeapon(null); }
private void PlaceAreaMarker() { Vector3D cameraPos, cameraDir; if (MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator || MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Entity) { var headMatrix = MySession.Static.ControlledEntity.GetHeadMatrix(true, true); cameraPos = headMatrix.Translation; cameraDir = headMatrix.Forward; } else { cameraPos = MySector.MainCamera.Position; cameraDir = MySector.MainCamera.WorldMatrix.Forward; } List<MyPhysics.HitInfo> hitInfos = new List<MyPhysics.HitInfo>(); MyPhysics.CastRay(cameraPos, cameraPos + cameraDir * 100, hitInfos, MyPhysics.CollisionLayers.ObjectDetectionCollisionLayer); if (hitInfos.Count == 0) return; MyPhysics.HitInfo? closestValidHit = null; foreach (var hitInfo in hitInfos) { var ent = hitInfo.HkHitInfo.GetHitEntity(); if (ent is MyCubeGrid) { closestValidHit = hitInfo; break; } else if (ent is MyVoxelMap) { closestValidHit = hitInfo; break; } } if (closestValidHit.HasValue) { MyAreaMarkerDefinition definition = AreaMarkerDefinition; Debug.Assert(definition != null, "Area marker definition cannot be null!"); if (definition == null) return; Vector3D position = closestValidHit.Value.Position; var forward = Vector3D.Reject(cameraDir, Vector3D.Up); if (Vector3D.IsZero(forward)) forward = Vector3D.Forward; var positionAndOrientation = new MyPositionAndOrientation(position, Vector3D.Normalize(forward), Vector3D.Up); MyObjectBuilder_AreaMarker objectBuilder = (MyObjectBuilder_AreaMarker)MyObjectBuilderSerializer.CreateNewObject(definition.Id); objectBuilder.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; objectBuilder.PositionAndOrientation = positionAndOrientation; if (objectBuilder.IsSynced) { SerializableDefinitionId id = definition.Id; MyMultiplayer.RaiseStaticEvent(x => CreateNewPlaceArea, id,positionAndOrientation); } else { MyAreaMarker flag = MyEntityFactory.CreateEntity<MyAreaMarker>(objectBuilder); flag.Init(objectBuilder); MyEntities.Add(flag); } } }
private void RaisePilotRelativeEntryUpdated(MyPositionAndOrientation relativeEntry) { var handler = PilotRelativeEntryUpdated; if (handler != null) handler(relativeEntry); }
public MyObjectBuilder_VoxelMap() : base() { PositionAndOrientation = new MyPositionAndOrientation(Vector3.Zero, Vector3.Forward, Vector3.Up); }
public StabilityInfo(MyPositionAndOrientation posAndOr) { PositionAndOr = posAndOr; }
public void Load(MyPositionAndOrientation characterPosition, float maxFloatingObjects) { MaxFloatingObjects = maxFloatingObjects; CharacterPosition = characterPosition; StockItemList.Clear(); var list = new List <ComponentItemModel>(); var contentPath = ToolboxUpdater.GetApplicationContentPath(); foreach (var componentDefinition in SpaceEngineersCore.Resources.ComponentDefinitions) { var bp = SpaceEngineersApi.GetBlueprint(componentDefinition.Id.TypeId, componentDefinition.Id.SubtypeName); list.Add(new ComponentItemModel { Name = componentDefinition.DisplayNameText, TypeId = componentDefinition.Id.TypeId, SubtypeId = componentDefinition.Id.SubtypeName, Mass = componentDefinition.Mass, TextureFile = componentDefinition.Icons == null ? null : SpaceEngineersCore.GetDataPathOrDefault(componentDefinition.Icons.First(), Path.Combine(contentPath, componentDefinition.Icons.First())), Volume = componentDefinition.Volume * SpaceEngineersConsts.VolumeMultiplyer, Accessible = componentDefinition.Public, Time = bp != null ? TimeSpan.FromSeconds(TimeSpan.TicksPerSecond * bp.BaseProductionTimeInSeconds) : (TimeSpan?)null, }); } foreach (var physicalItemDefinition in SpaceEngineersCore.Resources.PhysicalItemDefinitions) { if (physicalItemDefinition.Id.SubtypeName == "CubePlacerItem" || physicalItemDefinition.Id.SubtypeName == "WallPlacerItem") { continue; } var bp = SpaceEngineersApi.GetBlueprint(physicalItemDefinition.Id.TypeId, physicalItemDefinition.Id.SubtypeName); list.Add(new ComponentItemModel { Name = physicalItemDefinition.DisplayNameText, TypeId = physicalItemDefinition.Id.TypeId, SubtypeId = physicalItemDefinition.Id.SubtypeName, Mass = physicalItemDefinition.Mass, Volume = physicalItemDefinition.Volume * SpaceEngineersConsts.VolumeMultiplyer, TextureFile = physicalItemDefinition.Icons == null ? null : SpaceEngineersCore.GetDataPathOrDefault(physicalItemDefinition.Icons.First(), Path.Combine(contentPath, physicalItemDefinition.Icons.First())), Accessible = physicalItemDefinition.Public, Time = bp != null ? TimeSpan.FromSeconds(bp.BaseProductionTimeInSeconds) : (TimeSpan?)null, }); } foreach (var physicalItemDefinition in SpaceEngineersCore.Resources.AmmoMagazineDefinitions) { var bp = SpaceEngineersApi.GetBlueprint(physicalItemDefinition.Id.TypeId, physicalItemDefinition.Id.SubtypeName); list.Add(new ComponentItemModel { Name = physicalItemDefinition.DisplayNameText, TypeId = physicalItemDefinition.Id.TypeId, SubtypeId = physicalItemDefinition.Id.SubtypeName, Mass = physicalItemDefinition.Mass, Volume = physicalItemDefinition.Volume * SpaceEngineersConsts.VolumeMultiplyer, TextureFile = physicalItemDefinition.Icons == null ? null : SpaceEngineersCore.GetDataPathOrDefault(physicalItemDefinition.Icons.First(), Path.Combine(contentPath, physicalItemDefinition.Icons.First())), Accessible = !string.IsNullOrEmpty(physicalItemDefinition.Model), Time = bp != null ? TimeSpan.FromSeconds(bp.BaseProductionTimeInSeconds) : (TimeSpan?)null, }); } foreach (var item in list.OrderBy(i => i.FriendlyName)) { StockItemList.Add(item); } //list.Clear(); //foreach (var cubeDefinition in SpaceEngineersAPI.CubeBlockDefinitions) //{ // list.Add(new ComponentItemModel // { // Name = cubeDefinition.DisplayName, // TypeId = cubeDefinition.Id.TypeId, // SubtypeId = cubeDefinition.Id.SubtypeName, // CubeSize = cubeDefinition.CubeSize, // TextureFile = cubeDefinition.Icon == null ? null : Path.Combine(contentPath, cubeDefinition.Icon), // Accessible = !string.IsNullOrEmpty(cubeDefinition.Model), // }); //} //foreach (var item in list.OrderBy(i => i.FriendlyName)) //{ // StockItemList.Add(item); //} }
public MyObjectBuilder_VoxelMap(Vector3 position, string storageName) : base() { PositionAndOrientation = new MyPositionAndOrientation(position, Vector3.Forward, Vector3.Up); StorageName = storageName; }
protected override void sync_PilotRelativeEntryUpdated(MyPositionAndOrientation relativeEntry) { base.sync_PilotRelativeEntryUpdated(relativeEntry); m_pilotRelativeWorld = relativeEntry.GetMatrix(); }
public void AttachPilot(MyCharacter pilot, bool storeOriginalPilotWorld = true, bool calledFromInit = false) { System.Diagnostics.Debug.Assert(pilot != null); System.Diagnostics.Debug.Assert(m_pilot == null); MyAnalyticsHelper.ReportActivityStart(pilot, "cockpit", "cockpit", string.Empty, string.Empty); m_pilot = pilot; m_pilot.OnMarkForClose += m_pilotClosedHandler; m_pilot.IsUsing = this; StartLoopSound(); if (storeOriginalPilotWorld) { m_pilotRelativeWorld = (Matrix)MatrixD.Multiply(pilot.WorldMatrix, this.PositionComp.GetWorldMatrixNormalizedInv()); if (Sync.IsServer) { var relativeEntry = new MyPositionAndOrientation(m_pilotRelativeWorld.Value); SyncObject.SendPilotRelativeEntryUpdate(ref relativeEntry); } } if (pilot.InScene) MyEntities.Remove(pilot); m_pilot.Physics.Enabled = false; m_pilot.PositionComp.SetWorldMatrix(WorldMatrix); m_pilot.Physics.Clear(); //m_pilot.SetPosition(GetPosition() - WorldMatrix.Forward * 0.5f); Hierarchy.AddChild(m_pilot, true, true); var gunEntity = m_pilot.CurrentWeapon as MyEntity; if (gunEntity != null) { var ob = gunEntity.GetObjectBuilder(); m_pilotGunDefinition = ob.GetId(); } else m_pilotGunDefinition = null; MyAnimationDefinition animationDefinition; MyDefinitionId id = new MyDefinitionId(typeof(MyObjectBuilder_AnimationDefinition), BlockDefinition.CharacterAnimation); if (!MyDefinitionManager.Static.TryGetDefinition(id, out animationDefinition) && !MyFileSystem.FileExists(BlockDefinition.CharacterAnimation)) { BlockDefinition.CharacterAnimation = null; } PlacePilotInSeat(pilot); m_pilot.SuitBattery.ResourceSink.TemporaryConnectedEntity = this; m_rechargeSocket.PlugIn(m_pilot.SuitBattery.ResourceSink); // Control should be handled elsewhere if we initialize the grid in the Init(...) if (!calledFromInit) GiveControlToPilot(); m_pilot.SwitchToWeapon(null); }
public void Load(MyPositionAndOrientation characterPosition) { CharacterPosition = characterPosition; }
public void AddItemExecuted() { var model = new GenerateFloatingObjectModel(); var position = new MyPositionAndOrientation(Vector3D.Zero, Vector3.Forward, Vector3.Up); var settings = SpaceEngineersCore.WorldResource.Checkpoint.Settings; model.Load(position, settings.MaxFloatingObjects); var loadVm = new GenerateFloatingObjectViewModel(this, model); var result = _dialogService.ShowDialog<WindowGenerateFloatingObject>(this, loadVm); if (result == true) { var newEntities = loadVm.BuildEntities(); if (loadVm.IsValidItemToImport) { for (var i = 0; i < newEntities.Length; i++) { var item = ((MyObjectBuilder_FloatingObject)newEntities[i]).Item; _dataModel.Additem(item); } // TODO: need to bubble change up to MainViewModel.IsModified = true; } } }