Freeciv-3.1
Loading...
Searching...
No Matches
plrdlg_common.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 <string.h>
19
20/* utility */
21#include "fcintl.h"
22#include "log.h"
23#include "support.h"
24
25/* common */
26#include "connection.h"
27#include "game.h"
28#include "government.h"
29#include "research.h"
30
31/* client */
32#include "client_main.h"
33#include "climisc.h"
34#include "options.h"
35#include "text.h"
36
37/* client/include */
38#include "plrdlg_g.h"
39
40#include "plrdlg_common.h"
41
42
43/************************************************************************/
46static const char *col_name(const struct player *player)
47{
48 return player_name(player);
49}
50
51/************************************************************************/
54static int cmp_name(const struct player *pplayer1,
55 const struct player *pplayer2)
56{
57 return fc_stricoll(player_name(pplayer1), player_name(pplayer2));
58}
59
60/************************************************************************/
63static const char *col_username(const struct player *player)
64{
65 return player->username;
66}
67
68/************************************************************************/
71static const char *col_nation(const struct player *player)
72{
74}
75
76/************************************************************************/
79static const char *col_team(const struct player *player)
80{
82}
83
84/************************************************************************/
87static bool col_ai(const struct player *plr)
88{
89 /* TODO: Currently is_ai() is a macro so we can't have it
90 * directly as this callback, but once it's a function,
91 * do that. */
92 return is_ai(plr);
93}
94
95/************************************************************************/
99static const char *col_embassy(const struct player *player)
100{
102}
103
104/************************************************************************/
108static const char *col_diplstate(const struct player *player)
109{
110 static char buf[100];
111 const struct player_diplstate *pds;
112
113 if (NULL == client.conn.playing || player == client.conn.playing) {
114 return "-";
115 } else {
117 if (pds->type == DS_CEASEFIRE || pds->type == DS_ARMISTICE) {
118 fc_snprintf(buf, sizeof(buf), "%s (%d)",
119 diplstate_type_translated_name(pds->type),
120 pds->turns_left);
121 return buf;
122 } else {
123 return diplstate_type_translated_name(pds->type);
124 }
125 }
126}
127
128/************************************************************************/
134static int diplstate_value(const struct player *plr)
135{
136 /* these values are scaled so that adding/subtracting
137 the number of turns left makes sense */
138 static const int diplstate_cmp_lookup[DS_LAST] = {
139 [DS_TEAM] = 1 << 16,
140 [DS_ALLIANCE] = 2 << 16,
141 [DS_PEACE] = 3 << 16,
142 [DS_ARMISTICE] = 4 << 16,
143 [DS_CEASEFIRE] = 5 << 16,
144 [DS_WAR] = 6 << 16,
145 [DS_NO_CONTACT] = 7 << 16
146 };
147
148 const struct player_diplstate *pds;
149 int ds_value;
150
151 if (NULL == client.conn.playing || plr == client.conn.playing) {
152 /* current global player is as close as players get
153 -> return value smaller than for DS_TEAM */
154 return 0;
155 }
156
158 ds_value = diplstate_cmp_lookup[pds->type];
159
160 if (pds->type == DS_ARMISTICE || pds->type == DS_CEASEFIRE) {
161 ds_value += pds->turns_left;
162 }
163
164 return ds_value;
165}
166
167/************************************************************************/
170static int cmp_diplstate(const struct player *player1,
171 const struct player *player2)
172{
173 return diplstate_value(player1) - diplstate_value(player2);
174}
175
176/************************************************************************/
179static const char *col_love(const struct player *player)
180{
181 if (NULL == client.conn.playing || player == client.conn.playing
182 || is_human(player)) {
183 return "-";
184 } else {
186 }
187}
188
189/************************************************************************/
192static int cmp_love(const struct player *player1,
193 const struct player *player2)
194{
195 int love1, love2;
196
197 if (NULL == client.conn.playing) {
198 return player_number(player1) - player_number(player2);
199 }
200
201 if (player1 == client.conn.playing || is_human(player1)) {
202 love1 = MAX_AI_LOVE + 999;
203 } else {
204 love1 = player1->ai_common.love[player_index(client.conn.playing)];
205 }
206
207 if (player2 == client.conn.playing || is_human(player2)) {
208 love2 = MAX_AI_LOVE + 999;
209 } else {
210 love2 = player2->ai_common.love[player_index(client.conn.playing)];
211 }
212
213 return love1 - love2;
214}
215
216/************************************************************************/
219static const char *col_vision(const struct player *player)
220{
222}
223
224/************************************************************************/
229const char *plrdlg_col_state(const struct player *plr)
230{
231 if (!plr->is_alive) {
232 /* TRANS: Dead -- Rest In Peace -- Reqia In Pace */
233 return _("R.I.P.");
234 } else if (!plr->is_connected) {
235 struct option *opt;
236 bool consider_tb = FALSE;
237
238 if (is_ai(plr)) {
239 return "";
240 }
241
242 opt = optset_option_by_name(server_optset, "turnblock");
243 if (opt != NULL) {
244 consider_tb = option_bool_get(opt);
245 }
246
247 if (!consider_tb) {
248 /* TRANS: No connection */
249 return _("noconn");
250 }
251
252 if (!is_player_phase(plr, game.info.phase)) {
253 return _("waiting");
254 } else if (plr->phase_done) {
255 return _("done");
256 } else {
257 /* TRANS: Turnblocking & player not connected */
258 return _("blocking");
259 }
260 } else {
261 if (!is_player_phase(plr, game.info.phase)) {
262 return _("waiting");
263 } else if (plr->phase_done) {
264 return _("done");
265 } else {
266 return _("moving");
267 }
268 }
269}
270
271/************************************************************************/
275static const char *col_host(const struct player *player)
276{
277 return player_addr_hack(player);
278}
279
280/************************************************************************/
283static const char *col_idle(const struct player *plr)
284{
285 int idle;
286 static char buf[100];
287
288 if (plr->nturns_idle > 3) {
289 idle = plr->nturns_idle - 1;
290 } else {
291 idle = 0;
292 }
293 fc_snprintf(buf, sizeof(buf), "%d", idle);
294 return buf;
295}
296
297/************************************************************************/
300static int cmp_score(const struct player *player1,
301 const struct player *player2)
302{
303 return player1->score.game - player2->score.game;
304}
305
306/************************************************************************/
309static const char *col_government(const struct player *them)
310{
311 static char buf[100];
312 const struct player *me = client_player();
313
314 /* 'contact' gives the knowledge of other's government */
315 if (me == them
317 || team_has_embassy(me->team, them)
318 || player_diplstate_get(me, them)->contact_turns_left > 0 ) {
319 fc_snprintf(buf, sizeof(buf),"%s", government_name_for_player(them));
320 } else {
321 fc_snprintf(buf, sizeof(buf),"?");
322 }
323
324 return buf;
325}
326
327/************************************************************************/
331static int cmp_culture(const struct player *player1,
332 const struct player *player2)
333{
334 return player1->client.culture - player2->client.culture;
335}
336
337/************************************************************************/
340static const char *get_culture_info(const struct player *them)
341{
342 static char buf[10];
343 const struct player *me = client_player();
344 bool gobs = client_is_global_observer();
345
346 if (them == NULL || !them->is_alive) {
347 fc_snprintf(buf, sizeof(buf), "-");
348 } else if (gobs
349 || (me != NULL
350 && (me == them || team_has_embassy(me->team, them)))) {
351 fc_snprintf(buf, sizeof(buf), "%d", them->client.culture);
352 } else {
353 fc_snprintf(buf, sizeof(buf), "?");
354 }
355
356 return buf;
357}
358
359/************************************************************************/
362static const char *col_culture(const struct player *pplayer)
363{
364 return get_culture_info(pplayer);
365}
366
367/************************************************************************/
371static int cmp_gold(const struct player* player1,
372 const struct player* player2)
373{
374 return player1->economic.gold - player2->economic.gold;
375}
376
377/************************************************************************/
380static const char *get_gold_info(const struct player *them)
381{
382 static char buf[10];
383 const struct player *me = client_player();
384 bool gobs = client_is_global_observer();
385
386 if (them == NULL || !them->is_alive) {
387 fc_snprintf(buf, sizeof(buf), "-");
388 } else if (gobs
389 || (me != NULL
390 && (me == them || team_has_embassy(me->team, them)
391 || player_diplstate_get(me, them)->contact_turns_left > 0))) {
392 fc_snprintf(buf, sizeof(buf), "%d", them->economic.gold);
393 } else {
394 fc_snprintf(buf, sizeof(buf), "?");
395 }
396
397 return buf;
398}
399
400/************************************************************************/
403static const char *col_gold(const struct player *pplayer)
404{
405 return get_gold_info(pplayer);
406}
407
408/************************************************************************/
412static int cmp_tax(const struct player* player1,
413 const struct player* player2)
414{
415 return player1->economic.tax - player2->economic.tax;
416}
417
418/************************************************************************/
421static const char *get_tax_info(const struct player *them)
422{
423 static char buf[10];
424 const struct player *me = client_player();
425 bool gobs = client_is_global_observer();
426
427 if (them == NULL || !them->is_alive) {
428 fc_snprintf(buf, sizeof(buf), "-");
429 } else if (gobs
430 || (me != NULL
431 && (me == them || team_has_embassy(me->team, them)))) {
432 fc_snprintf(buf, sizeof(buf), "%d %%", them->economic.tax);
433 } else {
434 fc_snprintf(buf, sizeof(buf), "?");
435 }
436
437 return buf;
438}
439
440/************************************************************************/
443static const char *col_tax(const struct player *pplayer)
444{
445 return get_tax_info(pplayer);
446}
447
448/************************************************************************/
452static int cmp_science(const struct player* player1,
453 const struct player* player2)
454{
455 return player1->economic.science - player2->economic.science;
456}
457
458/************************************************************************/
461static const char *get_science_info(const struct player *them)
462{
463 static char buf[10];
464 const struct player *me = client_player();
465 bool gobs = client_is_global_observer();
466
467 if (them == NULL || !them->is_alive) {
468 fc_snprintf(buf, sizeof(buf), "-");
469 } else if (gobs
470 || (me != NULL
471 && (me == them || team_has_embassy(me->team, them)))) {
472 fc_snprintf(buf, sizeof(buf), "%d %%", them->economic.science);
473 } else {
474 fc_snprintf(buf, sizeof(buf), "?");
475 }
476
477 return buf;
478}
479
480/************************************************************************/
483static const char *col_science(const struct player *pplayer)
484{
485 return get_science_info(pplayer);
486}
487
488/************************************************************************/
492static int cmp_luxury(const struct player* player1,
493 const struct player* player2)
494{
495 return player1->economic.luxury - player2->economic.luxury;
496}
497
498/************************************************************************/
501static const char *get_luxury_info(const struct player *them)
502{
503 static char buf[10];
504 const struct player *me = client_player();
505 bool gobs = client_is_global_observer();
506
507 if (them == NULL || !them->is_alive) {
508 fc_snprintf(buf, sizeof(buf), "-");
509 } else if (gobs
510 || (me != NULL
511 && (me == them || team_has_embassy(me->team, them)))) {
512 fc_snprintf(buf, sizeof(buf), "%d %%", them->economic.luxury);
513 } else {
514 fc_snprintf(buf, sizeof(buf), "?");
515 }
516
517 return buf;
518}
519
520/************************************************************************/
523static const char *col_luxury(const struct player *pplayer)
524{
525 return get_luxury_info(pplayer);
526}
527
528/************************************************************************/
531static const char *get_researching_info(const struct player *them)
532{
533 static char buf[100];
534 const struct player *me = client_player();
535 bool gobs = client_is_global_observer();
536
537 if (them == NULL || !them->is_alive) {
538 fc_snprintf(buf, sizeof(buf), "-");
539 } else if (gobs
540 || (me != NULL
541 && (me == them || team_has_embassy(me->team, them)))) {
542 struct research *research = research_get(them);
543
544 fc_snprintf(buf, sizeof(buf), "%s",
546 } else {
547 fc_snprintf(buf, sizeof(buf), "?");
548 }
549
550 return buf;
551}
552
553/************************************************************************/
556static const char *col_research(const struct player *pplayer)
557{
558 return get_researching_info(pplayer);
559}
560
561/****************************************************************************
562 ...
563****************************************************************************/
565 {TRUE, COL_TEXT, N_("?Player:Name"), col_name, NULL, cmp_name, "name"},
566 {FALSE, COL_TEXT, N_("Username"), col_username, NULL, NULL, "username"},
567 {TRUE, COL_FLAG, N_("Flag"), NULL, NULL, NULL, "flag"},
568 {TRUE, COL_TEXT, N_("Nation"), col_nation, NULL, NULL, "nation"},
569 {TRUE, COL_COLOR, N_("Border"), NULL, NULL, NULL, "border"},
570 {TRUE, COL_RIGHT_TEXT, N_("Score"), get_score_text, NULL, cmp_score, "score"},
571 {TRUE, COL_TEXT, N_("Team"), col_team, NULL, NULL, "team"},
572 {TRUE, COL_BOOLEAN, N_("AI"), NULL, col_ai, NULL, "ai"},
573 {TRUE, COL_TEXT, N_("Attitude"), col_love, NULL, cmp_love, "attitude"},
574 {TRUE, COL_TEXT, N_("Embassy"), col_embassy, NULL, NULL, "embassy"},
575 {TRUE, COL_TEXT, N_("Dipl.State"), col_diplstate, NULL, cmp_diplstate,
576 "diplstate"},
577 {TRUE, COL_TEXT, N_("Vision"), col_vision, NULL, NULL, "vision"},
578 {TRUE, COL_TEXT, N_("State"), plrdlg_col_state, NULL, NULL, "state"},
579 {FALSE, COL_TEXT, N_("?Player_dlg:Host"), col_host, NULL, NULL, "host"},
580 {FALSE, COL_RIGHT_TEXT, N_("?Player_dlg:Idle"), col_idle, NULL, NULL, "idle"},
581 {FALSE, COL_RIGHT_TEXT, N_("Ping"), get_ping_time_text, NULL, NULL, "ping"},
582 {TRUE, COL_TEXT, N_("Government"), col_government, NULL, NULL, "government"},
583 {TRUE, COL_RIGHT_TEXT, N_("Culture"), col_culture, NULL, cmp_culture, "culture"},
584 {TRUE, COL_RIGHT_TEXT, N_("Gold"), col_gold, NULL, cmp_gold, "gold"},
585 {TRUE, COL_RIGHT_TEXT, N_("Tax"), col_tax, NULL, cmp_tax, "tax"},
586 {TRUE, COL_RIGHT_TEXT, N_("Science"), col_science, NULL, cmp_science, "science"},
587 {TRUE, COL_RIGHT_TEXT, N_("Luxury"), col_luxury, NULL, cmp_luxury, "luxury"},
588 {TRUE, COL_TEXT, N_("Research"), col_research, NULL, NULL, "research"}
589};
590
592
593/************************************************************************/
597{
598 return 3;
599}
600
601/************************************************************************/
605{
606 int i;
607
608 for (i = 0; i < num_player_dlg_columns; i++) {
610 }
611}
612
613/************************************************************************/
622const char *player_addr_hack(const struct player *pplayer)
623{
624 conn_list_iterate(pplayer->connections, pconn) {
625 if (!pconn->observer) {
626 return pconn->addr;
627 }
629
630 return blank_addr_str;
631}
bool client_is_global_observer(void)
struct civclient client
#define client_player()
const char * get_embassy_status(const struct player *me, const struct player *them)
Definition climisc.c:194
const char * get_vision_status(const struct player *me, const struct player *them)
Definition climisc.c:222
const char blank_addr_str[]
Definition connection.c:55
#define conn_list_iterate(connlist, pconn)
Definition connection.h:113
#define conn_list_iterate_end
Definition connection.h:115
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
#define N_(String)
Definition fcintl.h:69
struct civ_game game
Definition game.c:57
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:687
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:153
const char * title
Definition repodlgs.c:1313
@ COL_TEXT
Definition unitselect.c:50
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:168
const struct option_set * server_optset
Definition options.c:4009
bool option_bool_get(const struct option *poption)
Definition options.c:772
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Definition options.c:406
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:214
int player_index(const struct player *pplayer)
Definition player.c:820
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
const char * love_text(const int love)
Definition player.c:1330
#define MAX_AI_LOVE
Definition player.h:559
#define is_ai(plr)
Definition player.h:234
#define is_human(plr)
Definition player.h:233
static const char * col_username(const struct player *player)
static int cmp_name(const struct player *pplayer1, const struct player *pplayer2)
static const char * col_gold(const struct player *pplayer)
int player_dlg_default_sort_column(void)
static const char * get_culture_info(const struct player *them)
static bool col_ai(const struct player *plr)
static int cmp_culture(const struct player *player1, const struct player *player2)
static int cmp_diplstate(const struct player *player1, const struct player *player2)
static const char * col_nation(const struct player *player)
static const char * get_science_info(const struct player *them)
static int cmp_score(const struct player *player1, const struct player *player2)
static int cmp_tax(const struct player *player1, const struct player *player2)
static const char * col_vision(const struct player *player)
static const char * col_embassy(const struct player *player)
void init_player_dlg_common(void)
const char * plrdlg_col_state(const struct player *plr)
static int diplstate_value(const struct player *plr)
static const char * col_name(const struct player *player)
static const char * col_team(const struct player *player)
static const char * col_love(const struct player *player)
static int cmp_luxury(const struct player *player1, const struct player *player2)
static const char * get_luxury_info(const struct player *them)
struct player_dlg_column player_dlg_columns[]
static const char * col_science(const struct player *pplayer)
static const char * col_government(const struct player *them)
static const char * col_idle(const struct player *plr)
static int cmp_gold(const struct player *player1, const struct player *player2)
static const char * col_diplstate(const struct player *player)
static int cmp_science(const struct player *player1, const struct player *player2)
static const char * get_researching_info(const struct player *them)
static const char * get_gold_info(const struct player *them)
const char * player_addr_hack(const struct player *pplayer)
static const char * col_luxury(const struct player *pplayer)
static const char * col_host(const struct player *player)
static const char * get_tax_info(const struct player *them)
static const char * col_research(const struct player *pplayer)
static int cmp_love(const struct player *player1, const struct player *player2)
static const char * col_tax(const struct player *pplayer)
const int num_player_dlg_columns
static const char * col_culture(const struct player *pplayer)
@ COL_BOOLEAN
@ COL_FLAG
@ COL_RIGHT_TEXT
@ COL_COLOR
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:271
struct research * research_get(const struct player *pplayer)
Definition research.c:126
#define ARRAY_SIZE(x)
Definition shared.h:85
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
struct player * playing
Definition connection.h:156
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:130
enum diplstate_type type
Definition player.h:201
const char * title
struct player_ai ai_common
Definition player.h:288
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_connected
Definition player.h:296
struct player::@69::@72 client
int nturns_idle
Definition player.h:265
struct team * team
Definition player.h:261
struct conn_list * connections
Definition player.h:298
bool is_alive
Definition player.h:268
struct player_economic economic
Definition player.h:284
int culture
Definition player.h:367
struct player_score score
Definition player.h:283
bool phase_done
Definition player.h:263
Tech_type_id researching
Definition research.h:52
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
int fc_stricoll(const char *str0, const char *str1)
Definition support.c:486
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * team_name_translation(const struct team *pteam)
Definition team.c:420
const char * get_ping_time_text(const struct player *pplayer)
Definition text.c:1654
const char * get_score_text(const struct player *pplayer)
Definition text.c:1683