Revert "cleaning up the code. part 0."

This reverts commit e8eb775c23.
This commit is contained in:
jeefo 2016-08-27 23:39:25 +03:00
commit 74b97dadd5
13 changed files with 291 additions and 356 deletions

2
.gitignore vendored
View file

@ -61,5 +61,3 @@ project/yapb.vcxproj.user
*.enc *.enc
*.xml *.xml
/project/#Verone/incremental_index /project/#Verone/incremental_index
*.lastcodeanalysissucceeded
/project/hlds160301.vsp

View file

@ -63,8 +63,7 @@ enum GameFlags
GAME_CZERO = (1 << 2), // Counter-Strike: Condition Zero GAME_CZERO = (1 << 2), // Counter-Strike: Condition Zero
GAME_LEGACY = (1 << 3), // Counter-Strike 1.3-1.5 with/without Steam GAME_LEGACY = (1 << 3), // Counter-Strike 1.3-1.5 with/without Steam
GAME_MOBILITY = (1 << 4), // additional flag that bot is running on android (additional flag) GAME_MOBILITY = (1 << 4), // additional flag that bot is running on android (additional flag)
GAME_OFFICIAL_CSBOT = (1 << 5), // additional flag that indicates official cs bots are in game GAME_OFFICIAL_CSBOT = (1 << 5) // additional flag that indicates official cs bots are in game
GAME_METAMOD = (1 << 6)
}; };
// log levels // log levels
@ -126,14 +125,6 @@ enum ClientFlags
CF_ADMIN = (1 << 2) CF_ADMIN = (1 << 2)
}; };
// bot create status
enum BotCreationResult
{
BOT_RESULT_CREATED,
BOT_RESULT_MAX_PLAYERS_REACHED,
BOT_RESULT_NAV_ERROR
};
// radio messages // radio messages
enum RadioMessage_t enum RadioMessage_t
{ {
@ -811,7 +802,6 @@ private:
bool m_moveToGoal; // bot currently moving to goal?? bool m_moveToGoal; // bot currently moving to goal??
bool m_isStuck; // bot is stuck bool m_isStuck; // bot is stuck
bool m_isReloading; // bot is reloading a gun bool m_isReloading; // bot is reloading a gun
bool m_forceRadio; // should bot use radio anyway?
int m_reloadState; // current reload state int m_reloadState; // current reload state
int m_voicePitch; // bot voice pitch int m_voicePitch; // bot voice pitch
@ -998,6 +988,7 @@ private:
int ChangeWptIndex (int waypointIndex); int ChangeWptIndex (int waypointIndex);
bool IsDeadlyDrop (const Vector &to); bool IsDeadlyDrop (const Vector &to);
bool OutOfBombTimer (void); bool OutOfBombTimer (void);
void SelectLeaderEachTeam (int team);
Vector CheckThrow (const Vector &start, const Vector &stop); Vector CheckThrow (const Vector &start, const Vector &stop);
Vector CheckToss (const Vector &start, const Vector &stop); Vector CheckToss (const Vector &start, const Vector &stop);
@ -1248,9 +1239,8 @@ private:
int m_lastWinner; // the team who won previous round int m_lastWinner; // the team who won previous round
int m_balanceCount; // limit of bots to add int m_balanceCount; // limit of bots to add
bool m_leaderChoosen[SPECTATOR]; // is team leader choose theese round bool m_economicsGood[2]; // is team able to buy anything
bool m_economicsGood[SPECTATOR]; // is team able to buy anything bool m_deathMsgSent; // for fakeping
bool m_deathMsgSent; // for fake ping
Array <edict_t *> m_activeGrenades; // holds currently active grenades in the map Array <edict_t *> m_activeGrenades; // holds currently active grenades in the map
Array <edict_t *> m_trackedPlayers; // holds array of connected players, and waits the player joins team Array <edict_t *> m_trackedPlayers; // holds array of connected players, and waits the player joins team
@ -1258,13 +1248,13 @@ private:
edict_t *m_killerEntity; // killer entity for bots edict_t *m_killerEntity; // killer entity for bots
protected: protected:
BotCreationResult CreateBot (const String &name, int difficulty, int personality, int team, int member, bool isConsoleCmd); int CreateBot (const String &name, int difficulty, int personality, int team, int member, bool isConsoleCmd);
public: public:
BotManager (void); BotManager (void);
~BotManager (void); ~BotManager (void);
bool IsEcoValid (int team) { return m_economicsGood[team]; } bool EconomicsValid (int team) { return m_economicsGood[team]; }
int GetLastWinner (void) const { return m_lastWinner; } int GetLastWinner (void) const { return m_lastWinner; }
void SetLastWinner (int winner) { m_lastWinner = winner; } void SetLastWinner (int winner) { m_lastWinner = winner; }
@ -1306,7 +1296,6 @@ public:
void AddPlayerToCheckTeamQueue (edict_t *ent); void AddPlayerToCheckTeamQueue (edict_t *ent);
void VerifyPlayersHasJoinedTeam (int &desiredCount); void VerifyPlayersHasJoinedTeam (int &desiredCount);
void SelectLeaderEachTeam (int team, bool reset);
void ListBots (void); void ListBots (void);
void SetWeaponMode (int selection); void SetWeaponMode (int selection);
@ -1333,6 +1322,7 @@ public:
void SendDeathMsgFix (void); void SendDeathMsgFix (void);
}; };
// waypoint operation class // waypoint operation class
class Waypoint : public Singleton <Waypoint> class Waypoint : public Singleton <Waypoint>
{ {
@ -1345,7 +1335,6 @@ private:
bool m_isOnLadder; bool m_isOnLadder;
bool m_endJumpPoint; bool m_endJumpPoint;
bool m_learnJumpWaypoint; bool m_learnJumpWaypoint;
bool m_waypointsChanged;
float m_timeJumpStarted; float m_timeJumpStarted;
Vector m_learnVelocity; Vector m_learnVelocity;
@ -1432,9 +1421,7 @@ public:
int GetPathDistance (int srcIndex, int destIndex); int GetPathDistance (int srcIndex, int destIndex);
Path *GetPath (int id); Path *GetPath (int id);
const char *GetWaypointInfo (int id); const char *GetWaypointInfo (int id);
char *GetInfo (void) { return m_infoBuffer; } char *GetInfo (void) { return m_infoBuffer; }
bool HasChanged (void) { return m_waypointsChanged; }
void SetFindIndex (int index); void SetFindIndex (int index);
void SetLearnJumpWaypoint (void); void SetLearnJumpWaypoint (void);

View file

@ -13,11 +13,15 @@ extern bool g_canSayBombPlanted;
extern bool g_bombPlanted; extern bool g_bombPlanted;
extern bool g_bombSayString; extern bool g_bombSayString;
extern bool g_roundEnded; extern bool g_roundEnded;
extern bool g_radioInsteadVoice;
extern bool g_waypointOn; extern bool g_waypointOn;
extern bool g_waypointsChanged;
extern bool g_autoWaypoint; extern bool g_autoWaypoint;
extern bool g_botsCanPause; extern bool g_botsCanPause;
extern bool g_editNoclip; extern bool g_editNoclip;
extern bool g_isMetamod;
extern bool g_isCommencing; extern bool g_isCommencing;
extern bool g_leaderChoosen[2];
extern float g_autoPathDistance; extern float g_autoPathDistance;
extern float g_timeBombPlanted; extern float g_timeBombPlanted;
@ -25,6 +29,7 @@ extern float g_timeNextBombUpdate;
extern float g_lastChatTime; extern float g_lastChatTime;
extern float g_timeRoundEnd; extern float g_timeRoundEnd;
extern float g_timeRoundMid; extern float g_timeRoundMid;
extern float g_timeNextBombUpdate;
extern float g_timeRoundStart; extern float g_timeRoundStart;
extern float g_timePerSecondUpdate; extern float g_timePerSecondUpdate;
extern float g_lastRadioTime[2]; extern float g_lastRadioTime[2];
@ -66,6 +71,10 @@ extern edict_t *g_hostEntity;
extern Library *g_gameLib; extern Library *g_gameLib;
extern gamefuncs_t g_functionTable; extern gamefuncs_t g_functionTable;
extern EntityAPI_t g_entityAPI;
extern FuncPointers_t g_funcPointers;
extern NewEntityAPI_t g_getNewEntityAPI;
extern BlendAPI_t g_serverBlendingAPI;
static inline bool IsNullString (const char *input) static inline bool IsNullString (const char *input)
{ {

View file

@ -11,17 +11,17 @@
// general product information // general product information
#define PRODUCT_NAME "Yet Another POD-Bot" #define PRODUCT_NAME "Yet Another POD-Bot"
#define PRODUCT_VERSION "2.8" #define PRODUCT_VERSION "2.73"
#define PRODUCT_AUTHOR "YaPB Dev Team" #define PRODUCT_AUTHOR "YaPB Dev Team"
#define PRODUCT_URL "https://yapb.jeefo.net/" #define PRODUCT_URL "https://yapb.jeefo.net"
#define PRODUCT_EMAIL "dmitry@jeefo.net" #define PRODUCT_EMAIL "dmitry@jeefo.net"
#define PRODUCT_LOGTAG "YAPB" #define PRODUCT_LOGTAG "YAPB"
#define PRODUCT_DESCRIPTION PRODUCT_NAME " v" PRODUCT_VERSION " - The Counter-Strike Bot" #define PRODUCT_DESCRIPTION PRODUCT_NAME " v" PRODUCT_VERSION " - The Counter-Strike Bot"
#define PRODUCT_COPYRIGHT "Copyright © 1999-2017, by " PRODUCT_AUTHOR #define PRODUCT_COPYRIGHT "Copyright © 2003-2016, by " PRODUCT_AUTHOR
#define PRODUCT_LEGAL "Half-Life, Counter-Strike, Counter-Strike: Condition Zero, Steam, Valve is a trademark of Valve Corporation" #define PRODUCT_LEGAL "Half-Life, Counter-Strike, Counter-Strike: Condition Zero, Steam, Valve is a trademark of Valve Corporation"
#define PRODUCT_ORIGINAL_NAME "yapb.dll" #define PRODUCT_ORIGINAL_NAME "yapb.dll"
#define PRODUCT_INTERNAL_NAME "skybot" #define PRODUCT_INTERNAL_NAME "skybot"
#define PRODUCT_VERSION_DWORD_INTERNAL 2,8 #define PRODUCT_VERSION_DWORD_INTERNAL 2,73
#define PRODUCT_VERSION_DWORD PRODUCT_VERSION_DWORD_INTERNAL,0 #define PRODUCT_VERSION_DWORD PRODUCT_VERSION_DWORD_INTERNAL,0
#define PRODUCT_SUPPORT_VERSION "1.0 - CZ" #define PRODUCT_SUPPORT_VERSION "1.0 - CZ"
#define PRODUCT_COMMENTS "http://github.com/jeefo/yapb/" #define PRODUCT_COMMENTS "http://github.com/jeefo/yapb/"

View file

@ -1,14 +1,11 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14 # Visual Studio 2013
VisualStudioVersion = 14.0.25420.1 VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yapb", "yapb.vcxproj", "{C232645A-3B99-48F4-A1F3-F20CF0A9568B}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yapb", "yapb.vcxproj", "{C232645A-3B99-48F4-A1F3-F20CF0A9568B}"
EndProject EndProject
Global Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32 Release|Win32 = Release|Win32

View file

@ -62,7 +62,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc> <UseOfMfc>false</UseOfMfc>
<PlatformToolset>v140_xp</PlatformToolset> <PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">

View file

@ -4,7 +4,7 @@
// //
// This software is licensed under the BSD-style license. // This software is licensed under the BSD-style license.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit: // Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://yapb.ru/license // http://yapb.jeefo.net/license
// //
#include <core.h> #include <core.h>
@ -968,7 +968,7 @@ void Bot::SwitchChatterIcon (bool show)
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
const Client &client = g_clients[i]; Client &client = g_clients[i];
if (!(client.flags & CF_USED) || (client.ent->v.flags & FL_FAKECLIENT) || client.team != m_team) if (!(client.flags & CF_USED) || (client.ent->v.flags & FL_FAKECLIENT) || client.team != m_team)
continue; continue;
@ -1030,9 +1030,7 @@ void Bot::RadioMessage (int message)
return; return;
if (g_chatterFactory[message].IsEmpty () || (g_gameFlags & GAME_LEGACY) || yb_communication_type.GetInt () != 2) if (g_chatterFactory[message].IsEmpty () || (g_gameFlags & GAME_LEGACY) || yb_communication_type.GetInt () != 2)
m_forceRadio = true; // use radio instead voice g_radioInsteadVoice = true; // use radio instead voice
else
m_forceRadio = false;
m_radioSelect = message; m_radioSelect = message;
PushMessageQueue (GSM_RADIO); PushMessageQueue (GSM_RADIO);
@ -1243,7 +1241,7 @@ void Bot::CheckMessageQueue (void)
} }
} }
if ((m_radioSelect != Radio_ReportingIn && m_forceRadio) || yb_communication_type.GetInt () != 2 || g_chatterFactory[m_radioSelect].IsEmpty () || (g_gameFlags & GAME_LEGACY)) if ((m_radioSelect != Radio_ReportingIn && g_radioInsteadVoice) || yb_communication_type.GetInt () != 2 || g_chatterFactory[m_radioSelect].IsEmpty () || (g_gameFlags & GAME_LEGACY))
{ {
if (m_radioSelect < Radio_GoGoGo) if (m_radioSelect < Radio_GoGoGo)
engine.IssueBotCommand (GetEntity (), "radio1"); engine.IssueBotCommand (GetEntity (), "radio1");
@ -1264,7 +1262,7 @@ void Bot::CheckMessageQueue (void)
else if (m_radioSelect != -1 && m_radioSelect != Radio_ReportingIn) else if (m_radioSelect != -1 && m_radioSelect != Radio_ReportingIn)
InstantChatterMessage (m_radioSelect); InstantChatterMessage (m_radioSelect);
m_forceRadio = false; // reset radio to voice g_radioInsteadVoice = false; // reset radio to voice
g_lastRadioTime[m_team] = engine.Time (); // store last radio usage g_lastRadioTime[m_team] = engine.Time (); // store last radio usage
} }
else else
@ -1406,7 +1404,7 @@ void Bot::PurchaseWeapons (void)
int *ptr = g_weaponPrefs[m_personality] + NUM_WEAPONS; int *ptr = g_weaponPrefs[m_personality] + NUM_WEAPONS;
bool isPistolMode = g_weaponSelect[25].teamStandard == -1 && g_weaponSelect[3].teamStandard == 2; bool isPistolMode = g_weaponSelect[25].teamStandard == -1 && g_weaponSelect[3].teamStandard == 2;
bool teamEcoValid = bots.IsEcoValid (m_team); bool teamEcoValid = bots.EconomicsValid (m_team);
// do this, because xash engine is not capable to run all the features goldsrc, but we have cs 1.6 on it, so buy table must be the same // do this, because xash engine is not capable to run all the features goldsrc, but we have cs 1.6 on it, so buy table must be the same
bool isOldGame = (g_gameFlags & GAME_LEGACY) && !(g_gameFlags & GAME_XASH); bool isOldGame = (g_gameFlags & GAME_LEGACY) && !(g_gameFlags & GAME_XASH);
@ -2582,12 +2580,10 @@ void Bot::CheckRadioCommands (void)
// take nearest enemy to ordering player // take nearest enemy to ordering player
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
const Client &client = g_clients[i]; if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team == m_team)
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team == m_team)
continue; continue;
edict_t *enemy = client.ent; edict_t *enemy = g_clients[i].ent;
float curDist = (m_radioEntity->v.origin - enemy->v.origin).GetLengthSquared (); float curDist = (m_radioEntity->v.origin - enemy->v.origin).GetLengthSquared ();
if (curDist < nearestDistance) if (curDist < nearestDistance)
@ -2678,12 +2674,10 @@ void Bot::CheckRadioCommands (void)
// take nearest enemy to ordering player // take nearest enemy to ordering player
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
const Client &client = g_clients[i]; if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team == m_team)
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team == m_team)
continue; continue;
edict_t *enemy = client.ent; edict_t *enemy = g_clients[i].ent;
float dist = (m_radioEntity->v.origin - enemy->v.origin).GetLengthSquared (); float dist = (m_radioEntity->v.origin - enemy->v.origin).GetLengthSquared ();
if (dist < nearestDistance) if (dist < nearestDistance)
@ -2734,6 +2728,98 @@ void Bot::TryHeadTowardRadioEntity (void)
} }
} }
void Bot::SelectLeaderEachTeam (int team)
{
if (g_mapType & MAP_AS)
{
if (m_isVIP && !g_leaderChoosen[CT])
{
// vip bot is the leader
m_isLeader = true;
if (Random.Long (1, 100) < 50)
{
RadioMessage (Radio_FollowMe);
m_campButtons = 0;
}
g_leaderChoosen[CT] = true;
}
else if (team == TERRORIST && !g_leaderChoosen[TERRORIST])
{
Bot *botLeader = bots.GetHighestFragsBot(team);
if (botLeader != NULL && botLeader->m_notKilled)
{
botLeader->m_isLeader = true;
if (Random.Long (1, 100) < 45)
botLeader->RadioMessage (Radio_FollowMe);
}
g_leaderChoosen[TERRORIST] = true;
}
}
else if (g_mapType & MAP_DE)
{
if (team == TERRORIST && !g_leaderChoosen[TERRORIST])
{
if (m_hasC4)
{
// bot carrying the bomb is the leader
m_isLeader = true;
// terrorist carrying a bomb needs to have some company
if (Random.Long (1, 100) < 80)
{
if (yb_communication_type.GetInt () == 2)
ChatterMessage (Chatter_GoingToPlantBomb);
else
ChatterMessage (Radio_FollowMe);
m_campButtons = 0;
}
g_leaderChoosen[TERRORIST] = true;
}
}
else if (!g_leaderChoosen[CT])
{
Bot *botLeader = bots.GetHighestFragsBot(team);
if (botLeader != NULL)
{
botLeader->m_isLeader = true;
if (Random.Long (1, 100) < 30)
botLeader->RadioMessage (Radio_FollowMe);
}
g_leaderChoosen[CT] = true;
}
}
else if (g_mapType & (MAP_ES | MAP_KA | MAP_FY))
{
Bot *botLeader = bots.GetHighestFragsBot (team);
if (botLeader != NULL)
{
botLeader->m_isLeader = true;
if (Random.Long (1, 100) < 30)
botLeader->RadioMessage (Radio_FollowMe);
}
}
else
{
Bot *botLeader = bots.GetHighestFragsBot(team);
if (botLeader != NULL)
{
botLeader->m_isLeader = true;
if (Random.Long (1, 100) < (team == TERRORIST ? 30 : 40))
botLeader->RadioMessage (Radio_FollowMe);
}
}
}
void Bot::ChooseAimDirection (void) void Bot::ChooseAimDirection (void)
{ {
unsigned int flags = m_aimFlags; unsigned int flags = m_aimFlags;
@ -4698,6 +4784,9 @@ void Bot::CheckSpawnTimeConditions (void)
break; break;
} }
} }
// select a leader bot for this team
SelectLeaderEachTeam (m_team);
m_checkWeaponSwitch = false; m_checkWeaponSwitch = false;
} }
} }
@ -5291,7 +5380,7 @@ void Bot::CollectGoalExperience (int damage, int team)
// gets called each time a bot gets damaged by some enemy. tries to achieve a statistic about most/less dangerous // gets called each time a bot gets damaged by some enemy. tries to achieve a statistic about most/less dangerous
// waypoints for a destination goal used for pathfinding // waypoints for a destination goal used for pathfinding
if (g_numWaypoints < 1 || waypoints.HasChanged () || m_chosenGoalIndex < 0 || m_prevGoalIndex < 0) if (g_numWaypoints < 1 || g_waypointsChanged || m_chosenGoalIndex < 0 || m_prevGoalIndex < 0)
return; return;
// only rate goal waypoint if bot died because of the damage // only rate goal waypoint if bot died because of the damage
@ -5830,17 +5919,15 @@ void Bot::ReactOnSound (void)
// loop through all enemy clients to check for hearable stuff // loop through all enemy clients to check for hearable stuff
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
const Client &client = g_clients[i]; if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].ent == GetEntity () || g_clients[i].team == m_team || g_clients[i].timeSoundLasting < engine.Time ())
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.ent == GetEntity () || client.team == m_team || client.timeSoundLasting < engine.Time ())
continue; continue;
float distance = (client.soundPosition - pev->origin).GetLength (); float distance = (g_clients[i].soundPosition - pev->origin).GetLength ();
if (distance > client.hearingDistance) if (distance > g_clients[i].hearingDistance)
continue; continue;
if (!ENGINE_CHECK_VISIBILITY (client.ent, pas)) if (!ENGINE_CHECK_VISIBILITY (g_clients[i].ent, pas))
continue; continue;
if (distance < minDistance) if (distance < minDistance)
@ -5983,13 +6070,13 @@ bool Bot::IsBombDefusing (const Vector &bombOrigin)
defusingInProgress = true; defusingInProgress = true;
break; break;
} }
const Client &client = g_clients[i]; Client *client = &g_clients[i];
// take in account peoples too // take in account peoples too
if (defusingInProgress || !(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team != m_team || IsValidBot (client.ent)) if (defusingInProgress || !(client->flags & CF_USED) || !(client->flags & CF_ALIVE) || client->team != m_team || IsValidBot (g_clients[i].ent))
continue; continue;
if ((client.ent->v.origin - bombOrigin).GetLength () < 140.0f && ((client.ent->v.button | client.ent->v.oldbuttons) & IN_USE)) if ((client->ent->v.origin - bombOrigin).GetLength () < 140.0f && ((client->ent->v.button | client->ent->v.oldbuttons) & IN_USE))
{ {
defusingInProgress = true; defusingInProgress = true;
break; break;

View file

@ -22,12 +22,10 @@ int Bot::GetNearbyFriendsNearPosition(const Vector &origin, float radius)
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
const Client &client = g_clients[i]; if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team != m_team || g_clients[i].ent == GetEntity ())
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team != m_team || client.ent == GetEntity ())
continue; continue;
if ((client.origin - origin).GetLengthSquared () < GET_SQUARE (radius)) if ((g_clients[i].origin - origin).GetLengthSquared () < GET_SQUARE (radius))
count++; count++;
} }
return count; return count;
@ -39,12 +37,10 @@ int Bot::GetNearbyEnemiesNearPosition(const Vector &origin, float radius)
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
const Client &client = g_clients[i]; if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team == m_team)
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team == m_team)
continue; continue;
if ((client.origin - origin).GetLengthSquared () < GET_SQUARE (radius)) if ((g_clients[i].origin - origin).GetLengthSquared () < GET_SQUARE (radius))
count++; count++;
} }
return count; return count;
@ -250,12 +246,10 @@ bool Bot::LookupEnemy (void)
// search the world for players... // search the world for players...
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
const Client &client = g_clients[i]; if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team == m_team || g_clients[i].ent == GetEntity ())
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team == m_team || client.ent == GetEntity ())
continue; continue;
player = client.ent; player = g_clients[i].ent;
// let the engine check if this player is potentially visible // let the engine check if this player is potentially visible
if (!ENGINE_CHECK_VISIBILITY (player, pvs)) if (!ENGINE_CHECK_VISIBILITY (player, pvs))
@ -346,20 +340,18 @@ bool Bot::LookupEnemy (void)
// now alarm all teammates who see this bot & don't have an actual enemy of the bots enemy should simulate human players seeing a teammate firing // now alarm all teammates who see this bot & don't have an actual enemy of the bots enemy should simulate human players seeing a teammate firing
for (int j = 0; j < engine.MaxClients (); j++) for (int j = 0; j < engine.MaxClients (); j++)
{ {
const Client &client = g_clients[j]; if (!(g_clients[j].flags & CF_USED) || !(g_clients[j].flags & CF_ALIVE) || g_clients[j].team != m_team || g_clients[j].ent == GetEntity ())
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team != m_team || client.ent == GetEntity ())
continue; continue;
Bot *other = bots.GetBot (client.ent); Bot *friendBot = bots.GetBot (g_clients[j].ent);
if (other != NULL && other->m_seeEnemyTime + 2.0f < engine.Time () && engine.IsNullEntity (other->m_lastEnemy) && IsVisible (pev->origin, other->GetEntity ()) && other->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))
{ {
other->m_lastEnemy = newEnemy; friendBot->m_lastEnemy = newEnemy;
other->m_lastEnemyOrigin = m_lastEnemyOrigin; friendBot->m_lastEnemyOrigin = m_lastEnemyOrigin;
other->m_seeEnemyTime = engine.Time (); friendBot->m_seeEnemyTime = engine.Time ();
other->m_states |= (STATE_SUSPECT_ENEMY | STATE_HEARING_ENEMY); friendBot->m_states |= (STATE_SUSPECT_ENEMY | STATE_HEARING_ENEMY);
other->m_aimFlags |= AIM_LAST_ENEMY; friendBot->m_aimFlags |= AIM_LAST_ENEMY;
} }
} }
return true; return true;
@ -1437,24 +1429,22 @@ void Bot::SelectWeaponbyNumber (int num)
void Bot::AttachToUser (void) void Bot::AttachToUser (void)
{ {
// this function forces bot to follow user // this function forces bot to follow user
Array <edict_t *> users; Array <edict_t *> foundUsers;
// search friends near us // search friends near us
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
const Client &client = g_clients[i]; if (!(g_clients[i].flags & CF_USED) || !(g_clients[i].flags & CF_ALIVE) || g_clients[i].team != m_team || g_clients[i].ent == GetEntity ())
if (!(client.flags & CF_USED) || !(client.flags & CF_ALIVE) || client.team != m_team || client.ent == GetEntity ())
continue; continue;
if (EntityIsVisible (client.origin) && !IsValidBot (client.ent)) if (EntityIsVisible (g_clients[i].origin) && !IsValidBot (g_clients[i].ent))
users.Push (client.ent); foundUsers.Push (g_clients[i].ent);
} }
if (users.IsEmpty ()) if (foundUsers.IsEmpty ())
return; return;
m_targetEntity = users.GetRandomElement (); m_targetEntity = foundUsers.GetRandomElement ();
ChatterMessage (Chatter_LeadOnSir); ChatterMessage (Chatter_LeadOnSir);
PushTask (TASK_FOLLOWUSER, TASKPRI_FOLLOWUSER, -1, 0.0f, true); PushTask (TASK_FOLLOWUSER, TASKPRI_FOLLOWUSER, -1, 0.0f, true);

View file

@ -9,41 +9,20 @@
#include <core.h> #include <core.h>
class Chat
{
public:
};
class Globals
{
public:
};
class Practice
{
public:
};
class GameState
{
public:
};
class MenuManager
{
public:
};
bool g_canSayBombPlanted = true; bool g_canSayBombPlanted = true;
bool g_isMetamod = false;
bool g_radioInsteadVoice = false;
bool g_roundEnded = true; bool g_roundEnded = true;
bool g_botsCanPause = false; bool g_botsCanPause = false;
bool g_bombPlanted = false; bool g_bombPlanted = false;
bool g_bombSayString = false; bool g_bombSayString = false;
bool g_isCommencing = false; bool g_isCommencing = false;
bool g_editNoclip = false; bool g_editNoclip = false;
bool g_waypointOn = false; bool g_waypointOn = false;
bool g_waypointsChanged = true;
bool g_autoWaypoint = false; bool g_autoWaypoint = false;
bool g_bLearnJumpWaypoint = false;
bool g_leaderChoosen[2] = {false, false};
float g_lastChatTime = 0.0f; float g_lastChatTime = 0.0f;
float g_timeRoundStart = 0.0f; float g_timeRoundStart = 0.0f;
@ -78,6 +57,10 @@ gamedll_funcs_t *gpGamedllFuncs = NULL;
mutil_funcs_t *gpMetaUtilFuncs = NULL; mutil_funcs_t *gpMetaUtilFuncs = NULL;
gamefuncs_t g_functionTable; gamefuncs_t g_functionTable;
EntityAPI_t g_entityAPI = NULL;
NewEntityAPI_t g_getNewEntityAPI = NULL;
BlendAPI_t g_serverBlendingAPI = NULL;
FuncPointers_t g_funcPointers = NULL;
enginefuncs_t g_engfuncs; enginefuncs_t g_engfuncs;
Client g_clients[MAX_ENGINE_PLAYERS]; Client g_clients[MAX_ENGINE_PLAYERS];

View file

@ -915,7 +915,7 @@ void CommandHandler_NotMM (void)
// the stdio command-line parsing in C when you write "long main (long argc, char **argv)". // the stdio command-line parsing in C when you write "long main (long argc, char **argv)".
// this function is handler for non-metamod launch of yapb, it's just print error message. // this function is handler for non-metamod launch of yapb, it's just print error message.
engine.Printf ("You're launched standalone version of yapb. Metamod is not installed or not enabled!");
} }
void GameDLLInit (void) void GameDLLInit (void)
@ -928,6 +928,8 @@ void GameDLLInit (void)
// server is enabled. Here is a good place to do our own game session initialization, and // server is enabled. Here is a good place to do our own game session initialization, and
// to register by the engine side the server commands we need to administrate our bots. // to register by the engine side the server commands we need to administrate our bots.
// register server command(s) // register server command(s)
engine.RegisterCmd ("yapb", CommandHandler); engine.RegisterCmd ("yapb", CommandHandler);
engine.RegisterCmd ("yb", CommandHandler); engine.RegisterCmd ("yb", CommandHandler);
@ -939,15 +941,10 @@ void GameDLLInit (void)
yb_version.SetString (FormatBuffer ("%d.%d.%d.%u", PRODUCT_VERSION_DWORD_INTERNAL, GenerateBuildNumber ())); yb_version.SetString (FormatBuffer ("%d.%d.%d.%u", PRODUCT_VERSION_DWORD_INTERNAL, GenerateBuildNumber ()));
// register fake metamod command handler if we not! under mm // register fake metamod command handler if we not! under mm
if (!(g_gameFlags & GAME_METAMOD)) if (!g_isMetamod)
{ engine.RegisterCmd ("meta", CommandHandler_NotMM);
engine.RegisterCmd ("meta", [] (void)
{
engine.Printf ("You're launched standalone version of yapb. Metamod is not installed or not enabled!");
});
}
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnGameInit) (); (*g_functionTable.pfnGameInit) ();
@ -973,7 +970,7 @@ void Touch (edict_t *pentTouched, edict_t *pentOther)
if (bot != NULL) if (bot != NULL)
bot->VerifyBreakable (pentTouched); bot->VerifyBreakable (pentTouched);
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnTouch) (pentTouched, pentOther); (*g_functionTable.pfnTouch) (pentTouched, pentOther);
@ -1016,7 +1013,7 @@ int Spawn (edict_t *ent)
{ {
REMOVE_ENTITY (ent); REMOVE_ENTITY (ent);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_SUPERCEDE, 0); RETURN_META_VALUE (MRES_SUPERCEDE, 0);
return 0; return 0;
@ -1067,7 +1064,7 @@ int Spawn (edict_t *ent)
else if (strncmp (engine.GetMapName (), "ka_", 3) == 0) // knife arena map else if (strncmp (engine.GetMapName (), "ka_", 3) == 0) // knife arena map
g_mapType |= MAP_KA; g_mapType |= MAP_KA;
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_IGNORED, 0); RETURN_META_VALUE (MRES_IGNORED, 0);
int result = (*g_functionTable.pfnSpawn) (ent); // get result int result = (*g_functionTable.pfnSpawn) (ent); // get result
@ -1085,7 +1082,7 @@ void UpdateClientData (const struct edict_s *ent, int sendweapons, struct client
if (!(g_gameFlags & GAME_LEGACY) && yb_latency_display.GetInt () == 2) if (!(g_gameFlags & GAME_LEGACY) && yb_latency_display.GetInt () == 2)
bots.SendPingDataOffsets (const_cast <edict_t *> (ent)); bots.SendPingDataOffsets (const_cast <edict_t *> (ent));
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnUpdateClientData) (ent, sendweapons, cd); (*g_functionTable.pfnUpdateClientData) (ent, sendweapons, cd);
@ -1119,7 +1116,7 @@ int ClientConnect (edict_t *ent, const char *name, const char *addr, char reject
bots.AdjustQuota (true, ent); bots.AdjustQuota (true, ent);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_IGNORED, 0); RETURN_META_VALUE (MRES_IGNORED, 0);
return (*g_functionTable.pfnClientConnect) (ent, name, addr, rejectReason); return (*g_functionTable.pfnClientConnect) (ent, name, addr, rejectReason);
@ -1158,7 +1155,7 @@ void ClientDisconnect (edict_t *ent)
} }
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnClientDisconnect) (ent); (*g_functionTable.pfnClientDisconnect) (ent);
@ -1187,7 +1184,7 @@ void ClientUserInfoChanged (edict_t *ent, char *infobuffer)
} }
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnClientUserInfoChanged) (ent, infobuffer); (*g_functionTable.pfnClientUserInfoChanged) (ent, infobuffer);
@ -1230,7 +1227,7 @@ void ClientCommand (edict_t *ent)
engine.ClientPrintf (ent, "Command %s, can only be executed from server console.", arg1); engine.ClientPrintf (ent, "Command %s, can only be executed from server console.", arg1);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1268,7 +1265,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1299,7 +1296,7 @@ void ClientCommand (edict_t *ent)
waypoints.ToggleFlags (FLAG_SNIPER); waypoints.ToggleFlags (FLAG_SNIPER);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1360,7 +1357,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1456,7 +1453,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, &g_menus[9]); DisplayMenuToClient (ent, &g_menus[9]);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1472,7 +1469,7 @@ void ClientCommand (edict_t *ent)
if ((selection >= 1) && (selection <= 9)) if ((selection >= 1) && (selection <= 9))
waypoints.SetRadius (radiusValue[selection - 1]); waypoints.SetRadius (radiusValue[selection - 1]);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1506,7 +1503,7 @@ void ClientCommand (edict_t *ent)
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1541,7 +1538,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1584,7 +1581,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1630,7 +1627,7 @@ void ClientCommand (edict_t *ent)
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1649,7 +1646,7 @@ void ClientCommand (edict_t *ent)
else else
engine.CenterPrintf ("AutoPath maximum distance set to %f", g_autoPathDistance); engine.CenterPrintf ("AutoPath maximum distance set to %f", g_autoPathDistance);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1677,7 +1674,7 @@ void ClientCommand (edict_t *ent)
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1718,7 +1715,7 @@ void ClientCommand (edict_t *ent)
if (client->menu == &g_menus[4]) if (client->menu == &g_menus[4])
DisplayMenuToClient (ent, &g_menus[4]); DisplayMenuToClient (ent, &g_menus[4]);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1744,7 +1741,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1765,7 +1762,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1798,7 +1795,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1821,7 +1818,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1845,7 +1842,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1870,7 +1867,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL); DisplayMenuToClient (ent, NULL);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1900,7 +1897,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, &g_menus[2]); DisplayMenuToClient (ent, &g_menus[2]);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1930,7 +1927,7 @@ void ClientCommand (edict_t *ent)
bots.RemoveMenu (ent, 1); bots.RemoveMenu (ent, 1);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1960,7 +1957,7 @@ void ClientCommand (edict_t *ent)
bots.RemoveMenu (ent, 2); bots.RemoveMenu (ent, 2);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -1986,7 +1983,7 @@ void ClientCommand (edict_t *ent)
bots.RemoveMenu (ent, 3); bots.RemoveMenu (ent, 3);
break; break;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
@ -2063,7 +2060,7 @@ void ClientCommand (edict_t *ent)
else if (strncmp (command, "radio", 5) == 0) else if (strncmp (command, "radio", 5) == 0)
g_radioSelect[clientIndex] = atoi (&command[5]); g_radioSelect[clientIndex] = atoi (&command[5]);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnClientCommand) (ent); (*g_functionTable.pfnClientCommand) (ent);
@ -2098,7 +2095,7 @@ void ServerActivate (edict_t *pentEdictList, int edictCount, int clientMax)
} }
bots.InitQuota (); bots.InitQuota ();
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnServerActivate) (pentEdictList, edictCount, clientMax); (*g_functionTable.pfnServerActivate) (pentEdictList, edictCount, clientMax);
@ -2127,7 +2124,7 @@ void ServerDeactivate (void)
FreeLibraryMemory (); FreeLibraryMemory ();
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnServerDeactivate) (); (*g_functionTable.pfnServerDeactivate) ();
@ -2220,11 +2217,7 @@ void StartFrame (void)
} }
bots.CalculatePingOffsets (); bots.CalculatePingOffsets ();
// select the leader each team if (g_isMetamod)
for (int team = TERRORIST; team < SPECTATOR; team++)
bots.SelectLeaderEachTeam (team, false);
if (g_gameFlags & GAME_METAMOD)
{ {
static cvar_t *csdm_active; static cvar_t *csdm_active;
static cvar_t *mp_freeforall; static cvar_t *mp_freeforall;
@ -2247,7 +2240,7 @@ void StartFrame (void)
// keep bot number up to date // keep bot number up to date
bots.MaintainBotQuota (); bots.MaintainBotQuota ();
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnStartFrame) (); (*g_functionTable.pfnStartFrame) ();
@ -2317,7 +2310,7 @@ void pfnChangeLevel (char *s1, char *s2)
waypoints.SaveExperienceTab (); waypoints.SaveExperienceTab ();
waypoints.SaveVisibilityTab (); waypoints.SaveVisibilityTab ();
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
CHANGE_LEVEL (s1, s2); CHANGE_LEVEL (s1, s2);
@ -2329,7 +2322,7 @@ edict_t *pfnFindEntityByString (edict_t *edictStartSearchAfter, const char *fiel
if (strcmp (value, "info_map_parameters") == 0) if (strcmp (value, "info_map_parameters") == 0)
RoundInit (); RoundInit ();
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_IGNORED, 0); RETURN_META_VALUE (MRES_IGNORED, 0);
return FIND_ENTITY_BY_STRING (edictStartSearchAfter, field, value); return FIND_ENTITY_BY_STRING (edictStartSearchAfter, field, value);
@ -2349,7 +2342,7 @@ void pfnEmitSound (edict_t *entity, int channel, const char *sample, float volum
SoundAttachToClients (entity, sample, volume); SoundAttachToClients (entity, sample, volume);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_engfuncs.pfnEmitSound) (entity, channel, sample, volume, attenuation, flags, pitch); (*g_engfuncs.pfnEmitSound) (entity, channel, sample, volume, attenuation, flags, pitch);
@ -2381,13 +2374,13 @@ void pfnClientCommand (edict_t *ent, char const *format, ...)
// is the target entity an official bot, or a third party bot ? // is the target entity an official bot, or a third party bot ?
if (ent->v.flags & FL_FAKECLIENT) if (ent->v.flags & FL_FAKECLIENT)
{ {
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); // prevent bots to be forced to issue client commands RETURN_META (MRES_SUPERCEDE); // prevent bots to be forced to issue client commands
return; return;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
CLIENT_COMMAND (ent, buffer); CLIENT_COMMAND (ent, buffer);
@ -2398,7 +2391,7 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed
// this function called each time a message is about to sent. // 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... // store the message type in our own variables, since the GET_USER_MSG_ID () will just do a lot of strcmp()'s...
if ((g_gameFlags & GAME_METAMOD) && engine.FindMessageId (NETMSG_MONEY) == -1) if (g_isMetamod && engine.FindMessageId (NETMSG_MONEY) == -1)
{ {
engine.AssignMessageId (NETMSG_VGUI, GET_USER_MSG_ID (PLID, "VGUIMenu", 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_SHOWMENU, GET_USER_MSG_ID (PLID, "ShowMenu", NULL));
@ -2469,7 +2462,7 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed
} }
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
MESSAGE_BEGIN (msgDest, msgType, origin, ed); MESSAGE_BEGIN (msgDest, msgType, origin, ed);
@ -2479,7 +2472,7 @@ void pfnMessageEnd (void)
{ {
engine.ResetMessageCapture (); engine.ResetMessageCapture ();
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
MESSAGE_END (); MESSAGE_END ();
@ -2501,7 +2494,7 @@ void pfnWriteByte (int value)
// if this message is for a bot, call the client message function... // if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value); engine.ProcessMessageCapture ((void *) &value);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
WRITE_BYTE (value); WRITE_BYTE (value);
@ -2512,7 +2505,7 @@ void pfnWriteChar (int value)
// if this message is for a bot, call the client message function... // if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value); engine.ProcessMessageCapture ((void *) &value);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
WRITE_CHAR (value); WRITE_CHAR (value);
@ -2523,7 +2516,7 @@ void pfnWriteShort (int value)
// if this message is for a bot, call the client message function... // if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value); engine.ProcessMessageCapture ((void *) &value);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
WRITE_SHORT (value); WRITE_SHORT (value);
@ -2534,7 +2527,7 @@ void pfnWriteLong (int value)
// if this message is for a bot, call the client message function... // if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value); engine.ProcessMessageCapture ((void *) &value);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
WRITE_LONG (value); WRITE_LONG (value);
@ -2545,7 +2538,7 @@ void pfnWriteAngle (float value)
// if this message is for a bot, call the client message function... // if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value); engine.ProcessMessageCapture ((void *) &value);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
WRITE_ANGLE (value); WRITE_ANGLE (value);
@ -2556,7 +2549,7 @@ void pfnWriteCoord (float value)
// if this message is for a bot, call the client message function... // if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value); engine.ProcessMessageCapture ((void *) &value);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
WRITE_COORD (value); WRITE_COORD (value);
@ -2567,7 +2560,7 @@ void pfnWriteString (const char *sz)
// if this message is for a bot, call the client message function... // if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) sz); engine.ProcessMessageCapture ((void *) sz);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
WRITE_STRING (sz); WRITE_STRING (sz);
@ -2578,7 +2571,7 @@ void pfnWriteEntity (int value)
// if this message is for a bot, call the client message function... // if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value); engine.ProcessMessageCapture ((void *) &value);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
WRITE_ENTITY (value); WRITE_ENTITY (value);
@ -2596,13 +2589,13 @@ int pfnCmd_Argc (void)
// is this a bot issuing that client command? // is this a bot issuing that client command?
if (engine.IsBotCommand ()) if (engine.IsBotCommand ())
{ {
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_SUPERCEDE, engine.GetOverrideArgc ()); RETURN_META_VALUE (MRES_SUPERCEDE, engine.GetOverrideArgc ());
return engine.GetOverrideArgc (); // if so, then return the argument count we know return engine.GetOverrideArgc (); // if so, then return the argument count we know
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_IGNORED, 0); RETURN_META_VALUE (MRES_IGNORED, 0);
return CMD_ARGC (); // ask the engine how many arguments there are return CMD_ARGC (); // ask the engine how many arguments there are
@ -2620,13 +2613,13 @@ const char *pfnCmd_Args (void)
// is this a bot issuing that client command? // is this a bot issuing that client command?
if (engine.IsBotCommand ()) if (engine.IsBotCommand ())
{ {
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_SUPERCEDE, engine.GetOverrideArgs ()); RETURN_META_VALUE (MRES_SUPERCEDE, engine.GetOverrideArgs ());
return engine.GetOverrideArgs (); // else return the whole bot client command string we know return engine.GetOverrideArgs (); // else return the whole bot client command string we know
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_IGNORED, NULL); RETURN_META_VALUE (MRES_IGNORED, NULL);
return CMD_ARGS (); // ask the client command string to the engine return CMD_ARGS (); // ask the client command string to the engine
@ -2644,12 +2637,12 @@ const char *pfnCmd_Argv (int argc)
// is this a bot issuing that client command? // is this a bot issuing that client command?
if (engine.IsBotCommand ()) if (engine.IsBotCommand ())
{ {
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_SUPERCEDE, engine.GetOverrideArgv (argc)); RETURN_META_VALUE (MRES_SUPERCEDE, engine.GetOverrideArgv (argc));
return engine.GetOverrideArgv (argc); // if so, then return the wanted argument we know return engine.GetOverrideArgv (argc); // if so, then return the wanted argument we know
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_IGNORED, NULL); RETURN_META_VALUE (MRES_IGNORED, NULL);
return CMD_ARGV (argc); // ask the argument number "argc" to the engine return CMD_ARGV (argc); // ask the argument number "argc" to the engine
@ -2665,13 +2658,13 @@ void pfnClientPrintf (edict_t *ent, PRINT_TYPE printType, const char *message)
if (IsValidBot (ent)) if (IsValidBot (ent))
{ {
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_SUPERCEDE); RETURN_META (MRES_SUPERCEDE);
return; return;
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
CLIENT_PRINTF (ent, printType, message); CLIENT_PRINTF (ent, printType, message);
@ -2685,7 +2678,7 @@ void pfnSetClientMaxspeed (const edict_t *ent, float newMaxspeed)
if (bot != NULL) if (bot != NULL)
bot->pev->maxspeed = newMaxspeed; bot->pev->maxspeed = newMaxspeed;
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_engfuncs.pfnSetClientMaxspeed) (ent, newMaxspeed); (*g_engfuncs.pfnSetClientMaxspeed) (ent, newMaxspeed);
@ -2703,7 +2696,7 @@ int pfnRegUserMsg (const char *name, int size)
// using pfnMessageBegin (), it will know what message ID number to send, and the engine will // using pfnMessageBegin (), it will know what message ID number to send, and the engine will
// know what to do, only for non-metamod version // know what to do, only for non-metamod version
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META_VALUE (MRES_IGNORED, 0); RETURN_META_VALUE (MRES_IGNORED, 0);
int message = REG_USER_MSG (name, size); int message = REG_USER_MSG (name, size);
@ -2774,7 +2767,7 @@ void pfnAlertMessage (ALERT_TYPE alertType, char *format, ...)
} }
} }
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
(*g_engfuncs.pfnAlertMessage) (alertType, buffer); (*g_engfuncs.pfnAlertMessage) (alertType, buffer);
@ -2796,12 +2789,10 @@ SHARED_LIBRARAY_EXPORT int GetEntityAPI2 (gamefuncs_t *functionTable, int *)
memset (functionTable, 0, sizeof (gamefuncs_t)); memset (functionTable, 0, sizeof (gamefuncs_t));
if (!(g_gameFlags & GAME_METAMOD)) if (!g_isMetamod)
{ {
auto api_GetEntityAPI = g_gameLib->GetFuncAddr <EntityAPI_t> ("GetEntityAPI");
// pass other DLLs engine callbacks to function table... // pass other DLLs engine callbacks to function table...
if (api_GetEntityAPI (&g_functionTable, INTERFACE_VERSION) == 0) if ((*g_entityAPI) (&g_functionTable, INTERFACE_VERSION) == 0)
{ {
AddLogEntry (true, LL_FATAL, "GetEntityAPI2: ERROR - Not Initialized."); AddLogEntry (true, LL_FATAL, "GetEntityAPI2: ERROR - Not Initialized.");
return FALSE; // error initializing function table!!! return FALSE; // error initializing function table!!!
@ -2857,12 +2848,10 @@ SHARED_LIBRARAY_EXPORT int GetNewDLLFunctions (newgamefuncs_t *functionTable, in
// pass them too, else the DLL interfacing wouldn't be complete and the game possibly wouldn't // pass them too, else the DLL interfacing wouldn't be complete and the game possibly wouldn't
// run properly. // run properly.
auto api_GetNewDLLFunctions = g_gameLib->GetFuncAddr <NewEntityAPI_t> ("GetNewDLLFunctions"); if (g_getNewEntityAPI == NULL)
if (api_GetNewDLLFunctions == NULL)
return FALSE; return FALSE;
if (!api_GetNewDLLFunctions (functionTable, interfaceVersion)) if (!(*g_getNewEntityAPI) (functionTable, interfaceVersion))
{ {
AddLogEntry (true, LL_FATAL, "GetNewDLLFunctions: ERROR - Not Initialized."); AddLogEntry (true, LL_FATAL, "GetNewDLLFunctions: ERROR - Not Initialized.");
return FALSE; return FALSE;
@ -2874,7 +2863,7 @@ SHARED_LIBRARAY_EXPORT int GetNewDLLFunctions (newgamefuncs_t *functionTable, in
SHARED_LIBRARAY_EXPORT int GetEngineFunctions (enginefuncs_t *functionTable, int *) SHARED_LIBRARAY_EXPORT int GetEngineFunctions (enginefuncs_t *functionTable, int *)
{ {
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
memset (functionTable, 0, sizeof (enginefuncs_t)); memset (functionTable, 0, sizeof (enginefuncs_t));
functionTable->pfnChangeLevel = pfnChangeLevel; functionTable->pfnChangeLevel = pfnChangeLevel;
@ -2917,12 +2906,10 @@ SHARED_LIBRARAY_EXPORT int Server_GetBlendingInterface (int version, void **ppin
// of the body move, which bones, which hitboxes and how) between the server and the game DLL. // of the body move, which bones, which hitboxes and how) between the server and the game DLL.
// some MODs can be using a different hitbox scheme than the standard one. // some MODs can be using a different hitbox scheme than the standard one.
auto api_GetBlendingInterface = g_gameLib->GetFuncAddr <BlendAPI_t> ("Server_GetBlendingInterface"); if (g_serverBlendingAPI == NULL)
if (api_GetBlendingInterface == NULL)
return FALSE; return FALSE;
return api_GetBlendingInterface (version, ppinterface, pstudio, rotationmatrix, bonetransform); return (*g_serverBlendingAPI) (version, ppinterface, pstudio, rotationmatrix, bonetransform);
} }
SHARED_LIBRARAY_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)
@ -2967,7 +2954,7 @@ SHARED_LIBRARAY_EXPORT void Meta_Init (void)
// this function is called by metamod, before any other interface functions. Purpose of this // 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. // function to give plugin a chance to determine is plugin running under metamod or not.
g_gameFlags |= GAME_METAMOD; g_isMetamod = true;
} }
Library *LoadCSBinary (void) Library *LoadCSBinary (void)
@ -3000,7 +2987,7 @@ Library *LoadCSBinary (void)
{ {
g_gameFlags |= GAME_CZERO; g_gameFlags |= GAME_CZERO;
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
return NULL; return NULL;
return new Library (path); return new Library (path);
@ -3021,7 +3008,7 @@ Library *LoadCSBinary (void)
{ {
g_gameFlags |= (GAME_LEGACY | GAME_XASH); g_gameFlags |= (GAME_LEGACY | GAME_XASH);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
{ {
delete game; delete game;
return NULL; return NULL;
@ -3037,7 +3024,7 @@ Library *LoadCSBinary (void)
else else
g_gameFlags |= GAME_LEGACY; g_gameFlags |= GAME_LEGACY;
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
{ {
delete game; delete game;
return NULL; return NULL;
@ -3080,7 +3067,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
#ifdef PLATFORM_ANDROID #ifdef PLATFORM_ANDROID
g_gameFlags |= (GAME_LEGACY | GAME_XASH | GAME_MOBILITY); g_gameFlags |= (GAME_LEGACY | GAME_XASH | GAME_MOBILITY);
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
return; // we should stop the attempt for loading the real gamedll, since metamod handle this for us return; // we should stop the attempt for loading the real gamedll, since metamod handle this for us
#ifdef LOAD_HARDFP #ifdef LOAD_HARDFP
@ -3099,7 +3086,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
#else #else
g_gameLib = LoadCSBinary (); g_gameLib = LoadCSBinary ();
{ {
if (g_gameLib == NULL && !(g_gameFlags & GAME_METAMOD)) if (g_gameLib == NULL && !g_isMetamod)
{ {
AddLogEntry (true, LL_FATAL | LL_IGNORE, "Mod that you has started, not supported by this bot (gamedir: %s)", engine.GetModName ()); AddLogEntry (true, LL_FATAL | LL_IGNORE, "Mod that you has started, not supported by this bot (gamedir: %s)", engine.GetModName ());
return; return;
@ -3128,20 +3115,23 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
} }
engine.Printf ("YaPB Bot has detect game version as Counter-Strike: %s", gameVersionStr.GetBuffer ()); engine.Printf ("YaPB Bot has detect game version as Counter-Strike: %s", gameVersionStr.GetBuffer ());
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
return; return;
} }
#endif #endif
auto api_GiveFnptrsToDll = g_gameLib->GetFuncAddr <FuncPointers_t> ("GiveFnptrsToDll"); g_funcPointers = g_gameLib->GetFuncAddr <FuncPointers_t> ("GiveFnptrsToDll");
g_entityAPI = g_gameLib->GetFuncAddr <EntityAPI_t> ("GetEntityAPI");
g_getNewEntityAPI = g_gameLib->GetFuncAddr <NewEntityAPI_t> ("GetNewDLLFunctions");
g_serverBlendingAPI = g_gameLib->GetFuncAddr <BlendAPI_t> ("Server_GetBlendingInterface");
if (!api_GiveFnptrsToDll) if (!g_funcPointers || !g_entityAPI)
TerminateOnMalloc (); TerminateOnMalloc ();
GetEngineFunctions (functionTable, NULL); GetEngineFunctions (functionTable, NULL);
// give the engine functions to the other DLL... // give the engine functions to the other DLL...
api_GiveFnptrsToDll (functionTable, pGlobals); (*g_funcPointers) (functionTable, pGlobals);
} }
DLL_ENTRYPOINT DLL_ENTRYPOINT

View file

@ -100,7 +100,7 @@ void BotManager::CallGameEntity (entvars_t *vars)
{ {
// this function calls gamedll player() function, in case to create player entity in game // this function calls gamedll player() function, in case to create player entity in game
if (g_gameFlags & GAME_METAMOD) if (g_isMetamod)
{ {
CALL_GAME_ENTITY (PLID, "player", vars); CALL_GAME_ENTITY (PLID, "player", vars);
return; return;
@ -108,7 +108,7 @@ void BotManager::CallGameEntity (entvars_t *vars)
player (vars); player (vars);
} }
BotCreationResult BotManager::CreateBot (const String &name, int difficulty, int personality, int team, int member, bool isConsoleCmd) int BotManager::CreateBot (const String &name, int difficulty, int personality, int team, int member, bool isConsoleCmd)
{ {
// this function completely prepares bot entity (edict) for creation, creates team, difficulty, sets name etc, and // this function completely prepares bot entity (edict) for creation, creates team, difficulty, sets name etc, and
// then sends result to bot constructor // then sends result to bot constructor
@ -119,12 +119,12 @@ BotCreationResult BotManager::CreateBot (const String &name, int difficulty, int
if (g_numWaypoints < 1) // don't allow creating bots with no waypoints loaded if (g_numWaypoints < 1) // don't allow creating bots with no waypoints loaded
{ {
engine.CenterPrintf ("Map is not waypointed. Cannot create bot"); engine.CenterPrintf ("Map is not waypointed. Cannot create bot");
return BOT_RESULT_NAV_ERROR; return 0;
} }
else if (waypoints.HasChanged ()) // don't allow creating bots with changed waypoints (distance tables are messed up) else if (g_waypointsChanged) // don't allow creating bots with changed waypoints (distance tables are messed up)
{ {
engine.CenterPrintf ("Waypoints have been changed. Load waypoints again..."); engine.CenterPrintf ("Waypoints have been changed. Load waypoints again...");
return BOT_RESULT_NAV_ERROR; return 0;
} }
if (difficulty < 0 || difficulty > 4) if (difficulty < 0 || difficulty > 4)
@ -199,7 +199,7 @@ BotCreationResult BotManager::CreateBot (const String &name, int difficulty, int
if (engine.IsNullEntity (bot)) if (engine.IsNullEntity (bot))
{ {
engine.CenterPrintf ("Maximum players reached (%d/%d). Unable to create Bot.", engine.MaxClients (), engine.MaxClients ()); engine.CenterPrintf ("Maximum players reached (%d/%d). Unable to create Bot.", engine.MaxClients (), engine.MaxClients ());
return BOT_RESULT_MAX_PLAYERS_REACHED; return 2;
} }
int index = engine.IndexOfEntity (bot) - 1; int index = engine.IndexOfEntity (bot) - 1;
@ -216,7 +216,7 @@ BotCreationResult BotManager::CreateBot (const String &name, int difficulty, int
if (isConsoleCmd) if (isConsoleCmd)
yb_quota.SetInt (yb_quota.GetInt () + 1); yb_quota.SetInt (yb_quota.GetInt () + 1);
return BOT_RESULT_CREATED; return 1;
} }
int BotManager::GetIndex (edict_t *ent) int BotManager::GetIndex (edict_t *ent)
@ -260,19 +260,19 @@ Bot *BotManager::FindOneValidAliveBot (void)
{ {
// this function finds one bot, alive bot :) // this function finds one bot, alive bot :)
Array <int> result; Array <int> foundBots;
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
if (result.GetSize () > 4) if (foundBots.GetSize () > 4)
break; break;
if (m_bots[i] != NULL && IsAlive (m_bots[i]->GetEntity ())) if (m_bots[i] != NULL && IsAlive (m_bots[i]->GetEntity ()))
result.Push (i); foundBots.Push (i);
} }
if (!result.IsEmpty ()) if (!foundBots.IsEmpty ())
return m_bots[result.GetRandomElement ()]; return m_bots[foundBots.GetRandomElement ()];
return NULL; return NULL;
} }
@ -408,22 +408,22 @@ void BotManager::MaintainBotQuota (void)
// this function keeps number of bots up to date, and don't allow to maintain bot creation // this function keeps number of bots up to date, and don't allow to maintain bot creation
// while creation process in process. // while creation process in process.
if (g_numWaypoints < 1 || waypoints.HasChanged ()) if (g_numWaypoints < 1 || g_waypointsChanged)
return; return;
// bot's creation update // bot's creation update
if (!m_creationTab.IsEmpty () && m_maintainTime < engine.Time ()) if (!m_creationTab.IsEmpty () && m_maintainTime < engine.Time ())
{ {
const CreateQueue &last = m_creationTab.Pop (); CreateQueue last = m_creationTab.Pop ();
const BotCreationResult callResult = CreateBot (last.name, last.difficulty, last.personality, last.team, last.member, last.console); int resultOfCall = CreateBot (last.name, last.difficulty, last.personality, last.team, last.member, last.console);
// check the result of creation // check the result of creation
if (callResult == BOT_RESULT_NAV_ERROR) if (resultOfCall == 0)
{ {
m_creationTab.RemoveAll (); // something wrong with waypoints, reset tab of creation m_creationTab.RemoveAll (); // something wrong with waypoints, reset tab of creation
yb_quota.SetInt (0); // reset quota yb_quota.SetInt (0); // reset quota
} }
else if (callResult == BOT_RESULT_MAX_PLAYERS_REACHED) else if (resultOfCall == 2)
{ {
m_creationTab.RemoveAll (); // maximum players reached, so set quota to maximum players m_creationTab.RemoveAll (); // maximum players reached, so set quota to maximum players
yb_quota.SetInt (GetBotsNum ()); yb_quota.SetInt (GetBotsNum ());
@ -888,7 +888,6 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c
// initialize all the variables for this bot... // initialize all the variables for this bot...
m_notStarted = true; // hasn't joined game yet m_notStarted = true; // hasn't joined game yet
m_forceRadio = false;
m_startAction = GSM_IDLE; m_startAction = GSM_IDLE;
m_moneyAmount = 0; m_moneyAmount = 0;
@ -1029,6 +1028,7 @@ void Bot::NewRound (void)
{ {
// this function initializes a bot after creation & at the start of each round // this function initializes a bot after creation & at the start of each round
g_canSayBombPlanted = true;
int i = 0; int i = 0;
// delete all allocated path nodes // delete all allocated path nodes
@ -1478,108 +1478,3 @@ const Array <edict_t *> &BotManager::GetActiveGrenades (void)
{ {
return m_activeGrenades; return m_activeGrenades;
} }
void BotManager::SelectLeaderEachTeam (int team, bool reset)
{
if (reset)
{
m_leaderChoosen[team] = false;
return;
}
if (g_mapType & MAP_AS)
{
if (team == CT && !m_leaderChoosen[CT])
{
for (int i = 0; i < engine.MaxClients (); i++)
{
auto bot = m_bots[i];
if (bot != NULL && bot->m_isVIP)
{
// vip bot is the leader
bot->m_isLeader = true;
if (Random.Long (1, 100) < 50)
{
bot->RadioMessage (Radio_FollowMe);
bot->m_campButtons = 0;
}
}
}
m_leaderChoosen[CT] = true;
}
else if (team == TERRORIST && !m_leaderChoosen[TERRORIST])
{
auto bot = bots.GetHighestFragsBot (team);
if (bot != NULL && bot->m_notKilled)
{
bot->m_isLeader = true;
if (Random.Long (1, 100) < 45)
bot->RadioMessage (Radio_FollowMe);
}
m_leaderChoosen[TERRORIST] = true;
}
}
else if (g_mapType & MAP_DE)
{
if (team == TERRORIST && !m_leaderChoosen[TERRORIST])
{
for (int i = 0; i < engine.MaxClients (); i++)
{
auto bot = m_bots[i];
if (bot != NULL && bot->m_hasC4)
{
// bot carrying the bomb is the leader
bot->m_isLeader = true;
// terrorist carrying a bomb needs to have some company
if (Random.Long (1, 100) < 80)
{
if (yb_communication_type.GetInt () == 2)
bot->ChatterMessage (Chatter_GoingToPlantBomb);
else
bot->ChatterMessage (Radio_FollowMe);
bot->m_campButtons = 0;
}
}
m_leaderChoosen[TERRORIST] = true;
}
}
else if (!m_leaderChoosen[CT])
{
if (auto bot = bots.GetHighestFragsBot (team))
{
bot->m_isLeader = true;
if (Random.Long (1, 100) < 30)
bot->RadioMessage (Radio_FollowMe);
}
m_leaderChoosen[CT] = true;
}
}
else if (g_mapType & (MAP_ES | MAP_KA | MAP_FY))
{
if (auto bot = bots.GetHighestFragsBot (team))
{
bot->m_isLeader = true;
if (Random.Long (1, 100) < 30)
bot->RadioMessage (Radio_FollowMe);
}
}
else
{
if (auto bot = bots.GetHighestFragsBot (team))
{
bot->m_isLeader = true;
if (Random.Long (1, 100) < (team == TERRORIST ? 30 : 40))
bot->RadioMessage (Radio_FollowMe);
}
}
}

View file

@ -250,7 +250,7 @@ void UpdateGlobalExperienceData (void)
// this function called after each end of the round to update knowledge about most dangerous waypoints for each team. // this function called after each end of the round to update knowledge about most dangerous waypoints for each team.
// no waypoints, no experience used or waypoints edited or being edited? // no waypoints, no experience used or waypoints edited or being edited?
if (g_numWaypoints < 1 || waypoints.HasChanged ()) if (g_numWaypoints < 1 || g_waypointsChanged)
return; // no action return; // no action
unsigned short maxDamage; // maximum damage unsigned short maxDamage; // maximum damage
@ -371,14 +371,10 @@ void RoundInit (void)
// this is called at the start of each round // this is called at the start of each round
g_roundEnded = false; g_roundEnded = false;
g_canSayBombPlanted = true;
// check team economics // check team economics
for (int team = TERRORIST; team < SPECTATOR; team++) bots.CheckTeamEconomics (TERRORIST);
{ bots.CheckTeamEconomics (CT);
bots.CheckTeamEconomics (team);
bots.SelectLeaderEachTeam (team, true);
}
for (int i = 0; i < engine.MaxClients (); i++) for (int i = 0; i < engine.MaxClients (); i++)
{ {
@ -394,6 +390,9 @@ void RoundInit (void)
g_timeBombPlanted = 0.0f; g_timeBombPlanted = 0.0f;
g_timeNextBombUpdate = 0.0f; g_timeNextBombUpdate = 0.0f;
g_leaderChoosen[CT] = false;
g_leaderChoosen[TERRORIST] = false;
g_lastRadioTime[0] = 0.0f; g_lastRadioTime[0] = 0.0f;
g_lastRadioTime[1] = 0.0f; g_lastRadioTime[1] = 0.0f;
g_botsCanPause = false; g_botsCanPause = false;

View file

@ -166,7 +166,7 @@ void Waypoint::Add (int flags, const Vector &waypointOrigin)
if (bots.GetBotsNum () > 0) if (bots.GetBotsNum () > 0)
bots.RemoveAll (); bots.RemoveAll ();
m_waypointsChanged = true; g_waypointsChanged = true;
switch (flags) switch (flags)
{ {
@ -443,7 +443,7 @@ void Waypoint::Add (int flags, const Vector &waypointOrigin)
void Waypoint::Delete (void) void Waypoint::Delete (void)
{ {
m_waypointsChanged = true; g_waypointsChanged = true;
if (g_numWaypoints < 1) if (g_numWaypoints < 1)
return; return;
@ -634,9 +634,10 @@ void Waypoint::CreatePath (char dir)
} }
engine.EmitSound (g_hostEntity, "common/wpn_hudon.wav"); engine.EmitSound (g_hostEntity, "common/wpn_hudon.wav");
m_waypointsChanged = true; g_waypointsChanged = true;
} }
void Waypoint::DeletePath (void) void Waypoint::DeletePath (void)
{ {
// this function allow player to manually remove a path from one waypoint to another // this function allow player to manually remove a path from one waypoint to another
@ -666,7 +667,7 @@ void Waypoint::DeletePath (void)
{ {
if (m_paths[nodeFrom]->index[index] == nodeTo) if (m_paths[nodeFrom]->index[index] == nodeTo)
{ {
m_waypointsChanged = true; g_waypointsChanged = true;
m_paths[nodeFrom]->index[index] = -1; // unassigns this path m_paths[nodeFrom]->index[index] = -1; // unassigns this path
m_paths[nodeFrom]->distances[index] = 0; m_paths[nodeFrom]->distances[index] = 0;
@ -687,7 +688,7 @@ void Waypoint::DeletePath (void)
{ {
if (m_paths[nodeFrom]->index[index] == nodeTo) if (m_paths[nodeFrom]->index[index] == nodeTo)
{ {
m_waypointsChanged = true; g_waypointsChanged = true;
m_paths[nodeFrom]->index[index] = -1; // unassign this path m_paths[nodeFrom]->index[index] = -1; // unassign this path
m_paths[nodeFrom]->distances[index] = 0; m_paths[nodeFrom]->distances[index] = 0;
@ -828,7 +829,7 @@ void Waypoint::SaveExperienceTab (void)
{ {
ExtensionHeader header; ExtensionHeader header;
if (g_numWaypoints < 1 || m_waypointsChanged) if ((g_numWaypoints <= 0) || g_waypointsChanged)
return; return;
memset (header.header, 0, sizeof (header.header)); memset (header.header, 0, sizeof (header.header));
@ -1208,7 +1209,7 @@ bool Waypoint::Load (void)
InitPathMatrix (); InitPathMatrix ();
InitTypes (); InitTypes ();
m_waypointsChanged = false; g_waypointsChanged = false;
g_highestKills = 1; g_highestKills = 1;
m_pathDisplayTime = 0.0f; m_pathDisplayTime = 0.0f;
@ -1750,7 +1751,7 @@ void Waypoint::Think (void)
} }
// draw the danger directions // draw the danger directions
if (!m_waypointsChanged) if (!g_waypointsChanged)
{ {
if ((g_experienceData + (nearestIndex * g_numWaypoints) + nearestIndex)->team0DangerIndex != -1 && engine.GetTeam (g_hostEntity) == TERRORIST) if ((g_experienceData + (nearestIndex * g_numWaypoints) + nearestIndex)->team0DangerIndex != -1 && engine.GetTeam (g_hostEntity) == TERRORIST)
engine.DrawLine (g_hostEntity, path->origin, m_paths[(g_experienceData + (nearestIndex * g_numWaypoints) + nearestIndex)->team0DangerIndex]->origin, 15, 0, 255, 0, 0, 200, 0, 10, DRAW_ARROW); // draw a red arrow to this index's danger point engine.DrawLine (g_hostEntity, path->origin, m_paths[(g_experienceData + (nearestIndex * g_numWaypoints) + nearestIndex)->team0DangerIndex]->origin, 15, 0, 255, 0, 0, 200, 0, 10, DRAW_ARROW); // draw a red arrow to this index's danger point
@ -1769,7 +1770,7 @@ void Waypoint::Think (void)
// if waypoint is not changed display experience also // if waypoint is not changed display experience also
if (!m_waypointsChanged) if (!g_waypointsChanged)
{ {
int dangerIndexCT = (g_experienceData + nearestIndex * g_numWaypoints + nearestIndex)->team1DangerIndex; int dangerIndexCT = (g_experienceData + nearestIndex * g_numWaypoints + nearestIndex)->team1DangerIndex;
int dangerIndexT = (g_experienceData + nearestIndex * g_numWaypoints + nearestIndex)->team0DangerIndex; int dangerIndexT = (g_experienceData + nearestIndex * g_numWaypoints + nearestIndex)->team0DangerIndex;
@ -2477,7 +2478,6 @@ Waypoint::Waypoint (void)
m_endJumpPoint = false; m_endJumpPoint = false;
m_redoneVisibility = false; m_redoneVisibility = false;
m_learnJumpWaypoint = false; m_learnJumpWaypoint = false;
m_waypointsChanged = false;
m_timeJumpStarted = 0.0f; m_timeJumpStarted = 0.0f;
m_lastJumpWaypoint = -1; m_lastJumpWaypoint = -1;