some code cleanup
started to move game-specific stuff into own class
This commit is contained in:
parent
e4b4e92e10
commit
fa64fe2ea7
12 changed files with 131 additions and 85 deletions
|
|
@ -1062,6 +1062,7 @@ public:
|
|||
float m_spawnTime; // time this bot spawned
|
||||
float m_timeTeamOrder; // time of last radio command
|
||||
float m_timePeriodicUpdate; // time to per-second think
|
||||
float m_timeRepotingInDelay; // time to delay report-in
|
||||
|
||||
bool m_isVIP; // bot is vip?
|
||||
|
||||
|
|
@ -1502,6 +1503,7 @@ public:
|
|||
};
|
||||
|
||||
#include <engine.h>
|
||||
#include <gamestate.h>
|
||||
|
||||
// expose bot super-globals
|
||||
extern NetworkMsg netmsg;
|
||||
|
|
@ -1509,6 +1511,7 @@ extern Localizer locale;
|
|||
extern Waypoint waypoints;
|
||||
extern BotManager bots;
|
||||
extern Engine engine;
|
||||
extern Game game;
|
||||
|
||||
// prototypes of bot functions...
|
||||
extern int GetWeaponReturn (bool isString, const char *weaponAlias, int weaponIndex = -1);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
|
||||
// Copyright (c) YaPB Development Team.
|
||||
//
|
||||
|
|
|
|||
42
include/gamestate.h
Normal file
42
include/gamestate.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// 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
|
||||
//
|
||||
// Purpose: Represents Counter-Strike Game.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
class IGameEvents
|
||||
{
|
||||
public:
|
||||
|
||||
// called when new round occurs
|
||||
virtual void OnNewRound (void) = 0;
|
||||
};
|
||||
|
||||
class Game
|
||||
{
|
||||
private:
|
||||
IGameEvents *m_listener;
|
||||
|
||||
public:
|
||||
Game (void) : m_listener (NULL) { }
|
||||
~Game (void) { }
|
||||
|
||||
public:
|
||||
|
||||
// we have only one listener, so register it here
|
||||
void RegisterEventListener (IGameEvents *listener) { m_listener = listener; }
|
||||
|
||||
// get events interface
|
||||
IGameEvents *GetGameEventListener (void) { return m_listener; }
|
||||
};
|
||||
|
||||
// helper macros
|
||||
#define events game.GetGameEventListener ()
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
<ClInclude Include="..\include\engine\progdefs.h" />
|
||||
<ClInclude Include="..\include\engine\sdk_util.h" />
|
||||
<ClInclude Include="..\include\engine\util.h" />
|
||||
<ClInclude Include="..\include\gamestate.h" />
|
||||
<ClInclude Include="..\include\globals.h" />
|
||||
<ClInclude Include="..\include\platform.h" />
|
||||
<ClInclude Include="..\include\resource.h" />
|
||||
|
|
@ -35,6 +36,7 @@
|
|||
<ClCompile Include="..\source\basecode.cpp" />
|
||||
<ClCompile Include="..\source\combat.cpp" />
|
||||
<ClCompile Include="..\source\engine.cpp" />
|
||||
<ClCompile Include="..\source\gamestate.cpp" />
|
||||
<ClCompile Include="..\source\manager.cpp" />
|
||||
<ClCompile Include="..\source\chatlib.cpp" />
|
||||
<ClCompile Include="..\source\globals.cpp" />
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@
|
|||
<ClInclude Include="..\include\engine.h">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\gamestate.h">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\source\chatlib.cpp">
|
||||
|
|
@ -107,6 +110,9 @@
|
|||
<ClCompile Include="..\source\engine.cpp">
|
||||
<Filter>source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\gamestate.cpp">
|
||||
<Filter>source</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="yapb.rc">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
|
||||
// Copyright (c) YaPB Development Team.
|
||||
//
|
||||
|
|
@ -988,15 +988,13 @@ void Bot::InstantChatterMessage (int type)
|
|||
if (m_notKilled)
|
||||
SwitchChatterIcon (true);
|
||||
|
||||
static float reportTime = engine.Time ();
|
||||
|
||||
// delay only reportteam
|
||||
if (type == Radio_ReportTeam)
|
||||
if (type == Radio_ReportTeam && m_timeRepotingInDelay < engine.Time ())
|
||||
{
|
||||
if (reportTime >= engine.Time ())
|
||||
if (m_timeRepotingInDelay < engine.Time ())
|
||||
return;
|
||||
|
||||
reportTime = engine.Time () + Random.Float (30.0f, 80.0f);
|
||||
m_timeRepotingInDelay = engine.Time () + Random.Float (30.0f, 60.0f);
|
||||
}
|
||||
|
||||
String defaultSound = g_chatterFactory[type].GetRandomElement ().name;
|
||||
|
|
@ -1720,18 +1718,6 @@ void Bot::PurchaseWeapons (void)
|
|||
PushMessageQueue (GSM_BUY_STUFF);
|
||||
}
|
||||
|
||||
TaskItem *ClampDesire (TaskItem *first, float min, float max)
|
||||
{
|
||||
// this function iven some values min and max, clamp the inputs to be inside the [min, max] range.
|
||||
|
||||
if (first->desire < min)
|
||||
first->desire = min;
|
||||
else if (first->desire > max)
|
||||
first->desire = max;
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
TaskItem *MaxDesire (TaskItem *first, TaskItem *second)
|
||||
{
|
||||
// this function returns the behavior having the higher activation level.
|
||||
|
|
@ -2626,9 +2612,7 @@ void Bot::CheckRadioCommands (void)
|
|||
int bombPoint = -1;
|
||||
|
||||
// check if it's a ct command
|
||||
if (GetTeam (m_radioEntity) == CT && m_team == CT && IsValidBot (m_radioEntity))
|
||||
{
|
||||
if (g_timeNextBombUpdate < engine.Time ())
|
||||
if (GetTeam (m_radioEntity) == CT && m_team == CT && IsValidBot (m_radioEntity) && g_timeNextBombUpdate < engine.Time ())
|
||||
{
|
||||
float minDistance = 99999.0f;
|
||||
|
||||
|
|
@ -2663,7 +2647,6 @@ void Bot::CheckRadioCommands (void)
|
|||
g_timeNextBombUpdate = engine.Time () + 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Radio_GetInPosition:
|
||||
|
|
@ -3223,11 +3206,9 @@ void Bot::RunTask_Normal (void)
|
|||
if (m_personality == PERSONALITY_RUSHER)
|
||||
campTime *= 0.5f;
|
||||
|
||||
PushTask (TASK_CAMP, TASKPRI_CAMP, -1, engine.Time () + Random.Float (25.0, 40.0), true); // push camp task on to stack
|
||||
PushTask (TASK_CAMP, TASKPRI_CAMP, -1, engine.Time () + campTime, true); // push camp task on to stack
|
||||
PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, engine.Time () + Random.Float (5.0f, 11.0f), true); // push move command
|
||||
|
||||
DebugMsg ("i'm ct and going to defend bomb!");
|
||||
|
||||
if (waypoints.GetPath (index)->vis.crouch <= waypoints.GetPath (index)->vis.stand)
|
||||
m_campButtons |= IN_DUCK;
|
||||
else
|
||||
|
|
@ -4274,7 +4255,7 @@ void Bot::RunTask_Throw_SG (void)
|
|||
|
||||
void Bot::RunTask_DoubleJump (void)
|
||||
{
|
||||
if (IsNullEntity (m_doubleJumpEntity) || !IsAlive (m_doubleJumpEntity) || (m_aimFlags & AIM_ENEMY) || (m_travelStartIndex != -1 && GetTask ()->time + (waypoints.GetTravelTime (pev->maxspeed, waypoints.GetPath (m_travelStartIndex)->origin, m_doubleJumpOrigin) + 11.0) < engine.Time ()))
|
||||
if (!IsAlive (m_doubleJumpEntity) || (m_aimFlags & AIM_ENEMY) || (m_travelStartIndex != -1 && GetTask ()->time + (waypoints.GetTravelTime (pev->maxspeed, waypoints.GetPath (m_travelStartIndex)->origin, m_doubleJumpOrigin) + 11.0) < engine.Time ()))
|
||||
{
|
||||
ResetDoubleJumpState ();
|
||||
return;
|
||||
|
|
@ -4453,8 +4434,6 @@ void Bot::RunTask_PickupItem ()
|
|||
// find the distance to the item
|
||||
float itemDistance = (dest - pev->origin).GetLength ();
|
||||
|
||||
int id = 0;
|
||||
|
||||
switch (m_pickupType)
|
||||
{
|
||||
case PICKUP_DROPPED_C4:
|
||||
|
|
@ -4467,6 +4446,8 @@ void Bot::RunTask_PickupItem ()
|
|||
// near to weapon?
|
||||
if (itemDistance < 50.0f)
|
||||
{
|
||||
int id = 0;
|
||||
|
||||
for (id = 0; id < 7; id++)
|
||||
{
|
||||
if (strcmp (g_weaponSelect[id].modelName, STRING (m_pickupItem->v.model) + 9) == 0)
|
||||
|
|
@ -4805,8 +4786,7 @@ void Bot::BotAI (void)
|
|||
{
|
||||
// this function gets called each frame and is the core of all bot ai. from here all other subroutines are called
|
||||
|
||||
float movedDistance; // length of different vector (distance bot moved)
|
||||
TraceResult tr;
|
||||
float movedDistance = 2.0f; // length of different vector (distance bot moved)
|
||||
|
||||
// increase reaction time
|
||||
m_actualReactionTime += 0.3f;
|
||||
|
|
@ -4834,8 +4814,6 @@ void Bot::BotAI (void)
|
|||
m_prevOrigin = pev->origin;
|
||||
m_prevTime = engine.Time () + 0.2f;
|
||||
}
|
||||
else
|
||||
movedDistance = 2.0f;
|
||||
|
||||
// if there's some radio message to respond, check it
|
||||
if (m_radioOrder != 0)
|
||||
|
|
|
|||
|
|
@ -445,11 +445,11 @@ void ConVarWrapper::RegisterVariable (const char *variable, const char *value, V
|
|||
{
|
||||
// this function adds globally defined variable to registration stack
|
||||
|
||||
VarPair newVariable;
|
||||
memset (&newVariable, 0, sizeof (VarPair));
|
||||
VarPair pair;
|
||||
memset (&pair, 0, sizeof (VarPair));
|
||||
|
||||
newVariable.reg.name = const_cast <char *> (variable);
|
||||
newVariable.reg.string = const_cast <char *> (value);
|
||||
pair.reg.name = const_cast <char *> (variable);
|
||||
pair.reg.string = const_cast <char *> (value);
|
||||
|
||||
int engineFlags = FCVAR_EXTDLL;
|
||||
|
||||
|
|
@ -460,11 +460,11 @@ void ConVarWrapper::RegisterVariable (const char *variable, const char *value, V
|
|||
else if (varType == VT_PASSWORD)
|
||||
engineFlags |= FCVAR_PROTECTED;
|
||||
|
||||
newVariable.reg.flags = engineFlags;
|
||||
newVariable.self = self;
|
||||
newVariable.type = varType;
|
||||
pair.reg.flags = engineFlags;
|
||||
pair.self = self;
|
||||
pair.type = varType;
|
||||
|
||||
m_regs.Push (newVariable);
|
||||
m_regs.Push (pair);
|
||||
}
|
||||
|
||||
void ConVarWrapper::PushRegisteredConVarsToEngine (bool gameVars)
|
||||
|
|
|
|||
10
source/gamestate.cpp
Normal file
10
source/gamestate.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
//
|
||||
// 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>
|
||||
|
|
@ -15,6 +15,7 @@ Localizer locale;
|
|||
Waypoint waypoints;
|
||||
BotManager bots;
|
||||
Engine engine;
|
||||
Game game;
|
||||
|
||||
bool g_canSayBombPlanted = true;
|
||||
bool g_isMetamod = false;
|
||||
|
|
|
|||
|
|
@ -457,6 +457,14 @@ void CommandHandler (void)
|
|||
engine.Printf ("Unknown command: %s", CMD_ARGV (1));
|
||||
}
|
||||
|
||||
class GameEvents : public IGameEvents
|
||||
{
|
||||
virtual void OnNewRound (void)
|
||||
{
|
||||
RoundInit ();
|
||||
}
|
||||
} g_botEventListener;
|
||||
|
||||
void ParseVoiceEvent (const String &base, int type, float timeToRepeat)
|
||||
{
|
||||
// this function does common work of parsing single line of voice chatter
|
||||
|
|
@ -918,6 +926,9 @@ void GameDLLInit (void)
|
|||
// 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.
|
||||
|
||||
// register bot event listner
|
||||
game.RegisterEventListener (&g_botEventListener);
|
||||
|
||||
DetectCSVersion ();
|
||||
{
|
||||
// print game detection info
|
||||
|
|
@ -1014,9 +1025,7 @@ int Spawn (edict_t *ent)
|
|||
PRECACHE_SOUND (ENGINE_STR ("common/wpn_moveselect.wav")); // path add/delete cancel
|
||||
PRECACHE_SOUND (ENGINE_STR ("common/wpn_denyselect.wav")); // path add/delete error
|
||||
|
||||
g_roundEnded = true;
|
||||
RoundInit ();
|
||||
|
||||
events->OnNewRound ();
|
||||
g_mapType = NULL; // 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
|
||||
|
|
@ -2335,7 +2344,7 @@ edict_t *pfnFindEntityByString (edict_t *edictStartSearchAfter, const char *fiel
|
|||
{
|
||||
// round starts in counter-strike 1.5
|
||||
if (strcmp (value, "info_map_parameters") == 0)
|
||||
RoundInit ();
|
||||
events->OnNewRound ();
|
||||
|
||||
if (g_isMetamod)
|
||||
RETURN_META_VALUE (MRES_IGNORED, 0);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
|
||||
// Copyright (c) YaPB Development Team.
|
||||
//
|
||||
|
|
@ -329,7 +329,7 @@ void BotManager::AddBot (const String &name, const String &difficulty, const Str
|
|||
|
||||
void BotManager::AdjustQuota (bool isPlayerConnection, edict_t *ent)
|
||||
{
|
||||
// this function increases or decreases bot quota amount depending on autovacate variables
|
||||
// this function increases or decreases bot quota amount depending on auto vacate variables
|
||||
|
||||
if (!engine.IsDedicatedServer () || !yb_autovacate.GetBool () || GetBot (ent) != NULL)
|
||||
return;
|
||||
|
|
@ -550,7 +550,6 @@ void BotManager::RemoveMenu (edict_t *ent, int selection)
|
|||
{
|
||||
// this function displays remove bot menu to specified entity (this function show's only yapb's).
|
||||
|
||||
|
||||
if (selection > 4 || selection < 1)
|
||||
return;
|
||||
|
||||
|
|
@ -740,16 +739,11 @@ void BotManager::ListBots (void)
|
|||
|
||||
for (int i = 0; i < engine.MaxClients (); i++)
|
||||
{
|
||||
edict_t *player = EntityOfIndex (i);
|
||||
Bot *bot = GetBot (i);
|
||||
|
||||
// is this player slot valid
|
||||
if (IsValidBot (player))
|
||||
{
|
||||
Bot *bot = GetBot (player);
|
||||
|
||||
if (bot != NULL)
|
||||
engine.Printf ("[%-3.1d] %-9.13s %-17.18s %-3.4s %-3.1d %-3.1d", i, STRING (player->v.netname), bot->m_personality == PERSONALITY_RUSHER ? "rusher" : bot->m_personality == PERSONALITY_NORMAL ? "normal" : "careful", GetTeam (player) != 0 ? "CT" : "T", bot->m_difficulty, static_cast <int> (player->v.frags));
|
||||
}
|
||||
engine.Printf ("[%-3.1d] %-9.13s %-17.18s %-3.4s %-3.1d %-3.1d", i, STRING (bot->pev->netname), bot->m_personality == PERSONALITY_RUSHER ? "rusher" : bot->m_personality == PERSONALITY_NORMAL ? "normal" : "careful", bot->m_team == CT ? "CT" : "T", bot->m_difficulty, static_cast <int> (bot->pev->frags));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -777,7 +771,7 @@ Bot *BotManager::GetHighestFragsBot (int team)
|
|||
{
|
||||
Bot *bot = bots.GetBot (i);
|
||||
|
||||
if (bot != NULL && IsAlive (bot->GetEntity ()) && GetTeam (bot->GetEntity ()) == team)
|
||||
if (bot != NULL && bot->m_notKilled && bot->m_team == team)
|
||||
{
|
||||
if (bot->pev->frags > bestScore)
|
||||
{
|
||||
|
|
@ -1101,6 +1095,7 @@ void Bot::NewRound (void)
|
|||
|
||||
m_maxThrowTimer = 0.0f;
|
||||
m_timeTeamOrder = 0.0f;
|
||||
m_timeRepotingInDelay = 0.0f;
|
||||
m_askCheckTime = 0.0f;
|
||||
m_minSpeed = 260.0f;
|
||||
m_prevSpeed = 0.0f;
|
||||
|
|
@ -1156,7 +1151,7 @@ void Bot::NewRound (void)
|
|||
SetIdealReactionTimes (true);
|
||||
|
||||
m_targetEntity = NULL;
|
||||
m_tasks = NULL;
|
||||
m_tasks.RemoveAll ();
|
||||
m_followWaitTime = 0.0f;
|
||||
|
||||
for (i = 0; i < MAX_HOSTAGES; i++)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
|
||||
// Copyright (c) YaPB Development Team.
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue