cleaning up the code. part 0.1

This commit is contained in:
jeefo 2016-08-27 23:37:27 +03:00
commit 0c8a246c48
7 changed files with 109 additions and 74 deletions

View file

@ -1481,7 +1481,6 @@ extern bool FindNearestPlayer (void **holder, edict_t *to, float searchDistance
extern void FreeLibraryMemory (void); extern void FreeLibraryMemory (void);
extern void RoundInit (void); extern void RoundInit (void);
extern void CheckWelcomeMessage (void);
extern void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...); extern void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...);
extern void DisplayMenuToClient (edict_t *ent, MenuText *menu); extern void DisplayMenuToClient (edict_t *ent, MenuText *menu);
extern void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex); extern void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex);

View file

@ -4018,3 +4018,9 @@ public:
// Squared Length // Squared Length
// //
#define GET_SQUARE(in) (in * in) #define GET_SQUARE(in) (in * in)
//
// Wrapper for singleton access
//
#define SA(obj) obj::GetReference ()

View file

@ -17,7 +17,6 @@ extern bool g_waypointOn;
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_isCommencing;
extern float g_autoPathDistance; extern float g_autoPathDistance;
extern float g_timeBombPlanted; extern float g_timeBombPlanted;
@ -74,3 +73,35 @@ static inline bool IsNullString (const char *input)
return *input == '\0'; return *input == '\0';
} }
//
// simple class to handle welcome messages
//
class WelcomeMessage : public Singleton <WelcomeMessage>
{
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;
}
}

View file

@ -947,8 +947,8 @@ void Engine::ProcessMessageCapture (void *ptr)
{ {
g_roundEnded = true; g_roundEnded = true;
if (FStrEq (strVal, "#Game_Commencing")) if (strcmp (strVal, "#Game_Commencing") == 0)
g_isCommencing = true; SA (WelcomeMessage).SetGameCommenceFlag (true);
if (FStrEq (strVal, "#CTs_Win")) if (FStrEq (strVal, "#CTs_Win"))
{ {

View file

@ -439,3 +439,68 @@ MenuText g_menus[21] =
"0. Exit" "0. Exit"
} }
}; };
void WelcomeMessage::VerifyMessageSent (void)
{
if (m_msgReceived)
return;
static Array <String> 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 <char *> (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;
}
}

View file

@ -2183,7 +2183,7 @@ void StartFrame (void)
if (g_waypointOn) if (g_waypointOn)
waypoints.Think (); waypoints.Think ();
CheckWelcomeMessage (); SA (WelcomeMessage).VerifyMessageSent ();
} }
bots.SetDeathMsgState (false); bots.SetDeathMsgState (false);
@ -2317,6 +2317,9 @@ void pfnChangeLevel (char *s1, char *s2)
waypoints.SaveExperienceTab (); waypoints.SaveExperienceTab ();
waypoints.SaveVisibilityTab (); waypoints.SaveVisibilityTab ();
// reset welcome message strate
SA (WelcomeMessage).SetGameCommenceFlag (false);
if (g_gameFlags & GAME_METAMOD) if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);

View file

@ -501,75 +501,6 @@ bool OpenConfig (const char *fileName, const char *errorIfNotExists, MemoryFile
return true; 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 <String> 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 <char *> (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, ...) void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...)
{ {