qboolean _iCheckConfigVotes (void) { static qboolean enough = false; float p; configlist_t *tmp; if (!config_need_to_check_votes) return (enough); tmp = ConfigWithMostVotes (&p); enough = (tmp != NULL && p >= (float) (cvote_pass->value / 100.0f)); if (config_num_clients < cvote_min->value) enough = false; if (cvote_need->value) { if ((float) ((float)config_num_votes / (float)config_num_clients) < (float)(cvote_need->value / 100.0f)) enough = false; } config_need_to_check_votes = false; return (enough); }
qboolean _ConfigMostVotesStr (char *buf) { float p_most = 0.0f; configlist_t *most; most = ConfigWithMostVotes (&p_most); if (most != NULL) { sprintf (buf, "%s (%.2f%%)", most->configname, p_most * 100.0); return true; } else strcpy (buf, "(no config)"); return false; }
void _ConfigExitLevel (char *NextMap) { configlist_t *voteconfig = NULL; char buf[MAX_STR_LEN]; if (_iCheckConfigVotes ()) { voteconfig = ConfigWithMostVotes (NULL); gi.bprintf (PRINT_HIGH, "A new config was voted on and is %s.\n", voteconfig->configname); Com_sprintf (buf, sizeof (buf), "exec \"mode_%s.cfg\"\n", voteconfig->configname); //clear stats for (voteconfig = config_votes; voteconfig != NULL; voteconfig = voteconfig->next) { voteconfig->num_votes = 0; } //clear stats config_num_votes = 0; config_num_clients = 0; config_need_to_check_votes = true; gi.AddCommandString (buf); } else { //clear stats for (voteconfig = config_votes; voteconfig != NULL; voteconfig = voteconfig->next) { voteconfig->num_votes = 0; } //clear stats config_num_votes = 0; config_num_clients = 0; config_need_to_check_votes = true; } }
void Cmd_Configlist_f(edict_t *ent) { //go through the votelist and list out all the configs and % votes int lines, chars_on_line, len_mr; float p_test, p_most; configlist_t *search, *most; char msg_buf[MAX_STRING_CHARS], tmp_buf[128]; //only 40 are used if (!use_cvote->value) { gi.cprintf(ent, PRINT_HIGH, "Config voting is disabled.\n"); return; } p_test = p_most = 0.0; most = ConfigWithMostVotes (&p_most); sprintf (msg_buf, "List of configs that can be voted on:\nRequire more than %d%% votes (%.2f)\n\n", (int) cvote_pass->value, (float) ((float) cvote_pass->value / 100.0)); lines = chars_on_line = 0; for (search = config_votes; search != NULL; search = search->next) { if (config_num_clients > 0) p_test = (float)((float) search->num_votes / (float) config_num_clients); if (p_test >= 10.0) len_mr = 11; else len_mr = 10; len_mr += strlen (search->configname); if ((chars_on_line + len_mr + 2) > 39) { Q_strncatz (msg_buf, "\n", sizeof(msg_buf)); lines++; chars_on_line = 0; if (lines > 25) break; } sprintf (tmp_buf, "%s (%.2f) ", search->configname, p_test); Q_strncatz (msg_buf, tmp_buf, sizeof(msg_buf)); chars_on_line += len_mr; } if (config_votes == NULL) Q_strncatz (msg_buf, "None!", sizeof(msg_buf)); else if (most != NULL) { sprintf (tmp_buf, "\n\nMost votes: %s (%.2f)", most->configname, p_most); Q_strncatz (msg_buf, tmp_buf, sizeof(msg_buf)); } Q_strncatz (msg_buf, "\n\n", sizeof(msg_buf)); Com_sprintf (tmp_buf, sizeof(tmp_buf), "%d/%d (%.2f%%) clients voted\n%d client%s minimum (%d%% required)", config_num_votes, config_num_clients, (float) ((float) config_num_votes / (float) (config_num_clients > 0 ? config_num_clients : 1) * 100), (int) cvote_min->value, (cvote_min->value > 1 ? "s" : ""), (int) cvote_need->value); Q_strncatz (msg_buf, tmp_buf, sizeof(msg_buf)); gi.centerprintf (ent, "%s", msg_buf); return; }