Freeciv-3.1
Loading...
Searching...
No Matches
api_server_edit.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/* utility */
19#include "deprecations.h"
20#include "rand.h"
21
22/* common */
23#include "map.h"
24#include "movement.h"
25#include "research.h"
26#include "unittype.h"
27
28/* common/scriptcore */
29#include "api_game_find.h"
30#include "luascript.h"
31
32/* server */
33#include "aiiface.h"
34#include "barbarian.h"
35#include "citytools.h"
36#include "cityturn.h" /* city_refresh() auto_arrange_workers() */
37#include "console.h" /* enum rfc_status */
38#include "gamehand.h"
39#include "maphand.h"
40#include "notify.h"
41#include "plrhand.h"
42#include "srv_main.h" /* game_was_started() */
43#include "stdinhand.h"
44#include "techtools.h"
45#include "unithand.h"
46#include "unittools.h"
47
48/* server/scripting */
49#include "script_server.h"
50
51/* server/generator */
52#include "mapgen_utils.h"
53
54#include "api_server_edit.h"
55
56
57/**********************************************************************/
60static void deprecated_semantic_warning(const char *call, const char *aka,
61 const char *deprecated_since)
62{
65 "Deprecated: Lua call %s aka %s filling out the remaining"
66 " parameters based on the old rules is deprecated"
67 " since Freeciv %s.",
68 call, aka, deprecated_since);
69 }
70}
71
72/**********************************************************************/
76static bool
77ur_transform_unit(struct unit *punit, const struct unit_type *to_unit,
78 int vet_loss)
79{
80 if (UU_OK == unit_transform_result(&(wld.map), punit, to_unit)) {
81 /* Avoid getting overt veteranship if a user requests increasing it */
82 if (vet_loss < 0) {
83 int vl = utype_veteran_levels(to_unit);
84
85 vl = punit->veteran - vl + 1;
86 if (vl >= 0) {
87 vet_loss = 0;
88 } else {
89 vet_loss = MAX(vet_loss, vl);
90 }
91 }
92 transform_unit(punit, to_unit, vet_loss);
93 return TRUE;
94 } else {
95 return FALSE;
96 }
97}
98
99/**********************************************************************/
102bool api_edit_unleash_barbarians(lua_State *L, Tile *ptile)
103{
105 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, FALSE);
106
107 return unleash_barbarians(ptile);
108}
109
110/**********************************************************************/
113void api_edit_place_partisans(lua_State *L, Tile *ptile, Player *pplayer,
114 int count, int sq_radius)
115{
117 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
118 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player);
119 LUASCRIPT_CHECK_ARG(L, 0 <= sq_radius, 5, "radius must be positive");
120 LUASCRIPT_CHECK(L, 0 < num_role_units(L_PARTISAN),
121 "no partisans in ruleset");
122
123 return place_partisans(ptile, pplayer, count, sq_radius);
124}
125
126/**********************************************************************/
129Unit *api_edit_create_unit(lua_State *L, Player *pplayer, Tile *ptile,
130 Unit_Type *ptype, int veteran_level,
131 City *homecity, int moves_left)
132{
133 return api_edit_create_unit_full(L, pplayer, ptile, ptype, veteran_level,
134 homecity, moves_left, -1, NULL);
135}
136
137/**********************************************************************/
140Unit *api_edit_create_unit_full(lua_State *L, Player *pplayer,
141 Tile *ptile,
142 Unit_Type *ptype, int veteran_level,
143 City *homecity, int moves_left,
144 int hp_left,
145 Unit *ptransport)
146{
147 struct fc_lua *fcl;
148 struct city *pcity;
149 struct unit *punit;
150#ifndef FREECIV_NDEBUG
151 bool placed;
152#endif
153
154 LUASCRIPT_CHECK_STATE(L, NULL);
155 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
156 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, NULL);
157
158 fcl = luascript_get_fcl(L);
159
160 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!", NULL);
161
162 if (ptype == NULL
163 || ptype < unit_type_array_first() || ptype > unit_type_array_last()) {
164 return NULL;
165 }
166
167 if (is_non_allied_unit_tile(ptile, pplayer)) {
168 luascript_log(fcl, LOG_ERROR, "create_unit_full: tile is occupied by "
169 "enemy unit");
170 return NULL;
171 }
172
173 pcity = tile_city(ptile);
174 if (pcity != NULL && !pplayers_allied(pplayer, city_owner(pcity))) {
175 luascript_log(fcl, LOG_ERROR, "create_unit_full: tile is occupied by "
176 "enemy city");
177 return NULL;
178 }
179
180 if (utype_player_already_has_this_unique(pplayer, ptype)) {
182 "create_unit_full: player already has unique unit");
183 return NULL;
184 }
185
186 punit = unit_virtual_prepare(pplayer, ptile, ptype, veteran_level,
187 homecity ? homecity->id : 0,
188 moves_left, hp_left);
189 if (ptransport) {
190 /* The unit maybe can't freely load into the transport
191 * but must be able to be in it, see can_unit_load() */
192 int ret = same_pos(ptile, unit_tile(ptransport))
193 && could_unit_be_in_transport(punit, ptransport);
194
195 if (!ret) {
197 luascript_log(fcl, LOG_ERROR, "create_unit_full: '%s' cannot transport "
198 "'%s' here",
199 utype_rule_name(unit_type_get(ptransport)),
200 utype_rule_name(ptype));
201 return NULL;
202 }
203 } else if (!can_exist_at_tile(&(wld.map), ptype, ptile)) {
205 luascript_log(fcl, LOG_ERROR, "create_unit_full: '%s' cannot exist at "
206 "tile", utype_rule_name(ptype));
207 return NULL;
208 }
209
210#ifndef FREECIV_NDEBUG
211 placed =
212#endif
213 place_unit(punit, pplayer, homecity, ptransport, TRUE);
215
216 return punit;
217}
218
219/**********************************************************************/
222bool api_edit_unit_teleport(lua_State *L, Unit *punit, Tile *dest,
223 Unit *embark_to, bool allow_disembark,
224 bool conquer_city, bool conquer_extra,
225 bool enter_hut, bool frighten_hut)
226{
227 bool alive;
228
231 LUASCRIPT_CHECK_ARG_NIL(L, dest, 3, Tile, FALSE);
232
234 "Can't both enter and frighten a hut at the same time",
235 TRUE);
236
237 if (!allow_disembark && unit_transported(punit)) {
238 /* Can't leave the transport. */
239 return TRUE;
240 }
241
242 if (unit_teleport_to_tile_test(&(wld.map), punit, ACTIVITY_IDLE,
243 unit_tile(punit), dest, FALSE,
244 embark_to, TRUE) != MR_OK) {
245 /* Can't teleport to target. Return that unit is still alive. */
246 return TRUE;
247 }
248
249 /* Teleport first so destination is revealed even if unit dies */
250 alive = unit_move(punit, dest, 0,
251 embark_to, embark_to != NULL,
252 conquer_city, conquer_extra,
254 if (alive) {
255 struct player *owner = unit_owner(punit);
256 struct city *pcity = tile_city(dest);
257
258 if (!can_unit_exist_at_tile(&(wld.map), punit, dest)
259 && !unit_transported(punit)) {
260 wipe_unit(punit, ULR_NONNATIVE_TERR, NULL);
261 return FALSE;
262 }
264 || (pcity && !pplayers_allied(city_owner(pcity), owner))) {
265 wipe_unit(punit, ULR_STACK_CONFLICT, NULL);
266 return FALSE;
267 }
268 }
269
270 return alive;
271}
272
273/**********************************************************************/
276bool api_edit_unit_teleport_old(lua_State *L, Unit *punit, Tile *dest)
277{
278 bool alive;
279 struct city *pcity;
280
281 deprecated_semantic_warning("edit.unit_teleport(unit, dest)",
282 "Unit:teleport(dest)", "3.1");
283
286 LUASCRIPT_CHECK_ARG_NIL(L, dest, 3, Tile, FALSE);
287
288 /* Teleport first so destination is revealed even if unit dies */
289 alive = unit_move(punit, dest, 0,
290 /* Auto embark kept for backward compatibility. I have
291 * no objection if you see the old behavior as a bug and
292 * remove auto embarking completely or for transports
293 * the unit can't legally board. -- Sveinung */
294 NULL, TRUE,
295 /* Backwards compatibility for old scripts in rulesets
296 * and (scenario) savegames. I have no objection if you
297 * see the old behavior as a bug and remove auto
298 * conquering completely or for cities the unit can't
299 * legally conquer. -- Sveinung */
300 ((pcity = tile_city(dest))
301 && (unit_owner(punit)->ai_common.barbarian_type
302 != ANIMAL_BARBARIAN)
304 UCF_CAN_OCCUPY_CITY)
305 && !unit_has_type_flag(punit, UTYF_CIVILIAN)
307 city_owner(pcity))),
308 (extra_owner(dest) == NULL
312 /* Backwards compatibility: unit_enter_hut() would
313 * return without doing anything if the unit was
314 * HUT_NOTHING. Setting this parameter to FALSE makes
315 * sure unit_enter_hut() isn't called. */
316 unit_can_do_action_result(punit, ACTRES_HUT_ENTER),
317 unit_can_do_action_result(punit, ACTRES_HUT_FRIGHTEN));
318 if (alive) {
319 struct player *owner = unit_owner(punit);
320
321 if (!can_unit_exist_at_tile(&(wld.map), punit, dest)) {
322 wipe_unit(punit, ULR_NONNATIVE_TERR, NULL);
323 return FALSE;
324 }
326 || (pcity && !pplayers_allied(city_owner(pcity), owner))) {
327 wipe_unit(punit, ULR_STACK_CONFLICT, NULL);
328 return FALSE;
329 }
330 }
331
332 return alive;
333}
334
335/***********************************************************************/
339 Action *paction, City *tgt)
340{
343 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
345
346 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
347 fc_assert_ret_val(action_get_target_kind(paction) == ATK_CITY, FALSE);
348 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
349 if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
351 tgt->id, IDENTITY_NUMBER_ZERO, "",
352 paction->id, ACT_REQ_RULES);
353 } else {
354 /* Action not enabled */
355 return FALSE;
356 }
357}
358
359/***********************************************************************/
363 Action *paction, City *tgt,
364 Building_Type *sub_tgt)
365{
368 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
371
372 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
373 fc_assert_ret_val(action_get_target_kind(paction) == ATK_CITY, FALSE);
374 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
375 if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
377 tgt->id, sub_tgt->item_number, "",
378 paction->id, ACT_REQ_RULES);
379 } else {
380 /* Action not enabled */
381 return FALSE;
382 }
383}
384
385/***********************************************************************/
389 Action *paction, City *tgt,
390 Tech_Type *sub_tgt)
391{
394 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
396 LUASCRIPT_CHECK_ARG_NIL(L, sub_tgt, 5, Tech_Type, FALSE);
397
398 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
399 fc_assert_ret_val(action_get_target_kind(paction) == ATK_CITY, FALSE);
400 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
401 if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
403 tgt->id, sub_tgt->item_number, "",
404 paction->id, ACT_REQ_RULES);
405 } else {
406 /* Action not enabled */
407 return FALSE;
408 }
409}
410
411/***********************************************************************/
415 Action *paction, Unit *tgt)
416{
417 const struct civ_map *nmap = &(wld.map);
418
421 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
423
424 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
425 fc_assert_ret_val(action_get_target_kind(paction) == ATK_UNIT, FALSE);
426 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
427 if (is_action_enabled_unit_on_unit(nmap, paction->id, punit, tgt)) {
429 tgt->id, IDENTITY_NUMBER_ZERO, "",
430 paction->id, ACT_REQ_RULES);
431 } else {
432 /* Action not enabled */
433 return FALSE;
434 }
435}
436
437/***********************************************************************/
441 Action *paction, Tile *tgt)
442{
443 bool enabled = FALSE;
444 const struct civ_map *nmap = &(wld.map);
445
448 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
450
451 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
452 switch (action_get_target_kind(paction)) {
453 case ATK_UNITS:
454 enabled = is_action_enabled_unit_on_units(nmap, paction->id, punit, tgt);
455 break;
456 case ATK_TILE:
457 enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
458 tgt, NULL);
459 break;
460 case ATK_EXTRAS:
461 enabled = is_action_enabled_unit_on_extras(nmap, paction->id, punit,
462 tgt, NULL);
463 break;
464 case ATK_CITY:
465 /* Not handled here. */
466 fc_assert(action_get_target_kind(paction) != ATK_CITY);
467 break;
468 case ATK_UNIT:
469 /* Not handled here. */
470 fc_assert(action_get_target_kind(paction) != ATK_UNIT);
471 break;
472 case ATK_SELF:
473 /* Not handled here. */
474 fc_assert(action_get_target_kind(paction) != ATK_SELF);
475 break;
476 case ATK_COUNT:
477 /* Should not exist */
478 fc_assert(action_get_target_kind(paction) != ATK_COUNT);
479 break;
480 }
481
482 if (enabled) {
486 paction->id, ACT_REQ_RULES);
487 } else {
488 /* Action not enabled */
489 return FALSE;
490 }
491}
492
493/***********************************************************************/
497 Action *paction, Tile *tgt,
498 const char *sub_tgt)
499{
500 struct extra_type *sub_target;
501 bool enabled = FALSE;
502 const struct civ_map *nmap = &(wld.map);
503
506 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
508 LUASCRIPT_CHECK_ARG_NIL(L, sub_tgt, 5, string, FALSE);
509
510 sub_target = extra_type_by_rule_name(sub_tgt);
511 LUASCRIPT_CHECK_ARG(L, sub_target != NULL, 5, "No such extra", FALSE);
512
513 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
514 switch (action_get_target_kind(paction)) {
515 case ATK_UNITS:
516 enabled = is_action_enabled_unit_on_units(nmap, paction->id, punit, tgt);
517 break;
518 case ATK_TILE:
519 enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
520 tgt, sub_target);
521 break;
522 case ATK_EXTRAS:
523 enabled = is_action_enabled_unit_on_extras(nmap, paction->id, punit,
524 tgt, sub_target);
525 break;
526 case ATK_CITY:
527 /* Not handled here. */
528 fc_assert(action_get_target_kind(paction) != ATK_CITY);
529 break;
530 case ATK_UNIT:
531 /* Not handled here. */
532 fc_assert(action_get_target_kind(paction) != ATK_UNIT);
533 break;
534 case ATK_SELF:
535 /* Not handled here. */
536 fc_assert(action_get_target_kind(paction) != ATK_SELF);
537 break;
538 case ATK_COUNT:
539 /* Should not exist */
540 fc_assert(action_get_target_kind(paction) != ATK_COUNT);
541 break;
542 }
543
544 if (enabled) {
546 tile_index(tgt), sub_target->id,
548 paction->id, ACT_REQ_RULES);
549 } else {
550 /* Action not enabled */
551 return FALSE;
552 }
553}
554
555/***********************************************************************/
559 Action *paction)
560{
561 const struct civ_map *nmap = &(wld.map);
562
565 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
566
567 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
568 fc_assert_ret_val(action_get_target_kind(paction) == ATK_SELF, FALSE);
569 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
570 if (is_action_enabled_unit_on_self(nmap, paction->id, punit)) {
573 "",
574 paction->id, ACT_REQ_RULES);
575 } else {
576 /* Action not enabled */
577 return FALSE;
578 }
579}
580
581/**********************************************************************/
584void api_edit_unit_turn(lua_State *L, Unit *punit, Direction dir)
585{
588
589 if (direction8_is_valid(dir)) {
590 punit->facing = dir;
591
592 send_unit_info(NULL, punit);
593 } else {
594 log_error("Illegal direction %d for unit from lua script", dir);
595 }
596}
597
598/**********************************************************************/
602bool api_edit_unit_upgrade(lua_State *L, Unit *punit, int vet_loss)
603{
604 const struct unit_type *ptype;
605
608
610 if (!ptype) {
611 return FALSE;
612 }
613 return ur_transform_unit(punit, ptype, vet_loss);
614}
615
616/**********************************************************************/
620bool api_edit_unit_transform(lua_State *L, Unit *punit, Unit_Type *ptype,
621 int vet_loss)
622{
626
627 return ur_transform_unit(punit, ptype, vet_loss);
628}
629
630/**********************************************************************/
633void api_edit_unit_kill(lua_State *L, Unit *punit, const char *reason,
634 Player *killer)
635{
636 enum unit_loss_reason loss_reason;
637
640 LUASCRIPT_CHECK_ARG_NIL(L, reason, 3, string);
641
642 loss_reason = unit_loss_reason_by_name(reason, fc_strcasecmp);
643
644 LUASCRIPT_CHECK_ARG(L, unit_loss_reason_is_valid(loss_reason), 3,
645 "Invalid unit loss reason");
646
647 wipe_unit(punit, loss_reason, killer);
648}
649
650/**********************************************************************/
653bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr)
654{
655 struct terrain *old_terrain;
656
658 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, FALSE);
660
661 old_terrain = tile_terrain(ptile);
662
663 if (old_terrain == pterr
664 || (terrain_has_flag(pterr, TER_NO_CITIES)
665 && tile_city(ptile) != NULL)) {
666 return FALSE;
667 }
668
669 tile_change_terrain(ptile, pterr);
670 fix_tile_on_terrain_change(ptile, old_terrain, FALSE);
671 if (need_to_reassign_continents(old_terrain, pterr)) {
673
674 /* FIXME: adv / ai phase handling like in check_terrain_change() */
675
677 }
678
680
682
683 return TRUE;
684}
685
686/**********************************************************************/
689bool api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile,
690 const char *name)
691{
693 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, FALSE);
694 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
695
696 /* TODO: Allow initial citizen to be of nationality other than owner */
697 return create_city_for_player(pplayer, ptile, name);
698}
699
700/**********************************************************************/
703void api_edit_remove_city(lua_State *L, City *pcity)
704{
706 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
707
708 remove_city(pcity);
709}
710
711/**********************************************************************/
714void api_edit_create_building(lua_State *L, City *pcity, Building_Type *impr)
715{
717 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
719 /* FIXME: may "Special" impr be buildable? */
721 "It is a special item, not a city building");
722
723 if (!city_has_building(pcity, impr)) {
724 bool need_game_info = FALSE;
725 bool need_plr_info = FALSE;
726 struct player *old_owner = NULL, *pplayer = city_owner(pcity);
727 struct city *oldcity;
728
729 oldcity = build_or_move_building(pcity, impr, &old_owner);
730 if (oldcity) {
731 need_plr_info = TRUE;
732 }
733 if (old_owner && old_owner != pplayer) {
734 /* Great wonders make more changes. */
735 need_game_info = TRUE;
736 }
737
738 if (oldcity) {
739 if (city_refresh(oldcity)) {
740 auto_arrange_workers(oldcity);
741 }
742 send_city_info(NULL, oldcity);
743 }
744
745 if (city_refresh(pcity)) {
747 }
748 send_city_info(NULL, pcity);
749 if (need_game_info) {
750 send_game_info(NULL);
751 send_player_info_c(old_owner, NULL);
752 }
753 if (need_plr_info) {
754 send_player_info_c(pplayer, NULL);
755 }
756 }
757}
758
759/**********************************************************************/
762void api_edit_remove_building(lua_State *L, City *pcity, Building_Type *impr)
763{
765 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
767
768 if (city_has_building(pcity, impr)) {
769 city_remove_improvement(pcity, impr);
770 send_city_info(NULL, pcity);
771
772 if (is_wonder(impr)) {
773 if (is_great_wonder(impr)) {
774 send_game_info(NULL);
775 }
776 send_player_info_c(city_owner(pcity), NULL);
777 }
778 }
779}
780
781/**********************************************************************/
784Player *api_edit_create_player(lua_State *L, const char *username,
785 Nation_Type *pnation, const char *ai)
786{
787 struct player *pplayer = NULL;
788 char buf[128] = "";
789 struct fc_lua *fcl;
790
791 LUASCRIPT_CHECK_STATE(L, NULL);
792 LUASCRIPT_CHECK_ARG_NIL(L, username, 2, string, NULL);
793 if (!ai) {
795 }
796
797 fcl = luascript_get_fcl(L);
798
799 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!", NULL);
800
801 if (game_was_started()) {
802 create_command_newcomer(username, ai, FALSE, pnation, &pplayer,
803 buf, sizeof(buf));
804 } else {
805 create_command_pregame(username, ai, FALSE, &pplayer,
806 buf, sizeof(buf));
807 }
808
809 if (strlen(buf) > 0) {
810 luascript_log(fcl, LOG_NORMAL, "%s", buf);
811 }
812
813 return pplayer;
814}
815
816/**********************************************************************/
819void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
820{
822 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player);
823
824 pplayer->economic.gold = MAX(0, pplayer->economic.gold + amount);
825
826 send_player_info_c(pplayer, NULL);
827}
828
829/**********************************************************************/
836 Tech_Type *ptech, int cost,
837 bool notify,
838 const char *reason)
839{
840 struct research *presearch;
842 Tech_Type *result;
843
844 LUASCRIPT_CHECK_STATE(L, NULL);
845 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
846 LUASCRIPT_CHECK_ARG(L, cost >= -3, 4, "Unknown give_tech() cost value", NULL);
847
848 presearch = research_get(pplayer);
849 if (ptech) {
850 id = advance_number(ptech);
851 } else {
852 id = pick_free_tech(presearch);
853 }
854
855 if (is_future_tech(id)
856 || research_invention_state(presearch, id) != TECH_KNOWN) {
857 if (cost < 0) {
858 if (cost == -1) {
860 } else if (cost == -2) {
862 } else if (cost == -3) {
864 } else {
865
866 cost = 0;
867 }
868 }
869 research_apply_penalty(presearch, id, cost);
870 found_new_tech(presearch, id, FALSE, TRUE);
871 result = advance_by_number(id);
872 script_tech_learned(presearch, pplayer, result, reason);
873
874 if (notify && result != NULL) {
875 const char *adv_name = research_advance_name_translation(presearch, id);
876 char research_name[MAX_LEN_NAME * 2];
877
878 research_pretty_name(presearch, research_name, sizeof(research_name));
879
880 notify_player(pplayer, NULL, E_TECH_GAIN, ftc_server,
881 Q_("?fromscript:You acquire %s."), adv_name);
882 notify_research(presearch, pplayer, E_TECH_GAIN, ftc_server,
883 /* TRANS: "The Greeks ..." or "The members of
884 * team Red ..." */
885 Q_("?fromscript:The %s acquire %s and share this "
886 "advance with you."),
887 nation_plural_for_player(pplayer), adv_name);
888 notify_research_embassies(presearch, NULL, E_TECH_EMBASSY, ftc_server,
889 /* TRANS: "The Greeks ..." or "The members of
890 * team Red ..." */
891 Q_("?fromscript:The %s acquire %s."),
892 research_name, adv_name);
893 }
894
895 return result;
896 } else {
897 return NULL;
898 }
899}
900
901/**********************************************************************/
904bool api_edit_trait_mod_set(lua_State *L, Player *pplayer,
905 const char *tname, const int mod)
906{
907 enum trait tr;
908
910 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, FALSE);
911 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, FALSE);
912
913 tr = trait_by_name(tname, fc_strcasecmp);
914
915 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
916
917 pplayer->ai_common.traits[tr].mod += mod;
918
919 return TRUE;
920}
921
922/**********************************************************************/
925void api_edit_create_owned_extra(lua_State *L, Tile *ptile,
926 const char *name, Player *pplayer)
927{
928 struct extra_type *pextra;
929
931 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
932
933 if (name == NULL) {
934 return;
935 }
936
938
939 if (pextra != NULL) {
940 create_extra(ptile, pextra, pplayer);
943 }
944}
945
946/**********************************************************************/
949void api_edit_create_extra(lua_State *L, Tile *ptile, const char *name)
950{
951 api_edit_create_owned_extra(L, ptile, name, NULL);
952}
953
954/**********************************************************************/
957void api_edit_create_base(lua_State *L, Tile *ptile, const char *name,
958 Player *pplayer)
959{
960 api_edit_create_owned_extra(L, ptile, name, pplayer);
961}
962
963/**********************************************************************/
966void api_edit_create_road(lua_State *L, Tile *ptile, const char *name)
967{
968 api_edit_create_owned_extra(L, ptile, name, NULL);
969}
970
971/**********************************************************************/
974void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name)
975{
976 struct extra_type *pextra;
977
979 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
980
981 if (name == NULL) {
982 return;
983 }
984
986
987 if (pextra != NULL && tile_has_extra(ptile, pextra)) {
988 tile_extra_rm_apply(ptile, pextra);
991 }
992}
993
994/**********************************************************************/
997void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label)
998{
1000 LUASCRIPT_CHECK_SELF(L, ptile);
1001 LUASCRIPT_CHECK_ARG_NIL(L, label, 3, string);
1002
1003 tile_set_label(ptile, label);
1004 if (server_state() >= S_S_RUNNING) {
1005 send_tile_info(NULL, ptile, FALSE);
1006 }
1007}
1008
1009/**********************************************************************/
1012void api_edit_tile_show(lua_State *L, Tile *ptile, Player *pplayer)
1013{
1015 LUASCRIPT_CHECK_SELF(L, ptile);
1016 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player);
1017
1018 map_show_tile(pplayer, ptile);
1019}
1020
1021/**********************************************************************/
1024bool api_edit_tile_hide(lua_State *L, Tile *ptile, Player *pplayer)
1025{
1026 struct city *pcity;
1027
1029 LUASCRIPT_CHECK_SELF(L, ptile, FALSE);
1030 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player, FALSE);
1031
1032 if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
1033 /* Can't hide currently seen tile */
1034 return FALSE;
1035 }
1036
1037 pcity = tile_city(ptile);
1038
1039 if (pcity != NULL) {
1040 trade_partners_iterate(pcity, partner) {
1041 if (really_gives_vision(pplayer, city_owner(partner))) {
1042 /* Can't remove vision about trade partner */
1043 return FALSE;
1044 }
1046 }
1047
1048 dbv_clr(&pplayer->tile_known, tile_index(ptile));
1049
1050 send_tile_info(pplayer->connections, ptile, TRUE);
1051
1052 return TRUE;
1053}
1054
1055/**********************************************************************/
1059 int effect)
1060{
1064 2, "invalid climate change type");
1065 LUASCRIPT_CHECK_ARG(L, effect > 0, 3, "effect must be greater than zero");
1066
1068}
1069
1070/**********************************************************************/
1073Player *api_edit_civil_war(lua_State *L, Player *pplayer, int probability)
1074{
1075 LUASCRIPT_CHECK_STATE(L, NULL);
1076 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
1077 LUASCRIPT_CHECK_ARG(L, probability >= 0 && probability <= 100,
1078 3, "must be a percentage", NULL);
1079
1080 if (!civil_war_possible(pplayer, FALSE, FALSE)) {
1081 return NULL;
1082 }
1083
1084 if (probability == 0) {
1085 /* Calculate chance with normal rules */
1086 if (!civil_war_triggered(pplayer)) {
1087 return NULL;
1088 }
1089 } else {
1090 /* Fixed chance specified by script */
1091 if (fc_rand(100) >= probability) {
1092 return NULL;
1093 }
1094 }
1095
1096 return civil_war(pplayer);
1097}
1098
1099/**********************************************************************/
1102void api_edit_player_victory(lua_State *L, Player *pplayer)
1103{
1105 LUASCRIPT_CHECK_SELF(L, pplayer);
1106
1107 player_status_add(pplayer, PSTATUS_WINNER);
1108}
1109
1110/**********************************************************************/
1113bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile,
1114 int movecost,
1115 Unit *embark_to, bool disembark,
1116 bool conquer_city, bool conquer_extra,
1117 bool enter_hut, bool frighten_hut)
1118{
1121 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
1122 LUASCRIPT_CHECK_ARG(L, movecost >= 0, 4, "Negative move cost!", FALSE);
1123
1125 "Can't both enter and frighten a hut at the same time",
1126 TRUE);
1127
1128 if (!disembark && unit_transported(punit)) {
1129 /* Can't leave the transport. */
1130 return TRUE;
1131 }
1132
1133 if (unit_move_to_tile_test(&(wld.map), punit, ACTIVITY_IDLE,
1134 unit_tile(punit), ptile, TRUE,
1135 FALSE, embark_to, TRUE) != MR_OK) {
1136 /* Can't move to target. Return that unit is still alive. */
1137 return TRUE;
1138 }
1139
1140 return unit_move(punit, ptile, movecost,
1141 embark_to, embark_to != NULL,
1142 conquer_city, conquer_extra,
1144}
1145
1146/**********************************************************************/
1149bool api_edit_unit_move_old(lua_State *L, Unit *punit, Tile *ptile,
1150 int movecost)
1151{
1152 struct city *pcity;
1153
1154 deprecated_semantic_warning("edit.unit_move(unit, moveto, movecost)",
1155 "Unit:move(moveto, movecost)", "3.1");
1156
1159 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
1160 LUASCRIPT_CHECK_ARG(L, movecost >= 0, 4, "Negative move cost!", FALSE);
1161
1162 return unit_move(punit, ptile, movecost,
1163 /* Auto embark kept for backward compatibility. I have
1164 * no objection if you see the old behavior as a bug and
1165 * remove auto embarking completely or for transports
1166 * the unit can't legally board. -- Sveinung */
1167 NULL, TRUE,
1168 /* Backwards compatibility for old scripts in rulesets
1169 * and (scenario) savegames. I have no objection if you
1170 * see the old behavior as a bug and remove auto
1171 * conquering completely or for cities the unit can't
1172 * legally conquer. -- Sveinung */
1173 ((pcity = tile_city(ptile))
1174 && (unit_owner(punit)->ai_common.barbarian_type
1175 != ANIMAL_BARBARIAN)
1177 UCF_CAN_OCCUPY_CITY)
1178 && !unit_has_type_flag(punit, UTYF_CIVILIAN)
1180 city_owner(pcity))),
1181 (extra_owner(ptile) == NULL
1182 || pplayers_at_war(extra_owner(ptile),
1183 unit_owner(punit)))
1185 /* Backwards compatibility: unit_enter_hut() would
1186 * return without doing anything if the unit was
1187 * HUT_NOTHING. Setting this parameter to FALSE makes
1188 * sure unit_enter_hut() isn't called. */
1189 unit_can_do_action_result(punit, ACTRES_HUT_ENTER),
1190 unit_can_do_action_result(punit, ACTRES_HUT_FRIGHTEN));
1191}
1192
1193/**********************************************************************/
1197{
1200
1201 if (punit != NULL) {
1202 punit->stay = TRUE;
1203 }
1204}
1205
1206/**********************************************************************/
1210{
1213
1214 if (punit != NULL) {
1215 punit->stay = FALSE;
1216 }
1217}
1218
1219/**********************************************************************/
1222void api_edit_city_add_history(lua_State *L, City *pcity, int amount)
1223{
1225 LUASCRIPT_CHECK_SELF(L, pcity);
1226
1227 pcity->history += amount;
1228}
1229
1230/**********************************************************************/
1233void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount)
1234{
1236 LUASCRIPT_CHECK_SELF(L, pplayer);
1237
1238 pplayer->history += amount;
1239}
1240
1241/**********************************************************************/
1244void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount)
1245{
1247 LUASCRIPT_CHECK_SELF(L, pplayer);
1248
1249 update_bulbs(pplayer, amount, TRUE);
1250
1251 send_research_info(research_get(pplayer), NULL);
1252}
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1730
bool is_action_enabled_unit_on_tile(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4996
bool is_action_enabled_unit_on_units(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile)
Definition actions.c:4920
bool is_action_enabled_unit_on_city(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
Definition actions.c:4755
bool is_action_enabled_unit_on_unit(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Definition actions.c:4832
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1740
bool is_action_enabled_unit_on_self(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit)
Definition actions.c:5145
bool is_action_enabled_unit_on_extras(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:5073
#define action_has_result(_act_, _res_)
Definition actions.h:448
const char * default_ai_type_name(void)
Definition aiiface.c:262
static bool ur_transform_unit(struct unit *punit, const struct unit_type *to_unit, int vet_loss)
bool api_edit_perform_action_unit_vs_tile_extra(lua_State *L, Unit *punit, Action *paction, Tile *tgt, const char *sub_tgt)
bool api_edit_perform_action_unit_vs_tile(lua_State *L, Unit *punit, Action *paction, Tile *tgt)
void api_edit_climate_change(lua_State *L, enum climate_change_type type, int effect)
void api_edit_unit_moving_allow(lua_State *L, Unit *punit)
static void deprecated_semantic_warning(const char *call, const char *aka, const char *deprecated_since)
void api_edit_remove_city(lua_State *L, City *pcity)
bool api_edit_trait_mod_set(lua_State *L, Player *pplayer, const char *tname, const int mod)
bool api_edit_unleash_barbarians(lua_State *L, Tile *ptile)
void api_edit_remove_building(lua_State *L, City *pcity, Building_Type *impr)
void api_edit_player_victory(lua_State *L, Player *pplayer)
void api_edit_create_extra(lua_State *L, Tile *ptile, const char *name)
Unit * api_edit_create_unit(lua_State *L, Player *pplayer, Tile *ptile, Unit_Type *ptype, int veteran_level, City *homecity, int moves_left)
bool api_edit_perform_action_unit_vs_unit(lua_State *L, Unit *punit, Action *paction, Unit *tgt)
void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount)
Tech_Type * api_edit_give_technology(lua_State *L, Player *pplayer, Tech_Type *ptech, int cost, bool notify, const char *reason)
bool api_edit_perform_action_unit_vs_city_impr(lua_State *L, Unit *punit, Action *paction, City *tgt, Building_Type *sub_tgt)
void api_edit_create_building(lua_State *L, City *pcity, Building_Type *impr)
Unit * api_edit_create_unit_full(lua_State *L, Player *pplayer, Tile *ptile, Unit_Type *ptype, int veteran_level, City *homecity, int moves_left, int hp_left, Unit *ptransport)
void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount)
bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr)
void api_edit_create_owned_extra(lua_State *L, Tile *ptile, const char *name, Player *pplayer)
void api_edit_tile_show(lua_State *L, Tile *ptile, Player *pplayer)
void api_edit_unit_kill(lua_State *L, Unit *punit, const char *reason, Player *killer)
bool api_edit_tile_hide(lua_State *L, Tile *ptile, Player *pplayer)
void api_edit_unit_turn(lua_State *L, Unit *punit, Direction dir)
void api_edit_place_partisans(lua_State *L, Tile *ptile, Player *pplayer, int count, int sq_radius)
void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name)
void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label)
void api_edit_create_road(lua_State *L, Tile *ptile, const char *name)
bool api_edit_unit_move_old(lua_State *L, Unit *punit, Tile *ptile, int movecost)
bool api_edit_perform_action_unit_vs_city(lua_State *L, Unit *punit, Action *paction, City *tgt)
void api_edit_city_add_history(lua_State *L, City *pcity, int amount)
bool api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile, const char *name)
bool api_edit_unit_teleport(lua_State *L, Unit *punit, Tile *dest, Unit *embark_to, bool allow_disembark, bool conquer_city, bool conquer_extra, bool enter_hut, bool frighten_hut)
void api_edit_unit_moving_disallow(lua_State *L, Unit *punit)
bool api_edit_unit_teleport_old(lua_State *L, Unit *punit, Tile *dest)
bool api_edit_unit_upgrade(lua_State *L, Unit *punit, int vet_loss)
bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile, int movecost, Unit *embark_to, bool disembark, bool conquer_city, bool conquer_extra, bool enter_hut, bool frighten_hut)
bool api_edit_perform_action_unit_vs_self(lua_State *L, Unit *punit, Action *paction)
Player * api_edit_create_player(lua_State *L, const char *username, Nation_Type *pnation, const char *ai)
bool api_edit_unit_transform(lua_State *L, Unit *punit, Unit_Type *ptype, int vet_loss)
void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
Player * api_edit_civil_war(lua_State *L, Player *pplayer, int probability)
bool api_edit_perform_action_unit_vs_city_tech(lua_State *L, Unit *punit, Action *paction, City *tgt, Tech_Type *sub_tgt)
void api_edit_create_base(lua_State *L, Tile *ptile, const char *name, Player *pplayer)
climate_change_type
@ CLIMATE_CHANGE_GLOBAL_WARMING
@ CLIMATE_CHANGE_NUCLEAR_WINTER
bool unleash_barbarians(struct tile *ptile)
Definition barbarian.c:271
void dbv_clr(struct dbv *pdbv, int bit)
Definition bitvector.c:167
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_owner(_pcity_)
Definition city.h:543
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Definition citytools.c:456
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
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 auto_arrange_workers(struct city *pcity)
Definition cityturn.c:369
bool city_refresh(struct city *pcity)
Definition cityturn.c:161
bool are_deprecation_warnings_enabled(void)
#define log_deprecation_always(message,...)
static void conquer_city(QVariant data1, QVariant data2)
Definition dialogs.cpp:1832
static void enter_hut(QVariant data1, QVariant data2)
Definition dialogs.cpp:2571
static void frighten_hut(QVariant data1, QVariant data2)
Definition dialogs.cpp:2601
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
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:73
int int id
Definition editgui_g.h:28
struct extra_type * extra_type_by_rule_name(const char *name)
Definition extras.c:204
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1068
int Tech_type_id
Definition fc_types.h:347
#define MAX_LEN_NAME
Definition fc_types.h:66
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
#define Q_(String)
Definition fcintl.h:70
const struct ft_color ftc_server
struct civ_game game
Definition game.c:57
struct world wld
Definition game.c:58
void send_game_info(struct conn_list *dest)
Definition gamehand.c:905
struct city * owner
Definition citydlg.c:219
GType type
Definition repodlgs.c:1312
bool is_special_improvement(const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_assert_action(condition, action)
Definition log.h:187
@ LOG_ERROR
Definition log.h:30
@ LOG_NORMAL
Definition log.h:32
#define log_error(message,...)
Definition log.h:103
void luascript_log(struct fc_lua *fcl, enum log_level level, const char *format,...)
Definition luascript.c:409
struct fc_lua * luascript_get_fcl(lua_State *L)
Definition luascript.c:366
#define LUASCRIPT_CHECK_STATE(L,...)
Definition luascript.h:117
#define LUASCRIPT_CHECK_SELF(L, value,...)
Definition luascript.h:146
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition luascript.h:138
#define LUASCRIPT_CHECK_ARG(L, check, narg, msg,...)
Definition luascript.h:131
#define LUASCRIPT_CHECK(L, check, msg,...)
Definition luascript.h:124
enum direction8 Direction
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:938
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 climate_change(bool warming, int effect)
Definition maphand.c:130
void create_extra(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition maphand.c:2540
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
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:900
void fix_tile_on_terrain_change(struct tile *ptile, struct terrain *oldter, bool extend_rivers)
Definition maphand.c:1959
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1427
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:275
enum unit_move_result unit_move_to_tile_test(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity, const struct tile *src_tile, const struct tile *dst_tile, bool igzoc, bool enter_transport, struct unit *embark_to, bool enter_enemy_city)
Definition movement.c:595
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:304
enum unit_move_result unit_teleport_to_tile_test(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity, const struct tile *src_tile, const struct tile *dst_tile, bool enter_transport, struct unit *embark_to, bool enter_enemy_city)
Definition movement.c:732
@ MR_OK
Definition movement.h:33
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
void notify_research(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:393
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
void notify_research_embassies(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:433
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1364
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3042
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2785
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1000
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:2835
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2738
#define fc_rand(_size)
Definition rand.h:34
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:271
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
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:167
#define MAX(x, y)
Definition shared.h:54
bool game_was_started(void)
Definition srv_main.c:339
enum server_states server_state(void)
Definition srv_main.c:323
enum rfc_status create_command_newcomer(const char *name, const char *ai, bool check, struct nation_type *pnation, struct player **newplayer, char *buf, size_t buflen)
Definition stdinhand.c:810
enum rfc_status create_command_pregame(const char *name, const char *ai, bool check, struct player **newplayer, char *buf, size_t buflen)
Definition stdinhand.c:994
action_id id
Definition actions.h:380
Tech_type_id item_number
Definition tech.h:125
int mod
Definition traits.h:39
Definition agents.c:49
Definition city.h:309
int history
Definition city.h:393
int id
Definition city.h:315
struct civ_game::@30::@34 server
int diplbulbcost
Definition game.h:138
int conquercost
Definition game.h:135
int freecost
Definition game.h:147
int id
Definition extras.h:86
Impr_type_id item_number
Definition improvement.h:69
struct ai_trait * traits
Definition player.h:132
struct player_ai ai_common
Definition player.h:288
struct dbv tile_known
Definition player.h:306
struct conn_list * connections
Definition player.h:298
struct player_economic economic
Definition player.h:284
int history
Definition player.h:312
Definition tile.h:49
Definition unit.h:138
int moves_left
Definition unit.h:150
int id
Definition unit.h:145
bool stay
Definition unit.h:205
enum direction8 facing
Definition unit.h:142
int homecity
Definition unit.h:146
int veteran
Definition unit.h:152
struct civ_map map
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
void found_new_tech(struct research *presearch, Tech_type_id tech_found, bool was_discovery, bool saving_bulbs)
Definition techtools.c:327
void research_apply_penalty(struct research *presearch, Tech_type_id tech, int penalty_percent)
Definition techtools.c:67
Tech_type_id pick_free_tech(struct research *presearch)
Definition techtools.c:1361
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech)
Definition techtools.c:643
void script_tech_learned(struct research *presearch, struct player *originating_plr, struct advance *tech, const char *reason)
Definition techtools.c:84
#define terrain_has_flag(terr, flag)
Definition terrain.h:269
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:209
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
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:87
#define tile_terrain(_tile)
Definition tile.h:109
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
#define trade_partners_iterate_end
#define trade_partners_iterate(c, p)
enum unit_upgrade_result unit_transform_result(const struct civ_map *nmap, const struct unit *punit, const struct unit_type *to_unittype)
Definition unit.c:1940
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:338
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1713
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2409
bool could_unit_be_in_transport(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:687
#define unit_tile(_pu)
Definition unit.h:395
#define unit_owner(_pu)
Definition unit.h:394
@ UU_OK
Definition unit.h:61
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:430
bool unit_perform_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id_incoming, const char *name, const action_id action_type, const enum action_requester requester)
Definition unithand.c:3175
void place_partisans(struct tile *pcenter, struct player *powner, int count, int sq_radius)
Definition unittools.c:1177
void transform_unit(struct unit *punit, const struct unit_type *to_unit, int vet_loss)
Definition unittools.c:1565
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2794
bool place_unit(struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
Definition unittools.c:1723
struct unit * unit_virtual_prepare(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left, int hp_left)
Definition unittools.c:1675
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2247
bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost, struct unit *embark_to, bool find_embark_target, bool conquer_city_allowed, bool conquer_extras_allowed, bool enter_hut, bool frighten_hut)
Definition unittools.c:3884
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
struct unit_type * unit_type_array_first(void)
Definition unittype.c:58
int num_role_units(int role)
Definition unittype.c:2251
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1979
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1755
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2673
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2547
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
const struct unit_type * unit_type_array_last(void)
Definition unittype.c:69
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:753