Ejemplo n.º 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 (Tyr.Bot.UnitManager.Count(UnitTypes.LARVA) < 0)
            {
                return(true);
            }

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

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

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

            if (UnitTypes.LookUp[UnitType].TechRequirement != 0 &&
                Tyr.Bot.UnitManager.Completed(UnitTypes.LookUp[UnitType].TechRequirement) == 0 &&
                UnitTypes.LookUp[UnitType].TechRequirement != UnitTypes.HATCHERY)
            {
                Tyr.Bot.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] > Tyr.Bot.UnitManager.Count(UnitType))
            {
                if (!Morph(state, state.Desired[UnitType] - Tyr.Bot.UnitManager.Count(UnitType)))
                {
                    return(new WaitForResources());
                }
            }
            return(new NextItem());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        public StepResult Perform(BuildListState state)
        {
            if (!Condition.Invoke())
            {
                return(new NextItem());
            }

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

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

            while (upgradeType.Previous > 0 && !Tyr.Bot.Observation.Observation.RawData.Player.UpgradeIds.Contains(upgradeType.Previous))
            {
                upgradeType = UpgradeType.LookUp[upgradeType.Previous];
                if (Tyr.Bot.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 (Tyr.Bot.Frame - agent.LastOrderFrame < 5)
                {
                    continue;
                }

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

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

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

                return(new NextItem());
            }

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

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

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

            foreach (Agent agent in ProductionTask.Task.Units)
            {
                if (Build.FoodLeft() < trainType.Food)
                {
                    Tyr.Bot.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 (Tyr.Bot.Frame - agent.LastOrderFrame < 5)
                {
                    continue;
                }

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

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

                if (Tyr.Bot.Build.Minerals() < 0)
                {
                    return(new NextList());
                }
                if (Tyr.Bot.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);
                    Tyr.Bot.UnitManager.UnitTraining(trainType.UnitType);
                }

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

            return(new NextItem());
        }
Ejemplo n.º 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 - 75;
                }
                else if (DesiredBase != null &&
                         DesiredBase == Tyr.Bot.BaseManager.Natural &&
                         (Tyr.Bot.BaseManager.Natural.ResourceCenter == null || Tyr.Bot.BaseManager.Natural.ResourceCenter.Unit.BuildProgress >= 0.99))
                {
                    requiredMinerals = BuildingType.LookUp[UnitType].Minerals - 50;
                }
                else
                {
                    requiredMinerals = BuildingType.LookUp[UnitType].Minerals - 25;
                }
                int requiredGas = BuildingType.LookUp[UnitType].Gas - 16;
                if (Tyr.Bot.Minerals() < requiredMinerals ||
                    (Tyr.Bot.Gas() < requiredGas && BuildingType.LookUp[UnitType].Gas > 0))
                {
                    Tyr.Bot.DrawText("Not enough resources for " + UnitTypes.LookUp[UnitType].Name + ".");
                    return(false);
                }

                if (UnitTypes.GasGeysers.Contains(UnitType))
                {
                    if (Tyr.Bot.BaseManager.AvailableGasses == 0)
                    {
                        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 &&
                            Tyr.Bot.UnitManager.Count(UnitTypes.COMMAND_CENTER) + Tyr.Bot.UnitManager.Count(UnitTypes.NEXUS) + Tyr.Bot.UnitManager.Count(UnitTypes.HATCHERY) > Tyr.Bot.UnitManager.Completed(UnitTypes.COMMAND_CENTER) + Tyr.Bot.UnitManager.Completed(UnitTypes.NEXUS) + Tyr.Bot.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);
        }
Ejemplo n.º 7
0
        public StepResult Perform(BuildListState state)
        {
            if (!Condition.Invoke())
            {
                return(new NextItem());
            }

            if (UnitTypes.LookUp[UnitType].TechRequirement != 0 &&
                Tyr.Bot.UnitManager.Completed(UnitTypes.LookUp[UnitType].TechRequirement) == 0 &&
                UnitTypes.LookUp[UnitType].TechRequirement != UnitTypes.HATCHERY)
            {
                Tyr.Bot.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 Tyr.Bot.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] > Tyr.Bot.UnitManager.Count(UnitType) &&
                !Exact)
            {
                if (!Construct(state, state.Desired[UnitType] - Tyr.Bot.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());
        }