mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-12 16:21:04 +02:00
94 lines
1.9 KiB
C++
94 lines
1.9 KiB
C++
// BotAI_Battle_NBG.cpp
|
|
//
|
|
|
|
#pragma hdrstop
|
|
#include "precompiled.h"
|
|
#include "../Game_local.h"
|
|
|
|
/*
|
|
=====================
|
|
rvmBot::state_BattleNBG
|
|
=====================
|
|
*/
|
|
stateResult_t rvmBot::state_BattleNBG(stateParms_t* parms)
|
|
{
|
|
bot_goal_t goal;
|
|
idPlayer* entinfo;
|
|
idVec3 target;
|
|
|
|
// respawn if dead.
|
|
if( BotIsDead( &bs ) )
|
|
{
|
|
stateThread.SetState("state_Respawn");
|
|
return SRESULT_DONE_FRAME;
|
|
}
|
|
|
|
// if no enemy.
|
|
if( bs.enemy < 0 || bs.enemy >= gameLocal.num_entities || gameLocal.entities[bs.enemy] == NULL )
|
|
{
|
|
stateThread.SetState("state_SeekLTG");
|
|
return SRESULT_DONE_FRAME;
|
|
}
|
|
|
|
entinfo = gameLocal.entities[bs.enemy]->Cast<idPlayer>();
|
|
if( entinfo == NULL )
|
|
{
|
|
stateThread.SetState("state_SeekLTG");
|
|
return SRESULT_DONE_FRAME;
|
|
}
|
|
if( entinfo->health <= 0 )
|
|
{
|
|
stateThread.SetState("state_SeekNBG");
|
|
return SRESULT_DONE_FRAME;
|
|
}
|
|
|
|
//update the last time the enemy was visible
|
|
if( BotEntityVisible( bs.entitynum, bs.eye, bs.viewangles, 360, bs.enemy ) )
|
|
{
|
|
bs.enemyvisible_time = Bot_Time();
|
|
target = entinfo->GetOrigin();
|
|
bs.lastenemyorigin = target;
|
|
bs.last_enemy_visible_position = target;
|
|
}
|
|
|
|
//if the bot has no goal or touches the current goal
|
|
if( !botGoalManager.BotGetTopGoal( bs.gs, &goal ) )
|
|
{
|
|
bs.nbg_time = 0;
|
|
}
|
|
else if( BotReachedGoal( &bs, &goal ) )
|
|
{
|
|
bs.nbg_time = 0;
|
|
}
|
|
|
|
if( bs.nbg_time < Bot_Time() )
|
|
{
|
|
botGoalManager.BotPopGoal( bs.gs );
|
|
if( botGoalManager.BotGetTopGoal( bs.gs, &goal ) )
|
|
{
|
|
stateThread.SetState("state_Retreat");
|
|
}
|
|
else
|
|
{
|
|
stateThread.SetState("state_BattleFight");
|
|
}
|
|
|
|
return SRESULT_DONE_FRAME;
|
|
}
|
|
|
|
//move towards the goal
|
|
BotMoveToGoal( &bs, &goal );
|
|
|
|
//update the attack inventory values
|
|
BotUpdateBattleInventory( &bs, bs.enemy );
|
|
|
|
//choose the best weapon to fight with
|
|
BotChooseWeapon( &bs );
|
|
|
|
BotAimAtEnemy( &bs );
|
|
|
|
//attack the enemy if possible
|
|
BotCheckAttack( &bs );
|
|
return SRESULT_WAIT;
|
|
}
|