mapchooser_extended: multiple groups per map support GROUPS CAN NOW ONLY HAVE NUMBERS AS THEIR NAME!!!
This commit is contained in:
		
							parent
							
								
									ef5e739376
								
							
						
					
					
						commit
						ea03209f15
					
				| @ -2,7 +2,7 @@ | |||||||
| { | { | ||||||
| 	"_groups" | 	"_groups" | ||||||
| 	{ | 	{ | ||||||
| 		"final_fantasy" | 		"1" // final fantasy | ||||||
| 		{ | 		{ | ||||||
| 			"_max" "2" | 			"_max" "2" | ||||||
| 			"ze_ffvii_cosmo_canyon_v1beta1" {} | 			"ze_ffvii_cosmo_canyon_v1beta1" {} | ||||||
| @ -32,7 +32,7 @@ | |||||||
| 			"ze_FFXIV_Wanderers_Palace_v5_2f" {} | 			"ze_FFXIV_Wanderers_Palace_v5_2f" {} | ||||||
| 			"ze_FFVII_Temple_Ancient_v3_3" {} | 			"ze_FFVII_Temple_Ancient_v3_3" {} | ||||||
| 		} | 		} | ||||||
| 		"cosmo" | 		"2" // cosmo | ||||||
| 		{ | 		{ | ||||||
| 			"_max" "1" | 			"_max" "1" | ||||||
| 			"ze_ffvii_cosmo_canyon_v1beta1" {} | 			"ze_ffvii_cosmo_canyon_v1beta1" {} | ||||||
| @ -42,7 +42,7 @@ | |||||||
| 			"ze_ffvii_cosmo_canyon_v5test2" {} | 			"ze_ffvii_cosmo_canyon_v5test2" {} | ||||||
| 			"ze_ffvii_cosmo_canyon_v5fix" {} | 			"ze_ffvii_cosmo_canyon_v5fix" {} | ||||||
| 		} | 		} | ||||||
| 		"wester" | 		"3" // wester | ||||||
| 		{ | 		{ | ||||||
| 			"_max" "1" | 			"_max" "1" | ||||||
| 			"ze_ffxii_westersand_v2_11a" {} | 			"ze_ffxii_westersand_v2_11a" {} | ||||||
| @ -51,7 +51,7 @@ | |||||||
| 			"ze_FFXII_Westersand_v7" {} | 			"ze_FFXII_Westersand_v7" {} | ||||||
| 			"ze_FFXII_Westersand_v7_2" {} | 			"ze_FFXII_Westersand_v7_2" {} | ||||||
| 		} | 		} | ||||||
| 		"mako" | 		"4" // mako | ||||||
| 		{ | 		{ | ||||||
| 			"_max" "1" | 			"_max" "1" | ||||||
| 			"ze_FFVII_Mako_Reactor_b2" {} | 			"ze_FFVII_Mako_Reactor_b2" {} | ||||||
| @ -60,20 +60,20 @@ | |||||||
| 			"ze_FFVII_Mako_Reactor_v5_3" {} | 			"ze_FFVII_Mako_Reactor_v5_3" {} | ||||||
| 			"ZE_FFVII_Mako_Reactor_V6_B08" {} | 			"ZE_FFVII_Mako_Reactor_V6_B08" {} | ||||||
| 		} | 		} | ||||||
| 		"wanderes" | 		"5" // wanderes | ||||||
| 		{ | 		{ | ||||||
| 			"_max" "1" | 			"_max" "1" | ||||||
| 			"ze_ffxiv_wanderers_palace_css" {} | 			"ze_ffxiv_wanderers_palace_css" {} | ||||||
| 			"ze_ffxiv_wanderers_palace_v4_5s" {} | 			"ze_ffxiv_wanderers_palace_v4_5s" {} | ||||||
| 			"ze_FFXIV_Wanderers_Palace_v5_2f" {} | 			"ze_FFXIV_Wanderers_Palace_v5_2f" {} | ||||||
| 		} | 		} | ||||||
| 		"minas" | 		"6" // minas | ||||||
| 		{ | 		{ | ||||||
| 			"_max" "1" | 			"_max" "1" | ||||||
| 			"ze_lotr_minas_tirith_v2_2fix" {} | 			"ze_lotr_minas_tirith_v2_2fix" {} | ||||||
| 			"ze_lotr_minas_tirith_v3_3" {} | 			"ze_lotr_minas_tirith_v3_3" {} | ||||||
| 		} | 		} | ||||||
| 		"rooftop" | 		"7" // rooftop | ||||||
| 		{ | 		{ | ||||||
| 			"_max" "2" | 			"_max" "2" | ||||||
| 			"ze_gargantua_v2_0" {} | 			"ze_gargantua_v2_0" {} | ||||||
|  | |||||||
| @ -122,9 +122,9 @@ native int GetMapTimeRestriction(const char[] map); | |||||||
| // >0 = More than MaxPlayers
 | // >0 = More than MaxPlayers
 | ||||||
| native int GetMapPlayerRestriction(const char[] map); | native int GetMapPlayerRestriction(const char[] map); | ||||||
| 
 | 
 | ||||||
| // <0 = No group
 | // <=0 = No group
 | ||||||
| // >=0 = Group _max
 | // >0 = Groups found
 | ||||||
| native int GetMapGroup(const char[] map, char[] group, int size); | native int GetMapGroups(const char[] map, int[] groups, int size); | ||||||
| 
 | 
 | ||||||
| // <0 = No restriction
 | // <0 = No restriction
 | ||||||
| // >=0 = Group _max -> Group full
 | // >=0 = Group _max -> Group full
 | ||||||
|  | |||||||
| @ -408,7 +408,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max | |||||||
| 	CreateNative("GetMapMaxPlayers", Native_GetMapMaxPlayers); | 	CreateNative("GetMapMaxPlayers", Native_GetMapMaxPlayers); | ||||||
| 	CreateNative("GetMapTimeRestriction", Native_GetMapTimeRestriction); | 	CreateNative("GetMapTimeRestriction", Native_GetMapTimeRestriction); | ||||||
| 	CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction); | 	CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction); | ||||||
| 	CreateNative("GetMapGroup", Native_GetMapGroup); | 	CreateNative("GetMapGroups", Native_GetMapGroups); | ||||||
| 	CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction); | 	CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction); | ||||||
| 
 | 
 | ||||||
| 	return APLRes_Success; | 	return APLRes_Success; | ||||||
| @ -1659,9 +1659,28 @@ void CreateNextVote() | |||||||
| 	int voteSize = GetVoteSize(2); | 	int voteSize = GetVoteSize(2); | ||||||
| 	int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps)); | 	int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps)); | ||||||
| 
 | 
 | ||||||
| 	StringMap groups = new StringMap(); | 	// group -> number of maps nominated from group | ||||||
| 	char group[255]; | 	StringMap groupmap = new StringMap(); | ||||||
|  | 	char groupstr[8]; | ||||||
| 
 | 
 | ||||||
|  | 	// populate groupmap with maps from nomination list | ||||||
|  | 	static char map_[PLATFORM_MAX_PATH]; | ||||||
|  | 	int groups_[32]; | ||||||
|  | 	for(int i = 0; i < GetArraySize(g_NominateList); i++) | ||||||
|  | 	{ | ||||||
|  | 		GetArrayString(g_NominateList, i, map_, PLATFORM_MAX_PATH); | ||||||
|  | 		int groupsfound = InternalGetMapGroups(map_, groups_, sizeof(groups_)); | ||||||
|  | 		for(int group = 0; group < groupsfound; group++) | ||||||
|  | 		{ | ||||||
|  | 			IntToString(group, groupstr, sizeof(groupstr)); | ||||||
|  | 			int groupcur = 0; | ||||||
|  | 			groupmap.GetValue(groupstr, groupcur); | ||||||
|  | 			groupcur++; | ||||||
|  | 			groupmap.SetValue(groupstr, groupcur, true); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// find random maps which honor all restrictions | ||||||
| 	for(int i = 0; i < limit; i++) | 	for(int i = 0; i < limit; i++) | ||||||
| 	{ | 	{ | ||||||
| 		int b; | 		int b; | ||||||
| @ -1673,23 +1692,39 @@ void CreateNextVote() | |||||||
| 			if(InternalGetMapPlayerRestriction(map) == 0) | 			if(InternalGetMapPlayerRestriction(map) == 0) | ||||||
| 				break; | 				break; | ||||||
| 
 | 
 | ||||||
| 			int groupmax = InternalGetMapGroup(map, group, sizeof(group)); | 			bool okay = true; | ||||||
|  | 
 | ||||||
|  | 			int groups[32]; | ||||||
|  | 			int groupsfound = InternalGetMapGroups(map, groups, sizeof(groups)); | ||||||
|  | 			for(int group = 0; group < groupsfound; group++) | ||||||
|  | 			{ | ||||||
|  | 				IntToString(group, groupstr, sizeof(groupstr)); | ||||||
|  | 
 | ||||||
|  | 				int groupmax = InternalGetGroupMax(groups[group]); | ||||||
| 				if(groupmax >= 0) | 				if(groupmax >= 0) | ||||||
| 				{ | 				{ | ||||||
| 					int groupcur = 0; | 					int groupcur = 0; | ||||||
| 				groups.GetValue(group, groupcur); | 					groupmap.GetValue(groupstr, groupcur); | ||||||
| 
 | 
 | ||||||
| 					if(groupcur >= groupmax) | 					if(groupcur >= groupmax) | ||||||
|  | 					{ | ||||||
|  | 						okay = false; | ||||||
| 						break; | 						break; | ||||||
| 				groupcur++; |  | ||||||
| 				groups.SetValue(group, groupcur, true); |  | ||||||
| 					} | 					} | ||||||
|  | 
 | ||||||
|  | 					groupcur++; | ||||||
|  | 					groupmap.SetValue(groupstr, groupcur, true); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			if(okay) | ||||||
|  | 				break; | ||||||
| 		} | 		} | ||||||
| 		PushArrayString(g_NextMapList, map); | 		PushArrayString(g_NextMapList, map); | ||||||
| 		RemoveFromArray(tempMaps, b); | 		RemoveFromArray(tempMaps, b); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	delete groups; | 	delete groupmap; | ||||||
| 	CloseHandle(tempMaps); | 	CloseHandle(tempMaps); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -2177,7 +2212,7 @@ public int Native_GetMapPlayerRestriction(Handle plugin, int numParams) | |||||||
| 	return InternalGetMapPlayerRestriction(map); | 	return InternalGetMapPlayerRestriction(map); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| public int Native_GetMapGroup(Handle plugin, int numParams) | public int Native_GetMapGroups(Handle plugin, int numParams) | ||||||
| { | { | ||||||
| 	int len; | 	int len; | ||||||
| 	GetNativeStringLength(1, len); | 	GetNativeStringLength(1, len); | ||||||
| @ -2189,11 +2224,11 @@ public int Native_GetMapGroup(Handle plugin, int numParams) | |||||||
| 	char[] map = new char[len+1]; | 	char[] map = new char[len+1]; | ||||||
| 	GetNativeString(1, map, len+1); | 	GetNativeString(1, map, len+1); | ||||||
| 
 | 
 | ||||||
| 	char[] group = new char[size]; | 	int[] groups = new int[size]; | ||||||
| 	int groupmax = InternalGetMapGroup(map, group, size); | 	int found = InternalGetMapGroups(map, groups, size); | ||||||
| 	if(groupmax >= 0) | 	if(found >= 0) | ||||||
| 		SetNativeString(2, group, size); | 		SetNativeArray(2, groups, size); | ||||||
| 	return groupmax; | 	return found; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| public int Native_GetMapGroupRestriction(Handle plugin, int numParams) | public int Native_GetMapGroupRestriction(Handle plugin, int numParams) | ||||||
| @ -2208,24 +2243,30 @@ public int Native_GetMapGroupRestriction(Handle plugin, int numParams) | |||||||
| 	char[] map = new char[len+1]; | 	char[] map = new char[len+1]; | ||||||
| 	GetNativeString(1, map, len+1); | 	GetNativeString(1, map, len+1); | ||||||
| 
 | 
 | ||||||
| 	static char group[255]; | 	int groups[32]; | ||||||
| 	int groupmax = InternalGetMapGroup(map, group, sizeof(group)); | 	int groupsfound = InternalGetMapGroups(map, groups, sizeof(groups)); | ||||||
|  | 
 | ||||||
|  | 	for(int group = 0; group < groupsfound; group ++) | ||||||
|  | 	{ | ||||||
| 		int groupcur = 0; | 		int groupcur = 0; | ||||||
|  | 		int groupmax = InternalGetGroupMax(groups[group]); | ||||||
|  | 
 | ||||||
| 		if(groupmax >= 0) | 		if(groupmax >= 0) | ||||||
| 		{ | 		{ | ||||||
| 			static char map_[PLATFORM_MAX_PATH]; | 			static char map_[PLATFORM_MAX_PATH]; | ||||||
| 		static char group_[255]; | 			int groups_[32]; | ||||||
| 			for(int i = 0; i < GetArraySize(g_NominateList); i++) | 			for(int i = 0; i < GetArraySize(g_NominateList); i++) | ||||||
| 			{ | 			{ | ||||||
| 				GetArrayString(g_NominateList, i, map_, PLATFORM_MAX_PATH); | 				GetArrayString(g_NominateList, i, map_, PLATFORM_MAX_PATH); | ||||||
| 			int tmp = InternalGetMapGroup(map_, group_, sizeof(group_)); | 				int tmp = InternalGetMapGroups(map_, groups_, sizeof(groups_)); | ||||||
| 			if(tmp == groupmax && StrEqual(group, group_)) | 				if(FindIntInArray(groups_, tmp, groups[group]) != -1) | ||||||
| 					groupcur++; | 					groupcur++; | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			if(groupcur >= groupmax) | 			if(groupcur >= groupmax) | ||||||
| 			{ | 			{ | ||||||
| 				// Check if client has nominated a map in the same group and can change their nomination | 				// Check if client has nominated a map in the same group and can change their nomination | ||||||
|  | 				bool okay = false; | ||||||
| 				if(client > 0 && client < MaxClients) | 				if(client > 0 && client < MaxClients) | ||||||
| 				{ | 				{ | ||||||
| 					int index = FindValueInArray(g_NominateOwners, client); | 					int index = FindValueInArray(g_NominateOwners, client); | ||||||
| @ -2233,20 +2274,20 @@ public int Native_GetMapGroupRestriction(Handle plugin, int numParams) | |||||||
| 					{ | 					{ | ||||||
| 						static char oldmap[PLATFORM_MAX_PATH]; | 						static char oldmap[PLATFORM_MAX_PATH]; | ||||||
| 						GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH); | 						GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH); | ||||||
| 					char oldgroup[255]; | 						static int oldgroups[32]; | ||||||
| 					int tmp = InternalGetMapGroup(oldmap, oldgroup, sizeof(oldgroup)); | 						int tmp = InternalGetMapGroups(oldmap, oldgroups, sizeof(oldgroups)); | ||||||
| 					if(tmp == groupmax && StrEqual(group, group_)) | 						if(FindIntInArray(groups_, tmp, groups[group]) != -1) | ||||||
| 						return -321; | 							okay = true; | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
|  | 				if(!okay) | ||||||
| 					return groupmax; | 					return groupmax; | ||||||
| 			} | 			} | ||||||
| 
 | 		} | ||||||
| 		return -123; |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return groupmax; | 	return -1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -2433,8 +2474,9 @@ stock int InternalGetMapMaxPlayers(const char[] map) | |||||||
| 	return MaxPlayers; | 	return MaxPlayers; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| stock int InternalGetMapGroup(const char[] map, char[] group, int size) | stock int InternalGetMapGroups(const char[] map, int[] groups, int size) | ||||||
| { | { | ||||||
|  | 	int found = 0; | ||||||
| 	if(g_Config && g_Config.JumpToKey("_groups")) | 	if(g_Config && g_Config.JumpToKey("_groups")) | ||||||
| 	{ | 	{ | ||||||
| 		if(!g_Config.GotoFirstSubKey(false)) | 		if(!g_Config.GotoFirstSubKey(false)) | ||||||
| @ -2445,19 +2487,44 @@ stock int InternalGetMapGroup(const char[] map, char[] group, int size) | |||||||
| 
 | 
 | ||||||
| 		do | 		do | ||||||
| 		{ | 		{ | ||||||
| 			int ret = g_Config.GetNum("_max", 1); | 			char groupstr[8]; | ||||||
| 			g_Config.GetSectionName(group, size); | 			g_Config.GetSectionName(groupstr, sizeof(groupstr)); | ||||||
|  | 			int group = StringToInt(groupstr); | ||||||
| 			if(g_Config.JumpToKey(map, false)) | 			if(g_Config.JumpToKey(map, false)) | ||||||
|  | 			{ | ||||||
|  | 				groups[found++] = group; | ||||||
|  | 				if(found >= size) | ||||||
| 				{ | 				{ | ||||||
| 					g_Config.Rewind(); | 					g_Config.Rewind(); | ||||||
| 				return ret; | 					return found; | ||||||
|  | 				} | ||||||
|  | 				g_Config.GoBack(); | ||||||
| 			} | 			} | ||||||
| 		} while(g_Config.GotoNextKey()); | 		} while(g_Config.GotoNextKey()); | ||||||
| 
 | 
 | ||||||
| 		g_Config.Rewind(); | 		g_Config.Rewind(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return -999; | 	return found; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | stock int InternalGetGroupMax(int group) | ||||||
|  | { | ||||||
|  | 	char groupstr[8]; | ||||||
|  | 	IntToString(group, groupstr, sizeof(groupstr)); | ||||||
|  | 	if(g_Config && g_Config.JumpToKey("_groups")) | ||||||
|  | 	{ | ||||||
|  | 		if(g_Config.JumpToKey(groupstr, false)) | ||||||
|  | 		{ | ||||||
|  | 			int max = g_Config.GetNum("_max", -1); | ||||||
|  | 			g_Config.Rewind(); | ||||||
|  | 			return max; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		g_Config.Rewind(); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return -1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // 0 = Okay | // 0 = Okay | ||||||
| @ -2509,3 +2576,14 @@ stock int InternalGetMapPlayerRestriction(const char[] map) | |||||||
| 
 | 
 | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | stock int FindIntInArray(int[] array, int size, int value) | ||||||
|  | { | ||||||
|  | 	for(int i = 0; i < size; i++) | ||||||
|  | 	{ | ||||||
|  | 		if(array[i] == value) | ||||||
|  | 			return i; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return -1; | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user