コード例 #1
0
        public static Point2D FindPlacementPylon(Point2D reference, Point2D target, Point2D size, uint type)
        {
            UpdatePylonList();
            Point2D result = null;
            float   score  = 1000000;

            for (float x = reference.X - 34.5f; x <= reference.X + 28; x += 10)
            {
                for (float y = reference.Y - 30.5f; y <= reference.Y + 30; y += 2)
                {
                    if (!RectBuildable(x - 1f, y - 1f, x + 1f, y + 1f))
                    {
                        continue;
                    }

                    bool adjacentPylon = false;
                    foreach (Agent pylon in Pylons)
                    {
                        // Pylons should not be placed corner to corner as this prevents units from walking between them.
                        if (Math.Abs(pylon.Unit.Pos.X - x) == 2 &&
                            Math.Abs(pylon.Unit.Pos.Y - y) == 2)
                        {
                            adjacentPylon = true;
                            break;
                        }
                    }
                    if (adjacentPylon)
                    {
                        continue;
                    }

                    float newScore = 0;
                    if (Pylons.Count == 0)
                    {
                        if (!Bot.Main.MapAnalyzer.StartArea[(int)x, (int)y])
                        {
                            continue;
                        }

                        if (Bot.Main.MapAnalyzer.WallDistances[(int)x, (int)y] < 8 ||
                            SC2Util.DistanceSq(new Point2D()
                        {
                            X = x, Y = y
                        }, Bot.Main.MapAnalyzer.StartLocation) <= 7 * 7)
                        {
                            newScore += 100000;
                        }
                        if (newScore > score)
                        {
                            continue;
                        }
                    }
                    if (Bot.Main.MapAnalyzer.StartArea[(int)x, (int)y] &&
                        Bot.Main.MapAnalyzer.WallDistances[(int)x, (int)y] < 4)
                    {
                        newScore += 1000;
                    }

                    float closestPylonDist = 8 * 8;
                    foreach (Agent pylon in Pylons)
                    {
                        closestPylonDist = Math.Min(closestPylonDist, SC2Util.DistanceSq(pylon.Unit.Pos, SC2Util.Point(x, y)));
                    }

                    newScore += SC2Util.DistanceSq(target, SC2Util.Point(x, y)) - closestPylonDist * 4;

                    foreach (Unit gas in Bot.Main.Observation.Observation.RawData.Units)
                    {
                        if (!UnitTypes.GasGeysers.Contains(gas.UnitType))
                        {
                            continue;
                        }

                        if (SC2Util.DistanceSq(gas.Pos, SC2Util.Point(x, y)) <= 5 * 5)
                        {
                            newScore += 10000;
                        }
                    }

                    if (newScore > score)
                    {
                        continue;
                    }

                    bool blocked = false;
                    foreach (Unit unit in Bot.Main.Observation.Observation.RawData.Units)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 1f, y - 1f, x + 1f, y + 1f, SC2Util.To2D(unit.Pos), unit.UnitType))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    foreach (BuildRequest request in ConstructionTask.Task.UnassignedRequests)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 1f, y - 1f, x + 1f, y + 1f, request.Pos, request.Type))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    foreach (BuildRequest request in ConstructionTask.Task.BuildRequests)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 1f, y - 1f, x + 1f, y + 1f, request.Pos, request.Type))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    foreach (Base b in Bot.Main.BaseManager.Bases)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 1f, y - 1f, x + 1f, y + 1f, b.BaseLocation.Pos, UnitTypes.NEXUS))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    if (blocked)
                    {
                        continue;
                    }

                    score  = newScore;
                    result = SC2Util.Point(x, y);
                }
            }
            return(result);
        }
コード例 #2
0
        public static Point2D FindPlacementSupplyDepot(Point2D reference, Point2D target, Point2D size, uint type)
        {
            Point2D result   = null;
            float   distance = 1000000;

            for (float x = reference.X - 31.5f; x <= reference.X + 28; x += 7)
            {
                for (float y = reference.Y - 30.5f; y <= reference.Y + 30; y += 2)
                {
                    float newDist = SC2Util.DistanceSq(target, SC2Util.Point(x, y));

                    if (newDist > distance)
                    {
                        continue;
                    }

                    if (!RectBuildable(x - 0.5f, y - 0.5f, x + 0.5f, y + 0.5f))
                    {
                        continue;
                    }

                    bool blocked = false;
                    foreach (Unit unit in Bot.Main.Observation.Observation.RawData.Units)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 0.5f, y - 0.5f, x + 0.5f, y + 0.5f, SC2Util.To2D(unit.Pos), unit.UnitType))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    foreach (BuildRequest request in ConstructionTask.Task.UnassignedRequests)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 0.5f, y - 0.5f, x + 0.5f, y + 0.5f, request.Pos, request.Type))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    foreach (BuildRequest request in ConstructionTask.Task.BuildRequests)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 0.5f, y - 0.5f, x + 0.5f, y + 0.5f, request.Pos, request.Type))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    foreach (Base b in Bot.Main.BaseManager.Bases)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 0.5f, y - 0.5f, x + 0.5f, y + 0.5f, b.BaseLocation.Pos, UnitTypes.COMMAND_CENTER))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    if (blocked)
                    {
                        continue;
                    }

                    distance = newDist;
                    result   = SC2Util.Point(x, y);
                }
            }
            return(result);
        }
コード例 #3
0
        public static Point2D FindPlacementProduction(Point2D reference, Point2D target, Point2D size, uint type)
        {
            UpdatePylonList();
            Point2D result         = null;
            float   distance       = 1000000;
            bool    secondBuilding = false;

            for (float x = reference.X - 38f; x <= reference.X + 28; x += secondBuilding ? 7f : 3f)
            {
                for (float y = reference.Y - 30f; y <= reference.Y + 30f; y += 3f)
                {
                    float newDist = SC2Util.DistanceSq(target, SC2Util.Point(x, y));

                    if (newDist > distance)
                    {
                        continue;
                    }

                    if (!RectBuildable(x - 2.5f, y - 2.5f, x + 2.5f, y + 2.5f))
                    {
                        continue;
                    }

                    bool blocked = false;
                    foreach (Unit unit in Bot.Main.Observation.Observation.RawData.Units)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 1.5f, y - 1.5f, x + 1.5f, y + 1.5f, SC2Util.To2D(unit.Pos), unit.UnitType))
                        {
                            blocked = true;
                            break;
                        }
                    }
                    foreach (ReservedBuilding building in Bot.Main.buildingPlacer.ReservedLocation)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 1.5f, y - 1.5f, x + 1.5f, y + 1.5f, building.Pos, building.Type))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    foreach (Base b in Bot.Main.BaseManager.Bases)
                    {
                        if (!BuildingPlacer.CheckDistClose(x - 1.5f, y - 1.5f, x + 1.5f, y + 1.5f, b.BaseLocation.Pos, UnitTypes.NEXUS))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    if (blocked)
                    {
                        continue;
                    }

                    if (SC2Util.DistanceSq(new Point2D()
                    {
                        X = 41.5f, Y = 131.5f
                    }, new Point2D()
                    {
                        X = x, Y = y
                    }) <= 3 * 3)
                    {
                        BuildingPlacer.CheckDistDebug(x - 1.5f, y - 1.5f, x + 1.5f, y + 1.5f, new Point2D()
                        {
                            X = 39.5f, Y = 129.5f
                        }, UnitTypes.GATEWAY);
                    }

                    bool hasPower = false;
                    foreach (Agent pylon in Pylons)
                    {
                        if (pylon.Unit.BuildProgress < (Bot.Main.Build.Completed(UnitTypes.GATEWAY) == 0 ? 0.3 : 0.70))
                        {
                            continue;
                        }

                        if (Bot.Main.MapAnalyzer.MapHeight((int)pylon.Unit.Pos.X, (int)pylon.Unit.Pos.Y) < Bot.Main.MapAnalyzer.MapHeight((int)x, (int)y))
                        {
                            continue;
                        }

                        if (IsBuildingInPowerField(new Point2D()
                        {
                            X = x, Y = y
                        }, size, SC2Util.To2D(pylon.Unit.Pos)))
                        {
                            hasPower = true;
                            break;
                        }
                    }
                    if (!hasPower)
                    {
                        continue;
                    }

                    distance = newDist;
                    result   = SC2Util.Point(x, y);
                }
                secondBuilding = !secondBuilding;
            }

            return(result);
        }