Freeciv-3.3
Loading...
Searching...
No Matches
inteldlg.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 <stdio.h>
19#include <stdlib.h>
20
21#include <gtk/gtk.h>
22
23/* utility */
24#include "fcintl.h"
25#include "log.h"
26#include "shared.h"
27#include "support.h"
28
29/* common */
30#include "government.h"
31#include "nation.h"
32#include "packets.h"
33#include "player.h"
34#include "research.h"
35
36/* client */
37#include "client_main.h"
38#include "options.h"
39
40/* client/gui-gtk-3.22 */
41#include "gui_main.h"
42#include "gui_stuff.h"
43#include "mapview.h"
44
45#include "inteldlg.h"
46
47/******************************************************************/
48static const char *table_text[] = {
49 N_("Ruler:"),
50 N_("Government:"),
51 N_("Capital:"),
52 N_("Gold:"),
53 NULL,
54 N_("Tax:"),
55 N_("Science:"),
56 N_("Luxury:"),
57 NULL,
58 N_("Researching:"),
59 N_("Culture:")
60};
61
76
77/******************************************************************/
86
87#define SPECLIST_TAG dialog
88#define SPECLIST_TYPE struct intel_dialog
89#include "speclist.h"
90
91#define dialog_list_iterate(dialoglist, pdialog) \
92 TYPED_LIST_ITERATE(struct intel_dialog, dialoglist, pdialog)
93#define dialog_list_iterate_end LIST_ITERATE_END
94
102
103#define SPECLIST_TAG wonder_dialog
104#define SPECLIST_TYPE struct intel_wonder_dialog
105#include "speclist.h"
106
107#define wonder_dialog_list_iterate(dialoglist, pdialog) \
108 TYPED_LIST_ITERATE(struct intel_wonder_dialog, dialoglist, pdialog)
109#define wonder_dialog_list_iterate_end LIST_ITERATE_END
110
112static struct intel_dialog *create_intel_dialog(struct player *p);
115
116/**********************************************************************/
124
125/**********************************************************************/
133
134/**********************************************************************/
139{
141 if (pdialog->pplayer == pplayer) {
142 return pdialog;
143 }
145
146 return NULL;
147}
148
149/**********************************************************************/
154{
156 if (pdialog->pplayer == pplayer) {
157 return pdialog;
158 }
160
161 return NULL;
162}
163
164/**********************************************************************/
168{
169 struct intel_dialog *pdialog;
170
171 if (!(pdialog = get_intel_dialog(p))) {
173 }
174
176
178}
179
180/**********************************************************************/
184{
185 struct intel_wonder_dialog *pdialog;
186
187 if (!(pdialog = get_intel_wonder_dialog(p))) {
188 pdialog = create_intel_wonder_dialog(p);
189 }
190
192
194}
195
196/**********************************************************************/
200{
201 struct intel_dialog *pdialog = (struct intel_dialog *)data;
202
204
205 free(pdialog);
206}
207
208/**********************************************************************/
212{
213 struct intel_wonder_dialog *pdialog = (struct intel_wonder_dialog *)data;
214
216
217 free(pdialog);
218}
219
220/**********************************************************************/
229
230/**********************************************************************/
234{
235 struct intel_wonder_dialog *pdialog = get_intel_wonder_dialog(p);
236
238}
239
240/**********************************************************************/
244static struct intel_dialog *create_intel_dialog(struct player *p)
245{
246 struct intel_dialog *pdialog;
247
248 GtkWidget *shell, *notebook, *label, *sw, *view, *table;
251 int i;
252
253 pdialog = fc_malloc(sizeof(*pdialog));
254 pdialog->pplayer = p;
255
257 NULL,
258 0,
259 _("_Close"),
261 NULL);
262 pdialog->shell = shell;
266
267 g_signal_connect(shell, "destroy",
269 g_signal_connect(shell, "response",
271
272 notebook = gtk_notebook_new();
275
276 /* overview tab. */
278 g_object_set(table, "margin", 6, NULL);
279
282
283 /* TRANS: Overview tab of foreign intelligence report dialog */
284 label = gtk_label_new_with_mnemonic(_("_Overview"));
286
287 for (i = 0; i < ARRAY_SIZE(table_text); i++) {
288 if (table_text[i]) {
289 label = gtk_label_new(_(table_text[i]));
292 gtk_grid_attach(GTK_GRID(table), label, 0, i, 1, 1);
293
294 label = gtk_label_new(NULL);
295 pdialog->table_labels[i] = label;
298 gtk_grid_attach(GTK_GRID(table), label, 1, i, 1, 1);
299 } else {
300 pdialog->table_labels[i] = NULL;
301 }
302 }
303
304 /* diplomacy tab. */
305 pdialog->diplstates = gtk_tree_store_new(1, G_TYPE_STRING);
306
308 g_object_set(view, "margin", 6, NULL);
311 g_object_unref(pdialog->diplstates);
314
317 "text", 0, NULL);
319
321
326
329
330 label = gtk_label_new_with_mnemonic(_("_Diplomacy"));
331 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
332
333 /* techs tab. */
337
339 g_object_set(view, "margin", 6, NULL);
342 g_object_unref(pdialog->techs);
345
348 "active", 0, NULL);
350
353 "text", 1, NULL);
355
360
363
364 label = gtk_label_new_with_mnemonic(_("_Techs"));
365 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
366
368
370
371 return pdialog;
372}
373
374/**********************************************************************/
379{
380 struct intel_wonder_dialog *pdialog;
381 GtkWidget *shell, *sw, *view;
383 GtkWidget *box;
384
385 pdialog = fc_malloc(sizeof(*pdialog));
386 pdialog->pplayer = p;
387
389 NULL,
390 0,
391 _("_Close"),
393 NULL);
394 pdialog->shell = shell;
398
399 g_signal_connect(shell, "destroy",
401 g_signal_connect(shell, "response",
403
404
405 pdialog->rule = gtk_label_new("-");
406
407 /* columns: 0 - wonder name, 1 - location (city/unknown/lost),
408 * 2 - strikethrough (for lost or obsolete),
409 * 3 - font weight (great wonders in bold) */
413 G_TYPE_INT);
417 g_object_set(view, "margin", 6, NULL);
420 g_object_unref(pdialog->wonders);
423
426 rend, "text", 0,
427 "strikethrough", 2,
428 "weight", 3,
429 NULL);
430
433 rend, "text", 1,
434 NULL);
435
440 gtk_container_add(GTK_CONTAINER(box), pdialog->rule);
443
447
449 sw);
450
452
454
455 return pdialog;
456}
457
458/**********************************************************************/
463{
465
466 if (pdialog) {
467 const struct research *mresearch, *presearch;
468 GtkTreeIter diplstates[DS_LAST];
469 int i;
471 struct player *me = client_player();
474
475 /* window title. */
476 gchar *title = g_strdup_printf(_("Foreign Intelligence: %s Empire"),
479 g_free(title);
480
481 /* diplomacy tab. */
483
484 for (i = 0; i < ARRAY_SIZE(diplstates); i++) {
485 GtkTreeIter it;
486 GValue v = { 0, };
487
488 gtk_tree_store_append(pdialog->diplstates, &it, NULL);
491 gtk_tree_store_set_value(pdialog->diplstates, &it, 0, &v);
492 g_value_unset(&v);
493 diplstates[i] = it;
494 }
495
497 const struct player_diplstate *state;
498 GtkTreeIter it;
499 GValue v = { 0, };
500
501 if (other == p || !other->is_alive) {
502 continue;
503 }
504 state = player_diplstate_get(p, other);
505 gtk_tree_store_append(pdialog->diplstates, &it,
506 &diplstates[state->type]);
509 gtk_tree_store_set_value(pdialog->diplstates, &it, 0, &v);
510 g_value_unset(&v);
512
513 /* techs tab. */
514 gtk_list_store_clear(pdialog->techs);
515
520 GtkTreeIter it;
521
522 gtk_list_store_append(pdialog->techs, &it);
523
524 gtk_list_store_set(pdialog->techs, &it,
526 != TECH_KNOWN,
528 advi),
529 -1);
530 }
532
533 /* table labels. */
534 for (i = 0; i < ARRAY_SIZE(pdialog->table_labels); i++) {
535 if (pdialog->table_labels[i]) {
536 struct city *pcity;
537 gchar *buf = NULL;
538 char tbuf[256];
539
540 switch (i) {
541 case LABEL_RULER:
542 ruler_title_for_player(p, tbuf, sizeof(tbuf));
543 buf = g_strdup(tbuf);
544 break;
545 case LABEL_GOVERNMENT:
546 if (trade_knowledge) {
548 } else {
549 buf = g_strdup(_("(Unknown)"));
550 }
551 break;
552 case LABEL_CAPITAL:
554 /* TRANS: "unknown" location */
555 buf = g_strdup((!pcity) ? _("(Unknown)") : city_name_get(pcity));
556 break;
557 case LABEL_GOLD:
558 if (trade_knowledge) {
559 buf = g_strdup_printf("%d", p->economic.gold);
560 } else {
561 buf = g_strdup(_("(Unknown)"));
562 }
563 break;
564 case LABEL_TAX:
565 if (embassy_knowledge) {
566 buf = g_strdup_printf("%d%%", p->economic.tax);
567 } else {
568 buf = g_strdup(_("(Unknown)"));
569 }
570 break;
571 case LABEL_SCIENCE:
572 if (embassy_knowledge) {
573 buf = g_strdup_printf("%d%%", p->economic.science);
574 } else {
575 buf = g_strdup(_("(Unknown)"));
576 }
577 break;
578 case LABEL_LUXURY:
579 if (embassy_knowledge) {
580 buf = g_strdup_printf("%d%%", p->economic.luxury);
581 } else {
582 buf = g_strdup(_("(Unknown)"));
583 }
584 break;
586 {
587 struct research *research = research_get(p);
588
589 switch (research->researching) {
590 case A_UNKNOWN:
591 /* TRANS: "Unknown" advance/technology */
592 buf = g_strdup(_("(Unknown)"));
593 break;
594 case A_UNSET:
595 if (embassy_knowledge) {
596 /* TRANS: missing value */
597 buf = g_strdup(_("(none)"));
598 } else {
599 buf = g_strdup(_("(Unknown)"));
600 }
601 break;
602 default:
603 buf = g_strdup_printf("%s(%d/%d)",
608 break;
609 }
610 break;
611 }
612 case LABEL_CULTURE:
613 if (embassy_knowledge) {
614 buf = g_strdup_printf("%d", p->client.culture);
615 } else {
616 buf = g_strdup(_("(Unknown)"));
617 }
618 break;
619 }
620
621 if (buf) {
623 g_free(buf);
624 }
625 }
626 }
627 }
628
629 /* Update also wonders list dialog */
631}
632
633/**********************************************************************/
637{
638 struct intel_wonder_dialog *pdialog = get_intel_wonder_dialog(p);
639
640 if (pdialog != NULL) {
641 gchar *title = g_strdup_printf(_("Wonders of %s Empire"),
643 const char *rule = NULL;
644
646 g_free(title);
647
649 case WV_ALWAYS:
650 rule = _("All Wonders are known");
651 break;
652 case WV_NEVER:
653 rule = _("Small Wonders not known");
654 break;
655 case WV_EMBASSY:
656 rule = _("Small Wonders visible if we have an embassy");
657 break;
658 }
659
661
663
664 improvement_iterate(impr) {
665 if (is_wonder(impr)) {
666 GtkTreeIter it;
667 const char *cityname;
668 bool is_lost = FALSE;
669
670 if (wonder_is_built(p, impr)) {
671 struct city *pcity = city_from_wonder(p, impr);
672 if (pcity) {
673 cityname = city_name_get(pcity);
674 } else {
675 cityname = _("(unknown city)");
676 }
677 if (improvement_obsolete(p, impr, NULL)) {
678 is_lost = TRUE;
679 }
680 } else if (wonder_is_lost(p, impr)) {
681 cityname = _("(lost)");
682 is_lost = TRUE;
683 } else {
684 continue;
685 }
686
687 gtk_list_store_append(pdialog->wonders, &it);
688 gtk_list_store_set(pdialog->wonders, &it,
690 1, cityname,
691 2, is_lost,
692 /* font weight: great wonders in bold */
693 3, is_great_wonder(impr) ? 700 : 400,
694 -1);
695 }
697 }
698}
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
bool client_is_global_observer(void)
#define client_player()
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
bool could_intel_with_player(const struct player *pplayer, const struct player *aplayer)
Definition diptreaty.c:84
#define _(String)
Definition fcintl.h:67
#define N_(String)
Definition fcintl.h:69
struct civ_game game
Definition game.c:61
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Definition government.c:391
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:154
GtkWidget * toplevel
Definition gui_main.c:126
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:287
void popup_intel_dialog(struct player *p)
Definition inteldlg.c:167
static struct intel_dialog * get_intel_dialog(struct player *pplayer)
Definition inteldlg.c:138
static void intel_wonder_destroy_callback(GtkWidget *w, gpointer data)
Definition inteldlg.c:211
void close_intel_wonder_dialog(struct player *p)
Definition inteldlg.c:233
static struct intel_wonder_dialog * get_intel_wonder_dialog(struct player *pplayer)
Definition inteldlg.c:153
void close_intel_dialog(struct player *p)
Definition inteldlg.c:223
#define wonder_dialog_list_iterate_end
Definition inteldlg.c:109
static const char * table_text[]
Definition inteldlg.c:48
void update_intel_wonder_dialog(struct player *p)
Definition inteldlg.c:636
static void intel_destroy_callback(GtkWidget *w, gpointer data)
Definition inteldlg.c:199
#define wonder_dialog_list_iterate(dialoglist, pdialog)
Definition inteldlg.c:107
#define dialog_list_iterate_end
Definition inteldlg.c:93
void popup_intel_wonder_dialog(struct player *p)
Definition inteldlg.c:183
#define dialog_list_iterate(dialoglist, pdialog)
Definition inteldlg.c:91
void intel_dialog_done(void)
Definition inteldlg.c:128
static struct dialog_list * dialog_list
Definition inteldlg.c:111
static struct wonder_dialog_list * wonder_dialogs
Definition inteldlg.c:113
table_label
Definition inteldlg.c:62
@ LABEL_GOLD
Definition inteldlg.c:66
@ LABEL_GOVERNMENT
Definition inteldlg.c:64
@ LABEL_SEP2
Definition inteldlg.c:71
@ LABEL_LUXURY
Definition inteldlg.c:70
@ LABEL_SCIENCE
Definition inteldlg.c:69
@ LABEL_RULER
Definition inteldlg.c:63
@ LABEL_CULTURE
Definition inteldlg.c:73
@ LABEL_CAPITAL
Definition inteldlg.c:65
@ LABEL_RESEARCHING
Definition inteldlg.c:72
@ LABEL_TAX
Definition inteldlg.c:68
@ LABEL_SEP1
Definition inteldlg.c:67
@ LABEL_LAST
Definition inteldlg.c:74
static struct intel_wonder_dialog * create_intel_wonder_dialog(struct player *p)
Definition inteldlg.c:378
void intel_dialog_init(void)
Definition inteldlg.c:119
static struct intel_dialog * create_intel_dialog(struct player *p)
Definition inteldlg.c:244
void update_intel_dialog(struct player *p)
Definition inteldlg.c:462
static struct gui_dialog * shell
Definition messagedlg.c:39
const char * title
Definition repodlgs.c:1314
bool wonder_is_lost(const struct player *pplayer, const struct impr_type *pimprove)
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_malloc(sz)
Definition mem.h:34
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
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
struct city * player_primary_capital(const struct player *pplayer)
Definition player.c:1337
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
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
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
#define ARRAY_SIZE(x)
Definition shared.h:85
Definition city.h:317
struct packet_game_info info
Definition game.h:89
GtkWidget * shell
Definition inteldlg.c:80
GtkTreeStore * diplstates
Definition inteldlg.c:82
GtkListStore * techs
Definition inteldlg.c:83
struct advanced_dialog * pdialog
Definition inteldlg.c:52
struct player * pplayer
Definition inteldlg.c:79
GtkWidget * table_labels[LABEL_LAST]
Definition inteldlg.c:84
struct player * pplayer
Definition inteldlg.c:96
GtkWidget * rule
Definition inteldlg.c:100
GtkListStore * wonders
Definition inteldlg.c:99
GtkWidget * shell
Definition inteldlg.c:97
enum wonder_visib_type small_wonder_visibility
enum diplstate_type type
Definition player.h:199
const struct player_diplstate ** diplstates
Definition player.h:278
bool is_alive
Definition player.h:268
struct player_economic economic
Definition player.h:284
int culture
Definition player.h:367
struct player::@73::@76 client
Tech_type_id researching
Definition research.h:52
struct research::@79::@81 client
int researching_cost
Definition research.h:96
int bulbs_researched
Definition research.h:53
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define advance_index_iterate_end
Definition tech.h:244
#define A_FIRST
Definition tech.h:44
#define A_UNSET
Definition tech.h:48
#define A_UNKNOWN
Definition tech.h:49
#define advance_index_iterate(_start, _index)
Definition tech.h:240