Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 53 additions & 41 deletions src/game/server/neo/bot/neo_bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,52 +577,17 @@ CNEOBot::~CNEOBot()
void CNEOBot::Spawn()
{
// CNEOBot do m_iNeoClass a bit earlier
if ((m_iNextSpawnClassChoice != NEO_CLASS_RANDOM) && (m_iNeoClass != m_iNextSpawnClassChoice))
// so that we get correct loadout choices for the class
if (m_iNextSpawnClassChoice == NEO_CLASS_RANDOM)
{
m_iNeoClass = m_iNextSpawnClassChoice;
m_iNeoClass = ChooseRandomClass();
}

const ENeoRank eRank = static_cast<ENeoRank>(GetRank(m_iXP) - 1);
if (eRank == NEO_RANK_RANKLESS_DOG || (false == IN_BETWEEN_EQ(NEO_CLASS_RECON, m_iNeoClass, NEO_CLASS_VIP)))
else if (m_iNeoClass != m_iNextSpawnClassChoice)
{
m_iLoadoutWepChoice = 0;
m_iNeoClass = m_iNextSpawnClassChoice;
}
else
{
const NEO_WEP_BITS_UNDERLYING_TYPE wepPrefsForCurRank = m_profile.flagsWepPrefs[m_iNeoClass][eRank];

int iChosenWeps[MAX_WEAPON_LOADOUTS] = {};
int iChosenWepsSize = 0;
for (int i = 0; i < MAX_WEAPON_LOADOUTS; ++i)
{
if (wepPrefsForCurRank & CNEOWeaponLoadout::s_LoadoutWeapons[m_iNeoClass][i].info.m_iWepBit)
{
iChosenWeps[iChosenWepsSize++] = i;
}
}

if (iChosenWepsSize == 0)
{
// Generally shouldn't happen, but if so, just pick from any under the XP limit
for (int i = 0; i < MAX_WEAPON_LOADOUTS; ++i)
{
if (CNEOWeaponLoadout::s_LoadoutWeapons[m_iNeoClass][i].m_iWeaponPrice > m_iXP)
{
break;
}
iChosenWeps[iChosenWepsSize++] = i;
}
}

if (iChosenWepsSize == 1)
{
m_iLoadoutWepChoice = iChosenWeps[0];
}
else
{
m_iLoadoutWepChoice = iChosenWeps[RandomInt(0, iChosenWepsSize - 1)];
}
}
ChooseRandomWeapon();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this section below as ChooseRandomWeapon()


BaseClass::Spawn();

Expand Down Expand Up @@ -651,6 +616,53 @@ void CNEOBot::Spawn()
m_bRespawnCopyCorpse = false;
}

int CNEOBot::ChooseRandomWeaponIndex() const
{
const ENeoRank eRank = static_cast<ENeoRank>(GetRank(m_iXP) - 1);
if (eRank == NEO_RANK_RANKLESS_DOG || (false == IN_BETWEEN_EQ(NEO_CLASS_RECON, m_iNeoClass, NEO_CLASS_VIP)))
{
return 0;
}
const NEO_WEP_BITS_UNDERLYING_TYPE wepPrefsForCurRank = m_profile.flagsWepPrefs[m_iNeoClass][eRank];

int iChosenWeps[MAX_WEAPON_LOADOUTS] = {};
int iChosenWepsSize = 0;
for (int i = 0; i < MAX_WEAPON_LOADOUTS; ++i)
{
if (wepPrefsForCurRank & CNEOWeaponLoadout::s_LoadoutWeapons[m_iNeoClass][i].info.m_iWepBit)
{
iChosenWeps[iChosenWepsSize++] = i;
}
}

if (iChosenWepsSize == 0)
{
// Generally shouldn't happen, but if so, just pick from any under the XP limit
for (int i = 0; i < MAX_WEAPON_LOADOUTS; ++i)
{
if (CNEOWeaponLoadout::s_LoadoutWeapons[m_iNeoClass][i].m_iWeaponPrice > m_iXP)
{
break;
}
iChosenWeps[iChosenWepsSize++] = i;
}
}

if (iChosenWepsSize == 1)
{
return iChosenWeps[0];
}
else
{
return iChosenWeps[RandomInt(0, iChosenWepsSize - 1)];
}
}

void CNEOBot::ChooseRandomWeapon()
{
m_iLoadoutWepChoice = ChooseRandomWeaponIndex();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to make this block as similar as possible with what was originally in void CNEOBot::Spawn() , but doesn't quite show up easily in the GitHub diff.

Image



//-----------------------------------------------------------------------------------------------------
void CNEOBot::SetMission(MissionType mission, bool resetBehaviorSystem)
Expand Down
2 changes: 2 additions & 0 deletions src/game/server/neo/bot/neo_bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ class CNEOBot : public NextBotPlayer< CNEO_Player >, public CGameEventListener

CNEOBotProfile m_profile = {};
NeoClass ChooseRandomClass() const;
void ChooseRandomWeapon();
int ChooseRandomWeaponIndex() const;
int m_iIntendTeam = 0;
int m_iProfileIdx = -1;

Expand Down
6 changes: 6 additions & 0 deletions src/game/server/neo/neo_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,15 @@ void CNEO_Player::Spawn(void)
if (forcedBotClass == NEO_CLASS_RANDOM)
{
if (auto* thisBot = ToNEOBot(this))
{
m_iNextSpawnClassChoice = thisBot->ChooseRandomClass();
m_iNeoClass = m_iNextSpawnClassChoice;
m_iLoadoutWepChoice = thisBot->ChooseRandomWeaponIndex();
}
else
{
AssertMsg(false, "this IsBot() but can't convert to NEO bot!?");
}
}
else
{
Expand Down