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-4.0 */
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/******************************************************************/
78struct intel_dialog {
79 struct player *pplayer;
81
85};
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
96 struct player *pplayer;
98
101};
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. */
282
285
286 /* TRANS: Overview tab of foreign intelligence report dialog */
287 label = gtk_label_new_with_mnemonic(_("_Overview"));
289
290 for (i = 0; i < ARRAY_SIZE(table_text); i++) {
291 if (table_text[i]) {
292 label = gtk_label_new(_(table_text[i]));
295 gtk_grid_attach(GTK_GRID(table), label, 0, i, 1, 1);
296
297 label = gtk_label_new(NULL);
298 pdialog->table_labels[i] = label;
301 gtk_grid_attach(GTK_GRID(table), label, 1, i, 1, 1);
302 } else {
303 pdialog->table_labels[i] = NULL;
304 }
305 }
306
307 /* Diplomacy tab. */
308 pdialog->diplstates = gtk_tree_store_new(1, G_TYPE_STRING);
309
317 g_object_unref(pdialog->diplstates);
323
326 "text", 0, NULL);
328
330
334
337
338 label = gtk_label_new_with_mnemonic(_("_Diplomacy"));
339 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
340
341 /* techs tab. */
345
353 g_object_unref(pdialog->techs);
359
362 "active", 0, NULL);
364
367 "text", 1, NULL);
369
373
376
377 label = gtk_label_new_with_mnemonic(_("_Techs"));
378 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
379
381 TRUE);
382
384
385 return pdialog;
386}
387
388/**********************************************************************/
393{
394 struct intel_wonder_dialog *pdialog;
395 GtkWidget *shell, *sw, *view;
397 GtkWidget *box;
398
399 pdialog = fc_malloc(sizeof(*pdialog));
400 pdialog->pplayer = p;
401
403 NULL,
404 0,
405 _("_Close"),
407 NULL);
408 pdialog->shell = shell;
412
413 g_signal_connect(shell, "destroy",
415 g_signal_connect(shell, "response",
417
418
419 pdialog->rule = gtk_label_new("-");
420
421 /* Columns: 0 - wonder name, 1 - location (city/unknown/lost),
422 * 2 - strikethrough (for lost or obsolete),
423 * 3 - font weight (great wonders in bold) */
427 G_TYPE_INT);
437 g_object_unref(pdialog->wonders);
443
446 rend, "text", 0,
447 "strikethrough", 2,
448 "weight", 3,
449 NULL);
450
453 rend, "text", 1,
454 NULL);
455
459 gtk_box_append(GTK_BOX(box), pdialog->rule);
462
466
468
470 TRUE);
471
473
474 return pdialog;
475}
476
477/**********************************************************************/
482{
484
485 if (pdialog) {
486 const struct research *mresearch, *presearch;
487 GtkTreeIter diplstates[DS_LAST];
488 int i;
490 struct player *me = client_player();
493
494 /* Window title. */
495 gchar *title = g_strdup_printf(_("Foreign Intelligence: %s Empire"),
498 g_free(title);
499
500 /* Diplomacy tab. */
502
503 for (i = 0; i < ARRAY_SIZE(diplstates); i++) {
504 GtkTreeIter it;
505 GValue v = { 0, };
506
507 gtk_tree_store_append(pdialog->diplstates, &it, NULL);
510 gtk_tree_store_set_value(pdialog->diplstates, &it, 0, &v);
511 g_value_unset(&v);
512 diplstates[i] = it;
513 }
514
516 const struct player_diplstate *state;
517 GtkTreeIter it;
518 GValue v = { 0, };
519
520 if (other == p || !other->is_alive) {
521 continue;
522 }
523 state = player_diplstate_get(p, other);
524 gtk_tree_store_append(pdialog->diplstates, &it,
525 &diplstates[state->type]);
528 gtk_tree_store_set_value(pdialog->diplstates, &it, 0, &v);
529 g_value_unset(&v);
531
532 /* Techs tab. */
533 gtk_list_store_clear(pdialog->techs);
534
539 GtkTreeIter it;
540
541 gtk_list_store_append(pdialog->techs, &it);
542
543 gtk_list_store_set(pdialog->techs, &it,
545 != TECH_KNOWN,
547 advi),
548 -1);
549 }
551
552 /* Table labels. */
553 for (i = 0; i < ARRAY_SIZE(pdialog->table_labels); i++) {
554 if (pdialog->table_labels[i]) {
555 struct city *pcity;
556 gchar *buf = NULL;
557 char tbuf[256];
558
559 switch (i) {
560 case LABEL_RULER:
561 ruler_title_for_player(p, tbuf, sizeof(tbuf));
562 buf = g_strdup(tbuf);
563 break;
564 case LABEL_GOVERNMENT:
565 if (trade_knowledge) {
567 } else {
568 buf = g_strdup(_("(Unknown)"));
569 }
570 break;
571 case LABEL_CAPITAL:
573 /* TRANS: "unknown" location */
574 buf = g_strdup((!pcity) ? _("(Unknown)") : city_name_get(pcity));
575 break;
576 case LABEL_GOLD:
577 if (trade_knowledge) {
578 buf = g_strdup_printf("%d", p->economic.gold);
579 } else {
580 buf = g_strdup(_("(Unknown)"));
581 }
582 break;
583 case LABEL_TAX:
584 if (embassy_knowledge) {
585 buf = g_strdup_printf("%d%%", p->economic.tax);
586 } else {
587 buf = g_strdup(_("(Unknown)"));
588 }
589 break;
590 case LABEL_SCIENCE:
591 if (embassy_knowledge) {
592 buf = g_strdup_printf("%d%%", p->economic.science);
593 } else {
594 buf = g_strdup(_("(Unknown)"));
595 }
596 break;
597 case LABEL_LUXURY:
598 if (embassy_knowledge) {
599 buf = g_strdup_printf("%d%%", p->economic.luxury);
600 } else {
601 buf = g_strdup(_("(Unknown)"));
602 }
603 break;
605 {
606 struct research *research = research_get(p);
607
608 switch (research->researching) {
609 case A_UNKNOWN:
610 /* TRANS: "Unknown" advance/technology */
611 buf = g_strdup(_("(Unknown)"));
612 break;
613 case A_UNSET:
614 if (embassy_knowledge) {
615 /* TRANS: Missing value */
616 buf = g_strdup(_("(none)"));
617 } else {
618 buf = g_strdup(_("(Unknown)"));
619 }
620 break;
621 default:
622 buf = g_strdup_printf("%s(%d/%d)",
627 break;
628 }
629 break;
630 }
631 case LABEL_CULTURE:
632 if (embassy_knowledge) {
633 buf = g_strdup_printf("%d", p->client.culture);
634 } else {
635 buf = g_strdup(_("(Unknown)"));
636 }
637 break;
638 }
639
640 if (buf) {
642 g_free(buf);
643 }
644 }
645 }
646 }
647
648 /* Update also wonders list dialog */
650}
651
652/**********************************************************************/
656{
657 struct intel_wonder_dialog *pdialog = get_intel_wonder_dialog(p);
658
659 if (pdialog != NULL) {
660 gchar *title = g_strdup_printf(_("Wonders of %s Empire"),
662 const char *rule = NULL;
663
665 g_free(title);
666
668 case WV_ALWAYS:
669 rule = _("All Wonders are known");
670 break;
671 case WV_NEVER:
672 rule = _("Small Wonders not known");
673 break;
674 case WV_EMBASSY:
675 rule = _("Small Wonders visible if we have an embassy");
676 break;
677 }
678
680
682
683 improvement_iterate(impr) {
684 if (is_wonder(impr)) {
685 GtkTreeIter it;
686 const char *cityname;
687 bool is_lost = FALSE;
688
689 if (wonder_is_built(p, impr)) {
690 struct city *pcity = city_from_wonder(p, impr);
691
692 if (pcity) {
693 cityname = city_name_get(pcity);
694 } else {
695 cityname = _("(unknown city)");
696 }
697 if (improvement_obsolete(p, impr, NULL)) {
698 is_lost = TRUE;
699 }
700 } else if (wonder_is_lost(p, impr)) {
701 cityname = _("(lost)");
702 is_lost = TRUE;
703 } else {
704 continue;
705 }
706
707 gtk_list_store_append(pdialog->wonders, &it);
708 gtk_list_store_set(pdialog->wonders, &it,
710 1, cityname,
711 2, is_lost,
712 /* Font weight: great wonders in bold */
713 3, is_great_wonder(impr) ? 700 : 400,
714 -1);
715 }
717 }
718}
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