Fixed defending issues

* Fixed bug where aliens wouldn't properly defend their hive if the marines weren't sieging it
* Fixed some stuck issues with skulks
* Added a proper debug printout for bots on-screen
This commit is contained in:
RGreenlees 2024-04-26 16:03:25 +01:00 committed by pierow
parent e8a85852e8
commit d209fe5184
3 changed files with 33 additions and 30 deletions

View file

@ -3,6 +3,7 @@
#include "AvHAIPlayerUtil.h"
#include "AvHAITactical.h"
#include "AvHAINavigation.h"
#include "AvHAIPlayerManager.h"
#include "AvHGamerules.h"
@ -522,21 +523,12 @@ void UTIL_DrawBox(edict_t* pEntity, Vector bMin, Vector bMax, float drawTimeSeco
void UTIL_DrawHUDText(edict_t* pEntity, char channel, float x, float y, unsigned char r, unsigned char g, unsigned char b, const char* string)
{
// higher level wrapper for hudtextparms TE_TEXTMESSAGEs. This function is meant to be called
// every frame, since the duration of the display is roughly worth the duration of a video
// frame. The X and Y coordinates are unary fractions which are bound to this rule:
// 0: top of the screen (Y) or left of the screen (X), left aligned text
// 1: bottom of the screen (Y) or right of the screen (X), right aligned text
// -1(only one negative value possible): center of the screen (X and Y), centered text
// Any value ranging from 0 to 1 will represent a valid position on the screen.
//static short duration;
if (FNullEnt(pEntity)) { return; }
//duration = (int)GAME_GetServerMSecVal() * 256 / 750; // compute text message duration
//if (duration < 5)
// duration = 5;
float FrameDelta = AIMGR_GetFrameDelta();
FrameDelta *= 256.0f;
short Duration = (short)roundf(FrameDelta);
MESSAGE_BEGIN(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, NULL, pEntity);
WRITE_BYTE(TE_TEXTMESSAGE);
@ -552,9 +544,9 @@ void UTIL_DrawHUDText(edict_t* pEntity, char channel, float x, float y, unsigned
WRITE_BYTE(g); // effect GREEN
WRITE_BYTE(b); // effect BLUE
WRITE_BYTE(1); // effect ALPHA
WRITE_SHORT(0); // fade-in time in seconds * 256
WRITE_SHORT(0); // fade-out time in seconds * 256
WRITE_SHORT(20); // hold time in seconds * 256
WRITE_SHORT(1); // fade-in time in seconds * 256
WRITE_SHORT(Duration); // fade-out time in seconds * 256
WRITE_SHORT(Duration); // hold time in seconds * 256
WRITE_STRING(string);//string); // send the string
MESSAGE_END(); // end

View file

@ -5975,6 +5975,10 @@ void UpdateBotStuck(AvHAIPlayer* pBot)
{
pBot->Button |= IN_DUCK;
}
else
{
pBot->Button &= ~IN_DUCK;
}
}
}
}
@ -7196,7 +7200,6 @@ void PerformUnstuckMove(AvHAIPlayer* pBot, const Vector MoveDestination)
BotJump(pBot);
}
if (bBlockedRightSide && !bBlockedLeftSide)
{
pBot->desiredMovementDir = MoveRightVector;

View file

@ -2388,6 +2388,8 @@ AvHAICombatStrategy GetGorgeCombatStrategyForTarget(AvHAIPlayer* pBot, enemy_sta
float CurrentHealthPercent = GetPlayerOverallHealthPercent(pBot->Edict);
bool bPlayerCloaked = pBot->Player->GetOpacity() <= 0.5f;
if (pBot->CurrentCombatStrategy == COMBAT_STRATEGY_RETREAT)
{
if (CurrentHealthPercent < 0.99f)
@ -2437,11 +2439,11 @@ AvHAICombatStrategy GetGorgeCombatStrategyForTarget(AvHAIPlayer* pBot, enemy_sta
if (bHasBackup)
{
return (CurrentHealthPercent > 0.5f) ? COMBAT_STRATEGY_ATTACK : COMBAT_STRATEGY_SKIRMISH;
return (CurrentHealthPercent > 0.5f) ? COMBAT_STRATEGY_ATTACK : ((bPlayerCloaked) ? COMBAT_STRATEGY_RETREAT : COMBAT_STRATEGY_SKIRMISH);
}
else
{
return (CurrentHealthPercent > 0.5f) ? COMBAT_STRATEGY_SKIRMISH : COMBAT_STRATEGY_RETREAT;
return (CurrentHealthPercent > 0.7f) ? ((bPlayerCloaked) ? COMBAT_STRATEGY_RETREAT : COMBAT_STRATEGY_SKIRMISH) : COMBAT_STRATEGY_RETREAT;
}
}
@ -5522,7 +5524,7 @@ void AIPlayerDMThink(AvHAIPlayer* pBot)
void AIPlayerThink(AvHAIPlayer* pBot)
{
#ifdef DEBUG
//#ifdef DEBUG
if (pBot == AIMGR_GetDebugAIPlayer())
{
bool bBreak = true; // Add a break point here if you want to debug a specific bot
@ -5530,9 +5532,9 @@ void AIPlayerThink(AvHAIPlayer* pBot)
AIDEBUG_DrawBotPath(pBot);
DEBUG_PrintTaskInfo(pBot);
//DEBUG_PrintCombatInfo(pBot);
DEBUG_PrintCombatInfo(pBot);
}
#endif
//#endif
pBot->ThinkDelta = fminf(gpGlobals->time - pBot->LastThinkTime, 0.1f);
pBot->LastThinkTime = gpGlobals->time;
@ -7037,10 +7039,12 @@ void AIPlayerSetSecondaryAlienTask(AvHAIPlayer* pBot, AvHAIPlayerTask* Task)
if (ThisHive && ThisHive->bIsUnderAttack)
{
float DistToHive = vDist2DSq(ThisHive->FloorLocation, pBot->Edict->v.origin);
int AttackerStrength = 0;
int DefenderStrength = 0;
vector<AvHPlayer*> AttackingPlayers = AITAC_GetAllPlayersOfTeamInArea(EnemyTeam, ThisHive->FloorLocation, UTIL_MetresToGoldSrcUnits(15.0f), false, nullptr, AVH_USER3_NONE);
vector<AvHPlayer*> AttackingPlayers = AITAC_GetAllPlayersOfTeamInArea(EnemyTeam, ThisHive->FloorLocation, UTIL_MetresToGoldSrcUnits(20.0f), false, nullptr, AVH_USER3_NONE);
for (auto AttackerIt = AttackingPlayers.begin(); AttackerIt != AttackingPlayers.end(); AttackerIt++)
{
@ -7067,13 +7071,18 @@ void AIPlayerSetSecondaryAlienTask(AvHAIPlayer* pBot, AvHAIPlayerTask* Task)
AttackerStrength += ThisAttackerStrength;
}
vector<AvHPlayer*> DefendingPlayers = AITAC_GetAllPlayersOfTeamInArea(EnemyTeam, ThisHive->FloorLocation, UTIL_MetresToGoldSrcUnits(15.0f), false, pBot->Edict, AVH_USER3_ALIEN_PLAYER2);
vector<AvHPlayer*> DefendingPlayers = AITAC_GetAllPlayersOfTeamInArea(BotTeam, ThisHive->FloorLocation, UTIL_MetresToGoldSrcUnits(20.0f), false, pBot->Edict, AVH_USER3_ALIEN_PLAYER2);
for (auto DefenderIt = DefendingPlayers.begin(); DefenderIt != DefendingPlayers.end(); DefenderIt++)
{
AvHPlayer* ThisPlayer = (*DefenderIt);
edict_t* ThisPlayerEdict = ThisPlayer->edict();
float ThisPlayerDist = vDist2DSq(ThisPlayerEdict->v.origin, ThisHive->FloorLocation);
// This potential defender is further than us, don't count them in the strength measurements
if (ThisPlayerDist > DistToHive) { continue; }
int ThisDefenderStrength = 1;
if (IsPlayerFade(ThisPlayerEdict))
@ -7118,12 +7127,10 @@ void AIPlayerSetSecondaryAlienTask(AvHAIPlayer* pBot, AvHAIPlayerTask* Task)
if (AttackerStrength >= DefenderStrength)
{
float ThisDist = vDist2DSq(ThisHive->FloorLocation, pBot->Edict->v.origin);
if (!HiveToDefend || ThisDist < MinDist)
if (!HiveToDefend || DistToHive < MinDist)
{
HiveToDefend = ThisHive;
MinDist = ThisDist;
MinDist = DistToHive;
}
}
}
@ -7131,6 +7138,7 @@ void AIPlayerSetSecondaryAlienTask(AvHAIPlayer* pBot, AvHAIPlayerTask* Task)
if (HiveToDefend)
{
UTIL_DrawLine(INDEXENT(1), pBot->Edict->v.origin, HiveToDefend->Location, 255, 255, 0);
AITASK_SetDefendTask(pBot, Task, HiveToDefend->HiveEdict, true);
return;
}
@ -8543,7 +8551,7 @@ void DEBUG_PrintCombatInfo(AvHAIPlayer* pBot)
if (TrackedEnemy < 0)
{
UTIL_DrawHUDText(INDEXENT(1), 0, 0.6f, 0.1f, 255, 255, 255, buf);
UTIL_DrawHUDText(INDEXENT(1), 1, 0.6f, 0.1f, 255, 255, 255, buf);
return;
}
@ -8599,7 +8607,7 @@ void DEBUG_PrintCombatInfo(AvHAIPlayer* pBot)
strcat(buf, interbuf);
UTIL_DrawHUDText(INDEXENT(1), 0, 0.6f, 0.1f, 255, 255, 255, buf);
UTIL_DrawHUDText(INDEXENT(1), 1, 0.6f, 0.1f, 255, 255, 255, buf);
if (!vIsZero(TrackedInfo->LastDetectedLocation))
{