mapchooser_extended: new feature: map group restrictions

This commit is contained in:
BotoX
2018-03-20 01:06:26 +01:00
parent 229fb7b8cd
commit 3d24fb83e0
5 changed files with 192 additions and 11 deletions
@@ -405,6 +405,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("GetMapMaxPlayers", Native_GetMapMaxPlayers);
CreateNative("GetMapTimeRestriction", Native_GetMapTimeRestriction);
CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction);
CreateNative("GetMapGroup", Native_GetMapGroup);
CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction);
return APLRes_Success;
}
@@ -1144,17 +1146,14 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
GetArrayString(g_NextMapList, count, map, PLATFORM_MAX_PATH);
count++;
if(InternalGetMapPlayerRestriction(map) == 0)
if(randomizeList == INVALID_HANDLE)
{
if(randomizeList == INVALID_HANDLE)
{
/* Insert the map and increment our count */
AddMapItem(map);
}
else
PushArrayString(randomizeList, map);
i++;
/* Insert the map and increment our count */
AddMapItem(map);
}
else
PushArrayString(randomizeList, map);
i++;
//Run out of maps, this will have to do.
if(count >= availableMaps)
@@ -1655,6 +1654,9 @@ void CreateNextVote()
int voteSize = GetVoteSize();
int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps));
StringMap groups = new StringMap();
char group[255];
for(int i = 0; i < limit; i++)
{
int b;
@@ -1662,13 +1664,27 @@ void CreateNextVote()
{
b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
GetArrayString(tempMaps, b, map, PLATFORM_MAX_PATH);
if(InternalGetMapPlayerRestriction(map) == 0)
break;
int groupmax = InternalGetMapGroup(map, group, sizeof(group));
if(groupmax >= 0)
{
int groupcur = 0;
groups.GetValue(group, groupcur);
if(groupcur >= groupmax)
break;
groupcur++;
groups.SetValue(group, groupcur, true);
}
}
PushArrayString(g_NextMapList, map);
RemoveFromArray(tempMaps, b);
}
delete groups;
CloseHandle(tempMaps);
}
@@ -2149,6 +2165,79 @@ public int Native_GetMapPlayerRestriction(Handle plugin, int numParams)
return InternalGetMapPlayerRestriction(map);
}
public int Native_GetMapGroup(Handle plugin, int numParams)
{
int len;
GetNativeStringLength(1, len);
int size = GetNativeCell(3);
if(len <= 0)
return -999;
char[] map = new char[len+1];
GetNativeString(1, map, len+1);
char[] group = new char[size];
int groupmax = InternalGetMapGroup(map, group, size);
if(groupmax >= 0)
SetNativeString(2, group, size);
return groupmax;
}
public int Native_GetMapGroupRestriction(Handle plugin, int numParams)
{
int client = GetNativeCell(2);
int len;
GetNativeStringLength(1, len);
if(len <= 0)
return -999;
char[] map = new char[len+1];
GetNativeString(1, map, len+1);
static char group[255];
int groupmax = InternalGetMapGroup(map, group, sizeof(group));
int groupcur = 0;
if(groupmax >= 0)
{
static char map_[PLATFORM_MAX_PATH];
static char group_[255];
for(int i = 0; i < GetArraySize(g_NominateList); i++)
{
GetArrayString(g_NominateList, i, map_, PLATFORM_MAX_PATH);
int tmp = InternalGetMapGroup(map_, group_, sizeof(group_));
if(tmp == groupmax && StrEqual(group, group_))
groupcur++;
}
if(groupcur >= groupmax)
{
// Check if client has nominated a map in the same group and can change their nomination
if(client > 0 && client < MaxClients)
{
int index = FindValueInArray(g_NominateOwners, client);
if(index != -1)
{
static char oldmap[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH);
char oldgroup[255];
int tmp = InternalGetMapGroup(oldmap, oldgroup, sizeof(oldgroup));
if(tmp == groupmax && StrEqual(group, group_))
return -321;
}
}
return groupmax;
}
return -123;
}
return groupmax;
}
stock void AddMapItem(const char[] map)
{
if(g_NativeVotes)
@@ -2319,6 +2408,33 @@ stock int InternalGetMapMaxPlayers(const char[] map)
return MaxPlayers;
}
stock int InternalGetMapGroup(const char[] map, char[] group, int size)
{
if(g_Config && g_Config.JumpToKey("_groups"))
{
if(!g_Config.GotoFirstSubKey(false))
{
g_Config.Rewind();
return -999;
}
do
{
int ret = g_Config.GetNum("_max", 1);
g_Config.GetSectionName(group, size);
if(g_Config.JumpToKey(map, false))
{
g_Config.Rewind();
return ret;
}
} while(g_Config.GotoNextKey());
g_Config.Rewind();
}
return -999;
}
// 0 = Okay
// >0 = Minutes till Okay
stock int InternalGetMapTimeRestriction(const char[] map)