public bool Proxy() { Unit worker = GetAvailableWorker(); Vector3?expandPosition = GetSortedExpandLocationsForEnemy()[1].Value; if (expandPosition != null) { if (Controller.Construct(GetAvailableWorker(), Units.HATCHERY, expandPosition)) { Logger.Info("Expanding"); return(true); } return(false); } else { Logger.Error("All expands are already taken"); return(false); } }
public bool Expand() { int currentBases = Expands.Count(); Unit worker = GetAvailableWorker(); Vector3?expandPosition = GetSortedExpandLocationsForMe()[currentBases].Value; if (expandPosition != null) { if (Controller.Construct(GetAvailableWorker(), Units.HATCHERY, expandPosition)) { Logger.Info("Expanding"); return(true); } return(false); } else { Logger.Error("All expands are already taken"); return(false); } }
public static void DistributeWorkers() { var workers = Controller.GetUnits(Units.Workers); List <Unit> idleWorkers = new List <Unit>(); foreach (var worker in workers) { if (worker.Order.AbilityId != 0) { continue; } idleWorkers.Add(worker); } if (idleWorkers.Count > 0) { var resourceCenters = Controller.GetUnits(Units.ResourceCenters, onlyCompleted: true); var mineralFields = Controller.GetUnits(Units.MineralFields, onlyVisible: true, alliance: Alliance.Neutral); foreach (var rc in resourceCenters) { //get one of the closer mineral fields var mf = Controller.GetFirstInRange(rc.Position, mineralFields, 7); if (mf == null) { continue; } //only one at a time Logger.Info("Distributing idle worker: {0}", idleWorkers[0].Tag); Controller.Smart(idleWorkers[0], mf); return; } //nothing to be done return; } else { //let's see if we can distribute between bases var resourceCenters = Controller.GetUnits(Units.ResourceCenters, onlyCompleted: true); Unit transferFrom = null; Unit transferTo = null; foreach (var rc in resourceCenters) { if (rc.AssignedWorkers <= rc.IdealWorkers) { transferTo = rc; } else { transferFrom = rc; } } if ((transferFrom != null) && (transferTo != null)) { var mineralFields = Controller.GetUnits(Units.MineralFields, onlyVisible: true, alliance: Alliance.Neutral); var sqrDistance = 7 * 7; foreach (var worker in workers) { if (worker.Order.AbilityId != Abilities.GATHER_MINERALS) { continue; } if (Vector3.DistanceSquared(worker.Position, transferFrom.Position) > sqrDistance) { continue; } var mf = Controller.GetFirstInRange(transferTo.Position, mineralFields, 7); if (mf == null) { continue; } //only one at a time Logger.Info("Distributing idle worker: {0}", worker.Tag); Controller.Smart(worker, mf); return; } } } }