Beispiel #1
0
    public bool StartSimulation(out string errorMessage)
    {
        bool result = false;

        errorMessage = "Start and End Tiles\nare not defined!";

        if (mStartTileObj != null && mEndTileObj != null)
        {
            PathFinder pf   = new PathFinder();
            var        path = pf.Astar(Map, mStartTileObj.Pos, mEndTileObj.Pos);

            // Instant visualization
            // VisualizePath(path);

            if (path != null)
            {
                // Incremantal visualization
                StartCoroutine(VisualizePathRoutine(path));
                errorMessage = "Path found :)";
                result       = true;
            }
            else
            {
                errorMessage = "Can't find path!";
                result       = false;
            }
        }

        return(result);
    }
Beispiel #2
0
 /// <summary>
 /// Calcule la trajectoire de ce Virus.
 /// </summary>
 void ComputePath()
 {
     if (m_currentAgro != null)
     {
         m_path = new Trajectory(PathFinder.Astar(this.Position, m_currentAgro.Position));
     }
 }
 /// <summary>
 /// Calcule la trajectoire de ce Virus.
 /// </summary>
 void ComputePath()
 {
     if (m_currentAgro != null)
     {
         m_path = new Trajectory(PathFinder.Astar(this.Position, m_currentAgro.Position));
         if (m_path.TrajectoryUnits.Count <= 0)
         {
             string ah = "5";
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Mets à jour l'aggro de la tour.
        /// </summary>
        void UpdateAggro(GameTime time)
        {
            EntityCollection entitiesInRange = GameServer.GetMap().Entities.GetAliveEntitiesInRange(this.Position, AttackRange);
            EntityBase       oldAggro        = m_currentAgro;

            if (m_currentAgro != null && (m_currentAgro.IsDead || !IsInVisionRange(m_currentAgro)))
            {
                m_currentAgro = null;
                m_path        = new Trajectory(PathFinder.Astar(this.Position, this.GuardPosition))
                {
                    Offset = new Vector2(0, 0)
                };
            }

            // Si pas d'aggro : on cherche le premier héros en range qui l'a attaqué.
            EntityBase aggressiveHero = GetRecentlyAgressiveEntities(0.2f).GetEntitiesByType(EntityType.Player).NearestFrom(this.Position);

            if (aggressiveHero != null)
            {
                m_currentAgro        = aggressiveHero;
                m_currentAggroOldPos = m_currentAgro.Position;
            }


            // Si l'aggro bouge, on recalcule l'A*.
            if (m_currentAgro != null && Vector2.DistanceSquared(m_currentAgro.Position, m_currentAggroOldPos) > 1 &&
                (m_path == null || m_stoppedAtAttackRange || IsAt(m_path.LastPosition())))
            {
                m_currentAggroOldPos = m_currentAgro.Position;
                ComputePath();
                return;
            }

            // Si on s'éloigne trop de la position de garde, on lâche l'aggro, et on revient.
            if (m_currentAgro != null && Vector2.DistanceSquared(GuardPosition, Position) >= MaxMoveDistance * MaxMoveDistance)
            {
                m_currentAgro = null;
                m_path        = new Trajectory(PathFinder.Astar(this.Position, this.GuardPosition))
                {
                    Offset = new Vector2(0, 0)
                };
                return;
            }

            // Si on change d'aggro, on recalcule le chemin.
            if (m_currentAgro != oldAggro)
            {
                ComputePath();
            }
        }