Add missing return values to check_complete functions.

Fix mistakes in scripts. Create bot objective glob and add objectives on map to the glob. Don't create 3 separate threads for bot think.
This commit is contained in:
JezuzLizard
2023-03-27 21:38:25 -07:00
parent 872630b7e2
commit ae7cfb991a
7 changed files with 374 additions and 87 deletions

View File

@ -15,7 +15,7 @@ bot_should_aimatsinglenormalzombie()
bot_check_complete_aimatsinglenormalzombie()
{
return false;
}
bot_set_complete_aimatsinglenormalzombie()
@ -70,7 +70,7 @@ bot_should_shootsinglenormalzombie()
bot_check_complete_shootsinglenormalzombie()
{
return false;
}
bot_set_complete_shootsinglenormalzombie()
@ -125,7 +125,7 @@ bot_should_aimatmultiplenormalzombies()
bot_check_complete_aimatmultiplenormalzombies()
{
return false;
}
bot_set_complete_aimatmultiplenormalzombies()
@ -180,7 +180,7 @@ bot_should_shootmultiplenormalzombies()
bot_check_complete_shootmultiplenormalzombies()
{
return false;
}
bot_set_complete_shootmultiplenormalzombies()
@ -235,7 +235,7 @@ bot_should_meleesinglenormalzombie()
bot_check_complete_meleesinglenormalzombie()
{
return false;
}
bot_set_complete_meleesinglenormalzombie()
@ -290,7 +290,7 @@ bot_should_shootsingledogzombie()
bot_check_complete_shootsingledogzombie()
{
return false;
}
bot_set_complete_shootsingledogzombie()
@ -345,7 +345,7 @@ bot_should_shootmultipledogzombies()
bot_check_complete_shootmultipledogzombies()
{
return false;
}
bot_set_complete_shootmultipledogzombies()
@ -400,7 +400,7 @@ bot_should_meleesingledogzombie()
bot_check_complete_meleesingledogzombie()
{
return false;
}
bot_set_complete_meleesingledogzombie()

View File

@ -10,17 +10,21 @@ bot_movetoobjective_process_order()
bot_should_movetoobjective()
{
if ( isDefined( self.action_queue[ "objective" ][ 0 ] ) )
{
return true;
}
return false;
}
bot_check_complete_movetoobjective()
{
return self.zbot_actions_in_queue[ "movement" ][ "movetoobjective" ].completed;
}
bot_set_complete_movetoobjective()
{
self.zbot_actions_in_queue[ "movement" ][ "movetoobjective" ].completed = true;
}
bot_movetoobjective_on_completion()
@ -40,6 +44,10 @@ bot_movetoobjective_on_cancel()
bot_movetoobjective_should_postpone()
{
if ( self bot_should_flee() )
{
return true;
}
return false;
}
@ -70,7 +78,7 @@ bot_should_train()
bot_check_complete_train()
{
return false;
}
bot_set_complete_train()
@ -125,7 +133,7 @@ bot_should_camp()
bot_check_complete_camp()
{
return false;
}
bot_set_complete_camp()
@ -180,7 +188,7 @@ bot_should_flee()
bot_check_complete_flee()
{
return false;
}
bot_set_complete_flee()

View File

@ -47,7 +47,7 @@ bot_should_purchase_magicbox()
bot_check_complete_magicbox()
{
return false;
}
bot_set_complete_magicbox()
@ -116,7 +116,7 @@ bot_should_purchase_wallbuy()
bot_check_complete_wallbuy()
{
return false;
}
bot_set_complete_wallbuy()
@ -171,7 +171,7 @@ bot_should_purchase_wallbuy_ammo()
bot_check_complete_wallbuy_ammo()
{
return false;
}
bot_set_complete_wallbuy_ammo()
@ -226,7 +226,7 @@ bot_should_purchase_perk()
bot_check_complete_perk_purchase()
{
return false;
}
bot_set_complete_perk_purchase()
@ -281,7 +281,7 @@ bot_should_purchase_door()
bot_check_complete_door_purchase()
{
return false;
}
bot_set_complete_door_purchase()
@ -336,7 +336,7 @@ bot_should_purchase_debris()
bot_check_complete_debris_purchase()
{
return false;
}
bot_set_complete_debris_purchase()
@ -391,7 +391,7 @@ bot_should_purchase_trap()
bot_check_complete_trap_purchase()
{
return false;
}
bot_set_complete_trap_purchase()
@ -446,7 +446,7 @@ bot_should_purchase_packapunch()
bot_check_complete_packapunch_purchase()
{
return false;
}
bot_set_complete_packapunch_purchase()
@ -501,7 +501,7 @@ bot_should_revive_player()
bot_check_complete_revive_player()
{
return false;
}
bot_set_complete_revive_player()
@ -556,7 +556,7 @@ bot_should_grab_buildable()
bot_check_complete_grab_buildable()
{
return false;
}
bot_set_complete_grab_buildable()
@ -611,7 +611,7 @@ bot_should_build_buildable()
bot_check_complete_build_buildable()
{
return false;
}
bot_set_complete_build_buildable()
@ -676,7 +676,7 @@ bot_part_should_cancel()
bot_check_complete_grab_part()
{
return false;
}
bot_set_complete_grab_part()
@ -773,7 +773,7 @@ bot_should_grab_powerup()
bot_check_complete_grab_powerup()
{
return false;
}
bot_set_complete_grab_powerup()

View File

@ -3,43 +3,49 @@
*/
#include common_scripts\utility;
#include maps\_utility;
#include maps\_zombiemode_utility;
#include maps\so\zm_common\_zm_utility;
register_bot_action( group, action_name, action_func, action_process_order_func, should_do_func, check_if_complete_func, set_complete_func, on_completion_func, should_cancel_func, on_cancel_func, should_postpone_func, on_postpone_func, priority_func )
register_bot_action( group_name, action_name, action_func, action_process_order_func, should_do_func, check_if_complete_func, set_complete_func, on_completion_func, should_cancel_func, on_cancel_func, should_postpone_func, on_postpone_func, priority_func )
{
if ( !isDefined( level.zbots_actions ) )
{
level.zbots_actions = [];
}
if ( !isDefined( level.zbots_actions[ action_name ] ) )
if ( !isDefined( level.zbots_actions[ group_name ] ) )
{
level.zbots_actions[ action_name ] = [];
level.zbots_actions[ group_name ] = [];
}
level.zbots_actions[ action_name ] = spawnStruct();
level.zbots_actions[ action_name ].group = group;
level.zbots_actions[ action_name ].action = action_func;
level.zbots_actions[ action_name ].should_do_func = should_do_func;
level.zbots_actions[ action_name ].action_process_order_func = action_process_order_func;
level.zbots_actions[ action_name ].check_if_complete_func = check_if_complete_func;
level.zbots_actions[ action_name ].set_complete_func = set_complete_func;
level.zbots_actions[ action_name ].on_completion_func = on_completion_func;
level.zbots_actions[ action_name ].should_cancel_func = should_cancel_func;
level.zbots_actions[ action_name ].on_cancel_func = on_cancel_func;
level.zbots_actions[ action_name ].should_postpone_func = should_postpone_func;
level.zbots_actions[ action_name ].on_postpone_func = on_postpone_func;
level.zbots_actions[ action_name ].priority_func = priority_func;
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 ].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 ].set_complete_func = set_complete_func;
level.zbots_actions[ group_name ][ action_name ].on_completion_func = on_completion_func;
level.zbots_actions[ group_name ][ action_name ].should_cancel_func = should_cancel_func;
level.zbots_actions[ group_name ][ action_name ].on_cancel_func = on_cancel_func;
level.zbots_actions[ group_name ][ action_name ].should_postpone_func = should_postpone_func;
level.zbots_actions[ group_name ][ action_name ].on_postpone_func = on_postpone_func;
level.zbots_actions[ group_name ][ action_name ].priority_func = priority_func;
}
initialize_bot_actions_queue()
{
keys = getArrayKeys( level.zbots_actions );
for ( i = 0; i < keys.size; i++ )
group_keys = getArrayKeys( level.zbots_actions );
for ( i = 0; i < group_keys.size; i++ )
{
self register_bot_objective_action_for_queue( keys[ i ], level.zbots_actions[ keys[ i ] ].group );
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( action_name )
register_bot_objective_action_for_queue( group_name, action_name )
{
if ( !isDefined( self.zbot_actions_in_queue ) )
{
@ -49,7 +55,10 @@ register_bot_objective_action_for_queue( action_name )
{
self.zbot_actions_in_queue[ group_name ] = [];
}
self.zbot_actions_in_queue[ group_name ][ action_name ] = spawnStruct();
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 ].canceled = false;
self.zbot_actions_in_queue[ group_name ][ action_name ].queued = false;
@ -91,6 +100,7 @@ wait_for_action_completion( group_name, action_name )
{
self.zbot_actions_in_queue[ group_name ][ self.action_queue[ group_name ][ 0 ].action_name ].postponed = false;
self.zbot_actions_in_queue[ group_name ][ self.action_queue[ group_name ][ 0 ].action_name ].queued = false;
self.zbot_actions_in_queue[ group_name ][ self.action_queue[ group_name ][ 0 ].action_name ].completed = false;
self.action_queue[ group_name ][ 0 ] = undefined;
self thread [[ self.action_queue[ group_name ][ 0 ].on_completion_func ]]();
}
@ -98,6 +108,7 @@ wait_for_action_completion( group_name, action_name )
{
self.zbot_actions_in_queue[ group_name ][ self.action_queue[ group_name ][ 0 ].action_name ].postponed = false;
self.zbot_actions_in_queue[ group_name ][ self.action_queue[ group_name ][ 0 ].action_name ].queued = false;
self.zbot_actions_in_queue[ group_name ][ self.action_queue[ group_name ][ 0 ].action_name ].completed = false;
self.action_queue[ group_name ][ 0 ] = undefined;
self thread [[ self.action_queue[ group_name ][ 0 ].on_cancel_func ]]();
}
@ -127,6 +138,8 @@ copy_default_action_settings_to_queue( group_name, action_name )
pick_actions_to_add_to_queue( group_name )
{
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
/*
@ -136,10 +149,6 @@ pick_actions_to_add_to_queue( group_name )
}
*/
action_keys = getArrayKeys( level.zbots_actions[ group_name ] );
action_keys = array_randomize( action_keys );
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 ]]() )

View File

@ -0,0 +1,110 @@
add_possible_bot_objective( objective_group, id, is_global_shared, target_ent )
{
if ( !isDefined( level.zbot_objective_glob ) )
{
level.zbot_objective_glob = [];
}
if ( !isDefined( level.zbot_objective_glob[ objective_group ] ) )
{
level.zbot_objective_glob[ objective_group ] = spawnStruct();
level.zbot_objective_glob[ objective_group ].active_objectives = [];
}
objective_struct = spawnStruct();
objective_struct.group = objective_group;
objective_struct.id = id;
objective_struct.is_global_shared = is_global_shared;
objective_struct.target_ent = target_ent;
objective_struct.owner = undefined;
level.zbot_objective_glob[ objective_group ].active_objectives[ "obj_id_" + id ] = objective_struct;
}
set_bot_objective_blocked_by_objective( primary_objective_group, primary_id, blocked_by_objective_group, blocked_by_id )
{
primary_active_objectives = level.zbot_objective_glob[ primary_objective_group ].active_objectives;
primary_objective = primary_active_objectives[ "obj_id_" + primary_id ];
primary_objective_exists = isDefined( primary_objective );
assert( primary_objective_exists, "Objective with " + primary_id + " id does not point to a objective in group " + primary_objective_group );
if ( !primary_objective_exists )
{
return;
}
if ( primary_objective_group == blocked_by_objective_group )
{
assert( primary_id != blocked_by_id, "Objective with " + primary_id + " id should not be the same as the blocked_by_id if the objectives are in the same group of " + primary_objective_group );
if ( primary_id == blocked_by_id )
{
return;
}
blocking_objective = primary_active_objectives[ "obj_id_" + blocked_by_id ];
blocking_objective_exists = isDefined( blocking_objective );
assert( blocking_objective_exists, "Objective with " + blocked_by_id + " id does not point to a objective in group " + blocked_by_objective_group );
if ( !blocking_objective_exists )
{
return;
}
primary_objective.blocking_objective = blocking_objective;
}
else
{
secondary_active_objectives = level.zbot_objective_glob[ blocked_by_objective_group ].active_objectives;
blocking_objective = secondary_active_objectives[ "obj_id_" + blocked_by_id ];
blocking_objective_exists = isDefined( blocking_objective );
assert( blocking_objective_exists, "Objective with " + blocked_by_id + " id does not point to a objective in group " + blocked_by_objective_group );
if ( !blocking_objective_exists )
{
return;
}
primary_objective.blocking_objective = blocking_objective;
}
}
set_bot_global_shared_objective_owner( objective_group, new_owner, id )
{
active_objectives = level.zbot_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;
}
assert( objective.is_global_shared, "Objective with " + id + " id number cannot be set an owner because is_global_shared field is false in group" + objective_group );
if ( !objective.is_global_shared )
{
return;
}
objective.owner = new_owner;
}
free_bot_objective( 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;
}
objective = undefined;
}

View File

@ -1,6 +1,6 @@
#include common_scripts\utility;
#include maps\_utility;
#include maps\_zombiemode_utility;
#include maps\so\zm_common\_zm_utility;
register_stats_for_bot_weapon( weapon, score )
{