diff --git a/data/scripts/mp/bots/_bot.gsc_raw b/data/scripts/mp/bots/_bot.gsc_raw index a8cac035..cd6b335d 100644 --- a/data/scripts/mp/bots/_bot.gsc_raw +++ b/data/scripts/mp/bots/_bot.gsc_raw @@ -73,52 +73,52 @@ #namespace bot; -#precache( "eventstring", "mpl_killstreak_cruisemissile" ); -#precache( "eventstring", "mpl_killstreak_raps" ); +#precache("eventstring", "mpl_killstreak_cruisemissile"); +#precache("eventstring", "mpl_killstreak_raps"); -REGISTER_SYSTEM( "bot_mp", &__init__, undefined ) +REGISTER_SYSTEM("bot_mp", &__init__, undefined) function __init__() { - callback::on_start_gametype( &init ); - + callback::on_start_gametype(&init); + level.getBotSettings = &get_bot_settings; - + level.onBotConnect = &on_bot_connect; level.onBotSpawned = &on_bot_spawned; level.onBotKilled = &on_bot_killed; - + level.botIdle = &bot_idle; - + level.botThreatLost = &bot_combat::chase_threat; level.botPreCombat = &bot_combat::mp_pre_combat; level.botCombat = &bot_combat::combat_think; level.botPostCombat = &bot_combat::mp_post_combat; - + level.botIgnoreThreat = &bot_combat::bot_ignore_threat; - + level.enemyEmpActive = &emp::enemyEmpActive; - + /# level.botDevguiCmd = &bot_devgui_cmd; level thread system_devgui_gadget_think(); #/ - setDvar( "bot_enableWallrun", 1 ); + setDvar("bot_enableWallrun", 1); } function init() -{ - level endon( "game_ended" ); - +{ + level endon("game_ended"); + level.botSoak = is_bot_soak(); - if( !init_bot_gametype() ) + if (!init_bot_gametype()) { return; } wait_for_host(); - + level thread populate_bots(); } @@ -127,18 +127,18 @@ function init() function is_bot_soak() { - return getDvarInt( "sv_botsoak", 0 ); + return getDvarInt("sv_botsoak", 0); } function wait_for_host() { - level endon( "game_ended" ); - + level endon("game_ended"); + host = util::getHostPlayerForBots(); - - while ( !isdefined( host ) ) + + while (!isdefined(host)) { - wait( 0.25 ); + wait(0.25); host = util::getHostPlayerForBots(); } } @@ -146,12 +146,12 @@ function wait_for_host() function get_host_team() { host = util::getHostPlayerForBots(); - - if ( !isdefined( host ) || host.team == "spectator" ) + + if (!isdefined(host) || host.team == "spectator") { return "allies"; } - + return host.team; } @@ -160,35 +160,34 @@ function is_bot_comp_stomp() return false; } - // Bot Events //======================================== function on_bot_connect() { - self endon( "disconnect" ); - level endon( "game_ended" ); - - if ( IS_TRUE( level.disableClassSelection ) ) + self endon("disconnect"); + level endon("game_ended"); + + if (IS_TRUE(level.disableClassSelection)) { self set_rank(); - + // Doesn't work if we don't do it in this order self bot_loadout::pick_hero_gadget(); self bot_loadout::pick_killstreaks(); - + return; } - - if ( !IS_TRUE( self.pers["bot_loadout"] ) ) + + if (!IS_TRUE(self.pers["bot_loadout"])) { self set_rank(); - + // Doesn't work if we don't do it in this order self bot_loadout::build_classes(); self bot_loadout::pick_hero_gadget(); self bot_loadout::pick_killstreaks(); - + self.pers["bot_loadout"] = true; } @@ -202,26 +201,26 @@ function on_bot_spawned() /# weapon = undefined; - if ( getDvarInt( "scr_botsHasPlayerWeapon" ) != 0 ) + if (getDvarInt("scr_botsHasPlayerWeapon") != 0) { player = util::getHostPlayer(); weapon = player getCurrentWeapon(); } - if ( getDvarString( "devgui_bot_weapon", "" ) != "" ) + if (getDvarString("devgui_bot_weapon", "") != "") { - weapon = getWeapon( getDvarString( "devgui_bot_weapon" ) ); + weapon = getWeapon(getDvarString("devgui_bot_weapon")); } - if ( isdefined( weapon ) && level.weaponNone != weapon ) + if (isdefined(weapon) && level.weaponNone != weapon) { self weapons::detach_all_weapons(); self takeAllWeapons(); - self giveWeapon( weapon ); - self switchToWeapon( weapon ); - self setSpawnWeapon( weapon ); + self giveWeapon(weapon); + self switchToWeapon(weapon); + self setSpawnWeapon(weapon); - self teams::set_player_model( self.team, weapon ); + self teams::set_player_model(self.team, weapon); } #/ } @@ -229,37 +228,37 @@ function on_bot_spawned() function on_bot_killed() { self endon("disconnect"); - level endon( "game_ended" ); - self endon( "spawned" ); - self waittill ( "death_delay_finished" ); + level endon("game_ended"); + self endon("spawned"); + self waittill("death_delay_finished"); wait RESPAWN_DELAY; - - if ( self choose_class() && level.playerForceRespawn ) + + if (self choose_class() && level.playerForceRespawn) { return; } - + self thread respawn(); } function respawn() { - self endon( "spawned" ); - self endon( "disconnect" ); - level endon( "game_ended" ); + self endon("spawned"); + self endon("disconnect"); + level endon("game_ended"); - while( 1 ) + while (1) { self bot::tap_use_button(); - + wait RESPAWN_INTERVAL; } } function bot_idle() -{ - if ( self do_supplydrop() ) +{ + if (self do_supplydrop()) { return; } @@ -274,85 +273,85 @@ function bot_idle() #define CRATE_GOAL_RADIUS 39 #define CRATE_USE_RADIUS 62 // Wild guess on usable radius -function do_supplydrop( maxRange = 1400 ) // A little under minimap width +function do_supplydrop(maxRange = 1400) // A little under minimap width { - crates = getEntArray( "care_package", "script_noteworthy" ); - + crates = getEntArray("care_package", "script_noteworthy"); + maxRangeSq = maxRange * maxRange; - + useRadiusSq = CRATE_USE_RADIUS * CRATE_USE_RADIUS; - + closestCrate = undefined; closestCrateDistSq = undefined; - foreach( crate in crates ) + foreach(crate in crates) { - if ( !crate isOnGround() ) + if (!crate isOnGround()) { continue; } - - crateDistSq = distance2DSquared( self.origin, crate.origin ); - - if ( crateDistSq > maxRangeSq ) + + crateDistSq = distance2DSquared(self.origin, crate.origin); + + if (crateDistSq > maxRangeSq) { continue; } - - inUse = isdefined( crate.useEnt ) && IS_TRUE( crate.useEnt.inUse ); - - if ( crateDistSq <= useRadiusSq ) + + inUse = isdefined(crate.useEnt) && IS_TRUE(crate.useEnt.inUse); + + if (crateDistSq <= useRadiusSq) { - if ( inUse && !self useButtonPressed() ) + if (inUse && !self useButtonPressed()) { continue; } - + self bot::press_use_button(); return true; } - if ( !self has_minimap() && !self botSightTracePassed( crate ) ) + if (!self has_minimap() && !self botSightTracePassed(crate)) { continue; } - if ( !isdefined( closestCrate ) || crateDistSq < closestCrateDistSq ) + if (!isdefined(closestCrate) || crateDistSq < closestCrateDistSq) { closestCrate = crate; closestCrateDistSq = crateDistSq; } } - - if ( isdefined( closestCrate ) ) - { - randomAngle = ( 0, randomInt( 360 ), 0 ); - randomVec = AnglesToForward( randomAngle ); - + + if (isdefined(closestCrate)) + { + randomAngle = (0, randomInt(360), 0); + randomVec = AnglesToForward(randomAngle); + point = closestCrate.origin + randomVec * CRATE_GOAL_RADIUS; - - if ( self botSetGoal( point ) ) + + if (self botSetGoal(point)) { - self thread watch_crate( closestCrate ); + self thread watch_crate(closestCrate); return true; } } - + return false; } -function watch_crate( crate ) +function watch_crate(crate) { - self endon( "death" ); - self endon( "bot_goal_reached" ); - level endon( "game_ended" ); - - while ( isdefined( crate ) && !self bot_combat::has_threat() ) + self endon("death"); + self endon("bot_goal_reached"); + level endon("game_ended"); + + while (isdefined(crate) && !self bot_combat::has_threat()) { wait level.botSettings.thinkInterval; } - - self botSetGoal( self.origin ); + + self botSetGoal(self.origin); } // Bot Team Population @@ -360,164 +359,164 @@ function watch_crate( crate ) function populate_bots() { - level endon( "game_ended" ); - - if ( level.teambased ) + level endon("game_ended"); + + if (level.teambased) { - maxAllies = getDvarInt( "bot_maxAllies", 0 ); - maxAxis = getDvarInt( "bot_maxAxis", 0 ); - - level thread monitor_bot_team_population( maxAllies, maxAxis ); + maxAllies = getDvarInt("bot_maxAllies", 0); + maxAxis = getDvarInt("bot_maxAxis", 0); + + level thread monitor_bot_team_population(maxAllies, maxAxis); } else { - maxFree = getDvarInt( "bot_maxFree", 0 ); - - level thread monitor_bot_population( maxFree ); + maxFree = getDvarInt("bot_maxFree", 0); + + level thread monitor_bot_population(maxFree); } } -function monitor_bot_team_population( maxAllies, maxAxis ) +function monitor_bot_team_population(maxAllies, maxAxis) { - level endon( "game_ended" ); - - if ( !maxAllies && !maxAxis ) + level endon("game_ended"); + + if (!maxAllies && !maxAxis) { return; } - - fill_balanced_teams( maxAllies, maxAxis ); - - while ( 1 ) + + fill_balanced_teams(maxAllies, maxAxis); + + while (1) { wait 3; - + // TODO: Get a player count that includes 'CON_CONNECTING' players - allies = getPlayers( "allies" ); - axis = getPlayers( "axis" ); - - if ( allies.size > maxAllies && - remove_best_bot( allies ) ) + allies = getPlayers("allies"); + axis = getPlayers("axis"); + + if (allies.size > maxAllies && + remove_best_bot(allies)) { continue; } - - if ( axis.size > maxAxis && - remove_best_bot( axis ) ) + + if (axis.size > maxAxis && + remove_best_bot(axis)) { continue; } - - if ( allies.size < maxAllies || axis.size < maxAxis ) + + if (allies.size < maxAllies || axis.size < maxAxis) { - add_balanced_bot( allies, maxAllies, axis, maxAxis ); + add_balanced_bot(allies, maxAllies, axis, maxAxis); } } } -function fill_balanced_teams( maxAllies, maxAxis ) +function fill_balanced_teams(maxAllies, maxAxis) { - allies = getPlayers( "allies" ); - axis = getPlayers( "axis" ); - - while ( ( allies.size < maxAllies || axis.size < maxAxis ) && - add_balanced_bot( allies, maxAllies, axis, maxAxis ) ) - { - WAIT_SERVER_FRAME; - - allies = getPlayers( "allies" ); - axis = getPlayers( "axis" ); - } -} + allies = getPlayers("allies"); + axis = getPlayers("axis"); -function add_balanced_bot( allies, maxAllies, axis, maxAxis ) -{ - bot = undefined; - - if ( allies.size < maxAllies && - ( allies.size <= axis.size || axis.size >= maxAxis ) ) - { - bot = add_bot( "allies" ); - } - else if ( axis.size < maxAxis ) + while ((allies.size < maxAllies || axis.size < maxAxis) && + add_balanced_bot(allies, maxAllies, axis, maxAxis)) { - bot = add_bot( "axis" ); - } + WAIT_SERVER_FRAME; - return isdefined( bot ); + allies = getPlayers("allies"); + axis = getPlayers("axis"); + } } -function monitor_bot_population( maxFree ) +function add_balanced_bot(allies, maxAllies, axis, maxAxis) { - level endon( "game_ended" ); - - if ( !maxFree ) + bot = undefined; + + if (allies.size < maxAllies && + (allies.size <= axis.size || axis.size >= maxAxis)) + { + bot = add_bot("allies"); + } + else if (axis.size < maxAxis) + { + bot = add_bot("axis"); + } + + return isdefined(bot); +} + +function monitor_bot_population(maxFree) +{ + level endon("game_ended"); + + if (!maxFree) { return; } - + // Initial Fill - players = getPlayers( ); - while ( players.size < maxFree ) + players = getPlayers(); + while (players.size < maxFree) { add_bot(); WAIT_SERVER_FRAME; - players = getPlayers( ); + players = getPlayers(); } - - while ( 1 ) + + while (1) { wait 3; - + // TODO: Get a player count that includes 'CON_CONNECTING' players - players = getPlayers( ); - - if ( players.size < maxFree ) + players = getPlayers(); + + if (players.size < maxFree) { add_bot(); } - else if ( players.size > maxFree ) + else if (players.size > maxFree) { - remove_best_bot( players ); + remove_best_bot(players); } } } -function remove_best_bot( players ) +function remove_best_bot(players) { - bots = filter_bots( players ); - - if ( !bots.size ) + bots = filter_bots(players); + + if (!bots.size) { return false; } - + // Prefer non-combat bots bestBots = []; - - foreach( bot in bots ) + + foreach(bot in bots) { // Don't kick bots in the process of connecting - if ( bot.sessionstate == "spectator" ) + if (bot.sessionstate == "spectator") { continue; } - - if ( bot.sessionstate == "dead" || !bot bot_combat::has_threat() ) + + if (bot.sessionstate == "dead" || !bot bot_combat::has_threat()) { bestBots[bestBots.size] = bot; } } - - if ( bestBots.size ) + + if (bestBots.size) { - remove_bot( bestBots[randomInt( bestBots.size )] ); + remove_bot(bestBots[randomInt(bestBots.size)]); } else { - remove_bot( bots[randomInt( bots.size )] ); + remove_bot(bots[randomInt(bots.size)]); } - + return true; } @@ -526,26 +525,26 @@ function remove_best_bot( players ) function choose_class() { - if ( IS_TRUE( level.disableClassSelection ) ) + if (IS_TRUE(level.disableClassSelection)) { return false; } - + currClass = self bot_loadout::get_current_class(); - if ( !isdefined( currClass ) || randomInt( 100 ) < VAL( level.botSettings.changeClassWeight, 0 ) ) + if (!isdefined(currClass) || randomInt(100) < VAL(level.botSettings.changeClassWeight, 0)) { - classIndex = randomInt( self.loadoutClasses.size ); + classIndex = randomInt(self.loadoutClasses.size); className = self.loadoutClasses[classIndex].name; } - - if ( !isdefined(className) || className === currClass ) + + if (!isdefined(className) || className == = currClass) { return false; } - - self notify( "menuresponse", MENU_CHANGE_CLASS, className ); - + + self notify("menuresponse", MENU_CHANGE_CLASS, className); + return true; } @@ -554,229 +553,229 @@ function choose_class() function use_killstreak() { - if ( !level.loadoutKillstreaksEnabled || - self emp::enemyEmpActive() ) + if (!level.loadoutKillstreaksEnabled || + self emp::enemyEmpActive()) { return; } - + weapons = self getWeaponsList(); inventoryWeapon = self getInventoryWeapon(); - - foreach( weapon in weapons ) - { - killstreak = killstreaks::get_killstreak_for_weapon( weapon ); - - if ( !isdefined( killstreak ) ) + + foreach(weapon in weapons) + { + killstreak = killstreaks::get_killstreak_for_weapon(weapon); + + if (!isdefined(killstreak)) { continue; } - - if ( weapon != inventoryWeapon && !self getWeaponAmmoClip( weapon ) ) + + if (weapon != inventoryWeapon && !self getWeaponAmmoClip(weapon)) { continue; } - - if ( self killstreakrules::isKillstreakAllowed( killstreak, self.team ) ) + + if (self killstreakrules::isKillstreakAllowed(killstreak, self.team)) { useWeapon = weapon; break; } } - - if ( !isdefined( useWeapon ) ) + + if (!isdefined(useWeapon)) { return; } - - killstreak_ref = killstreaks::get_menu_name( killstreak ); - - switch( killstreak_ref ) + + killstreak_ref = killstreaks::get_menu_name(killstreak); + + switch (killstreak_ref) { - case "killstreak_uav": - case "killstreak_counteruav": - case "killstreak_satellite": - case "killstreak_helicopter_player_gunner": - case "killstreak_raps": - case "killstreak_sentinel": - { - self switchToWeapon( useWeapon ); - break; - } - case "killstreak_ai_tank_drop": - { - self use_supply_drop( weapon ); - break; - } - case "killstreak_remote_missile": - { - self switchToWeapon( weapon ); - self waittill( "weapon_change_complete" ); - wait 1.5; - self bot::press_attack_button(); - return; - } + case "killstreak_uav": + case "killstreak_counteruav": + case "killstreak_satellite": + case "killstreak_helicopter_player_gunner": + case "killstreak_raps": + case "killstreak_sentinel": + { + self switchToWeapon(useWeapon); + break; + } + case "killstreak_ai_tank_drop": + { + self use_supply_drop(weapon); + break; + } + case "killstreak_remote_missile": + { + self switchToWeapon(weapon); + self waittill("weapon_change_complete"); + wait 1.5; + self bot::press_attack_button(); + return; + } } } -function get_closest_enemy( origin, on_radar ) +function get_closest_enemy(origin, on_radar) { - enemies = self get_enemies( on_radar ); - enemies = arraysort( enemies, origin ); + enemies = self get_enemies(on_radar); + enemies = arraysort(enemies, origin); - if ( enemies.size ) - return enemies[0]; + if (enemies.size) + return enemies[0]; - return undefined; + return undefined; } -function use_supply_drop( weapon ) +function use_supply_drop(weapon) { - if ( weapon == "inventory_supplydrop_mp" || weapon == "supplydrop_mp" ) - { - if ( gettime() - self.spawntime > 5000 ) - return; - } + if (weapon == "inventory_supplydrop_mp" || weapon == "supplydrop_mp") + { + if (gettime() - self.spawntime > 5000) + return; + } - yaw = ( 0, self.angles[1], 0 ); - dir = anglestoforward( yaw ); - dir = vectornormalize( dir ); - drop_point = self.origin + vectorscale( dir, 384 ); - end = drop_point + vectorscale( ( 0, 0, 1 ), 2048.0 ); + yaw = (0, self.angles[1], 0); + dir = anglestoforward(yaw); + dir = vectornormalize(dir); + drop_point = self.origin + vectorscale(dir, 384); + end = drop_point + vectorscale((0, 0, 1), 2048.0); - if ( !sighttracepassed( drop_point, end, 0, undefined ) ) - return; + if (!sighttracepassed(drop_point, end, 0, undefined)) + return; - if ( !sighttracepassed( self.origin, end, 0, undefined ) ) - return; + if (!sighttracepassed(self.origin, end, 0, undefined)) + return; - end = drop_point - vectorscale( ( 0, 0, 1 ), 32.0 ); + end = drop_point - vectorscale((0, 0, 1), 32.0); - if ( bullettracepassed( drop_point, end, 0, undefined ) ) - return; + if (bullettracepassed(drop_point, end, 0, undefined)) + return; - self addgoal( self.origin, 24, 4, "killstreak" ); + self addgoal(self.origin, 24, 4, "killstreak"); - if ( weapon == "missile_drone_mp" || weapon == "inventory_missile_drone_mp" ) - self lookat( drop_point + vectorscale( ( 0, 0, 1 ), 384.0 ) ); - else - self lookat( drop_point ); + if (weapon == "missile_drone_mp" || weapon == "inventory_missile_drone_mp") + self lookat(drop_point + vectorscale((0, 0, 1), 384.0)); + else + self lookat(drop_point); - wait 0.5; + wait 0.5; - if ( self getCurrentWeapon() != weapon ) - { - self thread weapon_switch_failsafe(); - self switchToWeapon( weapon ); + if (self getCurrentWeapon() != weapon) + { + self thread weapon_switch_failsafe(); + self switchToWeapon(weapon); - self waittill( "weapon_change_complete" ); - } + self waittill("weapon_change_complete"); + } - use_item( weapon ); - self switchToWeapon( self.lastnonkillstreakweapon ); - self clearlookat(); - self cancelgoal( "killstreak" ); + use_item(weapon); + self switchToWeapon(self.lastnonkillstreakweapon); + self clearlookat(); + self cancelgoal("killstreak"); } -function use_item( weapon ) +function use_item(weapon) { - self bot::press_attack_button(); - wait 0.5; + self bot::press_attack_button(); + wait 0.5; - for ( i = 0; i < 10; i++ ) - { - if ( self getCurrentWeapon() == weapon || self getCurrentWeapon() == "none" ) - self bot::press_attack_button(); - else - return; + for (i = 0; i < 10; i++) + { + if (self getCurrentWeapon() == weapon || self getCurrentWeapon() == "none") + self bot::press_attack_button(); + else + return; - wait 0.5; - } + wait 0.5; + } } -function killstreak_location( num, weapon ) +function killstreak_location(num, weapon) { - enemies = get_enemies(); + enemies = get_enemies(); - if ( !enemies.size ) - return; + if (!enemies.size) + return; - if ( !self switchToWeapon( weapon ) ) - return; + if (!self switchToWeapon(weapon)) + return; - self waittill( "weapon_change" ); + self waittill("weapon_change"); - self util::freeze_player_controls( true ); - wait_time = 1; + self util::freeze_player_controls(true); + wait_time = 1; - while ( !isdefined( self.selectinglocation ) || self.selectinglocation == 0 ) - { - wait 0.05; - wait_time -= 0.05; + while (!isdefined(self.selectinglocation) || self.selectinglocation == 0) + { + wait 0.05; + wait_time -= 0.05; - if ( wait_time <= 0 ) - { - self util::freeze_player_controls( false ); - self switchToWeapon( self.lastnonkillstreakweapon ); - return; - } - } + if (wait_time <= 0) + { + self util::freeze_player_controls(false); + self switchToWeapon(self.lastnonkillstreakweapon); + return; + } + } - wait 2; + wait 2; - for ( i = 0; i < num; i++ ) - { - enemies = get_enemies(); + for (i = 0; i < num; i++) + { + enemies = get_enemies(); - if ( enemies.size ) - { - enemy = randomInt( enemies ); - self notify( "confirm_location", enemy.origin, 0 ); - } + if (enemies.size) + { + enemy = randomInt(enemies); + self notify("confirm_location", enemy.origin, 0); + } - wait 0.25; - } + wait 0.25; + } - self util::freeze_player_controls( false ); + self util::freeze_player_controls(false); } function weapon_switch_failsafe() { - self endon( "death" ); - self endon( "disconnect" ); - self endon( "weapon_change_complete" ); - wait 10; - self notify( "weapon_change_complete" ); + self endon("death"); + self endon("disconnect"); + self endon("weapon_change_complete"); + wait 10; + self notify("weapon_change_complete"); } function has_radar() { - if ( level.teambased ) + if (level.teambased) { - return ( uav::HasUAV( self.team ) || satellite::HasSatellite( self.team ) ); + return (uav::HasUAV(self.team) || satellite::HasSatellite(self.team)); } - - return ( uav::HasUAV( self.entnum ) || satellite::HasSatellite( self.entnum ) ); + + return (uav::HasUAV(self.entnum) || satellite::HasSatellite(self.entnum)); } function has_minimap() { - if ( self IsEmpJammed() ) + if (self IsEmpJammed()) { return false; } - - if ( IS_TRUE( level.hardcoreMode ) ) + + if (IS_TRUE(level.hardcoreMode)) { return self has_radar(); } - + return true; } -function get_enemies( on_radar ) +function get_enemies(on_radar) { - if ( !isdefined( on_radar ) ) + if (!isdefined(on_radar)) { on_radar = false; } @@ -784,28 +783,28 @@ function get_enemies( on_radar ) enemies = self GetEnemies(); /# - for ( i = 0; i < enemies.size; i++ ) + for (i = 0; i < enemies.size; i++) { - if ( isplayer( enemies[i] ) && enemies[i] isInMoveMode( "ufo", "noclip" ) ) + if (isplayer(enemies[i]) && enemies[i] isInMoveMode("ufo", "noclip")) { - arrayRemoveIndex( enemies, i ); + arrayRemoveIndex(enemies, i); i--; } } #/ - if ( on_radar && !self has_radar() ) + if (on_radar && !self has_radar()) { - for ( i = 0; i < enemies.size; i++ ) + for (i = 0; i < enemies.size; i++) { - if ( !isdefined( enemies[i].lastFireTime ) ) + if (!isdefined(enemies[i].lastFireTime)) { - arrayRemoveIndex( enemies, i ); + arrayRemoveIndex(enemies, i); i--; } - else if ( GetTime() - enemies[i].lastFireTime > 2000 ) + else if (GetTime() - enemies[i].lastFireTime > 2000) { - arrayRemoveIndex( enemies, i ); + arrayRemoveIndex(enemies, i); i--; } } @@ -822,101 +821,101 @@ function set_rank() bot_ranks = []; human_ranks = []; - for ( i = 0; i < players.size; i++ ) + for (i = 0; i < players.size; i++) { - if ( players[i] == self ) + if (players[i] == self) continue; - if ( isdefined( players[i].pers[ "rank" ] ) ) + if (isdefined(players[i].pers["rank"])) { - if ( players[i] util::is_bot() ) + if (players[i] util::is_bot()) { - bot_ranks[ bot_ranks.size ] = players[i].pers[ "rank" ]; + bot_ranks[bot_ranks.size] = players[i].pers["rank"]; } else { - human_ranks[ human_ranks.size ] = players[i].pers[ "rank" ]; + human_ranks[human_ranks.size] = players[i].pers["rank"]; } } } - if( !human_ranks.size ) - human_ranks[ human_ranks.size ] = 10; + if (!human_ranks.size) + human_ranks[human_ranks.size] = 10; - human_avg = math::array_average( human_ranks ); + human_avg = math::array_average(human_ranks); - while ( bot_ranks.size + human_ranks.size < 5 ) + while (bot_ranks.size + human_ranks.size < 5) { // add some random ranks for better random number distribution - r = human_avg + randomIntRange( -5, 5 ); - rank = math::clamp( r, 0, level.maxRank ); - human_ranks[ human_ranks.size ] = rank; + r = human_avg + randomIntRange(-5, 5); + rank = math::clamp(r, 0, level.maxRank); + human_ranks[human_ranks.size] = rank; } - ranks = arrayCombine( human_ranks, bot_ranks, true, false ); + ranks = arrayCombine(human_ranks, bot_ranks, true, false); - avg = math::array_average( ranks ); - s = math::array_std_deviation( ranks, avg ); - - rank = Int( math::random_normal_distribution( avg, s, 0, level.maxRank ) ); - - while ( !isdefined( self.pers["codpoints"] ) ) + avg = math::array_average(ranks); + s = math::array_std_deviation(ranks, avg); + + rank = Int(math::random_normal_distribution(avg, s, 0, level.maxRank)); + + while (!isdefined(self.pers["codpoints"])) { wait 0.1; } - - self.pers[ "rank" ] = rank; - self.pers[ "rankxp" ] = rank::getRankInfoMinXP( rank ); - self setRank( rank ); + self.pers["rank"] = rank; + self.pers["rankxp"] = rank::getRankInfoMinXP(rank); + + self setRank(rank); self rank::syncXPStat(); } function init_bot_gametype() { - switch( level.gameType ) + switch (level.gameType) { - case "ball": - bot_ball::init(); - return true; - case "conf": - bot_conf::init(); - return true; - case "ctf": - bot_ctf::init(); - return true; - case "dem": - bot_dem::init(); - return true; - case "dm": - return true; - case "dom": - bot_dom::init(); - return true; - case "escort": - bot_escort::init(); - return true; + case "ball": + bot_ball::init(); + return true; + case "conf": + bot_conf::init(); + return true; + case "ctf": + bot_ctf::init(); + return true; + case "dem": + bot_dem::init(); + return true; + case "dm": + return true; + case "dom": + bot_dom::init(); + return true; + case "escort": + bot_escort::init(); + return true; // case "infect": // return true; - case "gun": - return true; - case "koth": - bot_koth::init(); - return true; - case "sd": - bot_sd::init(); - return true; - case "clean": - bot_clean::init(); - return true; - case "tdm": - return true; - case "sas": - return true; - case "prop": - return true; - case "sniperonly": - return true; + case "gun": + return true; + case "koth": + bot_koth::init(); + return true; + case "sd": + bot_sd::init(); + return true; + case "clean": + bot_clean::init(); + return true; + case "tdm": + return true; + case "sas": + return true; + case "prop": + return true; + case "sniperonly": + return true; } return false; @@ -924,99 +923,99 @@ function init_bot_gametype() function get_bot_settings() { - switch ( getDvarInt( "bot_difficulty", 1 ) ) + switch (getDvarInt("bot_difficulty", 1)) { - case 0: - bundleName = "bot_mp_easy"; - break; - - case 1: - bundleName = "bot_mp_normal"; - break; - case 2: - bundleName = "bot_mp_hard"; - break; - case 3: - default: - bundleName = "bot_mp_veteran"; - break; + case 0: + bundleName = "bot_mp_easy"; + break; + + case 1: + bundleName = "bot_mp_normal"; + break; + case 2: + bundleName = "bot_mp_hard"; + break; + case 3: + default: + bundleName = "bot_mp_veteran"; + break; } - - return struct::get_script_bundle( "botsettings", bundleName ); + + return struct::get_script_bundle("botsettings", bundleName); } -function friend_goal_in_radius( goal_name, origin, radius ) +function friend_goal_in_radius(goal_name, origin, radius) { return 0; } -function friend_in_radius( goal_name, origin, radius ) +function friend_in_radius(goal_name, origin, radius) { return false; } function get_friends() { - return []; + return[]; } -function bot_vehicle_weapon_ammo( weaponName ) +function bot_vehicle_weapon_ammo(weaponName) { return false; } -function navmesh_points_visible( origin, point ) +function navmesh_points_visible(origin, point) { return false; } -function dive_to_prone( exit_stance ) +function dive_to_prone(exit_stance) { - + } -/# +/ # // Devgui //======================================== -function bot_devgui_cmd( cmd ) +function bot_devgui_cmd(cmd) { - cmdTokens = strtok( cmd," "); - - if ( cmdTokens.size == 0 ) + cmdTokens = strtok(cmd, " "); + + if (cmdTokens.size == 0) { return false; } - + host = util::getHostPlayerForBots(); team = get_host_team(); - - switch( cmdTokens[0] ) + + switch (cmdTokens[0]) { case "spawn_enemy": - team = util::getotherteam(team); - case "spawn_friendly": + team = util::getotherteam(team); + case "spawn_friendly": count = 1; - if ( cmdTokens.size > 1 ) + if (cmdTokens.size > 1) { - count = int( cmdTokens[1] ); + count = int(cmdTokens[1]); } - for( i = 0; i < count; i++ ) + for (i = 0; i < count; i++) { - add_bot( team ); + add_bot(team); } return true; case "remove_enemy": team = util::getotherteam(team); case "remove_friendly": - remove_bots( undefined, team ); + remove_bots(undefined, team); return true; case "fixed_spawn_enemy": - team = util::getotherteam(team); - case "fixed_spawn_friendly": - bot = add_bot_at_eye_trace( team ); - if ( isdefined( bot ) ) + team = util::getotherteam(team); + case "fixed_spawn_friendly": + bot = add_bot_at_eye_trace(team); + if (isdefined(bot)) { bot thread fixed_spawn_override(); } @@ -1024,9 +1023,9 @@ function bot_devgui_cmd( cmd ) case "player_weapon": players = getPlayers(); - foreach( player in players ) + foreach(player in players) { - if ( !player util::is_bot() ) + if (!player util::is_bot()) { continue; } @@ -1035,11 +1034,11 @@ function bot_devgui_cmd( cmd ) player weapons::detach_all_weapons(); player takeAllWeapons(); - player giveWeapon( weapon ); - player switchToWeapon( weapon ); - player setSpawnWeapon( weapon ); + player giveWeapon(weapon); + player switchToWeapon(weapon); + player setSpawnWeapon(weapon); - player teams::set_player_model( player.team, weapon ); + player teams::set_player_model(player.team, weapon); } return true; } @@ -1049,71 +1048,69 @@ function bot_devgui_cmd( cmd ) function system_devgui_gadget_think() { - setDvar( "devgui_bot_gadget", "" ); + setDvar("devgui_bot_gadget", ""); - for ( ;; ) + for (;; ) { - wait( 1 ); + wait(1); - gadget = getDvarString( "devgui_bot_gadget" ); - - if ( gadget != "" ) + gadget = getDvarString("devgui_bot_gadget"); + + if (gadget != "") { - bot_turn_on_gadget( getWeapon(gadget) ); - setDvar( "devgui_bot_gadget", "" ); - } + bot_turn_on_gadget(getWeapon(gadget)); + setDvar("devgui_bot_gadget", ""); + } } } -function bot_turn_on_gadget( gadget ) +function bot_turn_on_gadget(gadget) { players = getPlayers(); - - foreach( player in players ) + + foreach(player in players) { - if ( !player util::is_bot() ) + if (!player util::is_bot()) { continue; } - + host = util::getHostPlayer(); weapon = host getCurrentWeapon(); - - if ( !isdefined( weapon ) || weapon == level.weaponNone || weapon == level.weaponNull ) + + if (!isdefined(weapon) || weapon == level.weaponNone || weapon == level.weaponNull) { - weapon = getWeapon( "smg_standard" ); + weapon = getWeapon("smg_standard"); } player weapons::detach_all_weapons(); player takeAllWeapons(); - player giveWeapon( weapon ); - player switchToWeapon( weapon ); - player setSpawnWeapon( weapon ); + player giveWeapon(weapon); + player switchToWeapon(weapon); + player setSpawnWeapon(weapon); - player teams::set_player_model( player.team, weapon ); - - player giveWeapon( gadget ); - slot = player gadgetGetSlot( gadget ); - player gadgetPowerSet( slot, 100.0 ); - player botPressButtonForGadget( gadget ); - } + player teams::set_player_model(player.team, weapon); + + player giveWeapon(gadget); + slot = player gadgetGetSlot(gadget); + player gadgetPowerSet(slot, 100.0); + player botPressButtonForGadget(gadget); + } } - - function fixed_spawn_override() { - self endon( "disconnect" ); - + self endon("disconnect"); + spawnOrigin = self.origin; spawnAngles = self.angles; - - while( 1 ) + + while (1) { - self waittill( "spawned_player" ); - - self setOrigin( spawnOrigin ); - self setPlayerAngles( spawnAngles ); + self waittill("spawned_player"); + + self setOrigin(spawnOrigin); + self setPlayerAngles(spawnAngles); } }