Skip to content

Commit

Permalink
Fixes and improvements
Browse files Browse the repository at this point in the history
Closes #91
Closes #92
To test: #94
  • Loading branch information
smilz0 committed Jun 1, 2024
1 parent bc60f5d commit 74a587b
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 26 deletions.
Binary file modified out/Left4Bots2.vpk
Binary file not shown.
2 changes: 1 addition & 1 deletion root/addoninfo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
addonSteamAppID 550
addontitle "Left 4 Bots 2"
addonversion "2.1.1"
addonversion "2.1.2"
addonauthor "smilzo"
addonDescription "Improvements for the L4D2 survivor bots"
addonContent_Script 1
Expand Down
128 changes: 108 additions & 20 deletions root/scripts/vscripts/left4bots.nut
Original file line number Diff line number Diff line change
Expand Up @@ -849,52 +849,140 @@ IncludeScript("left4bots_settings");
// Valid enemies are common and special infected (including tank), witch excluded
::Left4Bots.FindBotNearestEnemy <- function (bot, orig, radius, minDot = 0.96)
{
local ret_array = [];

local botFacing = bot.EyeAngles().Forward();
local ret = null;
local minDist = radius;
local tracemask_others = Settings.tracemask_others;

// [NEW] Perhaps we could add `foreach (ent in Dominators)` here so SurvivorBots can prioritize killing special infected that are grabbing survivors if they are within radius.

foreach (ent in Specials)
{
if (ent.IsValid() && !ent.IsGhost())
{
local toEnt = ent.GetOrigin() - orig;
local dist = toEnt.Length();
toEnt.Norm();
if (dist < minDist && botFacing.Dot(toEnt) >= minDot && Left4Utils.CanTraceTo(bot, ent, tracemask_others))
local dist = toEnt.Norm();

if (dist < radius && botFacing.Dot(toEnt) >= minDot)
{
ret = ent;
minDist = dist;
ret_array.append([dist, ent]);
}
}
}
if (ret) // TODO: Just return the special if it's within a certain range?
return ret;


// [NEW] Sort the array from closest to farthest special infected so the `CanTraceTo` function doesn't have to perform as many traces.

ret_array.sort(function (a, b) {return a[0] - b[0]});

foreach (ret_data in ret_array)
{
local ret = ret_data[1];

if (ret && Left4Utils.CanTraceTo(bot, ret, tracemask_others))
{
return ret;
}
}

ret_array.clear();

//lxc kill raged Witch if no Specials nearby

foreach (witch in Witches)
{
// fix for https://github.com/smilz0/Left4Bots/issues/84
if (witch.IsValid() && NetProps.GetPropFloat(witch, "m_rage") >= 1.0 && (witch.GetOrigin() - orig).Length() <= radius && Left4Utils.CanTraceTo(bot, witch, tracemask_others))
return witch;
if (witch.IsValid() && NetProps.GetPropFloat(witch, "m_rage") >= 1.0)
{
local dist = (witch.GetOrigin() - orig).Length();
if (dist < radius)
{
ret_array.append([dist, witch]);
}
}
}


// [NEW] Sort the array from closest to farthest Witch so the `CanTraceTo` function doesn't have to perform as many traces.

ret_array.sort(function (a, b) {return a[0] - b[0]});

foreach (ret_data in ret_array)
{
local ret = ret_data[1];

if (ret && Left4Utils.CanTraceTo(bot, ret, tracemask_others))
{
return ret;
}
}

ret_array.clear();

foreach (tank in Tanks)
{
if (tank.IsValid() && !tank.IsIncapacitated() && NetProps.GetPropInt(tank, "m_lookatPlayer") >= 0) //Aggroed
{
local dist = (tank.GetOrigin() - orig).Length();
if (dist < radius)
{
ret_array.append([dist, tank]);
}
}
}

local tank = null;
local newRadius = radius;

// [NEW] Sort the array from closest to farthest common infected so the `CanTraceTo` function doesn't have to perform as many traces.

ret_array.sort(function (a, b) {return a[0] - b[0]});

foreach (ret_data in ret_array)
{
local ret = ret_data[1];

if (ret && Left4Utils.CanTraceTo(bot, ret, tracemask_others))
{
tank = ret;
//newRadius = radius < 120 ? radius : 120;
newRadius = ret_data[0];
break;
}
}

ret_array.clear();

// [NEW] Added Tanks to the list of targets for SurvivorBots to shoot so they don't take too long to react to its presence.

local ent = null;
while (ent = Entities.FindByClassnameWithin(ent, "infected", orig, minDist)) // If only we had a infected_spawned event for the commons...
while (ent = Entities.FindByClassnameWithin(ent, "infected", orig, newRadius)) // If only we had a infected_spawned event for the commons...
{
if (ent.IsValid() && NetProps.GetPropInt(ent, "m_lifeState") == 0)
{
local toEnt = ent.GetOrigin() - orig;
local dist = toEnt.Length();
toEnt.Norm();
local dist = toEnt.Norm();
//lxc ignore wandering infected
if (dist < minDist && botFacing.Dot(toEnt) >= minDot && (Settings.manual_attack_skill >= 3 || IsInfectedAngry(ent)) && Left4Utils.CanTraceTo(bot, ent, tracemask_others))
if (botFacing.Dot(toEnt) >= minDot && (Settings.manual_attack_skill >= 3 || IsInfectedAngry(ent)))
{
ret = ent;
minDist = dist;
ret_array.append([dist, ent]);
}
}
}
return ret;

// [NEW] Sort the array from closest to farthest Tank so the `CanTraceTo` function doesn't have to perform as many traces.

ret_array.sort(function (a, b) {return a[0] - b[0]});

foreach (ret_data in ret_array)
{
local ret = ret_data[1];

if (ret && Left4Utils.CanTraceTo(bot, ret, tracemask_others))
{
return ret;
}
}

return tank;
}

// Called when the bot's pick-up algorithm decides to pick the item up
Expand Down
14 changes: 10 additions & 4 deletions root/scripts/vscripts/left4bots_ai.nut
Original file line number Diff line number Diff line change
Expand Up @@ -3455,24 +3455,30 @@ enum AI_AIM_TYPE {
if (L4B.Settings.pause_debug)
Say(self, "[->]", false);

// https://github.com/smilz0/Left4Bots/issues/91
if (MovePos)
NeedMove = 2; // Refresh previous MOVE

if (MoveType == AI_MOVE_TYPE.Order && CurrentOrder.OrderType == "lead")
{
if (CurrentOrder.DestPos)
{
// If we are executing a "lead" order and, during the pause, we moved ahead of the next position, the last MOVE will take us backwards. Better finalize the order to re-calc the next position from here
BotFinalizeCurrentOrder();
}
else if (MovePos)
NeedMove = 2; // Refresh previous MOVE
// https://github.com/smilz0/Left4Bots/issues/91
// else if (MovePos)
// NeedMove = 2; // Refresh previous MOVE

if ((CurTime - L4B.LastLeadStartVocalize) >= L4B.Settings.lead_vocalize_interval)
{
L4B.SpeakRandomVocalize(self, L4B.VocalizerLeadStart, RandomFloat(0.4, 0.9));
L4B.LastLeadStartVocalize = CurTime;
}
}
else if (MovePos)
NeedMove = 2; // Refresh previous MOVE
// https://github.com/smilz0/Left4Bots/issues/91
// else if (MovePos)
// NeedMove = 2; // Refresh previous MOVE
}

//lxc
Expand Down
37 changes: 37 additions & 0 deletions root/scripts/vscripts/left4bots_defaults.nut
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,43 @@ witch_autocrown = 0";

// -------------------------------------------------------

// Default settings overrides for 'c1m4_atrium' in 'Advanced' difficulty
defaults["left4bots2/cfg/settings_c1m4_atrium_hard.txt"] <- @"close_saferoom_door_highres = 1
heal_interrupt_minhealth = 40
horde_nades_chance = 35
jockey_redirect_damage = 45
manual_attack_mindot = 0.90
manual_attack_skill = 2
shove_deadstop_chance = 100
spit_block_nav = 1
tank_molotov_chance = 50
tank_throw_survivors_mindistance = 250
throw_molotov = 0";

// Default settings overrides for 'c1m4_atrium' in 'Expert' difficulty
defaults["left4bots2/cfg/settings_c1m4_atrium_impossible.txt"] <- @"automation_autostart = 0
close_saferoom_door_all_chance = 0
close_saferoom_door_highres = 1
heal_interrupt_minhealth = 30
horde_nades_chance = 35
jockey_redirect_damage = 50
manual_attack_always = 1
manual_attack_mindot = 0.90
manual_attack_skill = 3
scavenge_max_bots = 1
shove_deadstop_chance = 100
signal_chat = 1
spit_block_nav = 1
tank_molotov_chance = 50
tank_throw_survivors_mindistance = 260
throw_molotov = 0
witch_autocrown = 0";

// Default settings overrides for 'c1m4_atrium' in the other difficulties
defaults["left4bots2/cfg/settings_c1m4_atrium.txt"] <- @"throw_molotov = 0";

// -------------------------------------------------------

// Default settings overrides for 'c6m3_port' in 'Advanced' difficulty
defaults["left4bots2/cfg/settings_c6m3_port_hard.txt"] <- @"close_saferoom_door_highres = 1
file_weapons_prefix = ""left4bots2/cfg/weapons/c6m3_port/""
Expand Down
2 changes: 1 addition & 1 deletion root/scripts/vscripts/left4bots_settings.nut
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
jockey_redirect_damage = 40

// Bots will pause their current 'lead' order if they are at least this distance behind a human survivor. 0 = No pause
lead_pause_behind_dist = 180
lead_pause_behind_dist = 250

// [1/0] Enable/Disable the additional trace check on the ground when calculating the 'lead' path
lead_check_ground = 0
Expand Down

0 comments on commit 74a587b

Please sign in to comment.