diff --git a/include/core.h b/include/core.h index 4df35bd..c475c13 100644 --- a/include/core.h +++ b/include/core.h @@ -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 +#include // 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); diff --git a/include/corelib.h b/include/corelib.h index 36be456..a206db4 100644 --- a/include/corelib.h +++ b/include/corelib.h @@ -1,4 +1,4 @@ -// +// // Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd"). // Copyright (c) YaPB Development Team. // diff --git a/include/gamestate.h b/include/gamestate.h new file mode 100644 index 0000000..f576c96 --- /dev/null +++ b/include/gamestate.h @@ -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 () \ No newline at end of file diff --git a/project/yapb.vcxproj b/project/yapb.vcxproj index ec0f6d4..01f8564 100644 --- a/project/yapb.vcxproj +++ b/project/yapb.vcxproj @@ -27,6 +27,7 @@ + @@ -35,6 +36,7 @@ + diff --git a/project/yapb.vcxproj.filters b/project/yapb.vcxproj.filters index 4d9fb0d..7ac61fb 100644 --- a/project/yapb.vcxproj.filters +++ b/project/yapb.vcxproj.filters @@ -72,6 +72,9 @@ include + + include + @@ -107,6 +110,9 @@ source + + source + diff --git a/source/basecode.cpp b/source/basecode.cpp index c823771..265790f 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -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,42 +2612,39 @@ 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 (GetTeam (m_radioEntity) == CT && m_team == CT && IsValidBot (m_radioEntity) && g_timeNextBombUpdate < engine.Time ()) { - if (g_timeNextBombUpdate < engine.Time ()) + float minDistance = 99999.0f; + + // find nearest bomb waypoint to player + FOR_EACH_AE (waypoints.m_goalPoints, i) { - float minDistance = 99999.0f; + distance = (waypoints.GetPath (waypoints.m_goalPoints[i])->origin - m_radioEntity->v.origin).GetLengthSquared (); - // find nearest bomb waypoint to player - FOR_EACH_AE (waypoints.m_goalPoints, i) + if (distance < minDistance) { - distance = (waypoints.GetPath (waypoints.m_goalPoints[i])->origin - m_radioEntity->v.origin).GetLengthSquared (); - - if (distance < minDistance) - { - minDistance = distance; - bombPoint = waypoints.m_goalPoints[i]; - } + minDistance = distance; + bombPoint = waypoints.m_goalPoints[i]; } - - // mark this waypoint as restricted point - if (bombPoint != -1 && !waypoints.IsGoalVisited (bombPoint)) - { - // does this bot want to defuse? - if (GetTaskId () == TASK_NORMAL) - { - // is he approaching this goal? - if (GetTask ()->data == bombPoint) - { - GetTask ()->data = -1; - RadioMessage (Radio_Affirmative); - - } - } - waypoints.SetGoalVisited (bombPoint); - } - g_timeNextBombUpdate = engine.Time () + 0.5f; } + + // mark this waypoint as restricted point + if (bombPoint != -1 && !waypoints.IsGoalVisited (bombPoint)) + { + // does this bot want to defuse? + if (GetTaskId () == TASK_NORMAL) + { + // is he approaching this goal? + if (GetTask ()->data == bombPoint) + { + GetTask ()->data = -1; + RadioMessage (Radio_Affirmative); + + } + } + waypoints.SetGoalVisited (bombPoint); + } + g_timeNextBombUpdate = engine.Time () + 0.5f; } } break; @@ -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) diff --git a/source/engine.cpp b/source/engine.cpp index 88e2c7d..ed7cf6f 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -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 (variable); - newVariable.reg.string = const_cast (value); + pair.reg.name = const_cast (variable); + pair.reg.string = const_cast (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) diff --git a/source/gamestate.cpp b/source/gamestate.cpp new file mode 100644 index 0000000..c49297d --- /dev/null +++ b/source/gamestate.cpp @@ -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 \ No newline at end of file diff --git a/source/globals.cpp b/source/globals.cpp index 5536c4a..43efdc2 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -15,6 +15,7 @@ Localizer locale; Waypoint waypoints; BotManager bots; Engine engine; +Game game; bool g_canSayBombPlanted = true; bool g_isMetamod = false; diff --git a/source/interface.cpp b/source/interface.cpp index 8df7b07..dbe3ffa 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -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); diff --git a/source/manager.cpp b/source/manager.cpp index 0ddba32..95ec618 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -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 (player->v.frags)); - } + if (bot != NULL) + 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 (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++) diff --git a/source/waypoint.cpp b/source/waypoint.cpp index 27fe762..6298abe 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -1,4 +1,4 @@ -// +// // Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd"). // Copyright (c) YaPB Development Team. //