furhter updates for the casuapool in regards to the new playtime frontned updates

This commit is contained in:
jenz
2026-11-16 17:31:26 +01:00
parent 7cc074e31b
commit f79c1eb314
@@ -149,8 +149,11 @@ int g_iDontCooldownMap;
int g_iImpactMapsToCasualPool;
int g_iMapsFromCasualPool;
int g_iImpactExtraCooldownTime;
int g_iImpactExtraCooldownMaxHours;
int g_iImpactSeed;
float g_avg_net_change;
//"penalty" from the playtime frontend: max(0, -impact_score) * P(effect < 0). 0 for maps that do not hurt population.
float g_fImpactPenalty;
int g_iInterval;
char player_mapvote[MAXPLAYERS + 1][PLATFORM_MAX_PATH];
@@ -303,10 +306,15 @@ public void OnPluginStart()
delete cvar2_;
ConVar cvar2_1;
HookConVarChange((cvar2_1 = CreateConVar("mce_impact_extra_cooldown_addition", "100", "How much additional cooldowntime do we apply for negative impact rate. 0 disables the feature.")), Cvar_impact_extra_cooldown);
HookConVarChange((cvar2_1 = CreateConVar("mce_impact_extra_cooldown_addition", "100", "Extra cooldown hours per point of impact penalty from the playtime frontend. 0 disables the feature.")), Cvar_impact_extra_cooldown);
g_iImpactExtraCooldownTime = cvar2_1.IntValue;
delete cvar2_1;
ConVar cvar2_2;
HookConVarChange((cvar2_2 = CreateConVar("mce_impact_extra_cooldown_max_hours", "240", "Maximum extra cooldown hours from the impact penalty. 0 = no cap.")), Cvar_impact_extra_cooldown_max);
g_iImpactExtraCooldownMaxHours = cvar2_2.IntValue;
delete cvar2_2;
ConVar cvar1;
HookConVarChange((cvar1 = CreateConVar("mce_skip_map_restrictions_player_count", "10", "Amount of players required for any restrictions are enabled.")), Cvar_playerActiveRequired);
g_iSkipAllRestrictions = cvar1.IntValue;
@@ -468,6 +476,11 @@ public void Cvar_impact_extra_cooldown(ConVar convar, const char[] oldValue, con
g_iImpactExtraCooldownTime = convar.IntValue;
}
public void Cvar_impact_extra_cooldown_max(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iImpactExtraCooldownMaxHours = convar.IntValue;
}
public void Cvar_casual_pool_impact_enabled(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_bCasualPoolFromImpactPlayTime = convar.BoolValue;
@@ -596,11 +609,16 @@ public void OnMapStart()
}
g_Config.Rewind();
ClearArray(g_hTopImpactMaps);
FillMapsByImpact(0);
//new Thompson-sampling draw every map: proven maps show up reliably, uncertain maps still get a chance.
//the frontend picks the seed from the map that is running (its map_id), so the website shows the same list.
//we wait a bit so the playtime plugin has written this map into the map history first.
//-1 = let the frontend choose, the seed it returns on the first page is used for all following pages.
g_iImpactSeed = -1;
CreateTimer(15.0, Timer_FillMapsByImpact, _, TIMER_FLAG_NO_MAPCHANGE);
char currentmap[256];
GetCurrentMap(currentmap, PLATFORM_MAX_PATH);
g_avg_net_change = 0.0;
g_fImpactPenalty = 0.0;
GetMapsImpact(currentmap);
}
@@ -612,10 +630,23 @@ public void GetMapsImpact(char[] currentmap)
hRequest.Get(OnTransferComplete1, _);
}
public Action Timer_FillMapsByImpact(Handle timer)
{
FillMapsByImpact(0);
return Plugin_Stop;
}
public void FillMapsByImpact(int offset)
{
char sRequest[256];
FormatEx(sRequest, sizeof(sRequest), "https://playtime-sessions.unloze.com/api/maps/impact?sortBy=impact&direction=desc&offset=%i", offset);
if (g_iImpactSeed < 0)
{
FormatEx(sRequest, sizeof(sRequest), "https://playtime-sessions.unloze.com/api/maps/impact?sortBy=thompson&direction=desc&offset=%i", offset);
}
else
{
FormatEx(sRequest, sizeof(sRequest), "https://playtime-sessions.unloze.com/api/maps/impact?sortBy=thompson&direction=desc&seed=%i&offset=%i", g_iImpactSeed, offset);
}
HTTPRequest hRequest = new HTTPRequest(sRequest);
hRequest.Get(OnTransferComplete, offset);
}
@@ -636,6 +667,11 @@ public void OnTransferComplete(HTTPResponse response, int offset)
delete root;
return;
}
bool hasMore = root.GetBool("hasMore");
if (g_iImpactSeed < 0 && root.HasKey("seed"))
{
g_iImpactSeed = root.GetInt("seed"); //keep paging through the same draw
}
Handle tempMaps = CloneArray(g_MapList);
@@ -672,7 +708,8 @@ public void OnTransferComplete(HTTPResponse response, int offset)
delete root;
delete maps;
if (GetArraySize(g_hTopImpactMaps) < g_iImpactMapsToCasualPool)
//pages are always 50 results. stop when the frontend says there are no more, otherwise this would request forever.
if (GetArraySize(g_hTopImpactMaps) < g_iImpactMapsToCasualPool && hasMore)
{
FillMapsByImpact(offset + 50); //did not get enough maps from the public maplist, set offset to pick the next.
}
@@ -697,7 +734,7 @@ public void OnTransferComplete1(HTTPResponse response, any i)
JSONObject entry = view_as<JSONObject>(maps.Get(0));
if (entry != null)
{
g_avg_net_change = entry.GetFloat("avg_net_change");
g_fImpactPenalty = entry.GetFloat("penalty");
}
delete entry;
delete root;
@@ -3350,11 +3387,15 @@ public int additionalCooldownHoursCurrentMap()
{
int Cooldown = 0;
//0 == g_iImpactExtraCooldownTime means feature was disabled, so not adding any extra cooldown hours.
// g_avg_net_change < 0 means the map on average has a negative impact on player population
if (g_avg_net_change < 0 && g_iImpactExtraCooldownTime > 0)
//g_fImpactPenalty > 0 means the frontend is fairly confident the map loses players compared to what the
//server normally does at that time and population. It is already scaled by that confidence.
if (g_fImpactPenalty > 0.0 && g_iImpactExtraCooldownTime > 0)
{
//map has a negative impact on population and should be punished by additioanl g_iImpactExtraCooldownTime hours.
int extraCooldownHours = RoundToFloor((g_avg_net_change * -1) * g_iImpactExtraCooldownTime);
int extraCooldownHours = RoundToFloor(g_fImpactPenalty * g_iImpactExtraCooldownTime);
if (g_iImpactExtraCooldownMaxHours > 0 && extraCooldownHours > g_iImpactExtraCooldownMaxHours)
{
extraCooldownHours = g_iImpactExtraCooldownMaxHours;
}
Cooldown += extraCooldownHours * 60 * 60; //Hours -> minutes -> seconds
}
return Cooldown;