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-5.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#define FC_TYPE_TECH_ROW (fc_tech_row_get_type())
117
119
127
132
134
135#define FC_TYPE_WONDER_ROW (fc_wonder_row_get_type())
136
138
148
153
155
156#define TECH_ROW_NAME 0
157#define TECH_ROW_KNOWN 1
158
159#define WONDER_ROW_NAME 0
160#define WONDER_ROW_CITY 1
161
162/**********************************************************************/
165static void
169
170/**********************************************************************/
173static void
177
178/**********************************************************************/
182{
183 FcTechRow *result;
184
185 result = g_object_new(FC_TYPE_TECH_ROW, nullptr);
186
187 return result;
188}
189
190/**********************************************************************/
193static void
197
198/**********************************************************************/
201static void
205
206/**********************************************************************/
210{
211 FcWonderRow *result;
212
213 result = g_object_new(FC_TYPE_WONDER_ROW, nullptr);
214
215 return result;
216}
217
218/**********************************************************************/
226
227/**********************************************************************/
235
236/**********************************************************************/
241{
243 if (pdialog->pplayer == pplayer) {
244 return pdialog;
245 }
247
248 return NULL;
249}
250
251/**********************************************************************/
256{
258 if (pdialog->pplayer == pplayer) {
259 return pdialog;
260 }
262
263 return NULL;
264}
265
266/**********************************************************************/
270{
271 struct intel_dialog *pdialog;
272
273 if (!(pdialog = get_intel_dialog(p))) {
275 }
276
278
280}
281
282/**********************************************************************/
286{
287 struct intel_wonder_dialog *pdialog;
288
289 if (!(pdialog = get_intel_wonder_dialog(p))) {
290 pdialog = create_intel_wonder_dialog(p);
291 }
292
294
296}
297
298/**********************************************************************/
302{
303 struct intel_dialog *pdialog = (struct intel_dialog *)data;
304
306
307 free(pdialog);
308}
309
310/**********************************************************************/
314{
315 struct intel_wonder_dialog *pdialog = (struct intel_wonder_dialog *)data;
316
318
319 free(pdialog);
320}
321
322/**********************************************************************/
331
332/**********************************************************************/
336{
337 struct intel_wonder_dialog *pdialog = get_intel_wonder_dialog(p);
338
340}
341
342/**********************************************************************/
361
362/**********************************************************************/
375
376/**********************************************************************/
380static struct intel_dialog *create_intel_dialog(struct player *p)
381{
382 struct intel_dialog *pdialog;
383
384 GtkWidget *shell, *notebook, *label, *sw, *view, *table;
390 GtkSingleSelection *selection;
391 int i;
392
393 pdialog = fc_malloc(sizeof(*pdialog));
394 pdialog->pplayer = p;
395
397 NULL,
398 0,
399 _("_Close"),
401 NULL);
402 pdialog->shell = shell;
406
407 g_signal_connect(shell, "destroy",
409 g_signal_connect(shell, "response",
411
412 notebook = gtk_notebook_new();
415
416 /* Overview tab. */
422
425
426 /* TRANS: Overview tab of foreign intelligence report dialog */
427 label = gtk_label_new_with_mnemonic(_("_Overview"));
429
430 for (i = 0; i < ARRAY_SIZE(table_text); i++) {
431 if (table_text[i]) {
432 label = gtk_label_new(_(table_text[i]));
435 gtk_grid_attach(GTK_GRID(table), label, 0, i, 1, 1);
436
437 label = gtk_label_new(NULL);
438 pdialog->table_labels[i] = label;
441 gtk_grid_attach(GTK_GRID(table), label, 1, i, 1, 1);
442 } else {
443 pdialog->table_labels[i] = NULL;
444 }
445 }
446
447 /* Diplomacy tab. */
448 pdialog->diplstates = gtk_tree_store_new(1, G_TYPE_STRING);
449
457 g_object_unref(pdialog->diplstates);
463
466 "text", 0, NULL);
468
470
474
477
478 label = gtk_label_new_with_mnemonic(_("_Diplomacy"));
479 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
480
481 /* Techs tab. */
483
484 selection = gtk_single_selection_new(G_LIST_MODEL(pdialog->techs));
486
492
495
501
504
508
511
512 label = gtk_label_new_with_mnemonic(_("_Techs"));
513 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), sw, label);
514
516 TRUE);
517
519
520 return pdialog;
521}
522
523/**********************************************************************/
558
559/**********************************************************************/
568
569/**********************************************************************/
574{
575 struct intel_wonder_dialog *pdialog;
580 GtkSingleSelection *selection;
581 GtkWidget *box;
582
583 pdialog = fc_malloc(sizeof(*pdialog));
584 pdialog->pplayer = p;
585
587 NULL,
588 0,
589 _("_Close"),
591 NULL);
592 pdialog->shell = shell;
596
597 g_signal_connect(shell, "destroy",
599 g_signal_connect(shell, "response",
601
602
603 pdialog->rule = gtk_label_new("-");
604
606
607 selection = gtk_single_selection_new(G_LIST_MODEL(pdialog->wonders));
609
614 nullptr);
615
618
623 nullptr);
624
627
629 gtk_box_append(GTK_BOX(box), pdialog->rule);
631
633
635 TRUE);
636
638
639 return pdialog;
640}
641
642/**********************************************************************/
647{
649
650 if (pdialog) {
651 const struct research *mresearch, *presearch;
652 GtkTreeIter diplstates[DS_LAST];
653 int i;
655 struct player *me = client_player();
658
659 /* Window title. */
660 gchar *title = g_strdup_printf(_("Foreign Intelligence: %s Empire"),
663 g_free(title);
664
665 /* Diplomacy tab. */
667
668 for (i = 0; i < ARRAY_SIZE(diplstates); i++) {
669 GtkTreeIter it;
670 GValue v = { 0, };
671
672 gtk_tree_store_append(pdialog->diplstates, &it, NULL);
675 gtk_tree_store_set_value(pdialog->diplstates, &it, 0, &v);
676 g_value_unset(&v);
677 diplstates[i] = it;
678 }
679
681 const struct player_diplstate *state;
682 GtkTreeIter it;
683 GValue v = { 0, };
684
685 if (other == p || !other->is_alive) {
686 continue;
687 }
688 state = player_diplstate_get(p, other);
689 gtk_tree_store_append(pdialog->diplstates, &it,
690 &diplstates[state->type]);
693 gtk_tree_store_set_value(pdialog->diplstates, &it, 0, &v);
694 g_value_unset(&v);
696
697 /* Techs tab. */
699
705
708
709 g_list_store_append(pdialog->techs, row);
711 }
713
714 /* Table labels. */
715 for (i = 0; i < ARRAY_SIZE(pdialog->table_labels); i++) {
716 if (pdialog->table_labels[i]) {
717 struct city *pcity;
718 gchar *buf = NULL;
719 char tbuf[256];
720
721 switch (i) {
722 case LABEL_RULER:
723 ruler_title_for_player(p, tbuf, sizeof(tbuf));
724 buf = g_strdup(tbuf);
725 break;
726 case LABEL_GOVERNMENT:
727 if (trade_knowledge) {
729 } else {
730 buf = g_strdup(_("(Unknown)"));
731 }
732 break;
733 case LABEL_CAPITAL:
735 /* TRANS: "unknown" location */
736 buf = g_strdup((!pcity) ? _("(Unknown)") : city_name_get(pcity));
737 break;
738 case LABEL_GOLD:
739 if (trade_knowledge) {
740 buf = g_strdup_printf("%d", p->economic.gold);
741 } else {
742 buf = g_strdup(_("(Unknown)"));
743 }
744 break;
745 case LABEL_TAX:
746 if (embassy_knowledge) {
747 buf = g_strdup_printf("%d%%", p->economic.tax);
748 } else {
749 buf = g_strdup(_("(Unknown)"));
750 }
751 break;
752 case LABEL_SCIENCE:
753 if (embassy_knowledge) {
754 buf = g_strdup_printf("%d%%", p->economic.science);
755 } else {
756 buf = g_strdup(_("(Unknown)"));
757 }
758 break;
759 case LABEL_LUXURY:
760 if (embassy_knowledge) {
761 buf = g_strdup_printf("%d%%", p->economic.luxury);
762 } else {
763 buf = g_strdup(_("(Unknown)"));
764 }
765 break;
767 {
768 struct research *research = research_get(p);
769
770 switch (research->researching) {
771 case A_UNKNOWN:
772 /* TRANS: "Unknown" advance/technology */
773 buf = g_strdup(_("(Unknown)"));
774 break;
775 case A_UNSET:
776 if (embassy_knowledge) {
777 /* TRANS: Missing value */
778 buf = g_strdup(_("(none)"));
779 } else {
780 buf = g_strdup(_("(Unknown)"));
781 }
782 break;
783 default:
784 buf = g_strdup_printf("%s(%d/%d)",
789 break;
790 }
791 break;
792 }
793 case LABEL_CULTURE:
794 if (embassy_knowledge) {
795 buf = g_strdup_printf("%d", p->client.culture);
796 } else {
797 buf = g_strdup(_("(Unknown)"));
798 }
799 break;
800 }
801
802 if (buf) {
804 g_free(buf);
805 }
806 }
807 }
808 }
809
810 /* Update also wonders list dialog */
812}
813
814/**********************************************************************/
818{
819 struct intel_wonder_dialog *pdialog = get_intel_wonder_dialog(p);
820
821 if (pdialog != NULL) {
822 gchar *title = g_strdup_printf(_("Wonders of %s Empire"),
824 const char *rule = NULL;
825
827 g_free(title);
828
830 case WV_ALWAYS:
831 rule = _("All Wonders are known");
832 break;
833 case WV_NEVER:
834 rule = _("Small Wonders not known");
835 break;
836 case WV_EMBASSY:
837 rule = _("Small Wonders visible if we have an embassy");
838 break;
839 }
840
842
844
845 improvement_iterate(impr) {
846 if (is_wonder(impr)) {
847 const char *cityname;
848 bool is_lost = FALSE;
850
851 if (wonder_is_built(p, impr)) {
852 struct city *pcity = city_from_wonder(p, impr);
853
854 if (pcity) {
855 cityname = city_name_get(pcity);
856 } else {
857 cityname = _("(unknown city)");
858 }
859 if (improvement_obsolete(p, impr, NULL)) {
860 is_lost = TRUE;
861 }
862 } else if (wonder_is_lost(p, impr)) {
863 cityname = _("(lost)");
864 is_lost = TRUE;
865 } else {
866 continue;
867 }
868
869 row->name = improvement_name_translation(impr);
870 row->cityname = cityname;
871 row->is_lost = is_lost;
872 row->font_weight = is_great_wonder(impr) ? 700 : 400;
873
876 }
878 }
879}
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
static struct ai_type * self
Definition classicai.c:46
bool client_is_global_observer(void)
#define client_player()
static struct fc_sockaddr_list * list
Definition clinet.c:102
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
#define WONDER_ROW_CITY
Definition inteldlg.c:160
static void fc_tech_row_init(FcTechRow *self)
Definition inteldlg.c:174
static void wonder_factory_bind(GtkSignalListItemFactory *self, GtkListItem *list_item, gpointer user_data)
Definition inteldlg.c:526
#define TECH_ROW_KNOWN
Definition inteldlg.c:157
static void fc_tech_row_class_init(FcTechRowClass *klass)
Definition inteldlg.c:166
static FcWonderRow * fc_wonder_row_new(void)
Definition inteldlg.c:209
#define FC_TYPE_TECH_ROW
Definition inteldlg.c:116
static void fc_wonder_row_init(FcWonderRow *self)
Definition inteldlg.c:202
#define WONDER_ROW_NAME
Definition inteldlg.c:159
static void fc_wonder_row_class_init(FcWonderRowClass *klass)
Definition inteldlg.c:194
static FcTechRow * fc_tech_row_new(void)
Definition inteldlg.c:181
#define TECH_ROW_NAME
Definition inteldlg.c:156
static void tech_factory_bind(GtkSignalListItemFactory *self, GtkListItem *list_item, gpointer user_data)
Definition inteldlg.c:345
#define FC_TYPE_WONDER_ROW
Definition inteldlg.c:135
static void tech_factory_setup(GtkSignalListItemFactory *self, GtkListItem *list_item, gpointer user_data)
Definition inteldlg.c:365
static void wonder_factory_setup(GtkSignalListItemFactory *self, GtkListItem *list_item, gpointer user_data)
Definition inteldlg.c:562
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_assert(condition)
Definition log.h:177
#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
GObjectClass parent_class
Definition inteldlg.c:130
const char * name
Definition inteldlg.c:125
GObject parent_instance
Definition inteldlg.c:122
bool unknown
Definition inteldlg.c:124
GObjectClass parent_class
Definition inteldlg.c:151
int font_weight
Definition inteldlg.c:146
const char * name
Definition inteldlg.c:143
GObject parent_instance
Definition inteldlg.c:141
const char * cityname
Definition inteldlg.c:144
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
GListStore * techs
Definition inteldlg.c:83
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
GListStore * wonders
Definition inteldlg.c:99
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