Пример #1
0
        public override void OnFrame(Tyr tyr)
        {
            BuildingType pylonType    = BuildingType.LookUp[UnitTypes.PYLON];
            BuildingType gatewayType  = BuildingType.LookUp[UnitTypes.GATEWAY];
            BuildingType roboType     = BuildingType.LookUp[UnitTypes.ROBOTICS_FACILITY];
            Point2D      hideLocation = GetHideLocation();

            if (hideLocation == null)
            {
                return;
            }
            Agent pylon   = null;
            Agent gateway = null;
            Agent robo    = null;

            foreach (Agent agent in tyr.UnitManager.Agents.Values)
            {
                if (agent.Unit.UnitType != UnitTypes.PYLON &&
                    agent.Unit.UnitType != UnitTypes.GATEWAY &&
                    agent.Unit.UnitType != UnitTypes.WARP_GATE &&
                    agent.Unit.UnitType != UnitTypes.ROBOTICS_FACILITY)
                {
                    continue;
                }
                if (agent.DistanceSq(HideLocation) > 20 * 20)
                {
                    continue;
                }
                if (agent.Unit.UnitType == UnitTypes.PYLON)
                {
                    pylon = agent;
                }
                else if (agent.Unit.UnitType == UnitTypes.ROBOTICS_FACILITY)
                {
                    robo = agent;
                }
                else
                {
                    gateway = agent;
                }
            }
            if (pylon == null && tyr.Minerals() >= 100 && BuildRequests.Count == 0)
            {
                Point2D placement = ProxyBuildingPlacer.FindPlacement(GetHideLocation(), pylonType.Size, UnitTypes.PYLON);
                if (placement != null)
                {
                    BuildRequests.Add(new BuildRequest()
                    {
                        Type = UnitTypes.PYLON, Pos = placement
                    });
                }
            }
            else if (gateway == null && pylon != null && pylon.Unit.BuildProgress > 0.99 && tyr.Minerals() >= 150)
            {
                Point2D placement = ProxyBuildingPlacer.FindPlacement(GetHideLocation(), gatewayType.Size, UnitTypes.GATEWAY);
                if (placement != null)
                {
                    BuildRequests.Add(new BuildRequest()
                    {
                        Type = UnitTypes.GATEWAY, Pos = placement
                    });
                }
            }
            else if (BuildRobo && robo == null && pylon != null && gateway != null && pylon.Unit.BuildProgress > 0.99 && tyr.Minerals() >= 200 && tyr.Gas() >= 100)
            {
                Point2D placement = ProxyBuildingPlacer.FindPlacement(GetHideLocation(), roboType.Size, UnitTypes.ROBOTICS_FACILITY);
                if (placement != null)
                {
                    BuildRequests.Add(new BuildRequest()
                    {
                        Type = UnitTypes.ROBOTICS_FACILITY, Pos = placement
                    });
                }
            }

            List <BuildRequest> doneRequests = new List <BuildRequest>();

            foreach (BuildRequest request in BuildRequests)
            {
                if (request.worker != null && !Tyr.Bot.UnitManager.Agents.ContainsKey(request.worker.Unit.Tag))
                {
                    request.worker = null;
                }
                if (request.worker == null)
                {
                    foreach (Agent agent in Units)
                    {
                        if (BuildingType.BuildingAbilities.Contains((int)agent.CurrentAbility()))
                        {
                            continue;
                        }
                        request.worker = agent;
                        break;
                    }
                }

                if (!ProxyBuildingPlacer.CheckPlacement(request.Pos, BuildingType.LookUp[request.Type].Size, request.Type, null, true))
                {
                    doneRequests.Add(request);
                    continue;
                }
                foreach (Agent agent in tyr.UnitManager.Agents.Values)
                {
                    if (agent.Unit.UnitType == request.Type &&
                        agent.DistanceSq(request.Pos) < 4)
                    {
                        doneRequests.Add(request);
                        break;
                    }
                }
            }

            foreach (BuildRequest request in doneRequests)
            {
                BuildRequests.Remove(request);
            }

            foreach (Agent agent in Units)
            {
                bool building = false;
                foreach (BuildRequest request in BuildRequests)
                {
                    if (request.worker == null || request.worker.Unit.Tag != agent.Unit.Tag)
                    {
                        continue;
                    }

                    building = true;
                    if (agent.DistanceSq(request.Pos) <= 10 * 10)
                    {
                        agent.Order(BuildingType.LookUp[request.Type].Ability, request.Pos);
                    }
                    else
                    {
                        agent.Order(Abilities.MOVE, request.Pos);
                    }
                    break;
                }
                if (building)
                {
                    continue;
                }

                if (agent.DistanceSq(GetHideLocation()) >= 4 * 4)
                {
                    agent.Order(Abilities.MOVE, GetHideLocation());
                    continue;
                }
            }
        }