Esempio n. 1
0
        private List <Waypoint> FindPath(Tile startPosition, PotentialMap potentialMap)
        {
            var currentWeight = int.MaxValue;
            var currentTile   = startPosition;
            var path          = new List <Waypoint>();

            while (currentWeight > 0)
            {
                var neighbours            = currentTile.NeighbouringTiles;
                var lowestWeight          = int.MaxValue;
                var lowestWeightNeighbour = default(Tile);

                foreach (var neighbour in neighbours)
                {
                    var neighbourWeight = potentialMap.GetWeight(neighbour);
                    if (neighbourWeight < lowestWeight)
                    {
                        lowestWeight          = neighbourWeight;
                        lowestWeightNeighbour = neighbour;
                    }
                }

                var duration = currentWeight - lowestWeight;
                currentWeight = lowestWeight;
                currentTile   = lowestWeightNeighbour;
                path.Add(new Waypoint(duration * _settings.WeightDurationRatio, currentTile.gameObject.transform.position));
            }

            return(path);
        }
Esempio n. 2
0
    /// <summary>
    /// Creates a list that contains a tile and its weight that depends on its type & the path to it.
    /// </summary>
    /// <param name="building">Building to use as starting point for the potential map</param>
    public PotentialMap CreatePotentialFieldMapFor(Building building)
    {
        Tile buildingsTile   = building.Tile;
        var  potentialFields = new PotentialMap(buildingsTile, _tileWeights);

        return(potentialFields);
    }
Esempio n. 3
0
        public float MapValue(PotentialMap map, Vector2 position)
        {
            Point index = Game.GameManager.Navigation.IndexFromPosition(position);

            if (map.Grid.TestBounds(index))
            {
                return(map.Grid[index].Value);
            }
            return(map.LinearParameters.MinValue);
        }
Esempio n. 4
0
        public void NavigateToBestValue(PotentialMap map)
        {
            Point index = Game.GameManager.Navigation.IndexFromPosition(Player.Position);

            if (Game.GameManager.Navigation.Parameters.Debug)
            {
                Engine.Debug.Screen.ResetBrush(); Engine.Debug.Screen.Brush.DrawSurface = false;
                Engine.Debug.Screen.AddSquare(Game.GameManager.Navigation.NavigationGrid[index].Position, Game.GameManager.Navigation.Parameters.GridSpacing / 2);
            }

            if (map.Grid.TestBounds(index))
            {
                Vector2 grad = map.Gradient(index);

                Engine.Log.Debug("Player " + Player.PlayerIndex + " panic", "no");
                if (grad != Vector2.Zero)
                {
                    Move(grad);
                }
                else
                {
                    NavigationCell bestCell = null;
                    NavigationCell navCell  = Game.GameManager.Navigation.NavigationGrid[index];
                    foreach (var nextCell in navCell.Neighbours)
                    {
                        if (nextCell == null)
                        {
                            continue;
                        }

                        if (map.Grid[nextCell.Index].Value < map.Grid[index].Value)
                        {
                            continue;
                        }

                        if (bestCell != null && map.Grid[nextCell.Index].Value < map.Grid[bestCell.Index].Value)
                        {
                            continue;
                        }

                        Engine.Log.Debug("Player " + Player.PlayerIndex + " panic", "yes");

                        if (NavigationManager.RayCastVisibility(Player.Position, nextCell.Position))
                        {
                            bestCell = nextCell;
                        }
                    }

                    if (bestCell != null)
                    {
                        MoveToPosition(bestCell.Position);
                    }
                }
            }
        }
Esempio n. 5
0
        public void MoveToShootPosition()
        {
            PotentialMap shootMap = null;

            if (Game.Arena.LeftGoal.Team == PlayerAI.Player.Team)
            {
                shootMap = Game.GameManager.Navigation.PotentialMaps["ShootRight"];
            }
            else
            {
                shootMap = Game.GameManager.Navigation.PotentialMaps["ShootLeft"];
            }
            PlayerAI.NavigateToBestValue(shootMap);
        }
Esempio n. 6
0
        public override void Start()
        {
            m_mouseCtrl = new KeyControl(MouseButtons.Left);

            m_initialPositionMap                = new PotentialMap(Game.GameManager.Navigation, PotentialMapType.Linear);
            m_initialPositionMapSource          = new PotentialMapInfluencePoint();
            m_initialPositionMapSource.Radius   = 80;
            m_initialPositionMapSource.Value    = 1;
            m_initialPositionMapSource.Position = Player.InitialPosition;
            m_initialPositionMap.Sources.Add(m_initialPositionMapSource);
            var launcherObstacle = new PotentialMapInfluencePoint();

            launcherObstacle.Radius   = 60;
            launcherObstacle.Value    = 5.0f;
            launcherObstacle.Position = Vector2.Zero;
            m_initialPositionMap.Costs.Add(launcherObstacle);
            Game.GameManager.Navigation.PotentialMaps.Add("IntialPositionMap" + (int)Player.PlayerIndex, m_initialPositionMap);

            m_assistMap = new PotentialMap(Game.GameManager.Navigation, PotentialMapType.Linear);
            m_assistMap.Sources.Add(new AssistPlayerPotentialSource()
            {
                Assistee = Player.TeamMate, Assistant = Player
            });
            m_assistMap.LinearParameters.SpatialDecay = 0.03f;
            Game.GameManager.Navigation.PotentialMaps.Add("AssistMap" + (int)Player.PlayerIndex, m_assistMap);

            m_aiParams = new AIParameters();
            m_aiParams.Agressiveness  = Engine.Debug.EditSingle("AIAgressiveness", 0.5f);
            m_aiParams.Precision      = Engine.Debug.EditSingle("AIPrecision", 0.5f);
            m_aiParams.TacticalSkills = Engine.Debug.EditSingle("AiTactics", 0.5f);

            m_aiState = new AIState();
            m_aiState.SkillFluctuationPhase = Engine.Random.NextFloat(0, 1000);

            m_script          = new AssistAndDefendScript();
            m_script.PlayerAI = this;
            m_script.Start();

            m_gameInfos                = new GameInfo();
            m_gameInfos.BallInGoal     = false;
            m_gameInfos.BallShotByTeam = false;
            m_gameInfos.BallShotTime   = float.NegativeInfinity;
            m_gameInfos.BallTakenTime  = float.NegativeInfinity;

            Engine.World.EventManager.AddListener((int)EventId.Goal, OnGoal);
            Engine.World.EventManager.AddListener((int)EventId.KickOff, OnKickOff);
            Engine.World.EventManager.AddListener((int)EventId.PlayerShootBall, OnPlayerShootBall);
            Engine.World.EventManager.AddListener((int)EventId.PlayerReceiveBall, OnPlayerReceiveBall);
        }
Esempio n. 7
0
        private void MoveToDefense()
        {
            Engine.Log.Debug("State " + PlayerAI.Player.PlayerIndex, "Defend");
            PotentialMap defenseMap = null;

            if (Game.Arena.LeftGoal.Team == PlayerAI.Player.Team)
            {
                defenseMap = Game.GameManager.Navigation.PotentialMaps["ShootLeft"];
            }
            else
            {
                defenseMap = Game.GameManager.Navigation.PotentialMaps["ShootRight"];
            }
            PlayerAI.NavigateToBestValue(defenseMap);
        }
Esempio n. 8
0
        public void NavigateWithMapAndRaycast(PotentialMap map, Vector2 position)
        {
            float rayCastDist = 250;
            float distSq      = Vector2.DistanceSquared(Player.Position, position);

            if (distSq < rayCastDist * rayCastDist && NavigationManager.RayCastVisibility(Player.Position, position))
            {
                Engine.Debug.Screen.ResetBrush(); Engine.Debug.Screen.Brush.DrawSurface = false;
                Engine.Debug.Screen.AddLine(Player.Position, position);
                MoveToPosition(position);
            }
            else
            {
                NavigateToBestValue(map);
            }
        }
Esempio n. 9
0
        public float GetDefenseValue(Team team, Vector2 pos)
        {
            PotentialMap shootMap = null;

            if (Game.Arena.LeftGoal.Team == team)
            {
                shootMap = Game.GameManager.Navigation.PotentialMaps["ShootLeft"];
            }
            else
            {
                shootMap = Game.GameManager.Navigation.PotentialMaps["ShootRight"];
            }

            Point index = Game.GameManager.Navigation.IndexFromPosition(pos);

            return(shootMap.Grid[index].Value);
        }
Esempio n. 10
0
        internal void Move(GameObject gameObject, Tile startPosition, PotentialMap potentialMap)
        {
            List <Waypoint> path = FindPath(startPosition, potentialMap);

            StartCoroutine(MovementCoroutine(gameObject, path));
        }