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

@ -1,9 +1,9 @@
#include common_scripts\utility; #include common_scripts\utility;
#include maps\_utility; #include maps\_utility;
#include maps\_zombiemode_utility; #include maps\so\zm_common\_zm_utility;
#include scripts\sp\bots\bot_actions_common; #include scripts\sp\bots\bot_actions_common;
#include scripts\sp\bots\bot_objective_common;
#include scripts\sp\bots\bot_difficulty_presets_common; #include scripts\sp\bots\bot_difficulty_presets_common;
#include scripts\sp\bots\bot_personality_presets_common; #include scripts\sp\bots\bot_personality_presets_common;
#include scripts\sp\bots\actions\combat; #include scripts\sp\bots\actions\combat;
@ -12,9 +12,8 @@
main() main()
{ {
//3 separate bot think threads
//Objective group is for things to go to usually allowing the bot to kill zombies on the way and survive as normal //Objective group is for things to go to usually allowing the bot to kill zombies on the way and survive as normal
//Objectives can be canceled/postponed by combat thread, movement thread or by other objectives //Objectives can be canceled/postponed by combat, movement or by other objectives
register_bot_action( "objective", "magicbox", ::bot_magicbox_purchase, ::bot_magicbox_process_order, ::bot_should_purchase_magicbox, ::bot_check_complete_magicbox, ::bot_set_complete_magicbox, ::bot_magicbox_purchase_on_completion, ::bot_magicbox_purchase_should_cancel, ::bot_magicbox_purchase_on_cancel, ::bot_magicbox_purchase_should_postpone, ::bot_magicbox_purchase_on_postpone, ::bot_magicbox_purchase_priority ); register_bot_action( "objective", "magicbox", ::bot_magicbox_purchase, ::bot_magicbox_process_order, ::bot_should_purchase_magicbox, ::bot_check_complete_magicbox, ::bot_set_complete_magicbox, ::bot_magicbox_purchase_on_completion, ::bot_magicbox_purchase_should_cancel, ::bot_magicbox_purchase_on_cancel, ::bot_magicbox_purchase_should_postpone, ::bot_magicbox_purchase_on_postpone, ::bot_magicbox_purchase_priority );
register_bot_action( "objective", "wallbuy", ::bot_wallbuy_purchase, ::bot_wallbuy_process_order, ::bot_should_purchase_wallbuy, ::bot_check_complete_wallbuy, ::bot_set_complete_wallbuy, ::bot_wallbuy_purchase_on_completion, ::bot_wallbuy_purchase_should_cancel, ::bot_wallbuy_purchase_on_cancel, ::bot_wallbuy_purchase_should_postpone, ::bot_wallbuy_purchase_on_postpone, ::bot_wallbuy_purchase_priority ); register_bot_action( "objective", "wallbuy", ::bot_wallbuy_purchase, ::bot_wallbuy_process_order, ::bot_should_purchase_wallbuy, ::bot_check_complete_wallbuy, ::bot_set_complete_wallbuy, ::bot_wallbuy_purchase_on_completion, ::bot_wallbuy_purchase_should_cancel, ::bot_wallbuy_purchase_on_cancel, ::bot_wallbuy_purchase_should_postpone, ::bot_wallbuy_purchase_on_postpone, ::bot_wallbuy_purchase_priority );
register_bot_action( "objective", "wallbuyammo", ::bot_wallbuy_ammo_purchase, ::bot_wallbuyammo_process_order, ::bot_should_purchase_wallbuy_ammo, ::bot_check_complete_wallbuy_ammo, ::bot_set_complete_wallbuy_ammo, ::bot_wallbuy_ammo_purchase_on_completion, ::bot_wallbuy_ammo_purchase_should_cancel, ::bot_wallbuy_ammo_purchase_on_cancel, ::bot_wallbuy_ammo_purchase_should_postpone, ::bot_wallbuy_ammo_purchase_on_postpone, ::bot_wallbuy_ammo_purchase_priority ); register_bot_action( "objective", "wallbuyammo", ::bot_wallbuy_ammo_purchase, ::bot_wallbuyammo_process_order, ::bot_should_purchase_wallbuy_ammo, ::bot_check_complete_wallbuy_ammo, ::bot_set_complete_wallbuy_ammo, ::bot_wallbuy_ammo_purchase_on_completion, ::bot_wallbuy_ammo_purchase_should_cancel, ::bot_wallbuy_ammo_purchase_on_cancel, ::bot_wallbuy_ammo_purchase_should_postpone, ::bot_wallbuy_ammo_purchase_on_postpone, ::bot_wallbuy_ammo_purchase_priority );
@ -24,12 +23,12 @@ main()
register_bot_action( "objective", "trap", ::bot_trap_purchase, ::bot_trap_process_order, ::bot_should_purchase_trap, ::bot_check_complete_trap_purchase, ::bot_set_complete_trap_purchase, ::bot_trap_purchase_on_completion, ::bot_trap_purchase_should_cancel, ::bot_trap_purchase_on_cancel, ::bot_trap_purchase_should_postpone, ::bot_trap_purchase_on_postpone, ::bot_trap_purchase_priority ); register_bot_action( "objective", "trap", ::bot_trap_purchase, ::bot_trap_process_order, ::bot_should_purchase_trap, ::bot_check_complete_trap_purchase, ::bot_set_complete_trap_purchase, ::bot_trap_purchase_on_completion, ::bot_trap_purchase_should_cancel, ::bot_trap_purchase_on_cancel, ::bot_trap_purchase_should_postpone, ::bot_trap_purchase_on_postpone, ::bot_trap_purchase_priority );
register_bot_action( "objective", "packapunch", ::bot_packapunch_purchase, ::bot_packapunch_process_order, ::bot_should_purchase_packapunch, ::bot_check_complete_packapunch_purchase, ::bot_set_complete_packapunch_purchase, ::bot_packapunch_purchase_on_completion, ::bot_packapunch_purchase_should_cancel, ::bot_packapunch_purchase_on_cancel, ::bot_packapunch_purchase_should_postpone, ::bot_packapunch_purchase_on_postpone, ::bot_packapunch_purchase_priority ); register_bot_action( "objective", "packapunch", ::bot_packapunch_purchase, ::bot_packapunch_process_order, ::bot_should_purchase_packapunch, ::bot_check_complete_packapunch_purchase, ::bot_set_complete_packapunch_purchase, ::bot_packapunch_purchase_on_completion, ::bot_packapunch_purchase_should_cancel, ::bot_packapunch_purchase_on_cancel, ::bot_packapunch_purchase_should_postpone, ::bot_packapunch_purchase_on_postpone, ::bot_packapunch_purchase_priority );
register_bot_action( "objective", "revive", ::bot_revive_player, ::bot_revive_process_order, ::bot_should_revive_player, ::bot_check_complete_revive_player, ::bot_set_complete_revive_player, ::bot_revive_player_on_completion, ::bot_revive_player_should_cancel, ::bot_revive_player_on_cancel, ::bot_revive_player_should_postpone, ::bot_revive_player_on_postpone, ::bot_revive_player_priority ); register_bot_action( "objective", "revive", ::bot_revive_player, ::bot_revive_process_order, ::bot_should_revive_player, ::bot_check_complete_revive_player, ::bot_set_complete_revive_player, ::bot_revive_player_on_completion, ::bot_revive_player_should_cancel, ::bot_revive_player_on_cancel, ::bot_revive_player_should_postpone, ::bot_revive_player_on_postpone, ::bot_revive_player_priority );
register_bot_action( "objective", "grabbuildable", ::bot_grab_buildable, ::bot_grab_buildable_process_order, ::bot_should_grab_buildable, ::bot_check_complete_grab_buildable, ::bot_set_complete_grab_buildable, ::bot_grab_buildable_on_completion, ::bot_grab_buildable_should_cancel, ::bot_grabbuild_buildable_on_cancel, ::bot_grab_buildable_should_postpone, ::bot_grab_buildable_on_postpone, ::bot_grab_buildable_priority ); //register_bot_action( "objective", "grabbuildable", ::bot_grab_buildable, ::bot_grab_buildable_process_order, ::bot_should_grab_buildable, ::bot_check_complete_grab_buildable, ::bot_set_complete_grab_buildable, ::bot_grab_buildable_on_completion, ::bot_grab_buildable_should_cancel, ::bot_grabbuild_buildable_on_cancel, ::bot_grab_buildable_should_postpone, ::bot_grab_buildable_on_postpone, ::bot_grab_buildable_priority );
register_bot_action( "objective", "buildbuildable", ::bot_build_buildable, ::bot_build_buildable_process_order, ::bot_should_build_buildable, ::bot_check_complete_build_buildable, ::bot_set_complete_build_buildable, ::bot_build_buildable_on_completion, ::bot_build_buildable_should_cancel, ::bot_build_buildable_on_cancel, ::bot_build_buildable_should_postpone, ::bot_build_buildable_on_postpone, ::bot_build_buildable_priority ); //register_bot_action( "objective", "buildbuildable", ::bot_build_buildable, ::bot_build_buildable_process_order, ::bot_should_build_buildable, ::bot_check_complete_build_buildable, ::bot_set_complete_build_buildable, ::bot_build_buildable_on_completion, ::bot_build_buildable_should_cancel, ::bot_build_buildable_on_cancel, ::bot_build_buildable_should_postpone, ::bot_build_buildable_on_postpone, ::bot_build_buildable_priority );
register_bot_action( "objective", "part", ::bot_grab_part, ::bot_part_process_order, ::bot_should_grab_part, ::bot_check_complete_grab_part, ::bot_set_complete_grab_part, ::bot_part_on_completion, ::bot_part_should_cancel, ::bot_part_on_cancel, ::bot_part_should_postpone, ::bot_part_on_postpone, ::bot_part_priority ); //register_bot_action( "objective", "part", ::bot_grab_part, ::bot_part_process_order, ::bot_should_grab_part, ::bot_check_complete_grab_part, ::bot_set_complete_grab_part, ::bot_part_on_completion, ::bot_part_should_cancel, ::bot_part_on_cancel, ::bot_part_should_postpone, ::bot_part_on_postpone, ::bot_part_priority );
register_bot_action( "objective", "powerup", ::bot_grab_powerup, ::bot_powerup_process_order, ::bot_should_grab_powerup, ::bot_check_complete_grab_powerup, ::bot_set_complete_grab_powerup, ::bot_powerup_on_completion, ::bot_powerup_should_cancel, ::bot_powerup_on_cancel, ::bot_powerup_should_postpone, ::bot_powerup_on_postpone, ::bot_powerup_priority ); register_bot_action( "objective", "powerup", ::bot_grab_powerup, ::bot_powerup_process_order, ::bot_should_grab_powerup, ::bot_check_complete_grab_powerup, ::bot_set_complete_grab_powerup, ::bot_powerup_on_completion, ::bot_powerup_should_cancel, ::bot_powerup_on_cancel, ::bot_powerup_should_postpone, ::bot_powerup_on_postpone, ::bot_powerup_priority );
//Combat thread actions //Combat actions
//These all need definitions //These all need definitions
register_bot_action( "combat", "aimatsinglenormalzombie", ::bot_aimatsinglenormalzombie, ::bot_aimatsinglenormalzombie_process_order ::bot_should_aimatsinglenormalzombie, ::bot_check_complete_aimatsinglenormalzombie, ::bot_set_complete_aimatsinglenormalzombie, ::bot_aimatsinglenormalzombie_on_completion, ::bot_aimatsinglenormalzombie_should_cancel, ::bot_aimatsinglenormalzombie_on_cancel, ::bot_aimatsinglenormalzombie_should_postpone, ::bot_aimatsinglenormalzombie_on_postpone, ::bot_aimatsinglenormalzombie_priority ); register_bot_action( "combat", "aimatsinglenormalzombie", ::bot_aimatsinglenormalzombie, ::bot_aimatsinglenormalzombie_process_order ::bot_should_aimatsinglenormalzombie, ::bot_check_complete_aimatsinglenormalzombie, ::bot_set_complete_aimatsinglenormalzombie, ::bot_aimatsinglenormalzombie_on_completion, ::bot_aimatsinglenormalzombie_should_cancel, ::bot_aimatsinglenormalzombie_on_cancel, ::bot_aimatsinglenormalzombie_should_postpone, ::bot_aimatsinglenormalzombie_on_postpone, ::bot_aimatsinglenormalzombie_priority );
register_bot_action( "combat", "shootsinglenormalzombie", ::bot_shootsinglenormalzombie, ::bot_shootsinglenormalzombie_process_order ::bot_should_shootsinglenormalzombie, ::bot_check_complete_shootsinglenormalzombie, ::bot_set_complete_shootsinglenormalzombie, ::bot_shootsinglenormalzombie_on_completion, ::bot_shootsinglenormalzombie_should_cancel, ::bot_shootsinglenormalzombie_on_cancel, ::bot_shootsinglenormalzombie_should_postpone, ::bot_shootsinglenormalzombie_on_postpone, ::bot_shootsinglenormalzombie_priority ); register_bot_action( "combat", "shootsinglenormalzombie", ::bot_shootsinglenormalzombie, ::bot_shootsinglenormalzombie_process_order ::bot_should_shootsinglenormalzombie, ::bot_check_complete_shootsinglenormalzombie, ::bot_set_complete_shootsinglenormalzombie, ::bot_shootsinglenormalzombie_on_completion, ::bot_shootsinglenormalzombie_should_cancel, ::bot_shootsinglenormalzombie_on_cancel, ::bot_shootsinglenormalzombie_should_postpone, ::bot_shootsinglenormalzombie_on_postpone, ::bot_shootsinglenormalzombie_priority );
@ -40,7 +39,7 @@ main()
register_bot_action( "combat", "shootmultipledogzombies", ::bot_shootmultipledogzombies, ::bot_shootmultipledogzombies_process_order ::bot_should_shootmultipledogzombies, ::bot_check_complete_shootmultipledogzombies, ::bot_set_complete_shootmultipledogzombies, ::bot_shootmultipledogzombies_on_completion, ::bot_shootmultipledogzombies_should_cancel, ::bot_shootmultipledogzombies_on_cancel, ::bot_shootmultipledogzombies_should_postpone, ::bot_shootmultipledogzombies_on_postpone, ::bot_shootmultipledogzombies_priority ); register_bot_action( "combat", "shootmultipledogzombies", ::bot_shootmultipledogzombies, ::bot_shootmultipledogzombies_process_order ::bot_should_shootmultipledogzombies, ::bot_check_complete_shootmultipledogzombies, ::bot_set_complete_shootmultipledogzombies, ::bot_shootmultipledogzombies_on_completion, ::bot_shootmultipledogzombies_should_cancel, ::bot_shootmultipledogzombies_on_cancel, ::bot_shootmultipledogzombies_should_postpone, ::bot_shootmultipledogzombies_on_postpone, ::bot_shootmultipledogzombies_priority );
register_bot_action( "combat", "meleesingledogzombie", ::bot_meleesingledogzombie, ::bot_meleesingledogzombie_process_order ::bot_should_meleesingledogzombie, ::bot_check_complete_meleesingledogzombie, ::bot_set_complete_meleesingledogzombie, ::bot_meleesingledogzombie_on_completion, ::bot_meleesingledogzombie_should_cancel, ::bot_meleesingledogzombie_on_cancel, ::bot_meleesingledogzombie_should_postpone, ::bot_meleesingledogzombie_on_postpone, ::bot_meleesingledogzombie_priority ); register_bot_action( "combat", "meleesingledogzombie", ::bot_meleesingledogzombie, ::bot_meleesingledogzombie_process_order ::bot_should_meleesingledogzombie, ::bot_check_complete_meleesingledogzombie, ::bot_set_complete_meleesingledogzombie, ::bot_meleesingledogzombie_on_completion, ::bot_meleesingledogzombie_should_cancel, ::bot_meleesingledogzombie_on_cancel, ::bot_meleesingledogzombie_should_postpone, ::bot_meleesingledogzombie_on_postpone, ::bot_meleesingledogzombie_priority );
//Movement thread actions //Movement actions
//These all need definitions //These all need definitions
register_bot_action( "movement", "movetoobjective", ::bot_movetoobjective, ::bot_movetoobjective_process_order ::bot_should_movetoobjective, ::bot_check_complete_movetoobjective, ::bot_set_complete_movetoobjective, ::bot_movetoobjective_on_completion, ::bot_movetoobjective_should_cancel, ::bot_movetoobjective_on_cancel, ::bot_movetoobjective_should_postpone, ::bot_movetoobjective_on_postpone, ::bot_movetoobjective_priority ); register_bot_action( "movement", "movetoobjective", ::bot_movetoobjective, ::bot_movetoobjective_process_order ::bot_should_movetoobjective, ::bot_check_complete_movetoobjective, ::bot_set_complete_movetoobjective, ::bot_movetoobjective_on_completion, ::bot_movetoobjective_should_cancel, ::bot_movetoobjective_on_cancel, ::bot_movetoobjective_should_postpone, ::bot_movetoobjective_on_postpone, ::bot_movetoobjective_priority );
register_bot_action( "movement", "train", ::bot_train, ::bot_train_process_order ::bot_should_train, ::bot_check_complete_train, ::bot_set_complete_train, ::bot_train_on_completion, ::bot_train_should_cancel, ::bot_train_on_cancel, ::bot_train_should_postpone, ::bot_train_on_postpone, ::bot_train_priority ); register_bot_action( "movement", "train", ::bot_train, ::bot_train_process_order ::bot_should_train, ::bot_check_complete_train, ::bot_set_complete_train, ::bot_train_on_completion, ::bot_train_should_cancel, ::bot_train_on_cancel, ::bot_train_should_postpone, ::bot_train_on_postpone, ::bot_train_priority );
@ -84,14 +83,100 @@ main()
level.zbot_path_nodes = getAllNodes(); level.zbot_path_nodes = getAllNodes();
level thread store_powerups_dropped();
level thread spawn_bots(); level thread spawn_bots();
level thread on_player_connect();
}
on_player_connect()
{
i = 0;
while ( true )
{
level waittill( "connected", player );
player.id = i;
i++;
}
} }
//TODO: Make postponing save the settings for the action so when the action is being executed again the bot tries to do/get the same thing //TODO: Make postponing save the settings for the action so when the action is being executed again the bot tries to do/get the same thing
//TODO: Make global canceling and postponing functionality
//TODO: Make shared global objective and normal objective globs work
init() init()
{ {
if ( isDefined( level.chests ) && level.chests.size > 0 )
{
for ( i = 0; i < level.chests.size; i++ )
{
level.chests[ i ].id = i;
}
level thread watch_magicbox_objectives();
}
weapon_spawns = GetEntArray( "weapon_upgrade", "targetname" );
if ( isDefined( weapon_spawns ) && weapon_spawns.size > 0 )
{
for( i = 0; i < weapon_spawns.size; i++ )
{
weapon_spawns[ i ].id = i;
add_possible_bot_objective( "wallbuy", i, false, weapon_spawns[ i ] );
add_possible_bot_objective( "wallbuyammo", i, false, weapon_spawns[ i ] );
}
}
vending_triggers = GetEntArray( "zombie_vending", "targetname" );
if ( isDefined( vending_triggers ) && vending_triggers.size > 0 )
{
for ( i = 0; i < vending_triggers.size; i++ )
{
vending_triggers[ i ].id = i;
add_possible_bot_objective( "perk", i, false, vending_triggers[ i ] );
}
}
//TODO: See if its possible to automatically detect if a door is blocking an objective
zombie_doors = GetEntArray( "zombie_door", "targetname" );
if ( isDefined( zombie_doors ) && zombie_doors.size > 0 )
{
for ( i = 0; i < zombie_doors.size; i++ )
{
zombie_doors[ i ].id = i;
add_possible_bot_objective( "door", i, true, zombie_doors[ i ] );
}
level thread watch_door_objectives( zombie_doors );
}
zombie_debris = GetEntArray( "zombie_debris", "targetname" );
if ( isDefined( zombie_debris ) && zombie_debris.size > 0 )
{
for ( i = 0; i < zombie_debris.size; i++ )
{
zombie_debris.id = i;
add_possible_bot_objective( "debris", i, true, zombie_debris[ i ] );
}
level thread watch_debris_objectives( zombie_debris );
}
vending_upgrade_trigger = GetEntArray("zombie_vending_upgrade", "targetname");
if ( isDefined( vending_upgrade_trigger ) && vending_upgrade_trigger.size > 0 )
{
for ( i = 0; i < vending_upgrade_trigger.size; i++ )
{
vending_upgrade_trigger[ i ].id = i;
add_possible_bot_objective( "packapunch", i, false, vending_upgrade_trigger[ i ] );
}
}
level thread watch_for_downed_players();
level thread store_powerups_dropped();
parse_bot_weapon_stats_from_table(); parse_bot_weapon_stats_from_table();
} }
@ -123,17 +208,13 @@ spawn_bots()
bot.action_queue[ "combat" ] = []; bot.action_queue[ "combat" ] = [];
bot.action_queue[ "movement" ] = []; bot.action_queue[ "movement" ] = [];
bot register_action_queue_actions(); bot register_action_queue_actions();
bot thread bot_objective_think(); bot thread bot_think();
bot thread bot_combat_think();
bot thread bot_movement_think();
bot_count++; bot_count++;
} }
} }
bot_objective_think() bot_think()
{ {
group_name = "objective";
level endon( "end_game" ); level endon( "end_game" );
self endon( "disconnect" ); self endon( "disconnect" );
@ -148,33 +229,27 @@ bot_objective_think()
wait 1; wait 1;
continue; continue;
} }
group_name = "objective";
self pick_actions_to_add_to_queue( group_name ); self pick_actions_to_add_to_queue( group_name );
self process_next_queued_action(); self process_next_queued_action();
self check_if_action_is_completed_in_group( group_name ); self check_if_action_is_completed_in_group( group_name );
self check_if_action_should_be_postponed_in_group( group_name ); self check_if_action_should_be_postponed_in_group( group_name );
self check_if_action_should_be_canceled_in_group( group_name ); self check_if_action_should_be_canceled_in_group( group_name );
}
}
bot_combat_think() group_name = "movement";
{
group_name = "combat";
level endon( "end_game" ); self pick_actions_to_add_to_queue( group_name );
self endon( "disconnect" ); self process_next_queued_action();
self waittill( "spawned_player" ); self check_if_action_is_completed_in_group( group_name );
self check_if_action_should_be_postponed_in_group( group_name );
self check_if_action_should_be_canceled_in_group( group_name );
group_name = "combat";
while ( true )
{
wait 0.25;
if ( !bot_valid( self ) )
{
self.action_queue = [];
wait 1;
continue;
}
self pick_actions_to_add_to_queue( group_name ); self pick_actions_to_add_to_queue( group_name );
self process_next_queued_action(); self process_next_queued_action();
@ -221,11 +296,53 @@ bot_movement_think()
} }
} }
watch_door_objectives( zombie_doors )
{
level endon( "end_game" );
for ( doors_opened_count = 0; doors_opened_count < zombie_doors.size; doors_opened_count++ )
{
level waittill( "door_opened", door, player );
free_bot_objective( "door", door.id );
}
}
watch_debris_objectives( zombie_debris )
{
level endon( "end_game" );
for ( debris_opened_count = 0; debris_opened_count < zombie_debris.size; debris_opened_count++ )
{
level waittill( "door_opened", debris, player );
free_bot_objective( "door", debris.id );
}
}
watch_magicbox_objectives()
{
level endon( "end_game" );
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.id, false, cur_magicbox );
free_bot_objective( "magicbox", prev_magicbox.id );
prev_magicbox = cur_magicbox;
}
wait 1;
}
}
store_powerups_dropped() store_powerups_dropped()
{ {
level endon( "end_game" );
level.zbots_powerups = []; level.zbots_powerups = [];
level.zbots_powerups_targeted_for_grab = []; level.zbots_powerups_targeted_for_grab = [];
id_num = 0; id = 0;
while ( true ) while ( true )
{ {
level waittill( "powerup_dropped", powerup ); level waittill( "powerup_dropped", powerup );
@ -233,11 +350,54 @@ store_powerups_dropped()
{ {
continue; continue;
} }
powerup.id = id;
add_possible_bot_objective( "powerup", id, true, powerup );
assign_priority_to_powerup( powerup ); assign_priority_to_powerup( powerup );
level.zbots_powerups = sort_array_by_priority_field( level.zbots_powerups, powerup ); level.zbots_powerups = sort_array_by_priority_field( level.zbots_powerups, powerup );
id++;
} }
} }
free_powerups_dropped()
{
level endon( "end_game" );
while ( true )
{
level waittill( "powerup_freed", powerup );
free_bot_objective( "powerup", powerup.id );
}
}
watch_for_downed_players()
{
level endon( "end_game" );
while ( true )
{
level waittill( "player_entered_laststand", player );
if ( !isDefined( player ) )
{
continue;
}
add_possible_bot_objective( "revive", player.id, true, player );
player thread free_revive_objective_when_needed();
}
}
free_revive_objective_when_needed()
{
level endon( "end_game" );
id = self.id;
while ( isDefined( self ) && isDefined( self.revivetrigger ) )
{
wait 0.05;
}
free_bot_objective( "revive", id );
}
doBotMovement_loop() doBotMovement_loop()
{ {
move_To = self.bot.moveTo; move_To = self.bot.moveTo;

View File

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

View File

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

View File

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

View File

@ -3,43 +3,49 @@
*/ */
#include common_scripts\utility; #include common_scripts\utility;
#include maps\_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 ) ) if ( !isDefined( level.zbots_actions ) )
{ {
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(); if ( !isDefined( level.zbots_actions[ group_name ][ action_name ] ) )
level.zbots_actions[ action_name ].group = group; {
level.zbots_actions[ action_name ].action = action_func; level.zbots_actions[ group_name ][ action_name ] = spawnStruct();
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[ group_name ][ action_name ].action = action_func;
level.zbots_actions[ action_name ].check_if_complete_func = check_if_complete_func; level.zbots_actions[ group_name ][ action_name ].should_do_func = should_do_func;
level.zbots_actions[ action_name ].set_complete_func = set_complete_func; level.zbots_actions[ group_name ][ action_name ].action_process_order_func = action_process_order_func;
level.zbots_actions[ action_name ].on_completion_func = on_completion_func; level.zbots_actions[ group_name ][ action_name ].check_if_complete_func = check_if_complete_func;
level.zbots_actions[ action_name ].should_cancel_func = should_cancel_func; level.zbots_actions[ group_name ][ action_name ].set_complete_func = set_complete_func;
level.zbots_actions[ action_name ].on_cancel_func = on_cancel_func; level.zbots_actions[ group_name ][ action_name ].on_completion_func = on_completion_func;
level.zbots_actions[ action_name ].should_postpone_func = should_postpone_func; level.zbots_actions[ group_name ][ action_name ].should_cancel_func = should_cancel_func;
level.zbots_actions[ action_name ].on_postpone_func = on_postpone_func; level.zbots_actions[ group_name ][ action_name ].on_cancel_func = on_cancel_func;
level.zbots_actions[ action_name ].priority_func = priority_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() initialize_bot_actions_queue()
{ {
keys = getArrayKeys( level.zbots_actions ); group_keys = getArrayKeys( level.zbots_actions );
for ( i = 0; i < keys.size; i++ ) 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 ) ) 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 ] = [];
} }
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 ].postponed = false;
self.zbot_actions_in_queue[ group_name ][ action_name ].canceled = false; self.zbot_actions_in_queue[ group_name ][ action_name ].canceled = false;
self.zbot_actions_in_queue[ group_name ][ action_name ].queued = 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 ].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 ].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.action_queue[ group_name ][ 0 ] = undefined;
self thread [[ self.action_queue[ group_name ][ 0 ].on_completion_func ]](); 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 ].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 ].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.action_queue[ group_name ][ 0 ] = undefined;
self thread [[ self.action_queue[ group_name ][ 0 ].on_cancel_func ]](); 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 ) 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 //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 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++ ) 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.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 common_scripts\utility;
#include maps\_utility; #include maps\_utility;
#include maps\_zombiemode_utility; #include maps\so\zm_common\_zm_utility;
register_stats_for_bot_weapon( weapon, score ) register_stats_for_bot_weapon( weapon, score )
{ {