Freeciv-3.3
Loading...
Searching...
No Matches
voteinfo.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <time.h>
19
20/* utility */
21#include "log.h"
22
23/* common */
24#include "packets.h"
25
26/* client/include */
27#include "voteinfo_bar_g.h"
28
29/* client */
30#include "client_main.h"
31#include "clinet.h"
32#include "options.h"
33
34#include "voteinfo.h"
35
36
37/* Define struct voteinfo_list type. */
38#define SPECLIST_TAG voteinfo
39#define SPECLIST_TYPE struct voteinfo
40#include "speclist.h"
41#define voteinfo_list_iterate(alist, pitem)\
42 TYPED_LIST_ITERATE(struct voteinfo, alist, pitem)
43#define voteinfo_list_iterate_end LIST_ITERATE_END
44
47
48
49/**********************************************************************/
54{
55 struct voteinfo *vi;
56
58 "%s() called before votinfo_queue_init()!",
60
62 if (vi == NULL) {
63 return;
64 }
65 vi->remove_time = time(NULL);
66}
67
68/**********************************************************************/
73{
74 time_t now;
75 struct voteinfo_list *removed;
76
77 if (voteinfo_queue == NULL) {
78 return;
79 }
80
81 now = time(NULL);
82 removed = voteinfo_list_new();
84 if (vi != NULL && vi->remove_time > 0 && now - vi->remove_time > 2) {
85 voteinfo_list_append(removed, vi);
86 }
88
89 voteinfo_list_iterate(removed, vi) {
90 voteinfo_queue_remove(vi->vote_no);
92
93 if (voteinfo_list_size(removed) > 0) {
95 }
96
97 voteinfo_list_destroy(removed);
98}
99
100/**********************************************************************/
103void voteinfo_queue_remove(int vote_no)
104{
105 struct voteinfo *vi;
106
108 "%s() called before votinfo_queue_init()!",
110
112 if (vi == NULL) {
113 return;
114 }
115
117 free(vi);
118}
119
120/**********************************************************************/
123void voteinfo_queue_add(int vote_no, const char *user, const char *desc,
124 int percent_required, int flags)
125{
126 struct voteinfo *vi;
127
129 "%s() called before votinfo_queue_init()!",
131
132 vi = fc_calloc(1, sizeof(struct voteinfo));
133 vi->vote_no = vote_no;
134 sz_strlcpy(vi->user, user);
135 sz_strlcpy(vi->desc, desc);
136 vi->percent_required = percent_required;
137 vi->flags = flags;
138
142 } else {
144 }
145}
146
147/**********************************************************************/
151{
153 "%s() called before votinfo_queue_init()!",
155
157 if (vi->vote_no == vote_no) {
158 return vi;
159 }
161 return NULL;
162}
163
164/**********************************************************************/
175
176/**********************************************************************/
180{
181 if (voteinfo_queue == NULL) {
182 return;
183 }
184
186 if (vi != NULL) {
187 free(vi);
188 }
190
194}
195
196/**********************************************************************/
202{
203 struct voteinfo *vi;
204 int size;
205
206 if (voteinfo_queue == NULL) {
207 return NULL;
208 }
209
211
212 if (size <= 0) {
213 return NULL;
214 }
215
219 }
220
222
223 if (vi != NULL && pindex != NULL) {
225 }
226
227 return vi;
228}
229
230/**********************************************************************/
235{
236 struct voteinfo *vi;
237 struct packet_vote_submit packet;
238
239 if (!can_client_control()) {
240 return;
241 }
242
244 if (vi == NULL) {
245 return;
246 }
247
248 packet.vote_no = vi->vote_no;
249
250 switch (vote) {
251 case CVT_YES:
252 packet.value = 1;
253 break;
254 case CVT_NO:
255 packet.value = -1;
256 break;
257 case CVT_ABSTAIN:
258 packet.value = 0;
259 break;
260 default:
261 return;
262 break;
263 }
264
266 vi->client_vote = vote;
267}
268
269/**********************************************************************/
273{
274 int size;
275
276 if (voteinfo_queue == NULL) {
277 return;
278 }
279
281
285 }
286}
287
288/**********************************************************************/
292{
294}
295
296/**********************************************************************/
bool can_client_control(void)
bool client_is_observer(void)
struct civclient client
bool client_has_player(void)
char * incite_cost
Definition comments.c:76
void voteinfo_gui_update(void)
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:206
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:209
#define fc_calloc(n, esz)
Definition mem.h:38
struct client_options gui_options
Definition options.c:71
int send_packet_vote_submit(struct connection *pc, const struct packet_vote_submit *packet)
size_t size
Definition specvec.h:72
struct connection conn
Definition client_main.h:96
bool voteinfo_bar_use
Definition options.h:179
bool voteinfo_bar_hide_when_not_player
Definition options.h:181
bool voteinfo_bar_new_at_front
Definition options.h:182
bool voteinfo_bar_always_show
Definition options.h:180
Definition voting.h:46
char desc[512]
Definition voteinfo.h:33
int flags
Definition voteinfo.h:35
int vote_no
Definition voteinfo.h:31
int percent_required
Definition voteinfo.h:34
char user[MAX_LEN_NAME]
Definition voteinfo.h:32
#define sz_strlcpy(dest, src)
Definition support.h:195
void voteinfo_queue_init(void)
Definition voteinfo.c:167
static int voteinfo_queue_current_index
Definition voteinfo.c:46
void voteinfo_queue_delayed_remove(int vote_no)
Definition voteinfo.c:53
void voteinfo_do_vote(int vote_no, enum client_vote_type vote)
Definition voteinfo.c:234
bool voteinfo_bar_can_be_shown(void)
Definition voteinfo.c:299
void voteinfo_queue_remove(int vote_no)
Definition voteinfo.c:103
struct voteinfo * voteinfo_queue_find(int vote_no)
Definition voteinfo.c:150
struct voteinfo * voteinfo_queue_get_current(int *pindex)
Definition voteinfo.c:201
#define voteinfo_list_iterate(alist, pitem)
Definition voteinfo.c:41
void voteinfo_queue_next(void)
Definition voteinfo.c:272
int voteinfo_queue_size(void)
Definition voteinfo.c:291
void voteinfo_queue_check_removed(void)
Definition voteinfo.c:72
static struct voteinfo_list * voteinfo_queue
Definition voteinfo.c:45
#define voteinfo_list_iterate_end
Definition voteinfo.c:43
void voteinfo_queue_free(void)
Definition voteinfo.c:179
void voteinfo_queue_add(int vote_no, const char *user, const char *desc, int percent_required, int flags)
Definition voteinfo.c:123
client_vote_type
Definition voteinfo.h:22
@ CVT_YES
Definition voteinfo.h:24
@ CVT_NO
Definition voteinfo.h:25
@ CVT_ABSTAIN
Definition voteinfo.h:26