Freeciv-3.4
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
114 if (client.conn.playing == nullptr || player == client.conn.playing) {
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 (client.conn.playing == nullptr || 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{
182 if (client.conn.playing == nullptr || player == client.conn.playing
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 (client.conn.playing == nullptr) {
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 != nullptr) {
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
323 /* This gives sensible result even when the government is not known */
325
326 return buf;
327}
328
329/************************************************************************/
333static int cmp_culture(const struct player *player1,
334 const struct player *player2)
335{
336 return player1->client.culture - player2->client.culture;
337}
338
339/************************************************************************/
342static const char *get_culture_info(const struct player *them)
343{
344 static char buf[10];
345 const struct player *me = client_player();
347
348 if (them == nullptr || !them->is_alive) {
349 fc_snprintf(buf, sizeof(buf), "-");
350 } else if (gobs
351 || (me != nullptr
352 && (me == them || team_has_embassy(me->team, them)))) {
353 fc_snprintf(buf, sizeof(buf), "%d", them->client.culture);
354 } else {
355 fc_snprintf(buf, sizeof(buf), "?");
356 }
357
358 return buf;
359}
360
361/************************************************************************/
364static const char *col_culture(const struct player *pplayer)
365{
366 return get_culture_info(pplayer);
367}
368
369/************************************************************************/
373static int cmp_gold(const struct player* player1,
374 const struct player* player2)
375{
376 return player1->economic.gold - player2->economic.gold;
377}
378
379/************************************************************************/
382static const char *get_gold_info(const struct player *them)
383{
384 static char buf[10];
385 const struct player *me = client_player();
387
388 if (them == nullptr || !them->is_alive) {
389 fc_snprintf(buf, sizeof(buf), "-");
390 } else if (gobs
391 || (me != nullptr
392 && (me == them || team_has_embassy(me->team, them)
393 || player_diplstate_get(me, them)->contact_turns_left > 0))) {
394 fc_snprintf(buf, sizeof(buf), "%d", them->economic.gold);
395 } else {
396 fc_snprintf(buf, sizeof(buf), "?");
397 }
398
399 return buf;
400}
401
402/************************************************************************/
405static const char *col_gold(const struct player *pplayer)
406{
407 return get_gold_info(pplayer);
408}
409
410/************************************************************************/
414static int cmp_tax(const struct player* player1,
415 const struct player* player2)
416{
417 return player1->economic.tax - player2->economic.tax;
418}
419
420/************************************************************************/
423static const char *get_tax_info(const struct player *them)
424{
425 static char buf[10];
426 const struct player *me = client_player();
428
429 if (them == nullptr || !them->is_alive) {
430 fc_snprintf(buf, sizeof(buf), "-");
431 } else if (gobs
432 || (me != nullptr
433 && (me == them || team_has_embassy(me->team, them)))) {
434 fc_snprintf(buf, sizeof(buf), "%d %%", them->economic.tax);
435 } else {
436 fc_snprintf(buf, sizeof(buf), "?");
437 }
438
439 return buf;
440}
441
442/************************************************************************/
445static const char *col_tax(const struct player *pplayer)
446{
447 return get_tax_info(pplayer);
448}
449
450/************************************************************************/
454static int cmp_science(const struct player* player1,
455 const struct player* player2)
456{
457 return player1->economic.science - player2->economic.science;
458}
459
460/************************************************************************/
463static const char *get_science_info(const struct player *them)
464{
465 static char buf[10];
466 const struct player *me = client_player();
468
469 if (them == nullptr || !them->is_alive) {
470 fc_snprintf(buf, sizeof(buf), "-");
471 } else if (gobs
472 || (me != nullptr
473 && (me == them || team_has_embassy(me->team, them)))) {
474 fc_snprintf(buf, sizeof(buf), "%d %%", them->economic.science);
475 } else {
476 fc_snprintf(buf, sizeof(buf), "?");
477 }
478
479 return buf;
480}
481
482/************************************************************************/
485static const char *col_science(const struct player *pplayer)
486{
487 return get_science_info(pplayer);
488}
489
490/************************************************************************/
494static int cmp_luxury(const struct player* player1,
495 const struct player* player2)
496{
497 return player1->economic.luxury - player2->economic.luxury;
498}
499
500/************************************************************************/
503static const char *get_luxury_info(const struct player *them)
504{
505 static char buf[10];
506 const struct player *me = client_player();
508
509 if (them == nullptr || !them->is_alive) {
510 fc_snprintf(buf, sizeof(buf), "-");
511 } else if (gobs
512 || (me != nullptr
513 && (me == them || team_has_embassy(me->team, them)))) {
514 fc_snprintf(buf, sizeof(buf), "%d %%", them->economic.luxury);
515 } else {
516 fc_snprintf(buf, sizeof(buf), "?");
517 }
518
519 return buf;
520}
521
522/************************************************************************/
525static const char *col_luxury(const struct player *pplayer)
526{
527 return get_luxury_info(pplayer);
528}
529
530/************************************************************************/
533static const char *get_researching_info(const struct player *them)
534{
535 static char buf[100];
536 const struct player *me = client_player();
538
539 if (them == nullptr || !them->is_alive) {
540 fc_snprintf(buf, sizeof(buf), "-");
541 } else if (gobs
542 || (me != nullptr
543 && (me == them || team_has_embassy(me->team, them)))) {
545
546 fc_snprintf(buf, sizeof(buf), "%s",
548 } else {
549 fc_snprintf(buf, sizeof(buf), "?");
550 }
551
552 return buf;
553}
554
555/************************************************************************/
558static const char *col_research(const struct player *pplayer)
559{
560 return get_researching_info(pplayer);
561}
562
563/****************************************************************************
564 ...
565****************************************************************************/
567 {TRUE, COL_TEXT, N_("?Player:Name"), col_name, nullptr, cmp_name, "name"},
568 {FALSE, COL_TEXT, N_("Username"), col_username, nullptr, nullptr, "username"},
569 {TRUE, COL_FLAG, N_("Flag"), nullptr, nullptr, nullptr, "flag"},
570 {TRUE, COL_TEXT, N_("Nation"), col_nation, nullptr, nullptr, "nation"},
571 {TRUE, COL_COLOR, N_("Border"), nullptr, nullptr, nullptr, "border"},
572 {TRUE, COL_RIGHT_TEXT, N_("Score"), get_score_text, nullptr, cmp_score, "score"},
573 {TRUE, COL_TEXT, N_("Team"), col_team, nullptr, nullptr, "team"},
574 {TRUE, COL_BOOLEAN, N_("AI"), nullptr, col_ai, nullptr, "ai"},
575 {TRUE, COL_TEXT, N_("Attitude"), col_love, nullptr, cmp_love, "attitude"},
576 {TRUE, COL_TEXT, N_("Embassy"), col_embassy, nullptr, nullptr, "embassy"},
577 {TRUE, COL_TEXT, N_("Dipl.State"), col_diplstate, nullptr, cmp_diplstate,
578 "diplstate"},
579 {TRUE, COL_TEXT, N_("Vision"), col_vision, nullptr, nullptr, "vision"},
580 {TRUE, COL_TEXT, N_("State"), plrdlg_col_state, nullptr, nullptr, "state"},
581 {FALSE, COL_TEXT, N_("?Player_dlg:Host"), col_host, nullptr, nullptr, "host"},
582 {FALSE, COL_RIGHT_TEXT, N_("?Player_dlg:Idle"), col_idle, nullptr, nullptr, "idle"},
583 {FALSE, COL_RIGHT_TEXT, N_("Ping"), get_ping_time_text, nullptr, nullptr, "ping"},
584 {TRUE, COL_TEXT, N_("Government"), col_government, nullptr, nullptr, "government"},
585 {TRUE, COL_RIGHT_TEXT, N_("Culture"), col_culture, nullptr, cmp_culture, "culture"},
586 {TRUE, COL_RIGHT_TEXT, N_("Gold"), col_gold, nullptr, cmp_gold, "gold"},
587 {TRUE, COL_RIGHT_TEXT, N_("Tax"), col_tax, nullptr, cmp_tax, "tax"},
588 {TRUE, COL_RIGHT_TEXT, N_("Science"), col_science, nullptr, cmp_science, "science"},
589 {TRUE, COL_RIGHT_TEXT, N_("Luxury"), col_luxury, nullptr, cmp_luxury, "luxury"},
590 {TRUE, COL_TEXT, N_("Research"), col_research, nullptr, nullptr, "research"}
591};
592
594
595/************************************************************************/
599{
600 return 3;
601}
602
603/************************************************************************/
607{
608 int i;
609
610 for (i = 0; i < num_player_dlg_columns; i++) {
612 }
613}
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:77
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:716
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:150
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:4369
bool option_bool_get(const struct option *poption)
Definition options.c:848
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Definition options.c:482
int player_number(const struct player *pplayer)
Definition player.c:826
const char * player_name(const struct player *pplayer)
Definition player.c:885
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:225
int player_index(const struct player *pplayer)
Definition player.c:818
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:325
const char * love_text(const int love)
Definition player.c:1342
#define MAX_AI_LOVE
Definition player.h:576
#define is_ai(plr)
Definition player.h:232
#define is_human(plr)
Definition player.h:231
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:276
struct research * research_get(const struct player *pplayer)
Definition research.c:130
#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:124
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
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
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:925
int fc_stricoll(const char *str0, const char *str1)
Definition support.c:450
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * team_name_translation(const struct team *pteam)
Definition team.c:409
const char * get_ping_time_text(const struct player *pplayer)
Definition text.c:1674
const char * get_score_text(const struct player *pplayer)
Definition text.c:1703