Skip to content

Commit

Permalink
Fixed waypoints for CSV based maps
Browse files Browse the repository at this point in the history
  • Loading branch information
leiizko committed May 4, 2019
1 parent 1105729 commit cbb2d87
Showing 1 changed file with 72 additions and 5 deletions.
77 changes: 72 additions & 5 deletions LuaScripts/Rotu-R/waypoints.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ float(number){

loadWaypoints()
{
fileName = "waypoints/"+ toLower(getDvar("mapname")) + "_wp.csv";
fileNameLua = getDvar( "fs_game" ) + "/" + fileName;

if( isDefined( level.waypoints ) && level.waypoints.size > 0 ){ // In case the map has loaded its own waypoints already
if( !FS_TestFile( fileName ) )
dumpWp( fileName );
loadWaypoints_Internal( fileNameLua );
return;
}

level.waypoints = [];
level.waypointCount = 0;
level.waypointLoops = 0;

fileName = "waypoints/"+ toLower(getDvar("mapname")) + "_wp.csv";
/# printLn( "Getting waypoints from csv: "+fileName ); #/

level.waypointCount = int( tableLookup(fileName, 0, 0, 1) );
Expand All @@ -61,7 +66,12 @@ loadWaypoints()
for( j=0; j<tokens.size; j++ )
waypoint.children[j] = int(tokens[j]);
}
//thread draw_wp();

wait .05;

if( !FS_TestFile( fileName ) )
dumpWp( fileName );
loadWaypoints_Internal( fileNameLua );
}

draw_wp()
Expand All @@ -77,7 +87,7 @@ draw_wp()
}
}

getNearestWp( origin )
getNearestWp2( origin )
{
nearestWp = -1;
nearestDistance = 9999999999;
Expand All @@ -97,7 +107,7 @@ getNearestWp( origin )

// ASTAR PATHFINDING ALGORITHM: CREDITS GO TO PEZBOTS!

AStarSearch( startWp, goalWp )
AStarSearch2( startWp, goalWp )
{
pQOpen = [];
pQSize = 0;
Expand Down Expand Up @@ -305,3 +315,60 @@ drawWP()
}
}

dumpWp( path )
{
dump = [];

for( i = 0; i < level.waypoints.size; i++ )
{
if( !isDefined( level.waypoints[ i ].children ) )
level.waypoints[ i ].children = i;

dump[ i ] = "" + ( i + 1 ) + "," + dumpvec3( level.waypoints[ i ].origin ) + "," + dumpchildren( level.waypoints[ i ].children );

if( i % 1000 == 0 )
ResetTimeout();
}

writeToFile( path, dump );
}

dumpvec3( v )
{
string = "" + v[ 0 ] + " " + v[ 1 ] + " " + v[ 2 ];
return string;
}

dumpchildren( c )
{
string = "";
for( i = 0; i < c.size; i++ )
{
string += c[ i ] + " ";
}

return string;
}

writeArray( handle, array )
{
for( i = 0; i < array.size; i++ )
FS_WriteLine( handle, array[ i ] );
}

writeToFile( path, w )
{
file = FS_FOpen( path, "write" );

if( !isDefined( file ) )
return false;

if( isArray( w ) )
writeArray( file, w );
else
FS_WriteLine( file, w );

FS_FClose( file );

return true;
}

0 comments on commit cbb2d87

Please sign in to comment.