Example #1
0
        private bool Morph(MorphStep morph, int number)
        {
            if (number <= 0)
            {
                return(true);
            }


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

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

            return(number == 1);
        }
Example #2
0
        public bool Construct()
        {
            BuiltThisFrame = false;
            Dictionary <uint, int>           desired        = new Dictionary <uint, int>();
            Dictionary <BuildingAtBase, int> desiredPerBase = new Dictionary <BuildingAtBase, int>();

            for (int pos = 0; pos < Steps.Count; pos++)
            {
                BuildStep step = null;
                try
                {
                    step = Steps[pos];
                    if (step.GetType() == typeof(BuildingStep))
                    {
                        BuildingStep building = (BuildingStep)step;
                        if (!building.Condition.Invoke())
                        {
                            continue;
                        }

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

                        Add(desired, building.UnitType, building.Number);
                        if (building.Exact)
                        {
                            bool built = false;
                            foreach (BuildRequest request in ConstructionTask.Task.BuildRequests)
                            {
                                if (request.Type == building.UnitType && SC2Util.DistanceSq(request.Pos, building.DesiredPos) <= 2)
                                {
                                    built = true;
                                    break;
                                }
                            }
                            foreach (BuildRequest request in ConstructionTask.Task.UnassignedRequests)
                            {
                                if (request.Type == building.UnitType && SC2Util.DistanceSq(request.Pos, building.DesiredPos) <= 2)
                                {
                                    built = true;
                                    break;
                                }
                            }
                            if (!built)
                            {
                                foreach (Agent agent in Tyr.Bot.UnitManager.Agents.Values)
                                {
                                    if (agent.Unit.UnitType == building.UnitType && SC2Util.DistanceSq(agent.Unit.Pos, building.DesiredPos) <= 2)
                                    {
                                        built = true;
                                        break;
                                    }
                                }
                            }
                            if (!built)
                            {
                                if (!Construct(building, 1))
                                {
                                    return(false);
                                }
                            }
                        }

                        if (building.DesiredBase == null && desired[building.UnitType] > Tyr.Bot.UnitManager.Count(building.UnitType) &&
                            !building.Exact)
                        {
                            if (!Construct(building, desired[building.UnitType] - Tyr.Bot.UnitManager.Count(building.UnitType)))
                            {
                                return(false);
                            }
                        }
                        if (building.DesiredBase != null)
                        {
                            BuildingAtBase key = new BuildingAtBase(building.UnitType, building.DesiredBase);
                            Add(desiredPerBase, key, building.Number);

                            if (desiredPerBase[key] > Build.Count(building.DesiredBase, building.UnitType) &&
                                !building.Exact)
                            {
                                Tyr.Bot.DrawText("Building " + UnitTypes.LookUp[building.UnitType].Name + " at base.");
                                if (!Construct(building, desiredPerBase[key] - Build.Count(building.DesiredBase, building.UnitType)))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    else if (step.GetType() == typeof(ConditionalStep))
                    {
                        if (!((ConditionalStep)step).Check())
                        {
                            Tyr.Bot.DrawText("Skipping list. Condition not met.");
                            return(true);
                        }
                    }
                    else if (step.GetType() == typeof(GotoStep))
                    {
                        if (BuiltThisFrame)
                        {
                            return(true);
                        }
                        if (((GotoStep)step).Pos < 0)
                        {
                            pos += ((GotoStep)step).Pos;
                        }
                        else
                        {
                            pos = ((GotoStep)step).Pos - 1;
                        }
                    }
                    if (step.GetType() == typeof(MorphStep))
                    {
                        MorphStep morph = (MorphStep)step;
                        if (!morph.Condition.Invoke())
                        {
                            continue;
                        }

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

                        Add(desired, morph.UnitType, morph.Number);

                        if (desired[morph.UnitType] > Tyr.Bot.UnitManager.Count(morph.UnitType))
                        {
                            if (!Morph(morph, desired[morph.UnitType] - Tyr.Bot.UnitManager.Count(morph.UnitType)))
                            {
                                return(false);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Exception in buildlist at step " + pos + ": " + step, e);
                }
            }
            return(true);
        }