mirror of
https://github.com/ineedbots/iw3_bot_warfare.git
synced 2025-04-20 01:42:53 +00:00
Add perline reading/writing fileio again
This commit is contained in:
parent
dc58bf328a
commit
386e87d063
@ -1465,34 +1465,6 @@ FrontLinesWaypoints()
|
|||||||
return waypoints;
|
return waypoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Tokenizes a string (strtok has limits...) (only one char tok)
|
|
||||||
*/
|
|
||||||
tokenizeLine( line, tok )
|
|
||||||
{
|
|
||||||
tokens = [];
|
|
||||||
|
|
||||||
token = "";
|
|
||||||
|
|
||||||
for ( i = 0; i < line.size; i++ )
|
|
||||||
{
|
|
||||||
c = line[i];
|
|
||||||
|
|
||||||
if ( c == tok )
|
|
||||||
{
|
|
||||||
tokens[tokens.size] = token;
|
|
||||||
token = "";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
token += c;
|
|
||||||
}
|
|
||||||
|
|
||||||
tokens[tokens.size] = token;
|
|
||||||
|
|
||||||
return tokens;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Parses tokens into a waypoint obj
|
Parses tokens into a waypoint obj
|
||||||
*/
|
*/
|
||||||
@ -1541,26 +1513,16 @@ getABotName()
|
|||||||
|
|
||||||
if ( BotBuiltinFileExists( filename ) )
|
if ( BotBuiltinFileExists( filename ) )
|
||||||
{
|
{
|
||||||
names_str = BotBuiltinFileRead( filename );
|
f = BotBuiltinFileOpen( filename, "read" );
|
||||||
|
|
||||||
if ( isDefined( names_str ) )
|
if ( f > 0 )
|
||||||
{
|
{
|
||||||
line = "";
|
for ( line = BotBuiltinReadLine( f ); isDefined( line ); line = BotBuiltinReadLine( f ) )
|
||||||
|
|
||||||
for ( i = 0; i < names_str.size; i++ )
|
|
||||||
{
|
|
||||||
c = names_str[i];
|
|
||||||
|
|
||||||
if ( c == "\n" )
|
|
||||||
{
|
{
|
||||||
level.bot_names[level.bot_names.size] = line;
|
level.bot_names[level.bot_names.size] = line;
|
||||||
|
|
||||||
line = "";
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
line += c;
|
BotBuiltinFileClose( f );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1575,41 +1537,6 @@ getABotName()
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Returns an array of each line
|
|
||||||
*/
|
|
||||||
getWaypointLinesFromFile( filename )
|
|
||||||
{
|
|
||||||
result = spawnStruct();
|
|
||||||
result.lines = [];
|
|
||||||
|
|
||||||
waypointStr = BotBuiltinFileRead( filename );
|
|
||||||
|
|
||||||
if ( !isDefined( waypointStr ) )
|
|
||||||
return result;
|
|
||||||
|
|
||||||
line = "";
|
|
||||||
|
|
||||||
for ( i = 0; i < waypointStr.size; i++ )
|
|
||||||
{
|
|
||||||
c = waypointStr[i];
|
|
||||||
|
|
||||||
if ( c == "\n" )
|
|
||||||
{
|
|
||||||
result.lines[result.lines.size] = line;
|
|
||||||
|
|
||||||
line = "";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
line += c;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.lines[result.lines.size] = line;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Read from file a csv, and returns an array of waypoints
|
Read from file a csv, and returns an array of waypoints
|
||||||
*/
|
*/
|
||||||
@ -1621,23 +1548,35 @@ readWpsFromFile( mapname )
|
|||||||
if ( !BotBuiltinFileExists( filename ) )
|
if ( !BotBuiltinFileExists( filename ) )
|
||||||
return waypoints;
|
return waypoints;
|
||||||
|
|
||||||
res = getWaypointLinesFromFile( filename );
|
f = BotBuiltinFileOpen( filename, "read" );
|
||||||
|
|
||||||
if ( !res.lines.size )
|
if ( f < 1 )
|
||||||
return waypoints;
|
return waypoints;
|
||||||
|
|
||||||
BotBuiltinPrintConsole( "Attempting to read waypoints from " + filename );
|
BotBuiltinPrintConsole( "Attempting to read waypoints from " + filename );
|
||||||
|
|
||||||
waypointCount = int( res.lines[0] );
|
line = BotBuiltinReadLine( f );
|
||||||
|
|
||||||
|
if ( isDefined( line ) )
|
||||||
|
{
|
||||||
|
waypointCount = int( line );
|
||||||
|
|
||||||
for ( i = 1; i <= waypointCount; i++ )
|
for ( i = 1; i <= waypointCount; i++ )
|
||||||
{
|
{
|
||||||
tokens = tokenizeLine( res.lines[i], "," );
|
line = BotBuiltinReadLine( f );
|
||||||
|
|
||||||
|
if ( !isDefined( line ) )
|
||||||
|
break;
|
||||||
|
|
||||||
|
tokens = strtok( line, "," );
|
||||||
|
|
||||||
waypoint = parseTokensIntoWaypoint( tokens );
|
waypoint = parseTokensIntoWaypoint( tokens );
|
||||||
|
|
||||||
waypoints[i - 1] = waypoint;
|
waypoints[i - 1] = waypoint;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BotBuiltinFileClose( f );
|
||||||
|
|
||||||
return waypoints;
|
return waypoints;
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,10 @@ watchSaveWaypointsCommand()
|
|||||||
PrintLn( "********* Start Bot Warfare WPDump *********" );
|
PrintLn( "********* Start Bot Warfare WPDump *********" );
|
||||||
PrintLn( level.waypointCount );
|
PrintLn( level.waypointCount );
|
||||||
|
|
||||||
BotBuiltinFileWrite( filename, level.waypointCount + "\n", "write" );
|
f = BotBuiltinFileOpen( filename, "write" );
|
||||||
|
|
||||||
|
if ( f > 0 )
|
||||||
|
BotBuiltinWriteLine( f, level.waypointCount );
|
||||||
|
|
||||||
for ( i = 0; i < level.waypointCount; i++ )
|
for ( i = 0; i < level.waypointCount; i++ )
|
||||||
{
|
{
|
||||||
@ -342,9 +345,14 @@ watchSaveWaypointsCommand()
|
|||||||
str += ",";
|
str += ",";
|
||||||
|
|
||||||
PrintLn( str );
|
PrintLn( str );
|
||||||
BotBuiltinFileWrite( filename, str + "\n", "append" );
|
|
||||||
|
if ( f > 0 )
|
||||||
|
BotBuiltinWriteLine( f, str );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( f > 0 )
|
||||||
|
BotBuiltinFileClose( f );
|
||||||
|
|
||||||
PrintLn( "\n\n\n\n\n\n" );
|
PrintLn( "\n\n\n\n\n\n" );
|
||||||
|
|
||||||
self iprintln( "Saved!!! to " + filename );
|
self iprintln( "Saved!!! to " + filename );
|
||||||
|
@ -90,10 +90,9 @@ do_fs_fopen( file, mode )
|
|||||||
return FS_FOpen( file, mode );
|
return FS_FOpen( file, mode );
|
||||||
}
|
}
|
||||||
|
|
||||||
do_fs_fclose( file )
|
do_fs_fclose( fh )
|
||||||
{
|
{
|
||||||
file = "scriptdata/" + file;
|
FS_FClose( fh );
|
||||||
FS_FClose( file );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_fs_readline( fh )
|
do_fs_readline( fh )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user