From 6267c17c6be842f258c5baf5ca7cc08482e539de Mon Sep 17 00:00:00 2001 From: Brett Powell Date: Fri, 19 Nov 2010 17:39:53 +1300 Subject: [PATCH] Extend Nominations API (bug 4677, r=pred) --- plugins/include/mapchooser.inc | 35 ++++++++++- plugins/mapchooser.sp | 109 ++++++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 3 deletions(-) diff --git a/plugins/include/mapchooser.inc b/plugins/include/mapchooser.inc index 22468b7b..9f660454 100644 --- a/plugins/include/mapchooser.inc +++ b/plugins/include/mapchooser.inc @@ -29,14 +29,39 @@ enum MapChange */ native NominateResult:NominateMap(const String:map[], bool:force, owner); +/** + * Attempt to remove a map from the mapchooser map list. + * + * @param map Map to remove. + * @return True if the nomination was found and removed, or false if the nomination was not found. + */ +native bool:RemoveNominationByMap(const String:map[]); + +/** + * Attempt to remove a map from the mapchooser map list. + * + * @param owner Client index of the nominater. + * @return True if the nomination was found and removed, or false if the nomination was not found. + */ +native bool:RemoveNominationByOwner(owner); + /** * Gets the current list of excluded maps. * - * @param array An ADT array handle to add the map strings to. Needs to be + * @param array An ADT array handle to add the map strings to. * @noreturn */ native GetExcludeMapList(Handle:array); +/** + * Gets the current list of nominated maps. + * + * @param maparray An ADT array handle to add the map strings to. + * @param ownerarray An optional ADT array handle to add the nominator client indexes to. + * @noreturn + */ +native GetNominatedMapList(Handle:maparray, Handle:ownerarray = INVALID_HANDLE); + /** * Checks if MapChooser will allow a vote * @@ -75,6 +100,11 @@ native bool:EndOfMapVoteEnabled(); */ forward OnNominationRemoved(const String:map[], owner); +/** + * Called when mapchooser starts a Map Vote. + */ +forward OnMapVoteStarted(); + public SharedPlugin:__pl_mapchooser = { @@ -90,7 +120,10 @@ public SharedPlugin:__pl_mapchooser = public __pl_mapchooser_SetNTVOptional() { MarkNativeAsOptional("NominateMap"); + MarkNativeAsOptional("RemoveNominationByMap"); + MarkNativeAsOptional("RemoveNominationByOwner"); MarkNativeAsOptional("GetExcludeMapList"); + MarkNativeAsOptional("GetNominatedMapList"); MarkNativeAsOptional("CanMapChooserStartVote"); MarkNativeAsOptional("InitiateMapChooserVote"); MarkNativeAsOptional("HasEndOfMapVoteFinished"); diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index 7254ddee..a61ebf9c 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -91,6 +91,7 @@ new g_NominateCount = 0; new MapChange:g_ChangeTime; new Handle:g_NominationsResetForward = INVALID_HANDLE; +new Handle:g_MapVoteStartedForward = INVALID_HANDLE; /* Upper bound of how many team there could be */ #define MAXTEAMS 10 @@ -157,6 +158,7 @@ public OnPluginStart() } g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell); + g_MapVoteStartedForward = CreateGlobalForward("OnMapVoteStarted", ET_Ignore); } public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) @@ -164,10 +166,13 @@ public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) RegPluginLibrary("mapchooser"); CreateNative("NominateMap", Native_NominateMap); + CreateNative("RemoveNominationByMap", Native_RemoveNominationByMap); + CreateNative("RemoveNominationByOwner", Native_RemoveNominationByOwner); CreateNative("InitiateMapChooserVote", Native_InitiateVote); CreateNative("CanMapChooserStartVote", Native_CanVoteStart); CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone); CreateNative("GetExcludeMapList", Native_GetExcludeMapList); + CreateNative("GetNominatedMapList", Native_GetNominatedMapList); CreateNative("EndOfMapVoteEnabled", Native_EndOfMapVoteEnabled); return APLRes_Success; @@ -531,6 +536,10 @@ InitiateVote(MapChange:when, Handle:inputlist=INVALID_HANDLE) g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL); SetMenuTitle(g_VoteMenu, "Vote Nextmap"); SetVoteResultCallback(g_VoteMenu, Handler_MapVoteFinished); + + /* Call OnMapVoteStarted() Forward */ + Call_StartForward(g_MapVoteStartedForward); + Call_Finish(); /** * TODO: Make a proper decision on when to clear the nominations list. @@ -961,6 +970,78 @@ public Native_NominateMap(Handle:plugin, numParams) return _:InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3)); } +bool:InternalRemoveNominationByMap(String:map[]) +{ + for (new i = 0; i < GetArraySize(g_NominateList); i++) + { + new String:oldmap[33]; + GetArrayString(g_NominateList, i, oldmap, sizeof(oldmap)); + + if(strcmp(map, oldmap, false) == 0) + { + Call_StartForward(g_NominationsResetForward); + Call_PushString(oldmap); + Call_PushCell(GetArrayCell(g_NominateOwners, i)); + Call_Finish(); + + RemoveFromArray(g_NominateList, i); + RemoveFromArray(g_NominateOwners, i); + g_NominateCount--; + + return true; + } + } + + return false; +} + +/* native bool:RemoveNominationByMap(const String:map[]); */ +public Native_RemoveNominationByMap(Handle:plugin, numParams) +{ + new len; + GetNativeStringLength(1, len); + + if (len <= 0) + { + return false; + } + + new String:map[len+1]; + GetNativeString(1, map, len+1); + + return _:InternalRemoveNominationByMap(map); +} + +bool:InternalRemoveNominationByOwner(owner) +{ + new index; + + if (owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1)) + { + new String:oldmap[33]; + GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap)); + + Call_StartForward(g_NominationsResetForward); + Call_PushString(oldmap); + Call_PushCell(owner); + Call_Finish(); + + RemoveFromArray(g_NominateList, index); + RemoveFromArray(g_NominateOwners, index); + g_NominateCount--; + + return true; + } + + return false; +} + +/* native bool:RemoveNominationByOwner(owner); */ +public Native_RemoveNominationByOwner(Handle:plugin, numParams) +{ + return _:InternalRemoveNominationByOwner(GetNativeCell(1)); +} + /* native InitiateMapChooserVote(); */ public Native_InitiateVote(Handle:plugin, numParams) { @@ -994,8 +1075,6 @@ public Native_GetExcludeMapList(Handle:plugin, numParams) { return; } - - new size = GetArraySize(g_OldMapList); decl String:map[33]; @@ -1007,3 +1086,29 @@ public Native_GetExcludeMapList(Handle:plugin, numParams) return; } + +public Native_GetNominatedMapList(Handle:plugin, numParams) +{ + new Handle:maparray = Handle:GetNativeCell(1); + new Handle:ownerarray = Handle:GetNativeCell(2); + + if (maparray == INVALID_HANDLE) + return; + + decl String:map[33]; + + for (new i = 0; i < GetArraySize(g_NominateList); i++) + { + GetArrayString(g_NominateList, i, map, sizeof(map)); + PushArrayString(maparray, map); + + // If the optional parameter for an owner list was passed, then we need to fill that out as well + if(ownerarray != INVALID_HANDLE) + { + new index = GetArrayCell(g_NominateOwners, i); + PushArrayCell(ownerarray, index); + } + } + + return; +} \ No newline at end of file