Port mapchooser.

This commit is contained in:
David Anderson 2014-11-09 16:22:58 -08:00
parent 59fbeb4f2c
commit c425305cde

View File

@ -47,27 +47,27 @@ public Plugin:myinfo =
};
/* Valve ConVars */
new Handle:g_Cvar_Winlimit = INVALID_HANDLE;
new Handle:g_Cvar_Maxrounds = INVALID_HANDLE;
new Handle:g_Cvar_Fraglimit = INVALID_HANDLE;
new Handle:g_Cvar_Bonusroundtime = INVALID_HANDLE;
ConVar g_Cvar_Winlimit;
ConVar g_Cvar_Maxrounds;
ConVar g_Cvar_Fraglimit;
ConVar g_Cvar_Bonusroundtime;
/* Plugin ConVars */
new Handle:g_Cvar_StartTime = INVALID_HANDLE;
new Handle:g_Cvar_StartRounds = INVALID_HANDLE;
new Handle:g_Cvar_StartFrags = INVALID_HANDLE;
new Handle:g_Cvar_ExtendTimeStep = INVALID_HANDLE;
new Handle:g_Cvar_ExtendRoundStep = INVALID_HANDLE;
new Handle:g_Cvar_ExtendFragStep = INVALID_HANDLE;
new Handle:g_Cvar_ExcludeMaps = INVALID_HANDLE;
new Handle:g_Cvar_IncludeMaps = INVALID_HANDLE;
new Handle:g_Cvar_NoVoteMode = INVALID_HANDLE;
new Handle:g_Cvar_Extend = INVALID_HANDLE;
new Handle:g_Cvar_DontChange = INVALID_HANDLE;
new Handle:g_Cvar_EndOfMapVote = INVALID_HANDLE;
new Handle:g_Cvar_VoteDuration = INVALID_HANDLE;
new Handle:g_Cvar_RunOff = INVALID_HANDLE;
new Handle:g_Cvar_RunOffPercent = INVALID_HANDLE;
ConVar g_Cvar_StartTime;
ConVar g_Cvar_StartRounds;
ConVar g_Cvar_StartFrags;
ConVar g_Cvar_ExtendTimeStep;
ConVar g_Cvar_ExtendRoundStep;
ConVar g_Cvar_ExtendFragStep;
ConVar g_Cvar_ExcludeMaps;
ConVar g_Cvar_IncludeMaps;
ConVar g_Cvar_NoVoteMode;
ConVar g_Cvar_Extend;
ConVar g_Cvar_DontChange;
ConVar g_Cvar_EndOfMapVote;
ConVar g_Cvar_VoteDuration;
ConVar g_Cvar_RunOff;
ConVar g_Cvar_RunOffPercent;
new Handle:g_VoteTimer = INVALID_HANDLE;
new Handle:g_RetryTimer = INVALID_HANDLE;
@ -138,9 +138,9 @@ public OnPluginStart()
g_Cvar_Fraglimit = FindConVar("mp_fraglimit");
g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime");
if (g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE)
if (g_Cvar_Winlimit || g_Cvar_Maxrounds)
{
decl String:folder[64];
char folder[64];
GetGameFolderName(folder, sizeof(folder));
if (strcmp(folder, "tf") == 0)
@ -159,7 +159,7 @@ public OnPluginStart()
}
}
if (g_Cvar_Fraglimit != INVALID_HANDLE)
if (g_Cvar_Fraglimit)
{
HookEvent("player_death", Event_PlayerDeath);
}
@ -168,9 +168,9 @@ public OnPluginStart()
//Change the mp_bonusroundtime max so that we have time to display the vote
//If you display a vote during bonus time good defaults are 17 vote duration and 19 mp_bonustime
if (g_Cvar_Bonusroundtime != INVALID_HANDLE)
if (g_Cvar_Bonusroundtime)
{
SetConVarBounds(g_Cvar_Bonusroundtime, ConVarBound_Upper, true, 30.0);
g_Cvar_Bonusroundtime.SetBounds(ConVarBound_Upper, true, 30.0);
}
g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
@ -228,9 +228,9 @@ public OnConfigsExecuted()
/* Check if mapchooser will attempt to start mapvote during bonus round time - TF2 Only */
if ((g_Cvar_Bonusroundtime != INVALID_HANDLE) && !GetConVarInt(g_Cvar_StartRounds))
if (g_Cvar_Bonusroundtime && !g_Cvar_StartRounds.IntValue)
{
if (GetConVarFloat(g_Cvar_Bonusroundtime) <= GetConVarFloat(g_Cvar_VoteDuration))
if (g_Cvar_Bonusroundtime.FloatValue <= g_Cvar_VoteDuration.FloatValue)
{
LogError("Warning - Bonus Round Time shorter than Vote Time. Votes during bonus round may not have time to complete");
}
@ -251,7 +251,7 @@ public OnMapEnd()
GetCurrentMap(map, sizeof(map));
PushArrayString(g_OldMapList, map);
if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
if (GetArraySize(g_OldMapList) > g_Cvar_ExcludeMaps.IntValue)
{
RemoveFromArray(g_OldMapList, 0);
}
@ -316,8 +316,8 @@ SetupTimeleftTimer()
new time;
if (GetMapTimeLeft(time) && time > 0)
{
new startTime = GetConVarInt(g_Cvar_StartTime) * 60;
if (time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted)
new startTime = g_Cvar_StartTime.IntValue * 60;
if (time - startTime < 0 && g_Cvar_EndOfMapVote.BoolValue && !g_MapVoteCompleted && !g_HasVoteStarted)
{
InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
}
@ -351,7 +351,7 @@ public Action:Timer_StartMapVote(Handle:timer, Handle:data)
g_VoteTimer = INVALID_HANDLE;
}
if (!GetArraySize(g_MapList) || !GetConVarBool(g_Cvar_EndOfMapVote) || g_MapVoteCompleted || g_HasVoteStarted)
if (!GetArraySize(g_MapList) || !g_Cvar_EndOfMapVote.BoolValue || g_MapVoteCompleted || g_HasVoteStarted)
{
return Plugin_Stop;
}
@ -386,7 +386,7 @@ public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadc
{
g_TotalRounds++;
if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted || !GetConVarBool(g_Cvar_EndOfMapVote))
if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted || !g_Cvar_EndOfMapVote.BoolValue)
{
return;
}
@ -432,7 +432,7 @@ public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
winner = GetEventInt(event, "winner");
}
if (winner == 0 || winner == 1 || !GetConVarBool(g_Cvar_EndOfMapVote))
if (winner == 0 || winner == 1 || !g_Cvar_EndOfMapVote.BoolValue)
{
return;
}
@ -457,12 +457,12 @@ public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
public CheckWinLimit(winner_score)
{
if (g_Cvar_Winlimit != INVALID_HANDLE)
if (g_Cvar_Winlimit)
{
new winlimit = GetConVarInt(g_Cvar_Winlimit);
int winlimit = g_Cvar_Winlimit.IntValue;
if (winlimit)
{
if (winner_score >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
if (winner_score >= (winlimit - g_Cvar_StartRounds.IntValue))
{
InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
}
@ -472,12 +472,12 @@ public CheckWinLimit(winner_score)
public CheckMaxRounds(roundcount)
{
if (g_Cvar_Maxrounds != INVALID_HANDLE)
if (g_Cvar_Maxrounds)
{
new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
int maxrounds = g_Cvar_Maxrounds.IntValue;
if (maxrounds)
{
if (roundcount >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
if (roundcount >= (maxrounds - g_Cvar_StartRounds.IntValue))
{
InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
}
@ -487,12 +487,12 @@ public CheckMaxRounds(roundcount)
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted)
if (!GetArraySize(g_MapList) || !g_Cvar_Fraglimit || g_HasVoteStarted)
{
return;
}
if (!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote))
if (!g_Cvar_Fraglimit.IntValue || !g_Cvar_EndOfMapVote.BoolValue)
{
return;
}
@ -509,7 +509,7 @@ public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
return;
}
if (GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
if (GetClientFrags(fragger) >= (g_Cvar_Fraglimit.IntValue - g_Cvar_StartFrags.IntValue))
{
InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
}
@ -572,16 +572,16 @@ InitiateVote(MapChange:when, Handle:inputlist=INVALID_HANDLE)
* like sm_mapvote from the adminmenu in the future.
*/
decl String:map[PLATFORM_MAX_PATH];
char map[PLATFORM_MAX_PATH];
/* No input given - User our internal nominations and maplist */
if (inputlist == INVALID_HANDLE)
{
new nominateCount = GetArraySize(g_NominateList);
new voteSize = GetConVarInt(g_Cvar_IncludeMaps);
int nominateCount = GetArraySize(g_NominateList);
int voteSize = g_Cvar_IncludeMaps.IntValue;
/* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */
new nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount;
int nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount;
for (new i=0; i<nominationsToAdd; i++)
@ -652,11 +652,11 @@ InitiateVote(MapChange:when, Handle:inputlist=INVALID_HANDLE)
}
/* Do we add any special items? */
if ((when == MapChange_Instant || when == MapChange_RoundEnd) && GetConVarBool(g_Cvar_DontChange))
if ((when == MapChange_Instant || when == MapChange_RoundEnd) && g_Cvar_DontChange.BoolValue)
{
AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change");
}
else if (GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend))
else if (g_Cvar_Extend.BoolValue && g_Extends < g_Cvar_Extend.IntValue)
{
AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map");
}
@ -670,7 +670,7 @@ InitiateVote(MapChange:when, Handle:inputlist=INVALID_HANDLE)
return;
}
new voteDuration = GetConVarInt(g_Cvar_VoteDuration);
int voteDuration = g_Cvar_VoteDuration.IntValue;
SetMenuExitButton(g_VoteMenu, false);
VoteMenuToAll(g_VoteMenu, voteDuration);
@ -686,46 +686,46 @@ public Handler_VoteFinishedGeneric(Handle:menu,
num_items,
const item_info[][2])
{
decl String:map[PLATFORM_MAX_PATH];
char map[PLATFORM_MAX_PATH];
GetMenuItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map));
if (strcmp(map, VOTE_EXTEND, false) == 0)
{
g_Extends++;
new time;
int time;
if (GetMapTimeLimit(time))
{
if (time > 0)
{
ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);
ExtendMapTimeLimit(g_Cvar_ExtendTimeStep.IntValue * 60);
}
}
if (g_Cvar_Winlimit != INVALID_HANDLE)
if (g_Cvar_Winlimit)
{
new winlimit = GetConVarInt(g_Cvar_Winlimit);
int winlimit = g_Cvar_Winlimit.IntValue;
if (winlimit)
{
SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
g_Cvar_Winlimit.IntValue = winlimit + g_Cvar_ExtendRoundStep.IntValue;
}
}
if (g_Cvar_Maxrounds != INVALID_HANDLE)
if (g_Cvar_Maxrounds)
{
new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
new maxrounds = g_Cvar_Maxrounds.IntValue;
if (maxrounds)
{
SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
g_Cvar_Maxrounds.IntValue = maxrounds + g_Cvar_ExtendRoundStep.IntValue;
}
}
if (g_Cvar_Fraglimit != INVALID_HANDLE)
if (g_Cvar_Fraglimit)
{
new fraglimit = GetConVarInt(g_Cvar_Fraglimit);
int fraglimit = g_Cvar_Fraglimit.IntValue;
if (fraglimit)
{
SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));
g_Cvar_Fraglimit.IntValue = fraglimit + g_Cvar_ExtendFragStep.IntValue;
}
}
@ -781,10 +781,10 @@ public Handler_MapVoteFinished(Handle:menu,
num_items,
const item_info[][2])
{
if (GetConVarBool(g_Cvar_RunOff) && num_items > 1)
if (g_Cvar_RunOff.BoolValue && num_items > 1)
{
new Float:winningvotes = float(item_info[0][VOTEINFO_ITEM_VOTES]);
new Float:required = num_votes * (GetConVarFloat(g_Cvar_RunOffPercent) / 100.0);
float winningvotes = float(item_info[0][VOTEINFO_ITEM_VOTES]);
float required = num_votes * (g_Cvar_RunOffPercent.FloatValue / 100.0);
if (winningvotes < required)
{
@ -793,16 +793,16 @@ public Handler_MapVoteFinished(Handle:menu,
SetMenuTitle(g_VoteMenu, "Runoff Vote Nextmap");
SetVoteResultCallback(g_VoteMenu, Handler_VoteFinishedGeneric);
decl String:map[PLATFORM_MAX_PATH];
decl String:info1[PLATFORM_MAX_PATH];
decl String:info2[PLATFORM_MAX_PATH];
char map[PLATFORM_MAX_PATH];
char info1[PLATFORM_MAX_PATH];
char info2[PLATFORM_MAX_PATH];
GetMenuItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map), _, info1, sizeof(info1));
AddMenuItem(g_VoteMenu, map, info1);
GetMenuItem(menu, item_info[1][VOTEINFO_ITEM_INDEX], map, sizeof(map), _, info2, sizeof(info2));
AddMenuItem(g_VoteMenu, map, info2);
new voteDuration = GetConVarInt(g_Cvar_VoteDuration);
int voteDuration = g_Cvar_VoteDuration.IntValue;
SetMenuExitButton(g_VoteMenu, false);
VoteMenuToAll(g_VoteMenu, voteDuration);
@ -811,7 +811,7 @@ public Handler_MapVoteFinished(Handle:menu,
new Float:map2percent = float(item_info[1][VOTEINFO_ITEM_VOTES])/ float(num_votes) * 100;
PrintToChatAll("[SM] %t", "Starting Runoff", GetConVarFloat(g_Cvar_RunOffPercent), info1, map1percent, info2, map2percent);
PrintToChatAll("[SM] %t", "Starting Runoff", g_Cvar_RunOffPercent.FloatValue, info1, map1percent, info2, map2percent);
LogMessage("Voting for next map was indecisive, beginning runoff vote");
return;
@ -862,7 +862,7 @@ public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
case MenuAction_VoteCancel:
{
// If we receive 0 votes, pick at random.
if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode))
if (param1 == VoteCancel_NoVotes && g_Cvar_NoVoteMode.BoolValue)
{
new count = GetMenuItemCount(menu);
decl String:map[PLATFORM_MAX_PATH];
@ -940,13 +940,13 @@ CreateNextVote()
{
ClearArray(g_NextMapList);
decl String:map[PLATFORM_MAX_PATH];
char map[PLATFORM_MAX_PATH];
new Handle:tempMaps = CloneArray(g_MapList);
GetCurrentMap(map, sizeof(map));
RemoveStringFromArray(tempMaps, map);
if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
if (g_Cvar_ExcludeMaps.IntValue && GetArraySize(tempMaps) > g_Cvar_ExcludeMaps.IntValue)
{
for (new i = 0; i < GetArraySize(g_OldMapList); i++)
{
@ -955,10 +955,10 @@ CreateNextVote()
}
}
new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps));
for (new i = 0; i < limit; i++)
int limit = (g_Cvar_IncludeMaps.IntValue < GetArraySize(tempMaps) ? g_Cvar_IncludeMaps.IntValue : GetArraySize(tempMaps));
for (int i = 0; i < limit; i++)
{
new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
int b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
GetArrayString(tempMaps, b, map, sizeof(map));
PushArrayString(g_NextMapList, map);
RemoveFromArray(tempMaps, b);
@ -1007,7 +1007,7 @@ NominateResult:InternalNominateMap(String:map[], bool:force, owner)
}
/* Too many nominated maps. */
if (GetArraySize(g_NominateList) >= GetConVarInt(g_Cvar_IncludeMaps) && !force)
if (GetArraySize(g_NominateList) >= g_Cvar_IncludeMaps.IntValue && !force)
{
return Nominate_VoteFull;
}
@ -1015,9 +1015,9 @@ NominateResult:InternalNominateMap(String:map[], bool:force, owner)
PushArrayString(g_NominateList, map);
PushArrayCell(g_NominateOwners, owner);
while (GetArraySize(g_NominateList) > GetConVarInt(g_Cvar_IncludeMaps))
while (GetArraySize(g_NominateList) > g_Cvar_IncludeMaps.IntValue)
{
new String:oldmap[PLATFORM_MAX_PATH];
char oldmap[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList, 0, oldmap, sizeof(oldmap));
Call_StartForward(g_NominationsResetForward);
Call_PushString(oldmap);
@ -1142,7 +1142,7 @@ public Native_CheckVoteDone(Handle:plugin, numParams)
public Native_EndOfMapVoteEnabled(Handle:plugin, numParams)
{
return GetConVarBool(g_Cvar_EndOfMapVote);
return g_Cvar_EndOfMapVote.BoolValue;
}
public Native_GetExcludeMapList(Handle:plugin, numParams)