Added new natives and complete replay bots. (#537)

This commit is contained in:
shavit 2017-11-21 12:24:21 +02:00
parent d20839218c
commit 42ee76c742
3 changed files with 106 additions and 26 deletions

View File

@ -747,7 +747,7 @@ native void Shavit_PauseTimer(int client);
native void Shavit_ResumeTimer(int client);
/**
* Retrieve the engine time of the replay bot's first frame.
* Retrieves the engine time of the replay bot's first frame.
*
* @param style Style.
* @param time Reference to save the time on.
@ -787,6 +787,44 @@ native int Shavit_GetReplayBotTrack(int client);
*/
native int Shavit_GetReplayBotCurrentFrame(int style);
/**
* Retrieves a replay's frame count.
*
* @param style Style.
* @param track Track.
* @noreturn
*/
native int Shavit_GetReplayFrameCount(int style, int track);
/**
* Retrieves a replay's total length in seconds.
*
* @param style Style.
* @param track Track.
* @noreturn
*/
native float Shavit_GetReplayLength(int style, int track);
/**
* Retrieves an actively playing replay's time.
*
* @param style Style.
* @param track Track. (ignored for non-central bots)
* @noreturn
*/
native float Shavit_GetReplayTime(int style, int track);
/**
* Retrieves a replay holder's name.
*
* @param style Style.
* @param track Track.
* @param buffer Buffer string.
* @param length String length.
* @noreturn
*/
native void Shavit_GetReplayName(int style, int track, char[] buffer, int length);
/**
* Checks if there's loaded replay data for a bhop style or not.
*
@ -1079,6 +1117,10 @@ public void __pl_shavit_SetNTVOptional()
MarkNativeAsOptional("Shavit_GetReplayBotStyle");
MarkNativeAsOptional("Shavit_GetReplayBotTrack");
MarkNativeAsOptional("Shavit_GetReplayData");
MarkNativeAsOptional("Shavit_GetReplayFrameCount");
MarkNativeAsOptional("Shavit_GetReplayLength");
MarkNativeAsOptional("Shavit_GetReplayName");
MarkNativeAsOptional("Shavit_GetReplayTime");
MarkNativeAsOptional("Shavit_GetStrafeCount");
MarkNativeAsOptional("Shavit_GetStyleCount");
MarkNativeAsOptional("Shavit_GetStyleSettings");

View File

@ -742,32 +742,27 @@ void UpdateHUD(int client)
int style = Shavit_GetReplayBotStyle(target);
if(style == -1)
{
return;
}
track = Shavit_GetReplayBotTrack(target);
float start = 0.0;
Shavit_GetReplayBotFirstFrame(style, start);
float time = (GetEngineTime() - start);
float fWR = 0.0;
Shavit_GetWRTime(style, fWR, track);
if(time > fWR || !Shavit_IsReplayDataLoaded(style, track))
{
PrintHintText(client, "%T", "NoReplayData", client);
return;
}
char[] sTime = new char[32];
FormatSeconds(time, sTime, 32, false);
track = Shavit_GetReplayBotTrack(target);
char[] sWR = new char[32];
FormatSeconds(fWR, sWR, 32, false);
float fReplayTime = Shavit_GetReplayTime(style, track);
float fReplayLength = Shavit_GetReplayLength(style, track);
if(fReplayTime < 0.0 || fReplayTime > fReplayLength || !Shavit_IsReplayDataLoaded(style, track))
{
return;
}
char[] sReplayTime = new char[32];
FormatSeconds(fReplayTime, sReplayTime, 32, false);
char[] sReplayLength = new char[32];
FormatSeconds(fReplayLength, sReplayLength, 32, false);
char[] sTrack = new char[32];
@ -781,15 +776,19 @@ void UpdateHUD(int client)
{
FormatEx(sHintText, 512, "<font face='Stratum2'>");
Format(sHintText, 512, "%s\t<u><font color='#%s'>%s %T</font></u>", sHintText, gS_StyleStrings[style][sHTMLColor], gS_StyleStrings[style][sStyleName], "ReplayText", client);
Format(sHintText, 512, "%s\n\t%T: <font color='#00FF00'>%s</font> / %s", sHintText, "HudTimeText", client, sTime, sWR);
Format(sHintText, 512, "%s\n\t%T: <font color='#00FF00'>%s</font> / %s", sHintText, "HudTimeText", client, sReplayTime, sReplayLength);
Format(sHintText, 512, "%s\n\t%T: %d", sHintText, "HudSpeedText", client, iSpeed);
Format(sHintText, 512, "%s</font>", sHintText);
}
else
{
FormatEx(sHintText, 512, "%s %sReplay", gS_StyleStrings[style][sStyleName], sTrack);
Format(sHintText, 512, "%s\n%T: %s/%s", sHintText, "HudTimeText", client, sTime, sWR);
char[] sPlayerName = new char[MAX_NAME_LENGTH];
Shavit_GetReplayName(style, track, sPlayerName, MAX_NAME_LENGTH);
FormatEx(sHintText, 512, "%s %s%T", gS_StyleStrings[style][sStyleName], sTrack, "ReplayText", client);
Format(sHintText, 512, "%s\n%s", sHintText, sPlayerName);
Format(sHintText, 512, "%s\n%T: %s/%s", sHintText, "HudTimeText", client, sReplayTime, sReplayLength);
Format(sHintText, 512, "%s\n%T: %d", sHintText, "HudSpeedText", client, iSpeed);
}

View File

@ -66,7 +66,7 @@ int gI_ReplayBotClient[STYLE_LIMIT];
ArrayList gA_Frames[STYLE_LIMIT][TRACKS_SIZE];
float gF_StartTick[STYLE_LIMIT];
ReplayStatus gRS_ReplayStatus[STYLE_LIMIT];
any gA_FrameCache[STYLE_LIMIT][TRACKS_SIZE][3]; // int frame_count, float, time, bool new_format
any gA_FrameCache[STYLE_LIMIT][TRACKS_SIZE][3]; // int frame_count, float time, bool new_format
char gS_ReplayNames[STYLE_LIMIT][TRACKS_SIZE][MAX_NAME_LENGTH];
bool gB_ForciblyStopped = false;
@ -136,6 +136,10 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Shavit_GetReplayBotStyle", Native_GetReplayBotStyle);
CreateNative("Shavit_GetReplayBotTrack", Native_GetReplayBotTrack);
CreateNative("Shavit_GetReplayData", Native_GetReplayData);
CreateNative("Shavit_GetReplayFrameCount", Native_GetReplayFrameCount);
CreateNative("Shavit_GetReplayLength", Native_GetReplayLength);
CreateNative("Shavit_GetReplayName", Native_GetReplayName);
CreateNative("Shavit_GetReplayTime", Native_GetReplayTime);
CreateNative("Shavit_IsReplayDataLoaded", Native_IsReplayDataLoaded);
CreateNative("Shavit_ReloadReplay", Native_ReloadReplay);
CreateNative("Shavit_ReloadReplays", Native_ReloadReplays);
@ -250,7 +254,7 @@ public int Native_IsReplayDataLoaded(Handle handler, int numParams)
if(gB_CentralBot)
{
return (gA_CentralCache[iCentralClient] != -1 && gA_CentralCache[iCentralClient] != Replay_Idle && gA_FrameCache[style][track][0] > 0);
return (gA_CentralCache[iCentralClient] != -1 && gA_CentralCache[iCentralClient] != Replay_Idle && view_as<int>(gA_FrameCache[style][track][0]) > 0);
}
return view_as<int>(ReplayEnabled(style) && gA_FrameCache[style][Track_Main][0] > 0);
@ -366,6 +370,42 @@ public int Native_GetReplayData(Handle handler, int numParams)
return view_as<int>(frames);
}
public int Native_GetReplayFrameCount(Handle handler, int numParams)
{
return view_as<int>(gA_FrameCache[GetNativeCell(1)][GetNativeCell(2)][0]);
}
public int Native_GetReplayLength(Handle handler, int numParams)
{
return view_as<int>(gA_FrameCache[GetNativeCell(1)][GetNativeCell(2)][1]);
}
public int Native_GetReplayName(Handle handler, int numParams)
{
return SetNativeString(3, gS_ReplayNames[GetNativeCell(1)][GetNativeCell(2)], GetNativeCell(4));
}
public int Native_GetReplayTime(Handle handler, int numParams)
{
int style = GetNativeCell(1);
int track = GetNativeCell(2);
if(gB_CentralBot)
{
if(gA_CentralCache[iCentralReplayStatus] == Replay_End)
{
return view_as<int>(gA_FrameCache[style][track][1]);
}
}
else if(gRS_ReplayStatus[style] == Replay_End)
{
return view_as<int>(gA_FrameCache[style][Track_Main][1]);
}
return view_as<int>(float(gI_ReplayTick[style]) / gF_Tickrate);
}
public int Native_GetReplayBotStyle(Handle handler, int numParams)
{
return (gB_CentralBot && gA_CentralCache[iCentralReplayStatus] == Replay_Idle)? -1:GetReplayStyle(GetNativeCell(1));
@ -727,7 +767,6 @@ bool LoadReplay(int style, int track, const char[] path)
if(gH_SQL != null)
{
// TODO: query database with above steamid and store name into `gS_ReplayNames[style][track]`
char[] sQuery = new char[192];
FormatEx(sQuery, 192, "SELECT name FROM %susers WHERE auth = '%s';", gS_MySQLPrefix, sAuthID);