Fixed ignorance of quota maintaining if no bots on kicking team.

Minor refactoring.
This commit is contained in:
Dmitry 2019-05-11 23:55:33 +03:00 committed by jeefo
commit 78b2cb968a
4 changed files with 40 additions and 27 deletions

View file

@ -189,7 +189,7 @@ static inline void sincosf (const float x, const float y, const float z, float *
// using only two sse calls instead of 6 calls to sin/cos with standard functions // using only two sse calls instead of 6 calls to sin/cos with standard functions
#if defined (PLATFORM_HAS_SSE2) #if defined (PLATFORM_HAS_SSE2)
auto rad = _mm_set_ps (x, y, z, 0.0f); auto inputSet = _mm_set_ps (x, y, z, 0.0f);
auto _mm_sin = [] (__m128 rad) -> __m128 { auto _mm_sin = [] (__m128 rad) -> __m128 {
static auto pi2 = _mm_set_ps1 (PI * 2); static auto pi2 = _mm_set_ps1 (PI * 2);
@ -216,8 +216,8 @@ static inline void sincosf (const float x, const float y, const float z, float *
}; };
static auto hpi = _mm_set_ps1 (PI_HALF); static auto hpi = _mm_set_ps1 (PI_HALF);
auto s = _mm_sin (rad); auto s = _mm_sin (inputSet);
auto c = _mm_sin (_mm_add_ps (rad, hpi)); auto c = _mm_sin (_mm_add_ps (inputSet, hpi));
_mm_store_ps (sines, _mm_shuffle_ps (s, s, _MM_SHUFFLE (0, 1, 2, 3))); _mm_store_ps (sines, _mm_shuffle_ps (s, s, _MM_SHUFFLE (0, 1, 2, 3)));
_mm_store_ps (cosines, _mm_shuffle_ps (c, c, _MM_SHUFFLE (0, 1, 2, 3))); _mm_store_ps (cosines, _mm_shuffle_ps (c, c, _MM_SHUFFLE (0, 1, 2, 3)));
@ -650,7 +650,7 @@ public:
B second; B second;
public: public:
Pair (A a, B b) : first (a), second (b) { Pair (const A &a, const B &b) : first (a), second (b) {
} }
public: public:
@ -852,7 +852,7 @@ public:
} }
inline bool empty (void) const { inline bool empty (void) const {
return m_length <= 0; return m_length == 0;
} }
void shrink (bool destroyEmpty = true) { void shrink (bool destroyEmpty = true) {
@ -894,7 +894,7 @@ public:
} }
bool last (T &item) { bool last (T &item) {
if (m_length <= 0) { if (m_length == 0) {
return false; return false;
} }
item = m_data[m_length - 1]; item = m_data[m_length - 1];
@ -1416,17 +1416,17 @@ public:
Array <String> split (const char *delimiter) { Array <String> split (const char *delimiter) {
Array <String> tokens; Array <String> tokens;
size_t length, index = 0; size_t len, index = 0;
do { do {
index += strspn (&m_data[index], delimiter); index += strspn (&m_data[index], delimiter);
length = strcspn (&m_data[index], delimiter); len = strcspn (&m_data[index], delimiter);
if (length > 0) { if (len > 0) {
tokens.push (move (substr (index, length))); tokens.push (move (substr (index, len)));
} }
index += length; index += len;
} while (length > 0); } while (len > 0);
return tokens; return tokens;
} }

View file

@ -1357,7 +1357,7 @@ public:
void serverFill (int selection, int personality = PERSONALITY_NORMAL, int difficulty = -1, int numToAdd = -1); void serverFill (int selection, int personality = PERSONALITY_NORMAL, int difficulty = -1, int numToAdd = -1);
void kickEveryone (bool instant = false, bool zeroQuota = true); void kickEveryone (bool instant = false, bool zeroQuota = true);
void kickRandom (bool decQuota = true, Team fromTeam = TEAM_UNASSIGNED); bool kickRandom (bool decQuota = true, Team fromTeam = TEAM_UNASSIGNED);
void kickBot (int index); void kickBot (int index);
void kickFromTeam (Team team, bool removeAll = false); void kickFromTeam (Team team, bool removeAll = false);

View file

@ -1064,7 +1064,7 @@ void Engine::processMessages (void *ptr) {
break; break;
case 1: case 1:
if (playerIndex >= 0 && playerIndex <= maxClients ()) { if (playerIndex > 0 && playerIndex <= maxClients ()) {
int team = TEAM_UNASSIGNED; int team = TEAM_UNASSIGNED;
if (strVal[0] == 'U' && strVal[1] == 'N') { if (strVal[0] == 'U' && strVal[1] == 'N') {
@ -1192,7 +1192,7 @@ template <typename S, typename M> bool LightMeasure::recursiveLightPoint (const
} }
// blow it off if it doesn't split the plane... // blow it off if it doesn't split the plane...
if ((back < 0.0f) == side) { if ((back < 0.0f) == !!side) {
return false; // didn't hit anything return false; // didn't hit anything
} }

View file

@ -426,13 +426,20 @@ void BotManager::maintainQuota (void) {
int ts = 0, cts = 0; int ts = 0, cts = 0;
countTeamPlayers (ts, cts); countTeamPlayers (ts, cts);
bool isKicked = false;
if (ts > cts) { if (ts > cts) {
kickRandom (false, TEAM_TERRORIST); isKicked = kickRandom (false, TEAM_TERRORIST);
} }
else if (ts < cts) { else if (ts < cts) {
kickRandom (false, TEAM_COUNTER); isKicked = kickRandom (false, TEAM_COUNTER);
} }
else { else {
isKicked = kickRandom (false, TEAM_UNASSIGNED);
}
// if we can't kick player from correct team, just kick any random to keep quota control work
if (!isKicked) {
kickRandom (false, TEAM_UNASSIGNED); kickRandom (false, TEAM_UNASSIGNED);
} }
} }
@ -601,7 +608,7 @@ void BotManager::kickBot (int index) {
} }
} }
void BotManager::kickRandom (bool decQuota, Team fromTeam) { bool BotManager::kickRandom (bool decQuota, Team fromTeam) {
// this function removes random bot from server (only yapb's) // this function removes random bot from server (only yapb's)
// if forTeam is unassigned, that means random team // if forTeam is unassigned, that means random team
@ -635,7 +642,7 @@ void BotManager::kickRandom (bool decQuota, Team fromTeam) {
} }
if (deadBotFound) { if (deadBotFound) {
return; return true;
} }
// if no dead bots found try to find one with lowest amount of frags // if no dead bots found try to find one with lowest amount of frags
@ -657,7 +664,7 @@ void BotManager::kickRandom (bool decQuota, Team fromTeam) {
updateQuota (); updateQuota ();
m_bots[index]->kick (); m_bots[index]->kick ();
return; return true;
} }
// worst case, just kick some random bot // worst case, just kick some random bot
@ -669,9 +676,10 @@ void BotManager::kickRandom (bool decQuota, Team fromTeam) {
updateQuota (); updateQuota ();
bot->kick (); bot->kick ();
break; return true;
} }
} }
return false;
} }
void BotManager::setWeaponMode (int selection) { void BotManager::setWeaponMode (int selection) {
@ -1389,12 +1397,17 @@ void BotManager::calculatePingOffsets (void) {
botPing = rng.getInt (30, 40); botPing = rng.getInt (30, 40);
} }
for (int j = 0; j < 2; j++) { for (bot->m_pingOffset[0] = 0; bot->m_pingOffset[0] < 4; bot->m_pingOffset[0]++) {
for (bot->m_pingOffset[j] = 0; bot->m_pingOffset[j] < 4; bot->m_pingOffset[j]++) { if ((botPing - bot->m_pingOffset[0]) % 4 == 0) {
if ((botPing - bot->m_pingOffset[j]) % 4 == 0) { bot->m_ping[0] = (botPing - bot->m_pingOffset[0]) / 4;
bot->m_ping[j] = (botPing - bot->m_pingOffset[j]) / 4; break;
break; }
} }
for (bot->m_pingOffset[1] = 0; bot->m_pingOffset[1] < 2; bot->m_pingOffset[1]++) {
if ((botPing - bot->m_pingOffset[1]) % 2 == 0) {
bot->m_ping[1] = (botPing - bot->m_pingOffset[1]) / 2;
break;
} }
} }
bot->m_ping[2] = botPing; bot->m_ping[2] = botPing;