mirror of
https://github.com/JezuzLizard/t4sp_bot_warfare.git
synced 2025-04-22 14:35:44 +00:00
Bug fixes and optimizations for objective system.
This commit is contained in:
parent
09780b4ea0
commit
6994631128
@ -3,6 +3,30 @@
|
||||
#include maps\bots\_bot_utility;
|
||||
#include maps\bots\script_objectives\_obj_common;
|
||||
|
||||
bot_post_think_common( state, obj_ent )
|
||||
{
|
||||
obj = bot_objective_history_get_current();
|
||||
|
||||
switch ( state )
|
||||
{
|
||||
case "completed":
|
||||
bot_objective_print( "powerup", obj.id, "Bot <" + self.playername + "> objective was completed", "bot_post_think_common" );
|
||||
break;
|
||||
case "postponed":
|
||||
bot_objective_print( "powerup", obj.id, "Bot <" + self.playername + "> objective was postponed Reason: " + self.obj_postponed_reason, "bot_post_think_common" );
|
||||
break;
|
||||
case "canceled":
|
||||
bot_objective_print( "powerup", 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 ClearScriptGoal();
|
||||
self ClearScriptAimPos();
|
||||
self ClearPriorityObjective();
|
||||
self bot_clear_objective();
|
||||
}
|
||||
|
||||
bot_grab_powerup()
|
||||
{
|
||||
self endon( "disconnect" );
|
||||
@ -17,12 +41,11 @@ bot_grab_powerup()
|
||||
|
||||
powerup_obj = self.available_powerups[ 0 ];
|
||||
powerup_obj_ent = powerup_obj.target_ent;
|
||||
|
||||
set_bot_global_shared_objective_owner_by_ent( "powerup", powerup_obj_ent, self );
|
||||
self bot_set_objective( "powerup", powerup_obj_ent );
|
||||
self bot_set_objective_owner( "powerup", powerup_obj_ent );
|
||||
|
||||
bot_objective_print( "powerup", powerup_obj_ent, "Bot <" + self.playername + "> starts objective" );
|
||||
while ( isDefined( powerup_obj_ent ) && isDefined( powerup_obj ) && self bot_is_objective_owner( "powerup", powerup_obj_ent ) )
|
||||
bot_objective_print( "powerup", powerup_obj.id, "Bot <" + self.playername + "> starts objective", "bot_grab_powerup" );
|
||||
while ( true )
|
||||
{
|
||||
wait 1;
|
||||
self SetPriorityObjective();
|
||||
@ -32,7 +55,7 @@ bot_grab_powerup()
|
||||
|
||||
if ( result != "goal" )
|
||||
{
|
||||
bot_objective_print( "powerup", powerup_obj_ent, "Bot <" + self.playername + "> bad path" );
|
||||
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
|
||||
@ -40,8 +63,8 @@ bot_grab_powerup()
|
||||
//Check if powerup still exists
|
||||
if ( isDefined( powerup_obj_ent ) )
|
||||
{
|
||||
height_difference = self.origin[ 2 ] - powerup_obj_ent.origin[ 2 ];
|
||||
if ( height_difference < 49 )
|
||||
height_difference = powerup_obj_ent.origin[ 2 ] - self.origin[ 2 ];
|
||||
if ( height_difference > 0 && height_difference < 49 )
|
||||
{
|
||||
self BotJump();
|
||||
wait 0.5;
|
||||
@ -60,7 +83,7 @@ bot_grab_powerup()
|
||||
|
||||
if ( powerup_obj.bad )
|
||||
{
|
||||
bot_objective_print( "powerup", powerup_obj_ent, "Bot <" + self.playername + "> objective was marked as bad" );
|
||||
bot_objective_print( "powerup", powerup_obj.id, "Bot <" + self.playername + "> objective was marked as bad", "bot_grab_powerup" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -81,24 +104,8 @@ bot_powerup_post_think( state )
|
||||
{
|
||||
obj = self bot_get_objective();
|
||||
powerup_obj_ent = obj.target_ent;
|
||||
switch ( state )
|
||||
{
|
||||
case "completed":
|
||||
bot_objective_print( "powerup", powerup_obj_ent, "Bot <" + self.playername + "> objective was completed" );
|
||||
break;
|
||||
case "postponed":
|
||||
bot_objective_print( "powerup", powerup_obj_ent, "Bot <" + self.playername + "> objective was postponed Reason: " + self.obj_postponed_reason );
|
||||
break;
|
||||
case "canceled":
|
||||
bot_objective_print( "powerup", powerup_obj_ent, "Bot <" + self.playername + "> objective was canceled Reason: " + self.obj_cancel_reason );
|
||||
break;
|
||||
}
|
||||
self bot_post_think_common( state, powerup_obj_ent );
|
||||
self.successfully_grabbed_powerup = false;
|
||||
self.obj_cancel_reason = "";
|
||||
self ClearScriptGoal();
|
||||
self ClearScriptAimPos();
|
||||
self ClearPriorityObjective();
|
||||
self clear_objective_for_bot();
|
||||
}
|
||||
|
||||
bot_should_grab_powerup()
|
||||
@ -157,17 +164,19 @@ bot_check_complete_grab_powerup()
|
||||
|
||||
bot_powerup_should_cancel()
|
||||
{
|
||||
if ( !isDefined( self.available_powerups ) || self.available_powerups.size <= 0 )
|
||||
obj = self bot_get_objective();
|
||||
|
||||
canceled_goal = false;
|
||||
if ( !self bot_is_objective_owner( "powerup", obj.target_ent ) )
|
||||
{
|
||||
self.obj_cancel_reason = "No available powerups";
|
||||
return true;
|
||||
self.obj_cancel_reason = "No longer the obj owner";
|
||||
canceled_goal = true;
|
||||
}
|
||||
if ( !isDefined( self.available_powerups[ 0 ].target_ent ) )
|
||||
if ( canceled_goal )
|
||||
{
|
||||
self.obj_cancel_reason = "Powerup doesn't exist";
|
||||
return true;
|
||||
self notify( "goal" );
|
||||
}
|
||||
return false ;
|
||||
return canceled_goal;
|
||||
}
|
||||
|
||||
bot_powerup_should_postpone()
|
||||
@ -202,11 +211,11 @@ bot_revive_player()
|
||||
|
||||
player_to_revive = player_to_revive_obj.target_ent;
|
||||
self bot_set_objective( "revive", player_to_revive );
|
||||
set_bot_global_shared_objective_owner_by_ent( "revive", player_to_revive, self );
|
||||
bot_objective_print( "revive", player_to_revive, "Bot <" + self.playername + "> objective started" );
|
||||
self bot_set_objective_owner( "revive", player_to_revive );
|
||||
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 ( isDefined( player_to_revive ) && isDefined( player_to_revive_obj ) && self bot_is_objective_owner( "revive", player_to_revive ) )
|
||||
while ( true )
|
||||
{
|
||||
wait 1;
|
||||
//Constantly update the goal just in case the player is moving(T5 or higher only)
|
||||
@ -216,15 +225,14 @@ bot_revive_player()
|
||||
|
||||
result = self waittill_any_return( "goal", "bad_path", "new_goal" );
|
||||
|
||||
//printConsole( result );
|
||||
if ( result != "goal" )
|
||||
{
|
||||
bot_objective_print( "revive", player_to_revive, "Bot <" + self.playername + "> bad path" );
|
||||
bot_objective_print( "revive", player_to_revive_obj.id, "Bot <" + self.playername + "> bad path", "bot_revive_player" );
|
||||
continue;
|
||||
}
|
||||
if ( !isDefined( player_to_revive.revivetrigger ) )
|
||||
{
|
||||
return;
|
||||
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 )
|
||||
@ -265,25 +273,9 @@ bot_revive_player_post_think( state )
|
||||
{
|
||||
obj = self bot_get_objective();
|
||||
revive_obj_ent = obj.target_ent;
|
||||
switch ( state )
|
||||
{
|
||||
case "completed":
|
||||
bot_objective_print( "revive", revive_obj_ent, "Bot <" + self.playername + "> objective was completed" );
|
||||
break;
|
||||
case "postponed":
|
||||
bot_objective_print( "revive", revive_obj_ent, "Bot <" + self.playername + "> objective was postponed Reason: " + self.obj_postponed_reason );
|
||||
break;
|
||||
case "canceled":
|
||||
bot_objective_print( "revive", revive_obj_ent, "Bot <" + self.playername + "> objective was canceled Reason: " + self.obj_cancel_reason );
|
||||
break;
|
||||
}
|
||||
self bot_post_think_common( state, revive_obj_ent );
|
||||
self.should_cancel_revive_obj = false;
|
||||
self.successfully_revived_player = false;
|
||||
self.obj_cancel_reason = "";
|
||||
self ClearScriptGoal();
|
||||
self ClearScriptAimPos();
|
||||
self ClearPriorityObjective();
|
||||
self clear_objective_for_bot();
|
||||
}
|
||||
|
||||
bot_should_revive_player()
|
||||
@ -320,22 +312,24 @@ bot_check_complete_revive_player()
|
||||
|
||||
bot_revive_player_should_cancel()
|
||||
{
|
||||
if ( !isDefined( self.available_revives[ 0 ] ) )
|
||||
{
|
||||
self.obj_cancel_reason = "Obj didn't exist";
|
||||
return true;
|
||||
}
|
||||
if ( !isDefined( self.available_revives[ 0 ].target_ent ) )
|
||||
{
|
||||
self.obj_cancel_reason = "Entity didn't exist";
|
||||
return true;
|
||||
}
|
||||
if ( !isDefined( self.available_revives[ 0 ].target_ent.revivetrigger ) )
|
||||
obj = self bot_get_objective();
|
||||
|
||||
goal_canceled = false;
|
||||
if ( !isDefined( obj.target_ent.revivetrigger ) )
|
||||
{
|
||||
self.obj_cancel_reason = "Revive trigger didn't exist";
|
||||
return true;
|
||||
goal_canceled = true;
|
||||
}
|
||||
return false;
|
||||
else if ( !self bot_is_objective_owner( "revive", obj.target_ent ) )
|
||||
{
|
||||
self.obj_cancel_reason = "No longer the obj owner";
|
||||
goal_canceled = true;
|
||||
}
|
||||
if ( goal_canceled )
|
||||
{
|
||||
self notify( "goal" );
|
||||
}
|
||||
return goal_canceled;
|
||||
}
|
||||
|
||||
bot_revive_player_should_postpone()
|
||||
@ -346,4 +340,102 @@ bot_revive_player_should_postpone()
|
||||
bot_revive_player_priority()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bot_magicbox_purchase()
|
||||
{
|
||||
self.target_pos = self.available_chests[ 0 ].origin;
|
||||
}
|
||||
|
||||
bot_magicbox_purchase_process_order()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bot_magicbox_purchase_init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bot_magicbox_purchase_post_think( state )
|
||||
{
|
||||
obj = self bot_get_objective();
|
||||
magicbox_obj_ent = obj.target_ent;
|
||||
self bot_post_think_common( state, magicbox_obj_ent );
|
||||
}
|
||||
|
||||
bot_should_purchase_magicbox()
|
||||
{
|
||||
magicbox_objs = get_all_objectives_for_group( "magicbox" );
|
||||
if ( magicbox_objs.size <= 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( !level.enable_magic )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( level.chests.size <= 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
self.available_chests = [];
|
||||
for ( i = 0; i < magicbox_objs.size; i++ )
|
||||
{
|
||||
if ( level.chests[ i ].hidden )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( self.score < level.chests[ i ].zombie_cost )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
self.available_chests[ self.available_chests.size ] = level.chests[ i ];
|
||||
}
|
||||
if ( self.available_chests.size > 0 )
|
||||
{
|
||||
for ( i = 0; i < self.available_chests.size; i++ )
|
||||
{
|
||||
if ( isDefined( self.available_chests[ i ].chest_user ) )
|
||||
{
|
||||
maps\_utility::array_remove_index( self.available_chests, i );
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return self.available_chests.size > 0;
|
||||
}
|
||||
|
||||
bot_check_complete_purchase_magicbox()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bot_magicbox_purchase_should_cancel()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bot_magicbox_purchase_should_postpone()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bot_magicbox_purchase_priority()
|
||||
{
|
||||
priority = 0;
|
||||
LOW_AMMO_THRESHOLD = 0.3;
|
||||
weapons = self getWeaponsListPrimaries();
|
||||
if ( weapons.size < 2 )
|
||||
{
|
||||
priority += 1;
|
||||
}
|
||||
for ( j = 0; j < weapons.size; j++ )
|
||||
{
|
||||
if ( self getWeaponAmmoStock( weapons[ j ] ) <= int( weaponmaxammo( weapons[ j ] ) * LOW_AMMO_THRESHOLD ) )
|
||||
{
|
||||
priority += 1;
|
||||
}
|
||||
}
|
||||
return priority;
|
||||
}
|
@ -17,18 +17,26 @@ register_bot_objective( objective_group )
|
||||
|
||||
add_possible_bot_objective( objective_group, target_ent, is_global_shared )
|
||||
{
|
||||
assert( isDefined( level.zbot_objective_glob ), "Trying to add objective before calling register_bot_objective" );
|
||||
|
||||
assert( isDefined( level.zbot_objective_glob[ objective_group ] ), "Trying to add objective to group " + objective_group + " before calling register_bot_objective" );
|
||||
|
||||
if ( !isDefined( target_ent ) )
|
||||
{
|
||||
objective_ent_assert( objective_group, "add_possible_bot_objective", "[ent was undefined]" );
|
||||
objective_assert( objective_group, undefined, "add_possible_bot_objective", "[ent was undefined]" );
|
||||
return;
|
||||
}
|
||||
|
||||
id = target_ent getEntityNumber();
|
||||
|
||||
if ( !isDefined( level.zbot_objective_glob ) )
|
||||
{
|
||||
objective_assert( objective_group, id, "add_possible_bot_objective", "Trying to add objective before calling register_bot_objective for objective group " + objective_group );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !isDefined( level.zbot_objective_glob[ objective_group ] ) )
|
||||
{
|
||||
objective_assert( objective_group, id, "add_possible_bot_objective", "Trying to add objective to group " + objective_group + " before calling register_bot_objective" );
|
||||
return;
|
||||
}
|
||||
|
||||
objective_struct = spawnStruct();
|
||||
objective_struct.group = objective_group;
|
||||
objective_struct.is_global_shared = is_global_shared;
|
||||
@ -36,27 +44,14 @@ add_possible_bot_objective( objective_group, target_ent, is_global_shared )
|
||||
objective_struct.owner = undefined;
|
||||
objective_struct.is_objective = true;
|
||||
objective_struct.bad = false;
|
||||
objective_struct.id = id;
|
||||
|
||||
level.zbot_objective_glob[ objective_group ].active_objectives[ "obj_id_" + id ] = objective_struct;
|
||||
}
|
||||
|
||||
get_bot_objective_by_entity_ref( objective_group, ent )
|
||||
get_objective( objective_group, ent, id )
|
||||
{
|
||||
if ( !isDefined( ent ) )
|
||||
{
|
||||
objective_ent_assert( objective_group, "get_bot_objective_by_entity_ref", "[ent was undefined]" );
|
||||
return undefined;
|
||||
}
|
||||
|
||||
id = ent getEntityNumber();
|
||||
|
||||
active_objectives = level.zbot_objective_glob[ objective_group ].active_objectives;
|
||||
|
||||
objective = active_objectives[ "obj_id_" + id ];
|
||||
|
||||
objective_defined_assert( objective_group, id, "get_bot_objective_by_entity_ref", "[obj was undefined]" );
|
||||
|
||||
return objective;
|
||||
return get_objective_safe( objective_group, ent, id, "get_objective_by_entity_ref" );
|
||||
}
|
||||
|
||||
get_all_objectives_for_group( objective_group )
|
||||
@ -76,35 +71,39 @@ bot_has_objective()
|
||||
|
||||
bot_set_objective( objective_group, ent )
|
||||
{
|
||||
if ( !isDefined( ent ) )
|
||||
objective = get_objective_safe( objective_group, ent, id, "bot_set_objective" );
|
||||
if ( !isDefined( objective ) )
|
||||
{
|
||||
objective_ent_assert( objective_group, "bot_set_objective", "[ent was undefined]" );
|
||||
return;
|
||||
}
|
||||
|
||||
possible_objectives = level.zbot_objective_glob[ objective_group ].active_objectives;
|
||||
new_obj_history = spawnStruct();
|
||||
new_obj_history.id = ent getEntityNumber();
|
||||
new_obj_history.group = objective_group;
|
||||
new_obj_history.ent_start_pos = ent.origin;
|
||||
new_obj_history.ent_end_pos = ent.origin;
|
||||
new_obj_history.bot_start_pos = self.origin;
|
||||
new_obj_history.bot_end_pos = self.origin;
|
||||
new_obj_history.start_time = getTime();
|
||||
new_obj_history.end_time = getTime();
|
||||
new_obj_history.time_spent = 0;
|
||||
|
||||
id = ent getEntityNumber();
|
||||
|
||||
objective = possible_objectives[ "obj_id_" + id ];
|
||||
|
||||
objective_exists = isDefined( objective );
|
||||
|
||||
if ( !objective_exists )
|
||||
self.bot_obj_history_prev_index = self.bot_obj_history_index;
|
||||
if ( self.bot_obj_history_index >= self.bot_obj_history_max_entries )
|
||||
{
|
||||
objective_defined_assert( objective_group, id, "bot_set_objective", "[obj was undefined]" );
|
||||
return;
|
||||
self.bot_obj_history_index = 0;
|
||||
}
|
||||
|
||||
|
||||
self.obj_history[ self.bot_obj_history_index ] = new_obj_history;
|
||||
self.zbot_current_objective = objective;
|
||||
}
|
||||
|
||||
clear_objective_for_bot()
|
||||
bot_clear_objective()
|
||||
{
|
||||
self.zbot_current_objective = undefined;
|
||||
}
|
||||
|
||||
set_bot_objective_blocked_by_objective( primary_objective_group, primary_ent, blocked_by_objective_group, blocked_by_ent )
|
||||
objective_set_blocked( primary_objective_group, primary_ent, blocked_by_objective_group, blocked_by_ent )
|
||||
{
|
||||
if ( !isDefined( primary_ent ) )
|
||||
{
|
||||
@ -171,132 +170,89 @@ set_bot_objective_blocked_by_objective( primary_objective_group, primary_ent, bl
|
||||
}
|
||||
}
|
||||
|
||||
bot_is_objective_owner( objective_group, ent )
|
||||
objective_remove_blocked()
|
||||
{
|
||||
if ( !isDefined( ent ) )
|
||||
|
||||
}
|
||||
|
||||
objective_has_owner( objective_group, ent )
|
||||
{
|
||||
objective = get_objective_safe( objective_group, ent, id, "objective_has_owner" );
|
||||
if ( !isDefined( objective ) )
|
||||
{
|
||||
objective_ent_assert( objective_group, "bot_is_objective_owner", "[ent was undefined]" );
|
||||
return false;
|
||||
}
|
||||
|
||||
id = ent getEntityNumber();
|
||||
|
||||
active_objectives = level.zbot_objective_glob[ objective_group ].active_objectives;
|
||||
|
||||
objective = active_objectives[ "obj_id_" + id ];
|
||||
|
||||
objective_exists = isDefined( objective );
|
||||
if ( !objective_exists )
|
||||
if ( !objective.is_global_shared )
|
||||
{
|
||||
objective_defined_assert( objective_group, id, "bot_is_objective_owner", "[obj was undefined]" );
|
||||
objective_assert( objective_group, id, "objective_has_owner", "Objective with " + id + " id number cannot be set to have an owner because is_global_shared field is false in group " + objective_group )
|
||||
return false;
|
||||
}
|
||||
|
||||
assert( objective.is_global_shared, "Objective with " + id + " id number cannot be set to have an owner because is_global_shared field is false in group " + objective_group );
|
||||
return isDefined( objective.owner );
|
||||
}
|
||||
|
||||
bot_is_objective_owner( objective_group, ent )
|
||||
{
|
||||
objective = get_objective_safe( objective_group, ent, id, "bot_is_objective_owner" );
|
||||
if ( !isDefined( objective ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
id = ent getEntityNumber();
|
||||
|
||||
if ( !objective.is_global_shared )
|
||||
{
|
||||
objective_assert( objective_group, id, "bot_is_objective_owner", "Objective with " + id + " id number cannot be set to have an owner because is_global_shared field is false in group " + objective_group )
|
||||
return false;
|
||||
}
|
||||
|
||||
return isDefined( objective.owner ) && objective.owner == self;
|
||||
}
|
||||
|
||||
set_bot_global_shared_objective_owner_by_ent( objective_group, ent, new_owner )
|
||||
bot_set_objective_owner( objective_group, ent )
|
||||
{
|
||||
if ( !isDefined( ent ) )
|
||||
objective = get_objective_safe( objective_group, ent, id, "bot_set_objective_owner" );
|
||||
if ( !isDefined( objective ) )
|
||||
{
|
||||
objective_ent_assert( objective_group, "set_bot_global_shared_objective_owner_by_ent", "[ent was undefined]" );
|
||||
return;
|
||||
}
|
||||
|
||||
id = ent getEntityNumber();
|
||||
|
||||
active_objectives = level.zbot_objective_glob[ objective_group ].active_objectives;
|
||||
|
||||
objective = active_objectives[ "obj_id_" + id ];
|
||||
|
||||
objective_exists = isDefined( objective );
|
||||
if ( !objective_exists )
|
||||
{
|
||||
objective_defined_assert( objective_group, id, "set_bot_global_shared_objective_owner_by_ent", "[obj was undefined]" );
|
||||
return;
|
||||
}
|
||||
|
||||
assert( objective.is_global_shared, "Objective with " + id + " id number cannot be set to have an owner because is_global_shared field is false in group " + objective_group );
|
||||
if ( !objective.is_global_shared )
|
||||
{
|
||||
objective_assert( objective_group, id, "bot_set_objective_owner", "Objective with " + id + " id number cannot be set to have an owner because is_global_shared field is false in group " + objective_group )
|
||||
return;
|
||||
}
|
||||
|
||||
objective.owner = new_owner;
|
||||
}
|
||||
|
||||
set_bot_global_shared_objective_owner_by_reference( objective_group, objective, new_owner )
|
||||
{
|
||||
is_objective = isDefined( objective.is_objective );
|
||||
assert( is_objective, "Objective arg is not a valid objective object" );
|
||||
if ( !is_objective )
|
||||
{
|
||||
return;
|
||||
}
|
||||
assert( objective.is_global_shared, "Objective with " + objective.id + " id number cannot be set to have an owner because is_global_shared field is false in group " + objective_group );
|
||||
if ( !objective.is_global_shared )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
objective.owner = new_owner;
|
||||
objective.owner = self;
|
||||
}
|
||||
|
||||
mark_objective_bad( objective_group, ent )
|
||||
{
|
||||
if ( !isDefined( ent ) )
|
||||
objective = get_objective_safe( objective_group, ent, id, "mark_objective_bad" );
|
||||
if ( !isDefined( objective ) )
|
||||
{
|
||||
objective_ent_assert( objective_group, "mark_objective_bad", "[ent was undefined]" );
|
||||
return;
|
||||
}
|
||||
|
||||
id = ent getEntityNumber();
|
||||
|
||||
active_objectives = level.zbot_objective_glob[ objective_group ].active_objectives;
|
||||
|
||||
objective = active_objectives[ "obj_id_" + id ];
|
||||
|
||||
objective_exists = isDefined( objective );
|
||||
if ( !objective_exists )
|
||||
{
|
||||
objective_defined_assert( objective_group, id, "mark_objective_bad", "[obj was undefined]" );
|
||||
return;
|
||||
}
|
||||
|
||||
objective.bad = true;
|
||||
}
|
||||
|
||||
free_bot_objective( objective_group, ent )
|
||||
free_bot_objective( objective_group, ent, id )
|
||||
{
|
||||
if ( !isDefined( ent ) )
|
||||
objective = get_objective_safe( objective_group, ent, id, "free_bot_objective" );
|
||||
if ( !isDefined( objective ) )
|
||||
{
|
||||
objective_ent_assert( objective_group, "free_bot_objective", "[ent was undefined]" );
|
||||
return;
|
||||
}
|
||||
|
||||
id = ent getEntityNumber();
|
||||
|
||||
active_objectives = level.zbot_objective_glob[ objective_group ].active_objectives;
|
||||
|
||||
objective = active_objectives[ "obj_id_" + id ];
|
||||
|
||||
objective_exists = isDefined( objective );
|
||||
if ( !objective_exists )
|
||||
{
|
||||
objective_defined_assert( objective_group, id, "free_bot_objective", "[obj was undefined]" );
|
||||
return;
|
||||
}
|
||||
|
||||
players = getPlayers();
|
||||
for ( i = 0; i < players.size; i++ )
|
||||
{
|
||||
if ( isDefined( players[ i ].pers[ "isBot" ] ) && players[ i ].pers[ "isBot" ] )
|
||||
if ( players[ i ] is_bot() )
|
||||
{
|
||||
if ( isDefined( players[ i ].zbot_current_objective ) && players[ i ].zbot_current_objective == objective )
|
||||
{
|
||||
@ -305,18 +261,27 @@ free_bot_objective( objective_group, ent )
|
||||
}
|
||||
}
|
||||
|
||||
active_objectives[ "obj_id_" + id ] = undefined;
|
||||
level.zbot_objective_glob[ objective_group ].active_objectives[ "obj_id_" + id ] = undefined;
|
||||
}
|
||||
|
||||
bot_objective_print( objective_group, ent, message )
|
||||
get_objective_safe( objective_group, ent, id, function_name )
|
||||
{
|
||||
if ( !isDefined( ent ) )
|
||||
if ( !isDefined( ent ) && !isDefined( id ) )
|
||||
{
|
||||
objective_ent_assert( objective_group, "bot_objective_print", "[ent was undefined] " + message );
|
||||
return;
|
||||
objective_assert( objective_group, id, function_name, "[ent and id were undefined]" );
|
||||
return undefined;
|
||||
}
|
||||
|
||||
id = ent getEntityNumber();
|
||||
if ( isDefined( ent ) )
|
||||
{
|
||||
id = ent getEntityNumber();
|
||||
}
|
||||
|
||||
if ( !isDefined( level.zbot_objective_glob[ objective_group ] ) )
|
||||
{
|
||||
objective_assert( objective_group, id, function_name, "[obj group is invalid]" );
|
||||
return undefined;
|
||||
}
|
||||
|
||||
active_objectives = level.zbot_objective_glob[ objective_group ].active_objectives;
|
||||
|
||||
@ -325,37 +290,68 @@ bot_objective_print( objective_group, ent, message )
|
||||
objective_exists = isDefined( objective );
|
||||
if ( !objective_exists )
|
||||
{
|
||||
objective_defined_assert( objective_group, id, "bot_objective_print", "[obj was undefined] " + message );
|
||||
return;
|
||||
objective_assert( objective_group, id, function_name, "[obj was undefined]" );
|
||||
return undefined;
|
||||
}
|
||||
|
||||
objective_info_print( objective_group, id, "bot_objective_print", message );
|
||||
return objective;
|
||||
}
|
||||
|
||||
objective_ent_assert( objective_group, function_name, message )
|
||||
bot_objective_print( objective_group, id, message, function_name )
|
||||
{
|
||||
assertMsg( "Ent is undefined" );
|
||||
if ( getDvarInt( "bot_obj_debug_all" ) != 0 || getDvarInt( "bot_obj_debug_" + objective_group ) != 0 )
|
||||
{
|
||||
logprint( "ERROR: " + function_name + "() Obj <" + objective_group + "> " + message + "\n" );
|
||||
}
|
||||
objective_info_print( objective_group, id, function_name, message );
|
||||
}
|
||||
}
|
||||
|
||||
objective_defined_assert( objective_group, id, function_name, message )
|
||||
objective_assert( objective_group, id, function_name, message )
|
||||
{
|
||||
assertMsg( "Objective with " + id + " id number does not point to a objective in group " + objective_group );
|
||||
assertMsg( message );
|
||||
if ( getDvarInt( "bot_obj_debug_all" ) != 0 || getDvarInt( "bot_obj_debug_" + objective_group ) != 0 )
|
||||
{
|
||||
logprint( "ERROR: " + function_name + "() Obj <" + objective_group + "> ent <" + id + "> [obj was undefined] " + message + "\n" );
|
||||
if ( !isDefined( id ) )
|
||||
{
|
||||
error_message = "ERROR: " + function_name + "() Obj <" + objective_group + "> " + message;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_message = "ERROR: " + function_name + "() Obj <" + objective_group + "> ent <" + id + "> " + message;
|
||||
}
|
||||
logprint( error_message + "\n" );
|
||||
printConsole( error_message );
|
||||
}
|
||||
}
|
||||
|
||||
objective_info_print( objective_group, id, function_name, message )
|
||||
{
|
||||
if ( getDvarInt( "bot_obj_debug_all" ) != 0 || getDvarInt( "bot_obj_debug_" + objective_group ) != 0 )
|
||||
obj = bot_objective_history_get_current();
|
||||
message = "INFO: " + function_name + "() Obj <" + objective_group + "> ent <" + id + "> pos <" + obj.ent_end_pos + "> " + message;
|
||||
logprint( message + "\n" );
|
||||
printConsole( message );
|
||||
}
|
||||
|
||||
bot_objective_history_get_oldest()
|
||||
{
|
||||
oldest = self.obj_history[ 0 ];
|
||||
for ( i = 1; i < self.obj_history.size; i++ )
|
||||
{
|
||||
logprint( "INFO: " + function_name + "() Obj <" + objective_group + "> ent <" + id + "> " + message + "\n" );
|
||||
if ( oldest.end_time < self.obj_history[ i ] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
oldest = self.obj_history[ i ];
|
||||
}
|
||||
return oldest;
|
||||
}
|
||||
|
||||
bot_objective_history_get_current()
|
||||
{
|
||||
return self.obj_history[ level.bot_obj_history_index ];
|
||||
}
|
||||
|
||||
bot_objective_history_get_previous()
|
||||
{
|
||||
return self.obj_history[ level.bot_obj_history_prev_index ];
|
||||
}
|
||||
|
||||
/**********Action Section**********/
|
||||
@ -491,6 +487,13 @@ wait_for_action_completion( group_name, action_name )
|
||||
{
|
||||
self.action_queue[ group_name ][ 0 ] = undefined;
|
||||
}
|
||||
|
||||
self.obj_history[ self.bot_obj_history_index ].end_time = getTime();
|
||||
end_time = self.obj_history[ self.bot_obj_history_index ].end_time
|
||||
start_time = self.obj_history[ self.bot_obj_history_index ].start_time;
|
||||
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++;
|
||||
}
|
||||
|
||||
pick_actions_to_add_to_queue( group_name )
|
||||
@ -618,7 +621,11 @@ bot_action_think()
|
||||
wait 0.05;
|
||||
//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;
|
||||
waittillframeend;
|
||||
|
||||
if ( !maps\so\zm_common\_zm_utility::is_player_valid( self ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
group_name = "objective";
|
||||
|
||||
@ -653,15 +660,35 @@ action_should_be_canceled_global( primary_group_name, action_name )
|
||||
{
|
||||
obj = self bot_get_objective();
|
||||
|
||||
if ( self GetPathIsInaccessible() )
|
||||
goal_canceled = false;
|
||||
if ( !isDefined( obj ) )
|
||||
{
|
||||
self.obj_cancel_reason = "Obj didn't exist";
|
||||
goal_canceled = true;
|
||||
}
|
||||
else if ( !isDefined( obj.target_ent ) )
|
||||
{
|
||||
self.obj_cancel_reason = "Obj entity doesn't exist";
|
||||
canceled_goal = true;
|
||||
}
|
||||
else if ( self GetPathIsInaccessible( obj.target_ent.origin ) )
|
||||
{
|
||||
self.obj_cancel_reason = "Path was inaccessible";
|
||||
return true;
|
||||
goal_canceled = true;
|
||||
}
|
||||
if ( obj.bad )
|
||||
else if ( obj.bad )
|
||||
{
|
||||
self.obj_cancel_reason = "Obj was bad";
|
||||
return true;
|
||||
goal_canceled = true;
|
||||
}
|
||||
return false;
|
||||
else if ( !maps\so\zm_common\_zm_utility::is_player_valid( self ) )
|
||||
{
|
||||
self.obj_cancel_reason = "In laststand";
|
||||
goal_canceled = true;
|
||||
}
|
||||
if ( goal_canceled )
|
||||
{
|
||||
self notify( "goal" );
|
||||
}
|
||||
return goal_canceled;
|
||||
}
|
@ -28,8 +28,24 @@ init()
|
||||
::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,
|
||||
::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_objective( "powerup" );
|
||||
register_bot_objective( "revive" );
|
||||
register_bot_objective( "magicbox" );
|
||||
|
||||
if ( isDefined( level.chests ) && level.chests.size > 0 )
|
||||
{
|
||||
level thread watch_magicbox_objectives();
|
||||
}
|
||||
|
||||
//maps\bots\script_objectives\_obj_trackers;
|
||||
level thread store_powerups_dropped();
|
||||
@ -49,6 +65,11 @@ connected()
|
||||
|
||||
self.obj_postponed_reason = "";
|
||||
self.obj_cancel_reason = "";
|
||||
|
||||
self.obj_history = [];
|
||||
self.bot_obj_history_max_entries = 20;
|
||||
self.bot_obj_history_index = 0;
|
||||
self.bot_obj_history_prev_index = 0;
|
||||
}
|
||||
|
||||
spawned()
|
||||
|
@ -61,7 +61,7 @@ free_revive_objective_when_needed()
|
||||
wait 0.05;
|
||||
}
|
||||
|
||||
free_bot_objective( "revive", self );
|
||||
free_bot_objective( "revive", self, id );
|
||||
}
|
||||
|
||||
bot_valid_pump()
|
||||
@ -79,11 +79,11 @@ bot_valid_pump()
|
||||
if ( isDefined( self ) )
|
||||
{
|
||||
self notify( "bot_in_invalid_state" );
|
||||
self clear_objective_for_bot();
|
||||
self bot_clear_objective();
|
||||
}
|
||||
else if ( isDefined( obj_sav ) )
|
||||
{
|
||||
set_bot_global_shared_objective_owner_by_ent( obj_sav.group, obj_sav.target_ent, undefined );
|
||||
//set_bot_global_shared_objective_owner_by_ent( obj_sav.group, obj_sav.target_ent, undefined );
|
||||
}
|
||||
|
||||
while ( isDefined( self ) && !maps\so\zm_common\_zm_utility::is_player_valid( self ) )
|
||||
@ -135,14 +135,34 @@ bot_objective_inaccessible_pump()
|
||||
}
|
||||
}
|
||||
|
||||
watch_magicbox_objectives()
|
||||
{
|
||||
level endon( "end_game" );
|
||||
|
||||
level waittill( "connected", player );
|
||||
|
||||
prev_magicbox = maps\so\zm_common\_zm_magicbox::get_active_magicbox();
|
||||
while ( true )
|
||||
{
|
||||
cur_magicbox = maps\so\zm_common\_zm_magicbox::get_active_magicbox();
|
||||
if ( prev_magicbox != cur_magicbox )
|
||||
{
|
||||
add_possible_bot_objective( "magicbox", cur_magicbox, false );
|
||||
free_bot_objective( "magicbox", prev_magicbox );
|
||||
prev_magicbox = cur_magicbox;
|
||||
}
|
||||
wait 1;
|
||||
}
|
||||
}
|
||||
|
||||
bot_on_powerup_grab( powerup )
|
||||
{
|
||||
bot_objective_print( "powerup", powerup, "Bot <" + self.playername + "> bot grabbed powerup" );
|
||||
bot_objective_print( "powerup", powerup getEntityNumber(), "Bot <" + self.playername + "> grabbed powerup" );
|
||||
self.successfully_grabbed_powerup = true;
|
||||
}
|
||||
|
||||
bot_on_revive_success( revivee )
|
||||
{
|
||||
bot_objective_print( "revive", revivee, "Bot <" + self.playername + "> bot revived <" + revivee.playername + ">" );
|
||||
bot_objective_print( "revive", revivee getEntityNumber(), "Bot <" + self.playername + "> revived <" + revivee.playername + ">" );
|
||||
self.successfully_revived_player = true;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user