2015-06-30 12:46:07 +03:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of this program with the Half-Life Game Engine ("HL
|
|
|
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL Engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BOT_UTIL_H
|
|
|
|
#define BOT_UTIL_H
|
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma once
|
|
|
|
#endif
|
|
|
|
|
2015-12-07 17:18:21 +03:00
|
|
|
#define COS_TABLE_SIZE 256
|
|
|
|
|
|
|
|
#define RAD_TO_DEG(deg) ((deg) * 180.0 / M_PI)
|
|
|
|
#define DEG_TO_RAD(rad) ((rad) * M_PI / 180.0)
|
|
|
|
|
|
|
|
#define SIGN(num) (((num) < 0) ? -1 : 1)
|
|
|
|
#define ABS(num) (SIGN(num) * (num))
|
2015-06-30 12:46:07 +03:00
|
|
|
|
|
|
|
class CBasePlayer;
|
|
|
|
class BotProfile;
|
|
|
|
|
|
|
|
enum PriorityType
|
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
PRIORITY_LOW, PRIORITY_MEDIUM, PRIORITY_HIGH, PRIORITY_UNINTERRUPTABLE
|
2015-06-30 12:46:07 +03:00
|
|
|
};
|
|
|
|
|
2015-12-05 22:40:30 +03:00
|
|
|
// Simple class for tracking intervals of game time
|
2015-06-30 12:46:07 +03:00
|
|
|
class IntervalTimer
|
|
|
|
{
|
|
|
|
public:
|
2016-02-23 02:13:52 +03:00
|
|
|
IntervalTimer() { m_timestamp = -1.0f; }
|
|
|
|
void Reset() { m_timestamp = gpGlobals->time; }
|
|
|
|
void Start() { m_timestamp = gpGlobals->time; }
|
|
|
|
void Invalidate() { m_timestamp = -1.0f; }
|
2016-02-04 03:18:26 +03:00
|
|
|
|
|
|
|
bool HasStarted() const { return (m_timestamp > 0.0f); }
|
|
|
|
|
2015-12-05 22:40:30 +03:00
|
|
|
// if not started, elapsed time is very large
|
2016-02-23 02:13:52 +03:00
|
|
|
float GetElapsedTime() const { return (HasStarted()) ? (gpGlobals->time - m_timestamp) : 99999.9f; }
|
|
|
|
bool IsLessThen(float duration) const { return (gpGlobals->time - m_timestamp < duration) ? true : false; }
|
|
|
|
bool IsGreaterThen(float duration) const { return (gpGlobals->time - m_timestamp > duration) ? true : false; }
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
private:
|
2015-06-30 12:46:07 +03:00
|
|
|
float m_timestamp;
|
2016-02-04 03:18:26 +03:00
|
|
|
};
|
2015-06-30 12:46:07 +03:00
|
|
|
|
2015-12-05 22:40:30 +03:00
|
|
|
// Simple class for counting down a short interval of time
|
2015-06-30 12:46:07 +03:00
|
|
|
class CountdownTimer
|
|
|
|
{
|
|
|
|
public:
|
2016-02-23 02:13:52 +03:00
|
|
|
CountdownTimer() { m_timestamp = -1.0f; m_duration = 0.0f; }
|
|
|
|
void Reset() { m_timestamp = gpGlobals->time + m_duration; }
|
2016-02-04 03:18:26 +03:00
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
void Start(float duration) { m_timestamp = gpGlobals->time + duration; m_duration = duration; }
|
|
|
|
bool HasStarted() const { return (m_timestamp > 0.0f); }
|
2016-02-04 03:18:26 +03:00
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
void Invalidate() { m_timestamp = -1.0f; }
|
|
|
|
bool IsElapsed() const { return (gpGlobals->time > m_timestamp); }
|
2015-12-05 22:40:30 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
private:
|
|
|
|
float m_duration;
|
|
|
|
float m_timestamp;
|
2016-02-04 03:18:26 +03:00
|
|
|
};
|
2015-06-30 12:46:07 +03:00
|
|
|
|
2015-12-05 22:40:30 +03:00
|
|
|
// Return true if the given entity is valid
|
2015-06-30 12:46:07 +03:00
|
|
|
inline bool IsEntityValid(CBaseEntity *entity)
|
|
|
|
{
|
2015-07-12 23:32:09 +03:00
|
|
|
if (entity == NULL)
|
2015-06-30 12:46:07 +03:00
|
|
|
return false;
|
|
|
|
|
2015-07-12 23:32:09 +03:00
|
|
|
if (FNullEnt(entity->pev))
|
2015-06-30 12:46:07 +03:00
|
|
|
return false;
|
|
|
|
|
2015-07-12 23:32:09 +03:00
|
|
|
if (FStrEq(STRING(entity->pev->netname), ""))
|
2015-06-30 12:46:07 +03:00
|
|
|
return false;
|
|
|
|
|
2015-07-12 23:32:09 +03:00
|
|
|
if (entity->pev->flags & FL_DORMANT)
|
2015-06-30 12:46:07 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-05 22:40:30 +03:00
|
|
|
// Given two line segments: startA to endA, and startB to endB, return true if they intesect
|
|
|
|
// and put the intersection point in "result".
|
|
|
|
// Note that this computes the intersection of the 2D (x,y) projection of the line segments.
|
2015-06-30 12:46:07 +03:00
|
|
|
inline bool IsIntersecting2D(const Vector &startA, const Vector &endA, const Vector &startB, const Vector &endB, Vector *result = NULL)
|
|
|
|
{
|
|
|
|
float denom = (endA.x - startA.x) * (endB.y - startB.y) - (endA.y - startA.y) * (endB.x - startB.x);
|
|
|
|
if (denom == 0.0f)
|
|
|
|
{
|
2015-12-05 22:40:30 +03:00
|
|
|
// parallel
|
2015-06-30 12:46:07 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-19 14:54:31 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
float numS = (startA.y - startB.y) * (endB.x - startB.x) - (startA.x - startB.x) * (endB.y - startB.y);
|
|
|
|
if (numS == 0.0f)
|
|
|
|
{
|
2015-12-05 22:40:30 +03:00
|
|
|
// coincident
|
2015-06-30 12:46:07 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-01-19 14:54:31 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
float numT = (startA.y - startB.y) * (endA.x - startA.x) - (startA.x - startB.x) * (endA.y - startA.y);
|
|
|
|
float s = numS / denom;
|
|
|
|
if (s < 0.0f || s > 1.0f)
|
|
|
|
{
|
2015-12-05 22:40:30 +03:00
|
|
|
// intersection is not within line segment of startA to endA
|
2015-06-30 12:46:07 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-19 14:54:31 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
float t = numT / denom;
|
|
|
|
if (t < 0.0f || t > 1.0f)
|
|
|
|
{
|
2015-12-05 22:40:30 +03:00
|
|
|
// intersection is not within line segment of startB to endB
|
2015-06-30 12:46:07 +03:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-05 22:40:30 +03:00
|
|
|
|
|
|
|
// compute intesection point
|
2016-02-23 02:13:52 +03:00
|
|
|
if (result != NULL)
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
|
|
|
*result = startA + s * (endA - startA);
|
|
|
|
}
|
2016-02-04 03:18:26 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-05 22:40:30 +03:00
|
|
|
// Iterate over all active players in the game, invoking functor on each.
|
|
|
|
// If functor returns false, stop iteration and return false.
|
2015-12-09 01:39:54 +03:00
|
|
|
template <typename Functor>
|
2015-07-05 14:05:26 +03:00
|
|
|
bool ForEachPlayer(Functor &func)
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
for (int i = 1; i <= gpGlobals->maxClients; ++i)
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
2016-05-31 17:04:51 +03:00
|
|
|
CBasePlayer *player = UTIL_PlayerByIndex(i);
|
2015-07-12 23:32:09 +03:00
|
|
|
if (!IsEntityValid((CBaseEntity *)player))
|
2015-06-30 12:46:07 +03:00
|
|
|
continue;
|
|
|
|
|
2015-07-12 23:32:09 +03:00
|
|
|
if (!player->IsPlayer())
|
2015-06-30 12:46:07 +03:00
|
|
|
continue;
|
|
|
|
|
2015-07-12 23:32:09 +03:00
|
|
|
if (func(player) == false)
|
2015-06-30 12:46:07 +03:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-09 01:39:54 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-05 22:40:30 +03:00
|
|
|
// For zombie game
|
2016-02-04 03:18:26 +03:00
|
|
|
inline bool IsZombieGame()
|
2015-06-30 12:46:07 +03:00
|
|
|
{
|
|
|
|
#ifdef TERRORSTRIKE
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif // TERRORSTRIKE
|
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
extern cvar_t cv_bot_traceview;
|
|
|
|
extern cvar_t cv_bot_stop;
|
|
|
|
extern cvar_t cv_bot_show_nav;
|
|
|
|
extern cvar_t cv_bot_show_danger;
|
|
|
|
extern cvar_t cv_bot_nav_edit;
|
|
|
|
extern cvar_t cv_bot_nav_zdraw;
|
|
|
|
extern cvar_t cv_bot_walk;
|
|
|
|
extern cvar_t cv_bot_difficulty;
|
|
|
|
extern cvar_t cv_bot_debug;
|
|
|
|
extern cvar_t cv_bot_quicksave;
|
|
|
|
extern cvar_t cv_bot_quota;
|
|
|
|
extern cvar_t cv_bot_quota_match;
|
|
|
|
extern cvar_t cv_bot_prefix;
|
|
|
|
extern cvar_t cv_bot_allow_rogues;
|
|
|
|
extern cvar_t cv_bot_allow_pistols;
|
|
|
|
extern cvar_t cv_bot_allow_shotguns;
|
|
|
|
extern cvar_t cv_bot_allow_sub_machine_guns;
|
|
|
|
extern cvar_t cv_bot_allow_rifles;
|
|
|
|
extern cvar_t cv_bot_allow_machine_guns;
|
|
|
|
extern cvar_t cv_bot_allow_grenades;
|
|
|
|
extern cvar_t cv_bot_allow_snipers;
|
|
|
|
extern cvar_t cv_bot_allow_shield;
|
|
|
|
extern cvar_t cv_bot_join_team;
|
|
|
|
extern cvar_t cv_bot_join_after_player;
|
|
|
|
extern cvar_t cv_bot_auto_vacate;
|
|
|
|
extern cvar_t cv_bot_zombie;
|
|
|
|
extern cvar_t cv_bot_defer_to_human;
|
|
|
|
extern cvar_t cv_bot_chatter;
|
|
|
|
extern cvar_t cv_bot_profile_db;
|
|
|
|
|
2016-06-14 01:13:13 +03:00
|
|
|
#ifdef REGAMEDLL_ADD
|
|
|
|
extern cvar_t cv_bot_deathmatch;
|
2017-02-03 12:55:00 +03:00
|
|
|
extern cvar_t cv_bot_quota_mode;
|
2016-06-14 01:13:13 +03:00
|
|
|
#endif
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
#define IS_ALIVE true
|
|
|
|
int UTIL_HumansOnTeam(int teamID, bool isAlive = false);
|
|
|
|
|
|
|
|
#define IGNORE_SPECTATORS true
|
|
|
|
int UTIL_HumansInGame(bool ignoreSpectators = false);
|
|
|
|
|
2015-08-02 20:45:57 +03:00
|
|
|
bool UTIL_IsNameTaken(const char *name, bool ignoreHumans = false);
|
2016-02-04 03:18:26 +03:00
|
|
|
int UTIL_ClientsInGame();
|
|
|
|
int UTIL_ActivePlayersInGame();
|
|
|
|
int UTIL_BotsInGame();
|
2015-08-20 13:35:01 +03:00
|
|
|
bool UTIL_KickBotFromTeam(TeamName kickTeam);
|
2016-01-19 14:54:31 +03:00
|
|
|
bool UTIL_IsTeamAllBots(int team);
|
2015-12-05 22:40:30 +03:00
|
|
|
CBasePlayer *UTIL_GetClosestPlayer(const Vector *pos, float *distance = NULL);
|
2016-01-19 14:54:31 +03:00
|
|
|
CBasePlayer *UTIL_GetClosestPlayer(const Vector *pos, int team, float *distance = NULL);
|
2015-08-02 20:45:57 +03:00
|
|
|
const char *UTIL_GetBotPrefix();
|
|
|
|
void UTIL_ConstructBotNetName(char *name, int nameLength, const BotProfile *profile);
|
2016-01-19 14:54:31 +03:00
|
|
|
bool UTIL_IsVisibleToTeam(const Vector &spot, int team, float maxRange = -1.0f);
|
2016-02-04 03:18:26 +03:00
|
|
|
CBasePlayer *UTIL_GetLocalPlayer();
|
2016-02-23 02:13:52 +03:00
|
|
|
Vector UTIL_ComputeOrigin(entvars_t *pevVars);
|
|
|
|
Vector UTIL_ComputeOrigin(CBaseEntity *pEntity);
|
|
|
|
Vector UTIL_ComputeOrigin(edict_t *pentEdict);
|
|
|
|
void UTIL_DrawBeamFromEnt(int iIndex, Vector vecEnd, int iLifetime, byte bRed, byte bGreen, byte bBlue);
|
2016-01-19 14:54:31 +03:00
|
|
|
void UTIL_DrawBeamPoints(Vector vecStart, Vector vecEnd, int iLifetime, byte bRed, byte bGreen, byte bBlue);
|
|
|
|
|
|
|
|
// Echos text to the console, and prints it on the client's screen. This is NOT tied to the developer cvar.
|
|
|
|
// If you are adding debugging output in cstrike, use UTIL_DPrintf() (debug.h) instead.
|
2016-03-13 16:11:22 +03:00
|
|
|
void CONSOLE_ECHO(const char *pszMsg, ...);
|
|
|
|
void CONSOLE_ECHO_LOGGED(const char *pszMsg, ...);
|
2016-01-19 14:54:31 +03:00
|
|
|
|
2016-02-04 03:18:26 +03:00
|
|
|
void BotPrecache();
|
|
|
|
void InitBotTrig();
|
2015-06-30 12:46:07 +03:00
|
|
|
float BotCOS(float angle);
|
|
|
|
float BotSIN(float angle);
|
2015-12-05 22:40:30 +03:00
|
|
|
bool IsGameEventAudible(enum GameEventType event, CBaseEntity *entity, CBaseEntity *other, float *range, PriorityType *priority, bool *isHostile);
|
2016-01-19 14:54:31 +03:00
|
|
|
void HintMessageToAllPlayers(const char *message);
|
2015-06-30 12:46:07 +03:00
|
|
|
|
|
|
|
#endif // BOT_UTIL_H
|