Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-05-2007, 06:22 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Pathfinder

Edges are of equal value.

PHP Code:
/**
  * Finds the path from one object to another through the nodes variable.
  *
  * Node is an object which has nodes variable containing a list of connected node.
  * Nodes are single directions. In order to make it two-directions, you have to define
  *   them separately.
**/

function findPathstartNodeendNode )
{
  
temp.nodeList.add( {startNode, new[0]} );
  
temp.nodeIndex 0;
  while ( 
temp.nodeList.size() > temp.nodeIndex )
  {
    
temp.node temp.nodeListtemp.nodeIndex ][0];
    
temp.nodePath temp.nodeListtemp.nodeIndex ][1];
    
temp.nodePath.addtemp.node );
    if ( 
temp.node == endNode )
      return 
temp.nodePath;

    for ( 
temp.subnodenode.nodes )
    {
      if ( 
temp.subnode in temp.nodeList )
        continue;

      
temp.nodeList.add( { temp.subnodetemp.nodePath } );
    }
    
temp.nodeIndex ++;
  }

  return 
null;

Example of Usage:
PHP Code:
function onCreated()
{
  
node1 = new TStaticVar("Node-1");
  
node2 = new TStaticVar("Node-2");
  
node3 = new TStaticVar("Node-3");
  
node4 = new TStaticVar("Node-4");

  
node1.nodes = { node2node3 };
  
node2.nodes = { node1node3 };
  
node3.nodes = { node4 };
  
node4.nodes = { node1 };
  
  
path findPathnode1node4 );
  for ( 
nodepath )
    echo( 
node.name );

Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:07 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.