Beispiel #1
0
        private bool Morph(BuildListState state, int number)
        {
            if (!MorphingType.LookUpToType.ContainsKey(UnitType))
            {
                throw new ArgumentException("There is no MorphingType defined for UnitType: " + UnitType);
            }

            if (number <= 0)
            {
                return(true);
            }


            if (Bot.Main.UnitManager.Count(UnitTypes.LARVA) < 0)
            {
                return(true);
            }

            if (Bot.Main.Minerals() < MorphingType.LookUpToType[UnitType].Minerals ||
                Bot.Main.Gas() < MorphingType.LookUpToType[UnitType].Gas)
            {
                return(false);
            }

            state.BuiltThisFrame = true;
            Bot.Main.DrawText("Morphing: " + UnitTypes.LookUp[UnitType].Name);
            MorphingTask.Task.Morph(UnitType);

            return(number == 1);
        }
Beispiel #2
0
        public StepResult Perform(BuildListState state)
        {
            if (!Condition.Invoke())
            {
                return(new NextItem());
            }

            if (UnitTypes.LookUp[UnitType].TechRequirement != 0 &&
                Bot.Main.UnitManager.Completed(UnitTypes.LookUp[UnitType].TechRequirement) == 0 &&
                UnitTypes.LookUp[UnitType].TechRequirement != UnitTypes.HATCHERY)
            {
                Bot.Main.DrawText("Skipping list. Morph tech for " + UnitTypes.LookUp[UnitType].Name + " not available: " + UnitTypes.LookUp[UnitType].TechRequirement);
                return(new NextList());
            }

            if (Build.FoodLeft() < UnitTypes.LookUp[UnitType].FoodRequired)
            {
                return(new NextItem());
            }

            state.AddDesired(UnitType, Number);

            if (state.Desired[UnitType] > Bot.Main.UnitManager.Count(UnitType))
            {
                if (!Morph(state, state.Desired[UnitType] - Bot.Main.UnitManager.Count(UnitType)))
                {
                    return(new WaitForResources());
                }
            }
            return(new NextItem());
        }
Beispiel #3
0
        public bool Construct()
        {
            BuildListState state = new BuildListState();

            for (int pos = 0; pos < Steps.Count; pos++)
            {
                BuildStep step = null;
                try
                {
                    StepResult result = Steps[pos].Perform(state);
                    if (result is WaitForResources)
                    {
                        return(false);
                    }
                    else if (result is NextList)
                    {
                        return(true);
                    }
                    else if (result is NextItem)
                    {
                        continue;
                    }
                    else if (result is ToLine)
                    {
                        int line = ((ToLine)result).Line;
                        if (pos < 0)
                        {
                            pos += line;
                        }
                        else
                        {
                            pos = line - 1;
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Exception in buildlist at step " + pos + ": " + step, e);
                }
            }
            return(true);
        }
Beispiel #4
0
        public StepResult Perform(BuildListState state)
        {
            if (!Condition.Invoke())
            {
                return(new NextItem());
            }

            if (UnitTypes.LookUp[UnitType].TechRequirement != 0 &&
                Bot.Main.UnitManager.Completed(UnitTypes.LookUp[UnitType].TechRequirement) == 0 &&
                UnitTypes.LookUp[UnitType].TechRequirement != UnitTypes.HATCHERY &&
                UnitTypes.LookUp[UnitType].TechRequirement != UnitTypes.TECH_LAB)
            {
                Bot.Main.DrawText("Tech requirement not met to train " + UnitTypes.LookUp[UnitType].Name + " requires: " + UnitTypes.LookUp[UnitType].TechRequirement);
                return(new NextItem());
            }

            int          alreadyTrained = Bot.Main.UnitManager.Count(UnitType) + state.GetTraining(UnitType);
            TrainingType trainType      = TrainingType.LookUp[UnitType];

            foreach (Agent agent in ProductionTask.Task.Units)
            {
                if (Build.FoodLeft() < trainType.Food)
                {
                    Bot.Main.DrawText("Not enough food to train " + UnitTypes.LookUp[UnitType].Name);
                    break;
                }
                if (alreadyTrained >= Number)
                {
                    break;
                }

                if (agent.Unit.BuildProgress < 0.99)
                {
                    continue;
                }

                if (trainType.IsAddOn && agent.GetAddOn() != null)
                {
                    continue;
                }

                if (!trainType.ProducingUnits.Contains(agent.Unit.UnitType))
                {
                    continue;
                }

                if (agent.Unit.Orders != null && agent.Unit.Orders.Count >= 2)
                {
                    continue;
                }

                if (agent.CurrentAbility() != 0 && (agent.GetAddOn() == null || !IsReactor(agent.GetAddOn().Unit.UnitType)))
                {
                    continue;
                }

                if (agent.Command != null)
                {
                    continue;
                }

                if (Bot.Main.Frame - agent.LastOrderFrame < 5)
                {
                    continue;
                }

                if (agent.Unit.UnitType == UnitTypes.GATEWAY && UpgradeType.LookUp[UpgradeType.WarpGate].Done())
                {
                    continue;
                }

                Bot.Main.ReservedGas      += trainType.Gas;
                Bot.Main.ReservedMinerals += trainType.Minerals;

                if (Bot.Main.Build.Minerals() < 0)
                {
                    return(new NextList());
                }
                if (Bot.Main.Build.Gas() < 0)
                {
                    return(new NextItem());
                }

                if (agent.Unit.UnitType == UnitTypes.WARP_GATE)
                {
                    bool success = WarpIn(agent, trainType);
                    if (!success)
                    {
                        continue;
                    }
                }
                else
                {
                    agent.Order((int)trainType.Ability);
                    Bot.Main.UnitManager.UnitTraining(trainType.UnitType);
                }

                state.AddTraining(UnitType, 1);
                alreadyTrained++;
            }

            return(new NextItem());
        }
Beispiel #5
0
        public StepResult Perform(BuildListState state)
        {
            if (!Condition.Invoke())
            {
                return(new NextItem());
            }

            if (Bot.Main.Observation.Observation.RawData.Player.UpgradeIds.Contains(UpgradeId))
            {
                return(new NextItem());
            }
            UpgradeType upgradeType = UpgradeType.LookUp[UpgradeId];

            if (Bot.Main.UnitManager.ActiveOrders.Contains(upgradeType.Ability))
            {
                return(new NextItem());
            }

            while (upgradeType.Previous > 0 && !Bot.Main.Observation.Observation.RawData.Player.UpgradeIds.Contains(upgradeType.Previous))
            {
                upgradeType = UpgradeType.LookUp[upgradeType.Previous];
                if (Bot.Main.UnitManager.ActiveOrders.Contains(upgradeType.Ability))
                {
                    return(new NextItem());
                }
            }


            foreach (Agent agent in ProductionTask.Task.Units)
            {
                if (!upgradeType.ProducingUnits.Contains(agent.Unit.UnitType))
                {
                    continue;
                }

                if (agent.Unit.Orders != null && agent.Unit.Orders.Count > 0)
                {
                    continue;
                }

                if (Bot.Main.Frame - agent.LastOrderFrame < 5)
                {
                    continue;
                }

                Bot.Main.ReservedGas      += upgradeType.Gas;
                Bot.Main.ReservedMinerals += upgradeType.Minerals;

                if (Bot.Main.Build.Gas() < 0)
                {
                    new NextItem();
                }
                if (Bot.Main.Build.Minerals() < 0)
                {
                    return(new NextList());
                }

                agent.Order((int)upgradeType.Ability);

                return(new NextItem());
            }

            return(new NextItem());
        }
Beispiel #6
0
        private bool Construct(BuildListState state, int number)
        {
            for (int i = 0; i < number; i++)
            {
                bool isCenter = UnitTypes.ResourceCenters.Contains(UnitType);

                int requiredMinerals;
                if (isCenter)
                {
                    requiredMinerals = BuildingType.LookUp[UnitType].Minerals - (UnitType == UnitTypes.HATCHERY ? 75 : 90);
                }
                else if (DesiredBase != null &&
                         DesiredBase == Bot.Main.BaseManager.Natural &&
                         (Bot.Main.BaseManager.Natural.ResourceCenter == null || Bot.Main.BaseManager.Natural.ResourceCenter.Unit.BuildProgress >= 0.99))
                {
                    requiredMinerals = BuildingType.LookUp[UnitType].Minerals - 50;
                }
                else if (UnitType == UnitTypes.PYLON && Bot.Main.UnitManager.Completed(UnitTypes.PYLON) == 0)
                {
                    requiredMinerals = BuildingType.LookUp[UnitType].Minerals - 45;
                }
                else if (UnitType == UnitTypes.GATEWAY && Bot.Main.UnitManager.Completed(UnitTypes.GATEWAY) == 0)
                {
                    requiredMinerals = BuildingType.LookUp[UnitType].Minerals - 70;
                }
                else
                {
                    requiredMinerals = BuildingType.LookUp[UnitType].Minerals - 25;
                }
                int requiredGas = BuildingType.LookUp[UnitType].Gas - 16;
                if (Bot.Main.Minerals() < requiredMinerals ||
                    (Bot.Main.Gas() < requiredGas && BuildingType.LookUp[UnitType].Gas > 0))
                {
                    Bot.Main.DrawText("Not enough resources for " + UnitTypes.LookUp[UnitType].Name + ".");
                    return(false);
                }

                if (UnitTypes.GasGeysers.Contains(UnitType))
                {
                    if (Bot.Main.BaseManager.AvailableGasses == 0)
                    {
                        Bot.Main.DrawText("No gasses available.");
                        return(true);
                    }
                    if (DesiredBase != null)
                    {
                        bool available = false;
                        foreach (Gas gas in DesiredBase.BaseLocation.Gasses)
                        {
                            if (gas.Available)
                            {
                                available = true;
                                break;
                            }
                        }
                        if (!available)
                        {
                            return(true);
                        }
                    }
                }

                if (DesiredPos == null && DesiredBase == null)
                {
                    state.BuiltThisFrame = true;
                    if (!Build.Construct(UnitType))
                    {
                        if (isCenter &&
                            Bot.Main.UnitManager.Count(UnitTypes.COMMAND_CENTER) + Bot.Main.UnitManager.Count(UnitTypes.NEXUS) + Bot.Main.UnitManager.Count(UnitTypes.HATCHERY) > Bot.Main.UnitManager.Completed(UnitTypes.COMMAND_CENTER) + Bot.Main.UnitManager.Completed(UnitTypes.NEXUS) + Bot.Main.UnitManager.Completed(UnitTypes.HATCHERY))
                        {
                            return(true);
                        }
                        return(!UnitTypes.DefensiveBuildingsTypes.Contains(UnitType));
                    }
                }
                else if (DesiredPos == null)
                {
                    state.BuiltThisFrame = true;
                    if (!Build.Construct(UnitType, DesiredBase))
                    {
                        return(!UnitTypes.DefensiveBuildingsTypes.Contains(UnitType));
                    }
                }
                else
                {
                    state.BuiltThisFrame = true;
                    if (!Build.Construct(UnitType, DesiredBase, DesiredPos, Exact))
                    {
                        return(!UnitTypes.DefensiveBuildingsTypes.Contains(UnitType));
                    }
                }
            }
            return(true);
        }
Beispiel #7
0
        public StepResult Perform(BuildListState state)
        {
            if (!Condition.Invoke())
            {
                return(new NextItem());
            }

            if (UnitTypes.LookUp[UnitType].TechRequirement != 0 &&
                Bot.Main.UnitManager.Completed(UnitTypes.LookUp[UnitType].TechRequirement) == 0 &&
                UnitTypes.LookUp[UnitType].TechRequirement != UnitTypes.HATCHERY &&
                UnitType != UnitTypes.GATEWAY)
            {
                bool almostReady = false;
                if (UnitType == UnitTypes.CYBERNETICS_CORE)
                {
                    foreach (Agent agent in Bot.Main.Units())
                    {
                        if (agent.Unit.UnitType == UnitTypes.GATEWAY &&
                            agent.Unit.BuildProgress >= 0.8)
                        {
                            almostReady = true;
                        }
                    }
                }
                if (!almostReady)
                {
                    Bot.Main.DrawText("Skipping list. Build tech for " + UnitTypes.LookUp[UnitType].Name + " not available: " + UnitTypes.LookUp[UnitType].TechRequirement);
                    return(new NextList());
                }
            }

            state.AddDesired(UnitType, Number);
            if (DesiredPos != null)
            {
                bool built = false;
                foreach (BuildRequest request in ConstructionTask.Task.BuildRequests)
                {
                    if (request.Type == UnitType && request.Exact == Exact && request.AroundLocation == DesiredPos)
                    {
                        built = true;
                        break;
                    }
                }
                foreach (BuildRequest request in ConstructionTask.Task.UnassignedRequests)
                {
                    if (request.Type == UnitType && request.Exact == Exact && request.AroundLocation == DesiredPos)
                    {
                        built = true;
                        break;
                    }
                }
                if (!built)
                {
                    foreach (Agent agent in Bot.Main.UnitManager.Agents.Values)
                    {
                        if (CheckTypeMatches(UnitType, agent.Unit.UnitType) && agent.Exact == Exact && agent.AroundLocation == DesiredPos)
                        {
                            built = true;
                            break;
                        }
                    }
                }
                if (!built)
                {
                    if (!Construct(state, 1))
                    {
                        return(new WaitForResources());
                    }
                }
            }

            if (DesiredBase == null && state.Desired[UnitType] > Bot.Main.UnitManager.Count(UnitType) &&
                !Exact)
            {
                if (!Construct(state, state.Desired[UnitType] - Bot.Main.UnitManager.Count(UnitType)))
                {
                    return(new WaitForResources());
                }
            }
            if (DesiredBase != null)
            {
                BuildingAtBase key = new BuildingAtBase(UnitType, DesiredBase);
                state.AddDesiredPerBase(key, Number);

                if (state.DesiredPerBase[key] > Build.Count(DesiredBase, UnitType) &&
                    !Exact)
                {
                    if (!Construct(state, state.DesiredPerBase[key] - Build.Count(DesiredBase, UnitType)))
                    {
                        return(new WaitForResources());
                    }
                }
            }

            return(new NextItem());
        }