From a1e60b39fab4435e0c53f38a3a4cde6f5a830149 Mon Sep 17 00:00:00 2001 From: Joe <55846624+rtldg@users.noreply.github.com> Date: Mon, 30 Nov 2020 16:40:45 +0000 Subject: [PATCH] Multiple bonuses (#982) * cleanup GetTrackName() * a few more changes to change mod_zone_bonus & add Track_Bonus_Last * fix undefined symbol sTrack * fixup !bwr for multiple bonuses * fix GetTrackName() after I broke it * add bonus number param to help text of sm_bwr * fix !wr after I broke it adding !bwr [bonus number] * ignore checkpoint zones for now because nothing is ready for them * update points for bonus #2 through #8 at same time so instead of something like `9 (track count) * 22 (style count)` queries, it'll do `3 (main, bonus1, rest of bonuses) * 22 (style count)` queries and the rest of the bonuses on the recalc all in the same query --- addons/sourcemod/scripting/include/shavit.inc | 11 ++++ addons/sourcemod/scripting/shavit-core.sp | 48 +++++++++----- addons/sourcemod/scripting/shavit-hud.sp | 14 ---- addons/sourcemod/scripting/shavit-misc.sp | 22 ++----- addons/sourcemod/scripting/shavit-rankings.sp | 38 ++++------- addons/sourcemod/scripting/shavit-replay.sp | 16 +---- addons/sourcemod/scripting/shavit-stats.sp | 14 ---- addons/sourcemod/scripting/shavit-wr.sp | 66 +++++++++++-------- addons/sourcemod/scripting/shavit-zones.sp | 30 ++++----- .../translations/shavit-common.phrases.txt | 7 +- 10 files changed, 117 insertions(+), 149 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index e1a546fe..79f5c647 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -114,6 +114,7 @@ enum { Track_Main, Track_Bonus, + Track_Bonus_Last = 8, TRACKS_SIZE }; @@ -452,6 +453,16 @@ stock bool GuessBestMapName(ArrayList maps, const char[] input, char[] output, i return false; } +stock void GetTrackName(int client, int track, char[] output, int size) +{ + if (track == Track_Main) + FormatEx(output, size, "%T", "Track_Main", client, track); + else if (track >= Track_Bonus) + FormatEx(output, size, "%T", "Track_Bonus", client, track); + else //if (track < Track_Main) + FormatEx(output, size, "%T", "Track_Unknown", client); +} + /** * Called before shavit-core processes the client's usercmd. * Before this is called, safety checks (fake/dead clients) happen. diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index 6fc93bbd..5357c069 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -563,7 +563,21 @@ public Action Command_StartTimer(int client, int args) if(StrContains(sCommand, "sm_b", false) == 0) { - track = Track_Bonus; + if (args < 1) + { + track = Shavit_GetClientTrack(client); + } + else + { + char arg[6]; + GetCmdArg(1, arg, sizeof(arg)); + track = StringToInt(arg); + } + + if (track < Track_Bonus || track > Track_Bonus_Last) + { + track = Track_Bonus; + } } if(gCV_AllowTimerWithoutZone.BoolValue || (gB_Zones && (Shavit_ZoneExists(Zone_Start, track) || gB_KZMap))) @@ -609,7 +623,21 @@ public Action Command_TeleportEnd(int client, int args) if(StrContains(sCommand, "sm_b", false) == 0) { - track = Track_Bonus; + if (args < 1) + { + track = Shavit_GetClientTrack(client); + } + else + { + char arg[6]; + GetCmdArg(1, arg, sizeof(arg)); + track = StringToInt(arg); + } + + if (track < Track_Bonus || track > Track_Bonus_Last) + { + track = Track_Bonus; + } } if(gB_Zones && (Shavit_ZoneExists(Zone_End, track) || gB_KZMap)) @@ -1126,7 +1154,7 @@ public Action Command_Style(int client, int args) char sWR[8]; strcopy(sWR, 8, "WR"); - if(gA_Timers[client].iTrack == Track_Bonus) + if(gA_Timers[client].iTrack >= Track_Bonus) { strcopy(sWR, 8, "BWR"); } @@ -3528,17 +3556,3 @@ void UpdateStyleSettings(int client) SetEntityGravity(client, view_as(gA_StyleSettings[gA_Timers[client].iStyle].fGravityMultiplier)); } - -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index 043c6752..035cb95c 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -1923,20 +1923,6 @@ public int Native_GetHUDSettings(Handle handler, int numParams) return gI_HUDSettings[client]; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - void PrintCSGOHUDText(int client, const char[] format, any ...) { char buff[MAX_HINT_SIZE]; diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index 0b3f4793..9326c976 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -968,11 +968,15 @@ void UpdateClanTag(int client) } int track = Shavit_GetClientTrack(client); - char sTrack[3]; + char sTrack[4]; if(track != Track_Main) { - GetTrackName(client, track, sTrack, 3); + sTrack[0] = 'B'; + if (track > Track_Bonus) + { + FormatEx(sTrack, sizeof(sTrack), "B%d", track); + } } char sRank[8]; @@ -2854,20 +2858,6 @@ public Action Shavit_OnStart(int client) return Plugin_Continue; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - public void Shavit_OnWorldRecord(int client, int style, float time, int jumps, int strafes, float sync, int track) { char sUpperCase[64]; diff --git a/addons/sourcemod/scripting/shavit-rankings.sp b/addons/sourcemod/scripting/shavit-rankings.sp index af42a75a..f4c19a93 100644 --- a/addons/sourcemod/scripting/shavit-rankings.sp +++ b/addons/sourcemod/scripting/shavit-rankings.sp @@ -86,8 +86,6 @@ Handle gH_Forwards_OnRankAssigned = null; chatstrings_t gS_ChatStrings; int gI_Styles = 0; stylesettings_t gA_StyleSettings[STYLE_LIMIT]; -char gS_StyleNames[STYLE_LIMIT][64]; -char gS_TrackNames[TRACKS_SIZE][32]; public Plugin myinfo = { @@ -159,11 +157,6 @@ public void OnPluginStart() Shavit_OnChatConfigLoaded(); } - for(int i = 0; i < TRACKS_SIZE; i++) - { - GetTrackName(LANG_SERVER, i, gS_TrackNames[i], 32); - } - SQL_DBConnect(); } @@ -187,7 +180,6 @@ public void Shavit_OnStyleConfigLoaded(int styles) for(int i = 0; i < gI_Styles; i++) { Shavit_GetStyleSettings(i, gA_StyleSettings[i]); - Shavit_GetStyleStrings(i, sStyleName, gS_StyleNames[i], 64); } } @@ -645,7 +637,7 @@ void RecalculateAll(const char[] map) LogError("DEBUG: 5 (RecalculateAll)"); #endif - for(int i = 0; i < TRACKS_SIZE; i++) + for(int i = 0; i < 3; i++) { for(int j = 0; j < gI_Styles; j++) { @@ -654,7 +646,7 @@ void RecalculateAll(const char[] map) continue; } - RecalculateMap(map, i, j); + RecalculateMap(map, i, j, (i > Track_Bonus)); } } } @@ -664,15 +656,23 @@ public void Shavit_OnFinish_Post(int client, int style, float time, int jumps, i RecalculateMap(gS_Map, track, style); } -void RecalculateMap(const char[] map, const int track, const int style) +void RecalculateMap(const char[] map, const int track, const int style, bool restOfTheBonuses=false) { #if defined DEBUG PrintToServer("Recalculating points. (%s, %d, %d)", map, track, style); #endif char sQuery[256]; - FormatEx(sQuery, 256, "UPDATE %splayertimes SET points = GetRecordPoints(%d, %d, time, '%s', %.1f, %.3f) WHERE style = %d AND track = %d AND map = '%s';", + if (restOfTheBonuses) + { + FormatEx(sQuery, 256, "UPDATE %splayertimes SET points = GetRecordPoints(%d, track, time, '%s', %.1f, %.3f) WHERE style = %d AND track > 1 AND map = '%s';", + gS_MySQLPrefix, style, map, gCV_PointsPerTier.FloatValue, gA_StyleSettings[style].fRankingMultiplier, style, map); + } + else + { + FormatEx(sQuery, 256, "UPDATE %splayertimes SET points = GetRecordPoints(%d, %d, time, '%s', %.1f, %.3f) WHERE style = %d AND track = %d AND map = '%s';", gS_MySQLPrefix, style, track, map, gCV_PointsPerTier.FloatValue, gA_StyleSettings[style].fRankingMultiplier, style, track, map); + } gH_SQL.Query(SQL_Recalculate_Callback, sQuery, 0, DBPrio_High); @@ -872,20 +872,6 @@ public void SQL_UpdateTop100_Callback(Database db, DBResultSet results, const ch gH_Top100Menu.ExitButton = true; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - public int Native_GetMapTier(Handle handler, int numParams) { int tier = 0; diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index a0a888b5..17ccf399 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -718,7 +718,7 @@ public any Native_GetReplayTime(Handle handler, int numParams) int style = GetNativeCell(1); int track = GetNativeCell(2); - if(style < 0 || track < 0) + if(style < 0 || track < 0 || track >= TRACKS_SIZE) { return ThrowNativeError(200, "Style/Track out of range"); } @@ -2782,20 +2782,6 @@ int GetSpectatorTarget(int client) return target; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - float GetReplayLength(int style, int track) { if(gA_FrameCache[style][track].iFrameCount == 0) diff --git a/addons/sourcemod/scripting/shavit-stats.sp b/addons/sourcemod/scripting/shavit-stats.sp index a7a89723..de49daa4 100644 --- a/addons/sourcemod/scripting/shavit-stats.sp +++ b/addons/sourcemod/scripting/shavit-stats.sp @@ -935,17 +935,3 @@ public int Native_GetWRCount(Handle handler, int numParams) { return gI_WRAmount[GetNativeCell(1)]; } - -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} diff --git a/addons/sourcemod/scripting/shavit-wr.sp b/addons/sourcemod/scripting/shavit-wr.sp index 704bf4ed..170aa79e 100644 --- a/addons/sourcemod/scripting/shavit-wr.sp +++ b/addons/sourcemod/scripting/shavit-wr.sp @@ -144,9 +144,9 @@ public void OnPluginStart() RegConsoleCmd("sm_wr", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_wr [map]"); RegConsoleCmd("sm_worldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_worldrecord [map]"); - RegConsoleCmd("sm_bwr", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bwr [map]"); - RegConsoleCmd("sm_bworldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bworldrecord [map]"); - RegConsoleCmd("sm_bonusworldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bonusworldrecord [map]"); + RegConsoleCmd("sm_bwr", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bwr [map] [bonus number]"); + RegConsoleCmd("sm_bworldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bworldrecord [map] [bonus number]"); + RegConsoleCmd("sm_bonusworldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bonusworldrecord [map] [bonus number]"); RegConsoleCmd("sm_recent", Command_RecentRecords, "View the recent #1 times set."); RegConsoleCmd("sm_recentrecords", Command_RecentRecords, "View the recent #1 times set."); @@ -1315,14 +1315,46 @@ public Action Command_WorldRecord(int client, int args) return Plugin_Handled; } - if(args == 0) + char sCommand[16]; + GetCmdArg(0, sCommand, 16); + + int track = Track_Main; + bool havemap = false; + + if(StrContains(sCommand, "sm_b", false) == 0) + { + if (args >= 1) + { + char arg[6]; + GetCmdArg((args > 1) ? 2 : 1, arg, sizeof(arg)); + track = StringToInt(arg); + + // if the track doesn't fit in the bonus track range then assume it's a map name + if (args > 1 || (track < Track_Bonus || track > Track_Bonus_Last)) + { + havemap = true; + } + } + + if (track < Track_Bonus || track > Track_Bonus_Last) + { + track = Track_Bonus; + } + } + + else + { + havemap = (args >= 1); + } + + if(!havemap) { strcopy(gA_WRCache[client].sClientMap, 128, gS_Map); } else { - GetCmdArgString(gA_WRCache[client].sClientMap, 128); + GetCmdArg(1, gA_WRCache[client].sClientMap, 128); if (!GuessBestMapName(gA_ValidMaps, gA_WRCache[client].sClientMap, gA_WRCache[client].sClientMap, 128)) { Shavit_PrintToChat(client, "%t", "Map was not found", gA_WRCache[client].sClientMap); @@ -1330,16 +1362,6 @@ public Action Command_WorldRecord(int client, int args) } } - char sCommand[16]; - GetCmdArg(0, sCommand, 16); - - int track = Track_Main; - - if(StrContains(sCommand, "sm_b", false) == 0) - { - track = Track_Bonus; - } - return ShowWRStyleMenu(client, track); } @@ -2265,17 +2287,3 @@ int GetRankForTime(int style, float time, int track) return (iRecords + 1); } - -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} diff --git a/addons/sourcemod/scripting/shavit-zones.sp b/addons/sourcemod/scripting/shavit-zones.sp index 575a53a9..44e82db9 100644 --- a/addons/sourcemod/scripting/shavit-zones.sp +++ b/addons/sourcemod/scripting/shavit-zones.sp @@ -802,6 +802,11 @@ public void Frame_HookTrigger(any data) return; } + if (StrContains(sName, "checkpoint") != -1) + { + return; // TODO + } + int zone = -1; int track = Track_Main; @@ -817,7 +822,16 @@ public void Frame_HookTrigger(any data) if(StrContains(sName, "bonus") != -1) { - track = Track_Bonus; + // Parse out the X in mod_zone_bonus_X_start and mod_zone_bonus_X_end + char sections[8][8]; + ExplodeString(sName, "_", sections, 8, 8, false); + track = StringToInt(sections[3]); // 0 on failure to parse. 0 is less than Track_Bonus + + if (track < Track_Bonus || track > Track_Bonus_Last) + { + // Just ignore because there's either too many bonuses or X can be 0 and nobody told me + return; + } } if(zone != -1) @@ -2197,20 +2211,6 @@ public Action OnClientSayCommand(int client, const char[] command, const char[] return Plugin_Continue; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - void UpdateTeleportZone(int client) { float vTeleport[3]; diff --git a/addons/sourcemod/translations/shavit-common.phrases.txt b/addons/sourcemod/translations/shavit-common.phrases.txt index 99849345..d849a1ff 100644 --- a/addons/sourcemod/translations/shavit-common.phrases.txt +++ b/addons/sourcemod/translations/shavit-common.phrases.txt @@ -9,13 +9,14 @@ { "en" "UNKNOWN TRACK" } - "Track_0" + "Track_Main" { "en" "Main" } - "Track_1" + "Track_Bonus" { - "en" "Bonus" + "#format" "{1:d}" + "en" "Bonus #{1}" } // ---------- Commands ---------- // "NoCommandAccess"