Esempio n. 1
0
        /// <summary>
        /// Calculates the magnitude of the specified position on the map relative to the centroid of the squad 
        /// (being close to the other units in the squad will give the best magnitude/attraction).
        /// </summary>
        /// <param name="squad"></param>
        /// <param name="possibleNextPosition"></param>
        /// <param name="force"></param>
        /// <param name="forceStep"></param>
        /// <param name="rangePercentage">How big the Range to the centroid of all the Units positions in the Squad/Group</param>
        /// <returns>The magnitude of squad attraction. 0 if a unit is inside the specified range and gives a negative linear drop-off the further away the unit is from the group.</returns>
        public double PFSquadAttraction(List<UnitAgent> squad, Position possibleNextPosition, double force, double forceStep, int rangePercentage)
        {
            var unitPositions = new Position[squad.Count];

            if (SWIG.BWAPI.bwapi.Broodwar.self().getUnits() != null && SWIG.BWAPI.bwapi.Broodwar.self().getUnits().Count > 0)
            {
                int i = 0;
                foreach (UnitAgent meleeUnitAgent in squad)
                {
                    unitPositions[i] = meleeUnitAgent.MyUnit.Position;
                    i++;
                }

                var meleeUnitPolygon = new Polygon(unitPositions);
                double distance = possibleNextPosition.GetDistance(meleeUnitPolygon.FindCentroid());
                return distance <= MyMath.GetPercentageOfMaxDistancePixels(rangePercentage)
                           ? force//0
                           : force - forceStep * distance;
            }
            Logger.Logger.AddAndPrint("Enemy unit list is null or has zero elements in CalculatePFValueForCollisionWithEnemyUnits");
            return 0;
        }