Wr suggestions (#972)

* make !wr say map not found when map not found...

* use translation string for 'map was not found'

* stockify GuessBestMapName() and also use in sm_tier

* fix formatting

Co-authored-by: KiD Fearless <kidfearless1@gmail.com>
This commit is contained in:
Joe 2020-10-17 21:41:43 +00:00 committed by GitHub
parent e1e7d3bf2e
commit c40ab49fac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 81 deletions

View File

@ -425,6 +425,32 @@ stock void FormatSeconds(float time, char[] newtime, int newtimesize, bool preci
}
}
stock bool GuessBestMapName(ArrayList maps, const char[] input, char[] output, int size)
{
if(maps.FindString(input) != -1)
{
strcopy(output, size, input);
return true;
}
char sCache[128];
for(int i = 0; i < maps.Length; i++)
{
maps.GetString(i, sCache, 128);
if(StrContains(sCache, input) != -1)
{
strcopy(output, size, sCache);
return true;
}
}
return false;
}
/**
* Called before shavit-core processes the client's usercmd.
* Before this is called, safety checks (fake/dead clients) happen.

View File

@ -67,7 +67,6 @@ int gI_Tier = 1; // No floating numbers for tiers, sorry.
char gS_Map[160];
int gI_ValidMaps = 0;
ArrayList gA_ValidMaps = null;
StringMap gA_MapTiers = null;
@ -434,34 +433,9 @@ public void SQL_FillTierCache_Callback(Database db, DBResultSet results, const c
Call_Finish();
}
gI_ValidMaps = gA_ValidMaps.Length;
SortADTArray(gA_ValidMaps, Sort_Ascending, Sort_String);
}
void GuessBestMapName(const char[] input, char[] output, int size)
{
if(gA_ValidMaps.FindString(input) != -1)
{
strcopy(output, size, input);
return;
}
char sCache[128];
for(int i = 0; i < gI_ValidMaps; i++)
{
gA_ValidMaps.GetString(i, sCache, 128);
if(StrContains(sCache, input) != -1)
{
strcopy(output, size, sCache);
return;
}
}
}
public void OnMapEnd()
{
RecalculateAll(gS_Map);
@ -473,16 +447,19 @@ public Action Command_Tier(int client, int args)
int tier = gI_Tier;
char sMap[128];
strcopy(sMap, 128, gS_Map);
if(args > 0)
if(args == 0)
{
strcopy(sMap, 128, gS_Map);
}
else
{
GetCmdArgString(sMap, 128);
GuessBestMapName(sMap, sMap, 128);
if(!gA_MapTiers.GetValue(sMap, tier))
if(!GuessBestMapName(gA_ValidMaps, sMap, sMap, 128) || !gA_MapTiers.GetValue(sMap, tier))
{
strcopy(sMap, 128, gS_Map);
Shavit_PrintToChat(client, "%t", "Map was not found", sMap);
return Plugin_Handled;
}
}

View File

@ -60,7 +60,6 @@ wrcache_t gA_WRCache[MAXPLAYERS+1];
char gS_Map[160]; // blame workshop paths being so fucking long
ArrayList gA_ValidMaps = null;
int gI_ValidMaps = 1;
// current wr stats
float gF_WRTime[STYLE_LIMIT][TRACKS_SIZE];
@ -124,6 +123,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
public void OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("shavit-common.phrases");
LoadTranslations("shavit-wr.phrases");
@ -143,9 +143,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_Bonus, "View the leaderboard of a map. Usage: sm_bwr [map]");
RegConsoleCmd("sm_bworldrecord", Command_WorldRecord_Bonus, "View the leaderboard of a map. Usage: sm_bworldrecord [map]");
RegConsoleCmd("sm_bonusworldrecord", Command_WorldRecord_Bonus, "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]");
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_recent", Command_RecentRecords, "View the recent #1 times set.");
RegConsoleCmd("sm_recentrecords", Command_RecentRecords, "View the recent #1 times set.");
@ -317,7 +317,6 @@ public void OnMapStart()
gA_ValidMaps.Clear();
gA_ValidMaps.PushString(sLowerCase);
gI_ValidMaps = 1;
char sQuery[128];
FormatEx(sQuery, 128, "SELECT map FROM %smapzones GROUP BY map;", gS_MySQLPrefix);
@ -358,7 +357,6 @@ public void SQL_UpdateMaps_Callback(Database db, DBResultSet results, const char
if(gA_ValidMaps.FindString(sLowerCase) == -1)
{
gA_ValidMaps.PushString(sLowerCase);
gI_ValidMaps++;
}
}
@ -1313,31 +1311,24 @@ public Action Command_WorldRecord(int client, int args)
else
{
GetCmdArgString(gA_WRCache[client].sClientMap, 128);
GuessBestMapName(gA_WRCache[client].sClientMap, gA_WRCache[client].sClientMap, 128);
}
return ShowWRStyleMenu(client, Track_Main);
}
public Action Command_WorldRecord_Bonus(int client, int args)
{
if(!IsValidClient(client))
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);
return Plugin_Handled;
}
if(args == 0)
{
strcopy(gA_WRCache[client].sClientMap, 128, gS_Map);
}
else
char sCommand[16];
GetCmdArg(0, sCommand, 16);
int track = Track_Main;
if(StrContains(sCommand, "sm_b", false) == 0)
{
GetCmdArgString(gA_WRCache[client].sClientMap, 128);
GuessBestMapName(gA_WRCache[client].sClientMap, gA_WRCache[client].sClientMap, 128);
track = Track_Bonus;
}
return ShowWRStyleMenu(client, Track_Bonus);
return ShowWRStyleMenu(client, track);
}
Action ShowWRStyleMenu(int client, int track)
@ -2263,30 +2254,6 @@ int GetRankForTime(int style, float time, int track)
return (iRecords + 1);
}
void GuessBestMapName(const char[] input, char[] output, int size)
{
if(gA_ValidMaps.FindString(input) != -1)
{
strcopy(output, size, input);
return;
}
char sCache[128];
for(int i = 0; i < gI_ValidMaps; i++)
{
gA_ValidMaps.GetString(i, sCache, 128);
if(StrContains(sCache, input) != -1)
{
strcopy(output, size, sCache);
return;
}
}
}
void GetTrackName(int client, int track, char[] output, int size)
{
if(track < 0 || track >= TRACKS_SIZE)