Beispiel #1
0
 public void RegisterTriggeredOrder(OrderTrigger trigger, Order order)
 {
     GD.Print(String.Format("Registering order - Trigger: {0}, Order: {1}", trigger.TriggerType, order.OrderType));
     if (!this._TriggerOrders.ContainsKey(order.UnitId))
     {
         this._TriggerOrders[order.UnitId] = new List <TriggeredOrder>();
     }
     this._TriggerOrders[order.UnitId].Add(new TriggeredOrder(trigger, order));
 }
Beispiel #2
0
        public static TriggeredOrder AdvanceIfUnitRetreatsRoutsOrWithdraws(Unit watchedUnit, Unit advanceUnit)
        {
            var trigger = new OrderTrigger(OrderTriggerType.UNIT_HAS_STANDING_ORDER, false,
                                           new List <string>()
            {
                watchedUnit.UnitId
            }, new List <UnitOrder>()
            {
                UnitOrder.ROUT
            });

            return(new TriggeredOrder(trigger, new Order(advanceUnit.UnitId, OrderType.ADVANCE)));
        }
Beispiel #3
0
 public TriggeredOrder(OrderTrigger trigger, Order order)
 {
     this.Trigger = trigger;
     this.Order   = order;
 }
Beispiel #4
0
        public static List <TriggeredOrder> ExecutePREPARE_SWEEP_NEXT_LANE(EncounterState state, Unit unit)
        {
            // Find your current lane
            Lane   closestLane     = null;
            double closestDistance = 9999.0;

            foreach (var lane in state.DeploymentInfo.Lanes)
            {
                var d = lane.LaneCenter.DistanceTo(unit.AveragePosition);
                if (d < closestDistance)
                {
                    closestDistance = d;
                    closestLane     = lane;
                }
            }

            // Find a target lane
            int targetLane = -1;

            for (int i = closestLane.LaneIdx - 1; i >= 0; i--)
            {
                GD.Print("PREPPING CHECKING: ", i);
                var clear = state.DeploymentInfo.Lanes[i].UnitsForFaction(unit.UnitFaction.Opposite())
                            .Select((unitAtLanePosition) => state.GetUnit(unitAtLanePosition.UnitId).StandingOrder)
                            .All((order) => order == UnitOrder.ROUT);
                if (!clear)
                {
                    targetLane = i;
                    break;
                }
            }
            for (int i = closestLane.LaneIdx + 1; i < state.DeploymentInfo.Lanes.Count; i++)
            {
                GD.Print("PREPPING CHECKING: ", i);
                var clear = state.DeploymentInfo.Lanes[i].UnitsForFaction(unit.UnitFaction.Opposite())
                            .Select((unitAtLanePosition) => state.GetUnit(unitAtLanePosition.UnitId).StandingOrder)
                            .All((order) => order == UnitOrder.ROUT);
                if (!clear)
                {
                    targetLane = i;
                    break;
                }
            }
            GD.Print("CHOSEN LANE: ", targetLane);
            if (targetLane == -1)
            {
                return(null);
            }

            // Given a target lane, get the closest unit, and advance to its center
            var closestUnroutedEnemy = state.DeploymentInfo.Lanes[targetLane]
                                       .UnitsForFaction(unit.UnitFaction.Opposite())
                                       .Last((u) => state.GetUnit((u.UnitId)).StandingOrder != UnitOrder.ROUT);
            var enemyUnit     = state.GetUnit(closestUnroutedEnemy.UnitId);
            var enemyPos      = enemyUnit.AveragePosition;
            var vectorToEnemy = AIUtils.VectorFromCenterRotated(unit.AveragePosition, enemyPos.X, enemyPos.Y, unit.UnitFacing);
            var stepsBehind   = vectorToEnemy.Item2;

            GD.Print("UNIT IS BEHIND THE ENEMY UNIT BY: ", stepsBehind, " unit pos: ", unit.AveragePosition, " enemy pos: ", enemyPos, "facing: ", unit.UnitFacing);

            // Order unit to march steps + 5
            // unit.StandingOrder = UnitOrder.ADVANCE;

            // Order unit to reform perpendicular to the enemy line
            // var triggerStepsPlusFive = new OrderTrigger(OrderTriggerType.ACTIVATE_ON_OR_AFTER_TURN, false, activateOnTurn: state.CurrentTurn + stepsBehind + 5);
            var oldFacing = unit.UnitFacing;
            var newFacing = vectorToEnemy.Item1 < 0 ? unit.UnitFacing.LeftOf() : unit.UnitFacing.RightOf();

            unit.RallyPoint    = AIUtils.RotateAndProject(unit.AveragePosition, 0, -1 * stepsBehind - 25, unit.UnitFacing);;
            unit.UnitFacing    = newFacing;
            unit.StandingOrder = UnitOrder.REFORM;

            var behindEnemyUnit = AIUtils.RotateAndProject(enemyUnit.AveragePosition, 0, 15, enemyUnit.UnitFacing);

            // Order unit to advance after wheeling
            var triggerStepsPlus40 = new OrderTrigger(OrderTriggerType.ACTIVATE_ON_OR_AFTER_TURN, false, activateOnTurn: state.CurrentTurn + Math.Max(0, stepsBehind) + 15);
            var sweepOrder         = new TriggeredOrder(triggerStepsPlus40, new Order(unit.UnitId, OrderType.ROTATE_AND_REFORM_AT, newPosition: behindEnemyUnit, newFacing: oldFacing.Opposite()));

            // Order unit to finally advance
            var triggerStepsPlus60 = new OrderTrigger(OrderTriggerType.ACTIVATE_ON_OR_AFTER_TURN, false, activateOnTurn: state.CurrentTurn + Math.Max(0, stepsBehind) + 50);
            var advance            = new TriggeredOrder(triggerStepsPlus60, new Order(unit.UnitId, OrderType.ADVANCE));

            return(new List <TriggeredOrder>()
            {
                sweepOrder, advance
            });
        }