Progress 2.

This commit is contained in:
JezuzLizard 2023-07-09 17:57:55 -07:00
parent 845b377eff
commit 8343d597c7
6 changed files with 442 additions and 435 deletions

View File

@ -822,6 +822,11 @@ ReverseHeap( item, item2 )
return item < item2;
}
HeapPriority( item, item2 )
{
return item.priority > item2.priority;
}
/*
A heap invarient comparitor, used for traces. Wanting the trace with the largest length first in the heap.
*/

View File

@ -12,14 +12,10 @@ bot_post_think_common( state )
case "completed":
self bot_objective_print( obj.group, obj.id, "Bot <" + self.playername + "> objective was completed", "bot_post_think_common" );
break;
case "postponed":
self bot_objective_print( obj.group, obj.id, "Bot <" + self.playername + "> objective was postponed Reason: " + self.obj_postponed_reason, "bot_post_think_common" );
break;
case "canceled":
self bot_objective_print( obj.group, obj.id, "Bot <" + self.playername + "> objective was canceled Reason: " + self.obj_cancel_reason, "bot_post_think_common" );
break;
}
self.obj_postponed_reason = "";
self.obj_cancel_reason = "";
self thread ClearScriptGoal();
self ClearScriptAimPos();
@ -43,57 +39,50 @@ bot_grab_powerup()
self bot_set_objective( "powerup", powerup_obj_ent );
self bot_set_objective_owner( "powerup", powerup_obj_ent );
self bot_objective_print( "powerup", powerup_obj.id, "Bot <" + self.playername + "> starts objective", "bot_grab_powerup" );
while ( true )
self bot_objective_print( "powerup", powerup_obj.id, "Bot <" + self.playername + "> Attempting to grab powerup", "bot_grab_powerup" );
self SetPriorityObjective();
self SetScriptGoal( powerup_obj_ent.origin );
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( result != "goal" )
{
wait 1;
self SetPriorityObjective();
self SetScriptGoal( powerup_obj_ent.origin );
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( result != "goal" )
self.obj_cancel_reason = "Bad path/new goal";
self notify( "powerup_cancel" );
return;
}
//Wait to see if the bot was able to grab the powerup
wait 0.5;
//Check if powerup still exists
if ( isDefined( powerup_obj_ent ) )
{
height_difference = powerup_obj_ent.origin[ 2 ] - self.origin[ 2 ];
if ( height_difference > 0 && height_difference < 39 )
{
self bot_objective_print( "powerup", powerup_obj.id, "Bot <" + self.playername + "> bad path", "bot_grab_powerup" );
continue;
}
//Wait to see if the bot was able to grab the powerup
wait 0.5;
//Check if powerup still exists
if ( isDefined( powerup_obj_ent ) )
{
height_difference = powerup_obj_ent.origin[ 2 ] - self.origin[ 2 ];
if ( height_difference > 0 && height_difference < 49 )
{
self BotJump();
wait 0.5;
waittillframeend;
//Check if bot was able to grab the powerup by jumping
if ( self bot_has_objective() || isDefined( powerup_obj_ent ) )
{
//Mark objective as bad so bots will ignore it from now on
powerup_obj.bad = true;
}
}
else
self BotJump();
wait 0.5;
waittillframeend;
//Check if bot was able to grab the powerup by jumping
if ( isDefined( powerup_obj_ent ) )
{
//Mark objective as bad so bots will ignore it from now on
powerup_obj.bad = true;
}
}
else
{
powerup_obj.bad = true;
}
if ( powerup_obj.bad )
{
self bot_objective_print( "powerup", powerup_obj.id, "Bot <" + self.playername + "> objective was marked as bad", "bot_grab_powerup" );
break;
}
if ( powerup_obj.bad )
{
self.obj_cancel_reason = "Obj was marked as bad";
self notify( "powerup_cancel" );
return;
}
}
}
bot_powerup_process_order()
{
return 0;
}
bot_powerup_init()
{
self.successfully_grabbed_powerup = false;
@ -143,7 +132,7 @@ bot_should_grab_powerup()
{
continue;
}
if ( !isDefined( generatePath( self.origin, powerup.origin, self.team, level.bot_allowed_negotiation_links ) ) )
if ( self GetPathIsInaccessible( powerup.origin ) )
{
continue;
}
@ -172,19 +161,9 @@ bot_powerup_should_cancel()
return goal_canceled;
}
bot_powerup_should_postpone()
{
return false;
}
bot_powerup_priority()
{
if ( !isDefined( self.available_powerups ) )
{
return 0;
}
//return self.available_powerups[ 0 ].target_ent.priority;
return 0;
return 3;
}
//TODO: Possibly add the ability to circle revive?
@ -204,55 +183,57 @@ bot_revive_player()
player_to_revive = player_to_revive_obj.target_ent;
self bot_set_objective( "revive", player_to_revive );
self bot_set_objective_owner( "revive", player_to_revive );
self bot_objective_print( "revive", player_to_revive_obj.id, "Bot <" + self.playername + "> objective started", "bot_revive_player" );
//If player is no longer valid to revive stop trying to revive
//If bot doesn't have an objective anymore or the objective has changed stop trying to revive
while ( true )
self bot_objective_print( "revive", player_to_revive_obj.id, "Bot <" + self.playername + "> Attempting to revive " + player_to_revive.playername, "bot_revive_player" );
//Constantly update the goal just in case the player is moving(T5 or higher only)
self ClearScriptAimPos();
self SetPriorityObjective();
self SetScriptGoal( player_to_revive.origin, 32 );
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( result != "goal" )
{
wait 1;
//Constantly update the goal just in case the player is moving(T5 or higher only)
self ClearScriptAimPos();
self SetPriorityObjective();
self SetScriptGoal( player_to_revive.origin, 32 );
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( result != "goal" )
{
self bot_objective_print( "revive", player_to_revive_obj.id, "Bot <" + self.playername + "> bad path", "bot_revive_player" );
continue;
}
if ( !isDefined( player_to_revive.revivetrigger ) )
{
continue;
}
//Check if the bot is reviving the player already and also that the player isn't being revived already
if ( player_to_revive.revivetrigger.beingrevived )
{
continue;
}
self SetScriptAimPos( player_to_revive.origin );
time = 3.2;
if ( self hasPerk( "specialty_quickrevive" ) )
{
time /= 2;
}
self thread BotPressUse( time );
while ( self maps\_laststand::is_reviving( player_to_revive ) )
{
wait 0.05;
}
//Wait to see if we cleared the objective by successfully reviving the player
waittillframeend;
self.obj_cancel_reason = "Bad path/new goal";
self notify( "revive_cancel" );
return;
}
if ( !isDefined( player_to_revive.revivetrigger ) )
{
self.obj_cancel_reason = "No revive trigger";
self notify( "revive_cancel" );
return;
}
//Check if the bot is reviving the player already and also that the player isn't being revived already
if ( player_to_revive.revivetrigger.beingrevived )
{
self.obj_cancel_reason = "Player is already being revived";
self notify( "revive_cancel" );
return;
}
self SetScriptAimPos( player_to_revive.origin );
time = 3.2;
if ( self hasPerk( "specialty_quickrevive" ) )
{
time /= 2;
}
self thread BotPressUse( time );
self thread knocked_off_revive_watcher();
}
bot_revive_process_order()
knocked_off_revive_watcher( revivee )
{
return 0;
while ( self maps\_laststand::is_reviving( revivee ) )
{
wait 0.05;
}
if ( isDefined( revivee.revivetrigger ) )
{
self.obj_cancel_reason = "Knocked off revive";
self notify( "revive_cancel" );
}
}
bot_revive_player_init()
@ -280,6 +261,11 @@ bot_should_revive_player()
for ( i = 0; i < downed_players_objs.size; i++ )
{
obj = downed_players_objs[ obj_keys[ i ] ];
player = obj.target_ent;
if ( player == self )
{
continue;
}
if ( isDefined( obj.owner ) )
{
continue;
@ -288,7 +274,7 @@ bot_should_revive_player()
{
continue;
}
if ( !isDefined( generatePath( self.origin, obj.target_ent.origin, self.team, level.bot_allowed_negotiation_links ) ) )
if ( self GetPathIsInaccessible( player.origin ) )
{
continue;
}
@ -320,14 +306,9 @@ bot_revive_player_should_cancel()
return goal_canceled;
}
bot_revive_player_should_postpone()
{
return false;
}
bot_revive_player_priority()
{
return 0;
return 2;
}
bot_magicbox_purchase()
@ -345,77 +326,75 @@ bot_magicbox_purchase()
magicbox = magicbox_obj.target_ent;
self bot_set_objective( "magicbox", magicbox );
self bot_set_objective_owner( "magicbox", magicbox );
self bot_objective_print( "magicbox", magicbox_obj.id, "Bot <" + self.playername + "> objective started", "bot_magicbox_purchase" );
//self bot_set_objective_owner( "magicbox", magicbox );
self bot_objective_print( "magicbox", magicbox_obj.id, "Bot <" + self.playername + "> Attempting to purchase magicbox", "bot_magicbox_purchase" );
magicbox_obj.magicbox_weapon_spawn_time = undefined;
magicbox_obj.magicbox_weapon_string = undefined;
while ( true )
lookat_org = magicbox.origin + ( 0, 0, 35 );
goal_org = magicbox.bot_use_node;
self ClearScriptAimPos();
self SetScriptGoal( goal_org, 32 );
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( result != "goal" )
{
wait 1;
self ClearScriptAimPos();
self SetPriorityObjective();
self SetScriptGoal( magicbox.bot_use_node, 32 );
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( result != "goal" )
{
self bot_objective_print( "magicbox", magicbox_obj.id, "Bot <" + self.playername + "> bad path", "bot_magicbox_purchase" );
continue;
}
self SetScriptAimPos( magicbox.origin );
self thread BotPressUse( 0.1 );
wait 0.1;
waittillframeend;
if ( !magicbox._box_open )
{
self bot_objective_print( "magicbox", magicbox_obj.id, "Bot <" + self.playername + "> magicbox didn't open", "bot_magicbox_purchase" );
continue;
}
// self ClearScriptGoal();
// self ClearScriptAimPos();
// self ClearPriorityObjective();
break;
self.obj_cancel_reason = "Bad path/new goal";
self notify( "magicbox_cancel" );
return;
}
while ( !isDefined( magicbox.weapon_spawn_org ) )
self SetScriptAimPos( lookat_org );
wait randomFloatRange( 0.5, 1.5 );
self thread BotPressUse( 0.2 );
wait 0.75;
waittillframeend;
//self ClearScriptAimPos();
//self ClearScriptGoal();
if ( !magicbox._box_open )
{
wait 0.05;
self.obj_cancel_reason = "Failed to open";
self notify( "magicbox_cancel" );
return;
}
if ( !isDefined( magicbox.weapon_spawn_org ) )
{
self.obj_cancel_reason = "No weapon spawn org";
self notify( "magicbox_cancel" );
return;
}
magicbox.weapon_spawn_org waittill( "randomization_done" );
self bot_objective_print( "magicbox", magicbox_obj.id, "Bot <" + self.playername + "> randomization_done", "bot_magicbox_purchase" );
magicbox_obj.magicbox_weapon_spawn_time = getTime();
magicbox_obj.magicbox_weapon_string = magicbox.weapon_string;
//Pickup logic
while ( true )
if ( self bot_should_reject_magicbox_weapon( magicbox.weapon_string ) )
{
wait 1;
self ClearScriptAimPos();
self SetPriorityObjective();
self SetScriptGoal( magicbox.bot_use_node, 32 );
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( result != "goal" )
{
self bot_objective_print( "magicbox", magicbox_obj.id, "Bot <" + self.playername + "> bad path on pickup", "bot_magicbox_purchase" );
continue;
}
self SetScriptAimPos( magicbox.origin );
self thread BotPressUse( 0.1 );
wait 0.1;
waittillframeend;
self.obj_cancel_reason = "Rejected magicbox weapon: " + magicbox.weapon_string;
self notify( "magicbox_cancel" );
return;
}
}
bot_magicbox_purchase_process_order()
{
return 0;
self ClearScriptAimPos();
self SetPriorityObjective();
self SetScriptGoal( goal_org, 32 );
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( result != "goal" )
{
self.obj_cancel_reason = "Bad path/new goal on pickup";
self notify( "magicbox_cancel" );
return;
}
self SetScriptAimPos( lookat_org );
wait randomFloatRange( 0.5, 1.5 );
self thread BotPressUse( 0.2 );
}
bot_magicbox_purchase_init()
@ -456,12 +435,17 @@ bot_should_purchase_magicbox()
self bot_objective_print( "magicbox", obj.id, "Bot <" + self.playername + "> not purchasing this magicbox box because it has an owner", "bot_should_purchase_magicbox" );
continue;
}
if ( isDefined( magicbox.chest_user ) )
{
self bot_objective_print( "magicbox", obj.id, "Bot <" + self.playername + "> not purchasing this magicbox box because it has a user", "bot_should_purchase_magicbox" );
continue;
}
if ( self.score < magicbox.zombie_cost )
{
self bot_objective_print( "magicbox", obj.id, "Bot <" + self.playername + "> not purchasing this magicbox box because it is unaffordable", "bot_should_purchase_magicbox" );
continue;
}
if ( !isDefined( generatePath( self.origin, magicbox.bot_use_node, self.team, level.bot_allowed_negotiation_links ) ) )
if ( self GetPathIsInaccessible( magicbox.bot_use_node ) )
{
self bot_objective_print( "magicbox", obj.id, "Bot <" + self.playername + "> not purchasing this magicbox box because it cannot be pathed to", "bot_should_purchase_magicbox" );
continue;
@ -486,17 +470,14 @@ bot_magicbox_purchase_should_cancel()
obj = self bot_get_objective();
goal_canceled = false;
/*
if ( !self bot_is_objective_owner( "magicbox", obj.target_ent ) )
{
self.obj_cancel_reason = "No longer the obj owner";
goal_canceled = true;
}
else if ( isDefined( obj.magicbox_weapon_string ) && self bot_should_reject_magicbox_weapon( obj ) )
{
self.obj_cancel_reason = "Rejected magicbox weapon: " + obj.magicbox_weapon_string;
goal_canceled = true;
}
else if ( isDefined( obj.magicbox_weapon_spawn_time ) && ( getTime() >= ( obj.magicbox_weapon_spawn_time + 12000 ) ) )
*/
if ( isDefined( obj.magicbox_weapon_spawn_time ) && ( getTime() >= ( obj.magicbox_weapon_spawn_time + 12000 ) ) )
{
self.obj_cancel_reason = "Weapon timed out";
goal_canceled = true;
@ -504,11 +485,6 @@ bot_magicbox_purchase_should_cancel()
return goal_canceled;
}
bot_magicbox_purchase_should_postpone()
{
return false;
}
bot_magicbox_purchase_priority()
{
/*
@ -529,4 +505,127 @@ bot_magicbox_purchase_priority()
return priority;
*/
return 0;
}
bot_perk_purchase()
{
if ( !isDefined( self.available_perks ) || self.available_perks.size <= 0 )
{
return;
}
self endon( "disconnect" );
self endon( "perk_end_think" );
level endon( "end_game" );
perk_obj = self.available_perks[ 0 ];
perk_ent = perk_obj.target_ent;
self bot_set_objective( "perk", perk_ent );
self bot_objective_print( "perk", perk_obj.id, "Bot <" + self.playername + "> Attempting to purchase " + perk_ent.script_noteworthy, "bot_perk_purchase" );
lookat_org = perk_ent.origin + ( 0, 0, 35 );
goal_org = perk_ent.bot_use_node;
self SetPriorityObjective();
self ClearScriptAimPos();
self SetScriptGoal( goal_org, 32 );
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( result != "goal" )
{
self.obj_cancel_reason = "Bad path/new goal";
self notify( "perk_cancel" );
return;
}
self SetScriptAimPos( lookat_org );
wait randomFloatRange( 0.5, 1.5 );
self thread BotPressUse( 0.2 );
}
bot_perk_purchase_init()
{
self.successfully_bought_perk = false;
}
bot_perk_purchase_post_think( state )
{
self bot_post_think_common( state );
self.successfully_bought_perk = false;
}
bot_should_purchase_perk()
{
perk_objs = get_all_objectives_for_group( "perk" );
if ( perk_objs.size <= 0 )
{
return false;
}
if ( isDefined( level.enable_magic ) && !level.enable_magic )
{
return false;
}
self.available_perks = [];
perk_objs_keys = getArrayKeys( perk_objs );
perk_objs_keys = array_randomize( perk_objs_keys );
for ( i = 0; i < perk_objs.size; i++ )
{
obj = perk_objs[ perk_objs_keys[ i ] ];
perk_ent = obj.target_ent;
perk = perk_ent.script_noteworthy;
if ( !level._custom_perks[ perk ].powered_on )
{
self bot_objective_print( "perk", obj.id, "Bot <" + self.playername + "> not purchasing " + perk + " because its not powered on", "bot_should_purchase_perk" );
continue;
}
if ( self hasPerk( perk ) )
{
self bot_objective_print( "perk", obj.id, "Bot <" + self.playername + "> not purchasing " + perk + " because we already have it", "bot_should_purchase_perk" );
continue;
}
if ( ( isDefined( self.is_drinking ) && self.is_drinking > 0 ) && self getCurrentWeapon() == level._custom_perks[ perk ].perk_bottle )
{
self bot_objective_print( "perk", obj.id, "Bot <" + self.playername + "> not purchasing " + perk + " because we are already drinking the perk we want", "bot_should_purchase_perk" );
continue;
}
if ( self.score < level._custom_perks[ perk ].cost )
{
self bot_objective_print( "perk", obj.id, "Bot <" + self.playername + "> not purchasing " + perk + " because we can't afford it", "bot_should_purchase_perk" );
continue;
}
if ( self GetPathIsInaccessible( perk_ent.bot_use_node ) )
{
self bot_objective_print( "perk", obj.id, "Bot <" + self.playername + "> not purchasing " + perk + " because it cannot be pathed to", "bot_should_purchase_perk" );
continue;
}
self.available_perks[ self.available_perks.size ] = obj;
}
return self.available_perks.size > 0;
}
bot_check_complete_perk_purchase()
{
return self.successfully_bought_perk;
}
bot_perk_purchase_should_cancel()
{
obj = self bot_get_objective();
goal_canceled = false;
perk = obj.target_ent.script_noteworthy;
if ( self hasPerk( perk ) )
{
self bot_objective_print( "perk", obj.id, "Bot <" + self.playername + "> not purchasing " + perk + " because we already have it", "bot_should_purchase_perk" );
goal_canceled = true;
}
return goal_canceled;
}
bot_perk_purchase_priority()
{
return 1;
}

View File

@ -325,137 +325,67 @@ bot_objective_history_get_previous()
/**********Action Section**********/
register_bot_action( group_name, action_name, action_func, action_process_order_func, init_func, post_think_func, should_do_func, check_if_complete_func, should_cancel_func, should_postpone_func, priority_func )
register_bot_action( action_name, action_func, init_func, post_think_func, should_do_func, check_if_complete_func, should_cancel_func, priority_func )
{
if ( !isDefined( level.zbots_actions ) )
{
level.zbots_actions = [];
}
if ( !isDefined( level.zbots_actions[ group_name ] ) )
if ( !isDefined( level.zbots_actions[ action_name ] ) )
{
level.zbots_actions[ group_name ] = [];
level.zbots_actions[ action_name ] = spawnStruct();
}
if ( !isDefined( level.zbots_actions[ group_name ][ action_name ] ) )
{
level.zbots_actions[ group_name ][ action_name ] = spawnStruct();
}
level.zbots_actions[ group_name ][ action_name ].action = action_func;
level.zbots_actions[ group_name ][ action_name ].init_func = init_func;
level.zbots_actions[ group_name ][ action_name ].post_think_func = post_think_func;
level.zbots_actions[ group_name ][ action_name ].should_do_func = should_do_func;
level.zbots_actions[ group_name ][ action_name ].action_process_order_func = action_process_order_func;
level.zbots_actions[ group_name ][ action_name ].check_if_complete_func = check_if_complete_func;
level.zbots_actions[ group_name ][ action_name ].should_cancel_func = should_cancel_func;
level.zbots_actions[ group_name ][ action_name ].should_postpone_func = should_postpone_func;
level.zbots_actions[ group_name ][ action_name ].priority_func = priority_func;
level.zbots_actions[ action_name ].action = action_func;
level.zbots_actions[ action_name ].init_func = init_func;
level.zbots_actions[ action_name ].post_think_func = post_think_func;
level.zbots_actions[ action_name ].should_do_func = should_do_func;
level.zbots_actions[ action_name ].check_if_complete_func = check_if_complete_func;
level.zbots_actions[ action_name ].should_cancel_func = should_cancel_func;
level.zbots_actions[ action_name ].priority_func = priority_func;
}
initialize_bot_actions_queue()
bot_process_action()
{
self.action_queue = [];
group_keys = getArrayKeys( level.zbots_actions );
for ( i = 0; i < group_keys.size; i++ )
{
self.action_queue[ group_keys[ i ] ] = [];
action_keys = getArrayKeys( level.zbots_actions[ group_keys[ i ] ] );
for ( j = 0; j < action_keys.size; j++ )
{
self register_bot_objective_action_for_queue( group_keys[ i ], action_keys[ j ] );
}
}
}
register_bot_objective_action_for_queue( group_name, action_name )
{
if ( !isDefined( self.zbot_actions_in_queue ) )
{
self.zbot_actions_in_queue = [];
}
if ( !isDefined( self.zbot_actions_in_queue[ group_name ] ) )
{
self.zbot_actions_in_queue[ group_name ] = [];
}
if ( !isDefined( self.zbot_actions_in_queue[ group_name ][ action_name ] ) )
{
self.zbot_actions_in_queue[ group_name ][ action_name ] = spawnStruct();
}
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 ].is_current = false;
}
process_next_queued_action( group_name )
{
if ( self.zbot_actions_in_queue[ group_name ][ self.action_queue[ group_name ][ 0 ].action_name ].is_current )
{
return;
}
self.action_queue[ group_name ] = self sort_array_by_priority_field( self.action_queue[ group_name ] );
action_name = self.action_queue[ group_name ][ 0 ].action_name;
self [[ level.zbots_actions[ group_name ][ action_name ].init_func ]]();
self thread [[ level.zbots_actions[ group_name ][ action_name ].action ]]();
self.zbot_actions_in_queue[ group_name ][ action_name ].is_current = true;
self thread wait_for_action_completion( group_name, action_name );
}
wait_for_action_completion( group_name, action_name )
{
self endon( "disconnect" );
self endon( "stop_action_think" );
level endon( "end_game" );
action_name = self.bot_action.action_name;
self [[ level.zbots_actions[ action_name ].init_func ]]();
self thread [[ level.zbots_actions[ action_name ].action ]]();
self.running_action = true;
self wait_for_action_completion( action_name );
}
wait_for_action_completion( action_name )
{
action_complete_name = action_name + "_complete";
action_cancel_name = action_name + "_cancel";
action_postpone_name = action_name + "_postpone";
result = self waittill_any_return( action_complete_name, action_cancel_name, action_postpone_name );
save_action = false;
end_state = undefined;
if ( ( result == action_complete_name ) )
{
self.zbot_actions_in_queue[ group_name ][ action_name ].postponed = false;
self.zbot_actions_in_queue[ group_name ][ action_name ].queued = false;
end_state = "completed";
}
else if ( result == action_cancel_name )
{
self.zbot_actions_in_queue[ group_name ][ action_name ].postponed = false;
self.zbot_actions_in_queue[ group_name ][ action_name ].queued = false;
end_state = "canceled";
}
else if ( result == action_postpone_name )
{
self.zbot_actions_in_queue[ group_name ][ action_name ].postponed = true;
save_action = true;
end_state = "postponed";
}
self.zbot_actions_in_queue[ group_name ][ action_name ].is_current = false;
self notify( action_name + "_end_think" );
self [[ level.zbots_actions[ group_name ][ action_name ].post_think_func ]]( end_state );
self [[ level.zbots_actions[ action_name ].post_think_func ]]( end_state );
if ( save_action )
{
postponed_action = self.action_queue[ group_name ][ 0 ];
postponed_action.priority = self [[ level.zbots_actions[ group_name ][ action_name ].priority_func ]]();
self.action_queue[ group_name ] = array_insert( self.action_queue[ group_name ], postponed_action, 2 );
self.action_queue[ group_name ][ 0 ] = undefined;
}
else
{
self.action_queue[ group_name ][ 0 ] = undefined;
}
self.bot_action = undefined;
self.obj_history[ self.bot_obj_history_index ].end_time = getTime();
end_time = self.obj_history[ self.bot_obj_history_index ].end_time;
@ -463,88 +393,52 @@ wait_for_action_completion( group_name, action_name )
self.obj_history[ self.bot_obj_history_index ].time_spent = end_time - start_time;
self.obj_history[ self.bot_obj_history_index ].bot_end_pos = self.origin;
self.bot_obj_history_index++;
self.running_action = false;
}
pick_actions_to_add_to_queue( group_name )
bot_pick_action()
{
action_keys = getArrayKeys( level.zbots_actions[ group_name ] );
//TODO: Use process order funcs to determine the order of actions being added to the queue
//For now just randomize the order of the keys
/*
for ( i = 0; i < action_keys; i++ )
{
}
*/
//Reboot the action queue because the last member was deleted which deletes the array
if ( !isDefined( self.action_queue ) || !isDefined( self.action_queue[ group_name ] ) )
{
self.action_queue = [];
self.action_queue[ group_name ] = [];
}
if ( !isDefined( self.action_id ) )
{
self.action_id = 0;
}
action_keys = getArrayKeys( level.zbots_actions );
possible_actions = NewHeap( ::HeapPriority );
for ( i = 0; i < action_keys.size; i++ )
{
if ( !self.zbot_actions_in_queue[ group_name ][ action_keys[ i ] ].queued && [[ level.zbots_actions[ group_name ][ action_keys[ i ] ].should_do_func ]]() )
if ( self [[ level.zbots_actions[ action_keys[ i ] ].should_do_func ]]() )
{
self.action_queue[ group_name ][ self.action_queue[ group_name ].size ] = spawnStruct();
self.action_queue[ group_name ][ self.action_queue[ group_name ].size - 1 ].action_name = action_keys[ i ];
self.action_queue[ group_name ][ self.action_queue[ group_name ].size - 1 ].action_id = self.action_id;
self.action_queue[ group_name ][ self.action_queue[ group_name ].size - 1 ].priority = self [[ level.zbots_actions[ group_name ][ action_keys[ i ] ].priority_func ]]();
self.zbot_actions_in_queue[ group_name ][ action_keys[ i ] ].queued = true;
self.action_id++;
possible_action = spawnStruct();
possible_action.action_name = action_keys[ i ];
possible_action.priority = self [[ level.zbots_actions[ action_keys[ i ] ].priority_func ]]();
possible_actions HeapInsert( possible_action );
printConsole( "Adding action " + action_keys[ i ] + " to queue of size: " + possible_actions.data.size );
}
}
}
bot_clear_actions_queue()
{
group_keys = getArrayKeys( level.zbots_actions );
for ( i = 0; i < group_keys.size; i++ )
if ( !isDefined( possible_actions.data ) || possible_actions.data.size <= 0 )
{
self.action_queue[ group_keys[ i ] ] = [];
action_keys = getArrayKeys( level.zbots_actions[ group_keys[ i ] ] );
for ( j = 0; j < action_keys.size; j++ )
{
self register_bot_objective_action_for_queue( group_keys[ i ], action_keys[ j ] );
}
}
return false;
}
self.bot_action = possible_actions.data[ 0 ];
printConsole( "Picking action " + self.bot_action.action_name + " Priority " + self.bot_action.priority );
return true;
}
check_if_action_is_completed_in_group( group_name, action_name )
bot_check_action_complete( action_name )
{
assert( isDefined( level.zbots_actions[ group_name ][ action_name ].check_if_complete_func ) );
assert( isDefined( level.zbots_actions[ action_name ].check_if_complete_func ) );
is_complete = self [[ level.zbots_actions[ group_name ][ action_name ].check_if_complete_func ]]();
is_complete = self [[ level.zbots_actions[ action_name ].check_if_complete_func ]]();
if ( is_complete )
{
self notify( action_name + "_complete" );
self notify( "goal" );
}
return is_complete;
}
check_if_action_should_be_postponed_in_group( group_name, action_name )
bot_check_if_action_should_be_canceled_in_group( action_name )
{
should_postpone = self [[ level.zbots_actions[ group_name ][ action_name ].should_postpone_func ]]();
if ( should_postpone )
{
self notify( action_name + "_postpone" );
self notify( "goal" );
}
return should_postpone;
}
check_if_action_should_be_canceled_in_group( group_name, action_name )
{
should_cancel = self [[ level.zbots_actions[ group_name ][ action_name ].should_cancel_func ]]();
should_cancel = self [[ level.zbots_actions[ action_name ].should_cancel_func ]]();
if ( should_cancel )
{
self notify( action_name + "_cancel" );
@ -554,20 +448,9 @@ check_if_action_should_be_canceled_in_group( group_name, action_name )
return should_cancel;
}
check_if_action_should_be_postponed_globally( group_name, action_name )
bot_check_if_action_should_be_canceled_globally( action_name )
{
should_postpone = self action_should_be_postponed_global( group_name, action_name );
if ( should_postpone )
{
self notify( action_name + "_postpone" );
self notify( "goal" );
}
return should_postpone;
}
check_if_action_should_be_canceled_globally( group_name, action_name )
{
should_cancel = self action_should_be_canceled_global( group_name, action_name );
should_cancel = self action_should_be_canceled_global( action_name );
if ( should_cancel )
{
self notify( action_name + "_cancel" );
@ -576,30 +459,13 @@ check_if_action_should_be_canceled_globally( group_name, action_name )
return should_cancel;
}
//TODO: Figure out way of overriding the current action for flee movement action
check_for_forced_action( group_name )
{
action_keys = getArrayKeys( level.zbots_actions[ group_name ] );
action_priorities_array = [];
for ( i = 0; i < action_keys.size; i++ )
{
action_priorities_array[ action_priorities_array.size ] = spawnStruct();
action_priorities_array[ action_priorities_array.size - 1 ].priority = self [[ level.zbots_actions[ group_name ][ action_keys[ i ] ].priority_func ]]();
action_priorities_array[ action_priorities_array.size - 1 ].action_name = action_keys[ i ];
}
action_priorities_array = sort_array_by_priority_field( action_priorities_array );
if ( self.action_queue[ group_name ][ 0 ].priority < action_priorities_array[ 0 ].priority )
{
self notify( self.action_queue[ group_name ][ 0 ].action_name + "_cancel" );
}
}
bot_action_think()
{
self endon( "disconnect" );
self endon( "zombified" );
level endon( "end_game" );
self thread bot_action_pump();
while ( true )
{
@ -609,65 +475,65 @@ bot_action_think()
}
else
{
wait 0.05;
wait 1;
}
//Wait until the end of the frame so any variables set by _bot_internal in the current frame will have up to date values
waittillframeend;
if ( !maps\so\zm_common\_zm_utility::is_player_valid( self ) )
self.bot_action = undefined;
if ( !self bot_pick_action() )
{
if ( getDvarInt( "bot_obj_debug_all" ) != 0 )
{
printConsole( "BOT_ACTION_THINK: " + self.playername + " does not have an action selected" );
}
continue;
}
self bot_process_action();
group_name = "objective";
self pick_actions_to_add_to_queue( group_name );
//self check_for_forced_action( group_name );
if ( !isDefined( self.action_queue[ group_name ][ 0 ] ) )
while ( !maps\so\zm_common\_zm_utility::is_player_valid( self ) )
{
continue;
}
self process_next_queued_action( group_name );
action_name = self.action_queue[ group_name ][ 0 ].action_name;
if ( self check_if_action_is_completed_in_group( group_name, action_name ) )
{
wait 0.1;
continue;
}
if ( self check_if_action_should_be_postponed_globally( group_name, action_name ) )
{
wait 0.1;
continue;
}
if ( self check_if_action_should_be_canceled_globally( group_name, action_name ) )
{
wait 0.1;
continue;
}
if ( self check_if_action_should_be_postponed_in_group( group_name, action_name ) )
{
wait 0.1;
continue;
}
if ( self check_if_action_should_be_canceled_in_group( group_name, action_name ) )
{
wait 0.1;
continue;
if ( getDvarInt( "bot_obj_debug_all" ) != 0 )
{
printConsole( "BOT_ACTION_THINK: " + self.playername + " is not in a valid state" );
}
wait 1;
}
}
}
action_should_be_postponed_global( primary_group_name, action_name )
bot_action_pump()
{
self endon( "disconnect" );
self endon( "zombified" );
level endon( "end_game" );
while ( true )
{
wait 0.05;
if ( !isDefined( self.bot_action ) )
{
continue;
}
action_name = self.bot_action.action_name;
self bot_check_action_complete( action_name );
self bot_check_if_action_should_be_canceled_globally( action_name );
self bot_check_if_action_should_be_canceled_in_group( action_name );
while ( !maps\so\zm_common\_zm_utility::is_player_valid( self ) )
{
wait 1;
}
}
}
action_should_be_postponed_global( action_name )
{
return false;
}
action_should_be_canceled_global( primary_group_name, action_name )
action_should_be_canceled_global( action_name )
{
obj = self bot_get_objective();

View File

@ -9,35 +9,41 @@ init()
{
//maps\bots\script_objectives\_obj_common;
//maps\bots\script_objectives\_obj_actions;
register_bot_action( "objective", "powerup", ::bot_grab_powerup,
::bot_powerup_process_order,
register_bot_action( "powerup",
::bot_grab_powerup,
::bot_powerup_init,
::bot_powerup_post_think,
::bot_should_grab_powerup,
::bot_check_complete_grab_powerup,
::bot_powerup_should_cancel,
::bot_powerup_should_postpone,
::bot_powerup_priority );
register_bot_action( "objective", "revive", ::bot_revive_player,
::bot_revive_process_order,
register_bot_action( "revive",
::bot_revive_player,
::bot_revive_player_init,
::bot_revive_player_post_think,
::bot_should_revive_player,
::bot_check_complete_revive_player,
::bot_revive_player_should_cancel,
::bot_revive_player_should_postpone,
::bot_revive_player_priority );
register_bot_action( "objective", "magicbox", ::bot_magicbox_purchase,
::bot_magicbox_purchase_process_order,
register_bot_action( "magicbox",
::bot_magicbox_purchase,
::bot_magicbox_purchase_init,
::bot_magicbox_purchase_post_think,
::bot_should_purchase_magicbox,
::bot_check_complete_purchase_magicbox,
::bot_magicbox_purchase_should_cancel,
::bot_magicbox_purchase_should_postpone,
::bot_magicbox_purchase_priority );
register_bot_action( "perk",
::bot_perk_purchase,
::bot_perk_purchase_init,
::bot_perk_purchase_post_think,
::bot_should_purchase_perk,
::bot_check_complete_perk_purchase,
::bot_perk_purchase_should_cancel,
::bot_perk_purchase_priority );
register_bot_objective( "magicbox" );
register_bot_objective( "wallbuy" );
@ -60,13 +66,11 @@ connected()
{
self endon( "disconnect" );
self thread initialize_bot_actions_queue();
self.on_powerup_grab_func = ::bot_on_powerup_grab;
self.on_revive_success_func = ::bot_on_revive_success;
self.on_magicbox_weapon_grab_func = ::bot_on_magicbox_weapon_grab;
self.on_perk_purchase_func = ::bot_on_perk_purchase;
self.obj_postponed_reason = "";
self.obj_cancel_reason = "";
self.obj_history = [];

View File

@ -5,6 +5,22 @@
create_static_objectives()
{
if ( getDvar( "magicbox_node_forward_size" ) == "" )
{
setDvar( "magicbox_node_forward_size", 55 );
}
if ( getDvar( "magicbox_node_vertical_offset" ) == "" )
{
setDvar( "magicbox_node_vertical_offset", 10 );
}
if ( getDvar( "perk_node_forward_size" ) == "" )
{
setDvar( "perk_node_forward_size", 55 );
}
if ( getDvar( "perk_node_vertical_offset" ) == "" )
{
setDvar( "perk_node_vertical_offset", 1 );
}
weapon_spawns = GetEntArray( "weapon_upgrade", "targetname" );
if ( isDefined( weapon_spawns ) && weapon_spawns.size > 0 )
@ -23,6 +39,9 @@ create_static_objectives()
for ( i = 0; i < vending_triggers.size; i++ )
{
obj = add_possible_bot_objective( "perk", vending_triggers[ i ], false );
model = getEnt( vending_triggers[ i ].target, "targetname" );
vending_triggers[ i ].bot_use_node = get_angle_offset_node( model, ( 0, 0, 0 ), getDvar( "perk_node_forward_size" ), ( 0, 0, getDvar( "perk_node_vertical_offset" ) ) );
vending_triggers[ i ] thread perk_debug();
}
}
@ -163,7 +182,7 @@ watch_magicbox_objectives()
cur_magicbox = maps\so\zm_common\_zm_magicbox::get_active_magicbox();
add_possible_bot_objective( "magicbox", cur_magicbox, true );
cur_magicbox.bot_use_node = get_angle_offset_node( cur_magicbox maps\so\zm_common\_zm_magicbox::get_chest_pieces()[ 1 ], ( 0, 90, 0 ), 40, ( 0, 0, 1 ) );
cur_magicbox.bot_use_node = get_angle_offset_node( cur_magicbox maps\so\zm_common\_zm_magicbox::get_chest_pieces()[ 1 ], ( 0, 90, 0 ), getDvarInt( "magicbox_node_forward_size" ), ( 0, 0, getDvarInt( "magicbox_node_vertical_offset" ) ) );
cur_magicbox thread magicbox_debug();
@ -174,7 +193,7 @@ watch_magicbox_objectives()
free_bot_objective( "magicbox", old_magicbox );
level waittill( "new_magicbox", new_magicbox );
add_possible_bot_objective( "magicbox", new_magicbox, true );
new_magicbox.bot_use_node = get_angle_offset_node( new_magicbox maps\so\zm_common\_zm_magicbox::get_chest_pieces()[ 1 ], ( 0, 90, 0 ), 40, ( 0, 0, 1 ) );
new_magicbox.bot_use_node = get_angle_offset_node( new_magicbox maps\so\zm_common\_zm_magicbox::get_chest_pieces()[ 1 ], ( 0, 90, 0 ), getDvarInt( "magicbox_node_forward_size" ), ( 0, 0, getDvarInt( "magicbox_node_vertical_offset" ) ) );
new_magicbox thread magicbox_debug();
}
}
@ -184,13 +203,28 @@ magicbox_debug()
self notify( "magicbox_debug" );
self endon( "magicbox_debug");
level endon( "magicbox_teddy_bear" );
if ( getDvarInt( "bot_obj_debug_all" ) == 0 && getDvarInt( "bot_obj_debug_perk" ) == 0 )
{
return;
}
while ( true )
{
node = get_angle_offset_node( self maps\so\zm_common\_zm_magicbox::get_chest_pieces()[ 1 ], ( 0, 90, 0 ), getDvarInt( "magicbox_node_forward_size" ), ( 0, 0, getDvarInt( "magicbox_node_vertical_offset" ) ) );
self.bot_use_node = node;
line( self.origin, node, ( 1.0, 1.0, 1.0 ) );
wait 0.05;
}
}
perk_debug()
{
if ( getDvarInt( "bot_obj_debug_all" ) == 0 && getDvarInt( "bot_obj_debug_magicbox" ) == 0 )
{
return;
}
while ( true )
{
node = get_angle_offset_node( self maps\so\zm_common\_zm_magicbox::get_chest_pieces()[ 1 ], ( 0, 90, 0 ), getDvarInt( "magicbox_node_forward_size" ), ( 0, 0, 1 ) );
node = get_angle_offset_node( self, ( 0, getDvarInt( "perk_node_angle" ), 0 ), getDvarInt( "perk_node_forward_size" ), ( 0, 0, getDvarInt( "perk_node_vertical_offset" ) ) );
self.bot_use_node = node;
line( self.origin, node, ( 1.0, 1.0, 1.0 ) );
wait 0.05;
@ -213,4 +247,10 @@ bot_on_magicbox_weapon_grab( magicbox, weapon )
{
self bot_objective_print( "magicbox", magicbox getEntityNumber(), "bot_on_magicbox_weapon_grab", "Bot <" + self.playername + "> grabbed <" + weapon + "> from the box" );
self.successfully_grabbed_magicbox_weapon = true;
}
bot_on_perk_purchase( trigger, perk )
{
self bot_objective_print( "perk", trigger getEntityNumber(), "bot_on_perk_purchase", "Bot <" + self.playername + "> purchased <" + perk + ">" );
self.successfully_bought_perk = true;
}

View File

@ -38,31 +38,24 @@ setupcallbacks()
killtestoverrideactordamage( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, iModelIndex, iTimeOffset )
{
if ( isDefined( eAttacker ) && isPlayer( eAttacker ) )
{
if ( sWeapon == "zombie_doublebarrel" )
iDamage = 1;
}
setDvar( "aa_player_damage_dealt", 0 );
if ( sMeansOfDeath == "MOD_MELEE" )
iDamage = 100000000;
if ( isPlayer( eAttacker ) && eAttacker isBot() && getDvarInt( "bots_t8_mode" ) )
{
iDamage += int( self.maxhealth * randomFloatRange( 0.25, 1.25 ) );
}
self [[level.killtestoldoverrideactordamage]]( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, iModelIndex, iTimeOffset );
}
killtestoverrideplayerdamage( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, modelIndex, psOffsetTime )
{
if ( self isBot() )
if ( self isBot() && getDvarInt( "bots_t8_mode" ) )
{
if ( isDefined( eAttacker ) && eAttacker == self )
return;
iDamage = 5;
iDamage = int( iDamage * 0.1 );
}
PrintConsole( self GetPlayerName() + " took " + iDamage );
//PrintConsole( self GetPlayerName() + " took " + iDamage );
self [[level.killtestoldoverrideplayerdamage]]( eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, modelIndex, psOffsetTime );
}