Skip to content

Commit

Permalink
Revert "Refactor game info synchronization by removing unused variabl…
Browse files Browse the repository at this point in the history
…es and simplifying progress calculations"

This reverts commit 3d790e3.
  • Loading branch information
altair-sossai committed Nov 15, 2024
1 parent faaccbd commit d61c9e7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Binary file modified addons/sourcemod/plugins/optional/l4d2_gameinfo_sync.smx
Binary file not shown.
42 changes: 36 additions & 6 deletions addons/sourcemod/scripting/l4d2_gameinfo_sync.sp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public Plugin myinfo =
ConVar
g_hUrl,
g_hSecretKey,
g_hConfigurationName;
g_hConfigurationName,
g_hVsBossBuffer;

char g_sConfigurationName[64];

Expand All @@ -42,6 +43,8 @@ float g_fSurvivorProgress[MAXPLAYERS + 1];

public void OnPluginStart()
{
g_hVsBossBuffer = FindConVar("versus_boss_buffer");

g_hUrl = CreateConVar("gameinfo_url", "", "Game Info API URL", FCVAR_PROTECTED);
g_hSecretKey = CreateConVar("gameinfo_secret", "", "Game Info API Secret Key", FCVAR_PROTECTED);

Expand Down Expand Up @@ -220,16 +223,13 @@ void SendScoreboard()
bool isInReady = IsInReady();
int bonus = SMPlus_GetHealthBonus() + SMPlus_GetDamageBonus() + SMPlus_GetPillsBonus();
int maxBonus = SMPlus_GetMaxHealthBonus() + SMPlus_GetMaxDamageBonus() + SMPlus_GetMaxPillsBonus();
int currentProgressPoints = isInReady ? 0 : L4D_GetTeamScore(flipped ? 2 : 1);
int maxChapterProgressPoints = L4D_GetVersusMaxCompletionScore();
float currentProgress = (isInReady || maxChapterProgressPoints == 0) ? 0.0 : (float(currentProgressPoints) / float(maxChapterProgressPoints));

command.SetInt("survivorScore", L4D2Direct_GetVSCampaignScore(flipped ? 1 : 0) + L4D_GetTeamScore(flipped ? 2 : 1));
command.SetInt("infectedScore", L4D2Direct_GetVSCampaignScore(flipped ? 0 : 1) + L4D_GetTeamScore(flipped ? 1 : 2));
command.SetInt("bonus", isInReady ? maxBonus : bonus);
command.SetInt("maxBonus", maxBonus);
command.SetFloat("currentProgress", currentProgress);
command.SetInt("currentProgressPoints", currentProgressPoints);
command.SetFloat("currentProgress", isInReady ? 0.0 : (GetCurrentProgress() / 100.0));
command.SetInt("currentProgressPoints", isInReady ? 0 : L4D_GetTeamScore(flipped ? 2 : 1));

HTTPRequest request = BuildHTTPRequest("/api/game-info/scoreboard");

Expand Down Expand Up @@ -385,6 +385,36 @@ float GetSurvivorProgress(int client)
return 0.0;
}

int GetCurrentProgress()
{
return RoundToNearest(GetBossProximity() * 100.0);
}

float GetBossProximity()
{
float proximity = GetMaxSurvivorCompletion() + g_hVsBossBuffer.FloatValue / L4D2Direct_GetMapMaxFlowDistance();

return (proximity > 1.0) ? 1.0 : proximity;
}

float GetMaxSurvivorCompletion()
{
float flow = 0.0, tmp_flow = 0.0, origin[3];
Address pNavArea;
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && GetClientTeam(i) == L4D2_TEAM_SURVIVOR) {
GetClientAbsOrigin(i, origin);
pNavArea = L4D2Direct_GetTerrorNavArea(origin);
if (pNavArea != Address_Null) {
tmp_flow = L4D2Direct_GetTerrorNavAreaFlow(pNavArea);
flow = (flow > tmp_flow) ? flow : tmp_flow;
}
}
}

return (flow / L4D2Direct_GetMapMaxFlowDistance());
}

float Max(float a, float b) {
return (a > b) ? a : b;
}
Expand Down

0 comments on commit d61c9e7

Please sign in to comment.