1
0
mirror of https://github.com/ineedbots/iw5_bot_warfare.git synced 2025-06-28 07:01:50 +00:00

Big cleanup

This commit is contained in:
ineed bots
2023-11-28 20:23:55 -06:00
parent b5cfd27fa0
commit 8ecaf48ba9
8 changed files with 245 additions and 116 deletions

View File

@ -23,6 +23,9 @@ init()
if ( !getDvarInt( "bots_main" ) )
return;
if ( !wait_for_builtins() )
PrintLn( "FATAL: NO BUILT-INS FOR BOTS" );
thread load_waypoints();
thread hook_callbacks();
@ -202,8 +205,6 @@ init()
level thread auditModels();
level thread handleBots();
//level thread maps\mp\bots\_bot_http::doVersionCheck();
}
/*
@ -764,11 +765,11 @@ watchBotDebugEvent()
if ( isDefined( g ) && isString( g ) )
big_str += ", " + g;
PrintLn( big_str );
BotBuiltinPrintConsole( big_str );
}
else if ( msg == "debug" && GetDvarInt( "bots_main_debug" ) )
{
PrintLn( "Bot Warfare debug: " + self.name + ": " + str );
BotBuiltinPrintConsole( "Bot Warfare debug: " + self.name + ": " + str );
}
}
}

View File

@ -143,7 +143,7 @@ resetBotVars()
self.bot.rand = randomInt( 100 );
self botStop();
self BotBuiltinBotStop();
}
/*
@ -373,7 +373,7 @@ watchUsingTurret()
{
if ( self getCurrentWeapon() != "killstreak_remote_turret_remote_mp" )
{
self changeToWeap( "killstreak_remote_turret_remote_mp" );
self switchToWeapon( "killstreak_remote_turret_remote_mp" );
}
if ( isDefined( self.bot.target ) )
@ -423,7 +423,7 @@ watchUsingTank()
{
if ( self getCurrentWeapon() != "killstreak_remote_tank_remote_mp" )
{
self changeToWeap( "killstreak_remote_tank_remote_mp" );
self switchToWeapon( "killstreak_remote_tank_remote_mp" );
}
if ( isDefined( self.bot.target ) )
@ -462,7 +462,7 @@ watchUsingUav()
{
if ( self getCurrentWeapon() != "uav_remote_mp" )
{
self changeToWeap( "uav_remote_mp" );
self switchToWeapon( "uav_remote_mp" );
}
if ( isDefined( self.lockedTarget ) )
@ -483,7 +483,7 @@ watchUsingMortar()
{
if ( self getCurrentWeapon() != "mortar_remote_mp" )
{
self changeToWeap( "mortar_remote_mp" );
self switchToWeapon( "mortar_remote_mp" );
}
if ( isDefined( self.bot.target ) )
@ -504,7 +504,7 @@ watchUsingMinigun()
{
if ( self getCurrentWeapon() != "heli_remote_mp" )
{
self changeToWeap( "heli_remote_mp" );
self switchToWeapon( "heli_remote_mp" );
}
if ( isDefined( self.bot.target ) )
@ -528,7 +528,7 @@ watchAc130Weapon()
curWeap = self GetCurrentWeapon();
if ( curWeap != "ac130_105mm_mp" && curWeap != "ac130_40mm_mp" && curWeap != "ac130_25mm_mp" )
self changeToWeap( "ac130_105mm_mp" );
self switchToWeapon( "ac130_105mm_mp" );
if ( isDefined( self.bot.target ) )
self thread pressFire();
@ -546,11 +546,11 @@ watchUsingAc130()
while ( isDefined( level.ac130Player ) && level.ac130player == self )
{
self changeToWeap( "ac130_105mm_mp" );
self switchToWeapon( "ac130_105mm_mp" );
wait 1 + randomInt( 2 );
self changeToWeap( "ac130_40mm_mp" );
self switchToWeapon( "ac130_40mm_mp" );
wait 2 + randomInt( 2 );
self changeToWeap( "ac130_25mm_mp" );
self switchToWeapon( "ac130_25mm_mp" );
wait 3 + randomInt( 2 );
}
}
@ -757,7 +757,7 @@ doBotMovement_loop( data )
if ( self.bot.wantsprint && self.bot.issprinting )
dir = ( 127, dir[1], 0 );
self botMovement( int( dir[0] ), int( dir[1] ) );
self BotBuiltinBotMovement( int( dir[0] ), int( dir[1] ) );
if ( isDefined( self.remoteUAV ) )
{
@ -2439,9 +2439,9 @@ getRandomLargestStafe( dist )
holdbreath( what )
{
if ( what )
self botAction( "+holdbreath" );
self BotBuiltinBotAction( "+holdbreath" );
else
self botAction( "-holdbreath" );
self BotBuiltinBotAction( "-holdbreath" );
}
/*
@ -2454,9 +2454,9 @@ sprint()
self notify( "bot_sprint" );
self endon( "bot_sprint" );
self botAction( "+sprint" );
self BotBuiltinBotAction( "+sprint" );
wait 0.05;
self botAction( "-sprint" );
self BotBuiltinBotAction( "-sprint" );
}
/*
@ -2469,9 +2469,9 @@ gostand()
self notify( "bot_gostand" );
self endon( "bot_gostand" );
self botAction( "+gostand" );
self BotBuiltinBotAction( "+gostand" );
wait 0.05;
self botAction( "-gostand" );
self BotBuiltinBotAction( "-gostand" );
}
/*
@ -2484,9 +2484,9 @@ pressfrag()
self notify( "bot_frag" );
self endon( "bot_frag" );
self botAction( "+frag" );
self BotBuiltinBotAction( "+frag" );
wait 0.05;
self botAction( "-frag" );
self BotBuiltinBotAction( "-frag" );
}
/*
@ -2502,9 +2502,9 @@ knife()
self.bot.isknifing = true;
self.bot.isknifingafter = true;
self botAction( "+melee" );
self BotBuiltinBotAction( "+melee" );
wait 0.05;
self botAction( "-melee" );
self BotBuiltinBotAction( "-melee" );
self.bot.isknifing = false;
@ -2523,9 +2523,9 @@ reload()
self notify( "bot_reload" );
self endon( "bot_reload" );
self botAction( "+reload" );
self BotBuiltinBotAction( "+reload" );
wait 0.05;
self botAction( "-reload" );
self BotBuiltinBotAction( "-reload" );
}
/*
@ -2541,14 +2541,14 @@ frag( time )
if ( !isDefined( time ) )
time = 0.05;
self botAction( "+frag" );
self BotBuiltinBotAction( "+frag" );
self.bot.isfragging = true;
self.bot.isfraggingafter = true;
if ( time )
wait time;
self botAction( "-frag" );
self BotBuiltinBotAction( "-frag" );
self.bot.isfragging = false;
wait 1.25;
@ -2568,14 +2568,14 @@ smoke( time )
if ( !isDefined( time ) )
time = 0.05;
self botAction( "+smoke" );
self BotBuiltinBotAction( "+smoke" );
self.bot.issmoking = true;
self.bot.issmokingafter = true;
if ( time )
wait time;
self botAction( "-smoke" );
self BotBuiltinBotAction( "-smoke" );
self.bot.issmoking = false;
wait 1.25;
@ -2590,9 +2590,9 @@ fire( what )
self notify( "bot_fire" );
if ( what )
self botAction( "+fire" );
self BotBuiltinBotAction( "+fire" );
else
self botAction( "-fire" );
self BotBuiltinBotAction( "-fire" );
}
/*
@ -2608,12 +2608,12 @@ pressFire( time )
if ( !isDefined( time ) )
time = 0.05;
self botAction( "+fire" );
self BotBuiltinBotAction( "+fire" );
if ( time )
wait time;
self botAction( "-fire" );
self BotBuiltinBotAction( "-fire" );
}
/*
@ -2624,9 +2624,9 @@ ads( what )
self notify( "bot_ads" );
if ( what )
self botAction( "+ads" );
self BotBuiltinBotAction( "+ads" );
else
self botAction( "-ads" );
self BotBuiltinBotAction( "-ads" );
}
/*
@ -2642,12 +2642,12 @@ pressADS( time )
if ( !isDefined( time ) )
time = 0.05;
self botAction( "+ads" );
self BotBuiltinBotAction( "+ads" );
if ( time )
wait time;
self botAction( "-ads" );
self BotBuiltinBotAction( "-ads" );
}
/*
@ -2663,12 +2663,12 @@ use( time )
if ( !isDefined( time ) )
time = 0.05;
self botAction( "+activate" );
self BotBuiltinBotAction( "+activate" );
if ( time )
wait time;
self botAction( "-activate" );
self BotBuiltinBotAction( "-activate" );
}
/*
@ -2690,9 +2690,9 @@ jump()
wait 1;
}
self botAction( "+gostand" );
self BotBuiltinBotAction( "+gostand" );
wait 0.05;
self botAction( "-gostand" );
self BotBuiltinBotAction( "-gostand" );
}
/*
@ -2703,8 +2703,8 @@ stand()
if ( self IsUsingRemote() )
return;
self botAction( "-gocrouch" );
self botAction( "-goprone" );
self BotBuiltinBotAction( "-gocrouch" );
self BotBuiltinBotAction( "-goprone" );
}
/*
@ -2715,8 +2715,8 @@ crouch()
if ( self IsUsingRemote() )
return;
self botAction( "+gocrouch" );
self botAction( "-goprone" );
self BotBuiltinBotAction( "+gocrouch" );
self BotBuiltinBotAction( "-goprone" );
}
/*
@ -2727,16 +2727,8 @@ prone()
if ( self IsUsingRemote() || self.hasRiotShieldEquipped )
return;
self botAction( "-gocrouch" );
self botAction( "+goprone" );
}
/*
Changes to the weap
*/
changeToWeap( weap )
{
self botWeapon( weap );
self BotBuiltinBotAction( "-gocrouch" );
self BotBuiltinBotAction( "+goprone" );
}
/*
@ -2860,11 +2852,3 @@ bot_lookat( pos, time, vel, doAimPredict )
wait 0.05;
}
}
/*
Bot change weap
*/
botWeapon( weap )
{
self switchToWeapon( weap );
}

View File

@ -2003,7 +2003,7 @@ changeToWeapon( weap )
if ( !self HasWeapon( weap ) )
return false;
self BotChangeToWeapon( weap );
self switchToWeapon( weap );
if ( self GetCurrentWeapon() == weap )
return true;

View File

@ -9,6 +9,109 @@
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
/*
Waits for the built-ins to be defined
*/
wait_for_builtins()
{
for ( i = 0; i < 20; i++ )
{
if ( isDefined( level.bot_builtins ) )
return true;
if ( i < 18 )
waittillframeend;
else
wait 0.05;
}
return false;
}
/*
Prints to console without dev script on
*/
BotBuiltinPrintConsole( s )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["printconsole"] ) )
{
[[ level.bot_builtins["printconsole" ]]]( s );
}
}
/*
Writes to the file, mode can be "append" or "write"
*/
BotBuiltinFileWrite( file, contents, mode )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["filewrite"] ) )
{
[[ level.bot_builtins["filewrite" ]]]( file, contents, mode );
}
}
/*
Returns the whole file as a string
*/
BotBuiltinFileRead( file )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fileread"] ) )
{
return [[ level.bot_builtins["fileread" ]]]( file );
}
return undefined;
}
/*
Test if a file exists
*/
BotBuiltinFileExists( file )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fileexists"] ) )
{
return [[ level.bot_builtins["fileexists" ]]]( file );
}
return false;
}
/*
Bot action, does a bot action
<client> botAction(<action string (+ or - then action like frag or smoke)>)
*/
BotBuiltinBotAction( action )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["botaction"] ) )
{
self [[ level.bot_builtins["botaction" ]]]( action );
}
}
/*
Clears the bot from movement and actions
<client> botStop()
*/
BotBuiltinBotStop()
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["botstop"] ) )
{
self [[ level.bot_builtins["botstop" ]]]();
}
}
/*
Sets the bot's movement
<client> botMovement(<int left>, <int forward>)
*/
BotBuiltinBotMovement( left, forward )
{
if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["botmovement"] ) )
{
self [[ level.bot_builtins["botmovement" ]]]( left, forward );
}
}
/*
Returns if player is the host
*/
@ -31,7 +134,7 @@ doHostCheck()
if ( getDvar( "bots_main_firstIsHost" ) != "0" )
{
printLn( "WARNING: bots_main_firstIsHost is enabled" );
BotBuiltinPrintConsole( "WARNING: bots_main_firstIsHost is enabled" );
if ( getDvar( "bots_main_firstIsHost" ) == "1" )
{
@ -93,14 +196,6 @@ BotSetStance( stance )
}
}
/*
Bot changes to the weap
*/
BotChangeToWeapon( weap )
{
self maps\mp\bots\_bot_internal::changeToWeap( weap );
}
/*
Bot presses the frag button for time.
*/
@ -855,20 +950,21 @@ parseTokensIntoWaypoint( tokens )
*/
getWaypointLinesFromFile( filename )
{
/* result = spawnStruct();
result.lines = [];
result = spawnStruct();
result.lines = [];
waypointStr = fileRead(filename);
waypointStr = BotBuiltinFileRead( filename );
if (!isDefined(waypointStr))
if ( !isDefined( waypointStr ) )
return result;
line = "";
for (i=0;i<waypointStr.size;i++)
{
line = "";
for ( i = 0; i < waypointStr.size; i++ )
{
c = waypointStr[i];
if (c == "\n")
if ( c == "\n" )
{
result.lines[result.lines.size] = line;
@ -877,10 +973,11 @@ getWaypointLinesFromFile( filename )
}
line += c;
}
result.lines[result.lines.size] = line;
}
return result;*/
result.lines[result.lines.size] = line;
return result;
}
/*
@ -888,31 +985,31 @@ getWaypointLinesFromFile( filename )
*/
readWpsFromFile( mapname )
{
/* waypoints = [];
filename = "waypoints/" + mapname + "_wp.csv";
waypoints = [];
filename = "waypoints/" + mapname + "_wp.csv";
if (!fileExists(filename))
if ( !BotBuiltinFileExists( filename ) )
return waypoints;
res = getWaypointLinesFromFile(filename);
res = getWaypointLinesFromFile( filename );
if (!res.lines.size)
if ( !res.lines.size )
return waypoints;
printLn("Attempting to read waypoints from " + filename);
BotBuiltinPrintConsole( "Attempting to read waypoints from " + filename );
waypointCount = int(res.lines[0]);
waypointCount = int( res.lines[0] );
for (i = 1; i <= waypointCount; i++)
{
tokens = tokenizeLine(res.lines[i], ",");
for ( i = 1; i <= waypointCount; i++ )
{
tokens = tokenizeLine( res.lines[i], "," );
waypoint = parseTokensIntoWaypoint(tokens);
waypoint = parseTokensIntoWaypoint( tokens );
waypoints[i-1] = waypoint;
}
waypoints[i - 1] = waypoint;
}
return waypoints;*/
return waypoints;
return [];
}
@ -937,7 +1034,7 @@ load_waypoints()
if ( wps.size )
{
level.waypoints = wps;
printLn( "Loaded " + wps.size + " waypoints from csv." );
BotBuiltinPrintConsole( "Loaded " + wps.size + " waypoints from csv." );
}
else
{
@ -949,12 +1046,12 @@ load_waypoints()
}
if ( level.waypoints.size )
printLn( "Loaded " + level.waypoints.size + " waypoints from script." );
BotBuiltinPrintConsole( "Loaded " + level.waypoints.size + " waypoints from script." );
}
if ( !level.waypoints.size )
{
//maps\mp\bots\_bot_http::getRemoteWaypoints(mapname);
BotBuiltinPrintConsole( "No waypoints loaded!" );
}
level.waypointCount = level.waypoints.size;

View File

@ -543,7 +543,8 @@ watchSaveWaypointsCommand()
PrintLn( "********* Start Bot Warfare WPDump *********" );
PrintLn( level.waypointCount );
//fileWrite(filename, level.waypointCount+"\n", "write");
BotBuiltinFileWrite( filename, level.waypointCount + "\n", "write" );
for ( i = 0; i < level.waypointCount; i++ )
{
str = "";
@ -572,7 +573,7 @@ watchSaveWaypointsCommand()
str += ",";
PrintLn( str );
//fileWrite(filename, str+"\n", "append");
BotBuiltinFileWrite( filename, str + "\n", "append" );
}
PrintLn( "\n\n\n\n\n\n" );