From 23a64c5e1c3e6e6a687eb2129d71245293d25567 Mon Sep 17 00:00:00 2001 From: JezuzLizard Date: Sat, 29 Apr 2023 17:18:24 -0700 Subject: [PATCH] Clean up code, and add prototypes for objectives. --- scripts/sp/T4ZM_zbots_main.gsc | 21 ++++---- scripts/sp/bots/actions/objective.gsc | 27 ++++++---- scripts/sp/bots/bot_actions_common.gsc | 12 ++--- scripts/sp/bots/bot_objective_common.gsc | 22 ++++++++ scripts/sp/bots/bot_target_common.gsc | 65 +----------------------- 5 files changed, 54 insertions(+), 93 deletions(-) diff --git a/scripts/sp/T4ZM_zbots_main.gsc b/scripts/sp/T4ZM_zbots_main.gsc index 38983a5..80a9b5d 100644 --- a/scripts/sp/T4ZM_zbots_main.gsc +++ b/scripts/sp/T4ZM_zbots_main.gsc @@ -495,8 +495,8 @@ spawn_bots() bot.action_queue[ "combat" ] = []; bot.action_queue[ "movement" ] = []; bot.action_queue[ "look" ] = []; - //bot register_action_queue_actions(); - //bot thread bot_think(); + bot register_action_queue_actions(); + bot thread bot_think(); bot_count++; } } @@ -521,19 +521,19 @@ bot_think() } } - group_name = "movement"; + //group_name = "movement"; - self bot_action_think( group_name ); + //self bot_action_think( group_name ); - group_name = "look"; + //group_name = "look"; - self bot_action_think( group_name ); + //self bot_action_think( group_name ); - group_name = "combat"; + //group_name = "combat"; //self scripts\sp\bots\bot_target_common::bot_pick_target(); - self bot_action_think( group_name ); + //self bot_action_think( group_name ); group_name = "objective"; @@ -558,7 +558,7 @@ watch_debris_objectives( zombie_debris ) for ( debris_opened_count = 0; debris_opened_count < zombie_debris.size; debris_opened_count++ ) { - level waittill( "door_opened", debris, player ); + level waittill( "debris_opened", debris, player ); free_bot_objective( "door", debris.id ); } } @@ -587,6 +587,8 @@ store_powerups_dropped() { level endon( "end_game" ); + level thread free_powerups_dropped(); + level.zbots_powerups = []; level.zbots_powerups_targeted_for_grab = []; id = 0; @@ -599,6 +601,7 @@ store_powerups_dropped() } powerup.id = id; add_possible_bot_objective( "powerup", id, true, powerup ); + level thread objective_think( "powerup", id ); scripts\sp\bots\bot_utility::assign_priority_to_powerup( powerup ); level.zbots_powerups = scripts\sp\bots\bot_utility::sort_array_by_priority_field( level.zbots_powerups, powerup ); id++; diff --git a/scripts/sp/bots/actions/objective.gsc b/scripts/sp/bots/actions/objective.gsc index 4aef244..f205daa 100644 --- a/scripts/sp/bots/actions/objective.gsc +++ b/scripts/sp/bots/actions/objective.gsc @@ -758,13 +758,18 @@ bot_part_priority() bot_grab_powerup() { + self endon( "powerup_end_think" ); + if ( !isDefined( self.available_powerups ) || self.available_powerups.size <= 0 ) { return; } set_bot_global_shared_objective_owner_by_reference( "powerup", self.available_powerups[ 0 ], self ); - self.target_pos = self.available_powerups[ 0 ].target_ent.origin; - self.should_try_to_move_to_objective = true; + while ( true ) + { + self SetScriptGoal( self.available_powerups[ 0 ].target_ent.origin ); + wait 0.05; + } } bot_powerup_process_order() @@ -774,7 +779,7 @@ bot_powerup_process_order() bot_should_grab_powerup() { - if ( !isDefined( level.zbot_objective_glob[ "powerup" ] ) || !isDefined( level.zbot_objective_glob[ "powerup" ].active_objectives ) || level.zbot_objective_glob[ "powerup" ].active_objectives.size <= 0 ) + if ( level.zbot_objective_glob[ "powerup" ].active_objectives.size <= 0 ) { return false; } @@ -786,30 +791,30 @@ bot_should_grab_powerup() obj_keys = getArrayKeys( powerup_objectives ); for ( i = 0; i < powerup_objectives.size; i++ ) { - if ( isDefined( powerup_objectives[ obj_keys[ i ] ].owner ) ) + obj = powerup_objectives[ obj_keys[ i ] ]; + powerup = obj.target_ent; + if ( isDefined( obj.owner ) ) { continue; } - time_left = powerup_objectives[ obj_keys[ i ] ].target_ent.time_left_until_timeout; - distance_required_to_reach_powerup = distanceSquared( powerup_objectives[ obj_keys[ i ] ].target_ent.origin, self.origin ); + time_left = powerup.time_left_until_timeout; + distance_required_to_reach_powerup = distanceSquared( powerup.origin, self.origin ); if ( distance_required_to_reach_powerup > BOT_SPEED_WHILE_SPRINTING_SQ * time_left ) { continue; } - if ( distanceSquared( powerup_objectives[ obj_keys[ i ] ].target_ent.origin, self.origin ) > MAX_DISTANCE_SQ ) + if ( distanceSquared( powerup.origin, self.origin ) > MAX_DISTANCE_SQ ) { continue; } - if ( !findPath( self.origin, powerup_objectives[ obj_keys[ i ] ].target_ent.origin ) ) + if ( !isDefined( generatePath( self.origin, powerup.origin, self.team, false ) ) ) { continue; } - self.available_powerups[ self.available_powerups.size ] = powerup_objectives[ obj_keys[ i ] ]; + self.available_powerups[ self.available_powerups.size ] = obj; } //TODO: Sort powerups by priority here - time_left = undefined; - distance_required_to_reach_powerup = undefined; return self.available_powerups.size > 0; } diff --git a/scripts/sp/bots/bot_actions_common.gsc b/scripts/sp/bots/bot_actions_common.gsc index 536489e..2ccb49f 100644 --- a/scripts/sp/bots/bot_actions_common.gsc +++ b/scripts/sp/bots/bot_actions_common.gsc @@ -90,14 +90,6 @@ wait_for_action_completion( group_name, action_name ) level endon( "end_game" ); result = self waittill_any_return( action_name + "_complete", action_name + "_cancel", action_name + "_postpone" ); - if ( !isDefined( result ) ) - { - return; - } - if ( result == "disconnect" ) - { - return; - } if ( ( result == action_name + "_complete" ) ) { self.zbot_actions_in_queue[ group_name ][ action_name ].postponed = false; @@ -108,7 +100,7 @@ wait_for_action_completion( group_name, action_name ) } else if ( result == action_name + "_cancel" ) { - self.zbot_actions_in_queue[ group_name ][ action_name].postponed = false; + self.zbot_actions_in_queue[ group_name ][ action_name ].postponed = false; self.zbot_actions_in_queue[ group_name ][ action_name ].queued = false; self.zbot_actions_in_queue[ group_name ][ action_name ].completed = false; self.action_queue[ group_name ][ 0 ] = undefined; @@ -124,6 +116,8 @@ wait_for_action_completion( group_name, action_name ) self thread [[ self.action_queue[ group_name ][ 0 ].on_postpone_func ]](); } + self notify( action_name + "_end_think" ); + self.zbot_actions_in_queue[ group_name ][ action_name ].is_current = false; } diff --git a/scripts/sp/bots/bot_objective_common.gsc b/scripts/sp/bots/bot_objective_common.gsc index 973ee49..eb3d89e 100644 --- a/scripts/sp/bots/bot_objective_common.gsc +++ b/scripts/sp/bots/bot_objective_common.gsc @@ -182,4 +182,26 @@ free_bot_objective( objective_group, id ) } objective = undefined; +} + +objective_think( objective_group, id ) +{ + active_objectives = level.zbot_global_shared_objective_glob[ objective_group ].active_objectives; + + objective = active_objectives[ "obj_id_" + id ]; + + objective_exists = isDefined( objective ); + assert( objective_exists, "Objective with " + id + " id number does not point to a objective in group " + objective_group ); + if ( !objective_exists ) + { + return; + } + + level endon( "end_obj_think_" + objective.target_ent getEntityNumber() ); + + while ( true ) + { + if ( ) + wait 0.05; + } } \ No newline at end of file diff --git a/scripts/sp/bots/bot_target_common.gsc b/scripts/sp/bots/bot_target_common.gsc index a88baf5..3affad1 100644 --- a/scripts/sp/bots/bot_target_common.gsc +++ b/scripts/sp/bots/bot_target_common.gsc @@ -191,67 +191,4 @@ free_bot_target( target_group, id ) target.targeted_by = undefined; target = undefined; -} - -/* - The main target thread, will update the bot's main target. Will auto target enemy players and handle script targets. -*/ -/* -bot_pick_target() -{ - myEye = self GetEyePos(); - myAngles = self GetPlayerAngles(); - myFov = 90; - hasTarget = self bot_has_target(); - adsAmount = self PlayerADS(); - adsFovFact = 1; - - // reduce fov if ads'ing - if ( adsAmount > 0 ) - { - myFov *= 1 - adsFovFact * adsAmount; - } - - groups = get_all_groups_for_targets(); - - ents = []; - for ( i = 0; i < groups.size; i++ ) - { - targets = level.zbot_target_glob[ groups[ i ] ].active_targets; - for ( j = 0; j < targets; j++ ) - { - ents[ ents.size ] = targets[ j ].target_ent; - } - } - - ents = get_array_of_closest( self.origin, ents ); - - for ( i = 0; i < ents.size; i++ ) - { - ent = ents[ i ]; - targetHead = ent getTagOrigin( "j_head" ); - targetAnkleLeft = ent getTagOrigin( "j_ankle_le" ); - targetAnkleRight = ent getTagOrigin( "j_ankle_ri" ); - - traceHead = bulletTrace( myEye, targetHead, false, undefined ); - traceAnkleLeft = bulletTrace( myEye, targetAnkleLeft, false, undefined ); - traceAnkleRight = bulletTrace( myEye, targetAnkleRight, false, undefined ); - - canTargetEnt = ( ( sightTracePassed( myEye, targetHead, false, undefined ) || - sightTracePassed( myEye, targetAnkleLeft, false, undefined ) || - sightTracePassed( myEye, targetAnkleRight, false, undefined ) ) - - && ( traceHead["fraction"] >= 1.0 || - traceAnkleLeft["fraction"] >= 1.0 || - traceAnkleRight["fraction"] >= 1.0 ) - - && ( getConeDot( ent.origin, self.origin, myAngles ) >= myFov || - ( isObjDef && obj.trace_time ) ) ); - if ( canTargetEnt ) - { - self set_target_for_bot( ent.targetname, ent.target_id ); - break; - } - } -} -*/ \ No newline at end of file +} \ No newline at end of file