Exemplo n.º 1
0
    public static bool Search(GraphNode source, GraphNode destination, ref List <GraphNode> path, int maxSteps)
    {
        bool found = false;

        SimplePriorityQueue <GraphNode> nodes = new SimplePriorityQueue <GraphNode>();

        source.Cost = 0;
        nodes.Enqueue(source, source.Cost);

        int steps = 0;

        while (!found && nodes.Count > 0 && steps++ < maxSteps)
        {
            // <dequeue node>
            GraphNode node = nodes.Dequeue();
            if (node == destination)
            {
                // <set found to true>
                found = true;
                // continue, do not execute the rest of this loop
                continue;
            }
            // search node edges for unvisited node
            foreach (GraphNode.Edge edge in node.Edges)
            {
                // calculate cost to nodeB = node cost + edge distance (nodeA to nodeB)
                float cost = node.Cost + Vector3.Distance(edge.nodeA.transform.position, edge.nodeB.transform.position);
                // if cost < nodeB cost, add to priority queue
                if (cost < edge.nodeB.Cost)
                {
                    // <set nodeB cost to cost>
                    edge.nodeB.Cost = cost;
                    // <set nodeB parent to node>
                    edge.nodeB.Parent = node;
                    // <enqueue without duplicates nodeB with cost as priority>
                    nodes.Enqueue(edge.nodeB, edge.nodeB.Cost);
                }
            }
        }

        // create a list of graph nodes (path)
        path = new List <GraphNode>();
        // if found is true
        if (found)
        {
            GraphNode node = destination;
            // while node not null
            while (node != null)
            {
                path.Add(node);
                node = node.Parent;
            }
            path.Reverse();
        }
        else
        {
            path = nodes.ToList();
        }
        return(found);
    }
Exemplo n.º 2
0
        /// <summary>
        /// Begin strafe run.
        /// </summary>
        public void spawnStrafeRun(Vector3 targetPos)
        {
            // do nothing if a strafe run is already active
            if (_isActive)
            {
                return;
            }

            // sanity check the target position
            if (targetPos == Vector3.Zero)
            {
                return;
            }
            else
            {
                _targetPos = targetPos;
            }

            // acquire initial targets
            SimplePriorityQueue <Ped> targetQ = buildTargetPriorityQueue(_targetPos, _searchRadius, true);

            initialTargetList = targetQ.ToList();

            // spawn a strafing vehicle formation
            int numVehicles = (targetQ.Count + 2) / vehiclesPerInitialTarget;

            strafeVehiclesList = spawnStrafeVehiclesInFormation(targetPos, initialTargetList, numVehicles);
            taskAllPilotsEngage(targetQ, true);                         // if no targets, fire at targetPos

            // mark the target position with flare ptfx
            targetMarkerPtfx = World.CreateParticleEffect(targetMarkerPtfxAsset, "exp_grd_flare", targetPos);

            // coordinate JDAM drops/explosions
            _jdamDrops = (new StrafeRunJdam[strafeVehiclesList.Count * _jdamsPerVehicle])
                         .Select(x => new StrafeRunJdam(_targetPos, _searchRadius)).ToArray();

            // render from cinematic cam if requested
            if (_cinematic)
            {
                cineCamCtrler.initializeCinematicCamSequence(
                    new StrafeRunPropertiesSummary(strafeVehiclesList, initialTargetList, _targetPos));
            }

            // if all has succeeded, flag it as such
            _isActive  = true;
            _spawnTime = Game.GameTime;
        }
Exemplo n.º 3
0
    public static bool Search(GraphNode source, GraphNode destination, ref List <GraphNode> path, int maxSteps)
    {
        bool found = false;
        //A* algorithm
        SimplePriorityQueue <GraphNode> nodes = new SimplePriorityQueue <GraphNode>();

        source.Cost      = 0;
        source.Heuristic = Vector3.Distance(source.transform.position, destination.transform.position);
        nodes.Enqueue(source, (source.Cost + source.Heuristic));

        // set the current number of steps
        int steps = 0;

        while (!found && nodes.Count > 0 && steps++ < maxSteps)
        {
            // <dequeue node>
            GraphNode node = nodes.Dequeue();
            if (node == destination)            //(< check if node is the destination node >)
            {
                // <set found to true>
                found = true;
                // <continue, do not execute the rest of this loop>
                continue;
            }

            foreach (GraphNode.Edge edge in node.Edges)
            {
                // calculate cost to nodeB = node cost + edge distance (nodeA to nodeB)
                float cost = node.Cost + Vector3.Distance(edge.nodeA.transform.position, edge.nodeB.transform.position); //< Vector3.Distance nodeA <->nodeB >;
                // if cost < nodeB cost, add to priority queue
                if (cost < edge.nodeB.Cost)                                                                              //(< cost is less than nodeB.cost >))
                {
                    // <set nodeB cost to cost>
                    edge.nodeB.Cost = cost;
                    // <set nodeB parent to node>
                    edge.nodeB.Parent = node;
                    // calculate heuristic = Vector3.Distance (nodeB <-> destination)
                    edge.nodeB.Heuristic = Vector3.Distance(edge.nodeB.transform.position, destination.transform.position);                    //< Vector3.Distance(nodeB <->destination) >

                    // <enqueue without duplicates nodeB with nodeB cost + nodeB heuristics as priority>
                    nodes.EnqueueWithoutDuplicates(edge.nodeB, (edge.nodeB.Cost + edge.nodeB.Heuristic));
                }
            }
        }

        // create a list of graph nodes (path)
        path = new List <GraphNode>();

        // if found is true
        if (found)
        {
            GraphNode node = destination;            //< set node to destination >
            // while node not null
            while (node != null)
            {
                // <add node to path list>
                path.Add(node);
                // <set node to node.Parent>
                node = node.Parent;
            }
            // reverse path
            path.Reverse();
        }
        else
        {
            // add all nodes to path
            path = nodes.ToList();
            while (nodes.Count > 0)
            {
                // <add (dequeued node) to path>
                GraphNode node = nodes.Dequeue();
                path.Add(node);
            }
        }

        return(found);
    }
Exemplo n.º 4
0
 public List <Event> ToList()
 {
     return(queue.ToList());
 }