From 977dc41f1806522770774fe65f40a1c07d5a6e6d Mon Sep 17 00:00:00 2001 From: ineed bots Date: Thu, 30 Nov 2023 03:15:34 -0600 Subject: [PATCH] cleanup --- .astylerc | 21 +++ .editorconfig | 11 ++ .gitignore | 1 + .vscode/settings.json | 15 ++ maps/bots/_bot.gsc | 37 ++-- maps/bots/_bot_debug.gsc | 22 +-- maps/bots/_bot_internal.gsc | 77 ++++---- maps/bots/_bot_script.gsc | 10 +- maps/bots/_bot_utility.gsc | 269 +++++++++++++++++++++++---- maps/bots/objectives/_wallweapon.gsc | 4 +- scripts/sp/bots.gsc | 5 - scripts/sp/bots_adapter.gsc | 105 +++++++++++ 12 files changed, 451 insertions(+), 126 deletions(-) create mode 100644 .astylerc create mode 100644 .editorconfig create mode 100644 .vscode/settings.json create mode 100644 scripts/sp/bots_adapter.gsc diff --git a/.astylerc b/.astylerc new file mode 100644 index 0000000..c0e7be1 --- /dev/null +++ b/.astylerc @@ -0,0 +1,21 @@ +# try to mimic the original gsc provided +mode=c +style=allman + +indent=tab +lineend=windows + +pad-oper +pad-paren-in +pad-header + +# delete-empty-lines + +break-blocks +# remove-braces + +indent-switches +indent-cases +indent-after-parens + +remove-comment-prefix diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bb97c78 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = tab +indent_size = 2 +charset = latin1 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index 26179d2..f7ddc4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.log missingasset.csv +console.log* diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2f316e2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "astyle.astylerc": "${workspaceRoot}/.astylerc", + "astyle.additional_languages": [ + "gsc" + ], + "[gsc]": { + "editor.defaultFormatter": "chiehyu.vscode-astyle", + }, + "editor.quickSuggestions": { + "other": true, + "comments": true, + "strings": true + }, + "vscode-codscript.use_builtin_completionItems": false +} diff --git a/maps/bots/_bot.gsc b/maps/bots/_bot.gsc index 4b32719..751b6a8 100644 --- a/maps/bots/_bot.gsc +++ b/maps/bots/_bot.gsc @@ -2,24 +2,6 @@ #include maps\_utility; #include maps\bots\_bot_utility; -/* - main -*/ -main() -{ - // stop the meme - func = GetFunction( "maps/_utility", "wait_network_frame" ); - replaceFunc( func, ::wait_network_frame_func ); -} - -/* - oof -*/ -wait_network_frame_func() -{ - wait 0.05; -} - /* Initiates the whole bot scripts. */ @@ -33,6 +15,9 @@ init() if ( !getDvarInt( "bots_main" ) ) return; + if ( !wait_for_builtins() ) + PrintLn( "FATAL: NO BUILT-INS FOR BOTS" ); + thread load_waypoints(); thread hook_callbacks(); @@ -159,7 +144,7 @@ handleBots() for ( i = 0; i < bots.size; i++ ) { - bots[i] RemoveTestClient(); + BotBuiltinCmdExec( "clientkick " + bots[i] getEntityNumber() ); } } @@ -168,7 +153,7 @@ handleBots() */ onPlayerDamage( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, modelIndex, psOffsetTime ) { - if ( self isBot() && getDvarInt( "bots_t8_mode" ) ) + if ( self is_bot() && getDvarInt( "bots_t8_mode" ) ) { if ( ( level.script == "nazi_zombie_asylum" || level.script == "nazi_zombie_sumpf" ) && self hasPerk( "specialty_armorvest" ) ) { @@ -191,7 +176,7 @@ onPlayerDamage( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, onActorDamage( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, iModelIndex, iTimeOffset ) { - if ( isDefined( eAttacker ) && isPlayer( eAttacker ) && eAttacker isBot() && getDvarInt( "bots_t8_mode" ) && ( !isDefined( self.magic_bullet_shield ) || !self.magic_bullet_shield ) ) + if ( isDefined( eAttacker ) && isPlayer( eAttacker ) && eAttacker is_bot() && getDvarInt( "bots_t8_mode" ) && ( !isDefined( self.magic_bullet_shield ) || !self.magic_bullet_shield ) ) { iDamage += int( self.maxhealth * randomFloatRange( 0.25, 1.25 ) ); } @@ -319,7 +304,7 @@ watchBotDebugEvent() if ( GetDvarInt( "bots_main_debug" ) >= 2 ) { - big_str = "Bot Warfare debug: " + self getPlayerName() + ": " + msg; + big_str = "Bot Warfare debug: " + self.playername + ": " + msg; if ( isDefined( str ) && isString( str ) ) big_str += ", " + str; @@ -342,11 +327,11 @@ watchBotDebugEvent() if ( isDefined( g ) && isString( g ) ) big_str += ", " + g; - PrintConsole( big_str ); + BotBuiltinPrintConsole( big_str ); } else if ( msg == "debug" && GetDvarInt( "bots_main_debug" ) ) { - PrintConsole( "Bot Warfare debug: " + self getPlayerName() + ": " + str ); + BotBuiltinPrintConsole( "Bot Warfare debug: " + self.playername + ": " + str ); } } } @@ -367,7 +352,7 @@ added() */ add_bot() { - bot = addtestclient(); + bot = BotBuiltinAddTestClient(); if ( isdefined( bot ) ) { @@ -501,7 +486,7 @@ addBots_loop() tempBot = PickRandom( getBotArray() ); if ( isDefined( tempBot ) ) - tempBot RemoveTestClient(); + BotBuiltinCmdExec( "clientkick " + tempBot getEntityNumber() ); } } diff --git a/maps/bots/_bot_debug.gsc b/maps/bots/_bot_debug.gsc index 894e9d2..29a0081 100644 --- a/maps/bots/_bot_debug.gsc +++ b/maps/bots/_bot_debug.gsc @@ -80,7 +80,7 @@ watch_for_unlink() self endon( "disconnect" ); self endon( "zombified" ); - self notifyOnPlayerCommand( "+smoke", "toggle_unlink" ); + self BotBuiltinNotifyOnPlayerCommand( "+smoke", "toggle_unlink" ); for ( ;; ) { @@ -94,7 +94,7 @@ watch_for_unlink() firstwp = level.waypoints[self.closest]; - self iprintln( "wp selected for unlink: " + firstwp getNodeNumber() ); + self iprintln( "wp selected for unlink: " + firstwp BotBuiltinGetNodeNumber() ); self waittill( "toggle_unlink" ); @@ -122,15 +122,15 @@ array_contains( arr, it ) toggle_link( firstwp, secondwp ) { // check if it exists - key = firstwp getNodeNumber() + ""; - secnum = secondwp getNodeNumber(); + key = firstwp BotBuiltinGetNodeNumber() + ""; + secnum = secondwp BotBuiltinGetNodeNumber(); - links = firstwp getLinkedNodes(); + links = firstwp BotBuiltinGetLinkedNodes(); linked = false; for ( i = 0; i < links.size; i++ ) { - if ( links[i] getNodeNumber() == secnum ) + if ( links[i] BotBuiltinGetNodeNumber() == secnum ) { linked = true; break; @@ -165,7 +165,7 @@ toggle_link( firstwp, secondwp ) } self iprintln( "removed unlink: " + key + " " + secnum ); - PrintConsole( "toggle_link: add: " + key + " " + secnum ); + BotBuiltinPrintConsole( "toggle_link: add: " + key + " " + secnum ); } else { @@ -180,7 +180,7 @@ toggle_link( firstwp, secondwp ) level.bot_ignore_links[key] = a; self iprintln( "added unlink: " + key + " " + secnum ); - PrintConsole( "toggle_link: del: " + key + " " + secnum ); + BotBuiltinPrintConsole( "toggle_link: del: " + key + " " + secnum ); } } @@ -208,15 +208,15 @@ debug() if ( distance( level.waypoints[i].origin, self.origin ) < getDvarFloat( "bots_main_debug_distance" ) && ( sightTracePassed( myEye, wpOrg, false, self ) || getDVarint( "bots_main_debug_drawThrough" ) ) && getConeDot( wpOrg, myEye, myAngles ) > getDvarFloat( "bots_main_debug_cone" ) ) { - linked = level.waypoints[i] getLinkedNodes(); - node_num_str = level.waypoints[i] getNodeNumber() + ""; + linked = level.waypoints[i] BotBuiltinGetLinkedNodes(); + node_num_str = level.waypoints[i] BotBuiltinGetNodeNumber() + ""; for ( h = linked.size - 1; h >= 0; h-- ) { if ( isDefined( level.bot_ignore_links[node_num_str] ) ) { found = false; - this_node_num = linked[h] getNodeNumber(); + this_node_num = linked[h] BotBuiltinGetNodeNumber(); for ( j = 0; j < level.bot_ignore_links[node_num_str].size; j++ ) { diff --git a/maps/bots/_bot_internal.gsc b/maps/bots/_bot_internal.gsc index c071fc3..9c38784 100644 --- a/maps/bots/_bot_internal.gsc +++ b/maps/bots/_bot_internal.gsc @@ -97,11 +97,10 @@ resetBotVars() self.bot.is_cur_sniper = false; self.bot.prio_objective = false; - self.bot.path_inaccessible = false; self.bot.rand = randomInt( 100 ); - self botStop(); + self BotBuiltinBotStop(); } /* @@ -664,7 +663,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] ) ); } /* @@ -1456,7 +1455,7 @@ walk() { wait 0.05; - self botMoveTo( self.origin ); + self botSetMoveTo( self.origin ); if ( !getDvarInt( "bots_play_move" ) ) continue; @@ -1544,12 +1543,8 @@ doWalk( goal, dist, isScriptGoal ) path_was_truncated = ( current + 1 ) >= 32; - //Couldn't generate path to goal - self.bot.path_inaccessible = false; - if ( current <= -1 ) { - self.bot.path_inaccessible = true; self notify( "bad_path_internal" ); return; } @@ -1629,7 +1624,7 @@ movetowards( goal ) while ( distanceSquared( self.origin, goal ) > tempGoalDist ) { - self botMoveTo( goal ); + self botSetMoveTo( goal ); if ( time > 3000 ) { @@ -1646,7 +1641,7 @@ movetowards( goal ) self BotNotifyBotEvent( "stuck" ); - self botMoveTo( randomDir ); + self botSetMoveTo( randomDir ); wait stucks; self stand(); @@ -1724,7 +1719,7 @@ strafe( target ) self.bot.last_next_wp = -1; self.bot.last_second_next_wp = -1; - self botMoveTo( strafe ); + self botSetMoveTo( strafe ); wait 2; self notify( "kill_goal" ); } @@ -1767,12 +1762,12 @@ getRandomLargestStafe( dist ) */ initAStar( goal ) { - nodes = GenerateThePath( self.origin, goal, self.team ); + nodes = BotBuiltinGeneratePath( self.origin, goal, self.team ); if ( !isDefined( nodes ) || nodes.size <= 0 ) { //Try again to find a path to the origin using best effort algo - nodes = GenerateThePath( self.origin, goal, self.team, 192.0 ); + nodes = BotBuiltinGeneratePath( self.origin, goal, self.team, 192.0 ); if ( !isDefined( nodes ) || nodes.size <= 0 ) { @@ -1785,7 +1780,7 @@ initAStar( goal ) for ( i = nodes.size - 1; i >= 0; i-- ) { - node_indexes[ node_indexes.size ] = nodes[ i ] getNodeNumber(); + node_indexes[ node_indexes.size ] = nodes[ i ] BotBuiltinGetNodeNumber(); } self.bot.astar = node_indexes; @@ -1854,7 +1849,7 @@ watchOnGoal( goal, dis ) /* Bot will move towards here */ -botMoveTo( where ) +botSetMoveTo( where ) { self.bot.moveTo = where; } @@ -1872,12 +1867,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" ); } /* @@ -1893,14 +1888,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; @@ -1913,9 +1908,9 @@ frag( time ) holdbreath( what ) { if ( what ) - self botAction( "+holdbreath" ); + self BotBuiltinBotAction( "+holdbreath" ); else - self botAction( "-holdbreath" ); + self BotBuiltinBotAction( "-holdbreath" ); } /* @@ -1931,14 +1926,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; @@ -2009,12 +2004,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" ); } /* @@ -2027,9 +2022,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" ); } /* @@ -2045,9 +2040,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; @@ -2069,12 +2064,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" ); } /* @@ -2093,9 +2088,9 @@ jump() wait 1; } - self botAction( "+gostand" ); + self BotBuiltinBotAction( "+gostand" ); wait 0.05; - self botAction( "-gostand" ); + self BotBuiltinBotAction( "-gostand" ); } /* @@ -2103,8 +2098,8 @@ jump() */ stand() { - self botAction( "-gocrouch" ); - self botAction( "-goprone" ); + self BotBuiltinBotAction( "-gocrouch" ); + self BotBuiltinBotAction( "-goprone" ); } /* @@ -2112,8 +2107,8 @@ stand() */ crouch() { - self botAction( "+gocrouch" ); - self botAction( "-goprone" ); + self BotBuiltinBotAction( "+gocrouch" ); + self BotBuiltinBotAction( "-goprone" ); } /* @@ -2121,8 +2116,8 @@ crouch() */ prone() { - self botAction( "-gocrouch" ); - self botAction( "+goprone" ); + self BotBuiltinBotAction( "-gocrouch" ); + self BotBuiltinBotAction( "+goprone" ); } /* @@ -2135,7 +2130,7 @@ sprint() self notify( "bot_sprint" ); self endon( "bot_sprint" ); - self botAction( "+sprint" ); + self BotBuiltinBotAction( "+sprint" ); wait 0.05; - self botAction( "-sprint" ); + self BotBuiltinBotAction( "-sprint" ); } diff --git a/maps/bots/_bot_script.gsc b/maps/bots/_bot_script.gsc index 2914648..0846924 100644 --- a/maps/bots/_bot_script.gsc +++ b/maps/bots/_bot_script.gsc @@ -104,7 +104,6 @@ difficulty() self.pers["bots"]["behavior"]["follow"] = 5; self.pers["bots"]["behavior"]["crouch"] = 20; self.pers["bots"]["behavior"]["switch"] = 2; - self.pers["bots"]["behavior"]["class"] = 2; self.pers["bots"]["behavior"]["jump"] = 0; break; @@ -136,7 +135,6 @@ difficulty() self.pers["bots"]["behavior"]["follow"] = 5; self.pers["bots"]["behavior"]["crouch"] = 15; self.pers["bots"]["behavior"]["switch"] = 2; - self.pers["bots"]["behavior"]["class"] = 2; self.pers["bots"]["behavior"]["jump"] = 10; break; @@ -168,7 +166,6 @@ difficulty() self.pers["bots"]["behavior"]["follow"] = 5; self.pers["bots"]["behavior"]["crouch"] = 10; self.pers["bots"]["behavior"]["switch"] = 2; - self.pers["bots"]["behavior"]["class"] = 2; self.pers["bots"]["behavior"]["jump"] = 25; break; @@ -200,7 +197,6 @@ difficulty() self.pers["bots"]["behavior"]["follow"] = 5; self.pers["bots"]["behavior"]["crouch"] = 10; self.pers["bots"]["behavior"]["switch"] = 2; - self.pers["bots"]["behavior"]["class"] = 2; self.pers["bots"]["behavior"]["jump"] = 35; break; @@ -232,7 +228,6 @@ difficulty() self.pers["bots"]["behavior"]["follow"] = 5; self.pers["bots"]["behavior"]["crouch"] = 10; self.pers["bots"]["behavior"]["switch"] = 2; - self.pers["bots"]["behavior"]["class"] = 2; self.pers["bots"]["behavior"]["jump"] = 50; break; @@ -264,7 +259,6 @@ difficulty() self.pers["bots"]["behavior"]["follow"] = 5; self.pers["bots"]["behavior"]["crouch"] = 10; self.pers["bots"]["behavior"]["switch"] = 2; - self.pers["bots"]["behavior"]["class"] = 2; self.pers["bots"]["behavior"]["jump"] = 75; break; @@ -296,7 +290,6 @@ difficulty() self.pers["bots"]["behavior"]["follow"] = 5; self.pers["bots"]["behavior"]["crouch"] = 5; self.pers["bots"]["behavior"]["switch"] = 2; - self.pers["bots"]["behavior"]["class"] = 2; self.pers["bots"]["behavior"]["jump"] = 90; break; } @@ -352,7 +345,6 @@ set_diff() self.pers["bots"]["behavior"]["follow"] = randomInt( 100 ); self.pers["bots"]["behavior"]["crouch"] = randomInt( 100 ); self.pers["bots"]["behavior"]["switch"] = randomInt( 100 ); - self.pers["bots"]["behavior"]["class"] = randomInt( 100 ); self.pers["bots"]["behavior"]["jump"] = randomInt( 100 ); break; @@ -419,7 +411,7 @@ changeToWeapon( weap ) if ( !self HasWeapon( weap ) ) return false; - self BotChangeToWeapon( weap ); + self switchToWeapon( weap ); if ( self GetCurrentWeapon() == weap ) return true; diff --git a/maps/bots/_bot_utility.gsc b/maps/bots/_bot_utility.gsc index 07b39c4..73d9eb2 100644 --- a/maps/bots/_bot_utility.gsc +++ b/maps/bots/_bot_utility.gsc @@ -1,6 +1,227 @@ #include common_scripts\utility; #include maps\_utility; +/* + 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 ); + } +} + +/* + Bot action, does a bot action + botAction() +*/ +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 + botStop() +*/ +BotBuiltinBotStop() +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["botstop"] ) ) + { + self [[ level.bot_builtins["botstop" ]]](); + } +} + +/* + Sets the bot's movement + botMovement(, ) +*/ +BotBuiltinBotMovement( left, forward ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["botmovement"] ) ) + { + self [[ level.bot_builtins["botmovement" ]]]( left, forward ); + } +} + +/* + Test if is a bot + +*/ +BotBuiltinIsBot() +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["isbot"] ) ) + { + return self [[ level.bot_builtins["isbot" ]]](); + } + + return false; +} + +/* + Generates a path +*/ +BotBuiltinGeneratePath( from, to, team, best_effort ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["generatepath"] ) ) + { + return [[ level.bot_builtins["generatepath" ]]]( from, to, team, best_effort ); + } + + return []; +} + +/* + Returns function pointer +*/ +BotBuiltinGetFunction( file, threadname ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["getfunction"] ) ) + { + return [[ level.bot_builtins["getfunction" ]]]( file, threadname ); + } + + return undefined; +} + +/* + waw sp doesnt have +*/ +BotBuiltinGetMins() +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["getmins"] ) ) + { + return self [[ level.bot_builtins["getmins" ]]](); + } + + return ( 0, 0, 0 ); +} + +/* + waw sp doesnt have +*/ +BotBuiltinGetMaxs() +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["getmaxs"] ) ) + { + return self [[ level.bot_builtins["getmaxs" ]]](); + } + + return ( 0, 0, 0 ); +} + +/* + waw sp doesnt have +*/ +BotBuiltinGetGuid() +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["getguid"] ) ) + { + return self [[ level.bot_builtins["getguid" ]]](); + } + + return 0; +} + +/* +*/ +BotBuiltinsSetAllowedTraversals( bot_allowed_negotiation_links ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["setallowedtraversals"] ) ) + { + [[ level.bot_builtins["setallowedtraversals" ]]]( bot_allowed_negotiation_links ); + } +} + +/* +*/ +BotBuiltinsSetIgnoredLinks( bot_ignore_links ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["setignoredlinks"] ) ) + { + [[ level.bot_builtins["setignoredlinks" ]]]( bot_ignore_links ); + } +} + +/* +*/ +BotBuiltinGetNodeNumber() +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["getnodenumber"] ) ) + { + return self [[ level.bot_builtins["getnodenumber" ]]](); + } + + return 0; +} + +/* +*/ +BotBuiltinGetLinkedNodes() +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["getlinkednodes"] ) ) + { + return self [[ level.bot_builtins["getlinkednodes" ]]](); + } + + return []; +} + +/* +*/ +BotBuiltinAddTestClient() +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["addtestclient"] ) ) + { + return [[ level.bot_builtins["addtestclient" ]]](); + } + + return undefined; +} + +/* +*/ +BotBuiltinCmdExec( what ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["cmdexec"] ) ) + { + [[ level.bot_builtins["cmdexec" ]]]( what ); + } +} + +/* +*/ +BotBuiltinNotifyOnPlayerCommand( cmd, notif ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["notifyonplayercommand"] ) ) + { + self [[ level.bot_builtins["notifyonplayercommand" ]]]( cmd, notif ); + } +} + /* Returns if player is the host */ @@ -23,14 +244,14 @@ doHostCheck() if ( getDvar( "bots_main_firstIsHost" ) != "0" ) { - PrintConsole( "WARNING: bots_main_firstIsHost is enabled\n" ); + BotBuiltinPrintConsole( "WARNING: bots_main_firstIsHost is enabled" ); if ( getDvar( "bots_main_firstIsHost" ) == "1" ) { - setDvar( "bots_main_firstIsHost", self getguid() ); + setDvar( "bots_main_firstIsHost", self BotBuiltinGetGuid() ); } - if ( getDvar( "bots_main_firstIsHost" ) == self getguid() + "" ) + if ( getDvar( "bots_main_firstIsHost" ) == self BotBuiltinGetGuid() + "" ) result = true; } @@ -42,7 +263,7 @@ doHostCheck() for ( i = 0; i < guids.size; i++ ) { - if ( self getguid() + "" == guids[i] ) + if ( self BotBuiltinGetGuid() + "" == guids[i] ) result = true; } } @@ -58,7 +279,7 @@ doHostCheck() */ is_bot() { - return self isBot(); + return self BotBuiltinIsBot(); } /* @@ -82,14 +303,6 @@ BotSetStance( stance ) } } -/* - Bot changes to the weap -*/ -BotChangeToWeapon( weap ) -{ - self botWeapon( weap ); -} - /* Bot presses the button for time. */ @@ -133,7 +346,6 @@ BotPressSmoke( time ) /* Bot jumps */ - BotJump() { self maps\bots\_bot_internal::jump(); @@ -935,8 +1147,9 @@ load_waypoints() break; } - setAllowedTraversals( bot_allowed_negotiation_links ); - setIgnoredLinks( bot_ignore_links ); + // arrays are passed by value in gsc... hope this isnt gunna run out of vars + BotBuiltinsSetAllowedTraversals( bot_allowed_negotiation_links ); + BotBuiltinsSetIgnoredLinks( bot_ignore_links ); level.bot_ignore_links = bot_ignore_links; level.waypoints = GetAllNodes(); @@ -1219,7 +1432,7 @@ random_normal_distribution( mean, std_deviation, lower_bound, upper_bound ) */ inLastStand() { - func = GetFunction( "maps/_laststand", "player_is_in_laststand" ); + func = BotBuiltinGetFunction( "maps/_laststand", "player_is_in_laststand" ); return self [[func]](); } @@ -1229,7 +1442,7 @@ inLastStand() */ isReviving( revivee ) { - func = GetFunction( "maps/_laststand", "is_reviving" ); + func = BotBuiltinGetFunction( "maps/_laststand", "is_reviving" ); return self [[func]]( revivee ); } @@ -1279,20 +1492,12 @@ isWeaponPrimary( weap ) return false; } -/* - Generates the path -*/ -GenerateThePath( from, to, team, best_effort ) -{ - return generatePath( from, to, team, best_effort ); -} - /* Checks whether the path generated by the ASTAR path finding is inaccessible */ GetPathIsInaccessible( from, to, team, best_effort ) { - path = GenerateThePath( from, to, team, best_effort ); + path = BotBuiltinGeneratePath( from, to, team, best_effort ); return ( !isDefined( path ) || ( path.size <= 0 ) ); } @@ -1301,7 +1506,7 @@ GetPathIsInaccessible( from, to, team, best_effort ) */ get_path_dist( start, end, team ) { - path = GenerateThePath( start, end, team, 192.0 ); + path = BotBuiltinGeneratePath( start, end, team, 192.0 ); if ( !isDefined( path ) || path.size <= 0 ) { @@ -1409,8 +1614,8 @@ PointInsideUseTrigger( point ) self thread debug_bounding_box_for_ent(); } - mins = self getmins(); - maxs = self getmaxs(); + mins = self BotBuiltinGetMins(); + maxs = self BotBuiltinGetMaxs(); box = spawnstruct(); box.x0 = self.origin[0] + mins[0]; @@ -1447,8 +1652,8 @@ debug_bounding_box_for_ent( color ) while ( isDefined( self ) ) { - mins = self getmins(); - maxs = self getmaxs(); + mins = self BotBuiltinGetMins(); + maxs = self BotBuiltinGetMaxs(); line( self.origin + ( mins[0], mins[1], mins[2] ), self.origin + ( mins[0], mins[1], maxs[2] ), color ); line( self.origin + ( mins[0], mins[1], mins[2] ), self.origin + ( mins[0], maxs[1], mins[2] ), color ); diff --git a/maps/bots/objectives/_wallweapon.gsc b/maps/bots/objectives/_wallweapon.gsc index 54530ed..80f5951 100644 --- a/maps/bots/objectives/_wallweapon.gsc +++ b/maps/bots/objectives/_wallweapon.gsc @@ -44,7 +44,7 @@ Finder( eObj ) if ( !player_has_weapon || is_grenade ) { - func = GetFunction( "maps/_zombiemode_weapons", "get_weapon_cost" ); + func = BotBuiltinGetFunction( "maps/_zombiemode_weapons", "get_weapon_cost" ); if ( self.score < [[func]]( weapon_spawns[i].zombie_weapon_upgrade ) ) { @@ -53,7 +53,7 @@ Finder( eObj ) } else { - func = GetFunction( "maps/_zombiemode_weapons", "get_ammo_cost" ); + func = BotBuiltinGetFunction( "maps/_zombiemode_weapons", "get_ammo_cost" ); if ( self.score < [[func]]( weapon_spawns[i].zombie_weapon_upgrade ) ) { diff --git a/scripts/sp/bots.gsc b/scripts/sp/bots.gsc index b87cd21..0fa1f2c 100644 --- a/scripts/sp/bots.gsc +++ b/scripts/sp/bots.gsc @@ -1,8 +1,3 @@ -main() -{ - level thread maps\bots\_bot::main(); -} - init() { level thread maps\bots\_bot::init(); diff --git a/scripts/sp/bots_adapter.gsc b/scripts/sp/bots_adapter.gsc new file mode 100644 index 0000000..f88019b --- /dev/null +++ b/scripts/sp/bots_adapter.gsc @@ -0,0 +1,105 @@ +init() +{ + level.bot_builtins["printconsole"] = ::do_printconsole; + level.bot_builtins["botaction"] = ::do_botaction; + level.bot_builtins["botstop"] = ::do_botstop; + level.bot_builtins["botmovement"] = ::do_botmovement; + level.bot_builtins["isbot"] = ::do_isbot; + level.bot_builtins["generatepath"] = ::do_generatepath; + level.bot_builtins["getfunction"] = ::do_getfunction; + level.bot_builtins["getmins"] = ::do_getmins; + level.bot_builtins["getmaxs"] = ::do_getmaxs; + level.bot_builtins["getguid"] = ::do_getguid; + level.bot_builtins["setallowedtraversals"] = ::do_setallowedtraversals; + level.bot_builtins["setignoredlinks"] = ::do_setignoredlinks; + level.bot_builtins["getnodenumber"] = ::do_getnodenumber; + level.bot_builtins["getlinkednodes"] = ::do_getlinkednodes; + level.bot_builtins["addtestclient"] = ::do_addtestclient; + level.bot_builtins["notifyonplayercommand"] = ::do_notifyonplayercommand; + level.bot_builtins["cmdexec"] = ::do_cmdexec; +} + +do_printconsole( s ) +{ + PrintConsole( s ); +} + +do_botaction( action ) +{ + self BotAction( action ); +} + +do_botstop() +{ + self BotStop(); +} + +do_botmovement( left, forward ) +{ + self BotMovement( left, forward ); +} + +do_isbot() +{ + return self isBot(); +} + +do_generatepath( from, to, team, best_effort ) +{ + return GeneratePath( from, to, team, best_effort ); +} + +do_getfunction( file, threadname ) +{ + return GetFunction( file, threadname ); +} + +do_getmins() +{ + return self GetMins(); +} + +do_getmaxs() +{ + return self GetMaxs(); +} + +do_getguid() +{ + return self GetGuid(); +} + +do_setallowedtraversals( a ) +{ + setallowedtraversals( a ); +} + +do_setignoredlinks( a ) +{ + setignoredlinks( a ); +} + +do_getnodenumber() +{ + return self GetNodeNumber(); +} + +do_getlinkednodes() +{ + return self GetLinkedNodes(); +} + +do_addtestclient() +{ + return addtestclient(); +} + +do_notifyonplayercommand( a, b ) +{ + self notifyonplayercommand( a, b ); +} + +do_cmdexec( a ) +{ + cmdexec( a ); +}