mirror of
https://github.com/ineedbots/iw3_bot_warfare.git
synced 2025-04-20 09:45:43 +00:00
Add perline reading/writing fileio again
This commit is contained in:
parent
dc58bf328a
commit
386e87d063
@ -1465,34 +1465,6 @@ FrontLinesWaypoints()
|
||||
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
|
||||
*/
|
||||
@ -1541,26 +1513,16 @@ getABotName()
|
||||
|
||||
if ( BotBuiltinFileExists( filename ) )
|
||||
{
|
||||
names_str = BotBuiltinFileRead( filename );
|
||||
f = BotBuiltinFileOpen( filename, "read" );
|
||||
|
||||
if ( isDefined( names_str ) )
|
||||
if ( f > 0 )
|
||||
{
|
||||
line = "";
|
||||
|
||||
for ( i = 0; i < names_str.size; i++ )
|
||||
for ( line = BotBuiltinReadLine( f ); isDefined( line ); line = BotBuiltinReadLine( f ) )
|
||||
{
|
||||
c = names_str[i];
|
||||
|
||||
if ( c == "\n" )
|
||||
{
|
||||
level.bot_names[level.bot_names.size] = line;
|
||||
|
||||
line = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
line += c;
|
||||
level.bot_names[level.bot_names.size] = line;
|
||||
}
|
||||
|
||||
BotBuiltinFileClose( f );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1575,41 +1537,6 @@ getABotName()
|
||||
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
|
||||
*/
|
||||
@ -1621,24 +1548,36 @@ readWpsFromFile( mapname )
|
||||
if ( !BotBuiltinFileExists( filename ) )
|
||||
return waypoints;
|
||||
|
||||
res = getWaypointLinesFromFile( filename );
|
||||
f = BotBuiltinFileOpen( filename, "read" );
|
||||
|
||||
if ( !res.lines.size )
|
||||
if ( f < 1 )
|
||||
return waypoints;
|
||||
|
||||
BotBuiltinPrintConsole( "Attempting to read waypoints from " + filename );
|
||||
|
||||
waypointCount = int( res.lines[0] );
|
||||
line = BotBuiltinReadLine( f );
|
||||
|
||||
for ( i = 1; i <= waypointCount; i++ )
|
||||
if ( isDefined( line ) )
|
||||
{
|
||||
tokens = tokenizeLine( res.lines[i], "," );
|
||||
waypointCount = int( line );
|
||||
|
||||
waypoint = parseTokensIntoWaypoint( tokens );
|
||||
for ( i = 1; i <= waypointCount; i++ )
|
||||
{
|
||||
line = BotBuiltinReadLine( f );
|
||||
|
||||
waypoints[i - 1] = waypoint;
|
||||
if ( !isDefined( line ) )
|
||||
break;
|
||||
|
||||
tokens = strtok( line, "," );
|
||||
|
||||
waypoint = parseTokensIntoWaypoint( tokens );
|
||||
|
||||
waypoints[i - 1] = waypoint;
|
||||
}
|
||||
}
|
||||
|
||||
BotBuiltinFileClose( f );
|
||||
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,10 @@ watchSaveWaypointsCommand()
|
||||
PrintLn( "********* Start Bot Warfare WPDump *********" );
|
||||
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++ )
|
||||
{
|
||||
@ -342,9 +345,14 @@ watchSaveWaypointsCommand()
|
||||
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" );
|
||||
|
||||
self iprintln( "Saved!!! to " + filename );
|
||||
|
@ -90,10 +90,9 @@ do_fs_fopen( file, mode )
|
||||
return FS_FOpen( file, mode );
|
||||
}
|
||||
|
||||
do_fs_fclose( file )
|
||||
do_fs_fclose( fh )
|
||||
{
|
||||
file = "scriptdata/" + file;
|
||||
FS_FClose( file );
|
||||
FS_FClose( fh );
|
||||
}
|
||||
|
||||
do_fs_readline( fh )
|
||||
|
Loading…
x
Reference in New Issue
Block a user