diff --git a/src/client/entry.c b/src/client/entry.c index 08053ed9..10db3c53 100644 --- a/src/client/entry.c +++ b/src/client/entry.c @@ -104,6 +104,7 @@ CSQC_Init(float apilevel, string enginename, float engineversion) Client_Init(apilevel, enginename, engineversion); DSP_Init(); CSQC_RendererRestarted("init"); + Titles_Init(); } void @@ -729,18 +730,15 @@ CSQC_Ent_ParseMapEntity(void) switch (strField) { case "classname": - print(strcat("[CSQC] Spawnfunc search for ", strValue)); eEnt = (CBaseEntity)spawn(); if (isfunction(strcat("spawnfunc_", strValue))) { self = eEnt; callfunction(strcat("spawnfunc_", strValue)); self = eOld; iClass = TRUE; - print(" [^2FOUND^7]"); } else { eEnt.classname = strValue; } - print("\n"); break; default: __fullspawndata = sprintf("%s\"%s\" \"%s\" ", diff --git a/src/defs.h b/src/defs.h index f1f13e73..6e6524ef 100644 --- a/src/defs.h +++ b/src/defs.h @@ -70,3 +70,11 @@ const vector VEC_PLAYER_CVIEWPOS = [0,0,12]; .float jumptime; .float teleport_time; + +void* memrealloc( __variant *oldptr, int elementsize, int oldelements, int newelements ) +{ + void *n = memalloc( elementsize * newelements ); + memcpy( n, oldptr, elementsize * min( oldelements, newelements ) ); + memfree( oldptr ); + return n; +} diff --git a/src/gs-entbase/client/text.cpp b/src/gs-entbase/client/text.cpp index b4991df1..1896b5a1 100644 --- a/src/gs-entbase/client/text.cpp +++ b/src/gs-entbase/client/text.cpp @@ -106,23 +106,60 @@ void GameText_Parse(void) g_textchannels[chan].m_flTime = 0.0f; } +typedef struct titles_s +{ + string m_strName; + string m_strMessage; + float m_flPosX; + float m_flPosY; + int m_iEffect; + vector m_vecColor1; + vector m_vecColor2; + float m_flFadeIn; + float m_flFadeOut; + float m_flHoldTime; + float m_flFXTime; +} titles_t; +static titles_t *g_titles; +static int g_titles_count; + void GameMessage_Parse(void) { string strSound; float flVolume; int iAttenuation; + string findme; + int findid = -1; - /* TODO: Fill in the other string data from titles.txt */ - g_textchannels[0].m_strMessage = readstring(); - g_textchannels[0].m_flTime = 0.0f; + findme = readstring(); - g_textchannels[0].m_flPosX = -1; - g_textchannels[0].m_flPosY = 0.75f; - g_textchannels[0].m_flFadeIn = 0.5f; - g_textchannels[0].m_flFadeOut = 0.5f; - g_textchannels[0].m_flHoldTime = 4.0f; - g_textchannels[0].m_vecColor1 = [1,1,1]; - g_textchannels[0].m_vecColor2 = [1,1,1]; + for (int i = 0; i < g_titles_count; i++) { + if (g_titles[i].m_strName == findme) { + findid = i; + } + } + + if (findid < 0) { + g_textchannels[0].m_strMessage = findme; + g_textchannels[0].m_flTime = 0.0f; + g_textchannels[0].m_flPosX = -1; + g_textchannels[0].m_flPosY = 0.75f; + g_textchannels[0].m_flFadeIn = 0.5f; + g_textchannels[0].m_flFadeOut = 0.5f; + g_textchannels[0].m_flHoldTime = 4.0f; + g_textchannels[0].m_vecColor1 = [1,1,1]; + g_textchannels[0].m_vecColor2 = [1,1,1]; + } else { + g_textchannels[0].m_strMessage = g_titles[findid].m_strMessage; + g_textchannels[0].m_flTime = 0.0f; + g_textchannels[0].m_flPosX = g_titles[findid].m_flPosX; + g_textchannels[0].m_flPosY = g_titles[findid].m_flPosY; + g_textchannels[0].m_flFadeIn = g_titles[findid].m_flFadeIn; + g_textchannels[0].m_flFadeOut = g_titles[findid].m_flFadeOut; + g_textchannels[0].m_flHoldTime = g_titles[findid].m_flHoldTime; + g_textchannels[0].m_vecColor1 = g_titles[findid].m_vecColor1; + g_textchannels[0].m_vecColor2 = g_titles[findid].m_vecColor2; + } strSound = readstring(); flVolume = readfloat(); @@ -130,3 +167,107 @@ void GameMessage_Parse(void) sound(self, CHAN_ITEM, strSound, flVolume, iAttenuation); } + +void Titles_Init(void) +{ + float t_position[2]; + int t_effect; + vector t_color; + vector t_color2; + float t_fxtime; + float t_holdtime; + float t_fadein; + float t_fadeout; + string t_name = ""; + string t_message = ""; + + filestream fs_titles; + string temp; + int c; + int braced; + + fs_titles = fopen("titles.txt", FILE_READ); + + if (fs_titles < 0) { + print("^1WARNING: ^7Could NOT load titles.lst"); + return; + } + + if (fs_titles >= 0) { + while ((temp = fgets(fs_titles))) { + c = tokenize_console(temp); + if (c < 1) { + continue; + } + switch(argv(0)) { + case "$position": + t_position[0] = stof(argv(1)); + t_position[1] = stof(argv(2)); + break; + case "$effect": + t_effect = stoi(argv(1)); + break; + case "$color": + if (c == 4) { + t_color[0] = stof(argv(1)) / 255; + t_color[1] = stof(argv(2)) / 255; + t_color[2] = stof(argv(3)) / 255; + } else { + t_color = stov(argv(1)); + } + break; + case "$color2": + if (c == 4) { + t_color2[0] = stof(argv(1)) / 255; + t_color2[1] = stof(argv(2)) / 255; + t_color2[2] = stof(argv(3)) / 255; + } else { + t_color2 = stov(argv(1)); + } + break; + case "$fxtime": + t_fxtime = stof(argv(1)); + break; + case "$holdtime": + t_holdtime = stof(argv(1)); + break; + case "$fadein": + t_fadein = stof(argv(1)); + break; + case "$fadeout": + t_fadeout = stof(argv(1)); + break; + case "{": + braced = TRUE; + break; + case "}": + int id = g_titles_count - 1; + braced = FALSE; + + g_titles[id].m_strName = t_name; + g_titles[id].m_strMessage = t_message; + g_titles[id].m_flPosX = t_position[0]; + g_titles[id].m_flPosY = t_position[1]; + g_titles[id].m_iEffect = t_effect; + g_titles[id].m_vecColor1 = t_color; + g_titles[id].m_vecColor2 = t_color2; + g_titles[id].m_flFadeIn = t_fadein; + g_titles[id].m_flFadeOut = t_fadeout; + g_titles[id].m_flHoldTime = t_holdtime; + g_titles[id].m_flFXTime = t_fxtime; + + t_message = ""; + t_name = ""; + break; + default: + if (braced) { + t_message = sprintf("%s%s\n", t_message, temp); + } else { + t_name = argv(0); + g_titles = memrealloc(g_titles, sizeof(titles_t), g_titles_count, ++g_titles_count); + dprint(sprintf("[TITLES] Found %s\n", t_name)); + } + } + } + } +}