public List <string> AllowedActions(EncounterState state, Entity parent, UnitOrder standingOrder) { var parentPos = parent.GetComponent <PositionComponent>().EncounterPosition; var unit = state.GetUnit(parent.GetComponent <UnitComponent>().UnitId); var actions = new List <string>(); var parentIsLagging = AIUtils.IsPositionTooFarBehind(parentPos, unit); // TODO: this is a silly place to run this check if (parentIsLagging) { parent.GetComponent <AIRotationComponent>().NotifyRotationCompleted(); } if (standingOrder == UnitOrder.ADVANCE && !parent.GetComponent <AIRotationComponent>().IsRotating) { // Directly ahead pos available if not too far ahead OR if too far behind var validAheadPositions = new List <EncounterPosition>() { AIUtils.RotateAndProject(parentPos, 0, -1, unit.UnitFacing), AIUtils.RotateAndProject(parentPos, 1, -1, unit.UnitFacing), AIUtils.RotateAndProject(parentPos, -1, -1, unit.UnitFacing), }; foreach (var possible in validAheadPositions) { if (positionNotTooFarAheadAndMovable(state, parentPos, unit, possible) || parentIsLagging) { actions.Add(ToCardinalDirection(parentPos, possible)); } } // Flank positions available if not too far ahead AND not too far behind var validFlankPositions = new List <EncounterPosition>() { AIUtils.RotateAndProject(parentPos, 1, 0, unit.UnitFacing), AIUtils.RotateAndProject(parentPos, -1, 0, unit.UnitFacing), }; foreach (var possible in validFlankPositions) { if (positionNotTooFarAheadAndMovable(state, parentPos, unit, possible) && !parentIsLagging) { actions.Add(ToCardinalDirection(parentPos, possible)); } } if (parent.GetComponent <AIRotationComponent>().BackSecure(state, parent, unit)) { actions.Add(InputHandler.ActionMapping.ROTATE); } } if (!parentIsLagging) { actions.Add(InputHandler.ActionMapping.WAIT); } actions.Add(InputHandler.ActionMapping.LEAVE_FORMATION); return(actions); }