void SkipIfObstructed(Vector3D directionalVector, CollectDetectedBlocks collect = null) { if (IsObstructed(directionalVector, collect)) { EchoR("Skipping: obstructed"); processStep++; throw new PutOffExecutionException(); } }
bool IsObstructed(Vector3D directionalVector, CollectDetectedBlocks collect = null) { if (collect == null) { collect = CollectAll; } var entities = FindDetectedGrids().FindAll(blk => collect(blk)); var referenceBlock = ReferenceBlock; foreach (var entity in entities) { var dir = Vector3D.Normalize(entity.Position - referenceBlock.GetPosition()); var dot = Vector3D.Dot(dir, Vector3D.Normalize(directionalVector)); var radians = Math.Acos(MathHelper.Clamp(dot, -1f, 1f)); var degrees = MathHelper.ToDegrees(radians); if (degrees > 0 && degrees < 60) { //EchoR(string.Format("Grid detected: {0}, degrees {1}, type: {2}", entity.Name, degrees, entity.Type)); return(true); } } return(false); }