Fix comment and reduce branching in TF2_IsPlayerInCondition.

This commit is contained in:
Nicholas Hastings 2016-05-21 12:55:47 -04:00
parent e127a55b0a
commit 9b3b2eb23e

View File

@ -529,10 +529,13 @@ stock int TF2_GetPlayerConditionFlags(int client)
*/
stock bool TF2_IsPlayerInCondition(int client, TFCond cond)
{
// Conditions are stored across two netprops now, one for each 32-bit segment.
if (view_as<int>(cond) < 32)
// Conditions are stored across multiple netprops now, one for each 32-bit segment.
int iCond = view_as<int>(cond);
switch (iCond / 32)
{
int bit = 1 << view_as<int>(cond);
case 0:
{
int bit = 1 << iCond;
if ((GetEntProp(client, Prop_Send, "m_nPlayerCond") & bit) == bit)
{
return true;
@ -543,30 +546,33 @@ stock bool TF2_IsPlayerInCondition(int client, TFCond cond)
return true;
}
}
else if (view_as<int>(cond) < 64)
case 1:
{
int bit = (1 << (view_as<int>(cond) - 32));
int bit = (1 << (iCond - 32));
if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx") & bit) == bit)
{
return true;
}
}
else if (view_as<int>(cond) < 96)
case 2:
{
int bit = (1 << (view_as<int>(cond) - 64));
int bit = (1 << (iCond - 64));
if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx2") & bit) == bit)
{
return true;
}
}
else
case 3:
{
int bit = (1 << (view_as<int>(cond) - 96));
int bit = (1 << (iCond - 96));
if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx3") & bit) == bit)
{
return true;
}
}
default:
ThrowError("Invalid TFCond value %d", iCond);
}
return false;
}