diff --git a/maps/mp/bots/_bot_utility.gsc b/maps/mp/bots/_bot_utility.gsc index 8f11a1d..b484f97 100644 --- a/maps/mp/bots/_bot_utility.gsc +++ b/maps/mp/bots/_bot_utility.gsc @@ -87,6 +87,45 @@ BotBuiltinFileExists( file ) return false; } +/* + Opens a file stream for reading. +*/ +BotBuiltinOpenFile( file, mode ) +{ + if ( isdefined( level.bot_builtins ) && isdefined( level.bot_builtins[ "openfile" ] ) ) + { + return [[ level.bot_builtins[ "openfile" ] ]]( file, mode ); + } + + return -1; +} + +/* + Reads the next line from the currently open file stream. +*/ +BotBuiltinReadStream() +{ + if ( isdefined( level.bot_builtins ) && isdefined( level.bot_builtins[ "readstream" ] ) ) + { + return [[ level.bot_builtins[ "readstream" ] ]](); + } + + return undefined; +} + +/* + Closes the currently open file stream. +*/ +BotBuiltinCloseFile() +{ + if ( isdefined( level.bot_builtins ) && isdefined( level.bot_builtins[ "closefile" ] ) ) + { + return [[ level.bot_builtins[ "closefile" ] ]](); + } + + return -1; +} + /* Bot action, does a bot action botaction() @@ -1285,27 +1324,39 @@ readWpsFromFile( mapname ) { return waypoints; } + + openResult = BotBuiltinOpenFile( filename, "read" ); - res = getWaypointLinesFromFile( filename ); - - if ( !res.lines.size ) + if ( openResult <= 0 ) { return waypoints; } - BotBuiltinPrintConsole( "Attempting to read waypoints from " + filename ); + firstLine = BotBuiltinReadStream(); - waypointCount = int( res.lines[ 0 ] ); + if ( !isdefined( firstLine ) ) + { + BotBuiltinCloseFile(); + return waypoints; + } + + waypointCount = int( firstLine ); for ( i = 1; i <= waypointCount; i++ ) { - tokens = strtok( res.lines[ i ], "," ); + line = BotBuiltinReadStream(); + if ( !isdefined( line ) ) + { + break; + } + + tokens = strtok( line, "," ); waypoint = parseTokensIntoWaypoint( tokens ); - waypoints[ i - 1 ] = waypoint; } + BotBuiltinCloseFile(); return waypoints; } diff --git a/scripts/mp/bots_adapter_codxe.gsc b/scripts/mp/bots_adapter_codxe.gsc index d188b39..8b78145 100644 --- a/scripts/mp/bots_adapter_codxe.gsc +++ b/scripts/mp/bots_adapter_codxe.gsc @@ -4,6 +4,9 @@ init() level.bot_builtins[ "filewrite" ] = ::do_filewrite; level.bot_builtins[ "fileread" ] = ::do_fileread; level.bot_builtins[ "fileexists" ] = ::do_fileexists; + level.bot_builtins[ "openfile" ] = ::do_openfile; + level.bot_builtins[ "readstream" ] = ::do_readstream; + level.bot_builtins[ "closefile" ] = ::do_closefile; level.bot_builtins[ "botaction" ] = ::do_botaction; level.bot_builtins[ "botstop" ] = ::do_botstop; level.bot_builtins[ "botmovement" ] = ::do_botmovement; @@ -35,6 +38,22 @@ do_fileexists( file ) return fileexists( file ); } +do_openfile( file, mode ) +{ + file = "scriptdata/" + file; + return openfile( file, mode ); +} + +do_readstream() +{ + return readstream(); +} + +do_closefile() +{ + return closefile(); +} + do_botaction( action ) { self botaction( action );