Skip to content

Commit 0bf019d

Browse files
authored
Merge pull request #1265 from rtldg/prioritize-special-in-mapchooser
2 parents 72a23e6 + cceba51 commit 0bf019d

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

addons/sourcemod/scripting/shavit-mapchooser.sp

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Convar g_cvAutocompletePrefixes;
7171
Convar g_cvMapVoteStartTime;
7272
Convar g_cvMapVoteDuration;
7373
Convar g_cvMapVoteBlockMapInterval;
74+
Convar g_cvMapVotePrioritizeSpecial;
7475
Convar g_cvMapVoteExtendLimit;
7576
Convar g_cvMapVoteEnableNoVote;
7677
Convar g_cvMapVoteEnableReRoll;
@@ -207,6 +208,7 @@ public void OnPluginStart()
207208
g_cvAutocompletePrefixes = new Convar("smc_autocomplete_prefixes", "bhop_,surf_,kz_,kz_bhop_,bhop_kz_,xc_,trikz_,jump_,rj_", "Some prefixes that are attempted when using !map");
208209

209210
g_cvMapVoteBlockMapInterval = new Convar("smc_mapvote_blockmap_interval", "1", "How many maps should be played before a map can be nominated again", _, true, 0.0, false);
211+
g_cvMapVotePrioritizeSpecial = new Convar("smc_mapvote_prioritize_special", "1", "Whether to prioritize extend, dontchange, and reroll for ties.", _, true, 0.0, true, 1.0);
210212
g_cvMapVoteEnableNoVote = new Convar("smc_mapvote_enable_novote", "1", "Whether players are able to choose 'No Vote' in map vote", _, true, 0.0, true, 1.0);
211213
g_cvMapVoteEnableReRoll = new Convar("smc_mapvote_enable_reroll", "0", "Whether players are able to choose 'ReRoll' in map vote", _, true, 0.0, true, 1.0);
212214
g_cvMapVoteExtendLimit = new Convar("smc_mapvote_extend_limit", "3", "How many times players can choose to extend a single map (0 = block extending, -1 = infinite extending)", _, true, -1.0, false);
@@ -896,12 +898,50 @@ public Action Timer_StartMapVote(Handle timer, DataPack data)
896898
return Plugin_Stop;
897899
}
898900

901+
// If for example a map & extend have the same number of votes, then we want to pick extend.
902+
int PrioritizeSpecialItem(Menu menu, int num_items, const int[][] item_info)
903+
{
904+
if (!g_cvMapVotePrioritizeSpecial.BoolValue)
905+
{
906+
return 0;
907+
}
908+
909+
int maxvotes = item_info[0][VOTEINFO_ITEM_VOTES];
910+
int last_index_with_maxvotes = 0;
911+
912+
for (int i = 1; i < num_items; ++i)
913+
{
914+
if (item_info[i][VOTEINFO_ITEM_VOTES] == maxvotes)
915+
{
916+
last_index_with_maxvotes = i;
917+
}
918+
}
919+
920+
if (last_index_with_maxvotes > 0)
921+
{
922+
for (int i = 0; i < last_index_with_maxvotes+1; ++i)
923+
{
924+
char map[32];
925+
menu.GetItem(item_info[i][VOTEINFO_ITEM_INDEX], map, sizeof(map));
926+
927+
if (StrEqual(map, "extend") || StrEqual(map, "dontchange") || StrEqual(map, "reroll"))
928+
{
929+
return i;
930+
}
931+
}
932+
}
933+
934+
return 0;
935+
}
936+
899937
public void Handler_VoteFinishedGeneric(Menu menu, int num_votes, int num_clients, const int[][] client_info, int num_items, const int[][] item_info)
900938
{
901939
char map[PLATFORM_MAX_PATH];
902940
char displayName[PLATFORM_MAX_PATH];
903941

904-
menu.GetItem(item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map), _, displayName, sizeof(displayName));
942+
int item = PrioritizeSpecialItem(menu, num_items, item_info);
943+
944+
menu.GetItem(item_info[item][VOTEINFO_ITEM_INDEX], map, sizeof(map), _, displayName, sizeof(displayName));
905945

906946
//PrintToChatAll("#1 vote was %s (%s)", map, (g_ChangeTime == MapChange_Instant) ? "instant" : "map end");
907947

@@ -918,7 +958,7 @@ public void Handler_VoteFinishedGeneric(Menu menu, int num_votes, int num_client
918958
}
919959
}
920960

921-
PrintToChatAll("%s%t", g_cPrefix, "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
961+
PrintToChatAll("%s%t", g_cPrefix, "Current Map Extended", RoundToFloor(float(item_info[item][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
922962
LogAction(-1, -1, "Voting for next map has finished. The current map has been extended.");
923963

924964
// We extended, so we'll have to vote again.
@@ -929,7 +969,7 @@ public void Handler_VoteFinishedGeneric(Menu menu, int num_votes, int num_client
929969
}
930970
else if(StrEqual(map, "dontchange"))
931971
{
932-
PrintToChatAll("%s%t", g_cPrefix, "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
972+
PrintToChatAll("%s%t", g_cPrefix, "Current Map Stays", RoundToFloor(float(item_info[item][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
933973
LogAction(-1, -1, "Voting for next map has finished. 'No Change' was the winner");
934974

935975
g_bMapVoteFinished = false;
@@ -941,7 +981,7 @@ public void Handler_VoteFinishedGeneric(Menu menu, int num_votes, int num_client
941981
else if (StrEqual(map, "reroll"))
942982
{
943983

944-
PrintToChatAll("%s%t", g_cPrefix, "ReRolling Maps", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
984+
PrintToChatAll("%s%t", g_cPrefix, "ReRolling Maps", RoundToFloor(float(item_info[item][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
945985
LogAction(-1, -1, "Voting for next map has restarted. Reroll complete.");
946986

947987
g_bMapVoteStarted = false;
@@ -952,7 +992,7 @@ public void Handler_VoteFinishedGeneric(Menu menu, int num_votes, int num_client
952992
}
953993
else
954994
{
955-
int percentage_of_votes = RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100);
995+
int percentage_of_votes = RoundToFloor(float(item_info[item][VOTEINFO_ITEM_VOTES])/float(num_votes)*100);
956996
DoMapChangeAfterMapVote(map, displayName, percentage_of_votes, num_votes);
957997
}
958998
}

0 commit comments

Comments
 (0)