bool UnloadUnits(UnitCommander commander, Point2D defensivePoint, int frame, out List <SC2APIProtocol.Action> action) { action = null; // TODO: if already unloading all return false and it will unload as it moves? if (commander.UnitCalculation.Unit.Orders.Any(o => o.AbilityId == (uint)Abilities.UNLOADALLAT_WARPPRISM || o.AbilityId == (uint)Abilities.UNLOADUNIT_WARPPRISM)) { // if a unit has been in there for more than a second, warp prism must be on unloadable ground, move to a new area then try again if (commander.LoadTimes.Any(l => l.Value > 100)) { action = commander.Order(frame, Abilities.MOVE, defensivePoint); } return(true); } if (!MapDataService.PathWalkable(commander.UnitCalculation.Unit.Pos)) { return(false); } foreach (var passenger in commander.UnitCalculation.Unit.Passengers) { if (!commander.LoadTimes.ContainsKey(passenger.Tag)) { commander.LoadTimes[passenger.Tag] = frame; } // use LoadTimes to calculate weapon cooldown if (commander.UnitCalculation.Unit.Shield + commander.UnitCalculation.Unit.Health < 50 || passenger.Shield > 25) // unload any units that regained shields, or if warp prism dying { action = commander.UnloadSpecificUnit(frame, Abilities.UNLOADUNIT_WARPPRISM, passenger.Tag); return(true); } else { if (!ActiveUnitData.SelfUnits.ContainsKey(passenger.Tag)) { action = commander.Order(frame, Abilities.UNLOADALLAT_WARPPRISM, null, commander.UnitCalculation.Unit.Tag); return(true); } else { var weapon = ActiveUnitData.SelfUnits[passenger.Tag].Weapon; if (weapon == null || (frame - commander.LoadTimes[passenger.Tag]) / SharkyOptions.FramesPerSecond > weapon.Speed) // unload any units ready to fire { action = commander.UnloadSpecificUnit(frame, Abilities.UNLOADUNIT_WARPPRISM, passenger.Tag); return(true); } } } } return(false); }
bool NavigateToSupportUnit(UnitCommander commander, Point2D target, int frame, out List <SC2APIProtocol.Action> action) { if (MapDataService.PathWalkable(commander.UnitCalculation.Unit.Pos)) // if it is in unplaceable terrain, can't unload { if (commander.UnitCalculation.Unit.Shield + commander.UnitCalculation.Unit.Health < 50 || commander.UnitCalculation.EnemiesInRangeOf.Count > 0) // if warp prism dying or enemies nearby unload { action = commander.Order(frame, Abilities.UNLOADALLAT_WARPPRISM, null, commander.UnitCalculation.Unit.Tag); return(true); } foreach (var passenger in commander.UnitCalculation.Unit.Passengers) { var passengerUnit = ActiveUnitData.Commanders[passenger.Tag].UnitCalculation.Unit; var unit = ActiveUnitData.Commanders[passenger.Tag].UnitCalculation; foreach (var enemyAttack in commander.UnitCalculation.NearbyEnemies) { if (DamageService.CanDamage(unit, enemyAttack) && InRange(commander.UnitCalculation.Position, enemyAttack.Position, unit.Range + passengerUnit.Radius + enemyAttack.Unit.Radius) && MapDataService.MapHeight(commander.UnitCalculation.Unit.Pos) == MapDataService.MapHeight(enemyAttack.Unit.Pos)) { if (!enemyAttack.UnitClassifications.Contains(UnitClassification.ArmyUnit) && !InRange(commander.UnitCalculation.Position, enemyAttack.Position, 2 + passengerUnit.Radius + enemyAttack.Unit.Radius)) { continue; } // if an enemy is in range drop the unit //action = commander.Order(frame, Abilities.UNLOADALLAT_WARPPRISM, null, commander.UnitCalculation.Unit.Tag); // TODO: dropping a specific unit not working, can only drop all, change it if they ever fix the api action = commander.UnloadSpecificUnit(frame, Abilities.UNLOADUNIT_WARPPRISM, passenger.Tag); return(true); } } } if (InRange(new Vector2(target.X, target.Y), commander.UnitCalculation.Position, 3)) // if made it to the target just drop { action = commander.Order(frame, Abilities.UNLOADALLAT_WARPPRISM, null, commander.UnitCalculation.Unit.Tag); return(true); } } if (commander.UnitCalculation.Unit.CargoSpaceMax > commander.UnitCalculation.Unit.CargoSpaceTaken && commander.UnitCalculation.Unit.Shield + commander.UnitCalculation.Unit.Health > 50) // find more units to load { var friendly = commander.UnitCalculation.NearbyAllies.Where(u => !u.Unit.IsFlying && u.Unit.BuildProgress == 1 && u.UnitClassifications.Contains(UnitClassification.ArmyUnit) && !commander.UnitCalculation.Unit.Passengers.Any(p => p.Tag == u.Unit.Tag) && commander.UnitCalculation.Unit.CargoSpaceMax - commander.UnitCalculation.Unit.CargoSpaceTaken >= UnitDataService.CargoSize((UnitTypes)u.Unit.UnitType) && u.EnemiesInRange.Count == 0 && u.EnemiesInRangeOf.Count == 0).OrderBy(u => Vector2.DistanceSquared(commander.UnitCalculation.Position, u.Position)).FirstOrDefault(); if (friendly != null) { action = commander.Order(frame, Abilities.LOAD, null, friendly.Unit.Tag); return(true); } } action = commander.Order(frame, Abilities.MOVE, target); return(true); }
bool DetermineMiningAction(UnitCommander commander, int frame, out List <SC2APIProtocol.Action> action) { action = new List <SC2APIProtocol.Action>(); if (commander.UnitCalculation.NearbyEnemies.Count > 0) { return(false); } var nexuses = BaseData.SelfBases.Where(u => u.ResourceCenter.BuildProgress == 1 && u.MineralMiningInfo.Count() > 0).OrderBy(u => u.MineralMiningInfo.Sum(m => m.Workers.Count) / u.MineralMiningInfo.Count()).ThenBy(u => Vector2.DistanceSquared(commander.UnitCalculation.Position, new Vector2(u.Location.X, u.Location.Y))); //foreach (var nexusBase in BaseData.Bases) //{ // DrawSphere(SC2Util.Point(nexusBase.MineralLinePos.X, nexusBase.MineralLinePos.Y, 11)); //} if (commander.UnitCalculation.Unit.Passengers.Count > 0) { //action = commander.Order(frame, Abilities.UNLOADALLAT_WARPPRISM, null, commander.UnitCalculation.Unit.Tag); foreach (var passenger in commander.UnitCalculation.Unit.Passengers) { var passengerAction = commander.UnloadSpecificUnit(frame, Abilities.UNLOADUNIT_WARPPRISM, passenger.Tag); if (passengerAction != null) { action.AddRange(passengerAction); } } return(true); } if (StopWarping(commander, frame, out action)) { return(true); } var otherWarpPrisms = ActiveUnitData.SelfUnits.Where(u => u.Value.Unit.Tag != commander.UnitCalculation.Unit.Tag && (u.Value.Unit.UnitType == (uint)UnitTypes.PROTOSS_WARPPRISM || u.Value.Unit.UnitType == (uint)UnitTypes.PROTOSS_WARPPRISMPHASING)); foreach (var nexus in nexuses) { if (!otherWarpPrisms.Any(o => Vector2.DistanceSquared(o.Value.Position, new Vector2(nexus.Location.X, nexus.Location.Y)) < 25)) { var miningLocation = GetMiningSpot(nexus); if (miningLocation != null) { //DrawSphere(SC2Util.Point(miningLocation.X, miningLocation.Y, 11)); if (Vector2.DistanceSquared(commander.UnitCalculation.Position, new Vector2(miningLocation.X, miningLocation.Y)) < .5) { var probe = commander.UnitCalculation.NearbyAllies.Where(a => a.Unit.BuffIds.Any(b => SharkyUnitData.CarryingMineralBuffs.Contains((Buffs)b)) && InRange(a.Position, commander.UnitCalculation.Position, PickupRange) && !InRange(a.Position, new Vector2(nexus.Location.X, nexus.Location.Y), nexus.ResourceCenter.Radius + 1)).OrderByDescending(u => Vector2.DistanceSquared(new Vector2(nexus.Location.X, nexus.Location.Y), u.Position)).FirstOrDefault(); if (probe != null) { action = commander.Order(frame, Abilities.LOAD, null, probe.Unit.Tag); return(true); } else { action = commander.Order(frame, Abilities.UNLOADALLAT_WARPPRISM, miningLocation); return(true); } } action = commander.Order(frame, Abilities.MOVE, miningLocation); return(true); } } } return(false); }