121 packet.
no = pvote->
no;
163 struct vote *pvote,
bool passed)
256 const struct player *pplayer, *caller_plr;
260 if (!pplayer || !caller_plr
273 const struct vote *pvote)
285 const struct player *pplayer, *caller_plr;
289 if (!pplayer || !caller_plr
308 if (pvote->vote_no ==
vote_no) {
326 if (pvote->caller_id == caller->
id) {
359 if (allargs != NULL && allargs[0] !=
'\0') {
375 double min_pc = 1.0 / (double) num_voters;
377 if (num_voters > 1 && min_pc > pvote->
need_pc) {
394 struct vote virtual_vote;
403 memset(&virtual_vote, 0,
sizeof(virtual_vote));
422 int num_cast = 0, num_voters = 0;
425 double yes_pc = 0.0, no_pc = 0.0, rem_pc = 0.0,
base = 0.0;
429 const double MY_EPSILON = 0.000001;
431 const struct player *callplr;
450 switch (pvc->vote_cast) {
464 log_error(
"Unknown vote cast variant: %d.", pvc->vote_cast);
472 if (num_voters > 0) {
478 if (
base > MY_EPSILON) {
479 yes_pc = (double) pvote->
yes /
base;
480 no_pc = (double) pvote->
no /
base;
483 rem_pc = (double) (num_voters - num_cast) /
base;
492 (yes_pc - need_pc > MY_EPSILON)
494 || (no_pc - 1.0 + need_pc > MY_EPSILON
495 || fabs(no_pc - 1.0 + need_pc) < MY_EPSILON)
497 || (no_pc + rem_pc - 1.0 + need_pc < -MY_EPSILON)
499 || (yes_pc + rem_pc - need_pc < -MY_EPSILON
500 || fabs(yes_pc + rem_pc - need_pc) < MY_EPSILON));
504 if (!resolve && fabs(rem_pc) < MY_EPSILON) {
514 if (!resolve && fabs(
base) < MY_EPSILON) {
519 log_debug(
"check_vote flags=%d need_pc=%0.2f yes_pc=%0.2f "
520 "no_pc=%0.2f rem_pc=%0.2f base=%0.2f resolve=%d",
521 flags, need_pc, yes_pc, no_pc, rem_pc,
base, resolve);
529 passed = yes_pc - need_pc > MY_EPSILON;
532 passed = fabs(no_pc) < MY_EPSILON;
551 _(
"%s %d \"%s\" is passed %d to %d with "
552 "%d abstentions and %d who did not vote."),
554 pvote->
no, pvote->
abstain, num_voters - num_cast);
558 _(
"%s %d \"%s\" failed with %d against, %d for, "
559 "%d abstentions and %d who did not vote."),
561 pvote->
yes, pvote->
abstain, num_voters - num_cast);
568 log_error(
"Got a vote from a lost connection");
571 log_error(
"Got a vote from a non-voting connection");
575 switch (pvc->vote_cast) {
578 _(
"%s %d: %s voted yes."),
583 _(
"%s %d: %s voted no."),
588 _(
"%s %d: %s chose to abstain."),
641 vote_cast_list_append(pvote->
votes_cast, pvc);
651 if (!pvote || !pvc) {
655 vote_cast_list_remove(pvote->
votes_cast, pvc);
681 log_error(
"Failed to create a vote cast for connection %s.",
721 log_error(
"voting_turn() called before voting_init()");
758 _(
"%s (needs %0.0f%% and no dissent)."),
764 _(
"%s (needs %0.0f%% in favor)."),
780 log_debug(
"Got vote submit (%d %d) from %s.",
787 log_verbose(
"Submit request for unknown vote_no %d from %s ignored.",
794 }
else if (value == -1) {
796 }
else if (value == 0) {
799 log_error(
"Invalid packet data for submit of vote %d "
819 log_debug(
"Sending %s running votes to %s.",
829 }
else if (!only_team_votes) {
850 log_debug(
"Sending remove info of the team votes to %s.",
874 log_debug(
"Sending updated vote totals to conn_list %p", dest);
const char * command_name(const struct command *pcommand)
int command_vote_percent(const struct command *pcommand)
const struct command * command_by_number(int i)
int command_vote_flags(const struct command *pcommand)
struct player * conn_get_player(const struct connection *pconn)
void conn_list_do_unbuffer(struct conn_list *dest)
void conn_list_do_buffer(struct conn_list *dest)
void connection_do_buffer(struct connection *pc)
bool conn_controls_player(const struct connection *pconn)
bool conn_is_global_observer(const struct connection *pconn)
const char * conn_description(const struct connection *pconn)
struct connection * conn_by_number(int id)
enum cmdlevel conn_get_access(const struct connection *pconn)
void connection_do_unbuffer(struct connection *pc)
#define conn_list_iterate(connlist, pconn)
#define conn_list_iterate_end
#define MAX_LEN_CONSOLE_LINE
static void base(QVariant data1, QVariant data2)
const struct ft_color ftc_vote_abstain
const struct ft_color ftc_vote_failed
const struct ft_color ftc_vote_yes
const struct ft_color ftc_vote_no
const struct ft_color ftc_vote_passed
#define log_verbose(message,...)
#define fc_assert(condition)
#define log_debug(message,...)
#define log_error(message,...)
void notify_team(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
int send_packet_vote_resolve(struct connection *pc, const struct packet_vote_resolve *packet)
int send_packet_vote_remove(struct connection *pc, const struct packet_vote_remove *packet)
int send_packet_vote_update(struct connection *pc, const struct packet_vote_update *packet)
int send_packet_vote_new(struct connection *pc, const struct packet_vote_new *packet)
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
bool handle_stdin_input(struct connection *caller, char *str)
struct conn_list * est_connections
char username[MAX_LEN_NAME]
struct vote_cast_list * votes_cast
int fc_snprintf(char *str, size_t n, const char *format,...)
#define sz_strlcpy(dest, src)
#define sz_strlcat(dest, src)
void send_running_votes(struct connection *pconn, bool only_team_votes)
static void lsend_vote_new(struct conn_list *dest, struct vote *pvote)
void send_remove_team_votes(struct connection *pconn)
int describe_vote(struct vote *pvote, char *buf, int buflen)
static void lsend_vote_remove(struct conn_list *dest, struct vote *pvote)
bool conn_can_vote(const struct connection *pconn, const struct vote *pvote)
static void check_vote(struct vote *pvote)
struct vote * vote_new(struct connection *caller, const char *allargs, int command_id)
bool vote_is_team_only(const struct vote *pvote)
void cancel_connection_votes(struct connection *pconn)
struct vote * get_vote_by_no(int vote_no)
bool vote_would_pass_immediately(const struct connection *caller, int command_id)
void send_updated_vote_totals(struct conn_list *dest)
void handle_vote_submit(struct connection *pconn, int vote_no, int value)
static void lsend_vote_resolve(struct conn_list *dest, struct vote *pvote, bool passed)
void clear_all_votes(void)
struct vote * get_vote_by_caller(const struct connection *caller)
static void lsend_vote_update(struct conn_list *dest, struct vote *pvote, int num_voters)
static void free_vote(struct vote *pvote)
static struct vote_cast * vote_cast_find(struct vote *pvote, int conn_id)
void connection_vote(struct connection *pconn, struct vote *pvote, enum vote_type type)
struct vote_list * vote_list
const struct connection * vote_get_caller(const struct vote *pvote)
int count_voters(const struct vote *pvote)
static void remove_vote_cast(struct vote *pvote, struct vote_cast *pvc)
void remove_vote(struct vote *pvote)
static struct vote_cast * vote_cast_new(struct vote *pvote)
bool conn_can_see_vote(const struct connection *pconn, const struct vote *pvote)
#define vote_list_iterate_end
#define vote_cast_list_iterate(alist, pvc)
#define vote_list_iterate(alist, pvote)
#define vote_cast_list_iterate_end