private void OnSpawned(HashSet <IMyCubeGrid> grids) { onDone.Invoke(); Vector3D velocity = p.CubeGrid.Physics.LinearVelocity; Vector3D diff = Vector3D.Zero; bool first = true; HashSet <long> gridIds = new HashSet <long>(); foreach (IMyCubeGrid grid in grids) { grid.Physics.LinearVelocity = velocity; if (first) { diff = AccelerateTime(grid, velocity); } else { MatrixD temp = grid.WorldMatrix; temp.Translation += diff; grid.WorldMatrix = temp; } gridIds.Add(grid.EntityId); IMyEntity e = GridBounds.GetOverlappingEntity(grid); if (e != null) { Constants.Notify(InstantProjector.GetOverlapString(true, e), Activator); ParallelSpawner.Close(grids); return; } if (grids.Count > 1) { var cubes = ((MyCubeGrid)grid).GetFatBlocks(); foreach (MyCubeBlock cube in cubes) { IMyMechanicalConnectionBlock baseBlock = cube as IMyMechanicalConnectionBlock; if (baseBlock != null) { baseBlock.Attach(); } } } } if (MyAPIGateway.Session.CreativeMode || comps.ConsumeComponents(Activator, GetInventories(p))) { ParallelSpawner.Add(grids); } else { ParallelSpawner.Close(grids); } }
public bool Spawn(Action onDone) { bounds.Update(); IMyEntity e = bounds.GetOverlappingEntity(); if (e != null) { if (shiftBuildArea) { Constants.Notify(Constants.msgDifferentSpace, Activator); if (!bounds.TryFindClearArea(finalOrientation)) { Constants.Notify(InstantProjector.GetOverlapString(true, e), Activator); return(false); } } else { Constants.Notify(InstantProjector.GetOverlapString(true, e), Activator); return(false); } } // Realign projection to projector int i = 0; foreach (MatrixD world in finalOrientation) { grids[i].PositionAndOrientation = new MyPositionAndOrientation(world); i++; } startTime = IPSession.Instance.Runtime; spawner = new ParallelSpawner(grids, OnSpawned); if (!spawner.Start()) { return(false); } this.onDone = onDone; return(true); }
// Context: Server public bool ConsumeComponents(ulong activator, IEnumerable <IMyInventory> inventories) { List <MyTuple <IMyInventory, IMyInventoryItem, MyFixedPoint> > toRemove = new List <MyTuple <IMyInventory, IMyInventoryItem, MyFixedPoint> >(); foreach (KeyValuePair <MyDefinitionId, int> c in comps) { MyFixedPoint needed = CountComponents(inventories, c.Key, c.Value, toRemove); if (needed > 0) { Constants.Notify(InstantProjector.GetCompsString((int)needed, c.Key.SubtypeName), activator); return(false); } } foreach (MyTuple <IMyInventory, IMyInventoryItem, MyFixedPoint> item in toRemove) { item.Item1.RemoveItemAmount(item.Item2, item.Item3); } return(true); }
public override void Received(ulong sender) { IMyProjector p = MyAPIGateway.Entities.GetEntityById(entityId) as IMyProjector; if (p != null) { InstantProjector gl = p.GameLogic.GetAs <InstantProjector>(); if (gl != null) { bool trustSender = (data & 1) == 1; bool cancel = (data & 2) == 2; if (cancel) { gl.CancelServer(sender, trustSender); } else { gl.BuildServer(sender, trustSender); } } } }
public static bool TryCreate(ulong activator, IMyProjector p, bool shiftBuildArea, out ProjectedGrid projectedGrid) { projectedGrid = null; // Ensure the projector is valid and has a projection if (p.CubeGrid?.Physics == null) { Constants.Notify(Constants.msgError + "bad_physics", activator); return(false); } if (p.ProjectedGrid == null) { Constants.Notify(Constants.msgNoGrid, activator); return(false); } MyObjectBuilder_Projector pBuilder = (MyObjectBuilder_Projector)p.GetObjectBuilderCubeBlock(true); if (pBuilder.ProjectedGrids == null || pBuilder.ProjectedGrids.Count == 0) { Constants.Notify(Constants.msgNoGrid, activator); return(false); } // Prepare list of grids List <MyObjectBuilder_CubeGrid> grids = pBuilder.ProjectedGrids; int largestIndex = FindLargest(grids); MyObjectBuilder_CubeGrid largestGrid = grids[largestIndex]; if (InstantProjector.SupportsSubgrids(p)) { if (largestIndex != 0) { MyObjectBuilder_CubeGrid temp = grids[0]; grids[0] = largestGrid; grids[largestIndex] = temp; } } else { grids.Clear(); grids.Add(largestGrid); } MatrixD largestMatrixInvert = MatrixD.Invert(largestGrid.PositionAndOrientation.Value.GetMatrix()); MatrixD targetMatrix = p.ProjectedGrid.WorldMatrix; float scale = GetScale(p); GridOrientation orientation = new GridOrientation(p); GridComponents comps = null; if (!MyAPIGateway.Session.CreativeMode) { comps = new GridComponents(); } int totalBlocks = 0; MyIDModule owner = ((MyCubeBlock)p).IDModule; if (activator != 0) { long temp = MyAPIGateway.Players.TryGetIdentityId(activator); if (temp != 0) { owner = new MyIDModule(temp, owner.ShareMode); } } foreach (MyObjectBuilder_CubeGrid grid in grids) { totalBlocks += grid.CubeBlocks.Count; if (totalBlocks > IPSession.Instance.MapSettings.MaxBlocks) { Constants.Notify(Constants.msgGridLarge, activator); return(false); } PrepBlocks(activator, owner, grid, comps); grid.IsStatic = false; grid.CreatePhysics = true; grid.Immune = false; grid.DestructibleBlocks = true; MatrixD current = grid.PositionAndOrientation.Value.GetMatrix(); if (scale != 1) { current.Translation /= scale; } MatrixD newWorldMatrix = (current * largestMatrixInvert) * targetMatrix; grid.PositionAndOrientation = new MyPositionAndOrientation(ref newWorldMatrix); orientation.Include(newWorldMatrix); } if (totalBlocks < IPSession.Instance.MapSettings.MinBlocks) { Constants.Notify(Constants.msgGridSmall, activator); return(false); } if (comps == null) { comps = new GridComponents(); } else { comps.ApplySettings(IPSession.Instance.MapSettings); int needed; string name; if (!comps.HasComponents(GetInventories(p), out needed, out name)) { Constants.Notify(InstantProjector.GetCompsString(needed, name), activator); return(false); } } GridBounds bounds = new GridBounds(p, grids); IMyEntity e = bounds.GetOverlappingEntity(); if (e != null && (!shiftBuildArea || !bounds.HasClearArea())) { Constants.Notify(InstantProjector.GetOverlapString(true, e), activator); return(false); } projectedGrid = new ProjectedGrid(activator, p, grids, bounds, comps, orientation, shiftBuildArea, totalBlocks); return(true); }