Beispiel #1
0
 private void SetSelectedLocation(BaseLocation loc)
 {
     NewGameChoices.ChosenLocation = loc;
     ScoutView.ClaimHomesteadButton.gameObject.SetActive(loc != null);
     ScoutView.SelectLocationButton.gameObject.SetActive(loc == null);
     ScoutView.ScoutCursor.transform.SetParent(loc == null ? null : ScoutView.ScoutOrreyHorizontal);
 }
        } //TraceBackPath

        private BaseLocation FindNextLocation(BaseLocation location)
        {
            double       bestValue    = double.MaxValue;
            BaseLocation bestLocation = location;

            List <BaseLocation> locations = GetAdjacentLocations(location);
            double foundValue;

            if (locations != null && locations.Count > 0)
            {
                for (int index = 0; index < locations.Count; index++)
                {
                    if (IsLocationValid(locations[index]))
                    {
                        foundValue = GetDistanceNodeValue(locations[index], double.MaxValue);
                        if (foundValue < bestValue)
                        {
                            bestLocation = locations[index];
                            bestValue    = foundValue;
                        }
                    }
                } //index
            }

            return(bestLocation);
        }
 public Node(BaseLocation location, bool end, double doneDistance, double todoDistance)
 {
     this.mLocation = location;
     this.mEnd      = end;
     this.mDistDone = doneDistance;
     this.mDistTodo = todoDistance;
 } //New
        } //AddLocation

        private Node CreateNode(BaseLocation location, Node previousNode, BaseLocation endLocation)
        {
            bool   isEnd    = location.Equals(endLocation);
            double doneDist = previousNode.DoneDistance + GetDistance(location, previousNode.Location);
            double todoDist = location.GetHeuristicDistance(endLocation);

            return(new Node(location, isEnd, doneDist, todoDist));
        } //CreateLocation
        }     //AddAdjacentLocations

        private void AddLocation(BaseLocation location, Node previousNode, BaseLocation endLocation)
        {
            Node item = CreateNode(location, previousNode, endLocation);

            this.mSortedList.Add(item);
            double dist = System.Math.Min(item.DoneDistance, GetDistanceNodeValue(location, System.Convert.ToDouble(int.MaxValue)));

            SetDistanceNodeValue(location, dist);
        } //AddLocation
Beispiel #6
0
        // Check if any crew members will turn on player/crew
        public static void WillCrewMemberTurnAfterHeist(List <BaseCriminal> crew, List <BaseLocation> locations, string locName)
        {
            // Get selected location
            BaseLocation selectedLocation = locations.Find(l => l.Name == locName);

            int locationCash = selectedLocation.Cash;

            // Loop through criminals to see if any fail the morale check
            // If criminal fails, heist is a success
            crew.ForEach(c =>
            {
                if (!c.IsPlayer)
                {
                    int morale = c.Morale;
                    // if morale is less than 40 and another crew member hasn't turned and stole the money first
                    if (morale <= 40 && selectedLocation.crewMemberStoleCash == false)
                    {
                        // Save as traitor for easy understanding
                        BaseCriminal traitor = c;

                        // Generate a new random number between 1-10 to handle the % a person will turn
                        Random r         = new Random();
                        int randomNumber = r.Next(101);
                        int chance30     = 0;
                        int chance50     = 0;
                        int chance70     = 0;
                        int chance100    = 0;

                        // Based on this member's morale, generate a number by chance
                        if (morale >= 30 && morale <= 40)
                        {
                            chance30 = r.Next(31) + 10;
                        }
                        else if (morale >= 20 && morale <= 29)
                        {
                            chance50 = r.Next(51) + 20;
                        }
                        else if (morale >= 10 && morale <= 19)
                        {
                            chance70 = r.Next(71) + 30;
                        }
                        // Chance100 equals the randomNumber so if they're at that level, they'll always turn
                        else if (morale <= 9)
                        {
                            chance100 = randomNumber;
                        }

                        ChanceToTurnAfterHeist(chance30, randomNumber, crew, locations, traitor, locName);
                        ChanceToTurnAfterHeist(chance50, randomNumber, crew, locations, traitor, locName);
                        ChanceToTurnAfterHeist(chance70, randomNumber, crew, locations, traitor, locName);
                        ChanceToTurnAfterHeist(chance100, randomNumber, crew, locations, traitor, locName);
                    }
                }
            });
        }
        } //CreateLocation

        private static double GetDistance(BaseLocation a, BaseLocation b)
        {
            return(a.GetDistance(b));
            //double dist = a.GetDistance(b)
            //bool aValid = IsLocationValid(a)
            //bool bValid = IsLocationValid(b)
            //Dim aMult As Single = 1.0F
            //Dim bMult As Single = 1.0F
            //If aValid = False) aMult = -1.0F
            //If bValid = False) bMult = -1.0F
            //Return dist * 0.5 * aMult + dist * 0.5 * bMult
        } //GetDistance
            } //New

            public double GetDistance(BaseLocation target)
            {
                if (target == null || !(target is MyLocation))
                {
                    return(double.MaxValue);
                }
                MyLocation targetLoc = (MyLocation)target;
                int        dx        = (this.X - targetLoc.X);
                int        dy        = (this.Y - targetLoc.Y);

                return(System.Math.Sqrt(dx * dx + dy * dy));
            } //GetDistance
        } //GetDistanceNodeValue

        private void SetDistanceNodeValue(BaseLocation location, double value)
        {
            int index = FindNodeAtLocation(this.mDistanceNodes, location);

            if (index < 0)
            {
                this.mDistanceNodes.Add(new DistanceNode(location, value));
            }
            else
            {
                this.mDistanceNodes[index].Value = value;
            }
        } //SetDistanceNodeValue
            } //GetDistance

            public double GetHeuristicDistance(BaseLocation target)
            {
                if (target == null || !(target is MyLocation))
                {
                    return(double.MaxValue);
                }
                MyLocation targetLoc = (MyLocation)target;
                double     cons      = 1.2;
                double     result    = cons * System.Math.Abs(this.X - targetLoc.X);

                result += cons * System.Math.Abs(this.Y - targetLoc.Y);
                return(result);
            } //GetHeuristicDistance
            public void CloneTo(BaseLocation item)
            {
                if (item == null)
                {
                    return;
                }

                if (item is MyLocation)
                {
                    MyLocation locItem = (MyLocation)item;
                    this.CloneTo(locItem);
                }
            } //CloneTo
Beispiel #12
0
        void SetMineralLineLocation(BaseLocation baseLocation)
        {
            var vectors = baseLocation.MineralFields.Select(m => new Vector2(m.Pos.X, m.Pos.Y));

            baseLocation.MineralLineLocation = new Point2D {
                X = vectors.Average(v => v.X), Y = vectors.Average(v => v.Y)
            };

            var angle = Math.Atan2(baseLocation.Location.Y - baseLocation.MineralLineLocation.Y, baseLocation.MineralLineLocation.X - baseLocation.Location.X);

            baseLocation.MineralLineBuildingLocation = new Point2D {
                X = baseLocation.MineralLineLocation.X + (float)(3 * Math.Cos(angle)), Y = baseLocation.MineralLineLocation.Y - (float)(3 * Math.Sin(angle))
            };
        }
Beispiel #13
0
        internal void LoadQuickstart()
        {
            this.Init();
            BoughtMatter.Set(Matter.RationMeals, 1);
            ChosenLocation = new BaseLocation()
            {
                Region = MarsRegion.meridiani_planum
            };
            AddOrIncrementVolume(BoughtMatter, Matter.Water, 2);
            AddOrIncrementVolume(BoughtMatter, Matter.Oxygen, 2);
            this.AddSuppliesFromModule(Module.SmallGasTank);
            this.AddSuppliesFromModule(Module.SabatierReactor);

            this.RecalculateFunds();
        }
        } //GetPath

        #region "Collection Helper Functions"
        private static int FindNodeAtLocation(List <Node> nodes, BaseLocation location)
        {
            if (nodes != null && nodes.Count > 0)
            {
                for (int index = 0; index < nodes.Count; index++)
                {
                    if (nodes[index].Location.Equals(location))
                    {
                        return(index);
                    }
                } //index
            }

            return(-1);
        } //FindNodeAtLocation
Beispiel #15
0
        Point2D GetMiningSpot(BaseLocation nexusBase)
        {
            if (nexusBase == null)
            {
                return(null);
            }
            var mineralPos = nexusBase.MineralLineLocation;

            var angle = Math.Atan2(nexusBase.Location.Y - mineralPos.Y, mineralPos.X - nexusBase.Location.X);
            var x     = nexusBase.ResourceCenter.Radius * Math.Cos(angle);
            var y     = nexusBase.ResourceCenter.Radius * Math.Sin(angle);

            return(new Point2D {
                X = nexusBase.Location.X + (float)x, Y = nexusBase.Location.Y - (float)y
            });
        }
            internal override List <BaseLocation> GetAdjacentLocations(BaseLocation location)
            {
                if (location == null || !(location is MyLocation))
                {
                    return(null);
                }
                MyLocation myLocation = (MyLocation)location;

                List <BaseLocation> result = new List <BaseLocation>();

                result.Add(new MyLocation(myLocation.X - 1, myLocation.Y));
                result.Add(new MyLocation(myLocation.X + 1, myLocation.Y));
                result.Add(new MyLocation(myLocation.X, myLocation.Y - 1));
                result.Add(new MyLocation(myLocation.X, myLocation.Y + 1));
                return(result);
            } //GetAdjacentLocations
        } //GetDistance

        #endregion 'Node Helper Functions

        #region "Tracing Helper Functions"
        private List <BaseLocation> TraceBackPath(BaseLocation startLocation, BaseLocation endLocation)
        {
            List <BaseLocation> locationList = new List <BaseLocation>();

            locationList.Add(endLocation);

            BaseLocation currentLocation = endLocation;

            while (!currentLocation.Equals(startLocation))
            {
                currentLocation = FindNextLocation(currentLocation);
                locationList.Add(currentLocation);
            }

            return(locationList);
        } //TraceBackPath
Beispiel #18
0
        float checkPosition(Point2D position, BaseLocation location)
        {
            foreach (var mineralField in location.MineralFields)
            {
                if (Math.Abs(mineralField.Pos.X - position.X) + Math.Abs(mineralField.Pos.Y - position.Y) <= 10 && Math.Abs(mineralField.Pos.X - position.X) <= 5.5 && Math.Abs(mineralField.Pos.Y - position.Y) <= 5.5)
                {
                    return(100000000);
                }
            }
            foreach (var gas in location.VespeneGeysers)
            {
                if (Math.Abs(gas.Pos.X - position.X) + Math.Abs(gas.Pos.Y - position.Y) <= 11 && Math.Abs(gas.Pos.X - position.X) <= 6.1 && Math.Abs(gas.Pos.Y - position.Y) <= 6.1)
                {
                    return(100000000);
                }

                if (Vector2.DistanceSquared(new Vector2(gas.Pos.X, gas.Pos.Y), new Vector2(position.X, position.Y)) >= 121)
                {
                    return(100000000);
                }
            }

            // Check if a resource center can actually be built here.
            for (float x = -2.5f; x < 2.5f + 0.1f; x++)
            {
                for (float y = -2.5f; y < 2.5f + 0.1f; y++)
                {
                    if (!GetTilePlacable((int)Math.Round(position.X + x), (int)Math.Round(position.Y + y)))
                    {
                        return(100000000);
                    }
                }
            }

            float maxDist = 0;

            foreach (var mineralField in location.MineralFields)
            {
                maxDist += Vector2.DistanceSquared(new Vector2(mineralField.Pos.X, mineralField.Pos.Y), new Vector2(position.X, position.Y));
            }

            foreach (var gas in location.VespeneGeysers)
            {
                maxDist += Vector2.DistanceSquared(new Vector2(gas.Pos.X, gas.Pos.Y), new Vector2(position.X, position.Y));
            }
            return(maxDist);
        }
Beispiel #19
0
        public override void InitializeTasks()
        {
            base.InitializeTasks();
            TimingAttackTask.Enable();
            WorkerScoutTask.Enable();
            QueenInjectTask.Enable();
            QueenDefenseTask.Enable();
            ArmyOverseerTask.Enable();
            QueenTumorTask.Enable();
            DefenseTask.Enable();
            WorkerRushDefenseTask.Enable();
            OverlordSuicideTask.Enable();
            SafeZerglingsFromReapersTask.Enable();

            BaseLocation enemyNatural = Tyr.Bot.MapAnalyzer.GetEnemyNatural();

            if (enemyNatural != null)
            {
                Base enemyNaturalBase = null;
                foreach (Base b in Tyr.Bot.BaseManager.Bases)
                {
                    if (SC2Util.DistanceSq(b.BaseLocation.Pos, enemyNatural.Pos) <= 2 * 2)
                    {
                        enemyNaturalBase = b;
                        break;
                    }
                }
                DefendEnemyNaturalTask = new DefenseSquadTask(enemyNaturalBase, UnitTypes.ZERGLING);
                DefendEnemyNaturalTask.MaxDefenders       = 100;
                DefendEnemyNaturalTask.AlwaysNeeded       = true;
                DefendEnemyNaturalTask.DraftFromFarAway   = true;
                DefendEnemyNaturalTask.DefendRange        = 12;
                DefendEnemyNaturalTask.RetreatMoveCommand = true;

                PotentialHelper potential = new PotentialHelper(enemyNatural.Pos);
                potential.Magnitude = 10;
                potential.From(Tyr.Bot.MapAnalyzer.GetEnemyRamp());
                DefendEnemyNaturalTask.OverrideIdleLocation = potential.Get();

                potential           = new PotentialHelper(enemyNatural.Pos);
                potential.Magnitude = 5;
                potential.From(Tyr.Bot.MapAnalyzer.GetEnemyRamp());
                DefendEnemyNaturalTask.OverrideDefenseLocation = potential.Get();
                DefenseSquadTask.Enable(DefendEnemyNaturalTask);
            }
        }
        } //IsUnVisited

        private void AddAdjacentLocations(Node previousNode, BaseLocation endLocation)
        {
            List <BaseLocation> locations = GetAdjacentLocations(previousNode.Location);

            if (locations == null || locations.Count == 0)
            {
                return;
            }

            for (int index = 0; index < locations.Count; index++)
            {
                if (this.IsLocationValid(locations[index]) && this.IsUnVisited(locations[index]))
                {
                    AddLocation(locations[index], previousNode, endLocation);
                }
            } //index
        }     //AddAdjacentLocations
            } //GetAdjacentLocations

            internal override bool IsLocationValid(BaseLocation location)
            {
                if (location == null || !(location is MyLocation))
                {
                    return(false);
                }
                MyLocation myLocation = (MyLocation)location;

                if (myLocation.X >= 1 && myLocation.Y >= 1 && myLocation.X <= this.Map.Width && myLocation.Y <= this.Map.Height)
                {
                    return(!this.Map.Item[myLocation.X - 1, myLocation.Y - 1]);
                }
                else
                {
                    return(false);
                }
            } //IsLocationValid
        public List <BaseLocation> GetPath(BaseLocation startLocation, BaseLocation endLocation)
        {
            // First check to see if(the starting and end locations are valid (in bounds, and not blocked), if(not return failure.
            if (!this.IsLocationValid(startLocation) || !this.IsLocationValid(endLocation))
            {
                return(null);
            }

            this.mDistanceNodes.Clear(); //just be reading Position, and DoneDistance()
            this.mVisitedNodes.Clear();  //just be finding out if(a node exists or not at BaseLocation.

            // Add the start location.
            Node startNode = new Node(startLocation, false, 0, -1);

            this.mSortedList.Clear();
            this.mSortedList.Add(startNode);
            this.mDistanceNodes.Add(new DistanceNode(startNode));

            Node tempLocation = null;
            bool endIsFound   = false;

            // Find the path.
            while (this.mSortedList.HasNext())
            {
                // Get the next node to check.
                tempLocation = this.mSortedList.GetNext();
                // if(the node is not visited then ...
                if (FindNodeAtLocation(this.mVisitedNodes, tempLocation.Location) < 0)
                {
                    this.mVisitedNodes.Add(tempLocation);
                    if (tempLocation.IsEnd)
                    {
                        endIsFound = true;
                        break;
                    }
                    else
                    {
                        AddAdjacentLocations(tempLocation, endLocation);
                    }
                }
            }

            // Resolve the path.
            return(endIsFound ? this.TraceBackPath(startLocation, endLocation) : null);
        } //GetPath
Beispiel #23
0
        // If an associate turns, lower morale
        public static void ChanceToTurnAfterHeist(
            int chanceInt,
            int randFrom100,
            List <BaseCriminal> crew,
            List <BaseLocation> locations,
            BaseCriminal traitor,
            string locName)
        {
            // If the percentage chance is under the random value picked
            if (chanceInt != 0 && chanceInt >= randFrom100)
            {
                // Get selected location
                BaseLocation selectedLocation = locations.Find(l => l.Name == locName);

                // Lower everyone's Morale
                crew.ForEach(c =>
                {
                    if (c.IsPlayer == false)
                    {
                        c.Morale = c.Morale - new Random().Next(10, 35);
                    }
                });

                // Set the current location to stolen
                locations.ForEach(l =>
                {
                    if (l.Name == locName)
                    {
                        l.crewMemberStoleCash = true;
                    }
                });

                // Get the traitor's index value
                int traitorsIndex = crew.IndexOf(traitor);
                // Remove that index value
                crew.RemoveAt(traitorsIndex);
                // Remove the cash from the crew
                crew.ForEach(c => c.CrewTotalCash = c.CrewTotalCash - selectedLocation.Cash);

                TraitorScreen(crew, locations, locName, traitor);
            }
        }
Beispiel #24
0
    private void HandleScoutInput()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (NewGameChoices.ChosenLocation == null && Physics.Raycast(ray, out hit))
        {
            hoverLocation = new BaseLocation()
            {
                Region  = GeoExtensions.ParseRegion(hit.collider.name),
                LatLong = LatLong.FromPointOnUnitSphere(ScoutView.ScoutOrreyHorizontal.transform.InverseTransformPoint(hit.point))
            };
            ScoutView.FillScoutInfo(hoverLocation.Region, hoverLocation.LatLong);
            ScoutView.ScoutCursor.position = hit.point;
            ScoutView.ScoutCursor.rotation = Quaternion.LookRotation(hit.normal);
        }

        if (Input.GetMouseButtonDown(0))
        {
            SetSelectedLocation(hoverLocation);
        }
        else if (Input.GetMouseButtonDown(1))
        {
            SetSelectedLocation(null);
        }
        else
        {
            float xDelta = CrossPlatformInputManager.GetAxis("Horizontal");
            float yDelta = CrossPlatformInputManager.GetAxis("Vertical");

            if (xDelta != 0f)
            {
                ScoutView.ScoutOrreyHorizontal.transform.Rotate(Vector3.up, xDelta, Space.Self);
            }

            if (yDelta != 0f)
            {
                ScoutView.ScoutOrreyVertical.transform.Rotate(Vector3.forward, -yDelta, Space.Self);
            }
        }
    }
Beispiel #25
0
        // Display traitor info
        public static void TraitorScreen(List <BaseCriminal> crew, List <BaseLocation> locations, string locName, BaseCriminal traitor)
        {
            Color.CrewTurnedYellow();

            BaseLocation currentLocation = locations.Find(l => l.Name == locName);

            Console.WriteLine(Heading.DisplayHeadingTraitor());
            Console.WriteLine(Heading.DisplaySubheadingTraitor());
            Console.WriteLine("");
            Console.WriteLine($"{traitor.Face}");
            Console.WriteLine("");
            Console.WriteLine($"{traitor.Name} stole ${currentLocation.Cash}");
            Console.WriteLine("--------------------");
            Console.WriteLine("Crew skill improved.");
            Console.WriteLine("Crew morale decreased.");
            Console.WriteLine("");
            Console.WriteLine("Watch the crew. Unhappy members may turn.");
            Console.WriteLine("");

            Menu.Continue();
            Level.LevelSelect(crew, locations);
        }
Beispiel #26
0
        public static void HeistSuccess(List <BaseCriminal> crew, List <BaseLocation> locations, string locName)
        {
            Color.SuccessGreen();

            // Morale check before continuing
            CrewLogicHeist.WillCrewMemberTurnAfterHeist(crew, locations, locName);

            Console.WriteLine(Heading.DisplayHeistSuccess());
            Console.WriteLine(Misc.DisplayMoney());
            Console.WriteLine(Heading.DisplaySuccessOveriew());

            BaseLocation currentLocation = locations.Find(l => l.Name == locName);
            BaseCriminal player          = crew.Find(c => c.IsPlayer);
            int          cashEarned      = player.CrewTotalCash;

            // Display how much money we earned from location
            Console.WriteLine($"Crew stole: ${currentLocation.Cash}");
            // Total earned
            if (cashEarned != currentLocation.Cash)
            {
                Console.WriteLine($"Total cash: ${cashEarned}");
            }
            // how much the current split will be if it's more than one crew member
            if (crew.Count() > 1)
            {
                Console.WriteLine($"The split per crew member will be: ${cashEarned / crew.Count()}");
                Console.WriteLine("----");
                Console.WriteLine("Crew skill increased");
                Console.WriteLine("Crew morale increased");
            }
            else if (crew.Count() == 1)
            {
                Console.WriteLine("Your skill increased");
            }
            Console.WriteLine("");
            Menu.Continue();
            Level.LevelSelect(crew, locations);
        }
Beispiel #27
0
        private void UpdateEnemyBases()
        {
            if (EnemyBases.Count > 0)
            {
                return;
            }

            if (EnemyMain == null && Bot.Main.TargetManager.PotentialEnemyStartLocations.Count == 1)
            {
                EnemyMain = Bot.Main.TargetManager.PotentialEnemyStartLocations[0];
            }
            if (EnemyNatural == null && Bot.Main.TargetManager.PotentialEnemyStartLocations.Count == 1)
            {
                BaseLocation enemyNaturalBase = Bot.Main.MapAnalyzer.GetEnemyNatural();
                if (enemyNaturalBase != null)
                {
                    EnemyNatural = enemyNaturalBase.Pos;
                }
            }

            foreach (Base b in Bot.Main.BaseManager.Bases)
            {
                if (b.Owner != -1)
                {
                    continue;
                }
                if (SC2Util.DistanceSq(b.BaseLocation.Pos, EnemyNatural) <= 2 * 2)
                {
                    continue;
                }
                float enemyMainDistance = SC2Util.DistanceSq(b.BaseLocation.Pos, EnemyMain);
                if (enemyMainDistance <= 2 * 2 || enemyMainDistance >= EnemyBaseRange * EnemyBaseRange)
                {
                    continue;
                }
                EnemyBases.Add(b);
            }
        }
Beispiel #28
0
        public static void StartGame()
        {
            // Displays intro, creates levels, player, crew, and enters the LevelSelect loop
            Color.DefaultGray();
            Console.Clear();
            Intro.DisplayIntro();

            // Create all the levels in memory
            BaseLocation        getLocations = new BaseLocation();
            List <BaseLocation> locations    = getLocations.GenerateAllLocations();

            // Create the player & initial crew
            List <BaseCriminal> currentCrew = Intro.CreateInitialCrew();

            // Only show the crew created message if you made a crew
            if (currentCrew.Count() > 1)
            {
                Intro.ShowCrewCreatedMsg(currentCrew);
            }

            // Begin LevelSelect while loop that runs until the player runs out of locations to rob, then begin end game
            Level.LevelSelect(currentCrew, locations);
        }
Beispiel #29
0
        public void OnStart(Tyr tyr)
        {
            int[,] distances = tyr.MapAnalyzer.Distances(SC2Util.To2D(tyr.MapAnalyzer.StartLocation));
            BaseLocation natural = null;
            int          dist    = 1000000000;

            foreach (BaseLocation loc in tyr.MapAnalyzer.BaseLocations)
            {
                int  distanceToMain = distances[(int)loc.Pos.X, (int)loc.Pos.Y];
                Base newBase        = new Base()
                {
                    BaseLocation = loc, DistanceToMain = distanceToMain
                };
                Bases.Add(newBase);

                if (distanceToMain <= 5)
                {
                    Main = newBase;
                }
                else if (tyr.MapAnalyzer.MainAndPocketArea[loc.Pos])
                {
                    Pocket = newBase;
                    System.Console.WriteLine("Found pocket base at: " + Pocket.BaseLocation.Pos);
                }
                else if (distanceToMain < dist)
                {
                    natural = loc;
                    dist    = distanceToMain;
                    Natural = newBase;
                }
            }

            System.Console.WriteLine("Mapname: " + tyr.GameInfo.MapName);

            NaturalDefensePos = tyr.MapAnalyzer.Walk(natural.Pos, tyr.MapAnalyzer.EnemyDistances, 10);
            int distToEnemy = tyr.MapAnalyzer.EnemyDistances[(int)NaturalDefensePos.X, (int)NaturalDefensePos.Y];
            int wallDist    = tyr.MapAnalyzer.WallDistances[(int)NaturalDefensePos.X, (int)NaturalDefensePos.Y];

            for (int x = (int)NaturalDefensePos.X - 5; x <= NaturalDefensePos.X + 5; x++)
            {
                for (int y = (int)NaturalDefensePos.Y - 5; y <= NaturalDefensePos.Y + 5; y++)
                {
                    if (SC2Util.DistanceSq(SC2Util.Point(x, y), natural.Pos) <= 7 * 7 ||
                        SC2Util.DistanceSq(SC2Util.Point(x, y), natural.Pos) >= 10 * 10)
                    {
                        continue;
                    }
                    if (tyr.MapAnalyzer.EnemyDistances[x, y] > distToEnemy)
                    {
                        continue;
                    }
                    int newDist = tyr.MapAnalyzer.WallDistances[x, y];
                    if (newDist > wallDist)
                    {
                        wallDist          = newDist;
                        NaturalDefensePos = SC2Util.Point(x, y);
                    }
                }
            }
            MainDefensePos = tyr.MapAnalyzer.Walk(SC2Util.To2D(tyr.MapAnalyzer.StartLocation), tyr.MapAnalyzer.EnemyDistances, 10);
        }
Beispiel #30
0
        public override void OnFrame(Tyr tyr)
        {
            tyr.DrawText("HydraTransitionFrame: " + HydraTransitionFrame);
            int          enemyNaturalWorkerCount = 0;
            BaseLocation enemyNatural            = tyr.MapAnalyzer.GetEnemyNatural();
            bool         enemyNaturalRemains     = enemyNatural == null;

            foreach (Unit enemy in tyr.Enemies())
            {
                if (enemyNatural == null)
                {
                    break;
                }
                if (UnitTypes.ResourceCenters.Contains(enemy.UnitType) && !enemy.IsFlying && SC2Util.DistanceSq(enemy.Pos, enemyNatural.Pos) < 2 * 2)
                {
                    enemyNaturalRemains = true;
                    continue;
                }
                if (!UnitTypes.WorkerTypes.Contains(enemy.UnitType))
                {
                    continue;
                }
                if (SC2Util.DistanceSq(enemy.Pos, enemyNatural.Pos) > 14 * 14)
                {
                    continue;
                }
                enemyNaturalWorkerCount++;
            }

            bool zerglingInEnemyNatural = false;

            foreach (Agent agent in tyr.UnitManager.Agents.Values)
            {
                if (agent.Unit.UnitType == UnitTypes.ZERGLING && agent.DistanceSq(enemyNatural.Pos) <= 10 * 10)
                {
                    zerglingInEnemyNatural = true;
                }
            }

            if (AllowHydraTransition && HydraTransitionFrame >= 1000000000 && tyr.EnemyStrategyAnalyzer.TotalCount(UnitTypes.PHOTON_CANNON) >= 3)
            {
                HydraTransitionFrame = tyr.Frame;
            }
            if (AllowHydraTransition && HydraTransitionFrame >= 1000000000 && tyr.Frame >= 22.4 * 60 * 5.5)
            {
                HydraTransitionFrame = tyr.Frame;
            }
            if (AllowHydraTransition && HydraTransitionFrame >= 1000000000 && Count(UnitTypes.ZERGLING) >= 25 && zerglingInEnemyNatural && enemyNaturalWorkerCount == 0 && !enemyNaturalRemains)
            {
                HydraTransitionFrame = (int)(tyr.Frame + 22.4 * 10);
            }
            if (AllowHydraTransition && HydraTransitionFrame >= 1000000000 && Count(UnitTypes.ZERGLING) >= 25 && tyr.EnemyStrategyAnalyzer.TotalCount(UnitTypes.REAPER) >= 2)
            {
                HydraTransitionFrame = (int)(tyr.Frame + 22.4 * 10);
            }

            if (DefendEnemyNaturalTask != null)
            {
                DefendEnemyNaturalTask.Stopped = tyr.EnemyStrategyAnalyzer.Count(UnitTypes.PHOTON_CANNON) < 3 || tyr.EnemyStrategyAnalyzer.TotalCount(UnitTypes.COLOSUS) > 0;
                if (DefendEnemyNaturalTask.Stopped)
                {
                    DefendEnemyNaturalTask.Clear();
                }
            }

            if (HydraTransitionFrame < 1000000000 || tyr.EnemyRace != Race.Terran)
            {
                OverlordSuicideTask.Task.Stopped = true;
                OverlordSuicideTask.Task.Clear();
            }
            else
            {
                OverlordSuicideTask.Task.Stopped = false;
            }

            if (TimingAttackTask.Task.AttackSent && !OverlordSuicideTask.Task.Suicide)
            {
                foreach (Agent agent in tyr.UnitManager.Agents.Values)
                {
                    if (agent.Unit.UnitType == UnitTypes.ZERGLING && agent.DistanceSq(tyr.TargetManager.PotentialEnemyStartLocations[0]) <= 80 * 80)
                    {
                        OverlordSuicideTask.Task.Suicide = true;
                    }
                }
            }

            if (tyr.TargetManager.PotentialEnemyStartLocations.Count <= 1)
            {
                WorkerScoutTask.Task.Stopped = true;
            }

            if (UpgradeType.LookUp[UpgradeType.MetabolicBoost].Done())
            {
                SafeZerglingsFromReapersTask.Task.Stopped = true;
                SafeZerglingsFromReapersTask.Task.Clear();
            }

            if (MeleeUpgrade == 0 && Tyr.Bot.Observation.Observation.RawData.Player.UpgradeIds.Contains(53))
            {
                MeleeUpgrade = 1;
            }
            else if (MeleeUpgrade == 1 && Tyr.Bot.Observation.Observation.RawData.Player.UpgradeIds.Contains(54))
            {
                MeleeUpgrade = 2;
            }
            else if (MeleeUpgrade == 2 && Tyr.Bot.Observation.Observation.RawData.Player.UpgradeIds.Contains(55))
            {
                MeleeUpgrade = 3;
            }

            if (ArmorUpgrade == 0 && Tyr.Bot.Observation.Observation.RawData.Player.UpgradeIds.Contains(56))
            {
                ArmorUpgrade = 1;
            }
            else if (ArmorUpgrade == 1 && Tyr.Bot.Observation.Observation.RawData.Player.UpgradeIds.Contains(57))
            {
                ArmorUpgrade = 2;
            }
            else if (ArmorUpgrade == 2 && Tyr.Bot.Observation.Observation.RawData.Player.UpgradeIds.Contains(58))
            {
                ArmorUpgrade = 3;
            }

            ResearchingUpgrades = 0;
            for (uint ability = 1186; ability <= 1191; ability++)
            {
                if (Tyr.Bot.UnitManager.ActiveOrders.Contains(ability))
                {
                    ResearchingUpgrades++;
                }
            }

            if (!Tyr.Bot.Observation.Observation.RawData.Player.UpgradeIds.Contains(66) &&
                !Tyr.Bot.UnitManager.ActiveOrders.Contains(1253))
            {
                if (Gas() < 92)
                {
                    GasWorkerTask.WorkersPerGas = 3;
                }
                else if (Gas() < 96)
                {
                    GasWorkerTask.WorkersPerGas = 2;
                }
                else if (Gas() < 100)
                {
                    GasWorkerTask.WorkersPerGas = 1;
                }
                else if (Gas() >= 100)
                {
                    GasWorkerTask.WorkersPerGas = 0;
                }
            }
            else if (TimingAttackTask.Task.AttackSent || tyr.Frame >= HydraTransitionFrame)
            {
                GasWorkerTask.WorkersPerGas = 3;
            }
            else
            {
                GasWorkerTask.WorkersPerGas = 0;
            }

            if (tyr.EnemyStrategyAnalyzer.Count(UnitTypes.PHOTON_CANNON) >= 3 && Completed(UnitTypes.HYDRALISK) < 20 && Completed(UnitTypes.ZERGLING) >= 40)
            {
                TimingAttackTask.Task.Clear();
                TimingAttackTask.Task.Stopped = true;
            }
            else
            {
                TimingAttackTask.Task.Stopped = false;
            }

            if (tyr.EnemyStrategyAnalyzer.Count(UnitTypes.PHOTON_CANNON) >= 3 && Completed(UnitTypes.ZERGLING) >= 40)
            {
                TimingAttackTask.Task.RequiredSize = 70;
                TimingAttackTask.Task.RetreatSize  = 5;
            }
            else if (tyr.Frame >= HydraTransitionFrame && Count(UnitTypes.HYDRALISK) < 20 && !UpgradeType.LookUp[UpgradeType.MetabolicBoost].Done())
            {
                TimingAttackTask.Task.RequiredSize = 50;
                TimingAttackTask.Task.RetreatSize  = 5;
            }
            else if (tyr.Frame >= HydraTransitionFrame && tyr.EnemyStrategyAnalyzer.TotalCount(UnitTypes.COLOSUS) > 0)
            {
                TimingAttackTask.Task.RequiredSize = 40;
                TimingAttackTask.Task.RetreatSize  = 8;
            }
            else if (tyr.Frame >= HydraTransitionFrame)
            {
                TimingAttackTask.Task.RequiredSize = 30;
                TimingAttackTask.Task.RetreatSize  = 5;
            }
            else if (TimingAttackTask.Task.AttackSent)
            {
                TimingAttackTask.Task.RequiredSize = 20;
                TimingAttackTask.Task.RetreatSize  = 0;
            }
            else
            {
                TimingAttackTask.Task.RequiredSize = 50;
                TimingAttackTask.Task.RetreatSize  = 0;
            }

            DefenseTask.GroundDefenseTask.MainDefenseRadius   = 20;
            DefenseTask.GroundDefenseTask.ExpandDefenseRadius = 18;
            DefenseTask.GroundDefenseTask.MaxDefenseRadius    = 55;
            DefenseTask.AirDefenseTask.MainDefenseRadius      = 20;
            DefenseTask.AirDefenseTask.ExpandDefenseRadius    = 18;
            DefenseTask.AirDefenseTask.MaxDefenseRadius       = 55;
        }