private MyOrientedBoundingBoxD?IsYardValid(IMyEntity entity, List <IMyCubeBlock> tools)
        {
            DateTime        startTime  = DateTime.Now;
            List <Vector3D> points     = new List <Vector3D>( );
            List <Vector3I> gridPoints = new List <Vector3I>( );

            foreach (IMyCubeBlock tool in tools)
            {
                gridPoints.Add(tool.Position);
                points.Add(tool.PositionComp.GetPosition( ));
            }

            if (!AreToolsConnected(tools))
            {
                return(null);
            }

            if (MathUtility.ArePointsOrthogonal(gridPoints))
            {
                UtilityPlugin.Log.Info("APO Time: " + (DateTime.Now - startTime).Milliseconds);
                startTime = DateTime.Now;
                MyOrientedBoundingBoxD?returnBox = MathUtility.CreateOrientedBoundingBox((MyCubeGrid)entity, points);
                UtilityPlugin.Log.Info("OBB Time: " + (DateTime.Now - startTime).Milliseconds);
                return(returnBox);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Checks if tools are on the same cargo system and are arranged orthogonally.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="tools"></param>
        /// <returns></returns>
        private bool IsYardValid(IMyEntity entity, List <IMyCubeBlock> tools)
        {
            using (Profiler.Start(FullName, nameof(IsYardValid)))
            {
                var gridPoints = new List <Vector3I>();
                foreach (IMyCubeBlock tool in tools)
                {
                    Vector3D point = tool.PositionComp.GetPosition();
                    //the grid position is not consistent with rotation, but world position is always the center of the block
                    //get the Vector3I of the center of the block and calculate APO on that
                    Vector3I adjustedPoint = ((IMyCubeGrid)entity).WorldToGridInteger(point);
                    gridPoints.Add(adjustedPoint);
                }

                if (!MathUtility.ArePointsOrthogonal(gridPoints))
                {
                    Logging.Instance.WriteDebug($"Yard {entity.EntityId} failed: APO");
                    foreach (var tool in tools)
                    {
                        Communication.SendCustomInfo(tool.EntityId, "Invalid Shipyard: Corners not aligned!");
                    }
                    return(false);
                }

                if (!AreToolsConnected(tools))
                {
                    Logging.Instance.WriteDebug($"Yard {entity.EntityId} failed: ATC");
                    foreach (var tool in tools)
                    {
                        Communication.SendCustomInfo(tool.EntityId, "Invalid Shipyard: All tools must be on the same conveyor network!");
                    }
                    return(false);
                }

                return(true);
            }
        }