Freeciv-3.1
Loading...
Searching...
No Matches
edithand.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/* utility */
21#include "bitvector.h"
22#include "capability.h"
23#include "fcintl.h"
24#include "log.h"
25#include "shared.h"
26#include "support.h"
27
28/* common */
29#include "events.h"
30#include "game.h"
31#include "government.h"
32#include "map.h"
33#include "movement.h"
34#include "nation.h"
35#include "terrain.h"
36#include "research.h"
37#include "unitlist.h"
38
39/* server */
40#include "aiiface.h"
41#include "citytools.h"
42#include "cityturn.h"
43#include "connecthand.h"
44#include "gamehand.h"
45#include <hand_gen.h> /* <> so looked from the build directory first. */
46#include "maphand.h"
47#include "plrhand.h"
48#include "notify.h"
49#include "sanitycheck.h"
50#include "stdinhand.h"
51#include "techtools.h"
52#include "unittools.h"
53
54/* server/generator */
55#include "mapgen_utils.h"
56
57/* server/savegame */
58#include "savemain.h"
59
60#include "edithand.h"
61
62/* Set if anything in a sequence of edits triggers the expensive
63 * assign_continent_numbers() check, which will be done once when the
64 * sequence is complete. */
66/* Hold pointers to tiles which were changed during the edit sequence,
67 * so that they can be sanity-checked when the sequence is complete
68 * and final global fix-ups have been done. */
69static struct tile_hash *modified_tile_table = NULL;
70
71/* Array of size player_slot_count() indexed by player
72 * number to tell whether a given player has fog of war
73 * disabled in edit mode. */
74static bool *unfogged_players;
75
76/************************************************************************/
79void edithand_init(void)
80{
81 if (NULL != modified_tile_table) {
82 tile_hash_destroy(modified_tile_table);
83 }
84 modified_tile_table = tile_hash_new();
85
87
88 if (unfogged_players != NULL) {
89 free(unfogged_players);
90 }
92}
93
94/************************************************************************/
97void edithand_free(void)
98{
99 if (NULL != modified_tile_table) {
100 tile_hash_destroy(modified_tile_table);
101 modified_tile_table = NULL;
102 }
103
104 if (unfogged_players != NULL) {
105 free(unfogged_players);
106 unfogged_players = NULL;
107 }
108}
109
110/************************************************************************/
113void edithand_send_initial_packets(struct conn_list *dest)
114{
116 struct packet_edit_startpos_full startpos_full;
117
118 if (NULL == dest) {
119 dest = game.est_connections;
120 }
121
122 /* Send map start positions. */
125 startpos.removal = FALSE;
126 startpos.tag = 0;
127
128 startpos_pack(psp, &startpos_full);
129
130 conn_list_iterate(dest, pconn) {
131 if (can_conn_edit(pconn)) {
133 send_packet_edit_startpos_full(pconn, &startpos_full);
134 }
137}
138
139/************************************************************************/
144{
149
150 /* FIXME: adv / ai phase handling like in check_terrain_change() */
151 }
152
153#ifdef SANITY_CHECKING
155 sanity_check_tile(ptile);
157#endif /* SANITY_CHECKING */
158 tile_hash_clear(modified_tile_table);
159}
160
161/************************************************************************/
165static void check_leaving_edit_mode(void)
166{
167 bool unfogged;
168
170 players_iterate(pplayer) {
171 unfogged = unfogged_players[player_number(pplayer)];
172 if (unfogged && game.info.fogofwar) {
174 } else if (!unfogged && !game.info.fogofwar) {
176 }
178
179 /* Clear the whole array. */
180 memset(unfogged_players, 0, player_slot_count() * sizeof(bool));
181
184}
185
186/************************************************************************/
189void handle_edit_mode(struct connection *pc, bool is_edit_mode)
190{
191 if (!can_conn_enable_editing(pc)) {
192 return;
193 }
194
195 if (!game.info.is_edit_mode && is_edit_mode) {
196 /* Someone could be cheating! Warn people. */
197 notify_conn(NULL, NULL, E_SETTING, ftc_editor,
198 _(" *** Server set to edit mode by %s! *** "),
199 conn_description(pc));
200 }
201
202 if (game.info.is_edit_mode && !is_edit_mode) {
203 notify_conn(NULL, NULL, E_SETTING, ftc_editor,
204 _(" *** Edit mode canceled by %s. *** "),
205 conn_description(pc));
206
208 }
209
210 if (game.info.is_edit_mode != is_edit_mode) {
211 game.info.is_edit_mode = is_edit_mode;
212
213 send_game_info(NULL);
215 }
216}
217
218/************************************************************************/
222static bool edit_tile_terrain_handling(struct tile *ptile,
223 struct terrain *pterrain,
224 bool send_info)
225{
226 struct terrain *old_terrain = tile_terrain(ptile);
227
228 if (old_terrain == pterrain
229 || (terrain_has_flag(pterrain, TER_NO_CITIES)
230 && NULL != tile_city(ptile))) {
231 return FALSE;
232 }
233
234 tile_change_terrain(ptile, pterrain);
235 fix_tile_on_terrain_change(ptile, old_terrain, FALSE);
236 tile_hash_insert(modified_tile_table, ptile, NULL);
237 if (need_to_reassign_continents(old_terrain, pterrain)) {
239 }
240
241 if (send_info) {
243 }
244
246
247 return TRUE;
248}
249
250/************************************************************************/
254static bool edit_tile_extra_handling(struct tile *ptile,
255 struct extra_type *pextra,
256 bool remove_mode, bool send_info)
257{
258 if (remove_mode) {
259 if (!tile_has_extra(ptile, pextra)) {
260 return FALSE;
261 }
262
263 if (!tile_extra_rm_apply(ptile, pextra)) {
264 return FALSE;
265 }
266
267 terrain_changed(ptile);
268
269 } else {
270 if (tile_has_extra(ptile, pextra)) {
271 return FALSE;
272 }
273
274 if (!tile_extra_apply(ptile, pextra)) {
275 return FALSE;
276 }
277
278 if (is_extra_caused_by(pextra, EC_RESOURCE)
279 && terrain_has_resource(ptile->terrain, pextra)) {
280 tile_set_resource(ptile, pextra);
281 }
282 }
283
284 if (send_info) {
286 }
287
289
290 return TRUE;
291}
292
293/************************************************************************/
301{
302 struct terrain *pterrain;
303 struct tile *ptile_center;
304
305 ptile_center = index_to_tile(&(wld.map), tile);
306 if (!ptile_center) {
307 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
308 _("Cannot edit the tile because %d is not a valid "
309 "tile index on this map!"), tile);
310 return;
311 }
312
313 pterrain = terrain_by_number(terrain);
314 if (!pterrain) {
315 notify_conn(pc->self, ptile_center, E_BAD_COMMAND, ftc_editor,
316 /* TRANS: ..." the tile <tile-coordinates> because"... */
317 _("Cannot modify terrain for the tile %s because "
318 "%d is not a valid terrain id."),
319 tile_link(ptile_center), terrain);
320 return;
321 }
322
324 /* This iterates outward, which gives any units that can't survive on
325 * changed terrain the best chance of survival. */
326 square_iterate(&(wld.map), ptile_center, size - 1, ptile) {
327 edit_tile_terrain_handling(ptile, pterrain, TRUE);
330}
331
332/************************************************************************/
337 int id, bool removal, int eowner, int size)
338{
339 struct tile *ptile_center;
340 struct player *plr_eowner;
341
342 ptile_center = index_to_tile(&(wld.map), tile);
343 if (!ptile_center) {
344 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
345 _("Cannot edit the tile because %d is not a valid "
346 "tile index on this map!"), tile);
347 return;
348 }
349
350 if (id < 0 || id >= game.control.num_extra_types) {
351 notify_conn(pc->self, ptile_center, E_BAD_COMMAND, ftc_editor,
352 /* TRANS: ..." the tile <tile-coordinates> because"... */
353 _("Cannot modify extras for the tile %s because "
354 "%d is not a valid extra id."),
355 tile_link(ptile_center), id);
356 return;
357 }
358
359 if (eowner != MAP_TILE_OWNER_NULL) {
360 plr_eowner = player_by_number(eowner);
361 } else {
362 plr_eowner = NULL;
363 }
364
366 square_iterate(&(wld.map), ptile_center, size - 1, ptile) {
367 ptile->extras_owner = plr_eowner;
368 edit_tile_extra_handling(ptile, extra_by_number(id), removal, TRUE);
371}
372
373/************************************************************************/
377 const struct packet_edit_tile *packet)
378{
379 struct tile *ptile;
380 struct player *eowner;
381 bool changed = FALSE;
382
383 ptile = index_to_tile(&(wld.map), packet->tile);
384 if (!ptile) {
385 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
386 _("Cannot edit the tile because %d is not a valid "
387 "tile index on this map!"), packet->tile);
388 return;
389 }
390
391 if (packet->eowner != MAP_TILE_OWNER_NULL) {
392 eowner = player_by_number(packet->eowner);
393 } else {
394 eowner = NULL;
395 }
396
397 /* Handle changes in extras. */
398 if (!BV_ARE_EQUAL(packet->extras, ptile->extras)) {
399 extra_type_iterate(pextra) {
400 if (edit_tile_extra_handling(ptile, pextra,
401 !BV_ISSET(packet->extras, extra_number(pextra)),
402 FALSE)) {
403 changed = TRUE;
404 }
406 }
407
408 if (ptile->extras_owner != eowner) {
409 ptile->extras_owner = eowner;
410 changed = TRUE;
411 }
412
413 /* Handle changes in label */
414 if (tile_set_label(ptile, packet->label)) {
415 changed = TRUE;
416 }
417
418 /* TODO: Handle more property edits. */
419
420
421 /* Send the new state to all affected. */
422 if (changed) {
424 send_tile_info(NULL, ptile, FALSE);
425 }
426
428}
429
430/************************************************************************/
435 Unit_type_id utid, int count, int tag)
436{
437 struct tile *ptile;
438 struct unit_type *punittype;
439 struct player *pplayer;
440 struct city *homecity;
441 struct unit *punit;
442 int id, i;
443
444 ptile = index_to_tile(&(wld.map), tile);
445 if (!ptile) {
446 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
447 _("Cannot create units because %d is not a valid "
448 "tile index on this map!"), tile);
449 return;
450 }
451
452 punittype = utype_by_number(utid);
453 if (!punittype) {
454 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
455 /* TRANS: ..." at <tile-coordinates> because"... */
456 _("Cannot create a unit at %s because the "
457 "given unit type id %d is invalid."),
458 tile_link(ptile), utid);
459 return;
460 }
461
462 pplayer = player_by_number(owner);
463 if (!pplayer) {
464 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
465 /* TRANS: ..." type <unit-type> at <tile-coordinates>"... */
466 _("Cannot create a unit of type %s at %s "
467 "because the given owner's player id %d is "
468 "invalid."), utype_name_translation(punittype),
469 tile_link(ptile), owner);
470 return;
471 }
472
473 if (utype_has_flag(punittype, UTYF_UNIQUE)) {
474 if (utype_player_already_has_this_unique(pplayer, punittype)) {
475 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
476 _("Cannot create another instance of unique unit type %s. "
477 "Player already has one such unit."),
478 utype_name_translation(punittype));
479 return;
480 }
481 if (count > 1) {
482 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
483 _("Cannot create multiple instances of unique unit type %s."),
484 utype_name_translation(punittype));
485 return;
486 }
487 }
488
489 if (is_non_allied_unit_tile(ptile, pplayer)
490 || (tile_city(ptile)
491 && !pplayers_allied(pplayer, city_owner(tile_city(ptile))))) {
492 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
493 /* TRANS: ..." type <unit-type> on enemy tile
494 * <tile-coordinates>"... */
495 _("Cannot create unit of type %s on enemy tile "
496 "%s."), utype_name_translation(punittype),
497 tile_link(ptile));
498 return;
499 }
500
501 if (!can_exist_at_tile(&(wld.map), punittype, ptile)) {
502 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
503 /* TRANS: ..." type <unit-type> on the terrain at
504 * <tile-coordinates>"... */
505 _("Cannot create a unit of type %s on the terrain "
506 "at %s."),
507 utype_name_translation(punittype), tile_link(ptile));
508 return;
509 }
510
511 if (count > 0 && !pplayer->is_alive) {
512 pplayer->is_alive = TRUE;
513 send_player_info_c(pplayer, NULL);
514 }
515
516 homecity = find_closest_city(ptile, NULL, pplayer, FALSE, FALSE, FALSE,
517 TRUE, FALSE, utype_class(punittype));
518 id = homecity ? homecity->id : 0;
519
521 map_show_circle(pplayer, ptile, punittype->vision_radius_sq);
522 for (i = 0; i < count; i++) {
523 /* As far as I can see create_unit is guaranteed to
524 * never return NULL. */
525 punit = create_unit(pplayer, ptile, punittype, 0, id, -1);
526 if (tag > 0) {
528 }
529 }
531}
532
533/************************************************************************/
538 int tile, Unit_type_id utid, int count)
539{
540 struct tile *ptile;
541 struct unit_type *punittype;
542 struct player *pplayer;
543 int i;
544
545 ptile = index_to_tile(&(wld.map), tile);
546 if (!ptile) {
547 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
548 _("Cannot remove units because %d is not a valid "
549 "tile index on this map!"), tile);
550 return;
551 }
552
553 punittype = utype_by_number(utid);
554 if (!punittype) {
555 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
556 /* TRANS: ..." at <tile-coordinates> because"... */
557 _("Cannot remove a unit at %s because the "
558 "given unit type id %d is invalid."),
559 tile_link(ptile), utid);
560 return;
561 }
562
563 pplayer = player_by_number(owner);
564 if (!pplayer) {
565 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
566 /* TRANS: ..." type <unit-type> at <tile-coordinates>
567 * because"... */
568 _("Cannot remove a unit of type %s at %s "
569 "because the given owner's player id %d is "
570 "invalid."), utype_name_translation(punittype),
571 tile_link(ptile), owner);
572 return;
573 }
574
575 i = 0;
577 if (i >= count) {
578 break;
579 }
580 if (unit_type_get(punit) != punittype
581 || unit_owner(punit) != pplayer) {
582 continue;
583 }
584 wipe_unit(punit, ULR_EDITOR, NULL);
585 i++;
587}
588
589/************************************************************************/
593 Unit_type_id id32)
594{
595 struct unit *punit;
596
597 if (!has_capability("ids32", pc->capability)) {
598 id32 = id16;
599 }
600
602 if (punit == NULL) {
603 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
604 _("No such unit (ID %d)."), id32);
605 return;
606 }
607
608 wipe_unit(punit, ULR_EDITOR, NULL);
609}
610
611/************************************************************************/
615 const struct packet_edit_unit *packet)
616{
617 const struct unit_type *putype;
618 struct unit *punit;
619 int id;
620 bool changed = FALSE;
621 int fuel, hp;
622
623 if (!has_capability("ids32", pc->capability)) {
624 id = packet->id16;
625 } else {
626 id = packet->id32;
627 }
628
630 if (punit == NULL) {
631 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
632 _("No such unit (ID %d)."), id);
633 return;
634 }
635
636 putype = unit_type_get(punit);
637
638 if (packet->moves_left != punit->moves_left) {
639 punit->moves_left = packet->moves_left;
640 changed = TRUE;
641 }
642
643 fuel = CLIP(0, packet->fuel, utype_fuel(putype));
644 if (fuel != punit->fuel) {
645 punit->fuel = fuel;
646 changed = TRUE;
647 }
648
649 if (packet->moved != punit->moved) {
650 punit->moved = packet->moved;
651 changed = TRUE;
652 }
653
654 if (packet->done_moving != punit->done_moving) {
655 punit->done_moving = packet->done_moving;
656 changed = TRUE;
657 }
658
659 hp = CLIP(1, packet->hp, putype->hp);
660 if (hp != punit->hp) {
661 punit->hp = hp;
662 changed = TRUE;
663 }
664
665 if (packet->veteran != punit->veteran) {
666 int v = packet->veteran;
667
668 if (utype_veteran_level(putype, v) == NULL) {
669 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
670 _("Invalid veteran level %d for unit %d (%s)."),
671 v, id, unit_link(punit));
672 } else {
673 punit->veteran = v;
674 changed = TRUE;
675 }
676 }
677
678 if (packet->stay != punit->stay) {
679 punit->stay = packet->stay;
680 changed = TRUE;
681 }
682
683 /* TODO: Handle more property edits. */
684
685
686 /* Send the new state to all affected. */
687 if (changed) {
688 send_unit_info(NULL, punit);
689 }
690}
691
692/************************************************************************/
697 int size, int tag)
698{
699 struct tile *ptile;
700 struct city *pcity;
701 struct player *pplayer;
702
703 ptile = index_to_tile(&(wld.map), tile);
704 if (!ptile) {
705 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
706 _("Cannot create a city because %d is not a valid "
707 "tile index on this map!"), tile);
708 return;
709 }
710
711 pplayer = player_by_number(owner);
712 if (!pplayer) {
713 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
714 /* TRANS: ..." at <tile-coordinates> because"... */
715 _("Cannot create a city at %s because the "
716 "given owner's player id %d is invalid"),
717 tile_link(ptile), owner);
718 return;
719
720 }
721
723
724 if (!create_city_for_player(pplayer, ptile, NULL)) {
725 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
726 /* TRANS: ..." at <tile-coordinates>." */
727 _("A city may not be built at %s."), tile_link(ptile));
729
730 return;
731 }
732
733 pcity = tile_city(ptile);
734
735 if (size > 1) {
736 /* FIXME: Slow and inefficient for large size changes. */
737 city_change_size(pcity, CLIP(1, size, MAX_CITY_SIZE), pplayer, NULL);
738 send_city_info(NULL, pcity);
739 }
740
741 if (tag > 0) {
742 dsend_packet_edit_object_created(pc, tag, pcity->id);
743 }
744
746}
747
748
749/************************************************************************/
753 const struct packet_edit_city *packet)
754{
755 struct tile *ptile;
756 struct city *pcity, *oldcity;
757 struct player *pplayer;
758 char buf[1024];
759 int id;
760 bool changed = FALSE;
761 bool need_game_info = FALSE;
762 bv_player need_player_info;
763 int cid;
764
765 if (!has_capability("ids32", pc->capability)) {
766 cid = packet->id16;
767 } else {
768 cid = packet->id32;
769 }
770
771 pcity = game_city_by_number(cid);
772 if (pcity == NULL) {
773 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
774 _("Cannot edit city with invalid city ID %d."),
775 cid);
776 return;
777 }
778
779 pplayer = city_owner(pcity);
780 ptile = city_tile(pcity);
781 BV_CLR_ALL(need_player_info);
782
783 /* Handle name change. */
784 if (0 != strcmp(pcity->name, packet->name)) {
785 if (!is_allowed_city_name(pplayer, packet->name, buf, sizeof(buf))) {
786 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
787 _("Cannot edit city name: %s"), buf);
788 } else {
789 city_name_set(pcity, packet->name);
790 changed = TRUE;
791 }
792 }
793
794 /* Handle size change. */
795 if (packet->size != city_size_get(pcity)) {
796 if (!(0 < packet->size && packet->size <= MAX_CITY_SIZE)) {
797 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
798 _("Invalid city size %d for city %s."),
799 packet->size, city_link(pcity));
800 } else {
801 /* FIXME: Slow and inefficient for large size changes. */
802 city_change_size(pcity, packet->size, NULL, NULL);
803 changed = TRUE;
804 }
805 }
806
807 if (packet->history != pcity->history) {
808 pcity->history = packet->history;
809 changed = TRUE;
810 }
811
812 /* Handle city improvement changes. */
813 improvement_iterate(pimprove) {
814 oldcity = NULL;
815 id = improvement_number(pimprove);
816
817 if (is_special_improvement(pimprove)) {
818 if (packet->built[id] >= 0) {
819 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
820 _("It is impossible for a city to have %s!"),
822 }
823 continue;
824 }
825
826 /* FIXME: game.info.great_wonder_owners and pplayer->wonders
827 * logic duplication with city_build_building. */
828
829 if (city_has_building(pcity, pimprove) && packet->built[id] < 0) {
830
831 city_remove_improvement(pcity, pimprove);
832 changed = TRUE;
833
834 } else if (!city_has_building(pcity, pimprove)
835 && packet->built[id] >= 0) {
836 struct player *old_owner = NULL;
837
838 oldcity = build_or_move_building(pcity, pimprove, &old_owner);
839 if (oldcity != pcity) {
840 BV_SET(need_player_info, player_index(pplayer));
841 }
842 if (oldcity && old_owner != pplayer) {
843 /* Great wonders make more changes. */
844 need_game_info = TRUE;
845 if (old_owner) {
846 BV_SET(need_player_info, player_index(old_owner));
847 }
848 }
849
850 if (oldcity) {
851 city_refresh_queue_add(oldcity);
852 }
853 changed = TRUE;
854 }
856
857 /* Handle food stock change. */
858 if (packet->food_stock != pcity->food_stock) {
859 int max = city_granary_size(city_size_get(pcity));
860 if (!(0 <= packet->food_stock && packet->food_stock <= max)) {
861 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
862 _("Invalid city food stock amount %d for city %s "
863 "(allowed range is %d to %d)."),
864 packet->food_stock, city_link(pcity), 0, max);
865 } else {
866 pcity->food_stock = packet->food_stock;
867 changed = TRUE;
868 }
869 }
870
871 /* Handle shield stock change. */
872 if (packet->shield_stock != pcity->shield_stock) {
873 int max = USHRT_MAX; /* Limited to uint16 by city info packet. */
874
875 if (!(0 <= packet->shield_stock && packet->shield_stock <= max)) {
876 notify_conn(pc->self, ptile, E_BAD_COMMAND, ftc_editor,
877 _("Invalid city shield stock amount %d for city %s "
878 "(allowed range is %d to %d)."),
879 packet->shield_stock, city_link(pcity), 0, max);
880 } else {
881 pcity->shield_stock = packet->shield_stock;
882 /* Make sure the shields stay if changing production back and forth */
883 pcity->before_change_shields = packet->shield_stock;
884 changed = TRUE;
885 }
886 }
887
888 /* TODO: Handle more property edits. */
889
890
891 if (changed) {
895
896 /* FIXME: city_refresh_queue_processing only sends to city owner? */
897 send_city_info(NULL, pcity);
898
900 }
901
902 /* Update wonder infos. */
903 if (need_game_info) {
904 send_game_info(NULL);
905 }
906 if (BV_ISSET_ANY(need_player_info)) {
907 players_iterate(aplayer) {
908 if (BV_ISSET(need_player_info, player_index(aplayer))) {
909 /* No need to send to detached connections. */
910 send_player_info_c(aplayer, NULL);
911 }
913 }
914}
915
916/************************************************************************/
919void handle_edit_player_create(struct connection *pc, int tag)
920{
921 struct player *pplayer;
922 struct nation_type *pnation;
923 struct research *presearch;
924 int existing = player_count();
925
926 if (existing >= player_slot_count()) {
927 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
928 _("No more players can be added because the maximum "
929 "number of players (%d) has been reached."),
931 return;
932 }
933
934 if (existing >= game.server.max_players) {
935 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
936 _("No more players can be added because there's "
937 "already maximum number of players allowed by maxplayers setting (value %d)"),
939 return;
940 }
941
942 if (existing >= nation_count() ) {
943 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
944 _("No more players can be added because there are "
945 "no available nations (%d used)."),
946 nation_count());
947 return;
948 }
949
950 pnation = pick_a_nation(NULL, TRUE, TRUE, NOT_A_BARBARIAN);
951 if (!pnation) {
952 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
953 _("Player cannot be created because random nation "
954 "selection failed."));
955 return;
956 }
957
959 NULL, FALSE);
960 if (!pplayer) {
961 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
962 _("Player creation failed."));
963 return;
964 }
965 server_player_init(pplayer, TRUE, TRUE);
966
967 player_nation_defaults(pplayer, pnation, TRUE);
968 if (game_was_started()) {
969 /* Find a color for the new player. */
971 }
973 pplayer->unassigned_user = TRUE;
974 pplayer->is_connected = FALSE;
975 pplayer->government = init_government_of_nation(pnation);
976 pplayer->server.got_first_city = FALSE;
977
978 pplayer->economic.gold = 0;
979 pplayer->economic.infra_points = 0;
981
982 presearch = research_get(pplayer);
983 init_tech(presearch, TRUE);
984 give_initial_techs(presearch, 0);
985
986 send_player_all_c(pplayer, NULL);
987 /* Send research info after player info, else the client will complain
988 * about invalid team. */
989 send_research_info(presearch, NULL);
990 if (tag > 0) {
992 }
993}
994
995/************************************************************************/
998void handle_edit_player_remove(struct connection *pc, int id)
999{
1000 struct player *pplayer;
1001
1002 pplayer = player_by_number(id);
1003 if (pplayer == NULL) {
1004 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1005 _("No such player (ID %d)."), id);
1006 return;
1007 }
1008
1009 /* Don't use conn_list_iterate here because connection_detach() can be
1010 * recursive and free the next connection pointer. */
1011 while (conn_list_size(pplayer->connections) > 0) {
1012 connection_detach(conn_list_get(pplayer->connections, 0), FALSE);
1013 }
1014
1015 kill_player(pplayer);
1016 server_remove_player(pplayer);
1017}
1018
1019/************************************************************************/
1023 const struct packet_edit_player *packet)
1024{
1025 struct player *pplayer;
1026 bool changed = FALSE, update_research = FALSE;
1027 struct nation_type *pnation;
1028 struct research *research;
1029 enum tech_state known;
1030 struct government *gov;
1031
1032 pplayer = player_by_number(packet->id);
1033 if (!pplayer) {
1034 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1035 _("Cannot edit player with invalid player ID %d."),
1036 packet->id);
1037 return;
1038 }
1039
1040 research = research_get(pplayer);
1041
1042
1043 /* Handle player name change. */
1044 if (0 != strcmp(packet->name, player_name(pplayer))) {
1045 char error_buf[256];
1046
1047 if (server_player_set_name_full(pc, pplayer, NULL, packet->name,
1048 error_buf, sizeof(error_buf))) {
1049 changed = TRUE;
1050 } else {
1051 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1052 _("Cannot change name of player (%d) '%s' to '%s': %s"),
1053 player_number(pplayer), player_name(pplayer),
1054 packet->name, error_buf);
1055 }
1056 }
1057
1058 /* Handle nation change. */
1059 pnation = nation_by_number(packet->nation);
1060 if (nation_of_player(pplayer) != pnation) {
1061 if (pnation == NULL) {
1062 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1063 _("Cannot change nation for player %d (%s) "
1064 "because the given nation ID %d is invalid."),
1065 player_number(pplayer), player_name(pplayer),
1066 packet->nation);
1067 } else if (pnation->player != NULL) {
1068 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1069 _("Cannot change nation for player %d (%s) "
1070 "to nation %d (%s) because that nation is "
1071 "already assigned to player %d (%s)."),
1072 player_number(pplayer), player_name(pplayer),
1073 packet->nation, nation_plural_translation(pnation),
1074 player_number(pnation->player),
1075 player_name(pnation->player));
1076 } else if (!nation_is_in_current_set(pnation)) {
1077 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1078 _("Cannot change nation for player %d (%s) "
1079 "to nation %d (%s) because that nation is "
1080 "not in the current nation set."),
1081 player_number(pplayer), player_name(pplayer),
1082 packet->nation, nation_plural_translation(pnation));
1083 } else if (pplayer->ai_common.barbarian_type
1084 != nation_barbarian_type(pnation)
1085 || (!is_barbarian(pplayer) && !is_nation_playable(pnation))) {
1086 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1087 _("Cannot change nation for player %d (%s) "
1088 "to nation %d (%s) because that nation is "
1089 "unsuitable for this player."),
1090 player_number(pplayer), player_name(pplayer),
1091 packet->nation, nation_plural_translation(pnation));
1092 } else {
1093 changed = player_set_nation(pplayer, pnation);
1094 }
1095 }
1096
1097 /* Handle a change in research progress. */
1098 if (packet->bulbs_researched != research->bulbs_researched) {
1100 changed = TRUE;
1101 update_research = TRUE;
1102 }
1103
1104 /* Handle a change in known inventions. */
1106 known = research_invention_state(research, tech);
1107 if ((packet->inventions[tech] && known == TECH_KNOWN)
1108 || (!packet->inventions[tech] && known != TECH_KNOWN)) {
1109 continue;
1110 }
1111 if (packet->inventions[tech]) {
1112 /* FIXME: Side-effect modifies game.info.global_advances. */
1113 research_invention_set(research, tech, TECH_KNOWN);
1115 } else {
1116 research_invention_set(research, tech, TECH_UNKNOWN);
1118 }
1119 changed = TRUE;
1120 update_research = TRUE;
1122
1123 /* Handle a change in the player's gold. */
1124 if (packet->gold != pplayer->economic.gold) {
1125 if (!(0 <= packet->gold && packet->gold <= 1000000)) {
1126 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1127 _("Cannot set gold for player %d (%s) because "
1128 "the value %d is outside the allowed range."),
1129 player_number(pplayer), player_name(pplayer),
1130 packet->gold);
1131 } else {
1132 pplayer->economic.gold = packet->gold;
1133 changed = TRUE;
1134 }
1135 }
1136
1137 /* Handle player government change */
1138 gov = government_by_number(packet->government);
1139 if (gov != pplayer->government) {
1141 government_change(pplayer, gov, FALSE);
1142 } else {
1143 int turns = revolution_length(gov, pplayer);
1144
1145 if (turns >= 0) {
1146 pplayer->government = gov;
1147 pplayer->revolution_finishes = game.info.turn + turns;
1148 }
1149 }
1150
1151 changed = TRUE;
1152 }
1153
1154 if (packet->scenario_reserved) {
1155 if (!player_has_flag(pplayer, PLRF_SCENARIO_RESERVED)) {
1156 changed = TRUE;
1157 BV_SET(pplayer->flags, PLRF_SCENARIO_RESERVED);
1158 }
1159 } else {
1160 if (player_has_flag(pplayer, PLRF_SCENARIO_RESERVED)) {
1161 changed = TRUE;
1162 BV_CLR(pplayer->flags, PLRF_SCENARIO_RESERVED);
1163 }
1164 }
1165
1166 /* TODO: Handle more property edits. */
1167
1168 if (update_research) {
1169 Tech_type_id current, goal;
1170
1172
1173 /* FIXME: Modifies struct research directly. */
1174
1175 current = research->researching;
1176 goal = research->tech_goal;
1177
1178 if (current != A_UNSET) {
1179 if (current != A_FUTURE) {
1180 known = research_invention_state(research, current);
1181 if (known != TECH_PREREQS_KNOWN) {
1183 }
1184 } else {
1185 /* Future Tech is legal only if all techs are known */
1187 known = research_invention_state(research, tech_i);
1188 if (known != TECH_KNOWN) {
1190 break;
1191 }
1193 }
1194 }
1195 if (goal != A_UNSET) {
1196 if (goal != A_FUTURE) {
1197 known = research_invention_state(research, goal);
1198 if (known == TECH_KNOWN) {
1200 }
1201 }
1202 }
1203 changed = TRUE;
1204
1205 /* Inform everybody about global advances */
1206 send_game_info(NULL);
1208 }
1209
1210 if (changed) {
1211 send_player_all_c(pplayer, NULL);
1212 }
1213}
1214
1215/************************************************************************/
1218void handle_edit_player_vision(struct connection *pc, int plr_no,
1219 int tile, bool known, int size)
1220{
1221 struct player *pplayer;
1222 struct tile *ptile_center;
1223
1224 ptile_center = index_to_tile(&(wld.map), tile);
1225 if (!ptile_center) {
1226 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1227 _("Cannot edit vision because %d is not a valid "
1228 "tile index on this map!"), tile);
1229 return;
1230 }
1231
1232 pplayer = player_by_number(plr_no);
1233 if (!pplayer) {
1234 notify_conn(pc->self, ptile_center, E_BAD_COMMAND, ftc_editor,
1235 /* TRANS: ..." at <tile-coordinates> because"... */
1236 _("Cannot edit vision for the tile at %s because "
1237 "given player id %d is invalid."),
1238 tile_link(ptile_center), plr_no);
1239 return;
1240 }
1241
1243 square_iterate(&(wld.map), ptile_center, size - 1, ptile) {
1244
1245 if (!known) {
1246 struct city *pcity = tile_city(ptile);
1247 bool cannot_make_unknown = FALSE;
1248
1249 if (pcity && city_owner(pcity) == pplayer) {
1250 continue;
1251 }
1252
1253 unit_list_iterate(ptile->units, punit) {
1254 if (unit_owner(punit) == pplayer
1255 || really_gives_vision(pplayer, unit_owner(punit))) {
1256 cannot_make_unknown = TRUE;
1257 break;
1258 }
1260
1261 if (cannot_make_unknown) {
1262 continue;
1263 }
1264
1265 /* The client expects tiles which become unseen to
1266 * contain no units (client/packhand.c +2368).
1267 * So here we tell it to remove units that do
1268 * not give it vision. */
1269 unit_list_iterate(ptile->units, punit) {
1270 conn_list_iterate(pplayer->connections, pconn) {
1274 }
1275
1276 if (known) {
1277 map_show_tile(pplayer, ptile);
1278 } else {
1279 map_hide_tile(pplayer, ptile);
1280 }
1283}
1284
1285/************************************************************************/
1294
1295/************************************************************************/
1298void handle_edit_city_remove(struct connection *pc, int id16, int id32)
1299{
1300 struct city *pcity;
1301
1302 if (!has_capability("ids32", pc->capability)) {
1303 id32 = id16;
1304 }
1305
1306 pcity = game_city_by_number(id32);
1307 if (pcity == NULL) {
1308 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1309 _("No such city (ID %d)."), id32);
1310 return;
1311 }
1312
1313 remove_city(pcity);
1314}
1315
1316/************************************************************************/
1323
1324/************************************************************************/
1329void handle_edit_toggle_fogofwar(struct connection *pc, int plr_no)
1330{
1331 struct player *pplayer;
1332
1333 if (!game.info.fogofwar) {
1334 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1335 _("Cannot toggle fog-of-war when it is already "
1336 "disabled."));
1337 return;
1338 }
1339
1340 pplayer = player_by_number(plr_no);
1341 if (!pplayer) {
1342 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1343 _("Cannot toggle fog-of-war for invalid player ID %d."),
1344 plr_no);
1345 return;
1346 }
1347
1349 if (unfogged_players[player_number(pplayer)]) {
1350 enable_fog_of_war_player(pplayer);
1352 } else {
1355 }
1357}
1358
1359/************************************************************************/
1363 const struct packet_edit_startpos *packet)
1364{
1365 struct tile *ptile = index_to_tile(&(wld.map), packet->id);
1366 bool changed;
1367
1368 /* Check. */
1369 if (NULL == ptile) {
1370 notify_conn(pconn->self, NULL, E_BAD_COMMAND, ftc_editor,
1371 _("Invalid tile index %d for start position."), packet->id);
1372 return;
1373 }
1374
1375 /* Handle. */
1376 if (packet->removal) {
1377 changed = map_startpos_remove(ptile);
1378 } else {
1379 if (NULL != map_startpos_get(ptile)) {
1380 changed = FALSE;
1381 } else {
1382 map_startpos_new(ptile);
1383 changed = TRUE;
1384 }
1385 }
1386
1387 /* Notify. */
1388 if (changed) {
1390 if (can_conn_edit(aconn)) {
1391 send_packet_edit_startpos(aconn, packet);
1392 }
1394 }
1395}
1396
1397/************************************************************************/
1401 const struct packet_edit_startpos_full *
1402 packet)
1403{
1404 struct tile *ptile = index_to_tile(&(wld.map), packet->id);
1405 struct startpos *psp;
1406
1407 /* Check. */
1408 if (NULL == ptile) {
1409 notify_conn(pconn->self, NULL, E_BAD_COMMAND, ftc_editor,
1410 _("Invalid tile index %d for start position."),
1411 packet->id);
1412 return;
1413 }
1414
1415 psp = map_startpos_get(ptile);
1416 if (NULL == psp) {
1417 notify_conn(pconn->self, ptile, E_BAD_COMMAND, ftc_editor,
1418 _("Cannot edit start position nations at (%d, %d) "
1419 "because there is no start position there."),
1420 TILE_XY(ptile));
1421 return;
1422 }
1423
1424 /* Handle. */
1425 if (startpos_unpack(psp, packet)) {
1426 /* Notify. */
1428 if (can_conn_edit(aconn)) {
1429 send_packet_edit_startpos_full(aconn, packet);
1430 }
1432 }
1433}
1434
1435/************************************************************************/
1439 const struct packet_edit_game *packet)
1440{
1441 bool changed = FALSE;
1442
1443 if (packet->scenario != game.scenario.is_scenario) {
1445 changed = TRUE;
1446 }
1447
1448 if (0 != strncmp(packet->scenario_name, game.scenario.name, 256)) {
1450 changed = TRUE;
1451 }
1452
1453 FC_STATIC_ASSERT(sizeof(packet->scenario_authors) == sizeof(game.scenario.authors),
1454 scen_authors_field_size_mismatch);
1455
1456 if (0 != strncmp(packet->scenario_authors, game.scenario.authors,
1457 sizeof(game.scenario.authors))) {
1459 changed = TRUE;
1460 }
1461
1462 if (packet->scenario_random != game.scenario.save_random) {
1464 changed = TRUE;
1465 }
1466
1467 if (packet->scenario_players != game.scenario.players) {
1469 changed = TRUE;
1470 }
1471
1474 changed = TRUE;
1475 }
1476
1479 changed = TRUE;
1480 }
1481
1482 if (packet->lake_flooding != game.scenario.lake_flooding) {
1484 changed = TRUE;
1485 }
1486
1487 if (packet->ruleset_locked != game.scenario.ruleset_locked) {
1489 changed = TRUE;
1490 }
1491
1492 if (changed) {
1493 send_scenario_info(NULL);
1494 send_game_info(NULL);
1495 }
1496}
1497
1498/************************************************************************/
1501void handle_edit_scenario_desc(struct connection *pc, const char *scenario_desc)
1502{
1503 if (0 != strncmp(scenario_desc, game.scenario_desc.description,
1504 MAX_LEN_PACKET)) {
1505 sz_strlcpy(game.scenario_desc.description, scenario_desc);
1507 }
1508}
1509
1510/************************************************************************/
1513void handle_save_scenario(struct connection *pc, const char *name)
1514{
1515 if (pc->access_level != ALLOW_HACK) {
1516 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1517 _("No permissions to remotely save scenario."));
1518 return;
1519 }
1520
1521 if (!game.scenario.is_scenario) {
1522 /* Scenario information not available */
1523 notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor,
1524 _("Scenario information not set. Cannot save scenario."));
1525 return;
1526 }
1527
1528 /* Client initiated scenario saving is not handmade */
1530
1531 save_game(name, "Scenario", TRUE);
1532}
const char * default_ai_type_name(void)
Definition aiiface.c:262
#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_ISSET_ANY(vec)
Definition bitvector.h:109
#define BV_CLR(bv, bit)
Definition bitvector.h:86
bool has_capability(const char *cap, const char *capstr)
Definition capability.c:77
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1123
int city_granary_size(int city_size)
Definition city.c:2104
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1216
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3284
#define city_tile(_pcity_)
Definition city.h:544
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
#define city_owner(_pcity_)
Definition city.h:543
#define MAX_CITY_SIZE
Definition city.h:98
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2327
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:2932
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Definition citytools.c:854
bool is_allowed_city_name(struct player *pplayer, const char *cityname, char *error_buf, size_t bufsz)
Definition citytools.c:372
void remove_city(struct city *pcity)
Definition citytools.c:1684
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name)
Definition citytools.c:1656
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:200
bool city_change_size(struct city *pcity, citizens size, struct player *nationality, const char *reason)
Definition cityturn.c:1061
void city_refresh_queue_processing(void)
Definition cityturn.c:216
int cid
Definition climisc.h:31
void connection_detach(struct connection *pconn, bool remove_unused_player)
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:365
bool can_conn_edit(const struct connection *pconn)
Definition connection.c:510
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:355
bool can_conn_enable_editing(const struct connection *pconn)
Definition connection.c:520
const char * conn_description(const struct connection *pconn)
Definition connection.c:473
#define MAX_LEN_PACKET
Definition connection.h:56
#define conn_list_iterate(connlist, pconn)
Definition connection.h:113
#define conn_list_iterate_end
Definition connection.h:115
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
int int id
Definition editgui_g.h:28
void handle_edit_tile(struct connection *pc, const struct packet_edit_tile *packet)
Definition edithand.c:376
void handle_edit_scenario_desc(struct connection *pc, const char *scenario_desc)
Definition edithand.c:1501
void handle_edit_check_tiles(struct connection *pc)
Definition edithand.c:1319
void handle_edit_mode(struct connection *pc, bool is_edit_mode)
Definition edithand.c:189
void handle_edit_tile_terrain(struct connection *pc, int tile, Terrain_type_id terrain, int size)
Definition edithand.c:299
void handle_edit_player(struct connection *pc, const struct packet_edit_player *packet)
Definition edithand.c:1022
static bool need_continents_reassigned
Definition edithand.c:65
void edithand_send_initial_packets(struct conn_list *dest)
Definition edithand.c:113
static bool * unfogged_players
Definition edithand.c:74
static struct tile_hash * modified_tile_table
Definition edithand.c:69
void handle_edit_player_remove(struct connection *pc, int id)
Definition edithand.c:998
static bool edit_tile_terrain_handling(struct tile *ptile, struct terrain *pterrain, bool send_info)
Definition edithand.c:222
void edithand_free(void)
Definition edithand.c:97
void handle_edit_player_vision(struct connection *pc, int plr_no, int tile, bool known, int size)
Definition edithand.c:1218
void handle_edit_city(struct connection *pc, const struct packet_edit_city *packet)
Definition edithand.c:752
void edithand_init(void)
Definition edithand.c:79
void handle_edit_city_create(struct connection *pc, int owner, int tile, int size, int tag)
Definition edithand.c:696
void handle_edit_unit_remove_by_id(struct connection *pc, Unit_type_id id16, Unit_type_id id32)
Definition edithand.c:592
static bool edit_tile_extra_handling(struct tile *ptile, struct extra_type *pextra, bool remove_mode, bool send_info)
Definition edithand.c:254
void handle_edit_game(struct connection *pc, const struct packet_edit_game *packet)
Definition edithand.c:1438
void handle_edit_city_remove(struct connection *pc, int id16, int id32)
Definition edithand.c:1298
void handle_edit_unit_remove(struct connection *pc, int owner, int tile, Unit_type_id utid, int count)
Definition edithand.c:537
void handle_edit_toggle_fogofwar(struct connection *pc, int plr_no)
Definition edithand.c:1329
void handle_edit_startpos_full(struct connection *pconn, const struct packet_edit_startpos_full *packet)
Definition edithand.c:1400
static void check_leaving_edit_mode(void)
Definition edithand.c:165
void handle_edit_player_create(struct connection *pc, int tag)
Definition edithand.c:919
void handle_edit_recalculate_borders(struct connection *pc)
Definition edithand.c:1290
void handle_save_scenario(struct connection *pc, const char *name)
Definition edithand.c:1513
void handle_edit_tile_extra(struct connection *pc, int tile, int id, bool removal, int eowner, int size)
Definition edithand.c:336
void handle_edit_unit_create(struct connection *pc, int owner, int tile, Unit_type_id utid, int count, int tag)
Definition edithand.c:434
void handle_edit_unit(struct connection *pc, const struct packet_edit_unit *packet)
Definition edithand.c:614
static void check_edited_tile_terrains(void)
Definition edithand.c:143
void handle_edit_startpos(struct connection *pconn, const struct packet_edit_startpos *packet)
Definition edithand.c:1362
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
struct extra_type * extra_by_number(int id)
Definition extras.c:175
#define extra_type_iterate(_p)
Definition extras.h:291
#define extra_type_iterate_end
Definition extras.h:297
#define is_extra_caused_by(e, c)
Definition extras.h:196
int Tech_type_id
Definition fc_types.h:347
int Terrain_type_id
Definition fc_types.h:343
int Unit_type_id
Definition fc_types.h:352
#define _(String)
Definition fcintl.h:67
const char * tile_link(const struct tile *ptile)
const struct ft_color ftc_editor
const char * city_link(const struct city *pcity)
const char * unit_link(const struct unit *punit)
struct civ_game game
Definition game.c:57
struct world wld
Definition game.c:58
struct unit * game_unit_by_number(int id)
Definition game.c:111
struct city * game_city_by_number(int id)
Definition game.c:102
void send_scenario_description(struct conn_list *dest)
Definition gamehand.c:962
void send_scenario_info(struct conn_list *dest)
Definition gamehand.c:948
void send_game_info(struct conn_list *dest)
Definition gamehand.c:905
struct government * government_by_number(const Government_type_id gov)
Definition government.c:102
struct city * owner
Definition citydlg.c:219
bool is_special_improvement(const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
const char * name
Definition inputfile.c:127
#define FC_STATIC_ASSERT(cond, tag)
Definition log.h:235
struct startpos * map_startpos_get(const struct tile *ptile)
Definition map.c:1686
struct startpos * map_startpos_new(struct tile *ptile)
Definition map.c:1669
struct tile * startpos_tile(const struct startpos *psp)
Definition map.c:1479
bool startpos_pack(const struct startpos *psp, struct packet_edit_startpos_full *packet)
Definition map.c:1509
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:454
bool map_startpos_remove(struct tile *ptile)
Definition map.c:1702
bool startpos_unpack(struct startpos *psp, const struct packet_edit_startpos_full *packet)
Definition map.c:1529
#define map_startpos_iterate(NAME_psp)
Definition map.h:124
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:385
#define square_iterate_end
Definition map.h:388
#define map_startpos_iterate_end
Definition map.h:127
#define MAP_TILE_OWNER_NULL
Definition map.h:568
void assign_continent_numbers(void)
bool really_gives_vision(struct player *me, struct player *them)
Definition maphand.c:342
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:488
void send_all_known_tiles(struct conn_list *dest)
Definition maphand.c:441
bool need_to_reassign_continents(const struct terrain *oldter, const struct terrain *newter)
Definition maphand.c:1921
void disable_fog_of_war_player(struct player *pplayer)
Definition maphand.c:1759
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:760
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2708
void terrain_changed(struct tile *ptile)
Definition maphand.c:1940
void map_calculate_borders(void)
Definition maphand.c:2357
void fix_tile_on_terrain_change(struct tile *ptile, struct terrain *oldter, bool extend_rivers)
Definition maphand.c:1959
void enable_fog_of_war_player(struct player *pplayer)
Definition maphand.c:1735
void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
Definition maphand.c:856
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1427
void map_hide_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:812
#define fc_calloc(n, esz)
Definition mem.h:38
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:275
Nation_type_id nation_count(void)
Definition nation.c:506
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:474
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:199
const char * nation_plural_translation(const struct nation_type *pnation)
Definition nation.c:158
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:210
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:658
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:238
int send_packet_edit_startpos_full(struct connection *pc, const struct packet_edit_startpos_full *packet)
int dsend_packet_edit_object_created(struct connection *pc, int tag, int id)
int dsend_packet_unit_remove(struct connection *pc, int unit_id16, int unit_id32)
int send_packet_edit_startpos(struct connection *pc, const struct packet_edit_startpos *packet)
struct player * player_by_number(const int player_id)
Definition player.c:840
int player_count(void)
Definition player.c:808
int player_slot_count(void)
Definition player.c:411
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1954
int player_index(const struct player *pplayer)
Definition player.c:820
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:852
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
#define players_iterate_end
Definition player.h:535
#define players_iterate(_pplayer)
Definition player.h:530
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:983
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1723
void player_limit_to_max_rates(struct player *pplayer)
Definition plrhand.c:1886
bool server_player_set_name_full(const struct connection *caller, struct player *pplayer, const struct nation_type *pnation, const char *name, char *error_buf, size_t error_buf_len)
Definition plrhand.c:1997
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
Definition plrhand.c:2282
void kill_player(struct player *pplayer)
Definition plrhand.c:125
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1000
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1772
void government_change(struct player *pplayer, struct government *gov, bool revolution_finished)
Definition plrhand.c:336
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1450
void assign_player_colors(void)
Definition plrhand.c:1563
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2419
int revolution_length(struct government *gov, struct player *plr)
Definition plrhand.c:438
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Definition research.c:634
struct research * research_get(const struct player *pplayer)
Definition research.c:126
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
void research_update(struct research *presearch)
Definition research.c:499
#define sanity_check_tile(x)
Definition sanitycheck.h:42
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition savemain.c:142
#define CLIP(lower, current, upper)
Definition shared.h:57
size_t size
Definition specvec.h:72
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2510
bool game_was_started(void)
Definition srv_main.c:339
Definition city.h:309
int food_stock
Definition city.h:354
int history
Definition city.h:393
int id
Definition city.h:315
char * name
Definition city.h:310
int before_change_shields
Definition city.h:375
int shield_stock
Definition city.h:355
struct civ_game::@30::@34 server
struct packet_scenario_description scenario_desc
Definition game.h:88
struct packet_ruleset_control control
Definition game.h:83
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
struct packet_scenario_info scenario
Definition game.h:87
int max_players
Definition game.h:155
struct government * government_during_revolution
Definition game.h:94
enum cmdlevel access_level
Definition connection.h:182
struct conn_list * self
Definition connection.h:168
char capability[MAX_LEN_CAPSTR]
Definition connection.h:176
struct player * player
Definition nation.h:117
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]
char label[MAX_LEN_NAME]
char description[MAX_LEN_CONTENT]
char authors[MAX_LEN_PACKET/3]
enum barbarian_type barbarian_type
Definition player.h:128
int infra_points
Definition player.h:74
struct player_ai ai_common
Definition player.h:288
bv_plr_flags flags
Definition player.h:292
bool got_first_city
Definition player.h:320
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_connected
Definition player.h:296
int revolution_finishes
Definition player.h:273
struct government * government
Definition player.h:258
struct conn_list * connections
Definition player.h:298
bool is_alive
Definition player.h:268
struct player_economic economic
Definition player.h:284
struct player::@69::@71 server
bool unassigned_user
Definition player.h:253
Tech_type_id researching
Definition research.h:52
Tech_type_id tech_goal
Definition research.h:85
int techs_researched
Definition research.h:42
int bulbs_researched
Definition research.h:53
Definition map.c:41
Definition tile.h:49
bv_extras extras
Definition tile.h:54
struct unit_list * units
Definition tile.h:57
struct player * extras_owner
Definition tile.h:62
struct terrain * terrain
Definition tile.h:56
int vision_radius_sq
Definition unittype.h:503
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
int homecity
Definition unit.h:146
bool done_moving
Definition unit.h:181
int veteran
Definition unit.h:152
struct civ_map map
#define sz_strlcpy(dest, src)
Definition support.h:167
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define A_FUTURE
Definition tech.h:46
#define advance_index_iterate_end
Definition tech.h:248
#define A_FIRST
Definition tech.h:44
#define A_UNSET
Definition tech.h:48
#define advance_index_iterate(_start, _index)
Definition tech.h:244
void init_tech(struct research *research, bool update)
Definition techtools.c:1070
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1162
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:144
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:243
#define terrain_has_flag(terr, flag)
Definition terrain.h:269
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:552
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:473
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:578
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1080
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:343
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:87
#define tile_hash_iterate(hash, ptile)
Definition tile.h:81
#define tile_terrain(_tile)
Definition tile.h:109
#define tile_hash_iterate_end
Definition tile.h:83
#define TILE_XY(ptile)
Definition tile.h:42
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
#define unit_owner(_pu)
Definition unit.h:394
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:430
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2794
struct unit * create_unit(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left)
Definition unittools.c:1615
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2247
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1979
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:112
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2645
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1612
#define utype_class(_t_)
Definition unittype.h:736
#define utype_fuel(ptype)
Definition unittype.h:825
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604