Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/editor.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
editor.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 <stdarg.h>
19#include <string.h>
20
21/* utility */
22#include "bitvector.h"
23#include "fcintl.h"
24#include "log.h"
25#include "support.h"
26
27/* common */
28#include "game.h"
29#include "map.h"
30#include "movement.h"
31#include "packets.h"
32
33/* client */
34#include "client_main.h"
35#include "climap.h"
36#include "control.h"
37#include "editor.h"
38#include "mapctrl_common.h"
39#include "tilespec.h"
40#include "zoom.h"
41
42/* client/include */
43#include "editgui_g.h"
44#include "mapview_g.h"
45
46
47 enum selection_modes {
48 SELECTION_MODE_NEW = 0,
49 SELECTION_MODE_ADD,
50 SELECTION_MODE_REMOVE
51};
52
53 enum editor_tool_flags {
54 ETF_NO_FLAGS = 0,
55 ETF_HAS_VALUE = 1<<0,
56 ETF_HAS_SIZE = 1<<1,
57 ETF_HAS_COUNT = 1<<2,
58 ETF_HAS_APPLIED_PLAYER = 1<<3,
59 ETF_HAS_VALUE_ERASE = 1<<4
60};
61
62 struct edit_buffer {
63 int type_flags;
64 struct tile_list *vtiles;
65 const struct tile *origin;
66};
67
68 struct editor_tool {
69 int flags;
70 enum editor_tool_mode mode;
71 int size;
72 int count;
73 int applied_player_no;
74 const char *name;
75 int value;
76 const char *tooltip;
77};
78
79 struct editor_state {
80 enum editor_tool_type tool;
81 struct editor_tool tools[NUM_EDITOR_TOOL_TYPES];
82
83 const struct tile *current_tile;
84 bool tool_active;
85
86 bool selrect_active;
87 int selrect_start_x;
88 int selrect_start_y;
89 int selrect_x;
90 int selrect_y;
91 int selrect_width;
92 int selrect_height;
93
94 enum selection_modes selection_mode;
95
96 struct tile_hash *selected_tile_table;
97 struct edit_buffer *copybuf;
98};
99
100 static struct editor_state *editor = NULL;
101
102/************************************************************************/
105 static void tool_set_init_value(enum editor_tool_type ett)
106{
107 struct editor_tool *tool = editor->tools + ett;
108
109 if (ett == ETT_TERRAIN_SPECIAL
110 || ett == ETT_ROAD
111 || ett == ETT_MILITARY_BASE
112 || ett == ETT_TERRAIN_RESOURCE) {
113 struct extra_type *first = NULL;
114
115 extra_type_iterate(pextra) {
116 if (ett == ETT_ROAD) {
117 if (is_extra_caused_by(pextra, EC_ROAD)) {
118 first = pextra;
119 break;
120 }
121 } else if (ett == ETT_MILITARY_BASE) {
122 if (is_extra_caused_by(pextra, EC_BASE)) {
123 first = pextra;
124 break;
125 }
126 } else if (ett == ETT_TERRAIN_RESOURCE) {
127 if (is_extra_caused_by(pextra, EC_RESOURCE)) {
128 first = pextra;
129 break;
130 }
131 } else {
132 /* Considers extras that are neither bases or roads, specials */
133 first = pextra;
134 break;
135 }
136 } extra_type_iterate_end;
137
138 if (first != NULL) {
139 tool->value = extra_index(first);
140 } else {
141 tool->value = 0;
142 }
143 } else {
144 tool->value = 0;
145 }
146}
147
148/************************************************************************/
151 static void tool_init(enum editor_tool_type ett, const char *name,
152 int flags, const char *tooltip)
153{
154 struct editor_tool *tool;
155
156 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
157 return;
158 }
159
160 tool = editor->tools + ett;
161
162 if (ett == ETT_COPYPASTE) {
163 tool->mode = ETM_COPY;
164 } else {
165 tool->mode = ETM_PAINT;
166 }
167 tool->name = name;
168 tool->flags = flags;
169 tool->tooltip = tooltip;
170 tool->size = 1;
171 tool->count = 1;
172 tool->applied_player_no = 0;
173
174 tool_set_init_value(ett);
175}
176
177/************************************************************************/
180 void editor_ruleset_changed(void)
181{
182 int t;
183
184 for (t = 0; t < NUM_EDITOR_TOOL_TYPES; t++) {
185 tool_set_init_value(t);
186 }
187}
188
189/************************************************************************/
193 void editor_init(void)
194{
195 fc_assert(editor == NULL);
196
197 editor = fc_calloc(1, sizeof(struct editor_state));
198
199 tool_init(ETT_TERRAIN, _("Terrain"),
200 ETF_HAS_VALUE | ETF_HAS_SIZE,
201 _("Change tile terrain.\nShortcut: t\n"
202 "Select terrain type: shift+t or right-click here."));
203 tool_init(ETT_TERRAIN_RESOURCE, _("Terrain Resource"),
204 ETF_HAS_VALUE | ETF_HAS_SIZE,
205 _("Change tile terrain resources.\nShortcut: r\n"
206 "Select resource type: shift+r or right-click here."));
207 tool_init(ETT_TERRAIN_SPECIAL, _("Terrain Special"), ETF_HAS_VALUE
208 | ETF_HAS_SIZE | ETF_HAS_VALUE_ERASE,
209 _("Modify tile specials.\nShortcut: s\n"
210 "Select special type: shift+s or right-click here."));
211 tool_init(ETT_ROAD, _("Road"), ETF_HAS_VALUE
212 | ETF_HAS_SIZE | ETF_HAS_VALUE_ERASE,
213 _("Modify roads on tile.\nShortcut: p\n"
214 "Select road type: shift+p or right-click here."));
215 tool_init(ETT_MILITARY_BASE, _("Military Base"), ETF_HAS_VALUE
216 | ETF_HAS_SIZE | ETF_HAS_VALUE_ERASE,
217 _("Create a military base.\nShortcut: m\n"
218 "Select base type: shift+m or right-click here."));
219 tool_init(ETT_UNIT, _("Unit"), ETF_HAS_VALUE | ETF_HAS_COUNT
220 | ETF_HAS_APPLIED_PLAYER | ETF_HAS_VALUE_ERASE,
221 _("Create unit.\nShortcut: u\nSelect unit "
222 "type: shift+u or right-click here."));
223 tool_init(ETT_CITY, _("City"), ETF_HAS_SIZE | ETF_HAS_APPLIED_PLAYER,
224 _("Create city.\nShortcut: c"));
225 tool_init(ETT_VISION, _("Vision"), ETF_HAS_SIZE,
226 _("Modify player's tile knowledge.\nShortcut: v"));
227 tool_init(ETT_STARTPOS, _("Start Position"), ETF_NO_FLAGS,
228 _("Place a start position which allows any nation to "
229 "start at the tile. To allow only certain nations to "
230 "start there, middle click on the start position on "
231 "the map and use the property editor.\nShortcut: b"));
232
233 tool_init(ETT_COPYPASTE, _("Copy/Paste"), ETF_HAS_SIZE,
234 _("Copy and paste tiles.\n"
235 "Shortcut for copy mode: shift-c\n"
236 "Shoftcut for paste mode: shift-v"));
237 editor->copybuf = edit_buffer_new(EBT_ALL);
238
239 editor->selected_tile_table = tile_hash_new();
240 tile_hash_set_no_shrink(editor->selected_tile_table, TRUE);
241}
242
243/************************************************************************/
246 void editor_clear(void)
247{
248 fc_assert_ret(editor != NULL);
249
250 edit_buffer_clear(editor->copybuf);
251 tile_hash_clear(editor->selected_tile_table);
252}
253
254/************************************************************************/
257 void editor_free(void)
258{
259 if (editor != NULL) {
260 edit_buffer_free(editor->copybuf);
261 tile_hash_destroy(editor->selected_tile_table);
262 free(editor);
263 editor = NULL;
264 }
265}
266
267/************************************************************************/
270 void editor_set_tool(enum editor_tool_type ett)
271{
272 if (editor == NULL) {
273 return;
274 }
275
276 if (!(ett < NUM_EDITOR_TOOL_TYPES)) {
277 return;
278 }
279
280 editor->tool = ett;
281}
282
283/************************************************************************/
286 enum editor_tool_type editor_get_tool(void)
287{
288 if (editor == NULL) {
289 return NUM_EDITOR_TOOL_TYPES;
290 }
291
292 return editor->tool;
293}
294
295/************************************************************************/
298 void editor_tool_set_mode(enum editor_tool_type ett,
299 enum editor_tool_mode etm)
300{
301 if (editor == NULL || !(ett < NUM_EDITOR_TOOL_TYPES)
302 || !(etm < NUM_EDITOR_TOOL_MODES)
303 || !editor_tool_has_mode(ett, etm)) {
304 return;
305 }
306
307 editor->tools[ett].mode = etm;
308}
309
310/************************************************************************/
313 bool editor_tool_has_mode(enum editor_tool_type ett,
314 enum editor_tool_mode etm)
315{
316 if (editor == NULL || !(ett < NUM_EDITOR_TOOL_TYPES)
317 || !(etm < NUM_EDITOR_TOOL_MODES)) {
318 return FALSE;
319 }
320
321 if (etm == ETM_COPY || etm == ETM_PASTE) {
322 return ett == ETT_COPYPASTE;
323 }
324
325 if (ett == ETT_COPYPASTE) {
326 return etm == ETM_COPY || etm == ETM_PASTE;
327 }
328
329 return TRUE;
330}
331
332/************************************************************************/
335 enum editor_tool_mode editor_tool_get_mode(enum editor_tool_type ett)
336{
337 if (editor == NULL || !(ett < NUM_EDITOR_TOOL_TYPES)) {
338 return NUM_EDITOR_TOOL_MODES;
339 }
340 return editor->tools[ett].mode;
341}
342
343/************************************************************************/
346 bool editor_is_active(void)
347{
348 return can_conn_edit(&client.conn);
349}
350
351/************************************************************************/
359 bool editor_tool_is_usable(enum editor_tool_type ett)
360{
361 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
362 return FALSE;
363 }
364
365 switch (ett) {
366 case ETT_MILITARY_BASE:
367 return base_count() > 0;
368 case ETT_ROAD:
369 return road_count() > 0;
370 case ETT_TERRAIN_RESOURCE:
371 return game.control.num_resource_types > 0;
372 case ETT_UNIT:
373 return utype_count() > 0;
374 default:
375 break;
376 }
377
378 return TRUE;
379}
380
381/************************************************************************/
385 bool editor_tool_has_value(enum editor_tool_type ett)
386{
387 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
388 return FALSE;
389 }
390 return editor->tools[ett].flags & ETF_HAS_VALUE;
391}
392
393/************************************************************************/
397 void editor_tool_set_value(enum editor_tool_type ett, int value)
398{
399 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)
400 || !editor_tool_has_value(ett)) {
401 return;
402 }
403 editor->tools[ett].value = value;
404}
405
406/************************************************************************/
409 int editor_tool_get_value(enum editor_tool_type ett)
410{
411 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)
412 || !editor_tool_has_value(ett)) {
413 return 0;
414 }
415
416 return editor->tools[ett].value;
417}
418
419/************************************************************************/
422 static void editor_start_selection_rectangle(int canvas_x, int canvas_y)
423{
424 if (!editor) {
425 return;
426 }
427
428 if (editor->selection_mode == SELECTION_MODE_NEW
429 && editor_selection_count() > 0) {
430 editor_selection_clear();
431 update_map_canvas_visible();
432 }
433
434 editor->selrect_start_x = canvas_x;
435 editor->selrect_start_y = canvas_y;
436 editor->selrect_width = 0;
437 editor->selrect_height = 0;
438 editor->selrect_active = TRUE;
439}
440
441/************************************************************************/
446 static inline bool tile_really_has_any_specials(const struct tile *ptile)
447{
448 if (!ptile) {
449 return FALSE;
450 }
451
452 extra_type_by_cause_iterate(EC_SPECIAL, pextra) {
453 if (tile_has_extra(ptile, pextra)) {
454 return TRUE;
455 }
456 } extra_type_by_cause_iterate_end;
457
458 return FALSE;
459}
460
461/************************************************************************/
465 static void editor_grab_applied_player(const struct tile *ptile)
466{
467 int apno = -1;
468
469 if (!editor || !ptile) {
470 return;
471 }
472
473 if (client_has_player()
474 && tile_get_known(ptile, client_player()) == TILE_UNKNOWN) {
475 return;
476 }
477
478 if (tile_city(ptile) != NULL) {
479 apno = player_number(city_owner(tile_city(ptile)));
480 } else if (unit_list_size(ptile->units) > 0) {
481 struct unit *punit = unit_list_get(ptile->units, 0);
482
483 apno = player_number(unit_owner(punit));
484 } else if (tile_owner(ptile) != NULL) {
485 apno = player_number(tile_owner(ptile));
486 }
487
488 if (player_by_number(apno) != NULL) {
489 editor_tool_set_applied_player(editor_get_tool(), apno);
490 editgui_refresh();
491 }
492}
493
494/************************************************************************/
497 static void editor_grab_tool(const struct tile *ptile)
498{
499 int ett = -1, value = 0;
500 struct extra_type *first_base = NULL;
501 struct extra_type *first_road = NULL;
502 struct extra_type *first_resource = NULL;
503
504 if (!editor) {
505 return;
506 }
507
508 if (!ptile) {
509 return;
510 }
511
512 extra_type_by_cause_iterate(EC_BASE, pextra) {
513 if (tile_has_extra(ptile, pextra)) {
514 first_base = pextra;
515 break;
516 }
517 } extra_type_by_cause_iterate_end;
518
519 extra_type_by_cause_iterate(EC_ROAD, pextra) {
520 if (tile_has_extra(ptile, pextra)) {
521 first_road = pextra;
522 break;
523 }
524 } extra_type_by_cause_iterate_end;
525
526 extra_type_by_cause_iterate(EC_RESOURCE, pextra) {
527 if (tile_has_extra(ptile, pextra)) {
528 first_resource = pextra;
529 break;
530 }
531 } extra_type_by_cause_iterate_end;
532
533 if (client_has_player()
534 && tile_get_known(ptile, client_player()) == TILE_UNKNOWN) {
535 ett = ETT_VISION;
536
537 } else if (tile_city(ptile)) {
538 ett = ETT_CITY;
539
540 } else if (unit_list_size(ptile->units) > 0) {
541 int max_score = 0, score;
542 struct unit *grabbed_punit = NULL;
543
544 unit_list_iterate(ptile->units, punit) {
545 if (uclass_has_flag(unit_class_get(punit), UCF_UNREACHABLE)) {
546 score = 5;
547 } else if (utype_move_type(unit_type_get(punit)) == UMT_LAND) {
548 score = 4;
549 } else if (utype_move_type(unit_type_get(punit)) == UMT_SEA) {
550 score = 3;
551 } else {
552 score = 2;
553 }
554 if (unit_transported(punit)) {
555 score = 1;
556 }
557
558 if (score > max_score) {
559 max_score = score;
560 grabbed_punit = punit;
561 }
562 } unit_list_iterate_end;
563
564 if (grabbed_punit) {
565 ett = ETT_UNIT;
566 value = utype_number(unit_type_get(grabbed_punit));
567 }
568 } else if (first_base != NULL) {
569 ett = ETT_MILITARY_BASE;
570 value = extra_index(first_base);
571
572 } else if (first_road != NULL) {
573 ett = ETT_ROAD;
574 value = extra_index(first_road);
575
576 } else if (tile_really_has_any_specials(ptile)) {
577 struct extra_type *specials_array[MAX_EXTRA_TYPES];
578 int count = 0, i;
579 struct extra_type *special = NULL;
580
581 extra_type_by_cause_iterate(EC_SPECIAL, s) {
582 specials_array[count++] = s;
583 } extra_type_by_cause_iterate_end;
584
585 /* Grab specials in reverse order of enum tile_special_type. */
586
587 for (i = count - 1; i >= 0; i--) {
588 if (tile_has_extra(ptile, specials_array[i])) {
589 special = specials_array[i];
590 break;
591 }
592 }
593
594 if (special != NULL) {
595 ett = ETT_TERRAIN_SPECIAL;
596 value = extra_index(special);
597 }
598 } else if (first_resource != NULL) {
599 ett = ETT_TERRAIN_RESOURCE;
600 value = extra_index(first_resource);
601
602 } else if (tile_terrain(ptile) != NULL) {
603 ett = ETT_TERRAIN;
604 value = terrain_number(tile_terrain(ptile));
605 }
606
607 if (ett < 0) {
608 return;
609 }
610
611 editor_set_tool(ett);
612 if (editor_tool_has_value(ett)) {
613 editor_tool_set_value(ett, value);
614 }
615 editgui_refresh();
616}
617
618/************************************************************************/
621 static inline bool can_edit_tile_properties(struct tile *ptile)
622{
623 return ptile != NULL;
624}
625
626/************************************************************************/
631 static void popup_properties(struct tile *ptile)
632{
633 struct tile_list *tiles;
634
635 if (!ptile) {
636 return;
637 }
638
639 tiles = tile_list_new();
640
641 if (editor_tile_is_selected(ptile)) {
642 tile_hash_iterate(editor->selected_tile_table, sel_tile) {
643 if (can_edit_tile_properties(sel_tile)) {
644 tile_list_append(tiles, sel_tile);
645 }
646 } tile_hash_iterate_end;
647 } else {
648 if (can_edit_tile_properties(ptile)) {
649 tile_list_append(tiles, ptile);
650 }
651 }
652
653 editgui_popup_properties(tiles, NUM_OBJTYPES);
654
655 tile_list_destroy(tiles);
656}
657
658/************************************************************************/
661 void editor_mouse_button_press(int canvas_x, int canvas_y,
662 int button, int modifiers)
663{
664 struct tile *ptile;
665
666 if (editor == NULL) {
667 return;
668 }
669
670 ptile = canvas_pos_to_tile(canvas_x, canvas_y, mouse_zoom);
671 if (ptile == NULL) {
672 return;
673 }
674
675 switch (button) {
676
677 case MOUSE_BUTTON_LEFT:
678 if (modifiers == EKM_SHIFT) {
679 editor_grab_tool(ptile);
680 } else if (modifiers == EKM_CTRL) {
681 editor_grab_applied_player(ptile);
682 } else if (modifiers == EKM_NONE) {
683 editor->tool_active = TRUE;
684 editor_apply_tool(ptile, FALSE);
685 editor_notify_edit_finished();
686 editor_set_current_tile(ptile);
687 }
688 break;
689
690 case MOUSE_BUTTON_RIGHT:
691 if (modifiers == (EKM_ALT | EKM_CTRL)) {
692 popup_properties(ptile);
693 break;
694 }
695
696 if (modifiers == EKM_SHIFT) {
697 editor->selection_mode = SELECTION_MODE_ADD;
698 } else if (modifiers == EKM_ALT) {
699 editor->selection_mode = SELECTION_MODE_REMOVE;
700 } else if (modifiers == EKM_NONE) {
701 editor->selection_mode = SELECTION_MODE_NEW;
702 } else {
703 break;
704 }
705 editor_start_selection_rectangle(canvas_x, canvas_y);
706 break;
707
708 case MOUSE_BUTTON_MIDDLE:
709 if (modifiers == EKM_NONE) {
710 popup_properties(ptile);
711 }
712 break;
713
714 default:
715 break;
716 }
717}
718
719/************************************************************************/
722 static void editor_end_selection_rectangle(int canvas_x, int canvas_y)
723{
724 int w, h;
725
726 if (!editor) {
727 return;
728 }
729
730 editor->selrect_active = FALSE;
731
732 if (editor->selrect_width <= 0 || editor->selrect_height <= 0) {
733 struct tile *ptile;
734
735 ptile = canvas_pos_to_tile(canvas_x, canvas_y, mouse_zoom);
736 if (ptile && editor->selection_mode == SELECTION_MODE_ADD) {
737 editor_selection_add(ptile);
738 } else if (ptile && editor->selection_mode == SELECTION_MODE_REMOVE) {
739 editor_selection_remove(ptile);
740 } else {
741 recenter_button_pressed(canvas_x, canvas_y);
742 return;
743 }
744
745 if (ptile) {
746 refresh_tile_mapcanvas(ptile, TRUE, TRUE);
747 }
748
749 return;
750 }
751
752 gui_rect_iterate(mapview.gui_x0 + editor->selrect_x,
753 mapview.gui_y0 + editor->selrect_y,
754 editor->selrect_width, editor->selrect_height,
755 ptile, pedge, pcorner, map_zoom) {
756 if (ptile == NULL) {
757 continue;
758 }
759 if (editor->selection_mode == SELECTION_MODE_NEW
760 || editor->selection_mode == SELECTION_MODE_ADD) {
761 editor_selection_add(ptile);
762 } else if (editor->selection_mode == SELECTION_MODE_REMOVE) {
763 editor_selection_remove(ptile);
764 }
765 } gui_rect_iterate_end;
766
767 w = tileset_tile_width(tileset);
768 h = tileset_tile_height(tileset);
769
770 update_map_canvas(editor->selrect_x - w,
771 editor->selrect_y - h,
772 editor->selrect_width + 2 * w,
773 editor->selrect_height + 2 * h);
774 flush_dirty();
775}
776
777/************************************************************************/
780 static void editor_draw_selrect(void)
781{
782 if (!editor) {
783 return;
784 }
785
786 if (editor->selrect_active && editor->selrect_width > 0
787 && editor->selrect_height > 0) {
788 draw_selection_rectangle(editor->selrect_x,
789 editor->selrect_y,
790 editor->selrect_width,
791 editor->selrect_height);
792 }
793}
794
795/************************************************************************/
798 void editor_mouse_button_release(int canvas_x, int canvas_y,
799 int button, int modifiers)
800{
801 switch (button) {
802
803 case MOUSE_BUTTON_LEFT:
804 editor_set_current_tile(NULL);
805 editor->tool_active = FALSE;
806 break;
807
808 case MOUSE_BUTTON_RIGHT:
809 if (editor->selrect_active) {
810 editor_end_selection_rectangle(canvas_x, canvas_y);
811 }
812 break;
813
814 case MOUSE_BUTTON_MIDDLE:
815 break;
816
817 default:
818 break;
819 }
820}
821
822/************************************************************************/
826 static void editor_resize_selection_rectangle(int canvas_x, int canvas_y)
827{
828 int xl, yt, xr, yb;
829
830 if (editor->selrect_start_x <= canvas_x) {
831 xl = editor->selrect_start_x;
832 xr = canvas_x;
833 } else {
834 xl = canvas_x;
835 xr = editor->selrect_start_x;
836 }
837
838 if (editor->selrect_start_y <= canvas_y) {
839 yt = editor->selrect_start_y;
840 yb = canvas_y;
841 } else {
842 yt = canvas_y;
843 yb = editor->selrect_start_y;
844 }
845
846 /* Erase the previously drawn rectangle. */
847 editor_draw_selrect();
848
849 if (xl == xr || yt == yb) {
850 editor->selrect_width = 0;
851 editor->selrect_height = 0;
852 return;
853 }
854
855 editor->selrect_x = xl;
856 editor->selrect_y = yt;
857 editor->selrect_width = xr - xl;
858 editor->selrect_height = yb - yt;
859
860 editor_draw_selrect();
861}
862
863/************************************************************************/
866 void editor_mouse_move(int canvas_x, int canvas_y, int modifiers)
867{
868 const struct tile *ptile, *old;
869
870 if (!editor) {
871 return;
872 }
873
874 old = editor_get_current_tile();
875 ptile = canvas_pos_to_tile(canvas_x, canvas_y, mouse_zoom);
876
877 if (!ptile) {
878 return;
879 }
880
881 if (editor->tool_active && old != NULL && old != ptile) {
882 editor_apply_tool(ptile, FALSE);
883 editor_notify_edit_finished();
884 editor_set_current_tile(ptile);
885 }
886
887 if (editor->selrect_active) {
888 editor_resize_selection_rectangle(canvas_x, canvas_y);
889 }
890}
891
892/************************************************************************/
897 void editor_notify_edit_finished(void)
898{
899 send_packet_edit_check_tiles(&client.conn);
900}
901
902/************************************************************************/
909 void editor_apply_tool(const struct tile *ptile,
910 bool part_of_selection)
911{
912 enum editor_tool_type ett;
913 enum editor_tool_mode etm;
914 int value, size, count, apno, tile, id;
915 bool erase;
916 struct connection *my_conn = &client.conn;
917
918 if (editor == NULL || ptile == NULL) {
919 return;
920 }
921
922 ett = editor_get_tool();
923 etm = editor_tool_get_mode(ett);
924 size = editor_tool_get_size(ett);
925 count = editor_tool_get_count(ett);
926 value = editor_tool_get_value(ett);
927 apno = editor_tool_get_applied_player(ett);
928
929 if (ett != ETT_VISION && !client_is_global_observer()
930 && client_has_player()
931 && tile_get_known(ptile, client_player()) == TILE_UNKNOWN) {
932 return;
933 }
934
935 if (editor_tool_has_applied_player(ett)
936 && player_by_number(apno) == NULL) {
937 return;
938 }
939
940 if (ett == ETT_COPYPASTE) {
941 struct edit_buffer *ebuf;
942 ebuf = editor_get_copy_buffer();
943 if (etm == ETM_COPY) {
944 if (part_of_selection) {
945 edit_buffer_copy(ebuf, ptile);
946 } else {
947 edit_buffer_clear(ebuf);
948 edit_buffer_copy_square(ebuf, ptile, size);
949 editgui_refresh();
950 }
951 } else if (etm == ETM_PAINT || etm == ETM_PASTE) {
952 edit_buffer_paste(ebuf, ptile);
953 }
954 return;
955 }
956
957 if (part_of_selection && ett != ETT_CITY) {
958 size = 1;
959 }
960
961 erase = (etm == ETM_ERASE);
962 tile = tile_index(ptile);
963
964 switch (ett) {
965
966 case ETT_TERRAIN:
967 dsend_packet_edit_tile_terrain(my_conn, tile, erase ? 0 : value, size);
968 break;
969
970 case ETT_TERRAIN_RESOURCE:
971 case ETT_TERRAIN_SPECIAL:
972 case ETT_ROAD:
973 case ETT_MILITARY_BASE:
974 dsend_packet_edit_tile_extra(my_conn, tile, value, erase, apno, size);
975 break;
976
977 case ETT_UNIT:
978 if (erase) {
979 dsend_packet_edit_unit_remove(my_conn, apno, tile, value, count);
980 } else {
981 dsend_packet_edit_unit_create(my_conn, apno, tile, value, count, 0);
982 }
983 break;
984
985 case ETT_CITY:
986 if (erase) {
987 struct city *pcity = tile_city(ptile);
988 if (pcity != NULL) {
989 id = pcity->id;
990 dsend_packet_edit_city_remove(my_conn, id, id);
991 }
992 } else {
993 dsend_packet_edit_city_create(my_conn, apno, tile, size, 0);
994 }
995 break;
996
997 case ETT_VISION:
998 if (client_has_player()) {
999 id = client_player_number();
1000 dsend_packet_edit_player_vision(my_conn, id, tile, !erase, size);
1001 }
1002 break;
1003
1004 case ETT_STARTPOS:
1005 dsend_packet_edit_startpos(my_conn, tile, erase, 0);
1006 break;
1007
1008 default:
1009 break;
1010 }
1011}
1012
1013/************************************************************************/
1016 void editor_set_current_tile(const struct tile *ptile)
1017{
1018 if (editor == NULL) {
1019 return;
1020 }
1021
1022 editor->current_tile = ptile;
1023}
1024
1025/************************************************************************/
1028 const struct tile *editor_get_current_tile(void)
1029{
1030 if (editor == NULL) {
1031 return NULL;
1032 }
1033
1034 return editor->current_tile;
1035}
1036
1037/************************************************************************/
1041 void editor_tool_toggle_mode(enum editor_tool_type ett,
1042 enum editor_tool_mode etm)
1043{
1044 if (!editor_tool_has_mode(ett, etm)) {
1045 return;
1046 }
1047 if (editor_tool_get_mode(ett) == etm) {
1048 editor_tool_set_mode(ett, ett == ETT_COPYPASTE
1049 ? ETM_COPY : ETM_PAINT);
1050 } else {
1051 editor_tool_set_mode(ett, etm);
1052 }
1053}
1054
1055/************************************************************************/
1058 void editor_tool_cycle_mode(enum editor_tool_type ett)
1059{
1060 int mode, count;
1061 bool found = FALSE;
1062
1063 mode = editor_tool_get_mode(ett);
1064 if (!(0 <= mode && mode < NUM_EDITOR_TOOL_MODES)) {
1065 return;
1066 }
1067
1068 for (count = 0; count < NUM_EDITOR_TOOL_MODES; count++) {
1069 mode = (mode + 1) % NUM_EDITOR_TOOL_MODES;
1070 if (editor_tool_has_mode(ett, mode)) {
1071 found = TRUE;
1072 break;
1073 }
1074 }
1075
1076 if (found) {
1077 editor_tool_set_mode(ett, mode);
1078 }
1079}
1080
1081/************************************************************************/
1084 void editor_selection_clear(void)
1085{
1086 if (!editor) {
1087 return;
1088 }
1089 tile_hash_clear(editor->selected_tile_table);
1090}
1091
1092/************************************************************************/
1095 void editor_selection_add(const struct tile *ptile)
1096{
1097 if (!editor || !ptile) {
1098 return;
1099 }
1100 tile_hash_insert(editor->selected_tile_table, ptile, NULL);
1101}
1102
1103/************************************************************************/
1106 void editor_selection_remove(const struct tile *ptile)
1107{
1108 if (!editor || !ptile) {
1109 return;
1110 }
1111 tile_hash_remove(editor->selected_tile_table, ptile);
1112}
1113
1114/************************************************************************/
1117 bool editor_tile_is_selected(const struct tile *ptile)
1118{
1119 if (!editor || !ptile) {
1120 return FALSE;
1121 }
1122 return tile_hash_lookup(editor->selected_tile_table, ptile, NULL);
1123}
1124
1125/************************************************************************/
1128 void editor_apply_tool_to_selection(void)
1129{
1130 enum editor_tool_type ett;
1131
1132 if (!editor || editor_selection_count() <= 0) {
1133 return;
1134 }
1135
1136 ett = editor_get_tool();
1137 if (editor_tool_get_mode(ett) == ETM_COPY) {
1138 struct edit_buffer *ebuf;
1139 ebuf = editor_get_copy_buffer();
1140 edit_buffer_clear(ebuf);
1141 edit_buffer_set_origin(ebuf, editor_get_selection_center());
1142 }
1143
1144 connection_do_buffer(&client.conn);
1145 tile_hash_iterate(editor->selected_tile_table, ptile) {
1146 editor_apply_tool(ptile, TRUE);
1147 } tile_hash_iterate_end;
1148 editor_notify_edit_finished();
1149 connection_do_unbuffer(&client.conn);
1150
1151 if (editor_tool_get_mode(ett) == ETM_COPY) {
1152 editgui_refresh();
1153 }
1154}
1155
1156/************************************************************************/
1159 const char *editor_tool_get_name(enum editor_tool_type ett)
1160{
1161 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1162 return "";
1163 }
1164
1165 return editor->tools[ett].name;
1166}
1167
1168/************************************************************************/
1172 const char *editor_tool_get_value_name(enum editor_tool_type emt, int value)
1173{
1174 struct terrain *pterrain;
1175 struct unit_type *putype;
1176 struct extra_type *pextra;
1177
1178 if (!editor) {
1179 return "";
1180 }
1181
1182 switch (emt) {
1183 case ETT_TERRAIN:
1184 pterrain = terrain_by_number(value);
1185 return pterrain ? terrain_name_translation(pterrain) : "";
1186 break;
1187 case ETT_TERRAIN_RESOURCE:
1188 case ETT_TERRAIN_SPECIAL:
1189 case ETT_ROAD:
1190 case ETT_MILITARY_BASE:
1191 pextra = extra_by_number(value);
1192 return pextra != NULL ? extra_name_translation(pextra) : "";
1193 break;
1194 case ETT_UNIT:
1195 putype = utype_by_number(value);
1196 return putype ? utype_name_translation(putype) : "";
1197 break;
1198 default:
1199 break;
1200 }
1201 return "";
1202}
1203
1204/************************************************************************/
1207 bool editor_tool_has_size(enum editor_tool_type ett)
1208{
1209 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1210 return FALSE;
1211 }
1212 return editor->tools[ett].flags & ETF_HAS_SIZE;
1213}
1214
1215/************************************************************************/
1218 int editor_tool_get_size(enum editor_tool_type ett)
1219{
1220 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1221 return 1;
1222 }
1223 return editor->tools[ett].size;
1224}
1225
1226/************************************************************************/
1229 void editor_tool_set_size(enum editor_tool_type ett, int size)
1230{
1231 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1232 return;
1233 }
1234 editor->tools[ett].size = MAX(1, size);
1235}
1236
1237/************************************************************************/
1241 bool editor_tool_has_count(enum editor_tool_type ett)
1242{
1243 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1244 return FALSE;
1245 }
1246 return editor->tools[ett].flags & ETF_HAS_COUNT;
1247}
1248
1249/************************************************************************/
1252 int editor_tool_get_count(enum editor_tool_type ett)
1253{
1254 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1255 return 1;
1256 }
1257 return editor->tools[ett].count;
1258}
1259
1260/************************************************************************/
1263 void editor_tool_set_count(enum editor_tool_type ett, int count)
1264{
1265 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1266 return;
1267 }
1268 editor->tools[ett].count = MAX(1, count);
1269}
1270
1271/************************************************************************/
1275 struct sprite *editor_tool_get_sprite(enum editor_tool_type ett)
1276{
1277 const struct editor_sprites *sprites;
1278
1279 if (!tileset || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1280 return NULL;
1281 }
1282
1283 sprites = get_editor_sprites(tileset);
1284 if (!sprites) {
1285 return NULL;
1286 }
1287
1288 switch (ett) {
1289 case ETT_COPYPASTE:
1290 return sprites->copypaste;
1291 break;
1292 case ETT_TERRAIN:
1293 return sprites->terrain;
1294 break;
1295 case ETT_TERRAIN_RESOURCE:
1296 return sprites->terrain_resource;
1297 break;
1298 case ETT_TERRAIN_SPECIAL:
1299 return sprites->terrain_special;
1300 break;
1301 case ETT_ROAD:
1302 return sprites->road;
1303 case ETT_MILITARY_BASE:
1304 return sprites->military_base;
1305 case ETT_UNIT:
1306 return sprites->unit;
1307 break;
1308 case ETT_CITY:
1309 return sprites->city;
1310 break;
1311 case ETT_VISION:
1312 return sprites->vision;
1313 break;
1314 case ETT_STARTPOS:
1315 return sprites->startpos;
1316 break;
1317 default:
1318 break;
1319 }
1320
1321 return NULL;
1322}
1323
1324/************************************************************************/
1327 const char *editor_tool_get_tooltip(enum editor_tool_type ett)
1328{
1329 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)
1330 || !editor->tools[ett].tooltip) {
1331 return "";
1332 }
1333 return editor->tools[ett].tooltip;
1334}
1335
1336/************************************************************************/
1341 int editor_tool_get_applied_player(enum editor_tool_type ett)
1342{
1343 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1344 return -1;
1345 }
1346 return editor->tools[ett].applied_player_no;
1347}
1348
1349/************************************************************************/
1352 void editor_tool_set_applied_player(enum editor_tool_type ett,
1353 int player_no)
1354{
1355 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1356 return;
1357 }
1358 editor->tools[ett].applied_player_no = player_no;
1359}
1360
1361/************************************************************************/
1365 bool editor_tool_has_applied_player(enum editor_tool_type ett)
1366{
1367 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1368 return FALSE;
1369 }
1370 return editor->tools[ett].flags & ETF_HAS_APPLIED_PLAYER;
1371}
1372
1373/************************************************************************/
1377 bool editor_tool_has_value_erase(enum editor_tool_type ett)
1378{
1379 if (!editor || !(ett < NUM_EDITOR_TOOL_TYPES)) {
1380 return FALSE;
1381 }
1382 return editor->tools[ett].flags & ETF_HAS_VALUE_ERASE;
1383}
1384
1385/************************************************************************/
1388 int editor_selection_count(void)
1389{
1390 if (!editor) {
1391 return 0;
1392 }
1393 return tile_hash_size(editor->selected_tile_table);
1394}
1395
1396/************************************************************************/
1405 struct unit *editor_unit_virtual_create(void)
1406{
1407 struct unit *vunit;
1408 struct player *pplayer;
1409 struct unit_type *putype;
1410 int apno, value;
1411
1412 value = editor_tool_get_value(ETT_UNIT);
1413 putype = utype_by_number(value);
1414
1415 if (!putype) {
1416 return NULL;
1417 }
1418
1419 apno = editor_tool_get_applied_player(ETT_UNIT);
1420 pplayer = player_by_number(apno);
1421 if (!pplayer) {
1422 return NULL;
1423 }
1424
1425 vunit = unit_virtual_create(pplayer, NULL, putype, 0);
1426
1427 return vunit;
1428}
1429
1430/************************************************************************/
1433 struct edit_buffer *edit_buffer_new(int type_flags)
1434{
1435 struct edit_buffer *ebuf;
1436
1437 if (!(0 <= type_flags && type_flags <= EBT_ALL)) {
1438 return NULL;
1439 }
1440
1441 ebuf = fc_calloc(1, sizeof(*ebuf));
1442 ebuf->type_flags = type_flags;
1443 ebuf->vtiles = tile_list_new();
1444
1445 return ebuf;
1446}
1447
1448/************************************************************************/
1451 void edit_buffer_free(struct edit_buffer *ebuf)
1452{
1453 if (!ebuf) {
1454 return;
1455 }
1456
1457 if (ebuf->vtiles) {
1458 tile_list_iterate(ebuf->vtiles, vtile) {
1459 tile_virtual_destroy(vtile);
1460 } tile_list_iterate_end;
1461 tile_list_destroy(ebuf->vtiles);
1462 ebuf->vtiles = NULL;
1463 }
1464 free(ebuf);
1465}
1466
1467/************************************************************************/
1470 void edit_buffer_clear(struct edit_buffer *ebuf)
1471{
1472 if (!ebuf || !ebuf->vtiles) {
1473 return;
1474 }
1475
1476 tile_list_iterate(ebuf->vtiles, vtile) {
1477 tile_virtual_destroy(vtile);
1478 } tile_list_iterate_end;
1479 tile_list_clear(ebuf->vtiles);
1480
1481 edit_buffer_set_origin(ebuf, NULL);
1482}
1483
1484/************************************************************************/
1488 void edit_buffer_copy_square(struct edit_buffer *ebuf,
1489 const struct tile *center,
1490 int radius)
1491{
1492 if (!ebuf || !center || radius < 1) {
1493 return;
1494 }
1495
1496 edit_buffer_set_origin(ebuf, center);
1497 square_iterate(&(wld.map), center, radius - 1, ptile) {
1498 edit_buffer_copy(ebuf, ptile);
1499 } square_iterate_end;
1500}
1501
1502/************************************************************************/
1505 void edit_buffer_copy(struct edit_buffer *ebuf, const struct tile *ptile)
1506{
1507 struct tile *vtile;
1508 struct unit *vunit;
1509 bool copied = FALSE;
1510
1511 if (!ebuf || !ptile) {
1512 return;
1513 }
1514
1515 vtile = tile_virtual_new(NULL);
1516 vtile->index = tile_index(ptile);
1517
1518 edit_buffer_type_iterate(ebuf, type) {
1519 switch (type) {
1520 case EBT_TERRAIN:
1521 if (tile_terrain(ptile)) {
1522 tile_set_terrain(vtile, tile_terrain(ptile));
1523 copied = TRUE;
1524 }
1525 break;
1526 case EBT_RESOURCE:
1527 if (tile_resource(ptile)) {
1528 tile_set_resource(vtile, tile_resource(ptile));
1529 copied = TRUE;
1530 }
1531 break;
1532 case EBT_SPECIAL:
1533 extra_type_by_cause_iterate(EC_SPECIAL, pextra) {
1534 if (tile_has_extra(ptile, pextra)) {
1535 tile_add_extra(vtile, pextra);
1536 copied = TRUE;
1537 }
1538 } extra_type_by_cause_iterate_end;
1539 break;
1540 case EBT_BASE:
1541 extra_type_iterate(pextra) {
1542 if (tile_has_extra(ptile, pextra)
1543 && is_extra_caused_by(pextra, EC_BASE)) {
1544 tile_add_extra(vtile, pextra);
1545 copied = TRUE;
1546 }
1547 } extra_type_iterate_end;
1548 break;
1549 case EBT_ROAD:
1550 extra_type_iterate(pextra) {
1551 if (tile_has_extra(ptile, pextra)
1552 && is_extra_caused_by(pextra, EC_ROAD)) {
1553 tile_add_extra(vtile, pextra);
1554 copied = TRUE;
1555 }
1556 } extra_type_iterate_end;
1557 break;
1558 case EBT_UNIT:
1559 unit_list_iterate(ptile->units, punit) {
1560 if (!punit) {
1561 continue;
1562 }
1563 vunit = unit_virtual_create(unit_owner(punit), NULL,
1564 unit_type_get(punit), punit->veteran);
1565 vunit->homecity = punit->homecity;
1566 vunit->hp = punit->hp;
1567 unit_list_append(vtile->units, vunit);
1568 copied = TRUE;
1569 } unit_list_iterate_end;
1570 break;
1571 case EBT_CITY:
1572 if (tile_city(ptile)) {
1573 struct city *pcity, *vcity;
1574 char name[MAX_LEN_NAME];
1575
1576 pcity = tile_city(ptile);
1577 fc_snprintf(name, sizeof(name), "Copy of %s",
1578 city_name_get(pcity));
1579 vcity = create_city_virtual(city_owner(pcity), NULL, name);
1580 city_size_set(vcity, city_size_get(pcity));
1581 improvement_iterate(pimprove) {
1582 if (!is_improvement(pimprove)
1583 || !city_has_building(pcity, pimprove)) {
1584 continue;
1585 }
1586 city_add_improvement(vcity, pimprove);
1587 } improvement_iterate_end;
1588 tile_set_worked(vtile, vcity);
1589 copied = TRUE;
1590 }
1591 break;
1592 default:
1593 break;
1594 }
1595 } edit_buffer_type_iterate_end;
1596
1597 if (copied) {
1598 tile_list_append(ebuf->vtiles, vtile);
1599 } else {
1600 tile_virtual_destroy(vtile);
1601 }
1602}
1603
1604/************************************************************************/
1607 static void fill_tile_edit_packet(struct packet_edit_tile *packet,
1608 const struct tile *ptile)
1609{
1610 const struct extra_type *presource;
1611 const struct terrain *pterrain;
1612
1613 if (!packet || !ptile) {
1614 return;
1615 }
1616 packet->tile = tile_index(ptile);
1617 packet->extras = *tile_extras(ptile);
1618
1619 presource = tile_resource(ptile);
1620 packet->resource = presource
1621 ? extra_number(presource)
1622 : extra_count();
1623
1624 pterrain = tile_terrain(ptile);
1625 packet->terrain = pterrain
1626 ? terrain_number(pterrain)
1627 : terrain_count();
1628 if (ptile->extras_owner != NULL) {
1629 packet->eowner = player_number(ptile->extras_owner);
1630 } else {
1631 packet->eowner = MAP_TILE_OWNER_NULL;
1632 }
1633
1634 if (ptile->label == NULL) {
1635 packet->label[0] = '\0';
1636 } else {
1637 sz_strlcpy(packet->label, ptile->label);
1638 }
1639}
1640
1641/************************************************************************/
1645 static void paste_tile(struct edit_buffer *ebuf,
1646 const struct tile *vtile,
1647 const struct tile *ptile_dest)
1648{
1649 struct connection *my_conn = &client.conn;
1650 struct packet_edit_tile tile_packet;
1651 struct city *vcity;
1652 int value, owner, tile;
1653 bool send_edit_tile = FALSE;
1654
1655 if (!ebuf || !vtile || !ptile_dest) {
1656 return;
1657 }
1658
1659 tile = tile_index(ptile_dest);
1660
1661 fill_tile_edit_packet(&tile_packet, ptile_dest);
1662
1663 edit_buffer_type_iterate(ebuf, type) {
1664 switch (type) {
1665 case EBT_TERRAIN:
1666 if (!tile_terrain(vtile)) {
1667 continue;
1668 }
1669 value = terrain_number(tile_terrain(vtile));
1670 dsend_packet_edit_tile_terrain(my_conn, tile, value, 1);
1671 break;
1672 case EBT_RESOURCE:
1673 extra_type_by_cause_iterate(EC_RESOURCE, pextra) {
1674 if (tile_has_extra(vtile, pextra)) {
1675 BV_SET(tile_packet.extras, extra_index(pextra));
1676 send_edit_tile = TRUE;
1677 }
1678 } extra_type_by_cause_iterate_end;
1679 break;
1680 case EBT_SPECIAL:
1681 extra_type_by_cause_iterate(EC_SPECIAL, pextra) {
1682 if (tile_has_extra(vtile, pextra)) {
1683 BV_SET(tile_packet.extras, extra_index(pextra));
1684 send_edit_tile = TRUE;
1685 }
1686 } extra_type_by_cause_iterate_end;
1687 break;
1688 case EBT_BASE:
1689 extra_type_iterate(pextra) {
1690 if (tile_has_extra(vtile, pextra)
1691 && is_extra_caused_by(pextra, EC_BASE)) {
1692 BV_SET(tile_packet.extras, extra_index(pextra));
1693 send_edit_tile = TRUE;
1694 }
1695 } extra_type_iterate_end;
1696 break;
1697 case EBT_ROAD:
1698 extra_type_iterate(pextra) {
1699 if (tile_has_extra(vtile, pextra)
1700 && is_extra_caused_by(pextra, EC_ROAD)) {
1701 BV_SET(tile_packet.extras, extra_index(pextra));
1702 send_edit_tile = TRUE;
1703 }
1704 } extra_type_iterate_end;
1705 break;
1706 case EBT_UNIT:
1707 unit_list_iterate(vtile->units, vunit) {
1708 value = utype_number(unit_type_get(vunit));
1709 owner = player_number(unit_owner(vunit));
1710 dsend_packet_edit_unit_create(my_conn, owner, tile, value, 1, 0);
1711 } unit_list_iterate_end;
1712 break;
1713 case EBT_CITY:
1714 vcity = tile_city(vtile);
1715 if (!vcity) {
1716 continue;
1717 }
1718 owner = player_number(city_owner(vcity));
1719 value = city_size_get(vcity);
1720 dsend_packet_edit_city_create(my_conn, owner, tile, value, 0);
1721 break;
1722 default:
1723 break;
1724 }
1725 } edit_buffer_type_iterate_end;
1726
1727 if (send_edit_tile) {
1728 send_packet_edit_tile(my_conn, &tile_packet);
1729 }
1730}
1731
1732/************************************************************************/
1735 void edit_buffer_paste(struct edit_buffer *ebuf, const struct tile *dest)
1736{
1737 struct connection *my_conn = &client.conn;
1738 const struct tile *origin, *ptile;
1739 int dx, dy;
1740
1741 if (!ebuf || !dest) {
1742 return;
1743 }
1744
1745 /* Calculate vector. */
1746 origin = edit_buffer_get_origin(ebuf);
1747 fc_assert_ret(origin != NULL);
1748 map_distance_vector(&dx, &dy, origin, dest);
1749
1750 connection_do_buffer(my_conn);
1751 tile_list_iterate(ebuf->vtiles, vtile) {
1752 int virt_x, virt_y;
1753
1754 index_to_map_pos(&virt_x, &virt_y, tile_index(vtile));
1755 ptile = map_pos_to_tile(&(wld.map), virt_x + dx, virt_y + dy);
1756 if (!ptile) {
1757 continue;
1758 }
1759 paste_tile(ebuf, vtile, ptile);
1760 } tile_list_iterate_end;
1761 connection_do_unbuffer(my_conn);
1762}
1763
1764/************************************************************************/
1767 struct edit_buffer *editor_get_copy_buffer(void)
1768{
1769 if (!editor) {
1770 return NULL;
1771 }
1772 return editor->copybuf;
1773}
1774
1775/************************************************************************/
1778 const char *editor_tool_get_mode_name(enum editor_tool_type ett,
1779 enum editor_tool_mode etm)
1780{
1781 bool value_erase;
1782
1783 value_erase = editor_tool_has_value_erase(ett);
1784
1785 switch (etm) {
1786 case ETM_PAINT:
1787 return _("Paint");
1788 break;
1789 case ETM_ERASE:
1790 if (value_erase) {
1791 return _("Erase Value");
1792 } else {
1793 return _("Erase");
1794 }
1795 break;
1796 case ETM_COPY:
1797 return _("Copy");
1798 break;
1799 case ETM_PASTE:
1800 return _("Paste");
1801 break;
1802 default:
1803 log_error("Unrecognized editor tool mode %d "
1804 "in editor_tool_get_mode_name().", etm);
1805 break;
1806 }
1807
1808 return "";
1809}
1810
1811/************************************************************************/
1815 const char *editor_get_mode_tooltip(enum editor_tool_mode etm)
1816{
1817 switch (etm) {
1818 case ETM_ERASE:
1819 return _("Toggle erase mode.\nShortcut: shift-d");
1820 break;
1821 case ETM_COPY:
1822 return _("Toggle copy mode.\nShortcut: shift-c");
1823 break;
1824 case ETM_PASTE:
1825 return _("Toggle paste mode.\nShortcut: shift-v");
1826 break;
1827 default:
1828 break;
1829 }
1830
1831 return NULL;
1832}
1833
1834/************************************************************************/
1837 struct sprite *editor_get_mode_sprite(enum editor_tool_mode etm)
1838{
1839 const struct editor_sprites *sprites;
1840
1841 sprites = get_editor_sprites(tileset);
1842 if (!sprites) {
1843 return NULL;
1844 }
1845
1846 switch (etm) {
1847 case ETM_PAINT:
1848 return sprites->brush;
1849 break;
1850 case ETM_ERASE:
1851 return sprites->erase;
1852 break;
1853 case ETM_COPY:
1854 return sprites->copy;
1855 break;
1856 case ETM_PASTE:
1857 return sprites->paste;
1858 break;
1859 default:
1860 break;
1861 }
1862
1863 return NULL;
1864}
1865
1866/************************************************************************/
1870 int edit_buffer_get_status_string(const struct edit_buffer *ebuf,
1871 char *buf, int buflen)
1872{
1873 int ret, total;
1874 const char *fmt;
1875
1876 if (!buf || buflen < 1) {
1877 return 0;
1878 }
1879
1880 ret = fc_strlcpy(buf, _("Buffer empty."), buflen);
1881 if (!ebuf || !ebuf->vtiles) {
1882 return ret;
1883 }
1884
1885 total = tile_list_size(ebuf->vtiles);
1886 if (total > 0) {
1887 fmt = PL_("%d tile copied.", "%d tiles copied.", total);
1888 ret = fc_snprintf(buf, buflen, fmt, total);
1889 }
1890
1891 return ret;
1892}
1893
1894/************************************************************************/
1898 void edit_buffer_set_origin(struct edit_buffer *ebuf,
1899 const struct tile *ptile)
1900{
1901 if (!ebuf) {
1902 return;
1903 }
1904 ebuf->origin = ptile;
1905}
1906
1907/************************************************************************/
1910 const struct tile *edit_buffer_get_origin(const struct edit_buffer *ebuf)
1911{
1912 if (!ebuf) {
1913 return NULL;
1914 }
1915 return ebuf->origin;
1916}
1917
1918/************************************************************************/
1921 bool edit_buffer_has_type(const struct edit_buffer *ebuf, int type)
1922{
1923 if (!ebuf) {
1924 return FALSE;
1925 }
1926 return ebuf->type_flags & type;
1927}
1928
1929/************************************************************************/
1934 const struct tile *editor_get_selection_center(void)
1935{
1936 int count;
1937 const struct tile *origin, *center;
1938 int dx, dy, cx, cy;
1939 int xsum = 0, ysum = 0;
1940
1941 if (!editor || !editor->selected_tile_table) {
1942 return NULL;
1943 }
1944
1945 count = tile_hash_size(editor->selected_tile_table);
1946 if (count < 1) {
1947 return NULL;
1948 }
1949
1950 origin = map_pos_to_tile(&(wld.map), 0, 0);
1951 tile_hash_iterate(editor->selected_tile_table, ptile) {
1952 map_distance_vector(&dx, &dy, origin, ptile);
1953 xsum += dx;
1954 ysum += dy;
1955 } tile_hash_iterate_end;
1956
1957 cx = xsum / count;
1958 cy = ysum / count;
1959 center = map_pos_to_tile(&(wld.map), cx, cy);
1960
1961 return center;
1962}
base_count
Base_type_id base_count(void)
Definition base.c:109
bitvector.h
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
canvas_y
struct canvas int int canvas_y
Definition canvas_g.h:43
canvas_x
struct canvas int canvas_x
Definition canvas_g.h:43
city_has_building
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1207
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1106
create_city_virtual
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3331
city_size_set
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1149
city_add_improvement
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3258
city_size_get
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
city_owner
#define city_owner(_pcity_)
Definition city.h:543
client_is_global_observer
bool client_is_global_observer(void)
Definition client_main.c:1346
client_player_number
int client_player_number(void)
Definition client_main.c:1354
client
struct civclient client
Definition client_main.c:149
client_has_player
bool client_has_player(void)
Definition client_main.c:1365
client_main.h
client_player
#define client_player()
Definition client_main.h:106
climap.h
can_conn_edit
bool can_conn_edit(const struct connection *pconn)
Definition connection.c:510
connection_do_buffer
void connection_do_buffer(struct connection *pc)
Definition connection.c:323
connection_do_unbuffer
void connection_do_unbuffer(struct connection *pc)
Definition connection.c:335
control.h
punit
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:73
editgui_g.h
id
int int id
Definition editgui_g.h:28
edit_buffer_get_status_string
int edit_buffer_get_status_string(const struct edit_buffer *ebuf, char *buf, int buflen)
Definition editor.c:1870
editor_is_active
bool editor_is_active(void)
Definition editor.c:346
editor_selection_remove
void editor_selection_remove(const struct tile *ptile)
Definition editor.c:1106
edit_buffer_has_type
bool edit_buffer_has_type(const struct edit_buffer *ebuf, int type)
Definition editor.c:1921
editor_tool_get_size
int editor_tool_get_size(enum editor_tool_type ett)
Definition editor.c:1218
paste_tile
static void paste_tile(struct edit_buffer *ebuf, const struct tile *vtile, const struct tile *ptile_dest)
Definition editor.c:1645
editor_set_tool
void editor_set_tool(enum editor_tool_type ett)
Definition editor.c:270
editor_mouse_button_press
void editor_mouse_button_press(int canvas_x, int canvas_y, int button, int modifiers)
Definition editor.c:661
editor_set_current_tile
void editor_set_current_tile(const struct tile *ptile)
Definition editor.c:1016
editor_mouse_move
void editor_mouse_move(int canvas_x, int canvas_y, int modifiers)
Definition editor.c:866
editor_tool_get_mode
enum editor_tool_mode editor_tool_get_mode(enum editor_tool_type ett)
Definition editor.c:335
editor_tool_has_value_erase
bool editor_tool_has_value_erase(enum editor_tool_type ett)
Definition editor.c:1377
editor_tool_set_count
void editor_tool_set_count(enum editor_tool_type ett, int count)
Definition editor.c:1263
editor_tool_toggle_mode
void editor_tool_toggle_mode(enum editor_tool_type ett, enum editor_tool_mode etm)
Definition editor.c:1041
tool_init
static void tool_init(enum editor_tool_type ett, const char *name, int flags, const char *tooltip)
Definition editor.c:151
editor_selection_add
void editor_selection_add(const struct tile *ptile)
Definition editor.c:1095
editor_tool_get_value_name
const char * editor_tool_get_value_name(enum editor_tool_type emt, int value)
Definition editor.c:1172
editor_notify_edit_finished
void editor_notify_edit_finished(void)
Definition editor.c:897
editor_init
void editor_init(void)
Definition editor.c:193
editor_tool_get_value
int editor_tool_get_value(enum editor_tool_type ett)
Definition editor.c:409
editor_end_selection_rectangle
static void editor_end_selection_rectangle(int canvas_x, int canvas_y)
Definition editor.c:722
edit_buffer_new
struct edit_buffer * edit_buffer_new(int type_flags)
Definition editor.c:1433
editor_get_copy_buffer
struct edit_buffer * editor_get_copy_buffer(void)
Definition editor.c:1767
editor_tool_set_applied_player
void editor_tool_set_applied_player(enum editor_tool_type ett, int player_no)
Definition editor.c:1352
editor_tool_get_mode_name
const char * editor_tool_get_mode_name(enum editor_tool_type ett, enum editor_tool_mode etm)
Definition editor.c:1778
editor_clear
void editor_clear(void)
Definition editor.c:246
editor_tool_cycle_mode
void editor_tool_cycle_mode(enum editor_tool_type ett)
Definition editor.c:1058
editor_grab_applied_player
static void editor_grab_applied_player(const struct tile *ptile)
Definition editor.c:465
editor_tool_get_count
int editor_tool_get_count(enum editor_tool_type ett)
Definition editor.c:1252
edit_buffer_get_origin
const struct tile * edit_buffer_get_origin(const struct edit_buffer *ebuf)
Definition editor.c:1910
edit_buffer_copy
void edit_buffer_copy(struct edit_buffer *ebuf, const struct tile *ptile)
Definition editor.c:1505
editor_selection_count
int editor_selection_count(void)
Definition editor.c:1388
editor_tool_set_size
void editor_tool_set_size(enum editor_tool_type ett, int size)
Definition editor.c:1229
editor_get_mode_tooltip
const char * editor_get_mode_tooltip(enum editor_tool_mode etm)
Definition editor.c:1815
editor_tool_is_usable
bool editor_tool_is_usable(enum editor_tool_type ett)
Definition editor.c:359
editor_get_tool
enum editor_tool_type editor_get_tool(void)
Definition editor.c:286
editor_tool_has_applied_player
bool editor_tool_has_applied_player(enum editor_tool_type ett)
Definition editor.c:1365
editor_tool_has_size
bool editor_tool_has_size(enum editor_tool_type ett)
Definition editor.c:1207
edit_buffer_clear
void edit_buffer_clear(struct edit_buffer *ebuf)
Definition editor.c:1470
selection_modes
selection_modes
Definition editor.c:47
SELECTION_MODE_ADD
@ SELECTION_MODE_ADD
Definition editor.c:49
SELECTION_MODE_REMOVE
@ SELECTION_MODE_REMOVE
Definition editor.c:50
SELECTION_MODE_NEW
@ SELECTION_MODE_NEW
Definition editor.c:48
editor_tool_set_value
void editor_tool_set_value(enum editor_tool_type ett, int value)
Definition editor.c:397
editor_tool_has_value
bool editor_tool_has_value(enum editor_tool_type ett)
Definition editor.c:385
popup_properties
static void popup_properties(struct tile *ptile)
Definition editor.c:631
editor_tool_get_tooltip
const char * editor_tool_get_tooltip(enum editor_tool_type ett)
Definition editor.c:1327
editor_selection_clear
void editor_selection_clear(void)
Definition editor.c:1084
editor_mouse_button_release
void editor_mouse_button_release(int canvas_x, int canvas_y, int button, int modifiers)
Definition editor.c:798
editor_grab_tool
static void editor_grab_tool(const struct tile *ptile)
Definition editor.c:497
tile_really_has_any_specials
static bool tile_really_has_any_specials(const struct tile *ptile)
Definition editor.c:446
edit_buffer_copy_square
void edit_buffer_copy_square(struct edit_buffer *ebuf, const struct tile *center, int radius)
Definition editor.c:1488
editor_start_selection_rectangle
static void editor_start_selection_rectangle(int canvas_x, int canvas_y)
Definition editor.c:422
editor_tool_get_sprite
struct sprite * editor_tool_get_sprite(enum editor_tool_type ett)
Definition editor.c:1275
editor_get_current_tile
const struct tile * editor_get_current_tile(void)
Definition editor.c:1028
editor_apply_tool_to_selection
void editor_apply_tool_to_selection(void)
Definition editor.c:1128
editor_apply_tool
void editor_apply_tool(const struct tile *ptile, bool part_of_selection)
Definition editor.c:909
editor_tile_is_selected
bool editor_tile_is_selected(const struct tile *ptile)
Definition editor.c:1117
edit_buffer_set_origin
void edit_buffer_set_origin(struct edit_buffer *ebuf, const struct tile *ptile)
Definition editor.c:1898
editor_free
void editor_free(void)
Definition editor.c:257
can_edit_tile_properties
static bool can_edit_tile_properties(struct tile *ptile)
Definition editor.c:621
edit_buffer_paste
void edit_buffer_paste(struct edit_buffer *ebuf, const struct tile *dest)
Definition editor.c:1735
editor_get_selection_center
const struct tile * editor_get_selection_center(void)
Definition editor.c:1934
editor_tool_flags
editor_tool_flags
Definition editor.c:53
ETF_NO_FLAGS
@ ETF_NO_FLAGS
Definition editor.c:54
ETF_HAS_APPLIED_PLAYER
@ ETF_HAS_APPLIED_PLAYER
Definition editor.c:58
ETF_HAS_SIZE
@ ETF_HAS_SIZE
Definition editor.c:56
ETF_HAS_VALUE_ERASE
@ ETF_HAS_VALUE_ERASE
Definition editor.c:59
ETF_HAS_COUNT
@ ETF_HAS_COUNT
Definition editor.c:57
ETF_HAS_VALUE
@ ETF_HAS_VALUE
Definition editor.c:55
editor_tool_has_mode
bool editor_tool_has_mode(enum editor_tool_type ett, enum editor_tool_mode etm)
Definition editor.c:313
editor_unit_virtual_create
struct unit * editor_unit_virtual_create(void)
Definition editor.c:1405
editor_draw_selrect
static void editor_draw_selrect(void)
Definition editor.c:780
editor_ruleset_changed
void editor_ruleset_changed(void)
Definition editor.c:180
editor_tool_get_applied_player
int editor_tool_get_applied_player(enum editor_tool_type ett)
Definition editor.c:1341
editor_tool_has_count
bool editor_tool_has_count(enum editor_tool_type ett)
Definition editor.c:1241
editor_get_mode_sprite
struct sprite * editor_get_mode_sprite(enum editor_tool_mode etm)
Definition editor.c:1837
editor_resize_selection_rectangle
static void editor_resize_selection_rectangle(int canvas_x, int canvas_y)
Definition editor.c:826
fill_tile_edit_packet
static void fill_tile_edit_packet(struct packet_edit_tile *packet, const struct tile *ptile)
Definition editor.c:1607
editor_tool_get_name
const char * editor_tool_get_name(enum editor_tool_type ett)
Definition editor.c:1159
tool_set_init_value
static void tool_set_init_value(enum editor_tool_type ett)
Definition editor.c:105
editor
static struct editor_state * editor
Definition editor.c:100
edit_buffer_free
void edit_buffer_free(struct edit_buffer *ebuf)
Definition editor.c:1451
editor_tool_set_mode
void editor_tool_set_mode(enum editor_tool_type ett, enum editor_tool_mode etm)
Definition editor.c:298
editor.h
editor_tool_mode
editor_tool_mode
Definition editor.h:52
ETM_PASTE
@ ETM_PASTE
Definition editor.h:56
NUM_EDITOR_TOOL_MODES
@ NUM_EDITOR_TOOL_MODES
Definition editor.h:58
ETM_ERASE
@ ETM_ERASE
Definition editor.h:54
ETM_PAINT
@ ETM_PAINT
Definition editor.h:53
ETM_COPY
@ ETM_COPY
Definition editor.h:55
EBT_RESOURCE
@ EBT_RESOURCE
Definition editor.h:157
EBT_CITY
@ EBT_CITY
Definition editor.h:162
EBT_UNIT
@ EBT_UNIT
Definition editor.h:161
EBT_BASE
@ EBT_BASE
Definition editor.h:159
EBT_ALL
@ EBT_ALL
Definition editor.h:165
EBT_ROAD
@ EBT_ROAD
Definition editor.h:160
EBT_TERRAIN
@ EBT_TERRAIN
Definition editor.h:156
EBT_SPECIAL
@ EBT_SPECIAL
Definition editor.h:158
edit_buffer_type_iterate_end
#define edit_buffer_type_iterate_end
Definition editor.h:195
edit_buffer_type_iterate
#define edit_buffer_type_iterate(ARG_ebuf, NAME_type)
Definition editor.h:184
MOUSE_BUTTON_LEFT
@ MOUSE_BUTTON_LEFT
Definition editor.h:126
MOUSE_BUTTON_RIGHT
@ MOUSE_BUTTON_RIGHT
Definition editor.h:128
MOUSE_BUTTON_MIDDLE
@ MOUSE_BUTTON_MIDDLE
Definition editor.h:127
NUM_OBJTYPES
@ NUM_OBJTYPES
Definition editor.h:33
EKM_CTRL
@ EKM_CTRL
Definition editor.h:120
EKM_SHIFT
@ EKM_SHIFT
Definition editor.h:118
EKM_ALT
@ EKM_ALT
Definition editor.h:119
EKM_NONE
@ EKM_NONE
Definition editor.h:117
editor_tool_type
editor_tool_type
Definition editor.h:36
ETT_ROAD
@ ETT_ROAD
Definition editor.h:40
ETT_TERRAIN_SPECIAL
@ ETT_TERRAIN_SPECIAL
Definition editor.h:39
ETT_UNIT
@ ETT_UNIT
Definition editor.h:42
ETT_VISION
@ ETT_VISION
Definition editor.h:44
ETT_STARTPOS
@ ETT_STARTPOS
Definition editor.h:46
NUM_EDITOR_TOOL_TYPES
@ NUM_EDITOR_TOOL_TYPES
Definition editor.h:49
ETT_CITY
@ ETT_CITY
Definition editor.h:43
ETT_COPYPASTE
@ ETT_COPYPASTE
Definition editor.h:47
ETT_TERRAIN_RESOURCE
@ ETT_TERRAIN_RESOURCE
Definition editor.h:38
ETT_MILITARY_BASE
@ ETT_MILITARY_BASE
Definition editor.h:41
ETT_TERRAIN
@ ETT_TERRAIN
Definition editor.h:37
extra_number
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
extra_by_number
struct extra_type * extra_by_number(int id)
Definition extras.c:175
extra_count
int extra_count(void)
Definition extras.c:145
extra_name_translation
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:291
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:297
is_extra_caused_by
#define is_extra_caused_by(e, c)
Definition extras.h:196
extra_index
#define extra_index(_e_)
Definition extras.h:177
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:315
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
EC_SPECIAL
#define EC_SPECIAL
Definition fc_types.h:968
MAX_EXTRA_TYPES
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
fcintl.h
PL_
#define PL_(String1, String2, n)
Definition fcintl.h:71
_
#define _(String)
Definition fcintl.h:67
game
struct civ_game game
Definition game.c:57
wld
struct world wld
Definition game.c:58
game.h
owner
struct city * owner
Definition citydlg.c:219
editgui_popup_properties
void editgui_popup_properties(const struct tile_list *tiles, int objtype)
Definition editgui.c:1874
editgui_refresh
void editgui_refresh(void)
Definition editgui.c:1795
flush_dirty
void flush_dirty(void)
Definition mapview.c:450
draw_selection_rectangle
void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
Definition mapview.c:728
tooltip
const char * tooltip
Definition repodlgs.c:1314
type
GType type
Definition repodlgs.c:1312
is_improvement
bool is_improvement(const struct impr_type *pimprove)
Definition improvement.c:783
improvement_iterate_end
#define improvement_iterate_end
Definition improvement.h:211
improvement_iterate
#define improvement_iterate(_p)
Definition improvement.h:205
name
const char * name
Definition inputfile.c:127
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
log_error
#define log_error(message,...)
Definition log.h:103
map_pos_to_tile
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:417
map_distance_vector
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1071
map.h
square_iterate
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:385
square_iterate_end
#define square_iterate_end
Definition map.h:388
MAP_TILE_OWNER_NULL
#define MAP_TILE_OWNER_NULL
Definition map.h:568
index_to_map_pos
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:227
recenter_button_pressed
void recenter_button_pressed(int canvas_x, int canvas_y)
Definition mapctrl_common.c:630
mapctrl_common.h
update_map_canvas_visible
void update_map_canvas_visible(void)
Definition mapview_common.c:1843
mapview
struct view mapview
Definition mapview_common.c:74
canvas_pos_to_tile
struct tile * canvas_pos_to_tile(float canvas_x, float canvas_y, float zoom)
Definition mapview_common.c:751
update_map_canvas
void update_map_canvas(int canvas_x, int canvas_y, int width, int height)
Definition mapview_common.c:1719
refresh_tile_mapcanvas
void refresh_tile_mapcanvas(struct tile *ptile, bool full_refresh, bool write_to_screen)
Definition mapview_common.c:494
gui_rect_iterate_end
#define gui_rect_iterate_end
Definition mapview_common.h:225
gui_rect_iterate
#define gui_rect_iterate(GRI_x0, GRI_y0, GRI_width, GRI_height, _t, _e, _c, _zoom)
Definition mapview_common.h:97
mapview_g.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
movement.h
packets.h
dsend_packet_edit_city_create
int dsend_packet_edit_city_create(struct connection *pc, int owner, int tile, int size, int tag)
Definition packets_gen.c:88804
dsend_packet_edit_city_remove
int dsend_packet_edit_city_remove(struct connection *pc, int id16, int id32)
Definition packets_gen.c:89112
dsend_packet_edit_startpos
int dsend_packet_edit_startpos(struct connection *pc, int id, bool removal, int tag)
Definition packets_gen.c:86012
dsend_packet_edit_unit_remove
int dsend_packet_edit_unit_remove(struct connection *pc, int owner, int tile, Unit_type_id type, int count)
Definition packets_gen.c:87036
dsend_packet_edit_unit_create
int dsend_packet_edit_unit_create(struct connection *pc, int owner, int tile, Unit_type_id type, int count, int tag)
Definition packets_gen.c:86766
dsend_packet_edit_tile_extra
int dsend_packet_edit_tile_extra(struct connection *pc, int tile, int extra_type_id, bool removal, int eowner, int size)
Definition packets_gen.c:85919
send_packet_edit_tile
int send_packet_edit_tile(struct connection *pc, const struct packet_edit_tile *packet)
Definition packets_gen.c:86466
send_packet_edit_check_tiles
int send_packet_edit_check_tiles(struct connection *pc)
Definition packets_gen.c:85234
dsend_packet_edit_tile_terrain
int dsend_packet_edit_tile_terrain(struct connection *pc, int tile, Terrain_type_id terrain, int size)
Definition packets_gen.c:85640
dsend_packet_edit_player_vision
int dsend_packet_edit_player_vision(struct connection *pc, int player, int tile, bool known, int size)
Definition packets_gen.c:93960
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:840
player_number
int player_number(const struct player *pplayer)
Definition player.c:828
road_count
Road_type_id road_count(void)
Definition road.c:50
MAX
#define MAX(x, y)
Definition shared.h:54
size
size_t size
Definition specvec.h:72
city
Definition city.h:309
city::id
int id
Definition city.h:315
city::tile
struct tile * tile
Definition city.h:311
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
civclient::conn
struct connection conn
Definition client_main.h:96
connection
Definition connection.h:141
edit_buffer
Definition editor.c:62
edit_buffer::origin
const struct tile * origin
Definition editor.c:65
edit_buffer::vtiles
struct tile_list * vtiles
Definition editor.c:64
edit_buffer::type_flags
int type_flags
Definition editor.c:63
editor_sprites
Definition tilespec.h:336
editor_sprites::terrain
struct sprite * terrain
Definition tilespec.h:344
editor_sprites::road
struct sprite * road
Definition tilespec.h:352
editor_sprites::city
struct sprite * city
Definition tilespec.h:348
editor_sprites::terrain_special
struct sprite * terrain_special
Definition tilespec.h:346
editor_sprites::vision
struct sprite * vision
Definition tilespec.h:349
editor_sprites::terrain_resource
struct sprite * terrain_resource
Definition tilespec.h:345
editor_sprites::copypaste
struct sprite * copypaste
Definition tilespec.h:342
editor_sprites::brush
struct sprite * brush
Definition tilespec.h:339
editor_sprites::startpos
struct sprite * startpos
Definition tilespec.h:343
editor_sprites::military_base
struct sprite * military_base
Definition tilespec.h:353
editor_sprites::copy
struct sprite * copy
Definition tilespec.h:340
editor_sprites::erase
struct sprite * erase
Definition tilespec.h:337
editor_sprites::paste
struct sprite * paste
Definition tilespec.h:341
editor_sprites::unit
struct sprite * unit
Definition tilespec.h:347
editor_state
Definition editor.c:79
editor_state::selected_tile_table
struct tile_hash * selected_tile_table
Definition editor.c:96
editor_state::selrect_active
bool selrect_active
Definition editor.c:86
editor_state::selrect_x
int selrect_x
Definition editor.c:89
editor_state::selection_mode
enum selection_modes selection_mode
Definition editor.c:94
editor_state::tools
struct editor_tool tools[NUM_EDITOR_TOOL_TYPES]
Definition editor.c:81
editor_state::copybuf
struct edit_buffer * copybuf
Definition editor.c:97
editor_state::tool_active
bool tool_active
Definition editor.c:84
editor_state::selrect_start_y
int selrect_start_y
Definition editor.c:88
editor_state::selrect_width
int selrect_width
Definition editor.c:91
editor_state::selrect_height
int selrect_height
Definition editor.c:92
editor_state::selrect_start_x
int selrect_start_x
Definition editor.c:87
editor_state::tool
enum editor_tool_type tool
Definition editor.c:80
editor_state::selrect_y
int selrect_y
Definition editor.c:90
editor_state::current_tile
const struct tile * current_tile
Definition editor.c:83
editor_tool
Definition editor.c:68
editor_tool::size
int size
Definition editor.c:71
editor_tool::flags
int flags
Definition editor.c:69
editor_tool::count
int count
Definition editor.c:72
editor_tool::mode
enum editor_tool_mode mode
Definition editor.c:70
editor_tool::tooltip
const char * tooltip
Definition editor.c:76
editor_tool::name
const char * name
Definition editor.c:74
editor_tool::applied_player_no
int applied_player_no
Definition editor.c:73
editor_tool::value
int value
Definition editor.c:75
extra_type
Definition extras.h:85
extra_type::flags
bv_extra_flags flags
Definition extras.h:128
packet_edit_tile
Definition packets_gen.h:1701
packet_edit_tile::resource
Resource_type_id resource
Definition packets_gen.h:1704
packet_edit_tile::eowner
int eowner
Definition packets_gen.h:1707
packet_edit_tile::label
char label[MAX_LEN_NAME]
Definition packets_gen.h:1708
packet_edit_tile::extras
bv_extras extras
Definition packets_gen.h:1703
packet_edit_tile::tile
int tile
Definition packets_gen.h:1702
packet_edit_tile::terrain
Terrain_type_id terrain
Definition packets_gen.h:1705
packet_ruleset_control::num_resource_types
int num_resource_types
Definition packets_gen.h:1463
player
Definition player.h:249
sprite
Definition sprite.h:22
terrain
Definition terrain.h:176
tile
Definition tile.h:49
tile::label
char * label
Definition tile.h:64
tile::index
int index
Definition tile.h:50
tile::units
struct unit_list * units
Definition tile.h:57
tile::extras_owner
struct player * extras_owner
Definition tile.h:62
tileset
Definition tilespec.c:459
unit_type
Definition unittype.h:481
unit
Definition unit.h:138
unit::hp
int hp
Definition unit.h:151
unit::homecity
int homecity
Definition unit.h:146
unit::veteran
int veteran
Definition unit.h:152
view::gui_x0
float gui_x0
Definition mapview_common.h:37
view::gui_y0
float gui_y0
Definition mapview_common.h:37
world::map
struct civ_map map
Definition world_object.h:38
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
fc_strlcpy
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:787
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
terrain_count
Terrain_type_id terrain_count(void)
Definition terrain.c:106
terrain_name_translation
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
terrain_by_number
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:144
terrain_number
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:135
tile_add_extra
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:940
tile_set_terrain
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:124
tile_virtual_destroy
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1018
tile_virtual_new
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:966
tile_set_resource
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:343
tile_get_known
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:386
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_set_worked
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
tile_index
#define tile_index(_pt_)
Definition tile.h:87
tile_hash_iterate
#define tile_hash_iterate(hash, ptile)
Definition tile.h:81
tile_resource
#define tile_resource(_tile)
Definition tile.h:101
TILE_UNKNOWN
@ TILE_UNKNOWN
Definition tile.h:35
tile_list_iterate
#define tile_list_iterate(tile_list, ptile)
Definition tile.h:72
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:109
tile_hash_iterate_end
#define tile_hash_iterate_end
Definition tile.h:83
tile_list_iterate_end
#define tile_list_iterate_end
Definition tile.h:74
tile_extras
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:119
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
tile_owner
#define tile_owner(_tile)
Definition tile.h:95
tileset_tile_height
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:728
tileset_tile_width
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:716
get_editor_sprites
const struct editor_sprites * get_editor_sprites(const struct tileset *t)
Definition tilespec.c:6649
tilespec.h
unit_virtual_create
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1613
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2405
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
utype_move_type
enum unit_move_type utype_move_type(const struct unit_type *punittype)
Definition unittype.c:1603
utype_count
Unit_type_id utype_count(void)
Definition unittype.c:80
unit_class_get
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2546
utype_by_number
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:112
utype_number
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:100
utype_name_translation
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1612
uclass_has_flag
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:753
mouse_zoom
float mouse_zoom
Definition zoom.c:28
map_zoom
float map_zoom
Definition zoom.c:25
zoom.h