code refactoring, still testing

some fixes all over the place
fixed all warnings from clang
This commit is contained in:
jeefo 2016-03-12 14:35:44 +03:00
commit bc2e57a7a8
22 changed files with 984 additions and 1051 deletions

View file

@ -25,7 +25,6 @@ LOCAL_SRC_FILES := \
engine.cpp \
interface.cpp \
navigate.cpp \
netmsg.cpp \
support.cpp \
waypoint.cpp \

View file

@ -59,7 +59,7 @@ void Bot::PushMessageQueue (int message)
if (otherBot != NULL && otherBot->pev != pev)
{
if (m_notKilled == IsAlive (otherBot->GetEntity ()))
if (m_notKilled == otherBot->m_notKilled)
{
otherBot->m_sayTextBuffer.entityIndex = entityIndex;
strcpy (otherBot->m_sayTextBuffer.sayText, m_tempStrings);
@ -482,7 +482,7 @@ edict_t *Bot::FindBreakable (void)
// this function checks if bot is blocked by a shoot able breakable in his moving direction
TraceResult tr;
engine.TestLine (pev->origin, pev->origin + (m_destOrigin - pev->origin).Normalize () * 64.0f, TRACE_IGNORE_NONE, GetEntity (), &tr);
engine.TestLine (pev->origin, pev->origin + (m_destOrigin - pev->origin).Normalize () * 72.0f, TRACE_IGNORE_NONE, GetEntity (), &tr);
if (tr.flFraction != 1.0f)
{
@ -491,11 +491,11 @@ edict_t *Bot::FindBreakable (void)
// check if this isn't a triggered (bomb) breakable and if it takes damage. if true, shoot the crap!
if (IsShootableBreakable (ent))
{
m_breakable = tr.vecEndPos;
m_breakableOrigin = engine.GetAbsOrigin (ent);
return ent;
}
}
engine.TestLine (EyePosition (), EyePosition () + (m_destOrigin - EyePosition ()).Normalize () * 64.0f, TRACE_IGNORE_NONE, GetEntity (), &tr);
engine.TestLine (EyePosition (), EyePosition () + (m_destOrigin - EyePosition ()).Normalize () * 72.0f, TRACE_IGNORE_NONE, GetEntity (), &tr);
if (tr.flFraction != 1.0f)
{
@ -503,12 +503,12 @@ edict_t *Bot::FindBreakable (void)
if (IsShootableBreakable (ent))
{
m_breakable = tr.vecEndPos;
m_breakableOrigin = engine.GetAbsOrigin (ent);
return ent;
}
}
m_breakableEntity = NULL;
m_breakable.Zero ();
m_breakableOrigin.Zero ();
return NULL;
}
@ -971,7 +971,7 @@ void Bot::SwitchChatterIcon (bool show)
if (!(g_clients[i].flags & CF_USED) || (g_clients[i].ent->v.flags & FL_FAKECLIENT) || g_clients[i].team != m_team)
continue;
MESSAGE_BEGIN (MSG_ONE, netmsg.GetId (NETMSG_BOTVOICE), NULL, g_clients[i].ent); // begin message
MESSAGE_BEGIN (MSG_ONE, engine.FindMessageId (NETMSG_BOTVOICE), NULL, g_clients[i].ent); // begin message
WRITE_BYTE (show); // switch on/off
WRITE_BYTE (GetIndex ());
MESSAGE_END ();
@ -1009,7 +1009,7 @@ void Bot::InstantChatterMessage (int type)
g_sendAudioFinished = false;
MESSAGE_BEGIN (MSG_ONE, netmsg.GetId (NETMSG_SENDAUDIO), NULL, ent); // begin message
MESSAGE_BEGIN (MSG_ONE, engine.FindMessageId (NETMSG_SENDAUDIO), NULL, ent); // begin message
WRITE_BYTE (GetIndex ());
if (pev->deadflag & DEAD_DYING)
@ -1071,13 +1071,13 @@ void Bot::CheckMessageQueue (void)
return;
// get message from stack
int currentQueueMessage = GetMessageQueue ();
int state = GetMessageQueue ();
// nothing to do?
if (currentQueueMessage == GSM_IDLE || (currentQueueMessage == GSM_RADIO && yb_csdm_mode.GetInt () == 2))
if (state == GSM_IDLE || (state == GSM_RADIO && yb_csdm_mode.GetInt () == 2))
return;
switch (currentQueueMessage)
switch (state)
{
case GSM_BUY_STUFF: // general buy message
@ -2907,7 +2907,7 @@ void Bot::Think (void)
if (m_thinkFps <= engine.Time ())
{
// execute delayed think
ThinkDelayed ();
ThinkFrame ();
// skip some frames
m_thinkFps = engine.Time () + m_thinkInterval;
@ -2916,7 +2916,7 @@ void Bot::Think (void)
UpdateLookAngles ();
}
void Bot::ThinkDelayed (void)
void Bot::ThinkFrame (void)
{
pev->button = 0;
pev->flags |= FL_FAKECLIENT; // restore fake client bit, if it were removed by some evil action =)
@ -4395,7 +4395,7 @@ void Bot::RunTask_ShootBreakable (void)
m_moveToGoal = false;
m_navTimeset = engine.Time ();
Vector src = m_breakable;
Vector src = m_breakableOrigin;
m_camp = src;
// is bot facing the breakable?
@ -5322,18 +5322,18 @@ void Bot::TakeDamage (edict_t *inflictor, int damage, int armor, int bits)
}
}
void Bot::TakeBlinded (const Vector &fade, int alpha)
void Bot::TakeBlinded (int r, int g, int b, int alpha)
{
// this function gets called by network message handler, when screenfade message get's send
// it's used to make bot blind from the grenade.
if (fade.x != 255.0f || fade.y != 255.0f || fade.z != 255.0f || alpha <= 170.0f)
if (r != 255 || g != 255 || b != 255 || alpha <= 170)
return;
m_enemy = NULL;
m_maxViewDistance = Random.Float (10.0f, 20.0f);
m_blindTime = engine.Time () + static_cast <float> (alpha - 200.0f) / 16.0f;
m_blindTime = engine.Time () + static_cast <float> (alpha - 200) / 16.0f;
if (m_difficulty <= 2)
{
@ -5577,13 +5577,13 @@ void Bot::DebugMsg (const char *format, ...)
return;
va_list ap;
char buffer[1024];
char buffer[MAX_PRINT_BUFFER];
va_start (ap, format);
vsprintf (buffer, format, ap);
vsnprintf (buffer, SIZEOF_CHAR (buffer), format, ap);
va_end (ap);
char printBuf[1024];
char printBuf[MAX_PRINT_BUFFER];
sprintf (printBuf, "%s: %s", STRING (pev->netname), buffer);
bool playMessage = false;
@ -5618,7 +5618,7 @@ Vector Bot::CheckToss(const Vector &start, const Vector &stop)
return Vector::GetZero ();
Vector midPoint = start + (end - start) * 0.5f;
engine.TestHull (midPoint, midPoint + Vector (0.0f, 0.0f, 500.0f), TRACE_IGNORE_MONSTERS, head_hull, ENT (pev), &tr);
engine.TestHull (midPoint, midPoint + Vector (0.0f, 0.0f, 500.0f), TRACE_IGNORE_MONSTERS, head_hull, GetEntity (), &tr);
if (tr.flFraction < 1.0f)
{
@ -5641,12 +5641,12 @@ Vector Bot::CheckToss(const Vector &start, const Vector &stop)
Vector apex = start + nadeVelocity * timeOne;
apex.z = midPoint.z;
engine.TestHull (start, apex, TRACE_IGNORE_NONE, head_hull, ENT (pev), &tr);
engine.TestHull (start, apex, TRACE_IGNORE_NONE, head_hull, GetEntity (), &tr);
if (tr.flFraction < 1.0f || tr.fAllSolid)
return Vector::GetZero ();
engine.TestHull (end, apex, TRACE_IGNORE_MONSTERS, head_hull, ENT (pev), &tr);
engine.TestHull (end, apex, TRACE_IGNORE_MONSTERS, head_hull, GetEntity (), &tr);
if (tr.flFraction != 1.0f)
{

View file

@ -345,7 +345,7 @@ bool Bot::LookupEnemy (void)
Bot *friendBot = bots.GetBot (g_clients[j].ent);
if (friendBot != NULL && friendBot->m_seeEnemyTime + 2.0f < engine.Time () && engine.IsNullEntity (friendBot->m_lastEnemy) && IsVisible (pev->origin, ENT (friendBot->pev)) && friendBot->IsInViewCone (pev->origin))
if (friendBot != NULL && friendBot->m_seeEnemyTime + 2.0f < engine.Time () && engine.IsNullEntity (friendBot->m_lastEnemy) && IsVisible (pev->origin, friendBot->GetEntity ()) && friendBot->IsInViewCone (pev->origin))
{
friendBot->m_lastEnemy = newEnemy;
friendBot->m_lastEnemyOrigin = m_lastEnemyOrigin;

View file

@ -9,6 +9,27 @@
#include <core.h>
Engine::Engine (void)
{
m_startEntity = NULL;
m_localEntity = NULL;
m_language.RemoveAll ();
ResetMessageCapture ();
for (int i = 0; i < NETMSG_NUM; i++)
m_msgBlock.regMsgs[i] = NETMSG_UNDEFINED;
}
Engine::~Engine (void)
{
TerminateTranslator ();
ResetMessageCapture ();
for (int i = 0; i < NETMSG_NUM; i++)
m_msgBlock.regMsgs[i] = NETMSG_UNDEFINED;
}
void Engine::Precache (edict_t *startEntity)
{
// this function precaches needed models and initialize class variables
@ -29,10 +50,10 @@ void Engine::Printf (const char *fmt, ...)
// this function outputs string into server console
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
va_start (ap, fmt);
vsnprintf (string, SIZEOF_CHAR (string), locale.TranslateInput (fmt), ap);
vsnprintf (string, SIZEOF_CHAR (string), TraslateMessage (fmt), ap);
va_end (ap);
g_engfuncs.pfnServerPrint (string);
@ -42,20 +63,20 @@ void Engine::Printf (const char *fmt, ...)
void Engine::ChatPrintf (const char *fmt, ...)
{
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
va_start (ap, fmt);
vsnprintf (string, SIZEOF_CHAR (string), locale.TranslateInput (fmt), ap);
vsnprintf (string, SIZEOF_CHAR (string), TraslateMessage (fmt), ap);
va_end (ap);
if (IsDedicatedServer ())
{
engine.Printf (string);
Printf (string);
return;
}
strcat (string, "\n");
MESSAGE_BEGIN (MSG_BROADCAST, netmsg.GetId (NETMSG_TEXTMSG));
MESSAGE_BEGIN (MSG_BROADCAST, FindMessageId (NETMSG_TEXTMSG));
WRITE_BYTE (HUD_PRINTTALK);
WRITE_STRING (string);
MESSAGE_END ();
@ -64,20 +85,20 @@ void Engine::ChatPrintf (const char *fmt, ...)
void Engine::CenterPrintf (const char *fmt, ...)
{
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
va_start (ap, fmt);
vsnprintf (string, SIZEOF_CHAR (string), locale.TranslateInput (fmt), ap);
vsnprintf (string, SIZEOF_CHAR (string), TraslateMessage (fmt), ap);
va_end (ap);
if (IsDedicatedServer ())
{
engine.Printf (string);
Printf (string);
return;
}
strcat (string, "\n");
MESSAGE_BEGIN (MSG_BROADCAST, netmsg.GetId (NETMSG_TEXTMSG));
MESSAGE_BEGIN (MSG_BROADCAST, FindMessageId (NETMSG_TEXTMSG));
WRITE_BYTE (HUD_PRINTCENTER);
WRITE_STRING (string);
MESSAGE_END ();
@ -86,15 +107,15 @@ void Engine::CenterPrintf (const char *fmt, ...)
void Engine::ClientPrintf (edict_t *ent, const char *fmt, ...)
{
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
va_start (ap, fmt);
vsnprintf (string, SIZEOF_CHAR (string), locale.TranslateInput (fmt), ap);
vsnprintf (string, SIZEOF_CHAR (string), TraslateMessage (fmt), ap);
va_end (ap);
if (engine.IsNullEntity (ent) || ent == g_hostEntity)
if (IsNullEntity (ent) || ent == g_hostEntity)
{
engine.Printf (string);
Printf (string);
return;
}
strcat (string, "\n");
@ -279,7 +300,7 @@ Vector Engine::GetAbsOrigin (edict_t *ent)
// this expanded function returns the vector origin of a bounded entity, assuming that any
// entity that has a bounding box has its center at the center of the bounding box itself.
if (engine.IsNullEntity (ent))
if (IsNullEntity (ent))
return Vector::GetZero ();
if (ent->v.origin.IsZero ())
@ -311,7 +332,7 @@ void Engine::IssueBotCommand (edict_t *ent, const char *fmt, ...)
// supply directly the whole string as if you were typing it in the bot's "console". It
// is supposed to work exactly like the pfnClientCommand (server-sided client command).
if (engine.IsNullEntity (ent))
if (IsNullEntity (ent))
return;
va_list ap;
@ -442,7 +463,7 @@ void Engine::IssueCmd (const char *fmt, ...)
// this function asks the engine to execute a server command
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
// concatenate all the arguments in one string
va_start (ap, fmt);
@ -453,7 +474,7 @@ void Engine::IssueCmd (const char *fmt, ...)
g_engfuncs.pfnServerCommand (string);
}
void ConVarWrapper::RegisterVariable(const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self)
void Engine::PushVariableToStack (const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self)
{
// this function adds globally defined variable to registration stack
@ -477,16 +498,16 @@ void ConVarWrapper::RegisterVariable(const char *variable, const char *value, Va
pair.self = self;
pair.type = varType;
m_regs.Push (pair);
m_cvars.Push (pair);
}
void ConVarWrapper::PushRegisteredConVarsToEngine (bool gameVars)
void Engine::PushRegisteredConVarsToEngine (bool gameVars)
{
// this function pushes all added global variables to engine registration
FOR_EACH_AE (m_regs, i)
FOR_EACH_AE (m_cvars, i)
{
VarPair *ptr = &m_regs[i];
VarPair *ptr = &m_cvars[i];
if (ptr->type != VT_NOREGISTER)
{
@ -512,7 +533,526 @@ void ConVarWrapper::PushRegisteredConVarsToEngine (bool gameVars)
}
}
char *Engine::TraslateMessage (const char *input)
{
// this function translate input string into needed language
if (IsDedicatedServer ())
return const_cast <char *> (&input[0]);
static char string[MAX_PRINT_BUFFER];
const char *ptr = input + strlen (input) - 1;
while (ptr > input && *ptr == '\n')
ptr--;
if (ptr != input)
ptr++;
strncpy (string, input, SIZEOF_CHAR (string));
String::TrimExternalBuffer (string);
FOR_EACH_AE (m_language, i)
{
if (strcmp (string, m_language[i].original) == 0)
{
strncpy (string, m_language[i].translated, SIZEOF_CHAR (string));
if (ptr != input)
strncat (string, ptr, MAX_PRINT_BUFFER - 1 - strlen (string));
return &string[0];
}
}
return const_cast <char *> (&input[0]); // nothing found
}
void Engine::TerminateTranslator (void)
{
// this function terminates language translator and frees all memory
FOR_EACH_AE (m_language, it)
{
delete[] m_language[it].original;
delete[] m_language[it].translated;
}
m_language.RemoveAll ();
}
void Engine::ProcessMesageCapture (void *ptr)
{
if (m_msgBlock.msg == NETMSG_UNDEFINED)
return;
// some needed variables
static byte r, g, b;
static byte enabled;
static int damageArmor, damageTaken, damageBits;
static int killerIndex, victimIndex, playerIndex;
static int index, numPlayers;
static int state, id, clip;
static Vector damageOrigin;
static WeaponProperty weaponProp;
// some widely used stuff
Bot *bot = bots.GetBot (m_msgBlock.bot);
char *strVal = reinterpret_cast <char *> (ptr);
int intVal = *reinterpret_cast <int *> (ptr);
unsigned char byteVal = *reinterpret_cast <unsigned char *> (ptr);
// now starts of network message execution
switch (m_msgBlock.msg)
{
case NETMSG_VGUI:
// this message is sent when a VGUI menu is displayed.
if (m_msgBlock.state == 0)
{
switch (intVal)
{
case VMS_TEAM:
bot->m_startAction = GSM_TEAM_SELECT;
break;
case VMS_TF:
case VMS_CT:
bot->m_startAction = GSM_CLASS_SELECT;
break;
}
}
break;
case NETMSG_SHOWMENU:
// this message is sent when a text menu is displayed.
if (m_msgBlock.state < 3) // ignore first 3 fields of message
break;
if (strcmp (strVal, "#Team_Select") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#Team_Select_Spect") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#IG_Team_Select_Spect") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#IG_Team_Select") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#IG_VIP_Team_Select") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#IG_VIP_Team_Select_Spect") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#Terrorist_Select") == 0) // T model select?
bot->m_startAction = GSM_CLASS_SELECT;
else if (strcmp (strVal, "#CT_Select") == 0) // CT model select menu?
bot->m_startAction = GSM_CLASS_SELECT;
break;
case NETMSG_WEAPONLIST:
// this message is sent when a client joins the game. All of the weapons are sent with the weapon ID and information about what ammo is used.
switch (m_msgBlock.state)
{
case 0:
strncpy (weaponProp.className, strVal, SIZEOF_CHAR (weaponProp.className));
break;
case 1:
weaponProp.ammo1 = intVal; // ammo index 1
break;
case 2:
weaponProp.ammo1Max = intVal; // max ammo 1
break;
case 5:
weaponProp.slotID = intVal; // slot for this weapon
break;
case 6:
weaponProp.position = intVal; // position in slot
break;
case 7:
weaponProp.id = intVal; // weapon ID
break;
case 8:
weaponProp.flags = intVal; // flags for weapon (WTF???)
g_weaponDefs[weaponProp.id] = weaponProp; // store away this weapon with it's ammo information...
break;
}
break;
case NETMSG_CURWEAPON:
// this message is sent when a weapon is selected (either by the bot chosing a weapon or by the server auto assigning the bot a weapon). In CS it's also called when Ammo is increased/decreased
switch (m_msgBlock.state)
{
case 0:
state = intVal; // state of the current weapon (WTF???)
break;
case 1:
id = intVal; // weapon ID of current weapon
break;
case 2:
clip = intVal; // ammo currently in the clip for this weapon
if (id <= 31)
{
if (state != 0)
bot->m_currentWeapon = id;
// ammo amount decreased ? must have fired a bullet...
if (id == bot->m_currentWeapon && bot->m_ammoInClip[id] > clip)
bot->m_timeLastFired = Time (); // remember the last bullet time
bot->m_ammoInClip[id] = clip;
}
break;
}
break;
case NETMSG_AMMOX:
// this message is sent whenever ammo amounts are adjusted (up or down). NOTE: Logging reveals that CS uses it very unreliable!
switch (m_msgBlock.state)
{
case 0:
index = intVal; // ammo index (for type of ammo)
break;
case 1:
bot->m_ammo[index] = intVal; // store it away
break;
}
break;
case NETMSG_AMMOPICKUP:
// this message is sent when the bot picks up some ammo (AmmoX messages are also sent so this message is probably
// not really necessary except it allows the HUD to draw pictures of ammo that have been picked up. The bots
// don't really need pictures since they don't have any eyes anyway.
switch (m_msgBlock.state)
{
case 0:
index = intVal;
break;
case 1:
bot->m_ammo[index] = intVal;
break;
}
break;
case NETMSG_DAMAGE:
// this message gets sent when the bots are getting damaged.
switch (m_msgBlock.state)
{
case 0:
damageArmor = intVal;
break;
case 1:
damageTaken = intVal;
break;
case 2:
damageBits = intVal;
if (bot != NULL && (damageArmor > 0 || damageTaken > 0))
bot->TakeDamage (bot->pev->dmg_inflictor, damageTaken, damageArmor, damageBits);
break;
}
break;
case NETMSG_MONEY:
// this message gets sent when the bots money amount changes
if (m_msgBlock.state == 0)
bot->m_moneyAmount = intVal; // amount of money
break;
case NETMSG_STATUSICON:
switch (m_msgBlock.state)
{
case 0:
enabled = byteVal;
break;
case 1:
if (strcmp (strVal, "defuser") == 0)
bot->m_hasDefuser = (enabled != 0);
else if (strcmp (strVal, "buyzone") == 0)
{
bot->m_inBuyZone = (enabled != 0);
// try to equip in buyzone
bot->EquipInBuyzone (BUYSTATE_PRIMARY_WEAPON);
}
else if (strcmp (strVal, "vipsafety") == 0)
bot->m_inVIPZone = (enabled != 0);
else if (strcmp (strVal, "c4") == 0)
bot->m_inBombZone = (enabled == 2);
break;
}
break;
case NETMSG_DEATH: // this message sends on death
switch (m_msgBlock.state)
{
case 0:
killerIndex = intVal;
break;
case 1:
victimIndex = intVal;
break;
case 2:
bots.SetDeathMsgState (true);
if (killerIndex != 0 && killerIndex != victimIndex)
{
edict_t *killer = EntityOfIndex (killerIndex);
edict_t *victim = EntityOfIndex (victimIndex);
if (IsNullEntity (killer) || IsNullEntity (victim))
break;
if (yb_communication_type.GetInt () == 2)
{
// need to send congrats on well placed shot
for (int i = 0; i < MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_notKilled && killer != bot->GetEntity () && bot->EntityIsVisible (victim->v.origin) && GetTeam (killer) == bot->m_team && GetTeam (killer) != GetTeam (victim))
{
if (killer == g_hostEntity)
bot->HandleChatterMessage ("#Bot_NiceShotCommander");
else
bot->HandleChatterMessage ("#Bot_NiceShotPall");
break;
}
}
}
// notice nearby to victim teammates, that attacker is near
for (int i = 0; i < MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_seeEnemyTime + 2.0f < Time () && bot->m_notKilled && bot->m_team == GetTeam (victim) && IsVisible (killer->v.origin, bot->GetEntity ()) && IsNullEntity (bot->m_enemy) && GetTeam (killer) != GetTeam (victim))
{
bot->m_actualReactionTime = 0.0f;
bot->m_seeEnemyTime = Time ();
bot->m_enemy = killer;
bot->m_lastEnemy = killer;
bot->m_lastEnemyOrigin = killer->v.origin;
}
}
Bot *bot = bots.GetBot (killer);
// is this message about a bot who killed somebody?
if (bot != NULL)
bot->m_lastVictim = victim;
else // did a human kill a bot on his team?
{
Bot *target = bots.GetBot (victim);
if (target != NULL)
{
if (GetTeam (killer) == GetTeam (victim))
target->m_voteKickIndex = killerIndex;
target->m_notKilled = false;
}
}
}
break;
}
break;
case NETMSG_SCREENFADE: // this message gets sent when the screen fades (flashbang)
switch (m_msgBlock.state)
{
case 3:
r = byteVal;
break;
case 4:
g = byteVal;
break;
case 5:
b = byteVal;
break;
case 6:
bot->TakeBlinded (r, g, b, byteVal);
break;
}
break;
case NETMSG_HLTV: // round restart in steam cs
switch (m_msgBlock.state)
{
case 0:
numPlayers = intVal;
break;
case 1:
if (numPlayers == 0 && intVal == 0)
RoundInit ();
break;
}
break;
case NETMSG_TEXTMSG:
if (m_msgBlock.state == 1)
{
if (FStrEq (strVal, "#CTs_Win") ||
FStrEq (strVal, "#Bomb_Defused") ||
FStrEq (strVal, "#Terrorists_Win") ||
FStrEq (strVal, "#Round_Draw") ||
FStrEq (strVal, "#All_Hostages_Rescued") ||
FStrEq (strVal, "#Target_Saved") ||
FStrEq (strVal, "#Hostages_Not_Rescued") ||
FStrEq (strVal, "#Terrorists_Not_Escaped") ||
FStrEq (strVal, "#VIP_Not_Escaped") ||
FStrEq (strVal, "#Escaping_Terrorists_Neutralized") ||
FStrEq (strVal, "#VIP_Assassinated") ||
FStrEq (strVal, "#VIP_Escaped") ||
FStrEq (strVal, "#Terrorists_Escaped") ||
FStrEq (strVal, "#CTs_PreventEscape") ||
FStrEq (strVal, "#Target_Bombed") ||
FStrEq (strVal, "#Game_Commencing") ||
FStrEq (strVal, "#Game_will_restart_in"))
{
g_roundEnded = true;
if (FStrEq (strVal, "#Game_Commencing"))
g_isCommencing = true;
if (FStrEq (strVal, "#CTs_Win"))
{
bots.SetLastWinner (CT); // update last winner for economics
if (yb_communication_type.GetInt () == 2)
{
Bot *bot = bots.FindOneValidAliveBot ();
if (bot != NULL && bot->m_notKilled)
bot->HandleChatterMessage (strVal);
}
}
if (FStrEq (strVal, "#Game_will_restart_in"))
{
bots.CheckTeamEconomics (CT, true);
bots.CheckTeamEconomics (TERRORIST, true);
}
if (FStrEq (strVal, "#Terrorists_Win"))
{
bots.SetLastWinner (TERRORIST); // update last winner for economics
if (yb_communication_type.GetInt () == 2)
{
Bot *bot = bots.FindOneValidAliveBot ();
if (bot != NULL && bot->m_notKilled)
bot->HandleChatterMessage (strVal);
}
}
waypoints.SetBombPosition (true);
}
else if (!g_bombPlanted && FStrEq (strVal, "#Bomb_Planted"))
{
waypoints.SetBombPosition ();
g_bombPlanted = g_bombSayString = true;
g_timeBombPlanted = Time ();
for (int i = 0; i < MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_notKilled)
{
bot->DeleteSearchNodes ();
bot->ResetTasks ();
if (yb_communication_type.GetInt () == 2 && Random.Long (0, 100) < 75 && bot->m_team == CT)
bot->ChatterMessage (Chatter_WhereIsTheBomb);
}
}
}
else if (bot != NULL && FStrEq (strVal, "#Switch_To_BurstFire"))
bot->m_weaponBurstMode = BM_ON;
else if (bot != NULL && FStrEq (strVal, "#Switch_To_SemiAuto"))
bot->m_weaponBurstMode = BM_OFF;
}
break;
case NETMSG_SCOREINFO:
switch (m_msgBlock.state)
{
case 0:
playerIndex = intVal;
break;
case 4:
if (playerIndex >= 0 && playerIndex <= MaxClients ())
{
#ifndef XASH_CSDM
Client &cl = g_clients[playerIndex - 1];
if (intVal == 1)
cl.realTeam = TERRORIST;
else if (intVal == 2)
cl.realTeam = CT;
else
cl.realTeam = SPECTATOR;
if (yb_csdm_mode.GetInt () == 2)
cl.team = playerIndex;
else
cl.team = cl.realTeam;
#endif
}
break;
}
break;
case NETMSG_BARTIME:
if (m_msgBlock.state == 0)
{
if (intVal > 0)
bot->m_hasProgressBar = true; // the progress bar on a hud
else if (intVal == 0)
bot->m_hasProgressBar = false; // no progress bar or disappeared
}
break;
default:
AddLogEntry (true, LL_FATAL, "Network message handler error. Call to unrecognized message id (%d).\n", m_msgBlock.msg);
}
m_msgBlock.state++; // and finally update network message state
}
ConVar::ConVar (const char *name, const char *initval, VarType type, bool regMissing) : m_eptr (NULL)
{
ConVarWrapper::GetReference ().RegisterVariable (name, initval, type, regMissing, this);
engine.PushVariableToStack (name, initval, type, regMissing, this);
}

View file

@ -9,6 +9,13 @@
#include <core.h>
// forward for super-globals
//NetworkMsg netmsg;
//Localizer locale;
//Waypoint waypoints;
//BotManager bots;
//Engine engine;
bool g_canSayBombPlanted = true;
bool g_isMetamod = false;
bool g_radioInsteadVoice = false;
@ -98,10 +105,10 @@ int *g_weaponPrefs[] =
// metamod engine & dllapi function tables
metamod_funcs_t gMetaFunctionTable =
{
NULL, // pfnEntityAPI_t ()
NULL, // pfnEntityAPI_t_Post ()
GetEntityAPI2, // pfnEntityAPI_t2 ()
GetEntityAPI2_Post, // pfnEntityAPI_t2_Post ()
NULL, // pfnGetEntityAPI ()
NULL, // pfnGetEntityAPI_Post ()
GetEntityAPI2, // pfnGetEntityAPI2 ()
GetEntityAPI2_Post, // pfnGetEntityAPI2_Post ()
NULL, // pfnGetNewDLLFunctions ()
NULL, // pfnGetNewDLLFunctions_Post ()
GetEngineFunctions, // pfnGetEngineFunctions ()
@ -424,10 +431,3 @@ MenuText g_menus[21] =
"0. Exit"
}
};
// forward for super-globals
NetworkMsg netmsg;
Localizer locale;
Waypoint waypoints;
BotManager bots;
Engine engine;

View file

@ -1,4 +1,4 @@
//
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team.
//
@ -300,7 +300,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c
// save waypoint data into file on hard disk
else if (stricmp (arg1, "save") == 0)
{
char *waypointSaveMessage = locale.TranslateInput ("Waypoints Saved");
char *waypointSaveMessage = engine.TraslateMessage ("Waypoints Saved");
if (FStrEq (arg2, "nocheck"))
{
@ -850,7 +850,7 @@ void InitConfig (void)
enum Lang { Lang_Original, Lang_Translate } langState = static_cast <Lang> (2);
char buffer[1024];
LanguageItem temp = {"", ""};
Engine::TranslatorPair temp = {"", ""};
while (fp.GetBuffer (line, 255))
{
@ -866,7 +866,7 @@ void InitConfig (void)
}
if (!IsNullString (temp.translated) && !IsNullString (temp.original))
locale.m_langTab.Push (temp);
engine.PushTranslationPair (temp);
}
else if (strncmp (line, "[TRANSLATED]", 12) == 0)
{
@ -1013,8 +1013,7 @@ int Spawn (edict_t *ent)
if (strcmp (entityClassname, "worldspawn") == 0)
{
engine.Precache (ent);
ConVarWrapper::GetReference ().PushRegisteredConVarsToEngine (true);
engine.PushRegisteredConVarsToEngine (true);
PRECACHE_SOUND (ENGINE_STR ("weapons/xbow_hit1.wav")); // waypoint add
PRECACHE_SOUND (ENGINE_STR ("weapons/mine_activate.wav")); // waypoint delete
@ -1024,7 +1023,7 @@ int Spawn (edict_t *ent)
PRECACHE_SOUND (ENGINE_STR ("common/wpn_denyselect.wav")); // path add/delete error
RoundInit ();
g_mapType = NULL; // reset map type as worldspawn is the first entity spawned
g_mapType = 0; // reset map type as worldspawn is the first entity spawned
// detect official csbots here, as they causing crash in linkent code when active for some reason
if (!(g_gameFlags & GAME_LEGACY) && g_engfuncs.pfnCVarGetPointer ("bot_stop") != NULL)
@ -2071,7 +2070,7 @@ void ClientCommand (edict_t *ent)
Bot *bot = bots.GetBot (i);
// validate bot
if (bot != NULL && bot->m_team == g_clients[clientIndex].team && VARS (ent) != bot->pev && bot->m_radioOrder == 0)
if (bot != NULL && bot->m_team == g_clients[clientIndex].team && ent != bot->GetEntity () && bot->m_radioOrder == 0)
{
bot->m_radioOrder = radioCommand;
bot->m_radioEntity = ent;
@ -2370,7 +2369,7 @@ void pfnEmitSound (edict_t *entity, int channel, const char *sample, float volum
(*g_engfuncs.pfnEmitSound) (entity, channel, sample, volume, attenuation, flags, pitch);
}
void pfnClientCommand (edict_t *ent, char *format, ...)
void pfnClientCommand (edict_t *ent, char const *format, ...)
{
// this function forces the client whose player entity is ent to issue a client command.
// How it works is that clients all have a g_xgv global string in their client DLL that
@ -2413,69 +2412,67 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed
// this function called each time a message is about to sent.
// store the message type in our own variables, since the GET_USER_MSG_ID () will just do a lot of strcmp()'s...
if (g_isMetamod && netmsg.GetId (NETMSG_MONEY) == -1)
if (g_isMetamod && engine.FindMessageId (NETMSG_MONEY) == -1)
{
netmsg.SetId (NETMSG_VGUI, GET_USER_MSG_ID (PLID, "VGUIMenu", NULL));
netmsg.SetId (NETMSG_SHOWMENU, GET_USER_MSG_ID (PLID, "ShowMenu", NULL));
netmsg.SetId (NETMSG_WEAPONLIST, GET_USER_MSG_ID (PLID, "WeaponList", NULL));
netmsg.SetId (NETMSG_CURWEAPON, GET_USER_MSG_ID (PLID, "CurWeapon", NULL));
netmsg.SetId (NETMSG_AMMOX, GET_USER_MSG_ID (PLID, "AmmoX", NULL));
netmsg.SetId (NETMSG_AMMOPICKUP, GET_USER_MSG_ID (PLID, "AmmoPickup", NULL));
netmsg.SetId (NETMSG_DAMAGE, GET_USER_MSG_ID (PLID, "Damage", NULL));
netmsg.SetId (NETMSG_MONEY, GET_USER_MSG_ID (PLID, "Money", NULL));
netmsg.SetId (NETMSG_STATUSICON, GET_USER_MSG_ID (PLID, "StatusIcon", NULL));
netmsg.SetId (NETMSG_DEATH, GET_USER_MSG_ID (PLID, "DeathMsg", NULL));
netmsg.SetId (NETMSG_SCREENFADE, GET_USER_MSG_ID (PLID, "ScreenFade", NULL));
netmsg.SetId (NETMSG_HLTV, GET_USER_MSG_ID (PLID, "HLTV", NULL));
netmsg.SetId (NETMSG_TEXTMSG, GET_USER_MSG_ID (PLID, "TextMsg", NULL));
netmsg.SetId (NETMSG_SCOREINFO, GET_USER_MSG_ID (PLID, "ScoreInfo", NULL));
netmsg.SetId (NETMSG_BARTIME, GET_USER_MSG_ID (PLID, "BarTime", NULL));
netmsg.SetId (NETMSG_SENDAUDIO, GET_USER_MSG_ID (PLID, "SendAudio", NULL));
netmsg.SetId (NETMSG_SAYTEXT, GET_USER_MSG_ID (PLID, "SayText", NULL));
netmsg.SetId (NETMSG_RESETHUD, GET_USER_MSG_ID (PLID, "ResetHUD", NULL));
engine.AssignMessageId (NETMSG_VGUI, GET_USER_MSG_ID (PLID, "VGUIMenu", NULL));
engine.AssignMessageId (NETMSG_SHOWMENU, GET_USER_MSG_ID (PLID, "ShowMenu", NULL));
engine.AssignMessageId (NETMSG_WEAPONLIST, GET_USER_MSG_ID (PLID, "WeaponList", NULL));
engine.AssignMessageId (NETMSG_CURWEAPON, GET_USER_MSG_ID (PLID, "CurWeapon", NULL));
engine.AssignMessageId (NETMSG_AMMOX, GET_USER_MSG_ID (PLID, "AmmoX", NULL));
engine.AssignMessageId (NETMSG_AMMOPICKUP, GET_USER_MSG_ID (PLID, "AmmoPickup", NULL));
engine.AssignMessageId (NETMSG_DAMAGE, GET_USER_MSG_ID (PLID, "Damage", NULL));
engine.AssignMessageId (NETMSG_MONEY, GET_USER_MSG_ID (PLID, "Money", NULL));
engine.AssignMessageId (NETMSG_STATUSICON, GET_USER_MSG_ID (PLID, "StatusIcon", NULL));
engine.AssignMessageId (NETMSG_DEATH, GET_USER_MSG_ID (PLID, "DeathMsg", NULL));
engine.AssignMessageId (NETMSG_SCREENFADE, GET_USER_MSG_ID (PLID, "ScreenFade", NULL));
engine.AssignMessageId (NETMSG_HLTV, GET_USER_MSG_ID (PLID, "HLTV", NULL));
engine.AssignMessageId (NETMSG_TEXTMSG, GET_USER_MSG_ID (PLID, "TextMsg", NULL));
engine.AssignMessageId (NETMSG_SCOREINFO, GET_USER_MSG_ID (PLID, "ScoreInfo", NULL));
engine.AssignMessageId (NETMSG_BARTIME, GET_USER_MSG_ID (PLID, "BarTime", NULL));
engine.AssignMessageId (NETMSG_SENDAUDIO, GET_USER_MSG_ID (PLID, "SendAudio", NULL));
engine.AssignMessageId (NETMSG_SAYTEXT, GET_USER_MSG_ID (PLID, "SayText", NULL));
if (!(g_gameFlags & GAME_LEGACY))
netmsg.SetId (NETMSG_BOTVOICE, GET_USER_MSG_ID (PLID, "BotVoice", NULL));
engine.AssignMessageId (NETMSG_BOTVOICE, GET_USER_MSG_ID (PLID, "BotVoice", NULL));
}
netmsg.Reset ();
engine.ResetMessageCapture ();
if (msgDest == MSG_SPEC && msgType == netmsg.GetId (NETMSG_HLTV) && !(g_gameFlags & GAME_LEGACY))
netmsg.SetMessage (NETMSG_HLTV);
if ((!(g_gameFlags & GAME_LEGACY) || (g_gameFlags & GAME_XASH)) && msgDest == MSG_SPEC && msgType == engine.FindMessageId (NETMSG_HLTV))
engine.SetOngoingMessageId (NETMSG_HLTV);
netmsg.HandleMessageIfRequired (msgType, NETMSG_WEAPONLIST);
engine.TryCaptureMessage (msgType, NETMSG_WEAPONLIST);
if (!engine.IsNullEntity (ed))
{
int index = bots.GetIndex (ed);
// is this message for a bot?
if (index != -1 && !(ed->v.flags & FL_DORMANT) && bots.GetBot (index)->GetEntity () == ed)
if (index != -1 && !(ed->v.flags & FL_DORMANT))
{
netmsg.Reset ();
netmsg.SetBot (bots.GetBot (index));
engine.ResetMessageCapture ();
engine.SetOngoingMessageReceiver (index);
// message handling is done in usermsg.cpp
netmsg.HandleMessageIfRequired (msgType, NETMSG_VGUI);
netmsg.HandleMessageIfRequired (msgType, NETMSG_CURWEAPON);
netmsg.HandleMessageIfRequired (msgType, NETMSG_AMMOX);
netmsg.HandleMessageIfRequired (msgType, NETMSG_AMMOPICKUP);
netmsg.HandleMessageIfRequired (msgType, NETMSG_DAMAGE);
netmsg.HandleMessageIfRequired (msgType, NETMSG_MONEY);
netmsg.HandleMessageIfRequired (msgType, NETMSG_STATUSICON);
netmsg.HandleMessageIfRequired (msgType, NETMSG_SCREENFADE);
netmsg.HandleMessageIfRequired (msgType, NETMSG_BARTIME);
netmsg.HandleMessageIfRequired (msgType, NETMSG_TEXTMSG);
netmsg.HandleMessageIfRequired (msgType, NETMSG_SHOWMENU);
netmsg.HandleMessageIfRequired (msgType, NETMSG_RESETHUD);
engine.TryCaptureMessage (msgType, NETMSG_VGUI);
engine.TryCaptureMessage (msgType, NETMSG_CURWEAPON);
engine.TryCaptureMessage (msgType, NETMSG_AMMOX);
engine.TryCaptureMessage (msgType, NETMSG_AMMOPICKUP);
engine.TryCaptureMessage (msgType, NETMSG_DAMAGE);
engine.TryCaptureMessage (msgType, NETMSG_MONEY);
engine.TryCaptureMessage (msgType, NETMSG_STATUSICON);
engine.TryCaptureMessage (msgType, NETMSG_SCREENFADE);
engine.TryCaptureMessage (msgType, NETMSG_BARTIME);
engine.TryCaptureMessage (msgType, NETMSG_TEXTMSG);
engine.TryCaptureMessage (msgType, NETMSG_SHOWMENU);
}
}
else if (msgDest == MSG_ALL)
{
netmsg.Reset ();
engine.ResetMessageCapture ();
netmsg.HandleMessageIfRequired (msgType, NETMSG_SCOREINFO);
netmsg.HandleMessageIfRequired (msgType, NETMSG_DEATH);
netmsg.HandleMessageIfRequired (msgType, NETMSG_TEXTMSG);
engine.TryCaptureMessage (msgType, NETMSG_SCOREINFO);
engine.TryCaptureMessage (msgType, NETMSG_DEATH);
engine.TryCaptureMessage (msgType, NETMSG_TEXTMSG);
if (msgType == SVC_INTERMISSION)
{
@ -2497,7 +2494,7 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed
void pfnMessageEnd (void)
{
netmsg.Reset ();
engine.ResetMessageCapture ();
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2519,7 +2516,7 @@ void pfnMessageEnd_Post (void)
void pfnWriteByte (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2530,7 +2527,7 @@ void pfnWriteByte (int value)
void pfnWriteChar (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2541,7 +2538,7 @@ void pfnWriteChar (int value)
void pfnWriteShort (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2552,7 +2549,7 @@ void pfnWriteShort (int value)
void pfnWriteLong (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2563,7 +2560,7 @@ void pfnWriteLong (int value)
void pfnWriteAngle (float value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2574,7 +2571,7 @@ void pfnWriteAngle (float value)
void pfnWriteCoord (float value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2585,7 +2582,7 @@ void pfnWriteCoord (float value)
void pfnWriteString (const char *sz)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) sz);
engine.ProcessMesageCapture ((void *) sz);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2596,7 +2593,7 @@ void pfnWriteString (const char *sz)
void pfnWriteEntity (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2729,43 +2726,41 @@ int pfnRegUserMsg (const char *name, int size)
int message = REG_USER_MSG (name, size);
if (strcmp (name, "VGUIMenu") == 0)
netmsg.SetId (NETMSG_VGUI, message);
engine.AssignMessageId (NETMSG_VGUI, message);
else if (strcmp (name, "ShowMenu") == 0)
netmsg.SetId (NETMSG_SHOWMENU, message);
engine.AssignMessageId (NETMSG_SHOWMENU, message);
else if (strcmp (name, "WeaponList") == 0)
netmsg.SetId (NETMSG_WEAPONLIST, message);
engine.AssignMessageId (NETMSG_WEAPONLIST, message);
else if (strcmp (name, "CurWeapon") == 0)
netmsg.SetId (NETMSG_CURWEAPON, message);
engine.AssignMessageId (NETMSG_CURWEAPON, message);
else if (strcmp (name, "AmmoX") == 0)
netmsg.SetId (NETMSG_AMMOX, message);
engine.AssignMessageId (NETMSG_AMMOX, message);
else if (strcmp (name, "AmmoPickup") == 0)
netmsg.SetId (NETMSG_AMMOPICKUP, message);
engine.AssignMessageId (NETMSG_AMMOPICKUP, message);
else if (strcmp (name, "Damage") == 0)
netmsg.SetId (NETMSG_DAMAGE, message);
engine.AssignMessageId (NETMSG_DAMAGE, message);
else if (strcmp (name, "Money") == 0)
netmsg.SetId (NETMSG_MONEY, message);
engine.AssignMessageId (NETMSG_MONEY, message);
else if (strcmp (name, "StatusIcon") == 0)
netmsg.SetId (NETMSG_STATUSICON, message);
engine.AssignMessageId (NETMSG_STATUSICON, message);
else if (strcmp (name, "DeathMsg") == 0)
netmsg.SetId (NETMSG_DEATH, message);
engine.AssignMessageId (NETMSG_DEATH, message);
else if (strcmp (name, "ScreenFade") == 0)
netmsg.SetId (NETMSG_SCREENFADE, message);
engine.AssignMessageId (NETMSG_SCREENFADE, message);
else if (strcmp (name, "HLTV") == 0)
netmsg.SetId (NETMSG_HLTV, message);
engine.AssignMessageId (NETMSG_HLTV, message);
else if (strcmp (name, "TextMsg") == 0)
netmsg.SetId (NETMSG_TEXTMSG, message);
engine.AssignMessageId (NETMSG_TEXTMSG, message);
else if (strcmp (name, "ScoreInfo") == 0)
netmsg.SetId (NETMSG_SCOREINFO, message);
engine.AssignMessageId (NETMSG_SCOREINFO, message);
else if (strcmp (name, "BarTime") == 0)
netmsg.SetId (NETMSG_BARTIME, message);
engine.AssignMessageId (NETMSG_BARTIME, message);
else if (strcmp (name, "SendAudio") == 0)
netmsg.SetId (NETMSG_SENDAUDIO, message);
engine.AssignMessageId (NETMSG_SENDAUDIO, message);
else if (strcmp (name, "SayText") == 0)
netmsg.SetId (NETMSG_SAYTEXT, message);
engine.AssignMessageId (NETMSG_SAYTEXT, message);
else if (strcmp (name, "BotVoice") == 0)
netmsg.SetId (NETMSG_BOTVOICE, message);
else if (strcmp (name, "ResetHUD") == 0)
netmsg.SetId (NETMSG_RESETHUD, message);
engine.AssignMessageId (NETMSG_BOTVOICE, message);
return message;
}
@ -2776,7 +2771,7 @@ void pfnAlertMessage (ALERT_TYPE alertType, char *format, ...)
char buffer[1024];
va_start (ap, format);
vsprintf (buffer, format, ap);
vsnprintf (buffer, SIZEOF_CHAR (buffer), format, ap);
va_end (ap);
if ((g_mapType & MAP_DE) && g_bombPlanted && strstr (buffer, "_Defuse_") != NULL)
@ -2802,7 +2797,7 @@ void pfnAlertMessage (ALERT_TYPE alertType, char *format, ...)
gamedll_funcs_t gameDLLFunc;
export int GetEntityAPI2 (gamefuncs_t *functionTable, int *)
SHARED_LIBRARAY_EXPORT int GetEntityAPI2 (gamefuncs_t *functionTable, int *)
{
// this function is called right after FuncPointers_t() by the engine in the game DLL (or
// what it BELIEVES to be the game DLL), in order to copy the list of MOD functions that can
@ -2846,7 +2841,7 @@ export int GetEntityAPI2 (gamefuncs_t *functionTable, int *)
return TRUE;
}
export int GetEntityAPI2_Post (gamefuncs_t *functionTable, int *)
SHARED_LIBRARAY_EXPORT int GetEntityAPI2_Post (gamefuncs_t *functionTable, int *)
{
// this function is called right after FuncPointers_t() by the engine in the game DLL (or
// what it BELIEVES to be the game DLL), in order to copy the list of MOD functions that can
@ -2867,7 +2862,7 @@ export int GetEntityAPI2_Post (gamefuncs_t *functionTable, int *)
return TRUE;
}
export int GetNewDLLFunctions (newgamefuncs_t *functionTable, int *interfaceVersion)
SHARED_LIBRARAY_EXPORT int GetNewDLLFunctions (newgamefuncs_t *functionTable, int *interfaceVersion)
{
// it appears that an extra function table has been added in the engine to gamedll interface
// since the date where the first enginefuncs table standard was frozen. These ones are
@ -2888,7 +2883,7 @@ export int GetNewDLLFunctions (newgamefuncs_t *functionTable, int *interfaceVers
return TRUE;
}
export int GetEngineFunctions (enginefuncs_t *functionTable, int *)
SHARED_LIBRARAY_EXPORT int GetEngineFunctions (enginefuncs_t *functionTable, int *)
{
if (g_isMetamod)
memset (functionTable, 0, sizeof (enginefuncs_t));
@ -2918,7 +2913,7 @@ export int GetEngineFunctions (enginefuncs_t *functionTable, int *)
return TRUE;
}
export int GetEngineFunctions_Post (enginefuncs_t *functionTable, int *)
SHARED_LIBRARAY_EXPORT int GetEngineFunctions_Post (enginefuncs_t *functionTable, int *)
{
memset (functionTable, 0, sizeof (enginefuncs_t));
@ -2927,7 +2922,7 @@ export int GetEngineFunctions_Post (enginefuncs_t *functionTable, int *)
return TRUE;
}
export int Server_GetBlendingInterface (int version, void **ppinterface, void *pstudio, float (*rotationmatrix)[3][4], float (*bonetransform)[128][3][4])
SHARED_LIBRARAY_EXPORT int Server_GetBlendingInterface (int version, void **ppinterface, void *pstudio, float (*rotationmatrix)[3][4], float (*bonetransform)[128][3][4])
{
// this function synchronizes the studio model animation blending interface (i.e, what parts
// of the body move, which bones, which hitboxes and how) between the server and the game DLL.
@ -2939,7 +2934,7 @@ export int Server_GetBlendingInterface (int version, void **ppinterface, void *p
return (*g_serverBlendingAPI) (version, ppinterface, pstudio, rotationmatrix, bonetransform);
}
export int Meta_Query (char *, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
SHARED_LIBRARAY_EXPORT int Meta_Query (char *, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{
// this function is the first function ever called by metamod in the plugin DLL. Its purpose
// is for metamod to retrieve basic information about the plugin, such as its meta-interface
@ -2951,7 +2946,7 @@ export int Meta_Query (char *, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUt
return TRUE; // tell metamod this plugin looks safe
}
export int Meta_Attach (PLUG_LOADTIME, metamod_funcs_t *functionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs)
SHARED_LIBRARAY_EXPORT int Meta_Attach (PLUG_LOADTIME, metamod_funcs_t *functionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs)
{
// this function is called when metamod attempts to load the plugin. Since it's the place
// where we can tell if the plugin will be allowed to run or not, we wait until here to make
@ -2965,7 +2960,7 @@ export int Meta_Attach (PLUG_LOADTIME, metamod_funcs_t *functionTable, meta_glob
return TRUE; // returning true enables metamod to attach this plugin
}
export int Meta_Detach (PLUG_LOADTIME, PL_UNLOAD_REASON)
SHARED_LIBRARAY_EXPORT int Meta_Detach (PLUG_LOADTIME, PL_UNLOAD_REASON)
{
// this function is called when metamod unloads the plugin. A basic check is made in order
// to prevent unloading the plugin if its processing should not be interrupted.
@ -2976,7 +2971,7 @@ export int Meta_Detach (PLUG_LOADTIME, PL_UNLOAD_REASON)
return TRUE;
}
export void Meta_Init (void)
SHARED_LIBRARAY_EXPORT void Meta_Init (void)
{
// this function is called by metamod, before any other interface functions. Purpose of this
// function to give plugin a chance to determine is plugin running under metamod or not.
@ -3002,7 +2997,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
g_pGlobals = pGlobals;
// register our cvars
ConVarWrapper::GetReference ().PushRegisteredConVarsToEngine ();
engine.PushRegisteredConVarsToEngine ();
// ensure we're have all needed directories
{
@ -3130,20 +3125,20 @@ DLL_ENTRYPOINT
DLL_RETENTRY; // the return data type is OS specific too
}
static void LinkEntity_Helper (EntityPtr_t &entAddress, const char *name, entvars_t *pev)
static void LinkEntity_Helper (EntityPtr_t &addr, const char *name, entvars_t *pev)
{
// here we're see an ugliest hack :)
if (entAddress == NULL || (g_gameFlags & GAME_OFFICIAL_CSBOT))
entAddress = g_gameLib->GetFuncAddr <EntityPtr_t > (name);
//if (addr == NULL || (g_gameFlags & GAME_OFFICIAL_CSBOT))
addr = g_gameLib->GetFuncAddr <EntityPtr_t > (name);
if (entAddress == NULL)
if (addr == NULL)
return;
entAddress (pev);
addr (pev);
}
#define LINK_ENTITY(entityName) \
export void entityName (entvars_t *pev) \
SHARED_LIBRARAY_EXPORT void entityName (entvars_t *pev) \
{ \
static EntityPtr_t addr = NULL; \
LinkEntity_Helper (addr, #entityName, pev); \

View file

@ -1114,7 +1114,7 @@ void Bot::NewRound (void)
m_itemCheckTime = 0.0f;
m_breakableEntity = NULL;
m_breakable.Zero ();
m_breakableOrigin.Zero ();
m_timeDoorOpen = 0.0f;
ResetCollideState ();

View file

@ -1,4 +1,4 @@
//
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team.
//
@ -441,7 +441,7 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal)
state[i++] = COLLISION_STRAFELEFT;
state[i++] = COLLISION_STRAFERIGHT;
state[i++] = COLLISION_JUMP;
// state[i++] = COLLISION_DUCK;
state[i++] = COLLISION_DUCK;
if (bits & PROBE_STRAFE)
{
@ -1410,7 +1410,6 @@ public:
}
};
float gfunctionKillsDistT (int currentIndex, int parentIndex)
{
// least kills and number of nodes to goal for a team

View file

@ -1,499 +0,0 @@
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team.
//
// This software is licensed under the BSD-style license.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// http://yapb.jeefo.net/license
//
#include <core.h>
NetworkMsg::NetworkMsg (void)
{
m_message = NETMSG_UNDEFINED;
m_state = 0;
m_bot = NULL;
for (int i = 0; i < NETMSG_NUM; i++)
m_registerdMessages[i] = -1;
}
void NetworkMsg::HandleMessageIfRequired (int messageType, int requiredType)
{
if (messageType == m_registerdMessages[requiredType])
SetMessage (requiredType);
}
void NetworkMsg::Execute (void *p)
{
if (m_message == NETMSG_UNDEFINED)
return; // no message or not for bot, return
// some needed variables
static byte r, g, b;
static byte enabled;
static int damageArmor, damageTaken, damageBits;
static int killerIndex, victimIndex, playerIndex;
static int index, numPlayers;
static int state, id, clip;
static Vector damageOrigin;
static WeaponProperty weaponProp;
// now starts of netmessage execution
switch (m_message)
{
case NETMSG_VGUI:
// this message is sent when a VGUI menu is displayed.
if (m_state == 0)
{
switch (PTR_TO_INT (p))
{
case VMS_TEAM:
m_bot->m_startAction = GSM_TEAM_SELECT;
break;
case VMS_TF:
case VMS_CT:
m_bot->m_startAction = GSM_CLASS_SELECT;
break;
}
}
break;
case NETMSG_SHOWMENU:
// this message is sent when a text menu is displayed.
if (m_state < 3) // ignore first 3 fields of message
break;
if (strcmp (PTR_TO_STR (p), "#Team_Select") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#Team_Select_Spect") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#IG_Team_Select_Spect") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#IG_Team_Select") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#IG_VIP_Team_Select") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#IG_VIP_Team_Select_Spect") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#Terrorist_Select") == 0) // T model select?
m_bot->m_startAction = GSM_CLASS_SELECT;
else if (strcmp (PTR_TO_STR (p), "#CT_Select") == 0) // CT model select menu?
m_bot->m_startAction = GSM_CLASS_SELECT;
break;
case NETMSG_WEAPONLIST:
// this message is sent when a client joins the game. All of the weapons are sent with the weapon ID and information about what ammo is used.
switch (m_state)
{
case 0:
strncpy (weaponProp.className, PTR_TO_STR (p), SIZEOF_CHAR (weaponProp.className));
break;
case 1:
weaponProp.ammo1 = PTR_TO_INT (p); // ammo index 1
break;
case 2:
weaponProp.ammo1Max = PTR_TO_INT (p); // max ammo 1
break;
case 5:
weaponProp.slotID = PTR_TO_INT (p); // slot for this weapon
break;
case 6:
weaponProp.position = PTR_TO_INT (p); // position in slot
break;
case 7:
weaponProp.id = PTR_TO_INT (p); // weapon ID
break;
case 8:
weaponProp.flags = PTR_TO_INT (p); // flags for weapon (WTF???)
g_weaponDefs[weaponProp.id] = weaponProp; // store away this weapon with it's ammo information...
break;
}
break;
case NETMSG_CURWEAPON:
// this message is sent when a weapon is selected (either by the bot chosing a weapon or by the server auto assigning the bot a weapon). In CS it's also called when Ammo is increased/decreased
switch (m_state)
{
case 0:
state = PTR_TO_INT (p); // state of the current weapon (WTF???)
break;
case 1:
id = PTR_TO_INT (p); // weapon ID of current weapon
break;
case 2:
clip = PTR_TO_INT (p); // ammo currently in the clip for this weapon
if (id <= 31)
{
if (state != 0)
m_bot->m_currentWeapon = id;
// ammo amount decreased ? must have fired a bullet...
if (id == m_bot->m_currentWeapon && m_bot->m_ammoInClip[id] > clip)
m_bot->m_timeLastFired = engine.Time (); // remember the last bullet time
m_bot->m_ammoInClip[id] = clip;
}
break;
}
break;
case NETMSG_AMMOX:
// this message is sent whenever ammo amounts are adjusted (up or down). NOTE: Logging reveals that CS uses it very unreliable!
switch (m_state)
{
case 0:
index = PTR_TO_INT (p); // ammo index (for type of ammo)
break;
case 1:
m_bot->m_ammo[index] = PTR_TO_INT (p); // store it away
break;
}
break;
case NETMSG_AMMOPICKUP:
// this message is sent when the bot picks up some ammo (AmmoX messages are also sent so this message is probably
// not really necessary except it allows the HUD to draw pictures of ammo that have been picked up. The bots
// don't really need pictures since they don't have any eyes anyway.
switch (m_state)
{
case 0:
index = PTR_TO_INT (p);
break;
case 1:
m_bot->m_ammo[index] = PTR_TO_INT (p);
break;
}
break;
case NETMSG_DAMAGE:
// this message gets sent when the bots are getting damaged.
switch (m_state)
{
case 0:
damageArmor = PTR_TO_INT (p);
break;
case 1:
damageTaken = PTR_TO_INT (p);
break;
case 2:
damageBits = PTR_TO_INT (p);
if (m_bot != NULL && (damageArmor > 0 || damageTaken > 0))
m_bot->TakeDamage (m_bot->pev->dmg_inflictor, damageTaken, damageArmor, damageBits);
break;
}
break;
case NETMSG_MONEY:
// this message gets sent when the bots money amount changes
if (m_state == 0)
m_bot->m_moneyAmount = PTR_TO_INT (p); // amount of money
break;
case NETMSG_STATUSICON:
switch (m_state)
{
case 0:
enabled = PTR_TO_BYTE (p);
break;
case 1:
if (strcmp (PTR_TO_STR (p), "defuser") == 0)
m_bot->m_hasDefuser = (enabled != 0);
else if (strcmp (PTR_TO_STR (p), "buyzone") == 0)
{
m_bot->m_inBuyZone = (enabled != 0);
// try to equip in buyzone
m_bot->EquipInBuyzone (BUYSTATE_PRIMARY_WEAPON);
}
else if (strcmp (PTR_TO_STR (p), "vipsafety") == 0)
m_bot->m_inVIPZone = (enabled != 0);
else if (strcmp (PTR_TO_STR (p), "c4") == 0)
m_bot->m_inBombZone = (enabled == 2);
break;
}
break;
case NETMSG_DEATH: // this message sends on death
switch (m_state)
{
case 0:
killerIndex = PTR_TO_INT (p);
break;
case 1:
victimIndex = PTR_TO_INT (p);
break;
case 2:
bots.SetDeathMsgState (true);
if (killerIndex != 0 && killerIndex != victimIndex)
{
edict_t *killer = engine.EntityOfIndex (killerIndex);
edict_t *victim = engine.EntityOfIndex (victimIndex);
if (engine.IsNullEntity (killer) || engine.IsNullEntity (victim))
break;
if (yb_communication_type.GetInt () == 2)
{
// need to send congrats on well placed shot
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_notKilled && killer != bot->GetEntity () && bot->EntityIsVisible (victim->v.origin) && engine.GetTeam (killer) == bot->m_team && engine.GetTeam (killer) != engine.GetTeam (victim))
{
if (killer == g_hostEntity)
bot->HandleChatterMessage ("#Bot_NiceShotCommander");
else
bot->HandleChatterMessage ("#Bot_NiceShotPall");
break;
}
}
}
// notice nearby to victim teammates, that attacker is near
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_seeEnemyTime + 2.0f < engine.Time () && bot->m_notKilled && bot->m_team == engine.GetTeam (victim) && IsVisible (killer->v.origin, bot->GetEntity ()) && engine.IsNullEntity (bot->m_enemy) && engine.GetTeam (killer) != engine.GetTeam (victim))
{
bot->m_actualReactionTime = 0.0f;
bot->m_seeEnemyTime = engine.Time ();
bot->m_enemy = killer;
bot->m_lastEnemy = killer;
bot->m_lastEnemyOrigin = killer->v.origin;
}
}
Bot *bot = bots.GetBot (killer);
// is this message about a bot who killed somebody?
if (bot != NULL)
bot->m_lastVictim = victim;
else // did a human kill a bot on his team?
{
Bot *target = bots.GetBot (victim);
if (target != NULL)
{
if (engine.GetTeam (killer) == engine.GetTeam (victim))
target->m_voteKickIndex = killerIndex;
target->m_notKilled = false;
}
}
}
break;
}
break;
case NETMSG_SCREENFADE: // this message gets sent when the Screen fades (Flashbang)
switch (m_state)
{
case 3:
r = PTR_TO_BYTE (p);
break;
case 4:
g = PTR_TO_BYTE (p);
break;
case 5:
b = PTR_TO_BYTE (p);
break;
case 6:
m_bot->TakeBlinded (Vector (r, g, b), PTR_TO_BYTE (p));
break;
}
break;
case NETMSG_HLTV: // round restart in steam cs
switch (m_state)
{
case 0:
numPlayers = PTR_TO_INT (p);
break;
case 1:
if (numPlayers == 0 && PTR_TO_INT (p) == 0)
RoundInit ();
break;
}
break;
case NETMSG_RESETHUD:
#if 0
if (m_bot != NULL)
m_bot->NewRound ();
#endif
break;
case NETMSG_TEXTMSG:
if (m_state == 1)
{
if (FStrEq (PTR_TO_STR (p), "#CTs_Win") ||
FStrEq (PTR_TO_STR (p), "#Bomb_Defused") ||
FStrEq (PTR_TO_STR (p), "#Terrorists_Win") ||
FStrEq (PTR_TO_STR (p), "#Round_Draw") ||
FStrEq (PTR_TO_STR (p), "#All_Hostages_Rescued") ||
FStrEq (PTR_TO_STR (p), "#Target_Saved") ||
FStrEq (PTR_TO_STR (p), "#Hostages_Not_Rescued") ||
FStrEq (PTR_TO_STR (p), "#Terrorists_Not_Escaped") ||
FStrEq (PTR_TO_STR (p), "#VIP_Not_Escaped") ||
FStrEq (PTR_TO_STR (p), "#Escaping_Terrorists_Neutralized") ||
FStrEq (PTR_TO_STR (p), "#VIP_Assassinated") ||
FStrEq (PTR_TO_STR (p), "#VIP_Escaped") ||
FStrEq (PTR_TO_STR (p), "#Terrorists_Escaped") ||
FStrEq (PTR_TO_STR (p), "#CTs_PreventEscape") ||
FStrEq (PTR_TO_STR (p), "#Target_Bombed") ||
FStrEq (PTR_TO_STR (p), "#Game_Commencing") ||
FStrEq (PTR_TO_STR (p), "#Game_will_restart_in"))
{
g_roundEnded = true;
if (FStrEq (PTR_TO_STR (p), "#Game_Commencing"))
g_isCommencing = true;
if (FStrEq (PTR_TO_STR (p), "#CTs_Win"))
{
bots.SetLastWinner (CT); // update last winner for economics
if (yb_communication_type.GetInt () == 2)
{
Bot *bot = bots.FindOneValidAliveBot ();
if (bot != NULL && bot->m_notKilled)
bot->HandleChatterMessage (PTR_TO_STR (p));
}
}
if (FStrEq (PTR_TO_STR (p), "#Game_will_restart_in"))
{
bots.CheckTeamEconomics (CT, true);
bots.CheckTeamEconomics (TERRORIST, true);
}
if (FStrEq (PTR_TO_STR (p), "#Terrorists_Win"))
{
bots.SetLastWinner (TERRORIST); // update last winner for economics
if (yb_communication_type.GetInt () == 2)
{
Bot *bot = bots.FindOneValidAliveBot ();
if (bot != NULL && bot->m_notKilled)
bot->HandleChatterMessage (PTR_TO_STR (p));
}
}
waypoints.SetBombPosition (true);
}
else if (!g_bombPlanted && FStrEq (PTR_TO_STR (p), "#Bomb_Planted"))
{
waypoints.SetBombPosition ();
g_bombPlanted = g_bombSayString = true;
g_timeBombPlanted = engine.Time ();
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_notKilled)
{
bot->DeleteSearchNodes ();
bot->ResetTasks ();
if (yb_communication_type.GetInt () == 2 && Random.Long (0, 100) < 75 && bot->m_team == CT)
bot->ChatterMessage (Chatter_WhereIsTheBomb);
}
}
}
else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_BurstFire"))
m_bot->m_weaponBurstMode = BM_ON;
else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_SemiAuto"))
m_bot->m_weaponBurstMode = BM_OFF;
}
break;
case NETMSG_SCOREINFO:
switch (m_state)
{
case 0:
playerIndex = PTR_TO_INT (p);
break;
case 4:
if (playerIndex >= 0 && playerIndex <= engine.MaxClients ())
{
#ifndef XASH_CSDM
Client &cl = g_clients[playerIndex - 1];
if (PTR_TO_INT (p) == 1)
cl.realTeam = TERRORIST;
else if (PTR_TO_INT (p) == 2)
cl.realTeam = CT;
else
cl.realTeam = SPECTATOR;
if (yb_csdm_mode.GetInt () == 2)
cl.team = playerIndex;
else
cl.team = cl.realTeam;
#endif
}
break;
}
break;
case NETMSG_BARTIME:
if (m_state == 0)
{
if (PTR_TO_INT (p) > 0)
m_bot->m_hasProgressBar = true; // the progress bar on a hud
else if (PTR_TO_INT (p) == 0)
m_bot->m_hasProgressBar = false; // no progress bar or disappeared
}
break;
default:
AddLogEntry (true, LL_FATAL, "Network message handler error. Call to unrecognized message id (%d).\n", m_message);
}
m_state++; // and finally update network message state
}

View file

@ -1,4 +1,4 @@
//
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team.
//
@ -42,14 +42,20 @@ short FixedSigned16 (float value, float scale)
const char *FormatBuffer (const char *format, ...)
{
va_list ap;
static char staticBuffer[3072];
static char strBuffer[2][MAX_PRINT_BUFFER];
static int rotator = 0;
if (format == NULL)
return strBuffer[rotator];
static char *ptr = strBuffer[rotator ^= 1];
va_list ap;
va_start (ap, format);
vsprintf (staticBuffer, format, ap);
vsnprintf (ptr, MAX_PRINT_BUFFER - 1, format, ap);
va_end (ap);
return &staticBuffer[0];
return ptr;
}
bool IsAlive (edict_t *ent)
@ -105,7 +111,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu)
String tempText = String (menu->menuText);
tempText.Replace ("\v", "\n");
char *text = locale.TranslateInput (tempText.GetBuffer ());
const char *text = engine.TraslateMessage (tempText.GetBuffer ());
tempText = String (text);
// make menu looks best
@ -115,11 +121,11 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu)
if ((g_gameFlags & (GAME_XASH | GAME_MOBILITY)) && !yb_display_menu_text.GetBool ())
text = " ";
else
text = (char *) tempText.GetBuffer ();
text = tempText.GetBuffer ();
while (strlen (text) >= 64)
{
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, netmsg.GetId (NETMSG_SHOWMENU), NULL, ent);
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), NULL, ent);
WRITE_SHORT (menu->validSlots);
WRITE_CHAR (-1);
WRITE_BYTE (1);
@ -132,7 +138,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu)
text += 64;
}
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, netmsg.GetId (NETMSG_SHOWMENU), NULL, ent);
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), NULL, ent);
WRITE_SHORT (menu->validSlots);
WRITE_CHAR (-1);
WRITE_BYTE (0);
@ -143,7 +149,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu)
}
else
{
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, netmsg.GetId (NETMSG_SHOWMENU), NULL, ent);
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), NULL, ent);
WRITE_SHORT (0);
WRITE_CHAR (0);
WRITE_BYTE (0);
@ -206,7 +212,7 @@ void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex)
{
MESSAGE_BEGIN (MSG_BROADCAST, SVC_TEMPENTITY);
WRITE_BYTE (TE_PLAYERDECAL);
WRITE_BYTE (engine.IndexOfEntity (ENT (pev)));
WRITE_BYTE (engine.IndexOfEntity (pev->pContainingEntity));
WRITE_COORD (trace->vecEndPos.x);
WRITE_COORD (trace->vecEndPos.y);
WRITE_COORD (trace->vecEndPos.z);
@ -234,7 +240,6 @@ void FreeLibraryMemory (void)
{
// this function free's all allocated memory
waypoints.Init (); // frees waypoint data
locale.Destroy (); // clear language
delete [] g_experienceData;
g_experienceData = NULL;
@ -566,7 +571,7 @@ void DetectCSVersion (void)
}
// counter-strike 1.6 or higher (plus detects for non-steam versions of 1.5)
byte *detection = (*g_engfuncs.pfnLoadFileForMe) ("events/galil.sc", NULL);
byte *detection = g_engfuncs.pfnLoadFileForMe ("events/galil.sc", NULL);
if (detection != NULL)
g_gameFlags |= GAME_CSTRIKE16; // just to be sure
@ -575,7 +580,7 @@ void DetectCSVersion (void)
// if we have loaded the file free it
if (detection != NULL)
(*g_engfuncs.pfnFreeFile) (detection);
g_engfuncs.pfnFreeFile (detection);
}
void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...)
@ -583,28 +588,28 @@ void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...)
// this function logs a message to the message log file root directory.
va_list ap;
char buffer[512] = {0, }, levelString[32] = {0, }, logLine[1024] = {0, };
char buffer[MAX_PRINT_BUFFER] = {0, }, levelString[32] = {0, }, logLine[MAX_PRINT_BUFFER] = {0, };
va_start (ap, format);
vsprintf (buffer, locale.TranslateInput (format), ap);
vsnprintf (buffer, SIZEOF_CHAR (buffer), format, ap);
va_end (ap);
switch (logLevel)
{
case LL_DEFAULT:
strcpy (levelString, "Log: ");
strcpy (levelString, "LOG: ");
break;
case LL_WARNING:
strcpy (levelString, "Warning: ");
strcpy (levelString, "WARN: ");
break;
case LL_ERROR:
strcpy (levelString, "Error: ");
strcpy (levelString, "ERROR: ");
break;
case LL_FATAL:
strcpy (levelString, "Critical: ");
strcpy (levelString, "FATAL: ");
break;
}
@ -661,49 +666,6 @@ void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...)
}
}
char *Localizer::TranslateInput (const char *input)
{
if (engine.IsDedicatedServer ())
return const_cast <char *> (&input[0]);
static char string[1024];
const char *ptr = input + strlen (input) - 1;
while (ptr > input && *ptr == '\n')
ptr--;
if (ptr != input)
ptr++;
strncpy (string, input, SIZEOF_CHAR (string));
String::TrimExternalBuffer (string);
FOR_EACH_AE (m_langTab, i)
{
if (strcmp (string, m_langTab[i].original) == 0)
{
strncpy (string, m_langTab[i].translated, SIZEOF_CHAR (string));
if (ptr != input)
strncat (string, ptr, 1024 - 1 - strlen (string));
return &string[0];
}
}
return const_cast <char *> (&input[0]); // nothing found
}
void Localizer::Destroy (void)
{
FOR_EACH_AE (m_langTab, it)
{
delete[] m_langTab[it].original;
delete[] m_langTab[it].translated;
}
m_langTab.RemoveAll ();
}
bool FindNearestPlayer (void **pvHolder, edict_t *to, float searchDistance, bool sameTeam, bool needBot, bool isAlive, bool needDrawn)
{
// this function finds nearest to to, player with set of parameters, like his

View file

@ -24,17 +24,21 @@ void Waypoint::Init (void)
// have any waypoint path nodes been allocated yet?
if (m_waypointPaths)
{
for (int i = 0; i < g_numWaypoints && m_paths[i] != NULL; i++)
{
delete m_paths[i];
m_paths[i] = NULL;
}
}
CleanupPathMemory ();
g_numWaypoints = 0;
}
void Waypoint::AddPath (short int addIndex, short int pathIndex, float distance)
void Waypoint::CleanupPathMemory (void)
{
for (int i = 0; i < g_numWaypoints && m_paths[i] != NULL; i++)
{
delete m_paths[i];
m_paths[i] = NULL;
}
}
void Waypoint::AddPath (int addIndex, int pathIndex, float distance)
{
if (addIndex < 0 || addIndex >= g_numWaypoints || pathIndex < 0 || pathIndex >= g_numWaypoints || addIndex == pathIndex)
return;
@ -967,7 +971,7 @@ void Waypoint::SaveVisibilityTab (void)
}
fp.Close ();
Compressor::Compress (FormatBuffer ("%slearned/%s.vis", GetDataDir (), engine.GetMapName ()), (unsigned char *) &header, sizeof (ExtensionHeader), (unsigned char *) m_visLUT, MAX_WAYPOINTS * (MAX_WAYPOINTS / 4) * sizeof (byte));
Compressor::Compress (FormatBuffer ("%slearned/%s.vis", GetDataDir (), engine.GetMapName ()), (unsigned char *) &header, sizeof (ExtensionHeader), (unsigned char *) m_visLUT, MAX_WAYPOINTS * (MAX_WAYPOINTS / 4) * sizeof (unsigned char));
}
void Waypoint::InitVisibilityTab (void)
@ -1008,7 +1012,7 @@ void Waypoint::InitVisibilityTab (void)
return;
}
int result = Compressor::Uncompress (FormatBuffer ("%slearned/%s.vis", GetDataDir (), engine.GetMapName ()), sizeof (ExtensionHeader), (unsigned char *) m_visLUT, MAX_WAYPOINTS * (MAX_WAYPOINTS / 4) * sizeof (byte));
int result = Compressor::Uncompress (FormatBuffer ("%slearned/%s.vis", GetDataDir (), engine.GetMapName ()), sizeof (ExtensionHeader), (unsigned char *) m_visLUT, MAX_WAYPOINTS * (MAX_WAYPOINTS / 4) * sizeof (unsigned char));
if (result == -1)
{
@ -1496,7 +1500,7 @@ const char *Waypoint::GetWaypointInfo(int id)
jumpPoint = true;
}
static char messageBuffer[1024];
static char messageBuffer[MAX_PRINT_BUFFER];
sprintf (messageBuffer, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s", (path->flags == 0 && !jumpPoint) ? " (none)" : "", (path->flags & FLAG_LIFT) ? " LIFT" : "", (path->flags & FLAG_CROUCH) ? " CROUCH" : "", (path->flags & FLAG_CROSSING) ? " CROSSING" : "", (path->flags & FLAG_CAMP) ? " CAMP" : "", (path->flags & FLAG_TF_ONLY) ? " TERRORIST" : "", (path->flags & FLAG_CF_ONLY) ? " CT" : "", (path->flags & FLAG_SNIPER) ? " SNIPER" : "", (path->flags & FLAG_GOAL) ? " GOAL" : "", (path->flags & FLAG_LADDER) ? " LADDER" : "", (path->flags & FLAG_RESCUE) ? " RESCUE" : "", (path->flags & FLAG_DOUBLEJUMP) ? " JUMPHELP" : "", (path->flags & FLAG_NOHOSTAGE) ? " NOHOSTAGE" : "", jumpPoint ? " JUMP" : "");
// return the message buffer
@ -2454,6 +2458,8 @@ void Waypoint::SetFindIndex (int index)
Waypoint::Waypoint (void)
{
CleanupPathMemory ();
m_waypointPaths = false;
m_endJumpPoint = false;
m_redoneVisibility = false;
@ -2480,13 +2486,12 @@ Waypoint::Waypoint (void)
m_distMatrix = NULL;
m_pathMatrix = NULL;
for (int i = 0; i < MAX_WAYPOINTS; i++)
m_paths[i] = NULL;
}
Waypoint::~Waypoint (void)
{
CleanupPathMemory ();
delete [] m_distMatrix;
delete [] m_pathMatrix;
@ -2573,7 +2578,7 @@ WaypointDownloadError Waypoint::RequestWaypoint (void)
return WDE_SOCKET_ERROR;
}
const int ChunkSize = 1024;
const int ChunkSize = MAX_PRINT_BUFFER;
char buffer[ChunkSize] = { 0, };
bool finished = false;