/// <summary> /// Generates a <see cref="GameFormation"/> with a single <see cref="GameUnit"/> via <see cref="GenerateTestUnit"/> /// and assigns a default, simple set of <see cref="VolleyOrders"/> to it for Volley 1; also assigns the new GameUnit /// a set of <see cref="GameUnitFireAllocation"/> orders to match up with the <see cref="FireOrder"/>s. /// </summary> /// <param name="id">Desired ID of the new formation</param> /// <param name="name">Desired name of the new formation</param> /// <param name="unitList">Reference to a list of GameUnits, so that the Formation's new GameUnit can be added to it.</param> /// <param name="targetFormationId">Optionally, specify the ID of a target Formation for this Formation's Orders to specify. Default is 0.</param> /// <returns>The new Formation with included <see cref="GameUnitFormationInfo"/> for the new GameUnit. Side Effect: adds the new GameUnit to <paramref name="unitList"/></returns> public static GameFormation GenerateTestFormation(int id, string name, ref List <GameUnit> unitList, int targetFormationId = 0) { GameUnit u = GenerateTestUnit(id: 1, name: $"{name}-1"); unitList.Add(u); var f = new GameFormation() { FormationId = id, FormationName = name, MaxThrust = 99, Orders = new List <VolleyOrders>(), PlayerId = 0, }; f.Units = new List <GameUnitFormationInfo>() { new GameUnitFormationInfo(u, f) }; var fOrder = new VolleyOrders() { Volley = 1, EvasionDice = 2, SpeedDice = 4, FiringOrders = new List <FireOrder>() { new FireOrder() { TargetID = targetFormationId, FireType = "Normal", Priority = "Primary", TargetFormationName = string.Empty, DiceAssigned = 0 } }, ManeuveringOrders = new List <ManeuverOrder>() { new ManeuverOrder() { TargetID = targetFormationId, ManeuverType = "Close", Priority = "Primary" } } }; u.FireAllocation = new List <GameUnitFireAllocation>() { new GameUnitFireAllocation(volley: 1, fireConId: u.Electronics.OfType <FireControlSystem>().First().Id, fireMode: "Normal", priority: "Primary", weaponIds: u.Weapons.Select(w => w.Id).ToList()) }; f.Orders.Add(fOrder); return(f); }
private static void ExecuteManeuversForFormation(int currentVolley, GameFormation f, GameState gameState) { VolleyOrders orders = f.GetOrdersForVolley(currentVolley); foreach (var o in orders.GetSortedManeuveringOrders()) { var target = gameState.Formations.Where(t => t.FormationId == o.TargetID).FirstOrDefault(); var speed = Math.Max(0, orders.SpeedSuccesses + ManeuverOrder.GetManeuverModifier(o.Priority)); if (target == null || o.ManeuverType == Constants.PassiveManeuverType) { // Bail early if the maneuver is a passive one, e.g. "Maintain" // Bail early if the maneuver is not against a valid target Id (e.g. "Target 0" default orders or orders against Formations that have been destroyed) continue; } int rangeShift = o.CalculateRangeShift(currentVolley, f, orders.SpeedSuccesses, target); gameState.DistanceGraph.UpdateDistance(f, target, rangeShift); } }