コード例 #1
0
        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)
                {
                    Utilities.Notify(Utilities.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, Utilities.GetInventories(p)))
            {
                ParallelSpawner.Add(grids);
            }
            else
            {
                ParallelSpawner.Close(grids);
            }
        }
コード例 #2
0
        public bool Spawn(Action onDone)
        {
            bounds.Update();
            IMyEntity e = bounds.GetOverlappingEntity();

            if (e != null)
            {
                if (shiftBuildArea)
                {
                    Utilities.Notify(Constants.msgDifferentSpace, Activator);
                    if (!bounds.TryFindClearArea(finalOrientation))
                    {
                        Utilities.Notify(Utilities.GetOverlapString(true, e), Activator);
                        return(false);
                    }
                }
                else
                {
                    Utilities.Notify(Utilities.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);
        }