Freeciv21
Develop your civilization from humble roots to a global empire
voting.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 #include "support.h" // bool type
16 
18  VCF_NONE = 0,
19  VCF_NODISSENT = (1 << 0), // No 'no' votes.'
20  VCF_NOPASSALONE = (1 << 1), /* Can't pass with just one vote for,
21  * when there are multiple voters. */
22  VCF_TEAMONLY = (1 << 2) // Only team members can vote on it.
23 };
24 
26 
27 // Forward declarations.
28 struct connection;
29 struct conn_list;
30 
31 struct vote_cast {
32  enum vote_type vote_cast; // see enum above
33  int conn_id; // user id
34 };
35 
36 #define SPECLIST_TAG vote_cast
37 #define SPECLIST_TYPE struct vote_cast
38 #include "speclist.h"
39 #define vote_cast_list_iterate(alist, pvc) \
40  TYPED_LIST_ITERATE(struct vote_cast, alist, pvc)
41 #define vote_cast_list_iterate_end LIST_ITERATE_END
42 
43 struct vote {
44  int caller_id; // caller connection id
46  char cmdline[512]; // Must match MAX_LEN_CONSOLE_LINE.
47  int turn_count; // Number of turns active.
48  struct vote_cast_list *votes_cast;
49  int vote_no; // place in the queue
50  int yes;
51  int no;
52  int abstain;
53  int flags;
54  double need_pc;
55 };
56 
57 #define SPECLIST_TAG vote
58 #define SPECLIST_TYPE struct vote
59 #include "speclist.h"
60 #define vote_list_iterate(alist, pvote) \
61  TYPED_LIST_ITERATE(struct vote, alist, pvote)
62 #define vote_list_iterate_end LIST_ITERATE_END
63 
64 extern struct vote_list *vote_list;
65 extern int vote_number_sequence;
66 
67 void voting_init();
68 void voting_free();
69 void voting_turn();
70 
71 int count_voters(const struct vote *pvote);
72 void clear_all_votes();
73 void cancel_connection_votes(struct connection *pconn);
74 bool conn_can_vote(const struct connection *pconn, const struct vote *pvote);
75 bool conn_can_see_vote(const struct connection *pconn,
76  const struct vote *pvote);
77 struct vote *get_vote_by_no(int vote_no);
78 void connection_vote(struct connection *pconn, struct vote *pvote,
79  enum vote_type type);
80 struct vote *get_vote_by_caller(const struct connection *caller);
81 void remove_vote(struct vote *pvote);
82 struct vote *vote_new(struct connection *caller, const char *allargs,
83  int command_id);
84 bool vote_would_pass_immediately(const struct connection *caller,
85  int command_id);
86 const struct connection *vote_get_caller(const struct vote *pvote);
87 bool vote_is_team_only(const struct vote *pvote);
88 int describe_vote(struct vote *pvote, char *buf, int buflen);
89 void send_running_votes(struct connection *pconn, bool only_team_votes);
90 void send_remove_team_votes(struct connection *pconn);
91 void send_updated_vote_totals(struct conn_list *dest);
command_id
Definition: commands.h:33
int conn_id
Definition: voting.h:33
enum vote_type vote_cast
Definition: voting.h:32
Definition: voting.h:43
double need_pc
Definition: voting.h:54
int no
Definition: voting.h:51
int turn_count
Definition: voting.h:47
int command_id
Definition: voting.h:45
int caller_id
Definition: voting.h:44
struct vote_cast_list * votes_cast
Definition: voting.h:48
int abstain
Definition: voting.h:52
int yes
Definition: voting.h:50
int flags
Definition: voting.h:53
char cmdline[512]
Definition: voting.h:46
int vote_no
Definition: voting.h:49
void send_running_votes(struct connection *pconn, bool only_team_votes)
Sends a packet_vote_new to pconn for every currently running votes.
Definition: voting.cpp:827
void send_remove_team_votes(struct connection *pconn)
Sends a packet_vote_remove to pconn for every currently running team vote 'pconn' can see.
Definition: voting.cpp:859
int describe_vote(struct vote *pvote, char *buf, int buflen)
Fills the supplied buffer with a string describing the given vote.
Definition: voting.cpp:763
struct vote * vote_new(struct connection *caller, const char *allargs, int command_id)
Create and return a newly allocated vote for the command with id 'command_id' and all arguments in th...
Definition: voting.cpp:344
void voting_turn()
Check running votes.
Definition: voting.cpp:731
vote_type
Definition: voting.h:25
@ VOTE_ABSTAIN
Definition: voting.h:25
@ VOTE_YES
Definition: voting.h:25
@ VOTE_NUM
Definition: voting.h:25
@ VOTE_NO
Definition: voting.h:25
bool conn_can_vote(const struct connection *pconn, const struct vote *pvote)
A user cannot vote if: is not connected access level < basic isn't a player the vote is a team vote a...
Definition: voting.cpp:250
const struct connection * vote_get_caller(const struct vote *pvote)
Returns the connection that called this vote.
Definition: voting.cpp:911
bool vote_is_team_only(const struct vote *pvote)
Returns TRUE if this vote is a "teamvote".
Definition: voting.cpp:237
vote_condition_flags
Definition: voting.h:17
@ VCF_TEAMONLY
Definition: voting.h:22
@ VCF_NOPASSALONE
Definition: voting.h:20
@ VCF_NODISSENT
Definition: voting.h:19
@ VCF_NONE
Definition: voting.h:18
void cancel_connection_votes(struct connection *pconn)
Cancel the votes of a lost or a detached connection.
Definition: voting.cpp:702
int vote_number_sequence
Definition: voting.cpp:37
bool vote_would_pass_immediately(const struct connection *caller, int command_id)
Return whether the vote would pass immediately when the caller will vote for.
Definition: voting.cpp:396
void send_updated_vote_totals(struct conn_list *dest)
Sends a packet_vote_update to every conn in dest.
Definition: voting.cpp:884
void voting_free()
Free all memory used by this module.
Definition: voting.cpp:749
void connection_vote(struct connection *pconn, struct vote *pvote, enum vote_type type)
Make the given connection vote 'type' on 'pvote', and check the vote.
Definition: voting.cpp:675
struct vote_list * vote_list
Definition: voting.cpp:36
struct vote * get_vote_by_caller(const struct connection *caller)
Returns the vote called by 'caller', or nullptr if none exists.
Definition: voting.cpp:323
int count_voters(const struct vote *pvote)
Helper function that returns the current number of eligible voters.
Definition: voting.cpp:42
void clear_all_votes()
Remove all votes.
Definition: voting.cpp:219
void voting_init()
Initialize data structures used by this module.
Definition: voting.cpp:720
void remove_vote(struct vote *pvote)
Remove the given vote and send a vote_remove packet to clients.
Definition: voting.cpp:205
struct vote * get_vote_by_no(int vote_no)
Returns the vote with vote number 'vote_no', or nullptr.
Definition: voting.cpp:303
bool conn_can_see_vote(const struct connection *pconn, const struct vote *pvote)
Usually, all users can see, except in the team vote case.
Definition: voting.cpp:274