private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, Vector3D TargetLocation, bool keepOriginalLocation, Chat chat, Hangar Plugin, bool force = false) { var grids = shipBlueprint.CubeGrids; if (grids == null || grids.Length == 0) { chat.Respond("No grids in blueprint!"); return(false); } try { MyIdentity IDentity = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(SteamID)); if (Plugin.GridBackup != null) { Plugin.GridBackup.GetType().GetMethod("BackupGridsManuallyWithBuilders", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, new Type[2] { typeof(List <MyObjectBuilder_CubeGrid>), typeof(long) }, null).Invoke(Plugin.GridBackup, new object[] { grids.ToList(), IDentity.IdentityId }); Log.Warn("Successfully BackedUp grid!"); } } catch (Exception e) { Log.Fatal(e); } //For loading in the same location ParallelSpawner Spawner = new ParallelSpawner(grids, chat); return(Spawner.Start(keepOriginalLocation, TargetLocation)); }
private bool BeginAlignToGravity(MyObjectBuilder_CubeGrid[] AllGrids, Vector3D forwardVector, Vector3D upVector) { //Create WorldMatrix MatrixD worldMatrix = MatrixD.CreateWorld(_PlayerPosition, forwardVector, upVector); int num = 0; MatrixD referenceMatrix = MatrixD.Identity; MatrixD rotationMatrix = MatrixD.Identity; //Find biggest grid and get their postion matrix Parallel.For(0, AllGrids.Length, i => { //Option to clone the BP //array[i] = (MyObjectBuilder_CubeGrid)TotalGrids[i].Clone(); if (AllGrids[i].CubeBlocks.Count > num) { num = AllGrids[i].CubeBlocks.Count; referenceMatrix = AllGrids[i].PositionAndOrientation.Value.GetMatrix(); rotationMatrix = FindRotationMatrix(AllGrids[i]); } }); //Huh? (Keen does this so i guess i will too) My guess so it can create large entities MyEntities.IgnoreMemoryLimits = true; //Update each grid in the array Parallel.For(0, AllGrids.Length, j => { MatrixD newWorldMatrix; if (AllGrids[j].PositionAndOrientation.HasValue) { MatrixD matrix3 = AllGrids[j].PositionAndOrientation.Value.GetMatrix() * MatrixD.Invert(referenceMatrix) * rotationMatrix; newWorldMatrix = matrix3 * worldMatrix; AllGrids[j].PositionAndOrientation = new MyPositionAndOrientation(newWorldMatrix); } else { AllGrids[j].PositionAndOrientation = new MyPositionAndOrientation(worldMatrix); } }); /* Where do we want to paste the grids? Lets find out. based from the character/position */ //Use Rexxars spciy spaghetti code for parallel spawning of ALL grids ParallelSpawner spawner = new ParallelSpawner(AllGrids, chat); spawner.LoadingInGravity = true; //Return completeted return(spawner.Start(false, _PlayerPosition)); }
private bool BeginAlignToGravity(MyObjectBuilder_CubeGrid[] AllGrids, Vector3D position, Vector3D direction, Vector3D vector3D) { //Create WorldMatrix MatrixD worldMatrix = MatrixD.CreateWorld(position, direction, vector3D); int num = 0; MatrixD matrix = MatrixD.Identity; //Find biggest grid and get their postion matrix Parallel.For(0, AllGrids.Length, i => { //Option to clone the BP //array[i] = (MyObjectBuilder_CubeGrid)TotalGrids[i].Clone(); if (AllGrids[i].CubeBlocks.Count > num) { num = AllGrids[i].CubeBlocks.Count; matrix = (AllGrids[i].PositionAndOrientation.HasValue ? AllGrids[i].PositionAndOrientation.Value.GetMatrix() : MatrixD.Identity); } }); MatrixD matrix2; //Align to Main/Biggest grid Vector3D value = Vector3D.Zero; if (AllGrids[0].PositionAndOrientation.HasValue) { value = AllGrids[0].PositionAndOrientation.Value.Position; } matrix2 = MatrixD.CreateWorld(-value, direction, vector3D); //Huh? (Keen does this so i guess i will too) My guess so it can create large entities MyEntities.IgnoreMemoryLimits = true; //Update each grid in the array Parallel.For(0, AllGrids.Length, j => { MatrixD newWorldMatrix; if (AllGrids[j].PositionAndOrientation.HasValue) { MatrixD matrix3 = AllGrids[j].PositionAndOrientation.Value.GetMatrix() * MatrixD.Invert(matrix); newWorldMatrix = matrix3 * worldMatrix; AllGrids[j].PositionAndOrientation = new MyPositionAndOrientation(newWorldMatrix); } else { newWorldMatrix = worldMatrix; AllGrids[j].PositionAndOrientation = new MyPositionAndOrientation(worldMatrix); } }); /* Where do we want to paste the grids? Lets find out. based from the character/position */ var pos = FindPastePosition(AllGrids, position); if (pos == null) { Hangar.Debug("No free Space found!"); chat.Respond("No free space available!"); return(false); } var newPosition = pos.Value; /* Update GridsPosition via xyz. (We already have the orientation correct) if that doesnt work get out of here. */ if (!UpdateGridsPosition(AllGrids, newPosition)) { chat.Respond("The File to be imported does not seem to be compatible with the server!"); return(false); } //Remap to prevent bad stuff MyEntities.RemapObjectBuilderCollection(AllGrids); //Use Rexxars spciy spaghetti code for parallel spawning of ALL grids ParallelSpawner spawner = new ParallelSpawner(AllGrids); spawner.Start(); //Return completeted return(true); }
private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, Vector3D playerPosition, bool keepOriginalLocation, Chat chat, bool force = false) { var grids = shipBlueprint.CubeGrids; if (grids == null || grids.Length == 0) { Hangar.Debug("No grids in blueprint!"); chat.Respond("No grids in blueprint!"); return(false); } bool LoadNearPosition = false; //For loading in the same location ParallelSpawner Spawner = new ParallelSpawner(grids); var position = grids[0].PositionAndOrientation.Value; if (keepOriginalLocation) { var sphere = FindBoundingSphere(grids); sphere.Center = position.Position; List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities); foreach (var entity in entities) { if (entity is MyCubeGrid) { chat.Respond("There are potentially other grids in the way. Loading near the original point."); LoadNearPosition = true; } } if (!LoadNearPosition) { /* Remapping to prevent any key problems upon paste. */ MyEntities.RemapObjectBuilderCollection(grids); Spawner.Start(); return(true); } } /* * Everything else is loading for near player * * * */ /* Where do we want to paste the grids? Lets find out. */ var pos = FindPastePosition(grids, position.Position); if (pos == null) { Hangar.Debug("No free Space found!"); chat.Respond("No free space available!"); return(false); } var newPosition = pos.Value; /* Update GridsPosition if that doesnt work get out of here. */ if (!UpdateGridsPosition(grids, newPosition)) { chat.Respond("The File to be imported does not seem to be compatible with the server!"); return(false); } MyEntities.RemapObjectBuilderCollection(grids); Spawner.Start(); return(true); }
private bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint, Vector3D playerPosition, bool keepOriginalLocation, Chat chat, Hangar Plugin, bool force = false) { var grids = shipBlueprint.CubeGrids; if (grids == null || grids.Length == 0) { Hangar.Debug("No grids in blueprint!"); chat.Respond("No grids in blueprint!"); return(false); } try { MyIdentity IDentity = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(SteamID)); if (Plugin.GridBackup != null) { Plugin.GridBackup.GetType().GetMethod("BackupGridsManuallyWithBuilders", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, new Type[2] { typeof(List <MyObjectBuilder_CubeGrid>), typeof(long) }, null).Invoke(Plugin.GridBackup, new object[] { grids.ToList(), IDentity.IdentityId }); Log.Warn("Successfully BackedUp grid!"); } } catch (Exception e) { Log.Fatal(e); } bool LoadNearPosition = false; //For loading in the same location ParallelSpawner Spawner = new ParallelSpawner(grids); var position = grids[0].PositionAndOrientation.Value; if (keepOriginalLocation) { var sphere = FindBoundingSphere(grids); sphere.Center = position.Position; List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities); foreach (var entity in entities) { if (entity is MyCubeGrid) { chat.Respond("There are potentially other grids in the way. Loading near the original point."); LoadNearPosition = true; } } if (!LoadNearPosition) { /* Remapping to prevent any key problems upon paste. */ MyEntities.RemapObjectBuilderCollection(grids); Spawner.Start(); return(true); } } /* * Everything else is loading for near player * * * */ /* Where do we want to paste the grids? Lets find out. */ var pos = FindPastePosition(grids, position.Position); if (pos == null) { Hangar.Debug("No free Space found!"); chat.Respond("No free space available!"); return(false); } var newPosition = pos.Value; /* Update GridsPosition if that doesnt work get out of here. */ if (!UpdateGridsPosition(grids, newPosition)) { chat.Respond("The File to be imported does not seem to be compatible with the server!"); return(false); } MyEntities.RemapObjectBuilderCollection(grids); Spawner.Start(); return(true); }