public void DetermineNextBuilding(Dictionary <uint, int> unitCounts) { if (BuildRequests.Count > 0) { return; } Dictionary <uint, int> desiredUnitCounts = new Dictionary <uint, int>(); foreach (ProxyBuilding building in Buildings) { if (!building.Test()) { continue; } CollectionUtil.Add(desiredUnitCounts, building.UnitType, building.Number); if (desiredUnitCounts[building.UnitType] > CollectionUtil.Get(unitCounts, building.UnitType)) { BuildingType buildingType = BuildingType.LookUp[building.UnitType]; Point2D placement = ProxyBuildingPlacer.FindPlacement(GetHideLocation(), buildingType.Size, building.UnitType); if (placement != null) { BuildRequests.Add(new BuildRequest() { Type = building.UnitType, Pos = placement }); } return; } } }
public void UnitTraining(uint unitType) { if (unitType == UnitTypes.ZERGLING) { CollectionUtil.Add(Counts, unitType, 2); } else { CollectionUtil.Increment(Counts, unitType); } }
public bool Fungal(Agent agent) { if (agent.Unit.Energy < 75) { return(false); } if (FungalTargets.ContainsKey(agent.Unit.Tag) && Tyr.Bot.Frame - FungalTargets[agent.Unit.Tag].Frame <= 22) { return(true); } foreach (UnitLocation mine in Tyr.Bot.EnemyMineManager.Mines) { bool closeFungal = false; foreach (FungalTarget fungal in FungalTargets.Values) { if (SC2Util.DistanceSq(mine.Pos, fungal.Pos) <= 3 * 3) { closeFungal = true; break; } } if (closeFungal) { continue; } if (SC2Util.DistanceSq(mine.Pos, agent.Unit.Pos) <= 10 * 10) { CollectionUtil.Add(FungalTargets, agent.Unit.Tag, new FungalTarget() { Pos = SC2Util.To2D(mine.Pos), Frame = Tyr.Bot.Frame, InfestorTag = agent.Unit.Tag }); agent.Order(74, SC2Util.To2D(mine.Pos)); return(true); } } foreach (Unit unit in Tyr.Bot.Enemies()) { if (UnitTypes.BuildingTypes.Contains(unit.UnitType)) { continue; } if (unit.UnitType == UnitTypes.ZERGLING || unit.UnitType == UnitTypes.BROODLING || unit.UnitType == UnitTypes.OVERLORD) { continue; } bool closeFungal = false; foreach (FungalTarget fungal in FungalTargets.Values) { if (SC2Util.DistanceSq(unit.Pos, fungal.Pos) <= 4 * 4) { closeFungal = true; break; } } if (closeFungal) { continue; } if (unit.UnitType == UnitTypes.BANSHEE || unit.UnitType == UnitTypes.TEMPEST || (unit.UnitType == UnitTypes.BATTLECRUISER && unit.Health < 200)) { CollectionUtil.Add(FungalTargets, agent.Unit.Tag, new FungalTarget() { Pos = SC2Util.To2D(unit.Pos), Frame = Tyr.Bot.Frame, InfestorTag = agent.Unit.Tag }); agent.Order(74, SC2Util.To2D(unit.Pos)); return(true); } if (SC2Util.DistanceSq(unit.Pos, agent.Unit.Pos) <= 10 * 10) { int count = 0; foreach (Unit unit2 in Tyr.Bot.Enemies()) { if (UnitTypes.BuildingTypes.Contains(unit.UnitType)) { continue; } if (unit.UnitType == UnitTypes.ZERGLING || unit.UnitType == UnitTypes.BROODLING || unit.UnitType == UnitTypes.OVERLORD) { continue; } if (SC2Util.DistanceSq(unit.Pos, unit2.Pos) <= 3 * 3) { count++; } } if (count >= 6) { CollectionUtil.Add(FungalTargets, agent.Unit.Tag, new FungalTarget() { Pos = SC2Util.To2D(unit.Pos), Frame = Tyr.Bot.Frame, InfestorTag = agent.Unit.Tag }); agent.Order(74, SC2Util.To2D(unit.Pos)); return(true); } } } return(false); }
private bool Phase(Agent agent) { if (PhaseFrame.ContainsKey(agent.Unit.Tag) && Tyr.Bot.Frame - PhaseFrame[agent.Unit.Tag] <= 224) { return(false); } foreach (Unit unit in Tyr.Bot.Enemies()) { if (UnitTypes.BuildingTypes.Contains(unit.UnitType)) { continue; } if (agent.Unit.UnitType == UnitTypes.ZERGLING || agent.Unit.UnitType == UnitTypes.BROODLING || agent.Unit.UnitType == UnitTypes.EGG || agent.Unit.UnitType == UnitTypes.LARVA) { continue; } if (unit.IsFlying) { continue; } if (SC2Util.DistanceSq(unit.Pos, agent.Unit.Pos) > 10 * 10) { continue; } int count = 0; bool closeAlly = false; foreach (Agent ally in Tyr.Bot.UnitManager.Agents.Values) { if (ally.Unit.IsFlying) { continue; } if (ally.DistanceSq(unit) <= 2 * 2) { closeAlly = true; break; } } if (closeAlly) { break; } foreach (Unit unit2 in Tyr.Bot.Enemies()) { if (UnitTypes.BuildingTypes.Contains(unit.UnitType)) { continue; } if (unit.UnitType == UnitTypes.ZERGLING || agent.Unit.UnitType == UnitTypes.BROODLING || agent.Unit.UnitType == UnitTypes.EGG || agent.Unit.UnitType == UnitTypes.LARVA) { continue; } if (unit.IsFlying) { continue; } if (SC2Util.DistanceSq(unit.Pos, unit2.Pos) <= 3 * 3) { count++; } } if (count >= 6) { agent.Order(2346, SC2Util.To2D(unit.Pos)); CollectionUtil.Add(PhaseFrame, agent.Unit.Tag, Tyr.Bot.Frame); return(true); } } return(false); }
public void OnFrame(Bot bot) { if (Bot.Main.Observation.Observation.RawData.Event != null && Bot.Main.Observation.Observation.RawData.Event.DeadUnits != null) { foreach (ulong tag in Bot.Main.Observation.Observation.RawData.Event.DeadUnits) { if (LastSeen.ContainsKey(tag)) { LastSeen.Remove(tag); } if (LastSeenFrame.ContainsKey(tag)) { LastSeenFrame.Remove(tag); } if (EnemyBuildings.ContainsKey(tag)) { EnemyBuildings.Remove(tag); } } } List <ulong> destroyedBuildings = new List <ulong>(); foreach (BuildingLocation location in EnemyBuildings.Values) { foreach (Agent agent in bot.UnitManager.Agents.Values) { if (SC2Util.DistanceSq(agent.Unit.Pos, SC2Util.To2D(location.Pos)) <= 6 * 6) { destroyedBuildings.Add(location.Tag); } } } foreach (ulong tag in destroyedBuildings) { EnemyBuildings.Remove(tag); } foreach (Unit unit in Bot.Main.Enemies()) { CollectionUtil.Add(LastSeen, unit.Tag, unit); CollectionUtil.Add(LastSeenFrame, unit.Tag, bot.Frame); if (!UnitTypes.BuildingTypes.Contains(unit.UnitType)) { continue; } if (EnemyBuildings.ContainsKey(unit.Tag)) { EnemyBuildings[unit.Tag] = new BuildingLocation() { Tag = unit.Tag, Pos = unit.Pos, Type = unit.UnitType, LastSeen = Bot.Main.Frame, Flying = unit.IsFlying } } ; else { EnemyBuildings.Add(unit.Tag, new BuildingLocation() { Tag = unit.Tag, Pos = unit.Pos, Type = unit.UnitType, LastSeen = Bot.Main.Frame, Flying = unit.IsFlying }); } } }
public override void OnFrame(Tyr tyr) { HashSet <Base> alreadyAssigned = new HashSet <Base>(); foreach (Agent agent in Units) { if (AssignedBases.ContainsKey(agent.Unit.Tag)) { if (AssignedBases[agent.Unit.Tag].Owner != -1) { AssignedBases.Remove(agent.Unit.Tag); } else { alreadyAssigned.Add(AssignedBases[agent.Unit.Tag]); } } } List <Base> bases = new List <Base>(); foreach (Base b in tyr.BaseManager.Bases) { if (!printed) { Console.WriteLine("Checking base: " + b.BaseLocation.Pos); Console.WriteLine("Is main: " + (b == tyr.BaseManager.Main)); Console.WriteLine("Is natural: " + (b == tyr.BaseManager.Natural)); Console.WriteLine("Is enemy main: " + (SC2Util.DistanceSq(b.BaseLocation.Pos, tyr.TargetManager.PotentialEnemyStartLocations[0]) < 2 * 2)); Console.WriteLine("Owner is neutral: " + (b.Owner == -1)); Console.WriteLine("Alread assigned: " + (alreadyAssigned.Contains(b))); } if (b != tyr.BaseManager.Main && b != tyr.BaseManager.Natural && SC2Util.DistanceSq(b.BaseLocation.Pos, tyr.TargetManager.PotentialEnemyStartLocations[0]) >= 2 * 2 && b.Owner == -1 && !alreadyAssigned.Contains(b)) { if (!printed) { Console.WriteLine("Adding base."); } bases.Add(b); } if (!printed) { Console.WriteLine(); } } printed = true; bases.Sort((Base a, Base b) => Math.Sign(tyr.MapAnalyzer.EnemyDistances[(int)a.BaseLocation.Pos.X, (int)a.BaseLocation.Pos.Y] - tyr.MapAnalyzer.EnemyDistances[(int)b.BaseLocation.Pos.X, (int)b.BaseLocation.Pos.Y])); int assignPos = 0; if (bases.Count > 0) { foreach (Agent agent in Units) { if (AssignedBases.ContainsKey(agent.Unit.Tag)) { continue; } CollectionUtil.Add(AssignedBases, agent.Unit.Tag, bases[assignPos % bases.Count]); assignPos++; } } foreach (Agent agent in Units) { if (!AssignedBases.ContainsKey(agent.Unit.Tag)) { continue; } if (agent.DistanceSq(AssignedBases[agent.Unit.Tag].BaseLocation.Pos) > 2 * 2) { agent.Order(Abilities.MOVE, AssignedBases[agent.Unit.Tag].BaseLocation.Pos); } } }
public override void OnFrame(Bot bot) { HashSet <Base> alreadyAssigned = new HashSet <Base>(); foreach (Agent agent in Units) { if (AssignedBases.ContainsKey(agent.Unit.Tag)) { if (AssignedBases[agent.Unit.Tag].Owner != -1) { AssignedBases.Remove(agent.Unit.Tag); } else { alreadyAssigned.Add(AssignedBases[agent.Unit.Tag]); } } } List <Base> bases = new List <Base>(); foreach (Base b in bot.BaseManager.Bases) { if (b != bot.BaseManager.Main && b != bot.BaseManager.Natural && SC2Util.DistanceSq(b.BaseLocation.Pos, bot.TargetManager.PotentialEnemyStartLocations[0]) >= 2 * 2 && b.Owner == -1 && !alreadyAssigned.Contains(b)) { bases.Add(b); } } bases.Sort((Base a, Base b) => Math.Sign(bot.MapAnalyzer.EnemyDistances[(int)a.BaseLocation.Pos.X, (int)a.BaseLocation.Pos.Y] - bot.MapAnalyzer.EnemyDistances[(int)b.BaseLocation.Pos.X, (int)b.BaseLocation.Pos.Y])); int assignPos = 0; if (bases.Count > 0) { foreach (Agent agent in Units) { if (AssignedBases.ContainsKey(agent.Unit.Tag)) { continue; } CollectionUtil.Add(AssignedBases, agent.Unit.Tag, bases[assignPos % bases.Count]); assignPos++; } } foreach (Agent agent in Units) { if (!AssignedBases.ContainsKey(agent.Unit.Tag)) { continue; } if (agent.DistanceSq(AssignedBases[agent.Unit.Tag].BaseLocation.Pos) > 2 * 2) { agent.Order(Abilities.MOVE, AssignedBases[agent.Unit.Tag].BaseLocation.Pos); } } }