From 0c8a246c48477c478ed4b063bb8a9d72effc335c Mon Sep 17 00:00:00 2001 From: jeefo Date: Sat, 27 Aug 2016 23:37:27 +0300 Subject: [PATCH] cleaning up the code. part 0.1 --- include/core.h | 1 - include/corelib.h | 6 ++++ include/globals.h | 33 ++++++++++++++++++++- source/engine.cpp | 4 +-- source/globals.cpp | 65 +++++++++++++++++++++++++++++++++++++++++ source/interface.cpp | 5 +++- source/support.cpp | 69 -------------------------------------------- 7 files changed, 109 insertions(+), 74 deletions(-) diff --git a/include/core.h b/include/core.h index bd6bc72..dd51ab2 100644 --- a/include/core.h +++ b/include/core.h @@ -1481,7 +1481,6 @@ extern bool FindNearestPlayer (void **holder, edict_t *to, float searchDistance extern void FreeLibraryMemory (void); extern void RoundInit (void); -extern void CheckWelcomeMessage (void); extern void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...); extern void DisplayMenuToClient (edict_t *ent, MenuText *menu); extern void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex); diff --git a/include/corelib.h b/include/corelib.h index d623331..1c7a30a 100644 --- a/include/corelib.h +++ b/include/corelib.h @@ -4018,3 +4018,9 @@ public: // Squared Length // #define GET_SQUARE(in) (in * in) + + +// +// Wrapper for singleton access +// +#define SA(obj) obj::GetReference () \ No newline at end of file diff --git a/include/globals.h b/include/globals.h index 38cdef3..c2f3826 100644 --- a/include/globals.h +++ b/include/globals.h @@ -17,7 +17,6 @@ extern bool g_waypointOn; extern bool g_autoWaypoint; extern bool g_botsCanPause; extern bool g_editNoclip; -extern bool g_isCommencing; extern float g_autoPathDistance; extern float g_timeBombPlanted; @@ -74,3 +73,35 @@ static inline bool IsNullString (const char *input) return *input == '\0'; } + +// +// simple class to handle welcome messages +// +class WelcomeMessage : public Singleton +{ +private: + bool m_gameCommenced; + bool m_msgReceived; + + float m_receiveTimer; + +public: + WelcomeMessage (void) : m_gameCommenced (false), m_msgReceived (false), m_receiveTimer (0.0f) { } + +public: + void SetGameCommenceFlag (bool isCommenced); + void VerifyMessageSent (void); +}; +]=. + + +inline void WelcomeMessage::SetGameCommenceFlag (bool isCommenced) +{ + m_gameCommenced = isCommenced; + + if (!isCommenced) + { + m_receiveTimer = 0.0f; + m_msgReceived = false; + } +} \ No newline at end of file diff --git a/source/engine.cpp b/source/engine.cpp index 38ec4cc..6b5293d 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -947,8 +947,8 @@ void Engine::ProcessMessageCapture (void *ptr) { g_roundEnded = true; - if (FStrEq (strVal, "#Game_Commencing")) - g_isCommencing = true; + if (strcmp (strVal, "#Game_Commencing") == 0) + SA (WelcomeMessage).SetGameCommenceFlag (true); if (FStrEq (strVal, "#CTs_Win")) { diff --git a/source/globals.cpp b/source/globals.cpp index 1e0441e..ba4dc0b 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -439,3 +439,68 @@ MenuText g_menus[21] = "0. Exit" } }; + + +void WelcomeMessage::VerifyMessageSent (void) +{ + if (m_msgReceived) + return; + + static Array sentences; + + if (!(g_gameFlags & (GAME_MOBILITY | GAME_XASH)) && sentences.IsEmpty ()) + { + // add default messages + sentences.Push ("hello user,communication is acquired"); + sentences.Push ("your presence is acknowledged"); + sentences.Push ("high man, your in command now"); + sentences.Push ("blast your hostile for good"); + sentences.Push ("high man, kill some idiot here"); + sentences.Push ("is there a doctor in the area"); + sentences.Push ("warning, experimental materials detected"); + sentences.Push ("high amigo, shoot some but"); + sentences.Push ("attention, hours of work software, detected"); + sentences.Push ("time for some bad ass explosion"); + sentences.Push ("bad ass son of a breach device activated"); + sentences.Push ("high, do not question this great service"); + sentences.Push ("engine is operative, hello and goodbye"); + sentences.Push ("high amigo, your administration has been great last day"); + sentences.Push ("attention, expect experimental armed hostile presence"); + sentences.Push ("warning, medical attention required"); + } + + if (IsAlive (g_hostEntity) && !m_msgReceived && m_receiveTimer < 1.0f && (g_numWaypoints > 0 ? m_gameCommenced : true)) + m_receiveTimer = engine.Time () + 4.0f; // receive welcome message in four seconds after game has commencing + + if (m_receiveTimer > 0.0f && m_receiveTimer < engine.Time () && !m_msgReceived && (g_numWaypoints > 0 ? m_gameCommenced : true)) + { + if (!(g_gameFlags & (GAME_MOBILITY | GAME_XASH))) + engine.IssueCmd ("speak \"%s\"", const_cast (sentences.GetRandomElement ().GetBuffer ())); + + engine.ChatPrintf ("----- %s v%s (Build: %u), {%s}, (c) 2016, by %s (%s)-----", PRODUCT_NAME, PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_DATE, PRODUCT_AUTHOR, PRODUCT_URL); + + MESSAGE_BEGIN (MSG_ONE, SVC_TEMPENTITY, NULL, g_hostEntity); + WRITE_BYTE (TE_TEXTMESSAGE); + WRITE_BYTE (1); + WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); + WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); + WRITE_BYTE (2); + WRITE_BYTE (Random.Long (33, 255)); + WRITE_BYTE (Random.Long (33, 255)); + WRITE_BYTE (Random.Long (33, 255)); + WRITE_BYTE (0); + WRITE_BYTE (Random.Long (230, 255)); + WRITE_BYTE (Random.Long (230, 255)); + WRITE_BYTE (Random.Long (230, 255)); + WRITE_BYTE (200); + WRITE_SHORT (FixedUnsigned16 (0.0078125f, 1 << 8)); + WRITE_SHORT (FixedUnsigned16 (2.0f, 1 << 8)); + WRITE_SHORT (FixedUnsigned16 (6.0f, 1 << 8)); + WRITE_SHORT (FixedUnsigned16 (0.1f, 1 << 8)); + WRITE_STRING (FormatBuffer ("\nServer is running YaPB v%s (Build: %u)\nDeveloped by %s\n\n%s", PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_AUTHOR, waypoints.GetInfo ())); + MESSAGE_END (); + + m_receiveTimer = 0.0; + m_msgReceived = true; + } +} diff --git a/source/interface.cpp b/source/interface.cpp index 8cdb76b..8f28dc5 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -2183,7 +2183,7 @@ void StartFrame (void) if (g_waypointOn) waypoints.Think (); - CheckWelcomeMessage (); + SA (WelcomeMessage).VerifyMessageSent (); } bots.SetDeathMsgState (false); @@ -2317,6 +2317,9 @@ void pfnChangeLevel (char *s1, char *s2) waypoints.SaveExperienceTab (); waypoints.SaveVisibilityTab (); + // reset welcome message strate + SA (WelcomeMessage).SetGameCommenceFlag (false); + if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_IGNORED); diff --git a/source/support.cpp b/source/support.cpp index fe1e691..42d228f 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -501,75 +501,6 @@ bool OpenConfig (const char *fileName, const char *errorIfNotExists, MemoryFile return true; } -void CheckWelcomeMessage (void) -{ - // the purpose of this function, is to send quick welcome message, to the listenserver entity. - - static bool alreadyReceived = false; - static float receiveTime = 0.0f; - - if (alreadyReceived) - return; - - Array sentences; - - if (!(g_gameFlags & (GAME_MOBILITY | GAME_XASH))) - { - // add default messages - sentences.Push ("hello user,communication is acquired"); - sentences.Push ("your presence is acknowledged"); - sentences.Push ("high man, your in command now"); - sentences.Push ("blast your hostile for good"); - sentences.Push ("high man, kill some idiot here"); - sentences.Push ("is there a doctor in the area"); - sentences.Push ("warning, experimental materials detected"); - sentences.Push ("high amigo, shoot some but"); - sentences.Push ("attention, hours of work software, detected"); - sentences.Push ("time for some bad ass explosion"); - sentences.Push ("bad ass son of a breach device activated"); - sentences.Push ("high, do not question this great service"); - sentences.Push ("engine is operative, hello and goodbye"); - sentences.Push ("high amigo, your administration has been great last day"); - sentences.Push ("attention, expect experimental armed hostile presence"); - sentences.Push ("warning, medical attention required"); - } - - if (IsAlive (g_hostEntity) && !alreadyReceived && receiveTime < 1.0 && (g_numWaypoints > 0 ? g_isCommencing : true)) - receiveTime = engine.Time () + 4.0f; // receive welcome message in four seconds after game has commencing - - if (receiveTime > 0.0f && receiveTime < engine.Time () && !alreadyReceived && (g_numWaypoints > 0 ? g_isCommencing : true)) - { - if (!(g_gameFlags & (GAME_MOBILITY | GAME_XASH))) - engine.IssueCmd ("speak \"%s\"", const_cast (sentences.GetRandomElement ().GetBuffer ())); - - engine.ChatPrintf ("----- %s v%s (Build: %u), {%s}, (c) 2016, by %s (%s)-----", PRODUCT_NAME, PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_DATE, PRODUCT_AUTHOR, PRODUCT_URL); - - MESSAGE_BEGIN (MSG_ONE, SVC_TEMPENTITY, NULL, g_hostEntity); - WRITE_BYTE (TE_TEXTMESSAGE); - WRITE_BYTE (1); - WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); - WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); - WRITE_BYTE (2); - WRITE_BYTE (Random.Long (33, 255)); - WRITE_BYTE (Random.Long (33, 255)); - WRITE_BYTE (Random.Long (33, 255)); - WRITE_BYTE (0); - WRITE_BYTE (Random.Long (230, 255)); - WRITE_BYTE (Random.Long (230, 255)); - WRITE_BYTE (Random.Long (230, 255)); - WRITE_BYTE (200); - WRITE_SHORT (FixedUnsigned16 (0.0078125f, 1 << 8)); - WRITE_SHORT (FixedUnsigned16 (2.0f, 1 << 8)); - WRITE_SHORT (FixedUnsigned16 (6.0f, 1 << 8)); - WRITE_SHORT (FixedUnsigned16 (0.1f, 1 << 8)); - WRITE_STRING (FormatBuffer ("\nServer is running YaPB v%s (Build: %u)\nDeveloped by %s\n\n%s", PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_AUTHOR, waypoints.GetInfo ())); - MESSAGE_END (); - - receiveTime = 0.0; - alreadyReceived = true; - } -} - void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...) {