From fcd130a132167061afe144547ef170b20c2c50a9 Mon Sep 17 00:00:00 2001 From: ineed bots Date: Thu, 4 Apr 2024 15:38:50 -0600 Subject: [PATCH] update bones --- maps/mp/bots/_bot_internal.gsc | 62 +++++++++++++++++++--------------- maps/mp/bots/_bot_utility.gsc | 55 ++++++++++++++++-------------- maps/mp/bots/_wp_editor.gsc | 1 + 3 files changed, 65 insertions(+), 53 deletions(-) diff --git a/maps/mp/bots/_bot_internal.gsc b/maps/mp/bots/_bot_internal.gsc index 5a509ce..effe60a 100644 --- a/maps/mp/bots/_bot_internal.gsc +++ b/maps/mp/bots/_bot_internal.gsc @@ -902,20 +902,23 @@ updateBones() { self endon( "disconnect" ); self endon( "death" ); - - bones = strtok( self.pers[ "bots" ][ "skill" ][ "bones" ], "," ); - waittime = self.pers[ "bots" ][ "skill" ][ "bone_update_interval" ]; - + for ( ;; ) { - self waittill_notify_or_timeout( "new_enemy", waittime ); - - if ( !isdefined( self.bot.target ) ) + oldbones = self.pers[ "bots" ][ "skill" ][ "bones" ]; + bones = strtok( oldbones, "," ); + + while ( oldbones == self.pers[ "bots" ][ "skill" ][ "bones" ] ) { - continue; + self waittill_notify_or_timeout( "new_enemy", self.pers[ "bots" ][ "skill" ][ "bone_update_interval" ] ); + + if ( !isdefined( self.bot.target ) ) + { + continue; + } + + self.bot.target.bone = random( bones ); } - - self.bot.target.bone = random( bones ); } } @@ -1024,6 +1027,23 @@ targetObjUpdateNoTrace( obj ) obj.didlook = false; } +/* + Returns true if myEye can see the bone of self +*/ +checkTraceForBone( myEye, bone ) +{ + boneLoc = self gettagorigin( bone ); + + if ( !isdefined( boneLoc ) ) + { + return false; + } + + trace = bullettrace( myEye, boneLoc, false, undefined ); + + return ( sighttracepassed( myEye, boneLoc, false, undefined ) && ( trace[ "fraction" ] >= 1.0 || trace[ "surfacetype" ] == "glass" ) ); +} + /* The main target thread, will update the bot's main target. Will auto target enemy players and handle script targets. */ @@ -1135,21 +1155,9 @@ target_loop() continue; } - targetHead = player gettagorigin( "j_head" ); - targetAnkleLeft = player gettagorigin( "j_ankle_le" ); - targetAnkleRight = player gettagorigin( "j_ankle_ri" ); - - traceHead = bullettrace( myEye, targetHead, false, undefined ); - traceAnkleLeft = bullettrace( myEye, targetAnkleLeft, false, undefined ); - traceAnkleRight = bullettrace( myEye, targetAnkleRight, false, undefined ); - - canTargetPlayer = ( ( sighttracepassed( myEye, targetHead, false, undefined ) || - sighttracepassed( myEye, targetAnkleLeft, false, undefined ) || - sighttracepassed( myEye, targetAnkleRight, false, undefined ) ) - - && ( ( traceHead[ "fraction" ] >= 1.0 || traceHead[ "surfacetype" ] == "glass" ) || - ( traceAnkleLeft[ "fraction" ] >= 1.0 || traceAnkleLeft[ "surfacetype" ] == "glass" ) || - ( traceAnkleRight[ "fraction" ] >= 1.0 || traceAnkleRight[ "surfacetype" ] == "glass" ) ) + canTargetPlayer = ( ( player checkTraceForBone( myEye, "j_head" ) || + player checkTraceForBone( myEye, "j_ankle_le" ) || + player checkTraceForBone( myEye, "j_ankle_ri" ) ) && ( SmokeTrace( myEye, player.origin, level.smokeradius ) || daDist < level.bots_maxknifedistance * 4 ) @@ -1954,9 +1962,9 @@ walk_loop() dist = 16; - if ( level.waypointcount ) + if ( level.waypoints.size ) { - goal = level.waypoints[ randomint( level.waypointcount ) ].origin; + goal = level.waypoints[ randomint( level.waypoints.size ) ].origin; } else { diff --git a/maps/mp/bots/_bot_utility.gsc b/maps/mp/bots/_bot_utility.gsc index 11bcd0c..84bf6e2 100644 --- a/maps/mp/bots/_bot_utility.gsc +++ b/maps/mp/bots/_bot_utility.gsc @@ -1750,7 +1750,6 @@ load_waypoints() { mapname = getdvar( "mapname" ); - level.waypointcount = 0; level.waypointusage = []; level.waypointusage[ "allies" ] = []; level.waypointusage[ "axis" ] = []; @@ -1797,9 +1796,7 @@ load_waypoints() BotBuiltinPrintConsole( "No waypoints loaded!" ); } - level.waypointcount = level.waypoints.size; - - for ( i = 0; i < level.waypointcount; i++ ) + for ( i = level.waypoints.size - 1; i >= 0; i-- ) { if ( !isdefined( level.waypoints[ i ].children ) || !isdefined( level.waypoints[ i ].children.size ) ) { @@ -1898,7 +1895,7 @@ getWaypointsOfType( type ) { answer = []; - for ( i = 0; i < level.waypointcount; i++ ) + for ( i = level.waypoints.size - 1; i >= 0; i-- ) { wp = level.waypoints[ i ]; @@ -2704,17 +2701,19 @@ RemoveWaypointUsage( wp, team ) { return; } + + wpstr = wp + ""; - if ( !isdefined( level.waypointusage[ team ][ wp + "" ] ) ) + if ( !isdefined( level.waypointusage[ team ][ wpstr ] ) ) { return; } - level.waypointusage[ team ][ wp + "" ]--; + level.waypointusage[ team ][ wpstr ]--; - if ( level.waypointusage[ team ][ wp + "" ] <= 0 ) + if ( level.waypointusage[ team ][ wpstr ] <= 0 ) { - level.waypointusage[ team ][ wp + "" ] = undefined; + level.waypointusage[ team ][ wpstr ] = undefined; } } @@ -2726,7 +2725,7 @@ GetNearestWaypointWithSight( pos ) candidate = undefined; dist = 2147483647; - for ( i = 0; i < level.waypointcount; i++ ) + for ( i = level.waypoints.size - 1; i >= 0; i-- ) { if ( !bullettracepassed( pos + ( 0, 0, 15 ), level.waypoints[ i ].origin + ( 0, 0, 15 ), false, undefined ) ) { @@ -2755,7 +2754,7 @@ getNearestWaypoint( pos ) candidate = undefined; dist = 2147483647; - for ( i = 0; i < level.waypointcount; i++ ) + for ( i = level.waypoints.size - 1; i >= 0; i-- ) { curdis = distancesquared( level.waypoints[ i ].origin, pos ); @@ -2840,7 +2839,8 @@ AStarSearch( start, goal, team, greedy_path ) // pop bestnode from queue bestNode = open.data[ 0 ]; open HeapRemove(); - openset[ bestNode.index + "" ] = undefined; + bestNodeStr = bestNode.index + ""; + openset[ bestNodeStr ] = undefined; wp = level.waypoints[ bestNode.index ]; // check if we made it to the goal @@ -2850,14 +2850,16 @@ AStarSearch( start, goal, team, greedy_path ) while ( isdefined( bestNode ) ) { + bestNodeStr = bestNode.index + ""; + if ( isdefined( team ) && isdefined( level.waypointusage ) ) { - if ( !isdefined( level.waypointusage[ team ][ bestNode.index + "" ] ) ) + if ( !isdefined( level.waypointusage[ team ][ bestNodeStr ] ) ) { - level.waypointusage[ team ][ bestNode.index + "" ] = 0; + level.waypointusage[ team ][ bestNodeStr ] = 0; } - level.waypointusage[ team ][ bestNode.index + "" ]++; + level.waypointusage[ team ][ bestNodeStr ]++; } // construct path @@ -2873,6 +2875,7 @@ AStarSearch( start, goal, team, greedy_path ) for ( i = wp.children.size - 1; i >= 0; i-- ) { child = wp.children[ i ]; + childStr = child + ""; childWp = level.waypoints[ child ]; penalty = 1; @@ -2881,9 +2884,9 @@ AStarSearch( start, goal, team, greedy_path ) { temppen = 1; - if ( isdefined( level.waypointusage[ team ][ child + "" ] ) ) + if ( isdefined( level.waypointusage[ team ][ childStr ] ) ) { - temppen = level.waypointusage[ team ][ child + "" ]; // consider how many bots are taking this path + temppen = level.waypointusage[ team ][ childStr ]; // consider how many bots are taking this path } if ( temppen > 1 ) @@ -2902,16 +2905,16 @@ AStarSearch( start, goal, team, greedy_path ) newg = bestNode.g + distancesquared( wp.origin, childWp.origin ) * penalty; // bots on same team's path are more expensive // check if this child is in open or close with a g value less than newg - inopen = isdefined( openset[ child + "" ] ); + inopen = isdefined( openset[ childStr ] ); - if ( inopen && openset[ child + "" ].g <= newg ) + if ( inopen && openset[ childStr ].g <= newg ) { continue; } - inclosed = isdefined( closed[ child + "" ] ); + inclosed = isdefined( closed[ childStr ] ); - if ( inclosed && closed[ child + "" ].g <= newg ) + if ( inclosed && closed[ childStr ].g <= newg ) { continue; } @@ -2920,11 +2923,11 @@ AStarSearch( start, goal, team, greedy_path ) if ( inopen ) { - node = openset[ child + "" ]; + node = openset[ childStr ]; } else if ( inclosed ) { - node = closed[ child + "" ]; + node = closed[ childStr ]; } else { @@ -2940,19 +2943,19 @@ AStarSearch( start, goal, team, greedy_path ) // check if in closed, remove it if ( inclosed ) { - closed[ child + "" ] = undefined; + closed[ childStr ] = undefined; } // check if not in open, add it if ( !inopen ) { open HeapInsert( node ); - openset[ child + "" ] = node; + openset[ childStr ] = node; } } // done with children, push onto closed - closed[ bestNode.index + "" ] = bestNode; + closed[ bestNodeStr ] = bestNode; } return []; diff --git a/maps/mp/bots/_wp_editor.gsc b/maps/mp/bots/_wp_editor.gsc index 3463035..845fb3d 100644 --- a/maps/mp/bots/_wp_editor.gsc +++ b/maps/mp/bots/_wp_editor.gsc @@ -461,6 +461,7 @@ LoadWaypoints() self deleteAllWaypoints(); self iprintlnbold( "Loading WPS..." ); load_waypoints(); + level.waypointcount = level.waypoints.size; wait 1;