2022-03-11 11:40:43 -08:00
|
|
|
/*
|
2023-10-13 08:22:31 -07:00
|
|
|
* Copyright (c) 2016-2023 Vera Visions LLC.
|
2022-03-11 11:40:43 -08:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2022-07-07 09:10:14 -07:00
|
|
|
*/
|
2022-03-11 11:40:43 -08:00
|
|
|
|
|
|
|
void
|
Add a whole bunch of new bot features, including bot profiles.
Developers: the internal class `bot` is now `NSBot`, and an entityDef
of the old name will be instantiated instead.
Override defs/bot.def in your mod and make it use any custom spawnclass
you wish. Now games don't have to override `addbot` or `bot_add` inside
the multiplayer game rules.
There's also more console commands. Clients now have access to:
addBot, killAllBots, killClass [classname], killMovables, trigger [targetname], input [entnum] [input] [data], listBotProfiles, listTargets, teleport [targetname], teleportToClass [classname], respawnEntities, spawn
2024-01-26 19:22:14 -08:00
|
|
|
NSBot::Pain(void)
|
2022-03-11 11:40:43 -08:00
|
|
|
{
|
2023-10-13 08:22:31 -07:00
|
|
|
NSGameRules rules = g_grMode;
|
2022-03-11 11:40:43 -08:00
|
|
|
|
2022-03-11 14:00:44 -08:00
|
|
|
super::Pain();
|
2022-03-11 11:40:43 -08:00
|
|
|
|
2022-07-16 15:11:33 -07:00
|
|
|
if (rules.IsTeamplay()) {
|
2022-03-11 11:40:43 -08:00
|
|
|
if (g_dmg_eAttacker.flags & FL_CLIENT && g_dmg_eAttacker.team == team) {
|
|
|
|
ChatSayTeam("Stop shooting me!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make this pain our new enemy! */
|
|
|
|
if (g_dmg_eAttacker && g_dmg_eAttacker != this) {
|
|
|
|
float enemydist = vlen(origin - m_eTarget.origin);
|
|
|
|
float newdist = vlen(origin - g_dmg_eAttacker.origin);
|
|
|
|
|
2023-10-13 08:22:31 -07:00
|
|
|
if (m_eTarget) {
|
|
|
|
if (newdist < enemydist) {
|
2022-03-11 11:40:43 -08:00
|
|
|
SetEnemy(g_dmg_eAttacker);
|
2023-10-13 08:22:31 -07:00
|
|
|
}
|
|
|
|
} else {
|
2022-03-11 11:40:43 -08:00
|
|
|
SetEnemy(g_dmg_eAttacker);
|
2023-10-13 08:22:31 -07:00
|
|
|
}
|
2022-03-11 11:40:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Add a whole bunch of new bot features, including bot profiles.
Developers: the internal class `bot` is now `NSBot`, and an entityDef
of the old name will be instantiated instead.
Override defs/bot.def in your mod and make it use any custom spawnclass
you wish. Now games don't have to override `addbot` or `bot_add` inside
the multiplayer game rules.
There's also more console commands. Clients now have access to:
addBot, killAllBots, killClass [classname], killMovables, trigger [targetname], input [entnum] [input] [data], listBotProfiles, listTargets, teleport [targetname], teleportToClass [classname], respawnEntities, spawn
2024-01-26 19:22:14 -08:00
|
|
|
NSBot::SetEnemy(entity en)
|
2022-03-11 11:40:43 -08:00
|
|
|
{
|
|
|
|
m_eTarget = en;
|
|
|
|
|
2023-10-13 08:22:31 -07:00
|
|
|
if (m_eTarget) {
|
2022-03-11 11:40:43 -08:00
|
|
|
m_flEnemyDist = vlen(origin - m_eTarget.origin);
|
2023-10-13 08:22:31 -07:00
|
|
|
} else {
|
2022-03-11 11:40:43 -08:00
|
|
|
m_flEnemyDist = -1;
|
2023-10-13 08:22:31 -07:00
|
|
|
}
|
2022-03-11 11:40:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Add a whole bunch of new bot features, including bot profiles.
Developers: the internal class `bot` is now `NSBot`, and an entityDef
of the old name will be instantiated instead.
Override defs/bot.def in your mod and make it use any custom spawnclass
you wish. Now games don't have to override `addbot` or `bot_add` inside
the multiplayer game rules.
There's also more console commands. Clients now have access to:
addBot, killAllBots, killClass [classname], killMovables, trigger [targetname], input [entnum] [input] [data], listBotProfiles, listTargets, teleport [targetname], teleportToClass [classname], respawnEntities, spawn
2024-01-26 19:22:14 -08:00
|
|
|
NSBot::WeaponThink(void)
|
2022-03-11 11:40:43 -08:00
|
|
|
{
|
|
|
|
int r = Weapons_IsEmpty(this, activeweapon);
|
|
|
|
|
|
|
|
/* clip empty, but the whole weapon isn't */
|
|
|
|
if (r == 0 && a_ammo1 <= 0) {
|
2023-10-13 08:22:31 -07:00
|
|
|
/* stop fire, tap reload */
|
2022-03-11 11:40:43 -08:00
|
|
|
input_buttons &= ~INPUT_BUTTON0;
|
|
|
|
input_buttons |= INPUT_BUTTON4;
|
|
|
|
} else if (r == 1) {
|
2023-10-13 08:22:31 -07:00
|
|
|
/* if empty, switch to the next best weapon */
|
2022-03-11 11:40:43 -08:00
|
|
|
Weapons_SwitchBest(this, activeweapon);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_wtWeaponType = Weapons_GetType(this, activeweapon);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Add a whole bunch of new bot features, including bot profiles.
Developers: the internal class `bot` is now `NSBot`, and an entityDef
of the old name will be instantiated instead.
Override defs/bot.def in your mod and make it use any custom spawnclass
you wish. Now games don't have to override `addbot` or `bot_add` inside
the multiplayer game rules.
There's also more console commands. Clients now have access to:
addBot, killAllBots, killClass [classname], killMovables, trigger [targetname], input [entnum] [input] [data], listBotProfiles, listTargets, teleport [targetname], teleportToClass [classname], respawnEntities, spawn
2024-01-26 19:22:14 -08:00
|
|
|
NSBot::WeaponAttack(void)
|
2022-03-11 11:40:43 -08:00
|
|
|
{
|
2023-10-13 08:22:31 -07:00
|
|
|
bool shouldAttack = false;
|
2022-03-11 11:40:43 -08:00
|
|
|
|
2022-03-15 19:33:11 -07:00
|
|
|
/* only attack when the type's suggested distance makes sense to */
|
2022-03-11 11:40:43 -08:00
|
|
|
if (m_wtWeaponType == WPNTYPE_RANGED) {
|
|
|
|
if (m_flEnemyDist <= 1024)
|
2023-10-13 08:22:31 -07:00
|
|
|
shouldAttack = true;
|
2022-03-11 11:40:43 -08:00
|
|
|
} else if (m_wtWeaponType == WPNTYPE_THROW) {
|
|
|
|
if (m_flEnemyDist <= 512)
|
2023-10-13 08:22:31 -07:00
|
|
|
shouldAttack = true;
|
2022-03-11 11:40:43 -08:00
|
|
|
} else if (m_wtWeaponType == WPNTYPE_CLOSE) {
|
|
|
|
if (m_flEnemyDist <= 128)
|
2023-10-13 08:22:31 -07:00
|
|
|
shouldAttack = true;
|
2022-03-11 11:40:43 -08:00
|
|
|
} else {
|
2022-03-15 19:33:11 -07:00
|
|
|
if (m_flEnemyDist <= 1024)
|
2023-10-13 08:22:31 -07:00
|
|
|
shouldAttack = true;
|
2022-03-11 11:40:43 -08:00
|
|
|
}
|
|
|
|
|
2023-10-11 00:55:07 -07:00
|
|
|
if (m_flForceWeaponAttack > time)
|
2023-10-13 08:22:31 -07:00
|
|
|
shouldAttack = true;
|
2023-10-11 00:55:07 -07:00
|
|
|
|
2023-10-13 08:22:31 -07:00
|
|
|
if (shouldAttack && m_flAttackTime < time) {
|
2022-03-11 11:40:43 -08:00
|
|
|
if (!m_iAttackMode) {
|
|
|
|
input_buttons |= INPUT_BUTTON0;
|
|
|
|
}
|
2022-03-15 19:33:11 -07:00
|
|
|
|
2022-06-22 15:25:08 -07:00
|
|
|
/* this might not affect much */
|
|
|
|
if (m_wtWeaponType != WPNTYPE_FULLAUTO) {
|
|
|
|
switch (cvar("bot_skill")) {
|
|
|
|
case 1:
|
|
|
|
m_flAttackTime = time + 0.25f;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
m_flAttackTime = time + 0.10f;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
m_flAttackTime = time + 0.05f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_flAttackTime = time + 1.0;
|
|
|
|
}
|
|
|
|
}
|
2022-03-11 11:40:43 -08:00
|
|
|
} else {
|
|
|
|
input_buttons &= ~INPUT_BUTTON0;
|
|
|
|
input_buttons &= ~INPUT_BUTTON4;
|
|
|
|
input_buttons &= ~INPUT_BUTTON5;
|
|
|
|
}
|
|
|
|
|
2022-03-15 19:33:11 -07:00
|
|
|
if (m_wtWeaponType != WPNTYPE_FULLAUTO)
|
|
|
|
m_iAttackMode = 1 - m_iAttackMode;
|
|
|
|
else
|
|
|
|
m_iAttackMode = 0;
|
2022-03-11 11:40:43 -08:00
|
|
|
}
|
2022-03-11 14:00:44 -08:00
|
|
|
|
2023-10-11 00:55:07 -07:00
|
|
|
void
|
Add a whole bunch of new bot features, including bot profiles.
Developers: the internal class `bot` is now `NSBot`, and an entityDef
of the old name will be instantiated instead.
Override defs/bot.def in your mod and make it use any custom spawnclass
you wish. Now games don't have to override `addbot` or `bot_add` inside
the multiplayer game rules.
There's also more console commands. Clients now have access to:
addBot, killAllBots, killClass [classname], killMovables, trigger [targetname], input [entnum] [input] [data], listBotProfiles, listTargets, teleport [targetname], teleportToClass [classname], respawnEntities, spawn
2024-01-26 19:22:14 -08:00
|
|
|
NSBot::ForceWeaponAttack(vector attackPos, float attackTime)
|
2023-10-11 00:55:07 -07:00
|
|
|
{
|
|
|
|
m_vecForceWeaponAttackPos = attackPos;
|
|
|
|
m_flForceWeaponAttack = attackTime + time;
|
|
|
|
}
|
|
|
|
|
2022-03-11 14:00:44 -08:00
|
|
|
var float g_botalert_timer;
|
2022-10-26 12:50:08 -07:00
|
|
|
|
2022-03-11 14:00:44 -08:00
|
|
|
void
|
|
|
|
BotLib_Alert(vector pos, float radius, float t)
|
|
|
|
{
|
2023-10-13 08:22:31 -07:00
|
|
|
NSGameRules rules = g_grMode;
|
2022-03-11 14:00:44 -08:00
|
|
|
|
2022-10-26 12:50:08 -07:00
|
|
|
/* sometimes many alert-sounds happen at once... we don't really want
|
|
|
|
* that */
|
2022-03-11 14:00:44 -08:00
|
|
|
if (g_botalert_timer > time)
|
|
|
|
return;
|
|
|
|
|
2022-10-26 12:50:08 -07:00
|
|
|
for (entity w = world; (w = find(w,::targetname, "_nuclide_bot_"));) {
|
2022-03-11 14:00:44 -08:00
|
|
|
/* out of radius */
|
|
|
|
if (vlen(pos - w.origin) > radius)
|
|
|
|
continue;
|
|
|
|
|
Add a whole bunch of new bot features, including bot profiles.
Developers: the internal class `bot` is now `NSBot`, and an entityDef
of the old name will be instantiated instead.
Override defs/bot.def in your mod and make it use any custom spawnclass
you wish. Now games don't have to override `addbot` or `bot_add` inside
the multiplayer game rules.
There's also more console commands. Clients now have access to:
addBot, killAllBots, killClass [classname], killMovables, trigger [targetname], input [entnum] [input] [data], listBotProfiles, listTargets, teleport [targetname], teleportToClass [classname], respawnEntities, spawn
2024-01-26 19:22:14 -08:00
|
|
|
NSBot f = (NSBot) w;
|
2022-03-11 14:00:44 -08:00
|
|
|
|
|
|
|
/* they already got a target of some kind */
|
|
|
|
if (f.m_eTarget)
|
|
|
|
continue;
|
|
|
|
|
2022-10-26 12:50:08 -07:00
|
|
|
/* if they're our friend... ignore */
|
|
|
|
if (rules.IsTeamplay())
|
2022-03-11 14:00:44 -08:00
|
|
|
if (w.team == t)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* if the bot is dead... ignore */
|
|
|
|
if (f.health <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* we've heard a noise. investigate the location */
|
2024-03-02 00:40:08 -08:00
|
|
|
BotLog("Bot %S (%d) alerted by noise at %v", f.netname, num_for_edict(f), pos);
|
2022-03-11 14:00:44 -08:00
|
|
|
f.RouteClear();
|
2022-07-20 16:27:24 -07:00
|
|
|
f.RouteToPosition(pos);
|
2022-03-11 14:00:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_botalert_timer = time + 0.5f;
|
|
|
|
}
|