Freeciv-3.2
Loading...
Searching...
No Matches
editprop.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
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 <limits.h> /* USHRT_MAX */
19
20#include <gtk/gtk.h>
21#include <gdk/gdkkeysyms.h>
22
23/* utility */
24#include "bitvector.h"
25#include "fc_cmdline.h"
26#include "fcintl.h"
27#include "log.h"
28#include "mem.h"
29
30/* common */
31#include "fc_interface.h"
32#include "game.h"
33#include "government.h"
34#include "map.h"
35#include "movement.h"
36#include "nation.h"
37#include "research.h"
38#include "tile.h"
39
40/* client */
41#include "client_main.h"
42#include "climisc.h"
43#include "editor.h"
44#include "mapview_common.h"
45#include "tilespec.h"
46
47/* client/gui-gtk-3.22 */
48#include "canvas.h"
49#include "gui_main.h"
50#include "gui_stuff.h"
51#include "plrdlg.h"
52#include "sprite.h"
53
54#include "editprop.h"
55
56
57/* Forward declarations. */
58struct objprop;
59struct objbind;
60struct property_page;
61struct property_editor;
62struct extviewer;
63
64/****************************************************************************
65 Miscellaneous helpers.
66****************************************************************************/
67static GdkPixbuf *create_pixbuf_from_layers(const struct tile *ptile,
68 const struct unit *punit,
69 const struct city *pcity,
70 enum layer_category category);
71static GdkPixbuf *create_tile_pixbuf(const struct tile *ptile);
72static GdkPixbuf *create_unit_pixbuf(const struct unit *punit);
73static GdkPixbuf *create_city_pixbuf(const struct city *pcity);
74
75static void add_column(GtkWidget *view,
76 int col_id,
77 const char *name,
79 bool editable,
80 bool is_radio,
83
84static bool can_create_unit_at_tile(struct tile *ptile);
85
86static int get_next_unique_tag(void);
87
88/* 'struct stored_tag_hash' and related functions. */
89#define SPECHASH_TAG stored_tag
90#define SPECHASH_INT_KEY_TYPE
91#define SPECHASH_INT_DATA_TYPE
92#include "spechash.h"
93
94/* NB: If packet definitions change, be sure to
95 * update objbind_pack_current_values()!!! */
111
112/* Helpers for the OPID_TILE_VISION property. */
116const char *vision_layer_get_name(enum vision_layer);
117
118#define PF_MAX_CLAUSES 16
119#define PF_DISJUNCTION_SEPARATOR "|"
120#define PF_CONJUNCTION_SEPARATOR "&"
121
123 bool negate;
124 char *text;
125};
126
131
136
137static struct property_filter *property_filter_new(const char *filter);
138static bool property_filter_match(struct property_filter *pf,
139 const struct objprop *op);
140static void property_filter_free(struct property_filter *pf);
141
142
143/****************************************************************************
144 Object type declarations.
145
146 To add a new object type:
147 1. Add a value in enum editor_object_type in client/editor.h.
148 2. Add a string name to objtype_get_name.
149 3. Add code in objtype_get_id_from_object.
150 4. Add code in objtype_get_object_from_id.
151 5. Add a case handler in objtype_is_conserved, and if
152 the object type is not conserved, then also in
153 objbind_request_destroy_object and property_page_create_objects.
154 6. Add an if-block in objbind_get_value_from_object.
155 7. Add an if-block in objbind_get_allowed_value_span.
156 9. Add a case handler in property_page_setup_objprops.
157 10. Add a case handler in property_page_add_objbinds_from_tile
158 if applicable.
159
160 Furthermore, if the object type is to be editable:
161 11. Define its edit packet in common/networking/packets.def.
162 12. Add the packet handler in server/edithand.c.
163 13. Add its edit packet type to union packetdata.
164 14. Add an if-block in objbind_pack_current_values.
165 15. Add an if-block in objbind_pack_modified_value.
166 16. Add code in property_page_new_packet.
167 17. Add code in property_page_send_packet.
168 18. Add calls to editgui_notify_object_changed in
169 client/packhand.c or where applicable.
170
171****************************************************************************/
172
173/* OBJTYPE_* enum values defined in client/editor.h */
174
175static const char *objtype_get_name(enum editor_object_type objtype);
177 gpointer object);
179 int id);
181
182
183/****************************************************************************
184 Value type declarations.
185
186 To add a new value type:
187 1. Add a value in enum value_types.
188 2. Add its field in union propval_data.
189 3. Add a case handler in valtype_get_name.
190 4. Add a case handler in propval_copy if needed.
191 5. Add a case handler in propval_free if needed.
192 6. Add a case handler in propval_equal if needed.
193 7. Add a case handler in objprop_get_gtype.
194 8. Add a case handler in property_page_set_store_value.
195 9. Add a case handler in propval_as_string if needed.
196****************************************************************************/
213
214static const char *valtype_get_name(enum value_types valtype);
215
216
217/****************************************************************************
218 Propstate and propval declarations.
219
220 To add a new member to union propval_data, see the steps for adding a
221 new value type above.
222
223 New property values are "constructed" by objbind_get_value_from_object().
224****************************************************************************/
242
248
249static void propval_free(struct propval *pv);
250static void propval_free_data(struct propval *pv);
251static struct propval *propval_copy(struct propval *pv);
252static bool propval_equal(struct propval *pva, struct propval *pvb);
253
258
259static struct propstate *propstate_new(struct objprop *op,
260 struct propval *pv);
261static void propstate_destroy(struct propstate *ps);
262static void propstate_clear_value(struct propstate *ps);
263static void propstate_set_value(struct propstate *ps,
264 struct propval *pv);
265static struct propval *propstate_get_value(struct propstate *ps);
266
267#define SPECHASH_TAG propstate
268#define SPECHASH_INT_KEY_TYPE
269#define SPECHASH_IDATA_TYPE struct propstate *
270#define SPECHASH_IDATA_FREE propstate_destroy
271#include "spechash.h"
272
273
274/****************************************************************************
275 Objprop declarations.
276
277 To add a new object property:
278 1. Add a value in enum object_property_ids (grouped by
279 object type).
280 2. Define the property in property_page_setup_objprops.
281 3. Add a case handler in objbind_get_value_from_object
282 in the appropriate object type block.
283 4. Add a case handler in objprop_setup_widget.
284 5. Add a case handler in objprop_refresh_widget.
285
286 Furthermore, if the property is editable:
287 5. Add a field for this property in the edit
288 packet for this object type in common/networking/packets.def.
289 6. Add a case handler in objbind_pack_modified_value.
290 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
291 !!! 7. Add code to set the packet field in !!!
292 !!! objbind_pack_current_values(). !!!
293 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
294 8. Add code to handle changes in the packet field in
295 server/edithand.c handle_edit_<objtype>.
296
297 If the property makes use of an extviewer:
298 9. Handle widget creation in extviewer_new.
299 10. Handle refresh in extviewer_refresh_widgets.
300 11. Handle clear in extviewer_clear_widgets.
301 12. Handle any signal callbacks (e.g. toggled) if needed.
302
303 TODO: Add more object properties.
304****************************************************************************/
312#ifdef FREECIV_DEBUG
314#endif /* FREECIV_DEBUG */
322 OPID_TILE_VISION, /* tile_known and tile_seen */
324
329
331#ifdef FREECIV_DEBUG
333#endif /* FREECIV_DEBUG */
344
347#ifdef FREECIV_DEBUG
349#endif /* FREECIV_DEBUG */
357
362#ifdef FREECIV_DEBUG
364#endif /* FREECIV_DEBUG */
371
383
390
403
404static struct objprop *objprop_new(int id,
405 const char *name,
406 const char *tooltip,
408 enum value_types valtype,
409 struct property_page *parent);
410static int objprop_get_id(const struct objprop *op);
411static const char *objprop_get_name(const struct objprop *op);
412static const char *objprop_get_tooltip(const struct objprop *op);
413static enum value_types objprop_get_valtype(const struct objprop *op);
414static struct property_page *
416
417static bool objprop_show_in_listview(const struct objprop *op);
418static bool objprop_is_sortable(const struct objprop *op);
419static bool objprop_is_readonly(const struct objprop *op);
420static bool objprop_has_widget(const struct objprop *op);
421
422static GType objprop_get_gtype(const struct objprop *op);
423static const char *objprop_get_attribute_type_string(const struct objprop *op);
424static void objprop_set_column_id(struct objprop *op, int col_id);
425static int objprop_get_column_id(const struct objprop *op);
426static void objprop_set_treeview_column(struct objprop *op,
430
431static void objprop_setup_widget(struct objprop *op);
432static GtkWidget *objprop_get_widget(struct objprop *op);
433static void objprop_set_child_widget(struct objprop *op,
434 const char *widget_name,
437 const char *widget_name);
438static void objprop_set_extviewer(struct objprop *op,
439 struct extviewer *ev);
440static struct extviewer *objprop_get_extviewer(struct objprop *op);
441static void objprop_refresh_widget(struct objprop *op,
442 struct objbind *ob);
448
449#define SPECHASH_TAG objprop
450#define SPECHASH_INT_KEY_TYPE
451#define SPECHASH_IDATA_TYPE struct objprop *
452#include "spechash.h"
453
454
455/****************************************************************************
456 Objbind declarations.
457****************************************************************************/
465
467 gpointer object);
468static void objbind_destroy(struct objbind *ob);
469static enum editor_object_type objbind_get_objtype(const struct objbind *ob);
470static void objbind_bind_properties(struct objbind *ob,
471 struct property_page *pp);
472static gpointer objbind_get_object(struct objbind *ob);
473static int objbind_get_object_id(struct objbind *ob);
474static void objbind_request_destroy_object(struct objbind *ob);
475static struct propval *objbind_get_value_from_object(struct objbind *ob,
476 struct objprop *op);
477static bool objbind_get_allowed_value_span(struct objbind *ob,
478 struct objprop *op,
479 double *pmin,
480 double *pmax,
481 double *pstep,
482 double *pbig_step);
483static bool objbind_set_modified_value(struct objbind *ob,
484 struct objprop *op,
485 struct propval *pv);
486static struct propval *objbind_get_modified_value(struct objbind *ob,
487 struct objprop *op);
488static void objbind_clear_modified_value(struct objbind *ob,
489 struct objprop *op);
490static bool objbind_property_is_modified(struct objbind *ob,
491 struct objprop *op);
492static bool objbind_has_modified_properties(struct objbind *ob);
493static void objbind_clear_all_modified_values(struct objbind *ob);
494static void objbind_pack_current_values(struct objbind *ob,
495 union packetdata packet);
496static void objbind_pack_modified_value(struct objbind *ob,
497 struct objprop *op,
498 union packetdata packet);
499static void objbind_set_rowref(struct objbind *ob,
502
503#define SPECHASH_TAG objbind
504#define SPECHASH_INT_KEY_TYPE
505#define SPECHASH_IDATA_TYPE struct objbind *
506#define SPECHASH_IDATA_FREE objbind_destroy
507#include "spechash.h"
508
509
510/****************************************************************************
511 Extended property viewer declarations. This is a set of widgets used
512 for viewing and/or editing properties with complex values (e.g. arrays).
513****************************************************************************/
529
530static struct extviewer *extviewer_new(struct objprop *op);
531static struct objprop *extviewer_get_objprop(struct extviewer *ev);
534static void extviewer_refresh_widgets(struct extviewer *ev,
535 struct propval *pv);
536static void extviewer_clear_widgets(struct extviewer *ev);
537static void extviewer_panel_button_clicked(GtkButton *button,
540 gchar *path,
542static void extviewer_textbuf_changed(GtkTextBuffer *textbuf,
544
545
546/****************************************************************************
547 Property page declarations.
548****************************************************************************/
565
566static struct property_page *
568 struct property_editor *parent);
570static const char *property_page_get_name(const struct property_page *pp);
571static enum editor_object_type
573static void property_page_load_tiles(struct property_page *pp,
574 const struct tile_list *tiles);
576 const struct tile *ptile);
577static int property_page_get_num_objbinds(const struct property_page *pp);
579static void property_page_add_objbind(struct property_page *pp,
581static void property_page_fill_widgets(struct property_page *pp);
582static struct objbind *
585 struct objbind *ob);
587 int object_id);
591 GtkTreeModel *model,
592 GtkTreePath *path,
594 gpointer data);
598 struct objprop *op,
599 struct propval *pv);
600static void property_page_send_values(struct property_page *pp);
604 struct tile_list *hint_tiles);
606static void property_page_send_packet(struct property_page *pp,
607 union packetdata packet);
608static void property_page_free_packet(struct property_page *pp,
609 union packetdata packet);
611 int object_id,
612 bool remove);
614 int tag, int object_id);
616 struct extviewer *ev);
618 struct extviewer *ev);
620 int tag, int count);
622 int tag);
623static bool property_page_tag_is_known(struct property_page *pp, int tag);
624static void property_page_clear_tags(struct property_page *pp);
633
634
635#define property_page_objprop_iterate(ARG_pp, NAME_op) \
636 TYPED_HASH_DATA_ITERATE(struct objprop *, (ARG_pp)->objprop_table, NAME_op)
637#define property_page_objprop_iterate_end HASH_DATA_ITERATE_END
638
639#define property_page_objbind_iterate(ARG_pp, NAME_ob) \
640 TYPED_HASH_DATA_ITERATE(struct objbind *, (ARG_pp)->objbind_table, NAME_ob)
641#define property_page_objbind_iterate_end HASH_DATA_ITERATE_END
642
643
644/****************************************************************************
645 Property editor declarations.
646****************************************************************************/
653
654static struct property_editor *property_editor_new(void);
657static struct property_page *
660
662
663
664/************************************************************************/
668{
669 switch (objtype) {
670 case OBJTYPE_TILE:
671 return _("Tile");
672 case OBJTYPE_STARTPOS:
673 return _("Start Position");
674 case OBJTYPE_UNIT:
675 return _("Unit");
676 case OBJTYPE_CITY:
677 return _("City");
678 case OBJTYPE_PLAYER:
679 return _("Player");
680 case OBJTYPE_GAME:
681 return Q_("?play:Game");
682 case NUM_OBJTYPES:
683 break;
684 }
685
686 log_error("%s() Unhandled request to get name of object type %d.",
688 return "Unknown";
689}
690
691/************************************************************************/
697 gpointer object)
698{
699 switch (objtype) {
700 case OBJTYPE_TILE:
701 return tile_index((struct tile *) object);
702 case OBJTYPE_STARTPOS:
703 return startpos_number((struct startpos *) object);
704 case OBJTYPE_UNIT:
705 return ((struct unit *) object)->id;
706 case OBJTYPE_CITY:
707 return ((struct city *) object)->id;
708 case OBJTYPE_PLAYER:
709 return player_number((struct player *) object);
710 case OBJTYPE_GAME:
711 return 1;
712 case NUM_OBJTYPES:
713 break;
714 }
715
716 log_error("%s(): Unhandled request to get object ID from object %p of "
717 "type %d (%s).", __FUNCTION__, object, objtype,
719 return -1;
720}
721
722/************************************************************************/
726 int id)
727{
728 switch (objtype) {
729 case OBJTYPE_TILE:
730 return index_to_tile(&(wld.map), id);
731 case OBJTYPE_STARTPOS:
732 return map_startpos_by_number(id);
733 case OBJTYPE_UNIT:
734 return game_unit_by_number(id);
735 case OBJTYPE_CITY:
736 return game_city_by_number(id);
737 case OBJTYPE_PLAYER:
738 return player_by_number(id);
739 case OBJTYPE_GAME:
740 return &game;
741 case NUM_OBJTYPES:
742 break;
743 }
744
745 log_error("%s(): Unhandled request to get object of type %d (%s) "
746 "with ID %d.", __FUNCTION__, objtype,
748 return NULL;
749}
750
751/************************************************************************/
757{
758 switch (objtype) {
759 case OBJTYPE_TILE:
760 case OBJTYPE_GAME:
761 return TRUE;
762 case OBJTYPE_STARTPOS:
763 case OBJTYPE_UNIT:
764 case OBJTYPE_CITY:
765 case OBJTYPE_PLAYER:
766 return FALSE;
767 case NUM_OBJTYPES:
768 break;
769 }
770
771 log_error("%s(): Unhandled request for object type %d (%s)).",
773 return TRUE;
774}
775
776/************************************************************************/
779static const char *valtype_get_name(enum value_types valtype)
780{
781 switch (valtype) {
782 case VALTYPE_NONE:
783 return "none";
784 case VALTYPE_STRING:
785 return "string";
786 case VALTYPE_INT:
787 return "int";
788 case VALTYPE_BOOL:
789 return "bool";
790 case VALTYPE_PIXBUF:
791 return "pixbuf";
793 return "struct built_status[B_LAST]";
795 return "bool[A_LAST]";
797 return "bv_special";
798 case VALTYPE_BV_ROADS:
799 return "bv_roads";
800 case VALTYPE_BV_BASES:
801 return "bv_bases";
802 case VALTYPE_NATION:
803 return "nation";
805 return "struct nation_hash";
806 case VALTYPE_GOV:
807 return "government";
809 return "struct tile_vision_data";
810 }
811
812 log_error("%s(): unhandled value type %d.", __FUNCTION__, valtype);
813 return "void";
814}
815
816/************************************************************************/
821 int col_id,
822 const char *name,
823 GType gtype,
824 bool editable,
825 bool is_radio,
828{
831 const char *attr = NULL;
832
833 if (gtype == G_TYPE_BOOLEAN) {
836 is_radio);
837 if (editable) {
839 }
840 attr = "active";
841 } else if (gtype == GDK_TYPE_PIXBUF) {
843 attr = "pixbuf";
844 } else {
846 if (editable) {
847 g_object_set(cell, "editable", TRUE, NULL);
849 }
850 attr = "text";
851 }
852
854 attr, col_id, NULL);
856}
857
858/************************************************************************/
863{
864 int count = 0;
865
867
868 switch (pv->valtype) {
869 case VALTYPE_NONE:
870 return g_strdup("");
871
872 case VALTYPE_INT:
873 return g_strdup_printf("%d", pv->data.v_int);
874
875 case VALTYPE_BOOL:
876 return g_strdup_printf("%s", pv->data.v_bool ? _("TRUE") : _("FALSE"));
877
878 case VALTYPE_NATION:
879 return g_strdup_printf("%s", nation_adjective_translation(pv->data.v_nation));
880
881 case VALTYPE_GOV:
882 if (pv->data.v_gov != NULL) {
883 return g_strdup_printf("%s", government_name_translation(pv->data.v_gov));
884 } else {
886 }
887
889 {
890 int great_wonder_count = 0, small_wonder_count = 0, building_count = 0;
891 int id;
892
893 improvement_iterate(pimprove) {
894 id = improvement_index(pimprove);
895 if (pv->data.v_built[id].turn < 0) {
896 continue;
897 }
898 if (is_great_wonder(pimprove)) {
900 } else if (is_small_wonder(pimprove)) {
902 } else {
903 building_count++;
904 }
906 /* TRANS: "Number of buildings, number of small
907 * wonders (e.g. palace), number of great wonders." */
908 return g_strdup_printf(_("%db %ds %dW"),
909 building_count, small_wonder_count,
911 }
912
915 if (BV_ISSET(pv->data.v_bv_inventions, tech)) {
916 count++;
917 }
919 /* TRANS: "Number of technologies known". */
920 return g_strdup_printf(_("%d known"), count);
921
924 if (BV_ISSET(pv->data.v_bv_special, spe->data.special_idx)) {
925 count++;
926 }
928 /* TRANS: "The number of terrain specials (e.g. hut,
929 * river, pollution, etc.) present on a tile." */
930 return g_strdup_printf(_("%d present"), count);
931
932 case VALTYPE_BV_ROADS:
934 struct road_type *proad = extra_road_get(pextra);
935
936 if (BV_ISSET(pv->data.v_bv_roads, road_number(proad))) {
937 count++;
938 }
940 return g_strdup_printf(_("%d present"), count);
941
942 case VALTYPE_BV_BASES:
944 struct base_type *pbase = extra_base_get(pextra);
945
946 if (BV_ISSET(pv->data.v_bv_bases, base_number(pbase))) {
947 count++;
948 }
950 return g_strdup_printf(_("%d present"), count);
951
953 count = nation_hash_size(pv->data.v_nation_hash);
954 if (0 == count) {
955 return g_strdup(_("All nations"));
956 } else {
957 return g_strdup_printf(PL_("%d nation", "%d nations",
958 count), count);
959 }
960
961 case VALTYPE_STRING:
962 /* Assume it is a very long string. */
963 count = strlen(pv->data.v_const_string);
964 return g_strdup_printf(PL_("%d byte", "%d bytes", count),
965 count);
966
967 case VALTYPE_PIXBUF:
969 break;
970 }
971
972 log_error("%s(): Unhandled value type %d for property value %p.",
973 __FUNCTION__, pv->valtype, pv);
974 return g_strdup("");
975}
976
977/************************************************************************/
982{
983 int turn_built;
984
985 turn_built = bs->turn;
986
987 if (turn_built == I_NEVER) {
988 /* TRANS: Improvement never built. */
989 return g_strdup(_("(never)"));
990 } else if (turn_built == I_DESTROYED) {
991 /* TRANS: Improvement was destroyed. */
992 return g_strdup(_("(destroyed)"));
993 } else {
994 return g_strdup_printf("%d", turn_built);
995 }
996}
997
998/************************************************************************/
1002static bool can_create_unit_at_tile(struct tile *ptile)
1003{
1004 struct unit *vunit;
1005 struct city *pcity;
1006 struct player *pplayer;
1007 bool ret;
1008
1009 if (!ptile) {
1010 return FALSE;
1011 }
1012
1014 if (!vunit) {
1015 return FALSE;
1016 }
1017
1018 pcity = tile_city(ptile);
1019 pplayer = unit_owner(vunit);
1020
1021 ret = (can_unit_exist_at_tile(&(wld.map), vunit, ptile)
1022 && !is_non_allied_unit_tile(ptile, pplayer)
1023 && (pcity == NULL
1024 || pplayers_allied(city_owner(pcity),
1025 unit_owner(vunit))));
1026 free(vunit);
1027
1028 return ret;
1029}
1030
1031/************************************************************************/
1034static int get_next_unique_tag(void)
1035{
1036 static int tag_series = 0;
1037
1038 tag_series++;
1039 return tag_series;
1040}
1041
1042/************************************************************************/
1045static struct propval *propval_copy(struct propval *pv)
1046{
1047 struct propval *pv_copy;
1048 size_t size;
1049
1050 if (!pv) {
1051 return NULL;
1052 }
1053
1054 pv_copy = fc_calloc(1, sizeof(*pv));
1055 pv_copy->valtype = pv->valtype;
1056
1057 switch (pv->valtype) {
1058 case VALTYPE_NONE:
1059 return pv_copy;
1060 case VALTYPE_INT:
1061 pv_copy->data.v_int = pv->data.v_int;
1062 return pv_copy;
1063 case VALTYPE_BOOL:
1064 pv_copy->data.v_bool = pv->data.v_bool;
1065 return pv_copy;
1066 case VALTYPE_STRING:
1067 pv_copy->data.v_string = fc_strdup(pv->data.v_string);
1068 pv_copy->must_free = TRUE;
1069 return pv_copy;
1070 case VALTYPE_PIXBUF:
1071 g_object_ref(pv->data.v_pixbuf);
1072 pv_copy->data.v_pixbuf = pv->data.v_pixbuf;
1073 pv_copy->must_free = TRUE;
1074 return pv_copy;
1076 size = B_LAST * sizeof(struct built_status);
1077 pv_copy->data.v_pointer = fc_malloc(size);
1078 memcpy(pv_copy->data.v_pointer, pv->data.v_pointer, size);
1079 pv_copy->must_free = TRUE;
1080 return pv_copy;
1081 case VALTYPE_BV_SPECIAL:
1082 pv_copy->data.v_bv_special = pv->data.v_bv_special;
1083 return pv_copy;
1084 case VALTYPE_BV_ROADS:
1085 pv_copy->data.v_bv_roads = pv->data.v_bv_roads;
1086 return pv_copy;
1087 case VALTYPE_BV_BASES:
1088 pv_copy->data.v_bv_bases = pv->data.v_bv_bases;
1089 return pv_copy;
1090 case VALTYPE_NATION:
1091 pv_copy->data.v_nation = pv->data.v_nation;
1092 return pv_copy;
1093 case VALTYPE_GOV:
1094 pv_copy->data.v_gov = pv->data.v_gov;
1095 return pv_copy;
1097 pv_copy->data.v_nation_hash
1098 = nation_hash_copy(pv->data.v_nation_hash);
1099 pv_copy->must_free = TRUE;
1100 return pv_copy;
1102 pv_copy->data.v_bv_inventions = pv->data.v_bv_inventions;
1103 return pv_copy;
1105 size = sizeof(struct tile_vision_data);
1106 pv_copy->data.v_tile_vision = fc_malloc(size);
1107 pv_copy->data.v_tile_vision->tile_known
1108 = pv->data.v_tile_vision->tile_known;
1110 pv_copy->data.v_tile_vision->tile_seen[v]
1111 = pv->data.v_tile_vision->tile_seen[v];
1113 pv_copy->must_free = TRUE;
1114 return pv_copy;
1115 }
1116
1117 log_error("%s(): Unhandled value type %d for property value %p.",
1118 __FUNCTION__, pv->valtype, pv);
1119 pv_copy->data = pv->data;
1120 return pv_copy;
1121}
1122
1123/************************************************************************/
1127static void propval_free(struct propval *pv)
1128{
1129 if (!pv) {
1130 return;
1131 }
1132
1134 free(pv);
1135}
1136
1137/************************************************************************/
1141static void propval_free_data(struct propval *pv)
1142{
1143 if (!pv || !pv->must_free) {
1144 return;
1145 }
1146
1147 switch (pv->valtype) {
1148 case VALTYPE_NONE:
1149 case VALTYPE_INT:
1150 case VALTYPE_BOOL:
1151 case VALTYPE_BV_SPECIAL:
1152 case VALTYPE_BV_ROADS:
1153 case VALTYPE_BV_BASES:
1154 case VALTYPE_NATION:
1155 case VALTYPE_GOV:
1156 return;
1157 case VALTYPE_PIXBUF:
1158 g_object_unref(pv->data.v_pixbuf);
1159 return;
1160 case VALTYPE_STRING:
1164 free(pv->data.v_pointer);
1165 return;
1167 nation_hash_destroy(pv->data.v_nation_hash);
1168 return;
1169 }
1170
1171 log_error("%s(): Unhandled request to free data %p (type %s).",
1172 __FUNCTION__, pv->data.v_pointer, valtype_get_name(pv->valtype));
1173}
1174
1175/************************************************************************/
1178static bool propval_equal(struct propval *pva,
1179 struct propval *pvb)
1180{
1181 if (!pva || !pvb) {
1182 return pva == pvb;
1183 }
1184
1185 if (pva->valtype != pvb->valtype) {
1186 return FALSE;
1187 }
1188
1189 switch (pva->valtype) {
1190 case VALTYPE_NONE:
1191 return TRUE;
1192 case VALTYPE_INT:
1193 return pva->data.v_int == pvb->data.v_int;
1194 case VALTYPE_BOOL:
1195 return pva->data.v_bool == pvb->data.v_bool;
1196 case VALTYPE_STRING:
1197 if (pva->data.v_const_string != NULL
1198 && pvb->data.v_const_string != NULL) {
1199 return !strcmp(pva->data.v_const_string,
1200 pvb->data.v_const_string);
1201 }
1202 return pva->data.v_const_string == pvb->data.v_const_string;
1203 case VALTYPE_PIXBUF:
1204 return pva->data.v_pixbuf == pvb->data.v_pixbuf;
1206 if (pva->data.v_pointer == pvb->data.v_pointer) {
1207 return TRUE;
1208 } else if (!pva->data.v_pointer || !pvb->data.v_pointer) {
1209 return FALSE;
1210 }
1211
1212 improvement_iterate(pimprove) {
1213 int id, vatb, vbtb;
1214 id = improvement_index(pimprove);
1215 vatb = pva->data.v_built[id].turn;
1216 vbtb = pvb->data.v_built[id].turn;
1217 if (vatb < 0 && vbtb < 0) {
1218 continue;
1219 }
1220 if (vatb != vbtb) {
1221 return FALSE;
1222 }
1224 return TRUE;
1226 return BV_ARE_EQUAL(pva->data.v_bv_inventions, pvb->data.v_bv_inventions);
1227 case VALTYPE_BV_SPECIAL:
1228 return BV_ARE_EQUAL(pva->data.v_bv_special, pvb->data.v_bv_special);
1229 case VALTYPE_BV_ROADS:
1230 return BV_ARE_EQUAL(pva->data.v_bv_roads, pvb->data.v_bv_roads);
1231 case VALTYPE_BV_BASES:
1232 return BV_ARE_EQUAL(pva->data.v_bv_bases, pvb->data.v_bv_bases);
1233 case VALTYPE_NATION:
1234 return pva->data.v_nation == pvb->data.v_nation;
1236 return nation_hashes_are_equal(pva->data.v_nation_hash,
1237 pvb->data.v_nation_hash);
1238 case VALTYPE_GOV:
1239 return pva->data.v_gov == pvb->data.v_gov;
1241 if (!BV_ARE_EQUAL(pva->data.v_tile_vision->tile_known,
1242 pvb->data.v_tile_vision->tile_known)) {
1243 return FALSE;
1244 }
1246 if (!BV_ARE_EQUAL(pva->data.v_tile_vision->tile_seen[v],
1247 pvb->data.v_tile_vision->tile_seen[v])) {
1248 return FALSE;
1249 }
1251 return TRUE;
1252 }
1253
1254 log_error("%s(): Unhandled value type %d for property values %p and %p.",
1255 __FUNCTION__, pva->valtype, pva, pvb);
1256 return pva->data.v_pointer == pvb->data.v_pointer;
1257}
1258
1259/************************************************************************/
1265static struct propstate *propstate_new(struct objprop *op,
1266 struct propval *pv)
1267{
1268 struct propstate *ps;
1269
1270 if (!op) {
1271 return NULL;
1272 }
1273
1274 ps = fc_calloc(1, sizeof(*ps));
1275 ps->property_id = objprop_get_id(op);
1276 ps->property_value = pv;
1277
1278 return ps;
1279}
1280
1281/************************************************************************/
1285{
1286 if (!ps) {
1287 return;
1288 }
1289
1290 propval_free(ps->property_value);
1291 ps->property_value = NULL;
1292}
1293
1294/************************************************************************/
1297static void propstate_destroy(struct propstate *ps)
1298{
1299 if (!ps) {
1300 return;
1301 }
1303 free(ps);
1304}
1305
1306/************************************************************************/
1313 struct propval *pv)
1314{
1315 if (!ps) {
1316 return;
1317 }
1319 ps->property_value = pv;
1320}
1321
1322/************************************************************************/
1328{
1329 if (!ps) {
1330 return NULL;
1331 }
1332 return ps->property_value;
1333}
1334
1335/************************************************************************/
1340 gpointer object)
1341{
1342 struct objbind *ob;
1343 int id;
1344
1345 if (object == NULL) {
1346 return NULL;
1347 }
1348
1349 id = objtype_get_id_from_object(objtype, object);
1350 if (id < 0) {
1351 return NULL;
1352 }
1353
1354 ob = fc_calloc(1, sizeof(*ob));
1355 ob->object_id = id;
1356 ob->objtype = objtype;
1357 ob->propstate_table = propstate_hash_new();
1358
1359 return ob;
1360}
1361
1362/************************************************************************/
1366{
1367 int id;
1368
1369 if (!ob) {
1370 return NULL;
1371 }
1372
1374
1375 return objtype_get_object_from_id(ob->objtype, id);
1376}
1377
1378/************************************************************************/
1382{
1383 if (NULL == ob) {
1384 return -1;
1385 }
1386 return ob->object_id;
1387}
1388
1389/************************************************************************/
1395{
1396 struct connection *my_conn = &client.conn;
1398 int id;
1399
1400 if (!ob) {
1401 return;
1402 }
1403
1406 return;
1407 }
1408
1410
1411 switch (objtype) {
1412 case OBJTYPE_STARTPOS:
1414 return;
1415 case OBJTYPE_UNIT:
1417 return;
1418 case OBJTYPE_CITY:
1420 return;
1421 case OBJTYPE_PLAYER:
1423 return;
1424 case OBJTYPE_TILE:
1425 case OBJTYPE_GAME:
1426 case NUM_OBJTYPES:
1427 break;
1428 }
1429
1430 log_error("%s(): Unhandled request to destroy object %p (ID %d) of type "
1431 "%d (%s).", __FUNCTION__, objbind_get_object(ob), id, objtype,
1433}
1434
1435/************************************************************************/
1443 struct objprop *op)
1444{
1447 struct propval *pv;
1448
1449 if (!ob || !op) {
1450 return NULL;
1451 }
1452
1455
1456 pv = fc_calloc(1, sizeof(*pv));
1457 pv->valtype = objprop_get_valtype(op);
1458
1459 switch (objtype) {
1460 case OBJTYPE_TILE:
1461 {
1462 const struct tile *ptile = objbind_get_object(ob);
1463 int tile_x, tile_y, nat_x, nat_y;
1464
1465 if (NULL == ptile) {
1466 goto FAILED;
1467 }
1468
1471
1472 switch (propid) {
1473 case OPID_TILE_IMAGE:
1474 pv->data.v_pixbuf = create_tile_pixbuf(ptile);
1475 pv->must_free = TRUE;
1476 break;
1477#ifdef FREECIV_DEBUG
1478 case OPID_TILE_ADDRESS:
1479 pv->data.v_string = g_strdup_printf("%p", ptile);
1480 pv->must_free = TRUE;
1481 break;
1482#endif /* FREECIV_DEBUG */
1483 case OPID_TILE_TERRAIN:
1484 {
1485 const struct terrain *pterrain = tile_terrain(ptile);
1486
1487 if (NULL != pterrain) {
1488 pv->data.v_const_string = terrain_name_translation(pterrain);
1489 } else {
1490 pv->data.v_const_string = "";
1491 }
1492 }
1493 break;
1494 case OPID_TILE_RESOURCE:
1495 {
1496 const struct extra_type *presource = tile_resource(ptile);
1497
1498 if (NULL != presource) {
1499 pv->data.v_const_string = extra_name_translation(presource);
1500 } else {
1501 pv->data.v_const_string = "";
1502 }
1503 }
1504 break;
1505 case OPID_TILE_XY:
1506 pv->data.v_string = g_strdup_printf("(%d, %d)", tile_x, tile_y);
1507 pv->must_free = TRUE;
1508 break;
1509 case OPID_TILE_INDEX:
1510 pv->data.v_int = tile_index(ptile);
1511 break;
1512 case OPID_TILE_X:
1513 pv->data.v_int = tile_x;
1514 break;
1515 case OPID_TILE_Y:
1516 pv->data.v_int = tile_y;
1517 break;
1518 case OPID_TILE_NAT_X:
1519 pv->data.v_int = nat_x;
1520 break;
1521 case OPID_TILE_NAT_Y:
1522 pv->data.v_int = nat_y;
1523 break;
1525 pv->data.v_int = ptile->continent;
1526 break;
1527 case OPID_TILE_SPECIALS:
1528 BV_CLR_ALL(pv->data.v_bv_special);
1530 if (tile_has_extra(ptile, pextra)) {
1531 BV_SET(pv->data.v_bv_special, pextra->data.special_idx);
1532 }
1534 break;
1535 case OPID_TILE_ROADS:
1536 BV_CLR_ALL(pv->data.v_bv_roads);
1538 if (tile_has_extra(ptile, pextra)) {
1539 BV_SET(pv->data.v_bv_roads, road_number(extra_road_get(pextra)));
1540 }
1542 break;
1543 case OPID_TILE_BASES:
1544 BV_CLR_ALL(pv->data.v_bv_bases);
1546 if (tile_has_extra(ptile, pextra)) {
1547 BV_SET(pv->data.v_bv_bases, base_number(extra_base_get(pextra)));
1548 }
1550 break;
1551 case OPID_TILE_VISION:
1552 pv->data.v_tile_vision = fc_malloc(sizeof(struct tile_vision_data));
1553
1554 /* The server saves the known tiles and the player vision in special
1555 * bitvectors with the number of tiles as index. Here we want the
1556 * information for one tile. Thus, the data is transformed to
1557 * bitvectors with the number of player slots as index. */
1558 BV_CLR_ALL(pv->data.v_tile_vision->tile_known);
1559 players_iterate(pplayer) {
1560 if (dbv_isset(&pplayer->tile_known, tile_index(ptile))) {
1561 BV_SET(pv->data.v_tile_vision->tile_known,
1562 player_index(pplayer));
1563 }
1565
1567 BV_CLR_ALL(pv->data.v_tile_vision->tile_seen[v]);
1568 players_iterate(pplayer) {
1569 if (fc_funcs->player_tile_vision_get(ptile, pplayer, v)) {
1570 BV_SET(pv->data.v_tile_vision->tile_seen[v],
1571 player_index(pplayer));
1572 }
1575 pv->must_free = TRUE;
1576 break;
1577 case OPID_TILE_LABEL:
1578 if (ptile->label != NULL) {
1579 pv->data.v_const_string = ptile->label;
1580 } else {
1581 pv->data.v_const_string = "";
1582 }
1583 break;
1584 default:
1585 log_error("%s(): Unhandled request for value of property %d "
1586 "(%s) from object of type \"%s\".", __FUNCTION__,
1588 goto FAILED;
1589 }
1590 }
1591 return pv;
1592
1593 case OBJTYPE_STARTPOS:
1594 {
1595 const struct startpos *psp = objbind_get_object(ob);
1596 const struct tile *ptile;
1597
1598 if (NULL == psp) {
1599 goto FAILED;
1600 }
1601
1602 switch (propid) {
1604 ptile = startpos_tile(psp);
1605 pv->data.v_pixbuf = create_tile_pixbuf(ptile);
1606 pv->must_free = TRUE;
1607 break;
1608 case OPID_STARTPOS_XY:
1609 ptile = startpos_tile(psp);
1610 pv->data.v_string = g_strdup_printf("(%d, %d)", TILE_XY(ptile));
1611 pv->must_free = TRUE;
1612 break;
1614 pv->data.v_bool = startpos_is_excluding(psp);
1615 break;
1617 pv->data.v_nation_hash = nation_hash_copy(startpos_raw_nations(psp));
1618 pv->must_free = TRUE;
1619 break;
1620 default:
1621 log_error("%s(): Unhandled request for value of property %d "
1622 "(%s) from object of type \"%s\".", __FUNCTION__,
1624 goto FAILED;
1625 }
1626 }
1627 return pv;
1628
1629 case OBJTYPE_UNIT:
1630 {
1631 struct unit *punit = objbind_get_object(ob);
1632
1633 if (NULL == punit) {
1634 goto FAILED;
1635 }
1636
1637 switch (propid) {
1638 case OPID_UNIT_IMAGE:
1639 pv->data.v_pixbuf = create_unit_pixbuf(punit);
1640 pv->must_free = TRUE;
1641 break;
1642#ifdef FREECIV_DEBUG
1643 case OPID_UNIT_ADDRESS:
1644 pv->data.v_string = g_strdup_printf("%p", punit);
1645 pv->must_free = TRUE;
1646 break;
1647#endif /* FREECIV_DEBUG */
1648 case OPID_UNIT_XY:
1649 {
1650 const struct tile *ptile = unit_tile(punit);
1651
1652 pv->data.v_string = g_strdup_printf("(%d, %d)", TILE_XY(ptile));
1653 pv->must_free = TRUE;
1654 }
1655 break;
1656 case OPID_UNIT_ID:
1657 pv->data.v_int = punit->id;
1658 break;
1659 case OPID_UNIT_TYPE:
1660 {
1661 const struct unit_type *putype = unit_type_get(punit);
1662
1663 pv->data.v_const_string = utype_name_translation(putype);
1664 }
1665 break;
1667 pv->data.v_int = punit->moves_left;
1668 break;
1669 case OPID_UNIT_FUEL:
1670 pv->data.v_int = punit->fuel;
1671 break;
1672 case OPID_UNIT_MOVED:
1673 pv->data.v_bool = punit->moved;
1674 break;
1676 pv->data.v_bool = punit->done_moving;
1677 break;
1678 case OPID_UNIT_HP:
1679 pv->data.v_int = punit->hp;
1680 break;
1681 case OPID_UNIT_VETERAN:
1682 pv->data.v_int = punit->veteran;
1683 break;
1684 case OPID_UNIT_STAY:
1685 pv->data.v_bool = punit->stay;
1686 break;
1687 default:
1688 log_error("%s(): Unhandled request for value of property %d "
1689 "(%s) from object of type \"%s\".", __FUNCTION__,
1691 goto FAILED;
1692 }
1693 }
1694 return pv;
1695
1696 case OBJTYPE_CITY:
1697 {
1698 const struct city *pcity = objbind_get_object(ob);
1699
1700 if (NULL == pcity) {
1701 goto FAILED;
1702 }
1703
1704 switch (propid) {
1705 case OPID_CITY_IMAGE:
1706 pv->data.v_pixbuf = create_city_pixbuf(pcity);
1707 pv->must_free = TRUE;
1708 break;
1709#ifdef FREECIV_DEBUG
1710 case OPID_CITY_ADDRESS:
1711 pv->data.v_string = g_strdup_printf("%p", pcity);
1712 pv->must_free = TRUE;
1713 break;
1714#endif /* FREECIV_DEBUG */
1715 case OPID_CITY_XY:
1716 {
1717 const struct tile *ptile = city_tile(pcity);
1718
1719 pv->data.v_string = g_strdup_printf("(%d, %d)", TILE_XY(ptile));
1720 pv->must_free = TRUE;
1721 }
1722 break;
1723 case OPID_CITY_ID:
1724 pv->data.v_int = pcity->id;
1725 break;
1726 case OPID_CITY_NAME:
1727 pv->data.v_const_string = pcity->name;
1728 break;
1729 case OPID_CITY_SIZE:
1730 pv->data.v_int = city_size_get(pcity);
1731 break;
1732 case OPID_CITY_HISTORY:
1733 pv->data.v_int = pcity->history;
1734 break;
1736 pv->data.v_built = fc_malloc(sizeof(pcity->built));
1737 memcpy(pv->data.v_built, pcity->built, sizeof(pcity->built));
1738 pv->must_free = TRUE;
1739 break;
1741 pv->data.v_int = pcity->food_stock;
1742 break;
1744 pv->data.v_int = pcity->shield_stock;
1745 break;
1746 default:
1747 log_error("%s(): Unhandled request for value of property %d "
1748 "(%s) from object of type \"%s\".", __FUNCTION__,
1750 goto FAILED;
1751 }
1752 }
1753 return pv;
1754
1755 case OBJTYPE_PLAYER:
1756 {
1757 const struct player *pplayer = objbind_get_object(ob);
1758 const struct research *presearch;
1759
1760 if (NULL == pplayer) {
1761 goto FAILED;
1762 }
1763
1764 switch (propid) {
1765 case OPID_PLAYER_NAME:
1766 pv->data.v_const_string = pplayer->name;
1767 break;
1768 case OPID_PLAYER_NATION:
1769 pv->data.v_nation = nation_of_player(pplayer);
1770 break;
1771 case OPID_PLAYER_GOV:
1772 pv->data.v_gov = pplayer->government;
1773 break;
1774 case OPID_PLAYER_AGE:
1775 pv->data.v_int = pplayer->turns_alive;
1776 break;
1777#ifdef FREECIV_DEBUG
1779 pv->data.v_string = g_strdup_printf("%p", pplayer);
1780 pv->must_free = TRUE;
1781 break;
1782#endif /* FREECIV_DEBUG */
1784 presearch = research_get(pplayer);
1785 BV_CLR_ALL(pv->data.v_bv_inventions);
1788 BV_SET(pv->data.v_bv_inventions, tech);
1789 }
1791 break;
1793 pv->data.v_bool = player_has_flag(pplayer, PLRF_SCENARIO_RESERVED);
1794 break;
1796 pv->data.v_int = pplayer->autoselect_weight;
1797 break;
1799 presearch = research_get(pplayer);
1800 pv->data.v_int = presearch->bulbs_researched;
1801 break;
1802 case OPID_PLAYER_GOLD:
1803 pv->data.v_int = pplayer->economic.gold;
1804 break;
1806 pv->data.v_int = pplayer->economic.infra_points;
1807 break;
1808 default:
1809 log_error("%s(): Unhandled request for value of property %d "
1810 "(%s) from object of type \"%s\".", __FUNCTION__,
1812 goto FAILED;
1813 }
1814 }
1815 return pv;
1816
1817 case OBJTYPE_GAME:
1818 {
1819 const struct civ_game *pgame = objbind_get_object(ob);
1820
1821 if (NULL == pgame) {
1822 goto FAILED;
1823 }
1824
1825 switch (propid) {
1826 case OPID_GAME_SCENARIO:
1827 pv->data.v_bool = pgame->scenario.is_scenario;
1828 break;
1830 pv->data.v_const_string = pgame->scenario.name;
1831 break;
1833 pv->data.v_const_string = pgame->scenario.authors;
1834 break;
1836 pv->data.v_const_string = pgame->scenario_desc.description;
1837 break;
1839 pv->data.v_bool = pgame->scenario.save_random;
1840 break;
1842 pv->data.v_bool = pgame->scenario.players;
1843 break;
1845 pv->data.v_bool = pgame->scenario.startpos_nations;
1846 break;
1848 pv->data.v_bool = pgame->scenario.prevent_new_cities;
1849 break;
1851 pv->data.v_bool = pgame->scenario.lake_flooding;
1852 break;
1854 pv->data.v_bool = pgame->scenario.ruleset_locked;
1855 break;
1856 default:
1857 log_error("%s(): Unhandled request for value of property %d "
1858 "(%s) from object of type \"%s\".", __FUNCTION__,
1860 goto FAILED;
1861 }
1862 }
1863 return pv;
1864
1865 case NUM_OBJTYPES:
1866 break;
1867 }
1868
1869 log_error("%s(): Unhandled request for object type \"%s\" (nb %d).",
1871
1872FAILED:
1873 if (NULL != pv) {
1874 free(pv);
1875 }
1876 return NULL;
1877}
1878
1879/************************************************************************/
1884 struct objprop *op,
1885 double *pmin,
1886 double *pmax,
1887 double *pstep,
1888 double *pbig_step)
1889{
1892 double dummy;
1893
1894 /* Fill the values with something. */
1895 if (NULL != pmin) {
1896 *pmin = 0;
1897 } else {
1898 pmin = &dummy;
1899 }
1900 if (NULL != pmax) {
1901 *pmax = 1;
1902 } else {
1903 pmax = &dummy;
1904 }
1905 if (NULL != pstep) {
1906 *pstep = 1;
1907 } else {
1908 pstep = &dummy;
1909 }
1910 if (NULL != pbig_step) {
1911 *pbig_step = 1;
1912 } else {
1913 pbig_step = &dummy;
1914 }
1915
1916 if (!ob || !op) {
1917 return FALSE;
1918 }
1919
1922
1923 switch (objtype) {
1924 case OBJTYPE_TILE:
1925 case OBJTYPE_STARTPOS:
1926 log_error("%s(): Unhandled request for value range of property %d (%s) "
1927 "from object of type \"%s\".", __FUNCTION__,
1929 return FALSE;
1930
1931 case OBJTYPE_UNIT:
1932 {
1933 const struct unit *punit = objbind_get_object(ob);
1934 const struct unit_type *putype;
1935
1936 if (NULL == punit) {
1937 return FALSE;
1938 }
1939
1941
1942 switch (propid) {
1944 *pmin = 0;
1946 *pstep = 1;
1947 *pbig_step = 5;
1948 return TRUE;
1949 case OPID_UNIT_FUEL:
1950 *pmin = 0;
1952 *pstep = 1;
1953 *pbig_step = 5;
1954 return TRUE;
1955 case OPID_UNIT_HP:
1956 *pmin = 1;
1957 *pmax = putype->hp;
1958 *pstep = 1;
1959 *pbig_step = 10;
1960 return TRUE;
1961 case OPID_UNIT_VETERAN:
1962 *pmin = 0;
1964 *pstep = 1;
1965 *pbig_step = 3;
1966 return TRUE;
1967 default:
1968 break;
1969 }
1970 }
1971 log_error("%s(): Unhandled request for value range of property %d (%s) "
1972 "from object of type \"%s\".", __FUNCTION__,
1974 return FALSE;
1975
1976 case OBJTYPE_CITY:
1977 {
1978 const struct city *pcity = objbind_get_object(ob);
1979
1980 if (NULL == pcity) {
1981 return FALSE;
1982 }
1983
1984 switch (propid) {
1985 case OPID_CITY_SIZE:
1986 *pmin = 1;
1988 *pstep = 1;
1989 *pbig_step = 5;
1990 return TRUE;
1991 case OPID_CITY_HISTORY:
1992 *pmin = 0;
1993 *pmax = USHRT_MAX;
1994 *pstep = 1;
1995 *pbig_step = 10;
1996 return TRUE;
1998 *pmin = 0;
2000 *pstep = 1;
2001 *pbig_step = 5;
2002 return TRUE;
2004 *pmin = 0;
2005 *pmax = USHRT_MAX; /* Limited to uint16 by city info packet. */
2006 *pstep = 1;
2007 *pbig_step = 10;
2008 return TRUE;
2009 default:
2010 break;
2011 }
2012 }
2013 log_error("%s(): Unhandled request for value range of property %d (%s) "
2014 "from object of type \"%s\".", __FUNCTION__,
2016 return FALSE;
2017
2018 case OBJTYPE_PLAYER:
2019 switch (propid) {
2021 *pmin = 0;
2022 *pmax = 1000000; /* Arbitrary. */
2023 *pstep = 1;
2024 *pbig_step = 100;
2025 return TRUE;
2026 case OPID_PLAYER_GOLD:
2027 *pmin = 0;
2028 *pmax = 1000000; /* Arbitrary. */
2029 *pstep = 1;
2030 *pbig_step = 100;
2031 return TRUE;
2033 *pmin = 0;
2034 *pmax = 1000000; /* Arbitrary. */
2035 *pstep = 1;
2036 *pbig_step = 100;
2037 return TRUE;
2039 *pmin = -1;
2040 *pmax = 10000; /* Keep it under SINT16 */
2041 *pstep = 1;
2042 *pbig_step = 10;
2043 return TRUE;
2044 default:
2045 break;
2046 }
2047 log_error("%s(): Unhandled request for value range of property %d (%s) "
2048 "from object of type \"%s\".", __FUNCTION__,
2050 return FALSE;
2051
2052 case OBJTYPE_GAME:
2053 log_error("%s(): Unhandled request for value range of property %d (%s) "
2054 "from object of type \"%s\".", __FUNCTION__,
2056 return FALSE;
2057
2058 case NUM_OBJTYPES:
2059 break;
2060 }
2061
2062 log_error("%s(): Unhandled request for object type \"%s\" (nb %d).",
2064 return FALSE;
2065}
2066
2067/************************************************************************/
2071 struct objprop *op)
2072{
2073 if (!ob || !op || !ob->propstate_table) {
2074 return;
2075 }
2076
2077 propstate_hash_remove(ob->propstate_table, objprop_get_id(op));
2078}
2079
2080/************************************************************************/
2085 struct objprop *op)
2086{
2087 if (!ob || !op) {
2088 return FALSE;
2089 }
2090
2091 if (objprop_is_readonly(op)) {
2092 return FALSE;
2093 }
2094
2095 return propstate_hash_lookup(ob->propstate_table,
2097}
2098
2099/************************************************************************/
2104{
2105 if (!ob) {
2106 return FALSE;
2107 }
2108
2109 return (0 < propstate_hash_size(ob->propstate_table));
2110}
2111
2112/************************************************************************/
2116{
2117 if (!ob) {
2118 return;
2119 }
2120 propstate_hash_clear(ob->propstate_table);
2121}
2122
2123/************************************************************************/
2130 struct objprop *op,
2131 struct propval *pv)
2132{
2133 struct propstate *ps;
2134 bool equal;
2135 struct propval *pv_old, *pv_copy;
2137
2138 if (!ob || !op) {
2139 return FALSE;
2140 }
2141
2143
2145 if (!pv_old) {
2146 return FALSE;
2147 }
2148
2151
2152 if (equal) {
2154 return FALSE;
2155 }
2156
2158
2159 if (propstate_hash_lookup(ob->propstate_table, propid, &ps)) {
2161 } else {
2163 propstate_hash_insert(ob->propstate_table, propid, ps);
2164 }
2165
2166 return TRUE;
2167}
2168
2169/************************************************************************/
2176 struct objprop *op)
2177{
2178 struct propstate *ps;
2179
2180 if (!ob || !op) {
2181 return NULL;
2182 }
2183
2184 if (propstate_hash_lookup(ob->propstate_table, objprop_get_id(op), &ps)) {
2185 return propstate_get_value(ps);
2186 } else {
2187 return NULL;
2188 }
2189}
2190
2191/************************************************************************/
2194static void objbind_destroy(struct objbind *ob)
2195{
2196 if (!ob) {
2197 return;
2198 }
2199 if (ob->propstate_table) {
2200 propstate_hash_destroy(ob->propstate_table);
2201 ob->propstate_table = NULL;
2202 }
2203 if (ob->rowref) {
2205 ob->rowref = NULL;
2206 }
2207 free(ob);
2208}
2209
2210/************************************************************************/
2214{
2215 if (!ob) {
2216 return NUM_OBJTYPES;
2217 }
2218 return ob->objtype;
2219}
2220
2221/************************************************************************/
2225 struct property_page *pp)
2226{
2227 if (!ob) {
2228 return;
2229 }
2230 ob->parent_property_page = pp;
2231}
2232
2233/************************************************************************/
2239 union packetdata pd)
2240{
2242
2243 if (!ob || !pd.pointers.v_pointer1) {
2244 return;
2245 }
2246
2248
2249 switch (objtype) {
2250 case OBJTYPE_TILE:
2251 {
2252 struct packet_edit_tile *packet = pd.tile;
2253 const struct tile *ptile = objbind_get_object(ob);
2254
2255 if (NULL == ptile) {
2256 return;
2257 }
2258
2259 packet->tile = tile_index(ptile);
2260 packet->extras = *tile_extras(ptile);
2261 /* TODO: Set more packet fields. */
2262 }
2263 return;
2264
2265 case OBJTYPE_STARTPOS:
2266 {
2267 struct packet_edit_startpos_full *packet = pd.startpos;
2268 const struct startpos *psp = objbind_get_object(ob);
2269
2270 if (NULL != psp) {
2271 startpos_pack(psp, packet);
2272 }
2273 }
2274 return;
2275
2276 case OBJTYPE_UNIT:
2277 {
2278 struct packet_edit_unit *packet = pd.unit;
2279 const struct unit *punit = objbind_get_object(ob);
2280
2281 if (NULL == punit) {
2282 return;
2283 }
2284
2285 packet->id = punit->id;
2286 packet->moves_left = punit->moves_left;
2287 packet->fuel = punit->fuel;
2288 packet->moved = punit->moved;
2289 packet->done_moving = punit->done_moving;
2290 packet->hp = punit->hp;
2291 packet->veteran = punit->veteran;
2292 packet->stay = punit->stay;
2293 /* TODO: Set more packet fields. */
2294 }
2295 return;
2296
2297 case OBJTYPE_CITY:
2298 {
2299 struct packet_edit_city *packet = pd.city;
2300 const struct city *pcity = objbind_get_object(ob);
2301 int i;
2302
2303 if (NULL == pcity) {
2304 return;
2305 }
2306
2307 packet->id = pcity->id;
2308 sz_strlcpy(packet->name, pcity->name);
2309 packet->size = city_size_get(pcity);
2310 packet->history = pcity->history;
2311 for (i = 0; i < B_LAST; i++) {
2312 packet->built[i] = pcity->built[i].turn;
2313 }
2314 packet->food_stock = pcity->food_stock;
2315 packet->shield_stock = pcity->shield_stock;
2316 /* TODO: Set more packet fields. */
2317 }
2318 return;
2319
2320 case OBJTYPE_PLAYER:
2321 {
2322 struct packet_edit_player *packet = pd.player;
2323 const struct player *pplayer = objbind_get_object(ob);
2324 const struct nation_type *pnation;
2325 const struct research *presearch;
2326
2327 if (NULL == pplayer) {
2328 return;
2329 }
2330
2331 packet->id = player_number(pplayer);
2332 sz_strlcpy(packet->name, pplayer->name);
2333 pnation = nation_of_player(pplayer);
2334 packet->nation = nation_index(pnation);
2335 presearch = research_get(pplayer);
2337 packet->inventions[tech]
2340 packet->autoselect_weight = pplayer->autoselect_weight;
2341 packet->gold = pplayer->economic.gold;
2342 packet->infrapoints = pplayer->economic.infra_points;
2343 packet->government = government_index(pplayer->government);
2345 /* TODO: Set more packet fields. */
2346 }
2347 return;
2348
2349 case OBJTYPE_GAME:
2350 {
2351 struct packet_edit_game *packet = pd.game.game;
2352 const struct civ_game *pgame = objbind_get_object(ob);
2353
2354 if (NULL == pgame) {
2355 return;
2356 }
2357
2358 packet->scenario = pgame->scenario.is_scenario;
2359 sz_strlcpy(packet->scenario_name, pgame->scenario.name);
2360 sz_strlcpy(packet->scenario_authors, pgame->scenario.authors);
2361 sz_strlcpy(pd.game.desc->scenario_desc, pgame->scenario_desc.description);
2362 packet->scenario_random = pgame->scenario.save_random;
2363 packet->scenario_players = pgame->scenario.players;
2364 packet->startpos_nations = pgame->scenario.startpos_nations;
2365 packet->prevent_new_cities = pgame->scenario.prevent_new_cities;
2366 packet->lake_flooding = pgame->scenario.lake_flooding;
2367 }
2368 return;
2369
2370 case NUM_OBJTYPES:
2371 break;
2372 }
2373
2374 log_error("%s(): Unhandled object type %s (nb %d).", __FUNCTION__,
2376}
2377
2378/************************************************************************/
2382 struct objprop *op,
2383 union packetdata pd)
2384{
2385 struct propval *pv;
2388
2389 if (!op || !ob || !pd.pointers.v_pointer1) {
2390 return;
2391 }
2392
2393 if (NULL == objbind_get_object(ob)) {
2394 return;
2395 }
2396
2398 return;
2399 }
2400
2402 if (!pv) {
2403 return;
2404 }
2405
2408
2409 switch (objtype) {
2410 case OBJTYPE_TILE:
2411 {
2412 struct packet_edit_tile *packet = pd.tile;
2413
2414 switch (propid) {
2415 case OPID_TILE_SPECIALS:
2417 if (BV_ISSET(pv->data.v_bv_special, pextra->data.special_idx)) {
2418 BV_SET(packet->extras, pextra->data.special_idx);
2419 } else {
2420 BV_CLR(packet->extras, pextra->data.special_idx);
2421 }
2423 return;
2424 case OPID_TILE_ROADS:
2426 int ridx = road_number(extra_road_get(pextra));
2427
2428 if (BV_ISSET(pv->data.v_bv_roads, ridx)) {
2429 BV_SET(packet->extras, extra_index(pextra));
2430 } else {
2431 BV_CLR(packet->extras, extra_index(pextra));
2432 }
2434 return;
2435 case OPID_TILE_BASES:
2437 int bidx = base_number(extra_base_get(pextra));
2438
2439 if (BV_ISSET(pv->data.v_bv_bases, bidx)) {
2440 BV_SET(packet->extras, extra_index(pextra));
2441 } else {
2442 BV_CLR(packet->extras, extra_index(pextra));
2443 }
2445 return;
2446 case OPID_TILE_LABEL:
2447 sz_strlcpy(packet->label, pv->data.v_string);
2448 return;
2449 default:
2450 break;
2451 }
2452 }
2453 log_error("%s(): Unhandled request to pack value of property "
2454 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2456 return;
2457
2458 case OBJTYPE_STARTPOS:
2459 {
2460 struct packet_edit_startpos_full *packet = pd.startpos;
2461
2462 switch (propid) {
2464 packet->exclude = pv->data.v_bool;
2465 return;
2467 BV_CLR_ALL(packet->nations);
2468 nation_hash_iterate(pv->data.v_nation_hash, pnation) {
2469 BV_SET(packet->nations, nation_number(pnation));
2471 return;
2472 default:
2473 break;
2474 }
2475 }
2476 log_error("%s(): Unhandled request to pack value of property "
2477 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2479 return;
2480
2481 case OBJTYPE_UNIT:
2482 {
2483 struct packet_edit_unit *packet = pd.unit;
2484
2485 switch (propid) {
2487 packet->moves_left = pv->data.v_int;
2488 return;
2489 case OPID_UNIT_FUEL:
2490 packet->fuel = pv->data.v_int;
2491 return;
2492 case OPID_UNIT_MOVED:
2493 packet->moved = pv->data.v_bool;
2494 return;
2496 packet->done_moving = pv->data.v_bool;
2497 return;
2498 case OPID_UNIT_HP:
2499 packet->hp = pv->data.v_int;
2500 return;
2501 case OPID_UNIT_VETERAN:
2502 packet->veteran = pv->data.v_int;
2503 return;
2504 case OPID_UNIT_STAY:
2505 packet->stay = pv->data.v_bool;
2506 return;
2507 default:
2508 break;
2509 }
2510 }
2511 log_error("%s(): Unhandled request to pack value of property "
2512 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2514 return;
2515
2516 case OBJTYPE_CITY:
2517 {
2518 struct packet_edit_city *packet = pd.city;
2519
2520 switch (propid) {
2521 case OPID_CITY_NAME:
2522 sz_strlcpy(packet->name, pv->data.v_string);
2523 return;
2524 case OPID_CITY_SIZE:
2525 packet->size = pv->data.v_int;
2526 return;
2527 case OPID_CITY_HISTORY:
2528 packet->history = pv->data.v_int;
2529 return;
2531 packet->food_stock = pv->data.v_int;
2532 return;
2534 packet->shield_stock = pv->data.v_int;
2535 return;
2537 {
2538 int i;
2539
2540 for (i = 0; i < B_LAST; i++) {
2541 packet->built[i] = pv->data.v_built[i].turn;
2542 }
2543 }
2544 return;
2545 default:
2546 break;
2547 }
2548 }
2549 log_error("%s(): Unhandled request to pack value of property "
2550 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2552 return;
2553
2554 case OBJTYPE_PLAYER:
2555 {
2556 struct packet_edit_player *packet = pd.player;
2557
2558 switch (propid) {
2559 case OPID_PLAYER_NAME:
2560 sz_strlcpy(packet->name, pv->data.v_string);
2561 return;
2562 case OPID_PLAYER_NATION:
2563 packet->nation = nation_index(pv->data.v_nation);
2564 return;
2565 case OPID_PLAYER_GOV:
2566 packet->government = government_index(pv->data.v_gov);
2567 return;
2570 packet->inventions[tech] = BV_ISSET(pv->data.v_bv_inventions, tech);
2572 return;
2574 packet->scenario_reserved = pv->data.v_bool;
2575 return;
2577 packet->autoselect_weight = pv->data.v_int;
2578 return;
2580 packet->bulbs_researched = pv->data.v_int;
2581 return;
2582 case OPID_PLAYER_GOLD:
2583 packet->gold = pv->data.v_int;
2584 return;
2586 packet->infrapoints = pv->data.v_int;
2587 return;
2588 default:
2589 break;
2590 }
2591 }
2592 log_error("%s(): Unhandled request to pack value of property "
2593 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2595 return;
2596
2597 case OBJTYPE_GAME:
2598 {
2599 struct packet_edit_game *packet = pd.game.game;
2600
2601 switch (propid) {
2602 case OPID_GAME_SCENARIO:
2603 packet->scenario = pv->data.v_bool;
2604 return;
2606 sz_strlcpy(packet->scenario_name, pv->data.v_const_string);
2607 return;
2609 sz_strlcpy(packet->scenario_authors, pv->data.v_const_string);
2610 return;
2612 sz_strlcpy(pd.game.desc->scenario_desc, pv->data.v_const_string);
2613 return;
2615 packet->scenario_random = pv->data.v_bool;
2616 return;
2618 packet->scenario_players = pv->data.v_bool;
2619 return;
2621 packet->startpos_nations = pv->data.v_bool;
2622 return;
2624 packet->prevent_new_cities = pv->data.v_bool;
2625 return;
2627 packet->lake_flooding = pv->data.v_bool;
2628 return;
2630 packet->ruleset_locked = pv->data.v_bool;
2631 return;
2632 default:
2633 break;
2634 }
2635 }
2636 log_error("%s(): Unhandled request to pack value of property "
2637 "%d (%s) from object of type \"%s\".", __FUNCTION__,
2639 return;
2640
2641 case NUM_OBJTYPES:
2642 break;
2643 }
2644
2645 log_error("%s(): Unhandled request for object type \"%s\" (nb %d).",
2647
2648}
2649
2650/************************************************************************/
2653static void objbind_set_rowref(struct objbind *ob,
2655{
2656 if (!ob) {
2657 return;
2658 }
2659 ob->rowref = rr;
2660}
2661
2662/************************************************************************/
2666{
2667 if (!ob) {
2668 return NULL;
2669 }
2670 return ob->rowref;
2671}
2672
2673/************************************************************************/
2676static int objprop_get_id(const struct objprop *op)
2677{
2678 if (!op) {
2679 return -1;
2680 }
2681 return op->id;
2682}
2683
2684/************************************************************************/
2691static GType objprop_get_gtype(const struct objprop *op)
2692{
2694
2695 switch (op->valtype) {
2696 case VALTYPE_NONE:
2698 return G_TYPE_NONE;
2699 case VALTYPE_INT:
2700 return G_TYPE_INT;
2701 case VALTYPE_BOOL:
2702 /* We want to show it as translated string, not as untranslated G_TYPE_BOOLEAN */
2703 return G_TYPE_STRING;
2704 case VALTYPE_STRING:
2707 case VALTYPE_BV_SPECIAL:
2708 case VALTYPE_BV_ROADS:
2709 case VALTYPE_BV_BASES:
2711 return G_TYPE_STRING;
2712 case VALTYPE_PIXBUF:
2713 case VALTYPE_NATION:
2714 case VALTYPE_GOV:
2715 return GDK_TYPE_PIXBUF;
2716 }
2717 log_error("%s(): Unhandled value type %d.", __FUNCTION__, op->valtype);
2718 return G_TYPE_NONE;
2719}
2720
2721/************************************************************************/
2724static enum value_types objprop_get_valtype(const struct objprop *op)
2725{
2726 if (!op) {
2727 return VALTYPE_NONE;
2728 }
2729 return op->valtype;
2730}
2731
2732/************************************************************************/
2735static bool objprop_show_in_listview(const struct objprop *op)
2736{
2737 if (!op) {
2738 return FALSE;
2739 }
2740 return op->flags & OPF_IN_LISTVIEW;
2741}
2742
2743/************************************************************************/
2746static bool objprop_has_widget(const struct objprop *op)
2747{
2748 if (!op) {
2749 return FALSE;
2750 }
2751 return op->flags & OPF_HAS_WIDGET;
2752}
2753
2754/************************************************************************/
2760static const char *objprop_get_attribute_type_string(const struct objprop *op)
2761{
2762 GType gtype;
2763
2764 if (!op) {
2765 return NULL;
2766 }
2767
2769 if (gtype == G_TYPE_INT || gtype == G_TYPE_STRING
2770 || gtype == G_TYPE_BOOLEAN) {
2771 return "text";
2772 } else if (gtype == GDK_TYPE_PIXBUF) {
2773 return "pixbuf";
2774 }
2775
2776 return NULL;
2777}
2778
2779/************************************************************************/
2785static void objprop_set_column_id(struct objprop *op, int col_id)
2786{
2787 if (!op) {
2788 return;
2789 }
2790 op->column_id = col_id;
2791}
2792
2793/************************************************************************/
2798static int objprop_get_column_id(const struct objprop *op)
2799{
2800 if (!op) {
2801 return -1;
2802 }
2803 return op->column_id;
2804}
2805
2806/************************************************************************/
2811{
2812 if (!op) {
2813 return;
2814 }
2815 op->view_column = col;
2816}
2817
2818/************************************************************************/
2823{
2824 if (!op) {
2825 return NULL;
2826 }
2827 return op->view_column;
2828}
2829
2830/************************************************************************/
2833static const char *objprop_get_name(const struct objprop *op)
2834{
2835 if (!op) {
2836 return NULL;
2837 }
2838 return op->name;
2839}
2840
2841/************************************************************************/
2844static const char *objprop_get_tooltip(const struct objprop *op)
2845{
2846 if (!op) {
2847 return NULL;
2848 }
2849 return op->tooltip;
2850}
2851
2852/************************************************************************/
2858{
2860 GType gtype;
2861
2863
2864 if (gtype == G_TYPE_INT || gtype == G_TYPE_STRING
2865 || gtype == G_TYPE_BOOLEAN) {
2867 } else if (gtype == GDK_TYPE_PIXBUF) {
2869 }
2870
2871 return cell;
2872}
2873
2874/************************************************************************/
2878static bool objprop_is_sortable(const struct objprop *op)
2879{
2880 GType gtype;
2881 if (!op) {
2882 return FALSE;
2883 }
2885 return gtype == G_TYPE_INT || gtype == G_TYPE_STRING;
2886}
2887
2888/************************************************************************/
2892static bool objprop_is_readonly(const struct objprop *op)
2893{
2894 if (!op) {
2895 return TRUE;
2896 }
2897 return !(op->flags & OPF_EDITABLE);
2898}
2899
2900/************************************************************************/
2904{
2905 struct objprop *op;
2906 struct property_page *pp;
2907 struct propval value = {{0,}, VALTYPE_STRING, FALSE};
2908
2909 op = userdata;
2912
2913 property_page_change_value(pp, op, &value);
2914}
2915
2916/************************************************************************/
2921{
2922 struct objprop *op;
2923 struct property_page *pp;
2924 struct propval value = {{0,}, VALTYPE_INT, FALSE};
2925
2926 op = userdata;
2929
2930 property_page_change_value(pp, op, &value);
2931}
2932
2933/************************************************************************/
2938{
2939 struct objprop *op;
2940 struct property_page *pp;
2941 struct propval value = {{0,}, VALTYPE_BOOL, FALSE};
2942
2943 op = userdata;
2946
2948}
2949
2950/************************************************************************/
2953static void objprop_setup_widget(struct objprop *op)
2954{
2955 GtkWidget *ebox, *hbox, *hbox2, *label, *image, *entry, *spin, *button;
2956 struct extviewer *ev = NULL;
2958
2959 if (!op) {
2960 return;
2961 }
2962
2963 if (!objprop_has_widget(op)) {
2964 return;
2965 }
2966
2967 ebox = gtk_event_box_new();
2968 op->widget = ebox;
2969
2970 hbox = gtk_grid_new();
2972
2974
2979 objprop_set_child_widget(op, "name-label", label);
2980
2982
2983 switch (propid) {
2984 case OPID_TILE_INDEX:
2985 case OPID_TILE_X:
2986 case OPID_TILE_Y:
2987 case OPID_TILE_NAT_X:
2988 case OPID_TILE_NAT_Y:
2990 case OPID_TILE_TERRAIN:
2991 case OPID_TILE_RESOURCE:
2992 case OPID_TILE_XY:
2993 case OPID_STARTPOS_XY:
2994 case OPID_UNIT_ID:
2995 case OPID_UNIT_XY:
2996 case OPID_UNIT_TYPE:
2997 case OPID_CITY_ID:
2998 case OPID_CITY_XY:
2999 case OPID_PLAYER_AGE:
3000#ifdef FREECIV_DEBUG
3001 case OPID_TILE_ADDRESS:
3002 case OPID_UNIT_ADDRESS:
3003 case OPID_CITY_ADDRESS:
3005#endif /* FREECIV_DEBUG */
3006 label = gtk_label_new(NULL);
3011 objprop_set_child_widget(op, "value-label", label);
3012 return;
3013
3014 case OPID_TILE_IMAGE:
3016 case OPID_UNIT_IMAGE:
3017 case OPID_CITY_IMAGE:
3018 image = gtk_image_new();
3024 return;
3025
3026 case OPID_CITY_NAME:
3027 case OPID_PLAYER_NAME:
3029 case OPID_TILE_LABEL:
3030 entry = gtk_entry_new();
3034 g_signal_connect(entry, "changed",
3038 return;
3039
3041 case OPID_CITY_SIZE:
3042 case OPID_CITY_HISTORY:
3046 case OPID_PLAYER_GOLD:
3048 spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0);
3051 g_signal_connect(spin, "value-changed",
3055 return;
3056
3057 case OPID_UNIT_FUEL:
3058 case OPID_UNIT_HP:
3059 case OPID_UNIT_VETERAN:
3061 hbox2 = gtk_grid_new();
3066 spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0);
3067 g_signal_connect(spin, "value-changed",
3071 label = gtk_label_new(NULL);
3075 objprop_set_child_widget(op, "max-value-label", label);
3076 return;
3077
3078 case OPID_TILE_SPECIALS:
3079 case OPID_TILE_ROADS:
3080 case OPID_TILE_BASES:
3081 case OPID_TILE_VISION:
3084 case OPID_PLAYER_NATION:
3085 case OPID_PLAYER_GOV:
3089 ev = extviewer_new(op);
3095 return;
3096
3098 case OPID_UNIT_MOVED:
3100 case OPID_UNIT_STAY:
3101 case OPID_GAME_SCENARIO:
3109 button = gtk_check_button_new();
3112 g_signal_connect(button, "toggled",
3115 objprop_set_child_widget(op, "checkbutton", button);
3116 return;
3117 }
3118
3119 log_error("%s(): Unhandled request to create widget for property %d (%s).",
3121}
3122
3123/************************************************************************/
3132 struct objbind *ob)
3133{
3134 GtkWidget *w, *label, *image, *entry, *spin, *button;
3135 struct extviewer *ev;
3136 struct propval *pv;
3137 bool modified;
3139 double min, max, step, big_step;
3140 char buf[256];
3141
3142 if (!op || !objprop_has_widget(op)) {
3143 return;
3144 }
3145
3147 if (!w) {
3148 return;
3149 }
3150
3152
3153 /* NB: We must take care to propval_free the return value of
3154 * objbind_get_value_from_object(), since it always makes a
3155 * copy, but to NOT free the result of objbind_get_modified_value()
3156 * since it returns its own stored value. */
3159
3160 if (pv && modified) {
3161 struct propval *pv_mod;
3162
3164 if (pv_mod) {
3165 if (propval_equal(pv, pv_mod)) {
3167 modified = FALSE;
3168 } else {
3170 pv = pv_mod;
3171 modified = TRUE;
3172 }
3173 } else {
3174 modified = FALSE;
3175 }
3176 }
3177
3178 switch (propid) {
3179 case OPID_TILE_IMAGE:
3181 case OPID_UNIT_IMAGE:
3182 case OPID_CITY_IMAGE:
3183 image = objprop_get_child_widget(op, "image");
3184 if (pv) {
3185 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pv->data.v_pixbuf);
3186 } else {
3188 }
3189 break;
3190
3191 case OPID_TILE_XY:
3192 case OPID_TILE_TERRAIN:
3193 case OPID_TILE_RESOURCE:
3194 case OPID_STARTPOS_XY:
3195 case OPID_UNIT_XY:
3196 case OPID_UNIT_TYPE:
3197 case OPID_CITY_XY:
3198#ifdef FREECIV_DEBUG
3199 case OPID_TILE_ADDRESS:
3200 case OPID_UNIT_ADDRESS:
3201 case OPID_CITY_ADDRESS:
3203#endif /* FREECIV_DEBUG */
3204 label = objprop_get_child_widget(op, "value-label");
3205 if (pv) {
3206 gtk_label_set_text(GTK_LABEL(label), pv->data.v_string);
3207 } else {
3209 }
3210 break;
3211
3212 case OPID_TILE_INDEX:
3213 case OPID_TILE_X:
3214 case OPID_TILE_Y:
3215 case OPID_TILE_NAT_X:
3216 case OPID_TILE_NAT_Y:
3218 case OPID_UNIT_ID:
3219 case OPID_CITY_ID:
3220 case OPID_PLAYER_AGE:
3221 label = objprop_get_child_widget(op, "value-label");
3222 if (pv) {
3223 char agebuf[16];
3224
3225 fc_snprintf(agebuf, sizeof(agebuf), "%d", pv->data.v_int);
3227 } else {
3229 }
3230 break;
3231
3232 case OPID_CITY_NAME:
3233 case OPID_PLAYER_NAME:
3235 case OPID_TILE_LABEL:
3236 entry = objprop_get_child_widget(op, "entry");
3237 if (pv) {
3238 gtk_entry_set_text(GTK_ENTRY(entry), pv->data.v_string);
3239 } else {
3241 }
3243 break;
3244
3246 case OPID_CITY_SIZE:
3247 case OPID_CITY_HISTORY:
3251 case OPID_PLAYER_GOLD:
3253 spin = objprop_get_child_widget(op, "spin");
3254 if (pv) {
3257 if (objbind_get_allowed_value_span(ob, op, &min, &max,
3258 &step, &big_step)) {
3261 step, big_step);
3262 }
3266 }
3268 break;
3269
3270 case OPID_UNIT_FUEL:
3271 case OPID_UNIT_HP:
3272 case OPID_UNIT_VETERAN:
3274 spin = objprop_get_child_widget(op, "spin");
3275 label = objprop_get_child_widget(op, "max-value-label");
3276 if (pv) {
3279 if (objbind_get_allowed_value_span(ob, op, &min, &max,
3280 &step, &big_step)) {
3283 step, big_step);
3284 fc_snprintf(buf, sizeof(buf), "/%d", (int) max);
3286 } else {
3288 }
3292 } else {
3294 }
3296 break;
3297
3298 case OPID_TILE_SPECIALS:
3299 case OPID_TILE_ROADS:
3300 case OPID_TILE_BASES:
3301 case OPID_TILE_VISION:
3304 case OPID_PLAYER_NATION:
3305 case OPID_PLAYER_GOV:
3310 if (pv) {
3312 } else {
3314 }
3315 break;
3316
3318 case OPID_UNIT_MOVED:
3320 case OPID_UNIT_STAY:
3321 case OPID_GAME_SCENARIO:
3329 button = objprop_get_child_widget(op, "checkbutton");
3332 if (pv) {
3334 pv->data.v_bool);
3335 } else {
3337 }
3340 gtk_widget_set_sensitive(button, pv != NULL);
3341 break;
3342 }
3343
3344 if (!modified) {
3346 }
3347
3348 label = objprop_get_child_widget(op, "name-label");
3349 if (label) {
3350 const char *name = objprop_get_name(op);
3351 if (modified) {
3352 char namebuf[128];
3353
3354 fc_snprintf(namebuf, sizeof(namebuf),
3355 "<span foreground=\"red\">%s</span>", name);
3357 } else {
3359 }
3360 }
3361}
3362
3363/************************************************************************/
3368{
3369 if (!op) {
3370 return NULL;
3371 }
3372 if (!op->widget) {
3374 }
3375 return op->widget;
3376}
3377
3378/************************************************************************/
3383 const char *widget_name,
3385{
3386 GtkWidget *w;
3387
3388 if (!op || !widget_name || !widget) {
3389 return;
3390 }
3391
3393 if (!w) {
3394 log_error("Cannot store child widget %p under name "
3395 "\"%s\" using objprop_set_child_widget for object "
3396 "property %d (%s) because objprop_get_widget does "
3397 "not return a valid widget.",
3399 return;
3400 }
3401
3403}
3404
3405/************************************************************************/
3410 const char *widget_name)
3411{
3412 GtkWidget *w, *child;
3413
3414 if (!op || !widget_name) {
3415 return NULL;
3416 }
3417
3419 if (!w) {
3420 log_error("Cannot retrieve child widget under name "
3421 "\"%s\" using objprop_get_child_widget for object "
3422 "property %d (%s) because objprop_get_widget does "
3423 "not return a valid widget.",
3425 return NULL;
3426 }
3427
3429 if (!child) {
3430 log_error("Child widget \"%s\" not found for object "
3431 "property %d (%s) via objprop_get_child_widget.",
3433 return NULL;
3434 }
3435
3436 return child;
3437}
3438
3439/************************************************************************/
3443 struct extviewer *ev)
3444{
3445 if (!op) {
3446 return;
3447 }
3448 op->extviewer = ev;
3449}
3450
3451/************************************************************************/
3455{
3456 if (!op) {
3457 return NULL;
3458 }
3459 return op->extviewer;
3460}
3461
3462/************************************************************************/
3466{
3467 if (!op) {
3468 return NULL;
3469 }
3470 return op->parent_page;
3471}
3472
3473/************************************************************************/
3476static struct objprop *objprop_new(int id,
3477 const char *name,
3478 const char *tooltip,
3480 enum value_types valtype,
3481 struct property_page *parent)
3482{
3483 struct objprop *op;
3484
3485 op = fc_calloc(1, sizeof(*op));
3486 op->id = id;
3487 op->name = name;
3488 op->tooltip = tooltip;
3489 op->flags = flags;
3490 op->valtype = valtype;
3491 op->column_id = -1;
3492 op->parent_page = parent;
3493
3494 return op;
3495}
3496
3497/************************************************************************/
3501static struct extviewer *extviewer_new(struct objprop *op)
3502{
3503 struct extviewer *ev;
3504 GtkWidget *hbox, *vbox, *label, *button, *scrollwin, *image;
3505 GtkWidget *view = NULL;
3509 GType *gtypes;
3511 int num_cols;
3512
3513 if (!op) {
3514 return NULL;
3515 }
3516
3517 ev = fc_calloc(1, sizeof(*ev));
3518 ev->objprop = op;
3519
3521
3522
3523 /* Create the panel widget. */
3524
3525 switch (propid) {
3526 case OPID_TILE_SPECIALS:
3527 case OPID_TILE_ROADS:
3528 case OPID_TILE_BASES:
3534 hbox = gtk_grid_new();
3536 ev->panel_widget = hbox;
3537
3538 label = gtk_label_new(NULL);
3542 ev->panel_label = label;
3543 break;
3544
3545 case OPID_PLAYER_NATION:
3546 case OPID_PLAYER_GOV:
3547 vbox = gtk_grid_new();
3551 ev->panel_widget = vbox;
3552
3553 label = gtk_label_new(NULL);
3556 gtk_container_add(GTK_CONTAINER(vbox), label);
3557 ev->panel_label = label;
3558
3559 hbox = gtk_grid_new();
3562
3563 image = gtk_image_new();
3567 ev->panel_image = image;
3568 break;
3569
3570 case OPID_TILE_VISION:
3571 hbox = gtk_grid_new();
3573 ev->panel_widget = hbox;
3574 break;
3575
3576 default:
3577 log_error("Unhandled request to create panel widget "
3578 "for property %d (%s) in extviewer_new().",
3580 hbox = gtk_grid_new();
3582 ev->panel_widget = hbox;
3583 break;
3584 }
3585
3586 if (objprop_is_readonly(op)) {
3587 button = gtk_button_new_with_label(Q_("?verb:View"));
3588 } else {
3589 button = gtk_button_new_with_label(_("Edit"));
3590 }
3591 g_signal_connect(button, "clicked",
3594 ev->panel_button = button;
3595
3596
3597 /* Create the data store. */
3598
3599 switch (propid) {
3600 case OPID_TILE_SPECIALS:
3601 case OPID_TILE_ROADS:
3602 case OPID_TILE_BASES:
3606 break;
3607 case OPID_TILE_VISION:
3608 num_cols = 3 + 1 + V_COUNT;
3609 gtypes = fc_malloc(num_cols * sizeof(GType));
3610 gtypes[0] = G_TYPE_INT; /* player number */
3611 gtypes[1] = GDK_TYPE_PIXBUF; /* player flag */
3612 gtypes[2] = G_TYPE_STRING; /* player name */
3613 gtypes[3] = G_TYPE_BOOLEAN; /* tile_known */
3615 gtypes[4 + v] = G_TYPE_BOOLEAN; /* tile_seen[v] */
3618 free(gtypes);
3619 break;
3623 break;
3625 case OPID_PLAYER_NATION:
3626 case OPID_PLAYER_GOV:
3629 break;
3633 break;
3634 default:
3635 log_error("Unhandled request to create data store "
3636 "for property %d (%s) in extviewer_new().",
3638 break;
3639 }
3640
3641 ev->store = store;
3642 ev->textbuf = textbuf;
3643
3644 /* Create the view widget. */
3645
3646 vbox = gtk_grid_new();
3651 ev->view_widget = vbox;
3652
3656 gtk_container_add(GTK_CONTAINER(vbox), label);
3657 ev->view_label = label;
3658
3659 if (store || textbuf) {
3667
3668 if (store) {
3672 } else {
3673 const bool editable = !objprop_is_readonly(op);
3677 }
3680
3682 }
3683
3684 switch (propid) {
3685
3686 case OPID_TILE_SPECIALS:
3687 case OPID_TILE_ROADS:
3688 case OPID_TILE_BASES:
3689 /* TRANS: As in "this tile special is present". */
3690 add_column(view, 0, _("Present"), G_TYPE_BOOLEAN, TRUE, FALSE,
3692 add_column(view, 1, _("ID"), G_TYPE_INT,
3693 FALSE, FALSE, NULL, NULL);
3694 add_column(view, 2, _("Name"), G_TYPE_STRING,
3695 FALSE, FALSE, NULL, NULL);
3696 break;
3697
3698 case OPID_TILE_VISION:
3699 add_column(view, 0, _("ID"), G_TYPE_INT,
3700 FALSE, FALSE, NULL, NULL);
3701 add_column(view, 1, _("Nation"), GDK_TYPE_PIXBUF,
3702 FALSE, FALSE, NULL, NULL);
3703 add_column(view, 2, _("Name"), G_TYPE_STRING,
3704 FALSE, FALSE, NULL, NULL);
3705 add_column(view, 3, _("Known"), G_TYPE_BOOLEAN,
3706 FALSE, FALSE, NULL, NULL);
3711 break;
3712
3714 /* TRANS: As in "this building is present". */
3715 add_column(view, 0, _("Present"), G_TYPE_BOOLEAN, TRUE, FALSE,
3717 add_column(view, 1, _("ID"), G_TYPE_INT,
3718 FALSE, FALSE, NULL, NULL);
3719 add_column(view, 2, _("Name"), G_TYPE_STRING,
3720 FALSE, FALSE, NULL, NULL);
3721 /* TRANS: As in "the turn when this building was built". */
3722 add_column(view, 3, _("Turn Built"), G_TYPE_STRING,
3723 FALSE, FALSE, NULL, NULL);
3724 break;
3725
3727 /* TRANS: As in "the player has set this nation". */
3728 add_column(view, 0, _("Set"), G_TYPE_BOOLEAN, TRUE, FALSE,
3730 add_column(view, 1, _("ID"), G_TYPE_INT,
3731 FALSE, FALSE, NULL, NULL);
3732 add_column(view, 2, _("Flag"), GDK_TYPE_PIXBUF,
3733 FALSE, FALSE, NULL, NULL);
3734 add_column(view, 3, _("Name"), G_TYPE_STRING,
3735 FALSE, FALSE, NULL, NULL);
3736 break;
3737
3738 case OPID_PLAYER_NATION:
3739 case OPID_PLAYER_GOV:
3740 /* TRANS: As in "the player has set this nation". */
3741 add_column(view, 0, _("Set"), G_TYPE_BOOLEAN, TRUE, TRUE,
3743 add_column(view, 1, _("ID"), G_TYPE_INT,
3744 FALSE, FALSE, NULL, NULL);
3745 add_column(view, 2,
3746 propid == OPID_PLAYER_GOV ? _("Icon") : _("Flag"),
3748 FALSE, FALSE, NULL, NULL);
3749 add_column(view, 3, _("Name"), G_TYPE_STRING,
3750 FALSE, FALSE, NULL, NULL);
3751 break;
3752
3754 /* TRANS: As in "this invention is known". */
3755 add_column(view, 0, _("Known"), G_TYPE_BOOLEAN, TRUE, FALSE,
3757 add_column(view, 1, _("ID"), G_TYPE_INT,
3758 FALSE, FALSE, NULL, NULL);
3759 add_column(view, 2, _("Name"), G_TYPE_STRING,
3760 FALSE, FALSE, NULL, NULL);
3761 break;
3762
3765 g_signal_connect(textbuf, "changed",
3767 break;
3768
3769 default:
3770 log_error("Unhandled request to configure view widget "
3771 "for property %d (%s) in extviewer_new().",
3773 break;
3774 }
3775
3776 gtk_widget_show_all(ev->panel_widget);
3777 gtk_widget_show_all(ev->view_widget);
3778
3779 return ev;
3780}
3781
3782/************************************************************************/
3786{
3787 if (!ev) {
3788 return NULL;
3789 }
3790 return ev->objprop;
3791}
3792
3793/************************************************************************/
3798{
3799 if (!ev) {
3800 return NULL;
3801 }
3802 return ev->panel_widget;
3803}
3804
3805/************************************************************************/
3810{
3811 if (!ev) {
3812 return NULL;
3813 }
3814 return ev->view_widget;
3815}
3816
3817/************************************************************************/
3821 struct propval *pv)
3822{
3823 struct objprop *op;
3825 int id, turn_built;
3826 bool present, all;
3827 const char *name;
3829 GtkListStore *store;
3830 GtkTextBuffer *textbuf;
3832 gchar *buf;
3833
3834 if (!ev) {
3835 return;
3836 }
3837
3840
3841 if (propval_equal(pv, ev->pv_cached)) {
3842 return;
3843 }
3844 propval_free(ev->pv_cached);
3845 ev->pv_cached = propval_copy(pv);
3846 store = ev->store;
3847 textbuf = ev->textbuf;
3848
3849
3850 /* NB: Remember to have -1 as the last argument to
3851 * gtk_list_store_set() and to use the correct column
3852 * number when inserting data. :) */
3853 switch (propid) {
3854
3855 case OPID_TILE_SPECIALS:
3856 gtk_list_store_clear(store);
3858 id = spe->data.special_idx;
3860 present = BV_ISSET(pv->data.v_bv_special, id);
3861 gtk_list_store_append(store, &iter);
3862 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
3865 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3866 g_free(buf);
3867 break;
3868
3869 case OPID_TILE_ROADS:
3870 gtk_list_store_clear(store);
3872 struct road_type *proad = extra_road_get(pextra);
3873
3874 id = road_number(proad);
3875 name = extra_name_translation(pextra);
3876 present = BV_ISSET(pv->data.v_bv_roads, id);
3877 gtk_list_store_append(store, &iter);
3878 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
3881 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3882 g_free(buf);
3883 break;
3884
3885 case OPID_TILE_BASES:
3886 gtk_list_store_clear(store);
3888 struct base_type *pbase = extra_base_get(pextra);
3889
3890 id = base_number(pbase);
3891 name = extra_name_translation(pextra);
3892 present = BV_ISSET(pv->data.v_bv_bases, id);
3893 gtk_list_store_append(store, &iter);
3894 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
3897 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3898 g_free(buf);
3899 break;
3900
3901 case OPID_TILE_VISION:
3902 gtk_list_store_clear(store);
3903 player_slots_iterate(pslot) {
3904 id = player_slot_index(pslot);
3905 if (player_slot_is_used(pslot)) {
3906 struct player *pplayer = player_slot_get_player(pslot);
3907 name = player_name(pplayer);
3908 pixbuf = get_flag(pplayer->nation);
3909 } else {
3910 name = "";
3911 pixbuf = NULL;
3912 }
3913 gtk_list_store_append(store, &iter);
3914 gtk_list_store_set(store, &iter, 0, id, 2, name, -1);
3915 if (pixbuf) {
3916 gtk_list_store_set(store, &iter, 1, pixbuf, -1);
3918 pixbuf = NULL;
3919 }
3920 present = BV_ISSET(pv->data.v_tile_vision->tile_known, id);
3921 gtk_list_store_set(store, &iter, 3, present, -1);
3923 present = BV_ISSET(pv->data.v_tile_vision->tile_seen[v], id);
3924 gtk_list_store_set(store, &iter, 4 + v, present, -1);
3927 break;
3928
3930 gtk_list_store_clear(store);
3931 gtk_list_store_append(store, &iter);
3932 all = (0 == nation_hash_size(pv->data.v_nation_hash));
3933 gtk_list_store_set(store, &iter, 0, all, 1, -1, 3,
3934 _("All nations"), -1);
3935 nations_iterate(pnation) {
3937 && is_nation_playable(pnation)) {
3938 present = (!all && nation_hash_lookup(pv->data.v_nation_hash,
3939 pnation, NULL));
3940 id = nation_number(pnation);
3941 pixbuf = get_flag(pnation);
3943 gtk_list_store_append(store, &iter);
3944 gtk_list_store_set(store, &iter, 0, present, 1, id,
3945 2, pixbuf, 3, name, -1);
3946 if (pixbuf) {
3948 }
3949 }
3952 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3953 g_free(buf);
3954 break;
3955
3957 gtk_list_store_clear(store);
3958 improvement_iterate(pimprove) {
3959 if (is_special_improvement(pimprove)) {
3960 continue;
3961 }
3962 id = improvement_index(pimprove);
3964 turn_built = pv->data.v_built[id].turn;
3965 present = turn_built >= 0;
3966 buf = built_status_to_string(&pv->data.v_built[id]);
3967 gtk_list_store_append(store, &iter);
3968 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name,
3969 3, buf, -1);
3970 g_free(buf);
3973 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
3974 g_free(buf);
3975 break;
3976
3977 case OPID_PLAYER_NATION:
3978 {
3979 enum barbarian_type barbarian_type =
3980 nation_barbarian_type(pv->data.v_nation);
3981
3982 gtk_list_store_clear(store);
3983 nations_iterate(pnation) {
3985 && nation_barbarian_type(pnation) == barbarian_type
3986 && (barbarian_type != NOT_A_BARBARIAN
3987 || is_nation_playable(pnation))) {
3988 present = (pnation == pv->data.v_nation);
3989 id = nation_index(pnation);
3990 pixbuf = get_flag(pnation);
3992 gtk_list_store_append(store, &iter);
3993 gtk_list_store_set(store, &iter, 0, present, 1, id,
3994 2, pixbuf, 3, name, -1);
3995 if (pixbuf) {
3997 }
3998 }
4000 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4001 nation_adjective_translation(pv->data.v_nation));
4002 pixbuf = get_flag(pv->data.v_nation);
4004 if (pixbuf) {
4006 }
4007 }
4008 break;
4009
4010 case OPID_PLAYER_GOV:
4011 {
4012 gtk_list_store_clear(store);
4014 present = (pgov == pv->data.v_gov);
4015 id = government_index(pgov);
4018 gtk_list_store_append(store, &iter);
4019 gtk_list_store_set(store, &iter, 0, present, 1, id,
4020 2, pixbuf, 3, name, -1);
4021 if (pixbuf) {
4023 }
4025 if (pv->data.v_gov != NULL) {
4026 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4027 government_name_translation(pv->data.v_gov));
4029 } else {
4030 gtk_label_set_text(GTK_LABEL(ev->panel_label), "?");
4033 }
4034
4036 if (pixbuf) {
4038 }
4039 }
4040 break;
4041
4043 gtk_list_store_clear(store);
4045 id = advance_index(padvance);
4046 present = BV_ISSET(pv->data.v_bv_inventions, id);
4048 gtk_list_store_append(store, &iter);
4049 gtk_list_store_set(store, &iter, 0, present, 1, id, 2, name, -1);
4052 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4053 g_free(buf);
4054 break;
4055
4060 {
4061 GtkTextIter start, end;
4062 char *oldtext;
4063
4064 /* Don't re-set content if unchanged, to avoid moving cursor */
4065 gtk_text_buffer_get_bounds(textbuf, &start, &end);
4066 oldtext = gtk_text_buffer_get_text(textbuf, &start, &end, TRUE);
4067 if (strcmp(oldtext, pv->data.v_const_string) != 0) {
4068 gtk_text_buffer_set_text(textbuf, pv->data.v_const_string, -1);
4069 }
4070 }
4073 gtk_widget_set_sensitive(ev->view_widget, TRUE);
4075 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4076 g_free(buf);
4077 break;
4078
4079 default:
4080 log_error("Unhandled request to refresh widgets "
4081 "extviewer_refresh_widgets() for objprop id=%d "
4082 "name \"%s\".", propid, objprop_get_name(op));
4083 break;
4084 }
4085}
4086
4087/************************************************************************/
4091{
4092 struct objprop *op;
4094
4095 if (!ev) {
4096 return;
4097 }
4098
4101
4102 propval_free(ev->pv_cached);
4103 ev->pv_cached = NULL;
4104
4105 if (ev->panel_label != NULL) {
4106 gtk_label_set_text(GTK_LABEL(ev->panel_label), NULL);
4107 }
4108
4109 switch (propid) {
4110 case OPID_TILE_SPECIALS:
4111 case OPID_TILE_ROADS:
4112 case OPID_TILE_BASES:
4113 case OPID_TILE_VISION:
4117 gtk_list_store_clear(ev->store);
4118 break;
4119 case OPID_PLAYER_NATION:
4120 case OPID_PLAYER_GOV:
4121 gtk_list_store_clear(ev->store);
4123 break;
4128 gtk_text_buffer_set_text(ev->textbuf, "", -1);
4131 gtk_widget_set_sensitive(ev->view_widget, FALSE);
4132 break;
4133 default:
4134 log_error("Unhandled request to clear widgets "
4135 "in extviewer_clear_widgets() for objprop id=%d "
4136 "name \"%s\".", propid, objprop_get_name(op));
4137 break;
4138 }
4139}
4140
4141/************************************************************************/
4147{
4148 struct extviewer *ev;
4149 struct property_page *pp;
4150 struct objprop *op;
4151
4152 ev = userdata;
4153 if (!ev) {
4154 return;
4155 }
4156
4160}
4161
4162/************************************************************************/
4166 gchar *path,
4168{
4169 struct extviewer *ev;
4170 struct objprop *op;
4171 struct property_page *pp;
4173 GtkTreeModel *model;
4175 int id, old_id, turn_built;
4176 struct propval *pv;
4177 bool active, present;
4178 gchar *buf;
4180
4181 ev = userdata;
4182 if (!ev) {
4183 return;
4184 }
4185
4186 pv = ev->pv_cached;
4187 if (!pv) {
4188 return;
4189 }
4190
4195
4196 model = GTK_TREE_MODEL(ev->store);
4197 if (!gtk_tree_model_get_iter_from_string(model, &iter, path)) {
4198 return;
4199 }
4200 present = !active;
4201
4202
4203 switch (propid) {
4204
4205 case OPID_TILE_SPECIALS:
4206 gtk_tree_model_get(model, &iter, 1, &id, -1);
4208 return;
4209 }
4210 if (present) {
4211 BV_SET(pv->data.v_bv_special, id);
4212 } else {
4213 BV_CLR(pv->data.v_bv_special, id);
4214 }
4215 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4217 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4218 g_free(buf);
4219 break;
4220
4221 case OPID_TILE_ROADS:
4222 gtk_tree_model_get(model, &iter, 1, &id, -1);
4223 if (!(0 <= id && id < road_count())) {
4224 return;
4225 }
4226 if (present) {
4227 BV_SET(pv->data.v_bv_roads, id);
4228 } else {
4229 BV_CLR(pv->data.v_bv_roads, id);
4230 }
4231 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4233 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4234 g_free(buf);
4235 break;
4236
4237 case OPID_TILE_BASES:
4238 gtk_tree_model_get(model, &iter, 1, &id, -1);
4239 if (!(0 <= id && id < base_count())) {
4240 return;
4241 }
4242 if (present) {
4243 BV_SET(pv->data.v_bv_bases, id);
4244 } else {
4245 BV_CLR(pv->data.v_bv_bases, id);
4246 }
4247 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4249 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4250 g_free(buf);
4251 break;
4252
4254 gtk_tree_model_get(model, &iter, 1, &id, -1);
4255 if (-1 > id && id >= nation_count()) {
4256 return;
4257 }
4258
4259 if (-1 == id) {
4260 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4262 if (present) {
4263 while (gtk_tree_model_iter_next(model, &iter)) {
4264 gtk_list_store_set(ev->store, &iter, 0, FALSE, -1);
4265 }
4266 nation_hash_clear(pv->data.v_nation_hash);
4267 } else {
4268 const struct nation_type *pnation;
4269 int id2;
4270
4272 gtk_tree_model_get(model, &iter, 0, &id2, -1);
4273 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4274 pnation = nation_by_number(id2);
4275 nation_hash_insert(pv->data.v_nation_hash, pnation, NULL);
4276 }
4277 } else {
4278 const struct nation_type *pnation;
4279 bool all;
4280
4281 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4282 pnation = nation_by_number(id);
4283 if (present) {
4284 nation_hash_insert(pv->data.v_nation_hash, pnation, NULL);
4285 } else {
4286 nation_hash_remove(pv->data.v_nation_hash, pnation);
4287 }
4289 all = (0 == nation_hash_size(pv->data.v_nation_hash));
4290 gtk_list_store_set(ev->store, &iter, 0, all, -1);
4291 }
4293 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4294 g_free(buf);
4295 break;
4296
4298 gtk_tree_model_get(model, &iter, 1, &id, -1);
4299 if (!(0 <= id && id < B_LAST)) {
4300 return;
4301 }
4302 turn_built = present ? game.info.turn : I_NEVER;
4303 pv->data.v_built[id].turn = turn_built;
4304 buf = built_status_to_string(&pv->data.v_built[id]);
4305 gtk_list_store_set(ev->store, &iter, 0, present, 3, buf, -1);
4306 g_free(buf);
4308 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4309 g_free(buf);
4310 break;
4311
4312 case OPID_PLAYER_NATION:
4313 gtk_tree_model_get(model, &iter, 1, &id, -1);
4314 if (!(0 <= id && id < nation_count()) || !present) {
4315 return;
4316 }
4317 old_id = nation_index(pv->data.v_nation);
4318 pv->data.v_nation = nation_by_number(id);
4319 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4321 gtk_list_store_set(ev->store, &iter, 0, FALSE, -1);
4322 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4323 nation_adjective_translation(pv->data.v_nation));
4324 pixbuf = get_flag(pv->data.v_nation);
4326 if (pixbuf) {
4328 }
4329 break;
4330
4331 case OPID_PLAYER_GOV:
4332 gtk_tree_model_get(model, &iter, 1, &id, -1);
4333 if (!(0 <= id && id < government_count()) || !present) {
4334 return;
4335 }
4336 if (pv->data.v_gov != NULL) {
4337 old_id = government_index(pv->data.v_gov);
4338 pv->data.v_gov = government_by_number(id);
4339 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4341 gtk_list_store_set(ev->store, &iter, 0, FALSE, -1);
4342 } else {
4343 pv->data.v_gov = government_by_number(id);
4344 gtk_list_store_set(ev->store, &iter, 0, TRUE, -1);
4345 }
4346
4347 gtk_label_set_text(GTK_LABEL(ev->panel_label),
4348 government_name_translation(pv->data.v_gov));
4351 if (pixbuf) {
4353 }
4354 break;
4355
4357 gtk_tree_model_get(model, &iter, 1, &id, -1);
4358 if (!(A_FIRST <= id && id < advance_count())) {
4359 return;
4360 }
4361 if (present) {
4362 BV_SET(pv->data.v_bv_inventions, id);
4363 } else {
4364 BV_CLR(pv->data.v_bv_inventions, id);
4365 }
4366 gtk_list_store_set(ev->store, &iter, 0, present, -1);
4368 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4369 g_free(buf);
4370 break;
4371
4372 default:
4373 log_error("Unhandled widget toggled signal in "
4374 "extviewer_view_cell_toggled() for objprop id=%d "
4375 "name \"%s\".", propid, objprop_get_name(op));
4376 return;
4377 break;
4378 }
4379
4381}
4382
4383/************************************************************************/
4388{
4389 struct extviewer *ev;
4390 struct objprop *op;
4391 struct property_page *pp;
4393 struct propval value = {{0,}, VALTYPE_STRING, FALSE}, *pv;
4394 GtkTextIter start, end;
4395 char *text;
4396 gchar *buf;
4397
4398 ev = userdata;
4399 if (!ev) {
4400 return;
4401 }
4402
4406
4407 gtk_text_buffer_get_start_iter(textbuf, &start);
4408 gtk_text_buffer_get_end_iter(textbuf, &end);
4409 text = gtk_text_buffer_get_text(textbuf, &start, &end, FALSE);
4410 value.data.v_const_string = text;
4411 pv = &value;
4412
4413 switch (propid) {
4417 gtk_label_set_text(GTK_LABEL(ev->panel_label), buf);
4418 g_free(buf);
4419 break;
4420 default:
4421 log_error("Unhandled widget modified signal in "
4422 "extviewer_textbuf_changed() for objprop id=%d "
4423 "name \"%s\".", propid, objprop_get_name(op));
4424 return;
4425 break;
4426 }
4427
4429 g_free(text);
4430}
4431
4432/************************************************************************/
4436{
4437#define ADDPROP(ARG_id, ARG_name, ARG_tooltip, ARG_flags, ARG_valtype) do { \
4438 struct objprop *MY_op = objprop_new(ARG_id, ARG_name, ARG_tooltip, \
4439 ARG_flags, ARG_valtype, pp); \
4440 objprop_hash_insert(pp->objprop_table, MY_op->id, MY_op); \
4441} while (FALSE)
4442
4443 switch (property_page_get_objtype(pp)) {
4444 case OBJTYPE_TILE:
4445 ADDPROP(OPID_TILE_IMAGE, _("Image"), NULL,
4447 ADDPROP(OPID_TILE_TERRAIN, _("Terrain"), NULL,
4449 ADDPROP(OPID_TILE_RESOURCE, _("Resource"), NULL,
4451 ADDPROP(OPID_TILE_INDEX, _("Index"), NULL,
4453 ADDPROP(OPID_TILE_X, Q_("?coordinate:X"), NULL,
4455 ADDPROP(OPID_TILE_Y, Q_("?coordinate:Y"), NULL,
4457 /* TRANS: The coordinate X in native coordinates.
4458 * The freeciv coordinate system is described in doc/HACKING. */
4459 ADDPROP(OPID_TILE_NAT_X, _("NAT X"), NULL,
4461 /* TRANS: The coordinate Y in native coordinates.
4462 * The freeciv coordinate system is described in doc/HACKING. */
4463 ADDPROP(OPID_TILE_NAT_Y, _("NAT Y"), NULL,
4465 ADDPROP(OPID_TILE_CONTINENT, _("Continent"), NULL,
4467 ADDPROP(OPID_TILE_XY, Q_("?coordinates:X,Y"), NULL,
4469 ADDPROP(OPID_TILE_SPECIALS, _("Specials"), NULL,
4472 ADDPROP(OPID_TILE_ROADS, _("Roads"), NULL,
4475 ADDPROP(OPID_TILE_BASES, _("Bases"), NULL,
4478#ifdef FREECIV_DEBUG
4479 ADDPROP(OPID_TILE_ADDRESS, _("Address"), NULL,
4481#endif /* FREECIV_DEBUG */
4482#if 0
4483 /* Disabled entirely for now as server is not sending other
4484 * players' vision information anyway. */
4485 ADDPROP(OPID_TILE_VISION, _("Vision"), NULL,
4487#endif
4488 /* TRANS: Tile property "Label" label in editor */
4489 ADDPROP(OPID_TILE_LABEL, Q_("?property:Label"), NULL,
4491 return;
4492
4493 case OBJTYPE_STARTPOS:
4494 ADDPROP(OPID_STARTPOS_IMAGE, _("Image"), NULL,
4496 ADDPROP(OPID_STARTPOS_XY, Q_("?coordinates:X,Y"), NULL,
4498 ADDPROP(OPID_STARTPOS_EXCLUDE, _("Exclude Nations"), NULL,
4500 ADDPROP(OPID_STARTPOS_NATIONS, _("Nations"), NULL,
4503 return;
4504
4505 case OBJTYPE_UNIT:
4506 ADDPROP(OPID_UNIT_IMAGE, _("Image"), NULL,
4508#ifdef FREECIV_DEBUG
4509 ADDPROP(OPID_UNIT_ADDRESS, _("Address"), NULL,
4511#endif /* FREECIV_DEBUG */
4512 ADDPROP(OPID_UNIT_TYPE, _("Type"), NULL,
4514 ADDPROP(OPID_UNIT_ID, _("ID"), NULL,
4516 ADDPROP(OPID_UNIT_XY, Q_("?coordinates:X,Y"), NULL,
4518 ADDPROP(OPID_UNIT_MOVES_LEFT, _("Moves Left"), NULL,
4520 ADDPROP(OPID_UNIT_FUEL, _("Fuel"), NULL,
4522 ADDPROP(OPID_UNIT_MOVED, _("Moved"), NULL,
4524 ADDPROP(OPID_UNIT_DONE_MOVING, _("Done Moving"), NULL,
4526 /* TRANS: HP = Hit Points of a unit. */
4527 ADDPROP(OPID_UNIT_HP, _("HP"), NULL,
4529 ADDPROP(OPID_UNIT_VETERAN, _("Veteran"), NULL,
4531 ADDPROP(OPID_UNIT_STAY, _("Stay put"), NULL,
4533 return;
4534
4535 case OBJTYPE_CITY:
4536 ADDPROP(OPID_CITY_IMAGE, _("Image"), NULL,
4538 ADDPROP(OPID_CITY_NAME, _("Name"), NULL,
4540#ifdef FREECIV_DEBUG
4541 ADDPROP(OPID_CITY_ADDRESS, _("Address"), NULL,
4543#endif /* FREECIV_DEBUG */
4544 ADDPROP(OPID_CITY_ID, _("ID"), NULL,
4546 ADDPROP(OPID_CITY_XY, Q_("?coordinates:X,Y"), NULL,
4548 ADDPROP(OPID_CITY_SIZE, _("Size"), NULL,
4550 ADDPROP(OPID_CITY_HISTORY, _("History"), NULL,
4552 ADDPROP(OPID_CITY_BUILDINGS, _("Buildings"), NULL,
4555 ADDPROP(OPID_CITY_FOOD_STOCK, _("Food Stock"), NULL,
4557 ADDPROP(OPID_CITY_SHIELD_STOCK, _("Shield Stock"), NULL,
4559 return;
4560
4561 case OBJTYPE_PLAYER:
4562 ADDPROP(OPID_PLAYER_NAME, _("Name"), NULL,
4565#ifdef FREECIV_DEBUG
4566 ADDPROP(OPID_PLAYER_ADDRESS, _("Address"), NULL,
4568#endif /* FREECIV_DEBUG */
4569 ADDPROP(OPID_PLAYER_NATION, _("Nation"), NULL,
4572 ADDPROP(OPID_PLAYER_GOV, _("Government"), NULL,
4574 VALTYPE_GOV);
4575 ADDPROP(OPID_PLAYER_AGE, _("Age"), NULL,
4577 ADDPROP(OPID_PLAYER_INVENTIONS, _("Inventions"), NULL,
4582 ADDPROP(OPID_PLAYER_SELECT_WEIGHT, _("Select Weight"),
4583 _("How likely user is to get this player by autoselect. '-1' for default behavior."),
4585 VALTYPE_INT);
4586 ADDPROP(OPID_PLAYER_SCIENCE, _("Science"), NULL,
4588 ADDPROP(OPID_PLAYER_GOLD, _("Gold"), NULL,
4590 VALTYPE_INT);
4591 ADDPROP(OPID_PLAYER_INFRAPOINTS, _("Infrapoints"), NULL,
4593 VALTYPE_INT);
4594 return;
4595
4596 case OBJTYPE_GAME:
4597 ADDPROP(OPID_GAME_SCENARIO, _("Scenario"), NULL,
4599 VALTYPE_BOOL);
4601 _("Scenario Name"), NULL,
4605 _("Scenario Authors"), NULL,
4609 _("Scenario Description"), NULL,
4613 _("Save Random Number State"), NULL,
4616 _("Save Players"), NULL,
4619 _("Nation Start Positions"), NULL,
4622 _("Prevent New Cities"), NULL,
4625 _("Saltwater Flooding Lakes"), NULL,
4628 _("Lock to current Ruleset"), NULL,
4630 return;
4631
4632 case NUM_OBJTYPES:
4633 break;
4634 }
4635
4636 log_error("%s(): Unhandled page object type %s (nb %d).", __FUNCTION__,
4639#undef ADDPROP
4640}
4641
4642/************************************************************************/
4665
4666/************************************************************************/
4671 GtkTreeModel *model,
4674 gpointer data)
4675{
4676 struct property_page *pp;
4677 struct objbind *ob = NULL, *old_ob;
4679
4680 pp = data;
4681 if (!pp || !sel_path) {
4682 return TRUE;
4683 }
4684
4685 if (!gtk_tree_model_get_iter(model, &iter, sel_path)) {
4686 return TRUE;
4687 }
4688
4690 gtk_tree_model_get(model, &iter, 0, &ob, -1);
4691 if (currently_selected) {
4692 if (ob == old_ob) {
4693 GList *rows, *p;
4694 GtkTreePath *path;
4695 struct objbind *new_ob = NULL;
4696
4698 for (p = rows; p != NULL; p = p->next) {
4699 path = p->data;
4700 if (gtk_tree_model_get_iter(model, &iter, path)) {
4701 struct objbind *test_ob = NULL;
4702 gtk_tree_model_get(model, &iter, 0, &test_ob, -1);
4703 if (test_ob == ob) {
4704 continue;
4705 }
4706 new_ob = test_ob;
4707 break;
4708 }
4709 }
4712
4714 }
4715 } else {
4717 }
4718
4719 return TRUE;
4720}
4721
4722/************************************************************************/
4727{
4728 struct property_page *pp;
4729 const gchar *text;
4730 GtkWidget *w;
4732 struct property_filter *pf;
4733 bool matched;
4734
4735 pp = userdata;
4737 pf = property_filter_new(text);
4738
4742 continue;
4743 }
4746 if (objprop_has_widget(op) && w != NULL) {
4747 if (matched) {
4748 gtk_widget_show(w);
4749 } else {
4750 gtk_widget_hide(w);
4751 }
4752 }
4754 if (objprop_show_in_listview(op) && col != NULL) {
4756 }
4758
4760}
4761
4762/************************************************************************/
4766static struct property_page *
4768 struct property_editor *pe)
4769{
4770 struct property_page *pp;
4771 GtkWidget *vbox, *vbox2, *hbox, *hbox2, *paned, *frame, *w;
4772 GtkWidget *scrollwin, *view, *label, *entry, *notebook;
4773 GtkWidget *button, *hsep, *image;
4778 int num_columns = 0;
4780 int col_id = 1;
4781 const char *attr_type_str, *name, *tooltip;
4782 gchar *title;
4783
4784 if (!(objtype < NUM_OBJTYPES)) {
4785 return NULL;
4786 }
4787
4788 pp = fc_calloc(1, sizeof(struct property_page));
4789 pp->objtype = objtype;
4790 pp->pe_parent = pe;
4791
4793
4794 pp->objprop_table = objprop_hash_new();
4796
4797 pp->objbind_table = objbind_hash_new();
4798
4799 pp->tag_table = stored_tag_hash_new();
4800
4803 num_columns++;
4804 }
4806
4807 /* Column zero in the store holds an objbind
4808 * pointer and is never displayed. */
4809 num_columns++;
4812
4817 col_id++;
4818 }
4820
4823
4826 pp->widget = paned;
4827
4828 /* Left side object list view. */
4829
4830 vbox = gtk_grid_new();
4836
4844
4848
4851 continue;
4852 }
4853
4855 if (!attr_type_str) {
4856 continue;
4857 }
4859 if (col_id < 0) {
4860 continue;
4861 }
4863 if (!name) {
4864 continue;
4865 }
4867 if (!cell) {
4868 continue;
4869 }
4870
4873 NULL);
4874
4878 if (objprop_is_sortable(op)) {
4881 } else {
4883 }
4886
4888
4891 g_signal_connect(sel, "changed",
4895
4897 pp->object_view = view;
4898
4900 hbox = gtk_grid_new();
4903
4904 button = gtk_button_new();
4907 gtk_button_set_label(GTK_BUTTON(button), _("Create"));
4910 _("Pressing this button will create a new object of the "
4911 "same type as the current property page and add it to "
4912 "the page. The specific type and count of the objects "
4913 "is taken from the editor tool state. So for example, "
4914 "the \"tool value\" of the unit tool and its \"count\" "
4915 "parameter affect unit creation."));
4916 g_signal_connect(button, "clicked",
4919
4920 button = gtk_button_new();
4921 image = gtk_image_new_from_icon_name("list-remove",
4924 gtk_button_set_label(GTK_BUTTON(button), _("Destroy"));
4927 _("Pressing this button will send a request to the server "
4928 "to destroy (i.e. erase) the objects selected in the object "
4929 "list."));
4930 g_signal_connect(button, "clicked",
4933 }
4934
4935 /* Right side properties panel. */
4936
4937 hbox = gtk_grid_new();
4940
4941 vbox = gtk_grid_new();
4947
4948 /* Extended property viewer to the right of the properties panel.
4949 * This needs to be created before property widgets, since some
4950 * might try to append themselves to this notebook. */
4951
4952 vbox2 = gtk_grid_new();
4959
4960 notebook = gtk_notebook_new();
4961 gtk_widget_set_vexpand(notebook, TRUE);
4962 gtk_widget_set_size_request(notebook, 256, -1);
4966 pp->extviewer_notebook = notebook;
4967
4970
4971 hbox2 = gtk_grid_new();
4974
4975 button = gtk_button_new_with_mnemonic(_("_Close"));
4977 g_signal_connect_swapped(button, "clicked",
4980
4981 /* Now create the properties panel. */
4982
4983 /* TRANS: %s is a type of object that can be edited, such as "Tile",
4984 * "Unit", "Start Position", etc. */
4985 title = g_strdup_printf(_("%s Properties"),
4987 frame = gtk_frame_new(title);
4988 g_free(title);
4989 gtk_widget_set_size_request(frame, 256, -1);
4990 gtk_container_add(GTK_CONTAINER(vbox), frame);
4991
4999
5000 vbox2 = gtk_grid_new();
5007
5009 if (!objprop_has_widget(op)) {
5010 continue;
5011 }
5013 if (!w) {
5014 continue;
5015 }
5018 if (NULL != tooltip) {
5020 }
5022
5023 hbox2 = gtk_grid_new();
5028
5029 label = gtk_label_new(_("Filter:"));
5031
5032 entry = gtk_entry_new();
5034 _("Enter a filter string to limit which properties are shown. "
5035 "The filter is one or more text patterns separated by | "
5036 "(\"or\") or & (\"and\"). The symbol & has higher precedence "
5037 "than |. A pattern may also be negated by prefixing it with !."));
5038 g_signal_connect(entry, "changed",
5041
5042 hbox2 = gtk_grid_new();
5045
5046 button = gtk_button_new_with_mnemonic(_("_Refresh"));
5049 _("Pressing this button will reset all modified properties of "
5050 "the selected objects to their current values (the values "
5051 "they have on the server)."));
5052 g_signal_connect(button, "clicked",
5055
5056 button = gtk_button_new_with_mnemonic(_("_Apply"));
5059 _("Pressing this button will send all modified properties of "
5060 "the objects selected in the object list to the server. "
5061 "Modified properties' names are shown in red in the properties "
5062 "panel."));
5063 g_signal_connect(button, "clicked",
5066
5067 return pp;
5068}
5069
5070/************************************************************************/
5073static const char *property_page_get_name(const struct property_page *pp)
5074{
5075 if (!pp) {
5076 return "";
5077 }
5079}
5080
5081/************************************************************************/
5084static enum editor_object_type
5086{
5087 if (!pp) {
5088 return -1;
5089 }
5090 return pp->objtype;
5091}
5092
5093/************************************************************************/
5101static GdkPixbuf *create_tile_pixbuf(const struct tile *ptile)
5102{
5104}
5105
5106/************************************************************************/
5117
5118/************************************************************************/
5125static GdkPixbuf *create_city_pixbuf(const struct city *pcity)
5126{
5127 return create_pixbuf_from_layers(city_tile(pcity), NULL, pcity,
5129}
5130
5131/************************************************************************/
5139static GdkPixbuf *create_pixbuf_from_layers(const struct tile *ptile,
5140 const struct unit *punit,
5141 const struct city *pcity,
5142 enum layer_category category)
5143{
5145 int h, fh, fw, canvas_x, canvas_y;
5147 cairo_t *cr;
5148
5152
5154
5157 cairo_paint(cr);
5158 cairo_destroy(cr);
5159
5160 canvas_x = 0;
5161 canvas_y = 0;
5162
5163 canvas_y += (fh - h);
5164
5165 mapview_layer_iterate(layer) {
5166 if (tileset_layer_in_category(layer, category)) {
5167 put_one_element(&canvas, 1.0, layer,
5168 ptile, NULL, NULL, punit, pcity,
5170 }
5174
5175 return pixbuf;
5176}
5177
5178/************************************************************************/
5182{
5183 if (!pp) {
5184 return;
5185 }
5186
5187 gtk_list_store_clear(pp->object_store);
5188 objbind_hash_clear(pp->objbind_table);
5190}
5191
5192/************************************************************************/
5198{
5199 struct objbind *ob;
5201 int id;
5202
5203 if (!pp) {
5204 return;
5205 }
5206
5209 if (id < 0) {
5210 return;
5211 }
5212
5213 if (objbind_hash_lookup(pp->objbind_table, id, NULL)) {
5214 /* Object already exists. */
5215 return;
5216 }
5217
5219 if (!ob) {
5220 return;
5221 }
5222
5224
5225 objbind_hash_insert(pp->objbind_table, ob->object_id, ob);
5226}
5227
5228/************************************************************************/
5233 const struct tile *ptile)
5234{
5235
5236 if (!pp || !ptile) {
5237 return;
5238 }
5239
5240 switch (property_page_get_objtype(pp)) {
5241 case OBJTYPE_TILE:
5243 return;
5244
5245 case OBJTYPE_STARTPOS:
5246 {
5247 struct startpos *psp = map_startpos_get(ptile);
5248
5249 if (NULL != psp) {
5251 }
5252 }
5253 return;
5254
5255 case OBJTYPE_UNIT:
5256 unit_list_iterate(ptile->units, punit) {
5259 return;
5260
5261 case OBJTYPE_CITY:
5262 if (tile_city(ptile)) {
5264 }
5265 return;
5266
5267 case OBJTYPE_PLAYER:
5268 case OBJTYPE_GAME:
5269 return;
5270
5271 case NUM_OBJTYPES:
5272 break;
5273 }
5274
5275 log_error("%s(): Unhandled page object type %s (nb %d).", __FUNCTION__,
5278}
5279
5280/************************************************************************/
5287 struct objprop *op,
5288 struct objbind *ob,
5290{
5291 int col_id;
5292 struct propval *pv;
5293 enum value_types valtype;
5294 char buf[128], *p;
5296 GtkListStore *store;
5297 gchar *buf2;
5298
5299 if (!pp || !pp->object_store || !op || !ob) {
5300 return FALSE;
5301 }
5302
5304 return FALSE;
5305 }
5306
5308 if (col_id < 0) {
5309 return FALSE;
5310 }
5311
5313 if (!pv) {
5314 return FALSE;
5315 }
5316
5318 store = pp->object_store;
5319
5320 switch (valtype) {
5321 case VALTYPE_NONE:
5322 break;
5323 case VALTYPE_INT:
5324 gtk_list_store_set(store, iter, col_id, pv->data.v_int, -1);
5325 break;
5326 case VALTYPE_BOOL:
5327 /* Set as translated string, not as untranslated G_TYPE_BOOLEAN */
5329 break;
5330 case VALTYPE_STRING:
5331 if (fc_strlcpy(buf, pv->data.v_string, 28) >= 28) {
5332 sz_strlcat(buf, "...");
5333 }
5334 for (p = buf; *p; p++) {
5335 if (*p == '\n' || *p == '\t' || *p == '\r') {
5336 *p = ' ';
5337 }
5338 }
5339 gtk_list_store_set(store, iter, col_id, buf, -1);
5340 break;
5341 case VALTYPE_PIXBUF:
5342 gtk_list_store_set(store, iter, col_id, pv->data.v_pixbuf, -1);
5343 break;
5346 case VALTYPE_BV_SPECIAL:
5347 case VALTYPE_BV_ROADS:
5348 case VALTYPE_BV_BASES:
5351 gtk_list_store_set(store, iter, col_id, buf2, -1);
5352 g_free(buf2);
5353 break;
5354 case VALTYPE_NATION:
5355 pixbuf = get_flag(pv->data.v_nation);
5356 gtk_list_store_set(store, iter, col_id, pixbuf, -1);
5357 if (pixbuf) {
5359 }
5360 break;
5361 case VALTYPE_GOV:
5362 if (pv->data.v_gov != NULL) {
5364 } else {
5367 }
5368 gtk_list_store_set(store, iter, col_id, pixbuf, -1);
5369 if (pixbuf) {
5371 }
5372 break;
5374 break;
5375 }
5376
5378
5379 return TRUE;
5380}
5381
5382/************************************************************************/
5387{
5388 struct objbind *focused;
5389
5390 if (!pp || !pp->objbind_table) {
5391 return;
5392 }
5393
5394 if (pp->object_store) {
5397 GtkTreeModel *model;
5398 GtkTreePath *path;
5399
5400 model = GTK_TREE_MODEL(pp->object_store);
5401
5403 if (objbind_get_rowref(ob)) {
5404 continue;
5405 }
5406 gtk_list_store_append(pp->object_store, &iter);
5407 gtk_list_store_set(pp->object_store, &iter, 0, ob, -1);
5408 path = gtk_tree_model_get_path(model, &iter);
5409 rr = gtk_tree_row_reference_new(model, path);
5410 gtk_tree_path_free(path);
5412
5417
5418 if (gtk_tree_model_get_iter_first(model, &iter)) {
5422 }
5423 }
5424
5429}
5430
5431/************************************************************************/
5436{
5437 if (!pp) {
5438 return NULL;
5439 }
5440 return pp->focused_objbind;
5441}
5442
5443/************************************************************************/
5448 struct objbind *ob)
5449{
5450 if (!pp) {
5451 return;
5452 }
5453 pp->focused_objbind = ob;
5454}
5455
5456/************************************************************************/
5461 int object_id)
5462{
5463 struct objbind *ob;
5464
5465 if (!pp || !pp->objbind_table) {
5466 return NULL;
5467 }
5468
5469 objbind_hash_lookup(pp->objbind_table, object_id, &ob);
5470 return ob;
5471}
5472
5473/************************************************************************/
5478 const struct tile_list *tiles)
5479{
5480 if (!pp || !tiles) {
5481 return;
5482 }
5483
5484 tile_list_iterate(tiles, ptile) {
5487
5489}
5490
5491/************************************************************************/
5495{
5496 if (!pp || !pp->objbind_table) {
5497 return 0;
5498 }
5499 return objbind_hash_size(pp->objbind_table);
5500}
5501
5502/************************************************************************/
5507 struct objprop *op,
5508 struct propval *pv)
5509{
5511 GtkTreeModel *model;
5512 GList *rows, *p;
5513 GtkTreePath *path;
5515 struct objbind *ob;
5516 bool changed = FALSE;
5517
5518 if (!pp || !op || !pp->object_view) {
5519 return;
5520 }
5521
5522 if (objprop_is_readonly(op)) {
5523 return;
5524 }
5525
5528
5529 for (p = rows; p != NULL; p = p->next) {
5530 path = p->data;
5531 if (gtk_tree_model_get_iter(model, &iter, path)) {
5532 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5533 changed |= objbind_set_modified_value(ob, op, pv);
5534 }
5535 gtk_tree_path_free(path);
5536 }
5538
5539 if (changed) {
5542 }
5543}
5544
5545/************************************************************************/
5549{
5551 GtkTreeModel *model;
5552 GList *rows, *p;
5553 GtkTreePath *path;
5555 struct objbind *ob;
5556 union packetdata packet;
5557 struct connection *my_conn = &client.conn;
5558
5559 if (!pp || !pp->object_view) {
5560 return;
5561 }
5562
5565 return;
5566 }
5567
5568 packet = property_page_new_packet(pp);
5569 if (!packet.pointers.v_pointer1) {
5570 return;
5571 }
5572
5575 for (p = rows; p != NULL; p = p->next) {
5576 path = p->data;
5577 if (gtk_tree_model_get_iter(model, &iter, path)) {
5578 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5582 if (objprop_is_readonly(op)) {
5583 continue;
5584 }
5588 }
5589 }
5590 gtk_tree_path_free(path);
5591 }
5594
5596}
5597
5598/************************************************************************/
5603{
5604 union packetdata packet;
5605
5606 packet.pointers.v_pointer2 = NULL;
5607
5608 if (!pp) {
5609 packet.pointers.v_pointer1 = NULL;
5610 return packet;
5611 }
5612
5613 switch (property_page_get_objtype(pp)) {
5614 case OBJTYPE_TILE:
5615 packet.tile = fc_calloc(1, sizeof(*packet.tile));
5616 break;
5617 case OBJTYPE_STARTPOS:
5618 packet.startpos = fc_calloc(1, sizeof(*packet.startpos));
5619 break;
5620 case OBJTYPE_UNIT:
5621 packet.unit = fc_calloc(1, sizeof(*packet.unit));
5622 break;
5623 case OBJTYPE_CITY:
5624 packet.city = fc_calloc(1, sizeof(*packet.city));
5625 break;
5626 case OBJTYPE_PLAYER:
5627 packet.player = fc_calloc(1, sizeof(*packet.player));
5628 break;
5629 case OBJTYPE_GAME:
5630 packet.game.game = fc_calloc(1, sizeof(*packet.game.game));
5631 packet.game.desc = fc_calloc(1, sizeof(*packet.game.desc));
5632 break;
5633 case NUM_OBJTYPES:
5634 break;
5635 }
5636
5637 return packet;
5638}
5639
5640/************************************************************************/
5644 union packetdata packet)
5645{
5646 struct connection *my_conn = &client.conn;
5647
5648 if (!pp || !packet.pointers.v_pointer1) {
5649 return;
5650 }
5651
5652 switch (property_page_get_objtype(pp)) {
5653 case OBJTYPE_TILE:
5655 return;
5656 case OBJTYPE_STARTPOS:
5658 return;
5659 case OBJTYPE_UNIT:
5661 return;
5662 case OBJTYPE_CITY:
5664 return;
5665 case OBJTYPE_PLAYER:
5667 return;
5668 case OBJTYPE_GAME:
5669 send_packet_edit_game(my_conn, packet.game.game);
5671 return;
5672 case NUM_OBJTYPES:
5673 break;
5674 }
5675
5676 log_error("%s(): Unhandled object type %s (nb %d).",
5679}
5680
5681/************************************************************************/
5685 union packetdata packet)
5686{
5687 if (!packet.pointers.v_pointer1) {
5688 return;
5689 }
5690
5691 free(packet.pointers.v_pointer1);
5692 packet.pointers.v_pointer1 = NULL;
5693
5694 if (packet.pointers.v_pointer2 != NULL) {
5695 free(packet.pointers.v_pointer2);
5696 packet.pointers.v_pointer2 = NULL;
5697 }
5698}
5699
5700/************************************************************************/
5705{
5707 GtkTreeModel *model;
5709 GtkTreePath *path;
5710 GList *rows, *p;
5711 struct objbind *ob;
5712
5713 if (!pp || !pp->object_view) {
5714 return;
5715 }
5716
5719 return;
5720 }
5721
5723 for (p = rows; p != NULL; p = p->next) {
5724 path = p->data;
5725 if (gtk_tree_model_get_iter(model, &iter, path)) {
5726 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5731 }
5732 gtk_tree_path_free(path);
5733 }
5735
5740}
5741
5742/************************************************************************/
5746{
5748 GtkTreeModel *model;
5750 GtkTreePath *path;
5751 GList *rows, *p;
5752 struct objbind *ob;
5753 struct connection *my_conn = &client.conn;
5754
5755 if (!pp || !pp->object_view) {
5756 return;
5757 }
5758
5761 return;
5762 }
5763
5766 for (p = rows; p != NULL; p = p->next) {
5767 path = p->data;
5768 if (gtk_tree_model_get_iter(model, &iter, path)) {
5769 gtk_tree_model_get(model, &iter, 0, &ob, -1);
5771 }
5772 gtk_tree_path_free(path);
5773 }
5776}
5777
5778/************************************************************************/
5785 struct tile_list *hint_tiles)
5786{
5788 int apno, value, count, size;
5789 int tag;
5790 struct connection *my_conn = &client.conn;
5791 struct tile *ptile = NULL;
5792 struct player *pplayer;
5793
5794 if (!pp) {
5795 return;
5796 }
5797
5800 return;
5801 }
5802
5803 tag = get_next_unique_tag();
5804 count = 1;
5805
5806 switch (objtype) {
5807 case OBJTYPE_STARTPOS:
5808 if (hint_tiles) {
5810 if (NULL == map_startpos_get(atile)) {
5811 ptile = atile;
5812 break;
5813 }
5815 }
5816
5817 if (NULL == ptile) {
5818 ptile = get_center_tile_mapcanvas();
5819 }
5820
5821 if (NULL == ptile) {
5822 break;
5823 }
5824
5826 break;
5827
5828 case OBJTYPE_UNIT:
5829 if (hint_tiles) {
5832 ptile = atile;
5833 break;
5834 }
5836 }
5837
5838 if (!ptile) {
5839 struct unit *punit;
5843 ptile = unit_tile(punit);
5844 break;
5845 }
5847 }
5848
5849 if (!ptile) {
5850 ptile = get_center_tile_mapcanvas();
5851 }
5852
5853 if (!ptile) {
5854 break;
5855 }
5856
5861 value, count, tag);
5862 break;
5863
5864 case OBJTYPE_CITY:
5866 pplayer = player_by_number(apno);
5867 if (pplayer && hint_tiles) {
5869 if (!is_enemy_unit_tile(atile, pplayer)
5871 ptile = atile;
5872 break;
5873 }
5875 }
5876
5877 if (!ptile) {
5878 ptile = get_center_tile_mapcanvas();
5879 }
5880
5881 if (!ptile) {
5882 break;
5883 }
5884
5887 size, tag);
5888 break;
5889
5890 case OBJTYPE_PLAYER:
5892 break;
5893
5894 case OBJTYPE_TILE:
5895 case OBJTYPE_GAME:
5896 case NUM_OBJTYPES:
5897 break;
5898 }
5899
5901}
5902
5903/************************************************************************/
5909 int object_id,
5910 bool removed)
5911{
5912 struct objbind *ob;
5914
5916 if (!ob) {
5917 return;
5918 }
5919
5922 GtkTreePath *path;
5924 GtkTreeModel *model;
5925
5926 model = GTK_TREE_MODEL(pp->object_store);
5928
5929 if (gtk_tree_model_get_iter(model, &iter, path)) {
5930 if (removed) {
5931 gtk_list_store_remove(pp->object_store, &iter);
5932 } else {
5936 }
5937 }
5938
5939 gtk_tree_path_free(path);
5940 }
5941
5942 if (removed) {
5943 objbind_hash_remove(pp->objbind_table, object_id);
5944 return;
5945 }
5946
5951 }
5952}
5953
5954/************************************************************************/
5961 int tag, int object_id)
5962{
5965
5966 if (!property_page_tag_is_known(pp, tag)) {
5967 return;
5968 }
5970
5973
5974 if (!object) {
5975 return;
5976 }
5977
5980}
5981
5982/************************************************************************/
5987 struct extviewer *ev)
5988{
5989 GtkWidget *w;
5990
5991 if (!pp || !ev) {
5992 return;
5993 }
5994
5996 if (!w) {
5997 return;
5998 }
5999 gtk_notebook_append_page(GTK_NOTEBOOK(pp->extviewer_notebook), w, NULL);
6000}
6001
6002/************************************************************************/
6007 struct extviewer *ev)
6008{
6009 GtkWidget *w;
6010 GtkNotebook *notebook;
6011 int page;
6012
6013 if (!pp || !ev) {
6014 return;
6015 }
6016
6018 if (!w) {
6019 return;
6020 }
6021
6022 notebook = GTK_NOTEBOOK(pp->extviewer_notebook);
6023 page = gtk_notebook_page_num(notebook, w);
6024 gtk_notebook_set_current_page(notebook, page);
6025}
6026
6027/************************************************************************/
6032 int tag, int count)
6033{
6034 if (!pp || !pp->tag_table) {
6035 return;
6036 }
6037
6038 if (stored_tag_hash_lookup(pp->tag_table, tag, NULL)) {
6039 log_error("Attempted to insert object creation tag %d "
6040 "twice into tag table for property page %p (%d %s).",
6043 return;
6044 }
6045
6046 stored_tag_hash_insert(pp->tag_table, tag, count);
6047}
6048
6049/************************************************************************/
6054 int tag)
6055{
6056 int count;
6057
6058 if (!pp || !pp->tag_table) {
6059 return;
6060 }
6061
6062 if (stored_tag_hash_lookup(pp->tag_table, tag, &count)) {
6063 if (0 >= --count) {
6064 stored_tag_hash_remove(pp->tag_table, tag);
6065 }
6066 }
6067}
6068
6069/************************************************************************/
6072static bool property_page_tag_is_known(struct property_page *pp, int tag)
6073{
6074 if (!pp || !pp->tag_table) {
6075 return FALSE;
6076 }
6077 return stored_tag_hash_lookup(pp->tag_table, tag, NULL);
6078}
6079
6080/************************************************************************/
6084{
6085 if (!pp || !pp->tag_table) {
6086 return;
6087 }
6088 stored_tag_hash_clear(pp->tag_table);
6089}
6090
6091/************************************************************************/
6100
6101/************************************************************************/
6111
6112/************************************************************************/
6117{
6118 struct property_page *pp = userdata, *tile_pp;
6119 struct tile_list *tiles = NULL;
6120 struct tile *ptile;
6121
6122 if (!pp) {
6123 return;
6124 }
6125
6127 tiles = tile_list_new();
6128
6130 ptile = objbind_get_object(ob);
6131 if (ptile) {
6132 tile_list_append(tiles, ptile);
6133 }
6135
6137 tile_list_destroy(tiles);
6138}
6139
6140/************************************************************************/
6149
6150/************************************************************************/
6156{
6157 struct property_page *pp;
6158 GtkWidget *label;
6159 const char *name;
6160
6161 if (!pe || !pe->notebook) {
6162 return FALSE;
6163 }
6164
6165 if (!(objtype < NUM_OBJTYPES)) {
6166 return FALSE;
6167 }
6168
6170 if (!pp) {
6171 return FALSE;
6172 }
6173
6175 label = gtk_label_new(name);
6177 pp->widget, label);
6178
6179 pe->property_pages[objtype] = pp;
6180
6181 return TRUE;
6182}
6183
6184/************************************************************************/
6187static struct property_page *
6190{
6191 if (!pe || !(objtype < NUM_OBJTYPES)) {
6192 return NULL;
6193 }
6194
6195 return pe->property_pages[objtype];
6196}
6197
6198/************************************************************************/
6202{
6203 struct property_editor *pe;
6204 GtkWidget *win, *notebook, *vbox;
6206
6207 pe = fc_calloc(1, sizeof(*pe));
6208
6209 /* The property editor dialog window. */
6210
6212 gtk_window_set_title(GTK_WINDOW(win), _("Property Editor"));
6220 g_signal_connect(win, "delete-event",
6222 pe->widget = win;
6223
6224 vbox = gtk_grid_new();
6225 gtk_container_add(GTK_CONTAINER(win), vbox);
6226
6227 /* Property pages. */
6228
6232 pe->notebook = notebook;
6233
6234 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6236 }
6237
6238 return pe;
6239}
6240
6241/************************************************************************/
6251
6252/************************************************************************/
6256 const struct tile_list *tiles)
6257{
6258 struct property_page *pp;
6260 int i;
6261 const enum editor_object_type preferred[] = {
6266 };
6267
6268 if (!pe || !tiles) {
6269 return;
6270 }
6271
6272 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6275 }
6276
6277 for (i = 0; i < ARRAY_SIZE(preferred) - 1; i++) {
6280 break;
6281 }
6282 }
6283 objtype = preferred[i];
6285}
6286
6287/************************************************************************/
6293{
6294 if (!pe || !pe->widget) {
6295 return;
6296 }
6297
6298 gtk_widget_show_all(pe->widget);
6299
6301 if (objtype < NUM_OBJTYPES) {
6303 }
6304}
6305
6306/************************************************************************/
6310{
6311 if (!pe || !pe->widget) {
6312 return;
6313 }
6314 gtk_widget_hide(pe->widget);
6315}
6316
6317/************************************************************************/
6323 int object_id,
6324 bool remove)
6325{
6326 struct property_page *pp;
6327
6328 if (!pe) {
6329 return;
6330 }
6331
6332 if (!(objtype < NUM_OBJTYPES)) {
6333 return;
6334 }
6335
6338}
6339
6340/************************************************************************/
6344 int tag, int object_id)
6345{
6347 struct property_page *pp;
6348
6349 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6351 continue;
6352 }
6354 property_page_object_created(pp, tag, object_id);
6355 }
6356}
6357
6358/************************************************************************/
6362{
6364 struct property_page *pp;
6365
6366 if (!pe) {
6367 return;
6368 }
6369
6370 for (objtype = 0; objtype < NUM_OBJTYPES; objtype++) {
6374 }
6375}
6376
6377/************************************************************************/
6383{
6384 struct property_page *pp;
6385
6386 if (!pe) {
6387 return;
6388 }
6389
6391 if (!pp) {
6392 return;
6393 }
6394
6396
6397 switch (objtype) {
6398 case OBJTYPE_PLAYER:
6399 players_iterate(pplayer) {
6400 property_page_add_objbind(pp, pplayer);
6402 break;
6403 case OBJTYPE_GAME:
6405 break;
6406 case OBJTYPE_TILE:
6407 case OBJTYPE_STARTPOS:
6408 case OBJTYPE_UNIT:
6409 case OBJTYPE_CITY:
6410 case NUM_OBJTYPES:
6411 break;
6412 }
6413
6416}
6417
6418/************************************************************************/
6429static struct property_filter *property_filter_new(const char *filter)
6430{
6431 struct property_filter *pf;
6432 struct pf_conjunction *pfc;
6433 struct pf_pattern *pfp;
6436 const char *pattern;
6437 int i, j;
6438
6439 pf = fc_calloc(1, sizeof(*pf));
6440
6441 if (!filter || filter[0] == '\0') {
6442 return pf;
6443 }
6444
6448
6449 for (i = 0; i < or_clause_count; i++) {
6450 if (or_clauses[i][0] == '\0') {
6451 continue;
6452 }
6453 pfc = &pf->disjunction[pf->count];
6454
6458
6459 for (j = 0; j < and_clause_count; j++) {
6460 if (and_clauses[j][0] == '\0') {
6461 continue;
6462 }
6463 pfp = &pfc->conjunction[pfc->count];
6464 pattern = and_clauses[j];
6465
6466 switch (pattern[0]) {
6467 case '!':
6468 pfp->negate = TRUE;
6469 pfp->text = fc_strdup(pattern + 1);
6470 break;
6471 default:
6472 pfp->text = fc_strdup(pattern);
6473 break;
6474 }
6475 pfc->count++;
6476 }
6478 pf->count++;
6479 }
6480
6482
6483 return pf;
6484}
6485
6486/************************************************************************/
6504 const struct objprop *op)
6505{
6506 struct pf_pattern *pfp;
6507 struct pf_conjunction *pfc;
6508 const char *name;
6509 bool match, or_result, and_result;
6510 int i, j;
6511
6512 if (!pf) {
6513 return TRUE;
6514 }
6515 if (!op) {
6516 return FALSE;
6517 }
6518
6520 if (!name) {
6521 return FALSE;
6522 }
6523
6524 if (pf->count < 1) {
6525 return TRUE;
6526 }
6527
6528 or_result = FALSE;
6529
6530 for (i = 0; i < pf->count; i++) {
6531 pfc = &pf->disjunction[i];
6532 and_result = TRUE;
6533 for (j = 0; j < pfc->count; j++) {
6534 pfp = &pfc->conjunction[j];
6535 match = (pfp->text[0] == '\0'
6536 || fc_strcasestr(name, pfp->text));
6537 if (pfp->negate) {
6538 match = !match;
6539 }
6540 and_result = and_result && match;
6541 if (!and_result) {
6542 break;
6543 }
6544 }
6546 if (or_result) {
6547 break;
6548 }
6549 }
6550
6551 return or_result;
6552}
6553
6554/************************************************************************/
6558{
6559 struct pf_pattern *pfp;
6560 struct pf_conjunction *pfc;
6561 int i, j;
6562
6563 if (!pf) {
6564 return;
6565 }
6566
6567 for (i = 0; i < pf->count; i++) {
6568 pfc = &pf->disjunction[i];
6569 for (j = 0; j < pfc->count; j++) {
6570 pfp = &pfc->conjunction[j];
6571 if (pfp->text != NULL) {
6572 free(pfp->text);
6573 pfp->text = NULL;
6574 }
6575 }
6576 pfc->count = 0;
6577 }
6578 pf->count = 0;
6579 free(pf);
6580}
6581
6582/************************************************************************/
6586{
6587 switch (vl) {
6588 case V_MAIN:
6589 /* TRANS: Vision layer name. Feel free to leave untranslated. */
6590 return _("Seen (Main)");
6591 case V_INVIS:
6592 /* TRANS: Vision layer name. Feel free to leave untranslated. */
6593 return _("Seen (Invis)");
6594 case V_SUBSURFACE:
6595 /* TRANS: Vision layer name. Feel free to leave untranslated. */
6596 return _("Seen (Subsurface)");
6597 case V_COUNT:
6598 break;
6599 }
6600
6601 log_error("%s(): Unrecognized vision layer %d.", __FUNCTION__, vl);
6602 return _("Unknown");
6603}
Base_type_id base_number(const struct base_type *pbase)
Definition base.c:92
Base_type_id base_count(void)
Definition base.c:109
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ARE_EQUAL(vec1, vec2)
Definition bitvector.h:113
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
int city_granary_size(int city_size)
Definition city.c:2132
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1487
#define city_tile(_pcity_)
Definition city.h:564
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define city_owner(_pcity_)
Definition city.h:563
#define MAX_CITY_SIZE
Definition city.h:106
#define I_DESTROYED
Definition city.h:248
#define I_NEVER
Definition city.h:247
struct civclient client
bool client_nation_is_in_current_set(const struct nation_type *pnation)
Definition climisc.c:1508
char * incite_cost
Definition comments.c:75
void connection_do_buffer(struct connection *pc)
Definition connection.c:324
void connection_do_unbuffer(struct connection *pc)
Definition connection.c:336
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 * punit
Definition dialogs_g.h:74
int objtype
Definition editgui_g.h:28
int int id
Definition editgui_g.h:28
int editor_tool_get_size(enum editor_tool_type ett)
Definition editor.c:1218
int editor_tool_get_value(enum editor_tool_type ett)
Definition editor.c:409
int editor_tool_get_count(enum editor_tool_type ett)
Definition editor.c:1252
struct unit * editor_unit_virtual_create(void)
Definition editor.c:1405
int editor_tool_get_applied_player(enum editor_tool_type ett)
Definition editor.c:1341
editor_object_type
Definition editor.h:25
@ OBJTYPE_PLAYER
Definition editor.h:30
@ OBJTYPE_UNIT
Definition editor.h:28
@ OBJTYPE_STARTPOS
Definition editor.h:27
@ OBJTYPE_GAME
Definition editor.h:31
@ NUM_OBJTYPES
Definition editor.h:33
@ OBJTYPE_CITY
Definition editor.h:29
@ OBJTYPE_TILE
Definition editor.h:26
@ ETT_UNIT
Definition editor.h:42
@ ETT_CITY
Definition editor.h:43
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Definition extras.c:249
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define extra_index(_e_)
Definition extras.h:183
#define extra_base_get(_e_)
Definition extras.h:190
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
void free_tokens(char **tokens, size_t ntokens)
Definition fc_cmdline.c:203
int get_tokens(const char *str, char **tokens, size_t num_tokens, const char *delimiterset)
Definition fc_cmdline.c:166
const struct functions * fc_funcs
#define EC_SPECIAL
Definition fc_types.h:1114
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:116
struct city * game_city_by_number(int id)
Definition game.c:107
const char * government_name_translation(const struct government *pgovern)
Definition government.c:143
Government_type_id government_count(void)
Definition government.c:71
struct government * government_by_number(const Government_type_id gov)
Definition government.c:103
Government_type_id government_index(const struct government *pgovern)
Definition government.c:82
#define governments_iterate(NAME_pgov)
Definition government.h:124
#define governments_iterate_end
Definition government.h:127
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:28
static void add_column(GtkWidget *view, int col_id, const char *name, GType gtype, bool editable, bool is_radio, GCallback edit_callback, gpointer callback_userdata)
Definition editprop.c:820
static void property_page_reset_objbinds(struct property_page *pp)
Definition editprop.c:5704
static void property_page_send_values(struct property_page *pp)
Definition editprop.c:5548
static void objprop_setup_widget(struct objprop *op)
Definition editprop.c:2953
static void property_page_store_creation_tag(struct property_page *pp, int tag, int count)
Definition editprop.c:6031
static gchar * propval_as_string(struct propval *pv)
Definition editprop.c:862
static struct property_page * objprop_get_property_page(const struct objprop *op)
Definition editprop.c:3465
static const char * objprop_get_name(const struct objprop *op)
Definition editprop.c:2833
const char * vision_layer_get_name(enum vision_layer)
Definition editprop.c:6585
static int objbind_get_object_id(struct objbind *ob)
Definition editprop.c:1381
static void objprop_set_extviewer(struct objprop *op, struct extviewer *ev)
Definition editprop.c:3442
static GtkWidget * extviewer_get_panel_widget(struct extviewer *ev)
Definition editprop.c:3797
static gpointer objtype_get_object_from_id(enum editor_object_type objtype, int id)
Definition editprop.c:725
void property_editor_handle_object_changed(struct property_editor *pe, enum editor_object_type objtype, int object_id, bool remove)
Definition editprop.c:6321
static struct propstate * propstate_new(struct objprop *op, struct propval *pv)
Definition editprop.c:1265
static const char * valtype_get_name(enum value_types valtype)
Definition editprop.c:779
static void propstate_destroy(struct propstate *ps)
Definition editprop.c:1297
static bool objbind_set_modified_value(struct objbind *ob, struct objprop *op, struct propval *pv)
Definition editprop.c:2129
static GtkCellRenderer * objprop_create_cell_renderer(const struct objprop *op)
Definition editprop.c:2857
static void extviewer_clear_widgets(struct extviewer *ev)
Definition editprop.c:4090
value_types
Definition editprop.c:197
@ VALTYPE_STRING
Definition editprop.c:201
@ VALTYPE_BV_SPECIAL
Definition editprop.c:205
@ VALTYPE_BV_BASES
Definition editprop.c:207
@ VALTYPE_INT
Definition editprop.c:199
@ VALTYPE_INVENTIONS_ARRAY
Definition editprop.c:204
@ VALTYPE_BV_ROADS
Definition editprop.c:206
@ VALTYPE_PIXBUF
Definition editprop.c:202
@ VALTYPE_TILE_VISION_DATA
Definition editprop.c:211
@ VALTYPE_NONE
Definition editprop.c:198
@ VALTYPE_NATION_HASH
Definition editprop.c:209
@ VALTYPE_BOOL
Definition editprop.c:200
@ VALTYPE_NATION
Definition editprop.c:208
@ VALTYPE_GOV
Definition editprop.c:210
@ VALTYPE_BUILT_ARRAY
Definition editprop.c:203
static void objprop_set_child_widget(struct objprop *op, const char *widget_name, GtkWidget *widget)
Definition editprop.c:3382
static bool property_editor_add_page(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6154
static void propstate_clear_value(struct propstate *ps)
Definition editprop.c:1284
static void objbind_pack_modified_value(struct objbind *ob, struct objprop *op, union packetdata packet)
Definition editprop.c:2381
static struct objbind * property_page_get_focused_objbind(struct property_page *pp)
Definition editprop.c:5435
static bool objprop_has_widget(const struct objprop *op)
Definition editprop.c:2746
static int objtype_get_id_from_object(enum editor_object_type objtype, gpointer object)
Definition editprop.c:696
static enum editor_object_type objbind_get_objtype(const struct objbind *ob)
Definition editprop.c:2213
static struct extviewer * objprop_get_extviewer(struct objprop *op)
Definition editprop.c:3454
static void extviewer_refresh_widgets(struct extviewer *ev, struct propval *pv)
Definition editprop.c:3820
static enum editor_object_type property_page_get_objtype(const struct property_page *pp)
Definition editprop.c:5085
#define property_page_objbind_iterate_end
Definition editprop.c:641
static void property_page_show_extviewer(struct property_page *pp, struct extviewer *ev)
Definition editprop.c:6006
static gpointer objbind_get_object(struct objbind *ob)
Definition editprop.c:1365
static const char * property_page_get_name(const struct property_page *pp)
Definition editprop.c:5073
void property_editor_handle_object_created(struct property_editor *pe, int tag, int object_id)
Definition editprop.c:6343
static bool objbind_property_is_modified(struct objbind *ob, struct objprop *op)
Definition editprop.c:2084
static struct propval * propstate_get_value(struct propstate *ps)
Definition editprop.c:1327
static void property_page_clear_tags(struct property_page *pp)
Definition editprop.c:6083
static void property_page_object_created(struct property_page *pp, int tag, int object_id)
Definition editprop.c:5960
static bool property_page_tag_is_known(struct property_page *pp, int tag)
Definition editprop.c:6072
static void property_page_remove_creation_tag(struct property_page *pp, int tag)
Definition editprop.c:6053
static void property_page_load_tiles(struct property_page *pp, const struct tile_list *tiles)
Definition editprop.c:5477
static void property_page_create_objects(struct property_page *pp, struct tile_list *hint_tiles)
Definition editprop.c:5784
static void property_page_add_extviewer(struct property_page *pp, struct extviewer *ev)
Definition editprop.c:5986
static void property_page_refresh_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6105
static void property_page_set_focused_objbind(struct property_page *pp, struct objbind *ob)
Definition editprop.c:5447
static void property_page_setup_objprops(struct property_page *pp)
Definition editprop.c:4435
static void objbind_set_rowref(struct objbind *ob, GtkTreeRowReference *rr)
Definition editprop.c:2653
object_property_flags
Definition editprop.c:384
@ OPF_IN_LISTVIEW
Definition editprop.c:387
@ OPF_EDITABLE
Definition editprop.c:386
@ OPF_HAS_WIDGET
Definition editprop.c:388
@ OPF_NO_FLAGS
Definition editprop.c:385
static void objbind_clear_modified_value(struct objbind *ob, struct objprop *op)
Definition editprop.c:2070
static struct propval * objbind_get_value_from_object(struct objbind *ob, struct objprop *op)
Definition editprop.c:1442
static void propval_free(struct propval *pv)
Definition editprop.c:1127
static struct property_filter * property_filter_new(const char *filter)
Definition editprop.c:6429
static bool property_page_set_store_value(struct property_page *pp, struct objprop *op, struct objbind *ob, GtkTreeIter *iter)
Definition editprop.c:5286
static const char * objtype_get_name(enum editor_object_type objtype)
Definition editprop.c:667
static void objprop_widget_entry_changed(GtkEntry *entry, gpointer userdata)
Definition editprop.c:2903
static void objbind_clear_all_modified_values(struct objbind *ob)
Definition editprop.c:2115
static bool property_filter_match(struct property_filter *pf, const struct objprop *op)
Definition editprop.c:6503
void property_editor_popup(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6291
static void property_page_destroy_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6143
static struct objbind * objbind_new(enum editor_object_type objtype, gpointer object)
Definition editprop.c:1339
static gboolean property_page_selection_func(GtkTreeSelection *sel, GtkTreeModel *model, GtkTreePath *path, gboolean currently_selected, gpointer data)
Definition editprop.c:4670
static int property_page_get_num_objbinds(const struct property_page *pp)
Definition editprop.c:5494
static bool objprop_show_in_listview(const struct objprop *op)
Definition editprop.c:2735
static GType objprop_get_gtype(const struct objprop *op)
Definition editprop.c:2691
static void objprop_set_treeview_column(struct objprop *op, GtkTreeViewColumn *col)
Definition editprop.c:2809
static void objbind_pack_current_values(struct objbind *ob, union packetdata packet)
Definition editprop.c:2238
static const char * objprop_get_attribute_type_string(const struct objprop *op)
Definition editprop.c:2760
static struct propval * propval_copy(struct propval *pv)
Definition editprop.c:1045
struct property_editor * editprop_get_property_editor(void)
Definition editprop.c:6244
void property_editor_reload(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6381
static GdkPixbuf * create_unit_pixbuf(const struct unit *punit)
Definition editprop.c:5113
static void extviewer_view_cell_toggled(GtkCellRendererToggle *cell, gchar *path, gpointer userdata)
Definition editprop.c:4165
static struct property_editor * property_editor_new(void)
Definition editprop.c:6201
static void property_page_send_packet(struct property_page *pp, union packetdata packet)
Definition editprop.c:5643
static gchar * built_status_to_string(struct built_status *bs)
Definition editprop.c:981
static int objprop_get_id(const struct objprop *op)
Definition editprop.c:2676
object_property_ids
Definition editprop.c:305
@ OPID_STARTPOS_IMAGE
Definition editprop.c:325
@ OPID_TILE_Y
Definition editprop.c:308
@ OPID_TILE_BASES
Definition editprop.c:321
@ OPID_CITY_XY
Definition editprop.c:351
@ OPID_UNIT_ID
Definition editprop.c:335
@ OPID_CITY_BUILDINGS
Definition editprop.c:354
@ OPID_CITY_NAME
Definition editprop.c:346
@ OPID_TILE_NAT_Y
Definition editprop.c:310
@ OPID_CITY_SIZE
Definition editprop.c:352
@ OPID_UNIT_VETERAN
Definition editprop.c:342
@ OPID_CITY_IMAGE
Definition editprop.c:345
@ OPID_CITY_SHIELD_STOCK
Definition editprop.c:356
@ OPID_PLAYER_NAME
Definition editprop.c:358
@ OPID_PLAYER_AGE
Definition editprop.c:361
@ OPID_STARTPOS_NATIONS
Definition editprop.c:328
@ OPID_GAME_LAKE_FLOODING
Definition editprop.c:380
@ OPID_UNIT_IMAGE
Definition editprop.c:330
@ OPID_TILE_TERRAIN
Definition editprop.c:315
@ OPID_TILE_SPECIALS
Definition editprop.c:319
@ OPID_TILE_RESOURCE
Definition editprop.c:318
@ OPID_TILE_IMAGE
Definition editprop.c:306
@ OPID_TILE_VISION
Definition editprop.c:322
@ OPID_PLAYER_INVENTIONS
Definition editprop.c:365
@ OPID_GAME_SCENARIO_NAME
Definition editprop.c:373
@ OPID_PLAYER_SCIENCE
Definition editprop.c:368
@ OPID_TILE_CONTINENT
Definition editprop.c:311
@ OPID_CITY_HISTORY
Definition editprop.c:353
@ OPID_TILE_XY
Definition editprop.c:317
@ OPID_GAME_SCENARIO_AUTHORS
Definition editprop.c:374
@ OPID_PLAYER_SELECT_WEIGHT
Definition editprop.c:367
@ OPID_TILE_X
Definition editprop.c:307
@ OPID_TILE_NAT_X
Definition editprop.c:309
@ OPID_PLAYER_NATION
Definition editprop.c:359
@ OPID_GAME_PREVENT_CITIES
Definition editprop.c:379
@ OPID_STARTPOS_XY
Definition editprop.c:326
@ OPID_UNIT_MOVED
Definition editprop.c:339
@ OPID_TILE_LABEL
Definition editprop.c:323
@ OPID_CITY_FOOD_STOCK
Definition editprop.c:355
@ OPID_UNIT_DONE_MOVING
Definition editprop.c:340
@ OPID_UNIT_MOVES_LEFT
Definition editprop.c:337
@ OPID_GAME_SCENARIO_DESC
Definition editprop.c:375
@ OPID_GAME_STARTPOS_NATIONS
Definition editprop.c:378
@ OPID_UNIT_HP
Definition editprop.c:341
@ OPID_UNIT_FUEL
Definition editprop.c:338
@ OPID_PLAYER_SCENARIO_RESERVED
Definition editprop.c:366
@ OPID_TILE_ROADS
Definition editprop.c:320
@ OPID_PLAYER_GOLD
Definition editprop.c:369
@ OPID_CITY_ID
Definition editprop.c:350
@ OPID_GAME_SCENARIO_RANDSTATE
Definition editprop.c:376
@ OPID_PLAYER_INFRAPOINTS
Definition editprop.c:370
@ OPID_GAME_SCENARIO_PLAYERS
Definition editprop.c:377
@ OPID_UNIT_STAY
Definition editprop.c:343
@ OPID_PLAYER_GOV
Definition editprop.c:360
@ OPID_STARTPOS_EXCLUDE
Definition editprop.c:327
@ OPID_UNIT_TYPE
Definition editprop.c:334
@ OPID_GAME_SCENARIO
Definition editprop.c:372
@ OPID_GAME_RULESET_LOCKED
Definition editprop.c:381
@ OPID_UNIT_XY
Definition editprop.c:336
@ OPID_TILE_INDEX
Definition editprop.c:316
static enum value_types objprop_get_valtype(const struct objprop *op)
Definition editprop.c:2724
static int get_next_unique_tag(void)
Definition editprop.c:1034
static bool objprop_is_sortable(const struct objprop *op)
Definition editprop.c:2878
static void property_page_add_objbinds_from_tile(struct property_page *pp, const struct tile *ptile)
Definition editprop.c:5232
static const char * objprop_get_tooltip(const struct objprop *op)
Definition editprop.c:2844
static GtkTreeRowReference * objbind_get_rowref(struct objbind *ob)
Definition editprop.c:2665
static void property_filter_free(struct property_filter *pf)
Definition editprop.c:6557
static void objprop_widget_spin_button_changed(GtkSpinButton *spin, gpointer userdata)
Definition editprop.c:2919
#define PF_DISJUNCTION_SEPARATOR
Definition editprop.c:119
static GtkWidget * objprop_get_child_widget(struct objprop *op, const char *widget_name)
Definition editprop.c:3409
static void property_page_selection_changed(GtkTreeSelection *sel, gpointer userdata)
Definition editprop.c:4645
static bool objtype_is_conserved(enum editor_object_type objtype)
Definition editprop.c:756
static struct extviewer * extviewer_new(struct objprop *op)
Definition editprop.c:3501
static bool propval_equal(struct propval *pva, struct propval *pvb)
Definition editprop.c:1178
static void property_page_quick_find_entry_changed(GtkWidget *entry, gpointer userdata)
Definition editprop.c:4725
static void objprop_refresh_widget(struct objprop *op, struct objbind *ob)
Definition editprop.c:3131
#define PF_MAX_CLAUSES
Definition editprop.c:118
void property_editor_popdown(struct property_editor *pe)
Definition editprop.c:6309
static void objbind_destroy(struct objbind *ob)
Definition editprop.c:2194
static void property_page_add_objbind(struct property_page *pp, gpointer object_data)
Definition editprop.c:5196
static void objbind_request_destroy_object(struct objbind *ob)
Definition editprop.c:1394
static void property_page_create_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6115
static GdkPixbuf * create_pixbuf_from_layers(const struct tile *ptile, const struct unit *punit, const struct city *pcity, enum layer_category category)
Definition editprop.c:5139
static union packetdata property_page_new_packet(struct property_page *pp)
Definition editprop.c:5602
static void propstate_set_value(struct propstate *ps, struct propval *pv)
Definition editprop.c:1312
static int objprop_get_column_id(const struct objprop *op)
Definition editprop.c:2798
static GdkPixbuf * create_tile_pixbuf(const struct tile *ptile)
Definition editprop.c:5101
static struct objprop * extviewer_get_objprop(struct extviewer *ev)
Definition editprop.c:3785
static bool can_create_unit_at_tile(struct tile *ptile)
Definition editprop.c:1002
static struct objbind * property_page_get_objbind(struct property_page *pp, int object_id)
Definition editprop.c:5460
static bool objbind_get_allowed_value_span(struct objbind *ob, struct objprop *op, double *pmin, double *pmax, double *pstep, double *pbig_step)
Definition editprop.c:1883
static void property_page_free_packet(struct property_page *pp, union packetdata packet)
Definition editprop.c:5684
static GdkPixbuf * create_city_pixbuf(const struct city *pcity)
Definition editprop.c:5125
#define ADDPROP(ARG_id, ARG_name, ARG_tooltip, ARG_flags, ARG_valtype)
static void extviewer_panel_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:4145
static void property_page_destroy_objects(struct property_page *pp)
Definition editprop.c:5745
void property_editor_load_tiles(struct property_editor *pe, const struct tile_list *tiles)
Definition editprop.c:6255
static struct property_page * property_page_new(enum editor_object_type objtype, struct property_editor *parent)
Definition editprop.c:4767
#define property_page_objprop_iterate_end
Definition editprop.c:637
static void property_page_clear_objbinds(struct property_page *pp)
Definition editprop.c:5181
void property_editor_clear(struct property_editor *pe)
Definition editprop.c:6361
#define property_page_objprop_iterate(ARG_pp, NAME_op)
Definition editprop.c:635
static void objprop_set_column_id(struct objprop *op, int col_id)
Definition editprop.c:2785
static void objbind_bind_properties(struct objbind *ob, struct property_page *pp)
Definition editprop.c:2224
static void property_page_fill_widgets(struct property_page *pp)
Definition editprop.c:5386
static bool objbind_has_modified_properties(struct objbind *ob)
Definition editprop.c:2103
static void property_page_change_value(struct property_page *pp, struct objprop *op, struct propval *pv)
Definition editprop.c:5506
static void objprop_widget_toggle_button_changed(GtkToggleButton *button, gpointer userdata)
Definition editprop.c:2936
#define PF_CONJUNCTION_SEPARATOR
Definition editprop.c:120
static void property_page_apply_button_clicked(GtkButton *button, gpointer userdata)
Definition editprop.c:6094
static struct objprop * objprop_new(int id, const char *name, const char *tooltip, enum object_property_flags flags, enum value_types valtype, struct property_page *parent)
Definition editprop.c:3476
static GtkWidget * extviewer_get_view_widget(struct extviewer *ev)
Definition editprop.c:3809
static GtkWidget * objprop_get_widget(struct objprop *op)
Definition editprop.c:3367
static void propval_free_data(struct propval *pv)
Definition editprop.c:1141
static void extviewer_textbuf_changed(GtkTextBuffer *textbuf, gpointer userdata)
Definition editprop.c:4386
static struct property_editor * the_property_editor
Definition editprop.c:661
static void property_page_object_changed(struct property_page *pp, int object_id, bool remove)
Definition editprop.c:5908
static bool objprop_is_readonly(const struct objprop *op)
Definition editprop.c:2892
#define property_page_objbind_iterate(ARG_pp, NAME_ob)
Definition editprop.c:639
static GtkTreeViewColumn * objprop_get_treeview_column(const struct objprop *op)
Definition editprop.c:2822
static struct property_page * property_editor_get_page(struct property_editor *pe, enum editor_object_type objtype)
Definition editprop.c:6188
static struct propval * objbind_get_modified_value(struct objbind *ob, struct objprop *op)
Definition editprop.c:2175
GtkWidget * toplevel
Definition gui_main.c:125
void disable_gobject_callback(GObject *obj, GCallback cb)
Definition gui_stuff.c:1090
void enable_gobject_callback(GObject *obj, GCallback cb)
Definition gui_stuff.c:1106
GdkPixbuf * get_flag(const struct nation_type *nation)
Definition plrdlg.c:607
const char * tooltip
Definition repodlgs.c:1315
const char * title
Definition repodlgs.c:1314
GdkPixbuf * surface_get_pixbuf(cairo_surface_t *surf, int width, int height)
Definition sprite.c:418
GdkPixbuf * sprite_get_pixbuf(struct sprite *sprite)
Definition sprite.c:402
value_types
Definition editprop.c:197
object_property_flags
Definition editprop.c:384
#define PF_MAX_CLAUSES
Definition editprop.c:118
bool is_special_improvement(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
const char * name
Definition inputfile.c:127
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_error(message,...)
Definition log.h:103
struct startpos * map_startpos_get(const struct tile *ptile)
Definition map.c:1883
int startpos_number(const struct startpos *psp)
Definition map.c:1633
#define nat_x
#define nat_y
struct tile * startpos_tile(const struct startpos *psp)
Definition map.c:1676
const struct nation_hash * startpos_raw_nations(const struct startpos *psp)
Definition map.c:1765
bool startpos_pack(const struct startpos *psp, struct packet_edit_startpos_full *packet)
Definition map.c:1706
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:456
bool startpos_is_excluding(const struct startpos *psp)
Definition map.c:1753
struct startpos * map_startpos_by_number(int id)
Definition map.c:1624
#define index_to_native_pos(pnat_x, pnat_y, mindex)
Definition map.h:157
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:233
struct tile * get_center_tile_mapcanvas(void)
void put_one_element(struct canvas *pcanvas, float zoom, enum mapview_layer layer, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner, const struct unit *punit, const struct city *pcity, int canvas_x, int canvas_y, const struct city *citymode, const struct unit_type *putype)
#define fc_calloc(n, esz)
Definition mem.h:38
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:319
#define MAX_MOVE_FRAGS
Definition movement.h:29
Nation_type_id nation_count(void)
Definition nation.c:507
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:486
const char * nation_adjective_translation(const struct nation_type *pnation)
Definition nation.c:149
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:475
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:200
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:498
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:211
#define nation_hash_iterate(nationhash, pnation)
Definition nation.h:93
#define nations_iterate_end
Definition nation.h:336
#define nations_iterate(NAME_pnation)
Definition nation.h:333
#define nation_hash_iterate_end
Definition nation.h:95
int dsend_packet_edit_city_create(struct connection *pc, int owner, int tile, int size, int tag)
int send_packet_edit_city(struct connection *pc, const struct packet_edit_city *packet)
int send_packet_edit_game(struct connection *pc, const struct packet_edit_game *packet)
int send_packet_edit_startpos_full(struct connection *pc, const struct packet_edit_startpos_full *packet)
int dsend_packet_edit_startpos(struct connection *pc, int id, bool removal, int tag)
int send_packet_edit_player(struct connection *pc, const struct packet_edit_player *packet)
int dsend_packet_edit_player_create(struct connection *pc, int tag)
int send_packet_edit_unit(struct connection *pc, const struct packet_edit_unit *packet)
int send_packet_edit_scenario_desc(struct connection *pc, const struct packet_edit_scenario_desc *packet)
int dsend_packet_edit_unit_remove_by_id(struct connection *pc, int id)
int dsend_packet_edit_unit_create(struct connection *pc, int owner, int tile, Unit_type_id type, int count, int tag)
int dsend_packet_edit_player_remove(struct connection *pc, int id)
int send_packet_edit_tile(struct connection *pc, const struct packet_edit_tile *packet)
int dsend_packet_edit_city_remove(struct connection *pc, int id)
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:448
struct player * player_by_number(const int player_id)
Definition player.c:849
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1990
int player_index(const struct player *pplayer)
Definition player.c:829
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
#define players_iterate_end
Definition player.h:537
#define players_iterate(_pplayer)
Definition player.h:532
#define player_slots_iterate(_pslot)
Definition player.h:523
#define player_slots_iterate_end
Definition player.h:527
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
Road_type_id road_count(void)
Definition road.c:50
Road_type_id road_number(const struct road_type *proad)
Definition road.c:32
#define ARRAY_SIZE(x)
Definition shared.h:85
int step
Definition specpq.h:92
size_t size
Definition specvec.h:72
int turn
Definition city.h:246
cairo_surface_t * surface
Definition canvas.h:23
Definition city.h:320
int food_stock
Definition city.h:367
struct built_status built[B_LAST]
Definition city.h:394
int history
Definition city.h:410
int id
Definition city.h:326
char * name
Definition city.h:321
int shield_stock
Definition city.h:368
struct packet_game_info info
Definition game.h:89
struct government * government_during_revolution
Definition game.h:94
struct connection conn
Definition client_main.h:96
GtkWidget * view_widget
Definition editprop.c:523
GtkWidget * panel_button
Definition editprop.c:520
GtkWidget * view_label
Definition editprop.c:524
GtkWidget * panel_image
Definition editprop.c:521
GtkTextBuffer * textbuf
Definition editprop.c:527
struct objprop * objprop
Definition editprop.c:515
GtkWidget * panel_label
Definition editprop.c:519
struct propval * pv_cached
Definition editprop.c:516
GtkListStore * store
Definition editprop.c:526
GtkWidget * panel_widget
Definition editprop.c:518
bool(* player_tile_vision_get)(const struct tile *ptile, const struct player *pplayer, enum vision_layer vision)
int object_id
Definition editprop.c:460
struct propstate_hash * propstate_table
Definition editprop.c:462
struct property_page * parent_property_page
Definition editprop.c:461
GtkTreeRowReference * rowref
Definition editprop.c:463
enum editor_object_type objtype
Definition editprop.c:459
const char * name
Definition editprop.c:393
const char * tooltip
Definition editprop.c:394
GtkWidget * widget
Definition editprop.c:399
struct property_page * parent_page
Definition editprop.c:401
enum object_property_flags flags
Definition editprop.c:395
struct extviewer * extviewer
Definition editprop.c:400
int id
Definition editprop.c:392
enum value_types valtype
Definition editprop.c:396
int column_id
Definition editprop.c:397
GtkTreeViewColumn * view_column
Definition editprop.c:398
int built[B_LAST]
char name[MAX_LEN_CITYNAME]
char scenario_name[256]
char scenario_authors[MAX_LEN_PACKET/3]
Nation_type_id nation
char name[MAX_LEN_NAME]
Government_type_id government
bool inventions[A_LAST+1]
bv_startpos_nations nations
char label[MAX_LEN_NAME]
struct pf_pattern conjunction[PF_MAX_CLAUSES]
Definition editprop.c:128
char * text
Definition editprop.c:124
bool negate
Definition editprop.c:123
int infra_points
Definition player.h:65
int autoselect_weight
Definition player.h:297
struct government * government
Definition player.h:256
int turns_alive
Definition player.h:264
struct player_economic economic
Definition player.h:282
char name[MAX_LEN_NAME]
Definition player.h:249
struct nation_type * nation
Definition player.h:258
GtkWidget * notebook
Definition editprop.c:649
struct property_page * property_pages[NUM_OBJTYPES]
Definition editprop.c:651
GtkWidget * widget
Definition editprop.c:648
struct pf_conjunction disjunction[PF_MAX_CLAUSES]
Definition editprop.c:133
GtkListStore * object_store
Definition editprop.c:553
struct property_editor * pe_parent
Definition editprop.c:557
GtkWidget * extviewer_notebook
Definition editprop.c:555
GtkWidget * widget
Definition editprop.c:552
struct objbind_hash * objbind_table
Definition editprop.c:560
GtkWidget * object_view
Definition editprop.c:554
struct objbind * focused_objbind
Definition editprop.c:563
struct stored_tag_hash * tag_table
Definition editprop.c:561
enum editor_object_type objtype
Definition editprop.c:550
struct objprop_hash * objprop_table
Definition editprop.c:559
struct propval * property_value
Definition editprop.c:256
int property_id
Definition editprop.c:255
union propval_data data
Definition editprop.c:244
enum value_types valtype
Definition editprop.c:245
bool must_free
Definition editprop.c:246
Definition map.c:41
bv_player tile_known
Definition editprop.c:114
bv_player tile_seen[V_COUNT]
Definition editprop.c:114
Definition tile.h:50
char * label
Definition tile.h:65
Continent_id continent
Definition tile.h:54
Definition unit.h:138
int moves_left
Definition unit.h:150
int id
Definition unit.h:145
bool moved
Definition unit.h:173
int hp
Definition unit.h:151
int fuel
Definition unit.h:153
bool stay
Definition unit.h:205
bool done_moving
Definition unit.h:181
int veteran
Definition unit.h:152
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
char * fc_strcasestr(const char *haystack, const char *needle)
Definition support.c:440
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:196
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
#define advance_index_iterate_end
Definition tech.h:248
static Tech_type_id advance_count(void)
Definition tech.h:170
#define A_FIRST
Definition tech.h:44
#define advance_iterate(_p)
Definition tech.h:275
#define advance_iterate_end
Definition tech.h:276
#define advance_index_iterate(_start, _index)
Definition tech.h:244
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:238
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:88
#define tile_resource(_tile)
Definition tile.h:102
#define tile_list_iterate(tile_list, ptile)
Definition tile.h:73
#define tile_terrain(_tile)
Definition tile.h:110
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_list_iterate_end
Definition tile.h:75
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:120
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
struct sprite * get_government_sprite(const struct tileset *t, const struct government *gov)
Definition tilespec.c:6793
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:789
bool tileset_layer_in_category(enum mapview_layer layer, enum layer_category cat)
Definition tilespec.c:7328
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:765
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:776
#define mapview_layer_iterate(layer)
Definition tilespec.h:175
#define mapview_layer_iterate_end
Definition tilespec.h:183
layer_category
Definition tilespec.h:189
@ LAYER_CATEGORY_TILE
Definition tilespec.h:191
@ LAYER_CATEGORY_CITY
Definition tilespec.h:190
@ LAYER_CATEGORY_UNIT
Definition tilespec.h:192
gpointer v_pointer2
Definition editprop.c:99
struct packet_edit_tile * tile
Definition editprop.c:101
gpointer v_pointer1
Definition editprop.c:98
struct packetdata::@148 pointers
struct packet_edit_unit * unit
Definition editprop.c:104
struct packet_edit_player * player
Definition editprop.c:105
struct packet_edit_scenario_desc * desc
Definition editprop.c:108
struct packet_edit_city * city
Definition editprop.c:103
struct packet_edit_game * game
Definition editprop.c:107
struct packet_edit_startpos_full * startpos
Definition editprop.c:102
struct government * v_gov
Definition editprop.c:238
bv_techs v_bv_inventions
Definition editprop.c:239
bv_max_extras v_bv_special
Definition editprop.c:233
struct tile_vision_data * v_tile_vision
Definition editprop.c:240
char * v_string
Definition editprop.c:229
struct built_status * v_built
Definition editprop.c:232
bv_max_extras v_bv_roads
Definition editprop.c:234
gpointer v_pointer
Definition editprop.c:226
struct nation_type * v_nation
Definition editprop.c:236
struct nation_hash * v_nation_hash
Definition editprop.c:237
bv_max_extras v_bv_bases
Definition editprop.c:235
GdkPixbuf * v_pixbuf
Definition editprop.c:231
const char * v_const_string
Definition editprop.c:230
#define unit_tile(_pu)
Definition unit.h:397
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:420
#define unit_owner(_pu)
Definition unit.h:396
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:432
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2625
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560
#define utype_fuel(ptype)
Definition unittype.h:839
#define vision_layer_iterate(v)
Definition vision.h:77
#define vision_layer_iterate_end
Definition vision.h:80