public override IEnumerable <SC2APIProtocol.Action> PerformActions(int frame) { var actions = new List <SC2APIProtocol.Action>(); if (lastFrameTime > 5) { lastFrameTime = 0; return(actions); } var stopwatch = new Stopwatch(); stopwatch.Start(); var attackingEnemies = ActiveUnitData.SelfUnits.Where(u => u.Value.Attributes.Contains(Attribute.Structure)).SelectMany(u => u.Value.NearbyEnemies).Distinct().Where(e => ActiveUnitData.EnemyUnits.ContainsKey(e.Unit.Tag)); if (attackingEnemies.Count() > 0) { if (UnitCommanders.Count() == 0) { actions.AddRange(DefendWithWorkers(attackingEnemies, frame)); } else { StopDefendingWithWorkers(); } foreach (var commander in UnitCommanders) { if (commander.UnitCalculation.TargetPriorityCalculation.TargetPriority == TargetPriority.Retreat || commander.UnitCalculation.TargetPriorityCalculation.TargetPriority == TargetPriority.FullRetreat) { commander.UnitCalculation.TargetPriorityCalculation.TargetPriority = TargetPriority.Attack; } } actions.AddRange(ArmySplitter.SplitArmy(frame, attackingEnemies, TargetingData.MainDefensePoint, UnitCommanders, true)); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } else { actions = MicroController.Attack(UnitCommanders, TargetingData.MainDefensePoint, TargetingData.ForwardDefensePoint, TargetingData.MainDefensePoint, frame); } StopDefendingWithWorkers(); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); }
public override IEnumerable <SC2APIProtocol.Action> PerformActions(int frame) { var actions = new List <SC2APIProtocol.Action>(); if (lastFrameTime > 5) { lastFrameTime = 0; return(actions); } var stopwatch = new Stopwatch(); stopwatch.Start(); var mainUnits = UnitCommanders.Where(c => MainAttackers.Contains((UnitTypes)c.UnitCalculation.Unit.UnitType)); var otherUnits = UnitCommanders.Where(c => !MainAttackers.Contains((UnitTypes)c.UnitCalculation.Unit.UnitType)); DistractionSquadService.UpdateDistractionSquad(otherUnits); DistractionSquadService.Enabled = UnitCommanders.Count() > 25; IEnumerable <UnitCommander> supportUnits; if (DistractionSquadService.DistractionSquadState == DistractionSquadState.NotDistracting) { supportUnits = otherUnits; } else { supportUnits = otherUnits.Where(c => !DistractionSquadService.DistractionSquad.Any(d => d.UnitCalculation.Unit.Tag == c.UnitCalculation.Unit.Tag)); } var hiddenBase = TargetingData.HiddenEnemyBase; if (mainUnits.Count() > 0) { AttackData.ArmyPoint = TargetingService.GetArmyPoint(mainUnits); } else { AttackData.ArmyPoint = TargetingService.GetArmyPoint(supportUnits); } TargetingData.AttackPoint = TargetingService.UpdateAttackPoint(AttackData.ArmyPoint, TargetingData.AttackPoint); var attackingEnemies = ActiveUnitData.SelfUnits.Where(u => u.Value.UnitClassifications.Contains(UnitClassification.ResourceCenter) || u.Value.UnitClassifications.Contains(UnitClassification.ProductionStructure) || u.Value.UnitClassifications.Contains(UnitClassification.DefensiveStructure)).SelectMany(u => u.Value.NearbyEnemies).Distinct(); if (attackingEnemies.Count() > 0) { var armyPoint = new Vector2(AttackData.ArmyPoint.X, AttackData.ArmyPoint.Y); var distanceToAttackPoint = Vector2.DistanceSquared(armyPoint, new Vector2(TargetingData.AttackPoint.X, TargetingData.AttackPoint.Y)); var closerEnemies = attackingEnemies; if (AttackData.Attacking) { closerEnemies = attackingEnemies.Where(e => Vector2.DistanceSquared(e.Position, armyPoint) < distanceToAttackPoint); } if (closerEnemies.Count() > 0) { actions = ArmySplitter.SplitArmy(frame, closerEnemies, TargetingData.AttackPoint, mainUnits.Concat(supportUnits), false); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } } if (!hiddenBase && TargetingData.HiddenEnemyBase) { ResetClaimedUnits(); if (MicroTaskData.MicroTasks.ContainsKey("FindHiddenBaseTask")) { MicroTaskData.MicroTasks["FindHiddenBaseTask"].Enable(); } } else if (hiddenBase && !TargetingData.HiddenEnemyBase) { if (MicroTaskData.MicroTasks.ContainsKey("FindHiddenBaseTask")) { MicroTaskData.MicroTasks["FindHiddenBaseTask"].Disable(); } } actions.AddRange(DistractionSquadService.TakeAction(frame)); if (mainUnits.Count() > 0) { if (AttackData.Attacking) { actions.AddRange(MicroController.Attack(mainUnits, TargetingData.AttackPoint, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame)); actions.AddRange(MicroController.Support(supportUnits, mainUnits, TargetingData.AttackPoint, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame)); } else { var cleanupActions = EnemyCleanupService.CleanupEnemies(mainUnits.Concat(supportUnits), TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); if (cleanupActions != null) { actions.AddRange(cleanupActions); } else { actions.AddRange(MicroController.Retreat(mainUnits, TargetingData.ForwardDefensePoint, null, frame)); actions.AddRange(MicroController.Retreat(supportUnits, TargetingData.ForwardDefensePoint, null, frame)); } } } else { if (AttackData.Attacking) { actions.AddRange(MicroController.Attack(supportUnits, TargetingData.AttackPoint, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame)); } else { var cleanupActions = EnemyCleanupService.CleanupEnemies(supportUnits, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); if (cleanupActions != null) { actions.AddRange(cleanupActions); } else { actions.AddRange(MicroController.Retreat(supportUnits, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame)); } } } stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); }
public override IEnumerable <SC2APIProtocol.Action> PerformActions(int frame) { var actions = new List <SC2APIProtocol.Action>(); if (lastFrameTime > 5) { lastFrameTime = 0; return(actions); } var stopwatch = new Stopwatch(); stopwatch.Start(); var hiddenBase = TargetingData.HiddenEnemyBase; AttackData.ArmyPoint = TargetingService.GetArmyPoint(UnitCommanders); TargetingData.AttackPoint = TargetingService.UpdateAttackPoint(AttackData.ArmyPoint, TargetingData.AttackPoint); if (!AttackData.CustomAttackFunction) { if (AttackData.Attacking) { if (MacroData.FoodUsed < AttackData.ArmyFoodRetreat) { AttackData.Attacking = false; } } else { AttackData.Attacking = MacroData.FoodArmy >= AttackData.ArmyFoodAttack || MacroData.FoodUsed > 190; } } var attackingEnemies = ActiveUnitData.SelfUnits.Where(u => u.Value.UnitClassifications.Contains(UnitClassification.ResourceCenter) || u.Value.UnitClassifications.Contains(UnitClassification.ProductionStructure)).SelectMany(u => u.Value.NearbyEnemies).Distinct(); if (attackingEnemies.Count() > 0) { var armyPoint = new Vector2(AttackData.ArmyPoint.X, AttackData.ArmyPoint.Y); var distanceToAttackPoint = Vector2.DistanceSquared(armyPoint, new Vector2(TargetingData.AttackPoint.X, TargetingData.AttackPoint.Y)); var closerEnemies = attackingEnemies.Where(e => Vector2.DistanceSquared(e.Position, armyPoint) < distanceToAttackPoint); if (!AttackData.Attacking) { closerEnemies = attackingEnemies; } if (closerEnemies.Count() > 0) { actions = ArmySplitter.SplitArmy(frame, closerEnemies, TargetingData.AttackPoint, UnitCommanders, false); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } } if (!hiddenBase && TargetingData.HiddenEnemyBase) { ResetClaimedUnits(); if (MicroTaskData.MicroTasks.ContainsKey("FindHiddenBaseTask")) { MicroTaskData.MicroTasks["FindHiddenBaseTask"].Enable(); } } else if (!TargetingData.HiddenEnemyBase) { if (MicroTaskData.MicroTasks.ContainsKey("FindHiddenBaseTask") && MicroTaskData.MicroTasks["FindHiddenBaseTask"].Enabled) { MicroTaskData.MicroTasks["FindHiddenBaseTask"].Disable(); } } if (AttackData.Attacking) { actions = MicroController.Attack(UnitCommanders, TargetingData.AttackPoint, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } else { var cleanupActions = EnemyCleanupService.CleanupEnemies(UnitCommanders, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); if (cleanupActions != null) { actions = cleanupActions; } else { actions = MicroController.Retreat(UnitCommanders, TargetingData.ForwardDefensePoint, AttackData.ArmyPoint, frame); } stopwatch.Stop(); lastFrameTime = stopwatch.ElapsedMilliseconds; return(actions); } }