///////////////////////////////////// /// PUBLIC PROPERTIES /////////////// ///////////////////////////////////// ///////////////////////////////////// /// PUBLIC METHODS ////////////////// ///////////////////////////////////// // For grouped units public List <Vector3> GetPhalanxFormation(Vector3 origin, Direction direction, int positionCount) { List <Vector3> positions = new List <Vector3>(); // Sets righthand offset vector between links based on direction of frontline float linkDistance = settings.standardPhalanxLinkDistance; Vector3 linkVectorForward = DirectionExtensions.DirectionToVector3(direction) * linkDistance; Vector3 linkVectorRight = Quaternion.Euler(0, 0, -90) * linkVectorForward; if (!ValidPosition(origin)) { return(positions); } // Adds position of cursor positions.Add(origin); bool rightFlankReached = false; bool leftFlankReached = false; // Generate frontline untill reaching wall or max width for (int i = 1; i <= settings.frontlineMaxWidth / 2; i++) { // Breaks when needed positions is generated if (positions.Count >= positionCount) { return(positions); } // Tentative right hand position Vector3 position = (linkVectorRight * i) + origin; // Check for wall at tentative right hand position. if (!ValidPosition(position)) { rightFlankReached = true; } // If no wall, add to positions. if (!rightFlankReached) { positions.Add(position); } // Check for wall within link max distance and flag if found if (LinksToWall(position)) { rightFlankReached = true; } ; // Repeats for left hand side position = (linkVectorRight * -i) + origin; if (!ValidPosition(position)) { leftFlankReached = true; } if (!leftFlankReached) { positions.Add(position); } if (LinksToWall(position)) { leftFlankReached = true; } ; } // Creates copy of all front rank positions (in reversed order) List <Vector3> frontlinePositions = new List <Vector3>(); foreach (Vector3 pos in positions) { frontlinePositions.Add(pos); } frontlinePositions.Reverse(); // Gets backwards vector int val = (int)direction + 4; val = val % (Enum.GetNames(typeof(Direction)).Length); Direction dir = (Direction)val; Vector3 backwards = DirectionExtensions.DirectionToVector3(dir) * settings.standardPhalanxLinkDistance; // Generate positions backwards from frontline up to 100 positions deep for (int i = 1; i <= 100; i++) { for (int j = frontlinePositions.Count - 1; j >= 0; j--) { // Breaks when needed positions is generated if (positions.Count >= positionCount) { return(positions); } Vector3 tentativePosition = frontlinePositions[j] + (backwards * i); if (ValidPosition(tentativePosition)) { positions.Add(tentativePosition); } else { frontlinePositions.RemoveAt(j); } } } return(positions); }