Freeciv-3.2
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 "nation.h"
30#include "research.h"
31
32/* client */
33#include "client_main.h"
34#include "climisc.h"
35#include "options.h"
36#include "text.h"
37
38/* client/include */
39#include "plrdlg_g.h"
40
41#include "plrdlg_common.h"
42
43
44/************************************************************************/
47static const char *col_name(const struct player *player)
48{
49 return player_name(player);
50}
51
52/************************************************************************/
55static int cmp_name(const struct player *pplayer1,
56 const struct player *pplayer2)
57{
59}
60
61/************************************************************************/
64static const char *col_username(const struct player *player)
65{
66 return player->username;
67}
68
69/************************************************************************/
72static const char *col_nation(const struct player *player)
73{
75}
76
77/************************************************************************/
80static const char *col_team(const struct player *player)
81{
83}
84
85/************************************************************************/
88static bool col_ai(const struct player *plr)
89{
90 /* TODO: Currently is_ai() is a macro so we can't have it
91 * directly as this callback, but once it's a function,
92 * do that. */
93 return is_ai(plr);
94}
95
96/************************************************************************/
100static const char *col_embassy(const struct player *player)
101{
103}
104
105/************************************************************************/
109static const char *col_diplstate(const struct player *player)
110{
111 static char buf[100];
112 const struct player_diplstate *pds;
113
115 return "-";
116 } else {
118 if (pds->type == DS_CEASEFIRE || pds->type == DS_ARMISTICE) {
119 fc_snprintf(buf, sizeof(buf), "%s (%d)",
121 pds->turns_left);
122 return buf;
123 } else {
125 }
126 }
127}
128
129/************************************************************************/
135static int diplstate_value(const struct player *plr)
136{
137 /* these values are scaled so that adding/subtracting
138 the number of turns left makes sense */
139 static const int diplstate_cmp_lookup[DS_LAST] = {
140 [DS_TEAM] = 1 << 16,
141 [DS_ALLIANCE] = 2 << 16,
142 [DS_PEACE] = 3 << 16,
143 [DS_ARMISTICE] = 4 << 16,
144 [DS_CEASEFIRE] = 5 << 16,
145 [DS_WAR] = 6 << 16,
146 [DS_NO_CONTACT] = 7 << 16
147 };
148
149 const struct player_diplstate *pds;
150 int ds_value;
151
152 if (NULL == client.conn.playing || plr == client.conn.playing) {
153 /* current global player is as close as players get
154 -> return value smaller than for DS_TEAM */
155 return 0;
156 }
157
160
161 if (pds->type == DS_ARMISTICE || pds->type == DS_CEASEFIRE) {
162 ds_value += pds->turns_left;
163 }
164
165 return ds_value;
166}
167
168/************************************************************************/
171static int cmp_diplstate(const struct player *player1,
172 const struct player *player2)
173{
175}
176
177/************************************************************************/
180static const char *col_love(const struct player *player)
181{
183 || is_human(player)) {
184 return "-";
185 } else {
187 }
188}
189
190/************************************************************************/
193static int cmp_love(const struct player *player1,
194 const struct player *player2)
195{
196 int love1, love2;
197
198 if (NULL == client.conn.playing) {
200 }
201
203 love1 = MAX_AI_LOVE + 999;
204 } else {
205 love1 = player1->ai_common.love[player_index(client.conn.playing)];
206 }
207
209 love2 = MAX_AI_LOVE + 999;
210 } else {
211 love2 = player2->ai_common.love[player_index(client.conn.playing)];
212 }
213
214 return love1 - love2;
215}
216
217/************************************************************************/
220static const char *col_vision(const struct player *player)
221{
223}
224
225/************************************************************************/
230const char *plrdlg_col_state(const struct player *plr)
231{
232 if (!plr->is_alive) {
233 /* TRANS: Dead -- Rest In Peace -- Reqia In Pace */
234 return _("R.I.P.");
235 } else if (!plr->is_connected) {
236 struct option *opt;
237 bool consider_tb = FALSE;
238
239 if (is_ai(plr)) {
240 return "";
241 }
242
244 if (opt != NULL) {
246 }
247
248 if (!consider_tb) {
249 /* TRANS: No connection */
250 return _("noconn");
251 }
252
253 if (!is_player_phase(plr, game.info.phase)) {
254 return _("waiting");
255 } else if (plr->phase_done) {
256 return _("done");
257 } else {
258 /* TRANS: Turnblocking & player not connected */
259 return _("blocking");
260 }
261 } else {
262 if (!is_player_phase(plr, game.info.phase)) {
263 return _("waiting");
264 } else if (plr->phase_done) {
265 return _("done");
266 } else {
267 return _("moving");
268 }
269 }
270}
271
272/************************************************************************/
279static const char *col_host(const struct player *pplayer)
280{
282 if (!pconn->observer) {
283 return pconn->addr;
284 }
286
287 return blank_addr_str;
288}
289
290/************************************************************************/
293static const char *col_idle(const struct player *plr)
294{
295 int idle;
296 static char buf[100];
297
298 if (plr->nturns_idle > 3) {
299 idle = plr->nturns_idle - 1;
300 } else {
301 idle = 0;
302 }
303 fc_snprintf(buf, sizeof(buf), "%d", idle);
304 return buf;
305}
306
307/************************************************************************/
310static int cmp_score(const struct player *player1,
311 const struct player *player2)
312{
313 return player1->score.game - player2->score.game;
314}
315
316/************************************************************************/
319static const char *col_government(const struct player *them)
320{
321 static char buf[100];
322 const struct player *me = client_player();
323
324 /* 'contact' gives the knowledge of other's government */
325 if (me == them
327 || team_has_embassy(me->team, them)
328 || player_diplstate_get(me, them)->contact_turns_left > 0 ) {
330 } else {
331 fc_snprintf(buf, sizeof(buf),"?");
332 }
333
334 return buf;
335}
336
337/************************************************************************/
341static int cmp_culture(const struct player *player1,
342 const struct player *player2)
343{
344 return player1->client.culture - player2->client.culture;
345}
346
347/************************************************************************/
350static const char *get_culture_info(const struct player *them)
351{
352 static char buf[10];
353 const struct player *me = client_player();
355
356 if (them == NULL || !them->is_alive) {
357 fc_snprintf(buf, sizeof(buf), "-");
358 } else if (gobs
359 || (me != NULL
360 && (me == them || team_has_embassy(me->team, them)))) {
361 fc_snprintf(buf, sizeof(buf), "%d", them->client.culture);
362 } else {
363 fc_snprintf(buf, sizeof(buf), "?");
364 }
365
366 return buf;
367}
368
369/************************************************************************/
372static const char *col_culture(const struct player *pplayer)
373{
374 return get_culture_info(pplayer);
375}
376
377/************************************************************************/
381static int cmp_gold(const struct player* player1,
382 const struct player* player2)
383{
384 return player1->economic.gold - player2->economic.gold;
385}
386
387/************************************************************************/
390static const char *get_gold_info(const struct player *them)
391{
392 static char buf[10];
393 const struct player *me = client_player();
395
396 if (them == NULL || !them->is_alive) {
397 fc_snprintf(buf, sizeof(buf), "-");
398 } else if (gobs
399 || (me != NULL
400 && (me == them || team_has_embassy(me->team, them)
401 || player_diplstate_get(me, them)->contact_turns_left > 0))) {
402 fc_snprintf(buf, sizeof(buf), "%d", them->economic.gold);
403 } else {
404 fc_snprintf(buf, sizeof(buf), "?");
405 }
406
407 return buf;
408}
409
410/************************************************************************/
413static const char *col_gold(const struct player *pplayer)
414{
415 return get_gold_info(pplayer);
416}
417
418/************************************************************************/
422static int cmp_tax(const struct player* player1,
423 const struct player* player2)
424{
425 return player1->economic.tax - player2->economic.tax;
426}
427
428/************************************************************************/
431static const char *get_tax_info(const struct player *them)
432{
433 static char buf[10];
434 const struct player *me = client_player();
436
437 if (them == NULL || !them->is_alive) {
438 fc_snprintf(buf, sizeof(buf), "-");
439 } else if (gobs
440 || (me != NULL
441 && (me == them || team_has_embassy(me->team, them)))) {
442 fc_snprintf(buf, sizeof(buf), "%d %%", them->economic.tax);
443 } else {
444 fc_snprintf(buf, sizeof(buf), "?");
445 }
446
447 return buf;
448}
449
450/************************************************************************/
453static const char *col_tax(const struct player *pplayer)
454{
455 return get_tax_info(pplayer);
456}
457
458/************************************************************************/
462static int cmp_science(const struct player* player1,
463 const struct player* player2)
464{
465 return player1->economic.science - player2->economic.science;
466}
467
468/************************************************************************/
471static const char *get_science_info(const struct player *them)
472{
473 static char buf[10];
474 const struct player *me = client_player();
476
477 if (them == NULL || !them->is_alive) {
478 fc_snprintf(buf, sizeof(buf), "-");
479 } else if (gobs
480 || (me != NULL
481 && (me == them || team_has_embassy(me->team, them)))) {
482 fc_snprintf(buf, sizeof(buf), "%d %%", them->economic.science);
483 } else {
484 fc_snprintf(buf, sizeof(buf), "?");
485 }
486
487 return buf;
488}
489
490/************************************************************************/
493static const char *col_science(const struct player *pplayer)
494{
495 return get_science_info(pplayer);
496}
497
498/************************************************************************/
502static int cmp_luxury(const struct player* player1,
503 const struct player* player2)
504{
505 return player1->economic.luxury - player2->economic.luxury;
506}
507
508/************************************************************************/
511static const char *get_luxury_info(const struct player *them)
512{
513 static char buf[10];
514 const struct player *me = client_player();
516
517 if (them == NULL || !them->is_alive) {
518 fc_snprintf(buf, sizeof(buf), "-");
519 } else if (gobs
520 || (me != NULL
521 && (me == them || team_has_embassy(me->team, them)))) {
522 fc_snprintf(buf, sizeof(buf), "%d %%", them->economic.luxury);
523 } else {
524 fc_snprintf(buf, sizeof(buf), "?");
525 }
526
527 return buf;
528}
529
530/************************************************************************/
533static const char *col_luxury(const struct player *pplayer)
534{
535 return get_luxury_info(pplayer);
536}
537
538/************************************************************************/
541static const char *get_researching_info(const struct player *them)
542{
543 static char buf[100];
544 const struct player *me = client_player();
546
547 if (them == NULL || !them->is_alive) {
548 fc_snprintf(buf, sizeof(buf), "-");
549 } else if (gobs
550 || (me != NULL
551 && (me == them || team_has_embassy(me->team, them)))) {
553
554 fc_snprintf(buf, sizeof(buf), "%s",
556 } else {
557 fc_snprintf(buf, sizeof(buf), "?");
558 }
559
560 return buf;
561}
562
563/************************************************************************/
566static const char *col_research(const struct player *pplayer)
567{
568 return get_researching_info(pplayer);
569}
570
571/****************************************************************************
572 ...
573****************************************************************************/
575 {TRUE, COL_TEXT, N_("?Player:Name"), col_name, NULL, cmp_name, "name"},
576 {FALSE, COL_TEXT, N_("Username"), col_username, NULL, NULL, "username"},
577 {TRUE, COL_FLAG, N_("Flag"), NULL, NULL, NULL, "flag"},
578 {TRUE, COL_TEXT, N_("Nation"), col_nation, NULL, NULL, "nation"},
579 {TRUE, COL_COLOR, N_("Border"), NULL, NULL, NULL, "border"},
580 {TRUE, COL_RIGHT_TEXT, N_("Score"), get_score_text, NULL, cmp_score, "score"},
581 {TRUE, COL_TEXT, N_("Team"), col_team, NULL, NULL, "team"},
582 {TRUE, COL_BOOLEAN, N_("AI"), NULL, col_ai, NULL, "ai"},
583 {TRUE, COL_TEXT, N_("Attitude"), col_love, NULL, cmp_love, "attitude"},
584 {TRUE, COL_TEXT, N_("Embassy"), col_embassy, NULL, NULL, "embassy"},
585 {TRUE, COL_TEXT, N_("Dipl.State"), col_diplstate, NULL, cmp_diplstate,
586 "diplstate"},
587 {TRUE, COL_TEXT, N_("Vision"), col_vision, NULL, NULL, "vision"},
588 {TRUE, COL_TEXT, N_("State"), plrdlg_col_state, NULL, NULL, "state"},
589 {FALSE, COL_TEXT, N_("?Player_dlg:Host"), col_host, NULL, NULL, "host"},
590 {FALSE, COL_RIGHT_TEXT, N_("?Player_dlg:Idle"), col_idle, NULL, NULL, "idle"},
591 {FALSE, COL_RIGHT_TEXT, N_("Ping"), get_ping_time_text, NULL, NULL, "ping"},
592 {TRUE, COL_TEXT, N_("Government"), col_government, NULL, NULL, "government"},
593 {TRUE, COL_RIGHT_TEXT, N_("Culture"), col_culture, NULL, cmp_culture, "culture"},
594 {TRUE, COL_RIGHT_TEXT, N_("Gold"), col_gold, NULL, cmp_gold, "gold"},
595 {TRUE, COL_RIGHT_TEXT, N_("Tax"), col_tax, NULL, cmp_tax, "tax"},
596 {TRUE, COL_RIGHT_TEXT, N_("Science"), col_science, NULL, cmp_science, "science"},
597 {TRUE, COL_RIGHT_TEXT, N_("Luxury"), col_luxury, NULL, cmp_luxury, "luxury"},
598 {TRUE, COL_TEXT, N_("Research"), col_research, NULL, NULL, "research"}
599};
600
602
603/************************************************************************/
607{
608 return 3;
609}
610
611/************************************************************************/
615{
616 int i;
617
618 for (i = 0; i < num_player_dlg_columns; i++) {
620 }
621}
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
char * incite_cost
Definition comments.c:75
const char blank_addr_str[]
Definition connection.c:55
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
#define conn_list_iterate_end
Definition connection.h:110
#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:62
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:707
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:154
const char * title
Definition repodlgs.c:1314
@ COL_TEXT
Definition unitselect.c:50
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
const struct option_set * server_optset
Definition options.c:4016
bool option_bool_get(const struct option *poption)
Definition options.c:797
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Definition options.c:431
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:220
int player_index(const struct player *pplayer)
Definition player.c:829
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
const char * love_text(const int love)
Definition player.c:1354
#define MAX_AI_LOVE
Definition player.h:561
#define is_ai(plr)
Definition player.h:230
#define is_human(plr)
Definition player.h:229
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_host(const struct player *pplayer)
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)
static const char * col_luxury(const struct player *pplayer)
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:273
struct research * research_get(const struct player *pplayer)
Definition research.c:128
#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:151
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:122
const char * title
struct player_ai ai_common
Definition player.h:286
char username[MAX_LEN_NAME]
Definition player.h:250
bool is_connected
Definition player.h:294
int nturns_idle
Definition player.h:263
struct team * team
Definition player.h:259
struct conn_list * connections
Definition player.h:296
bool is_alive
Definition player.h:266
bool phase_done
Definition player.h:261
Tech_type_id researching
Definition research.h:52
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
int fc_stricoll(const char *str0, const char *str1)
Definition support.c:487
#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:1621
const char * get_score_text(const struct player *pplayer)
Definition text.c:1650