int gf_SelectVote (int lp_optionsCount) {
int lv_i;
int lv_i2;
int lv_picked;
while(lv_i <= lp_optionsCount) {
if (lv_i2 < gv_votesFor[lv_i]) { // If the current option being evaluated has more votes than
lv_i2 = gv_votesFor[lv_i]; // the previous selected one, select the current option.
lv_picked = lv_i;
} else if (lv_i2 == gv_votesFor[lv_i]) { // If two options being evaluated are tied, pick at random.
if (RandomInt(0, 1) == 0) {
lv_picked = lv_i;
}
}
DebugMsg("Option (" + IntToString(lv_i) + ") has " + IntToString(gv_votesFor[lv_i]) + " votes");
lv_i += 1;
}
return lv_picked;
}
//--------------------------------------------------------------------------------------------------
// Tally up the votes when they're ready or the timer has expired and select an option.
//--------------------------------------------------------------------------------------------------
bool gt_onVote_Func (bool testConds, bool runActions) {
int lv_modeSelected;
if (gv_votingOn == "Game Mode") {
lv_modeSelected = gf_SelectVote(5);
DebugMsg("Vote Selected: " + IntToString(lv_modeSelected));
if (lv_modeSelected == 1) { // Team Deathmatch
gv_gameMode = "Team Deathmatch";
DebugMsg("Deathmatch Selected!");
gf_SetUpGame(1);
} else if (lv_modeSelected == 3) { // Survival
gv_gameMode = "Survival";
DebugMsg("Survival Selected!");
gf_SetUpGame(3);
} else if (lv_modeSelected == 5) { // Zerg vs Marines
gv_gameMode = "Zerg vs Marines";
DebugMsg("Zerg vs Marines Selected!");
gf_SetUpGame(5);
} else {
gv_gameMode = "Team Deathmatch";
DebugMsg("Mode selected not yet implemented. Defaulting to Team Deathmatch.");
gf_SetUpGame(1);
}
UISetWorldVisible(gv_allPlayers, true);
TriggerEnable(gt_AI, true);
DialogSetVisible(gv_configureGameMenuDialog, gv_allPlayers, false);
UISetFrameVisible(gv_allPlayers, 0, true);
UnitPauseAll(false);
}
gf_ShowDialogs(true);
DialogControlSetPropertyAsText(gv_teamScoreLabel[2], c_triggerControlPropertyText, gv_allPlayers, StringToText("<s val=\"ModCenterSize20Bold\">" + gv_gameMode));
return true;
}
//--------------------------------------------------------------------------------------------------
// Register Vote Timer Event
void gt_onVote_Init () {
TriggerAddEventTimer(gt_onVote, gv_voteTimer);
}
//--------------------------------------------------------------------------------------------------