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);
344 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) == ATK_CITY, 3,
345 "Not a city-targeted action", FALSE);
347
348 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
349 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
350 if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
352 tgt->id, IDENTITY_NUMBER_ZERO, "",
353 paction->id, ACT_REQ_RULES);
354 } else {
355 /* Action not enabled */
356 return FALSE;
357 }
358}
359
360/***********************************************************************/
364 Action *paction, City *tgt,
365 Building_Type *sub_tgt)
366{
369 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
370 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) == ATK_CITY, 3,
371 "Not a city-targeted action", FALSE);
374
375 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
376 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
377 if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
379 tgt->id, sub_tgt->item_number, "",
380 paction->id, ACT_REQ_RULES);
381 } else {
382 /* Action not enabled */
383 return FALSE;
384 }
385}
386
387/***********************************************************************/
391 Action *paction, City *tgt,
392 Tech_Type *sub_tgt)
393{
396 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
397 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) == ATK_CITY, 3,
398 "Not a city-targeted action", FALSE);
400 LUASCRIPT_CHECK_ARG_NIL(L, sub_tgt, 5, Tech_Type, FALSE);
401
402 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
403 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
404 if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
406 tgt->id, sub_tgt->item_number, "",
407 paction->id, ACT_REQ_RULES);
408 } else {
409 /* Action not enabled */
410 return FALSE;
411 }
412}
413
414/***********************************************************************/
418 Action *paction, Unit *tgt)
419{
420 const struct civ_map *nmap = &(wld.map);
421
424 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
425 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) == ATK_UNIT, 3,
426 "Not a unit-targeted action", FALSE);
428
429 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
430 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
431 if (is_action_enabled_unit_on_unit(nmap, paction->id, punit, tgt)) {
433 tgt->id, IDENTITY_NUMBER_ZERO, "",
434 paction->id, ACT_REQ_RULES);
435 } else {
436 /* Action not enabled */
437 return FALSE;
438 }
439}
440
441/***********************************************************************/
445 Action *paction, Tile *tgt)
446{
447 bool enabled = FALSE;
448 const struct civ_map *nmap = &(wld.map);
449
452 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
454
455 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
456 switch (action_get_target_kind(paction)) {
457 case ATK_UNITS:
458 enabled = is_action_enabled_unit_on_units(nmap, paction->id, punit, tgt);
459 break;
460 case ATK_TILE:
461 enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
462 tgt, NULL);
463 break;
464 case ATK_EXTRAS:
465 enabled = is_action_enabled_unit_on_extras(nmap, paction->id, punit,
466 tgt, NULL);
467 break;
468 case ATK_CITY:
469 /* Not handled here. */
470 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) != ATK_CITY, 3,
471 "City-targeted action applied to tile", FALSE);
472 break;
473 case ATK_UNIT:
474 /* Not handled here. */
475 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) != ATK_UNIT, 3,
476 "Unit-targeted action applied to tile", FALSE);
477 break;
478 case ATK_SELF:
479 /* Not handled here. */
480 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) != ATK_SELF, 3,
481 "Self-targeted action applied to tile", FALSE);
482 break;
483 case ATK_COUNT:
484 /* Should not exist */
485 fc_assert(action_get_target_kind(paction) != ATK_COUNT);
486 break;
487 }
488
489 if (enabled) {
493 paction->id, ACT_REQ_RULES);
494 } else {
495 /* Action not enabled */
496 return FALSE;
497 }
498}
499
500/***********************************************************************/
504 Action *paction, Tile *tgt,
505 const char *sub_tgt)
506{
507 struct extra_type *sub_target;
508 bool enabled = FALSE;
509 const struct civ_map *nmap = &(wld.map);
510
513 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
515 LUASCRIPT_CHECK_ARG_NIL(L, sub_tgt, 5, string, FALSE);
516
517 sub_target = extra_type_by_rule_name(sub_tgt);
518 LUASCRIPT_CHECK_ARG(L, sub_target != NULL, 5, "No such extra", FALSE);
519
520 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
521 switch (action_get_target_kind(paction)) {
522 case ATK_UNITS:
523 enabled = is_action_enabled_unit_on_units(nmap, paction->id, punit, tgt);
524 break;
525 case ATK_TILE:
526 enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
527 tgt, sub_target);
528 break;
529 case ATK_EXTRAS:
530 enabled = is_action_enabled_unit_on_extras(nmap, paction->id, punit,
531 tgt, sub_target);
532 break;
533 case ATK_CITY:
534 /* Not handled here. */
535 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) != ATK_CITY, 3,
536 "City-targeted action applied to tile", FALSE);
537 break;
538 case ATK_UNIT:
539 /* Not handled here. */
540 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) != ATK_UNIT, 3,
541 "Unit-targeted action applied to tile", FALSE);
542 break;
543 case ATK_SELF:
544 /* Not handled here. */
545 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) != ATK_SELF, 3,
546 "Self-targeted action applied to tile", FALSE);
547 break;
548 case ATK_COUNT:
549 /* Should not exist */
550 fc_assert(action_get_target_kind(paction) != ATK_COUNT);
551 break;
552 }
553
554 if (enabled) {
556 tile_index(tgt), sub_target->id,
558 paction->id, ACT_REQ_RULES);
559 } else {
560 /* Action not enabled */
561 return FALSE;
562 }
563}
564
565/***********************************************************************/
569 Action *paction)
570{
571 const struct civ_map *nmap = &(wld.map);
572
575 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
576 LUASCRIPT_CHECK_ARG(L, action_get_target_kind(paction) == ATK_SELF, 3,
577 "Not a self-targeted action", FALSE);
578
579 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
580 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
581 if (is_action_enabled_unit_on_self(nmap, paction->id, punit)) {
584 "",
585 paction->id, ACT_REQ_RULES);
586 } else {
587 /* Action not enabled */
588 return FALSE;
589 }
590}
591
592/**********************************************************************/
595void api_edit_unit_turn(lua_State *L, Unit *punit, Direction dir)
596{
599
600 if (direction8_is_valid(dir)) {
601 punit->facing = dir;
602
603 send_unit_info(NULL, punit);
604 } else {
605 log_error("Illegal direction %d for unit from lua script", dir);
606 }
607}
608
609/**********************************************************************/
613bool api_edit_unit_upgrade(lua_State *L, Unit *punit, int vet_loss)
614{
615 const struct unit_type *ptype;
616
619
621 if (!ptype) {
622 return FALSE;
623 }
624 return ur_transform_unit(punit, ptype, vet_loss);
625}
626
627/**********************************************************************/
631bool api_edit_unit_transform(lua_State *L, Unit *punit, Unit_Type *ptype,
632 int vet_loss)
633{
637
638 return ur_transform_unit(punit, ptype, vet_loss);
639}
640
641/**********************************************************************/
644void api_edit_unit_kill(lua_State *L, Unit *punit, const char *reason,
645 Player *killer)
646{
647 enum unit_loss_reason loss_reason;
648
651 LUASCRIPT_CHECK_ARG_NIL(L, reason, 3, string);
652
653 loss_reason = unit_loss_reason_by_name(reason, fc_strcasecmp);
654
655 LUASCRIPT_CHECK_ARG(L, unit_loss_reason_is_valid(loss_reason), 3,
656 "Invalid unit loss reason");
657
658 wipe_unit(punit, loss_reason, killer);
659}
660
661/**********************************************************************/
664bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr)
665{
666 struct terrain *old_terrain;
667
669 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, FALSE);
671
672 old_terrain = tile_terrain(ptile);
673
674 if (old_terrain == pterr
675 || (terrain_has_flag(pterr, TER_NO_CITIES)
676 && tile_city(ptile) != NULL)) {
677 return FALSE;
678 }
679
680 tile_change_terrain(ptile, pterr);
681 fix_tile_on_terrain_change(ptile, old_terrain, FALSE);
682 if (need_to_reassign_continents(old_terrain, pterr)) {
684
685 /* FIXME: adv / ai phase handling like in check_terrain_change() */
686
688 }
689
691
693
694 return TRUE;
695}
696
697/**********************************************************************/
700bool api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile,
701 const char *name)
702{
704 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, FALSE);
705 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
706
707 /* TODO: Allow initial citizen to be of nationality other than owner */
708 return create_city_for_player(pplayer, ptile, name);
709}
710
711/**********************************************************************/
714void api_edit_remove_city(lua_State *L, City *pcity)
715{
717 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
718
719 remove_city(pcity);
720}
721
722/**********************************************************************/
725void api_edit_create_building(lua_State *L, City *pcity, Building_Type *impr)
726{
728 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
730 /* FIXME: may "Special" impr be buildable? */
732 "It is a special item, not a city building");
733
734 if (!city_has_building(pcity, impr)) {
735 bool need_game_info = FALSE;
736 bool need_plr_info = FALSE;
737 struct player *old_owner = NULL, *pplayer = city_owner(pcity);
738 struct city *oldcity;
739
740 oldcity = build_or_move_building(pcity, impr, &old_owner);
741 if (oldcity) {
742 need_plr_info = TRUE;
743 }
744 if (old_owner && old_owner != pplayer) {
745 /* Great wonders make more changes. */
746 need_game_info = TRUE;
747 }
748
749 if (oldcity) {
750 if (city_refresh(oldcity)) {
751 auto_arrange_workers(oldcity);
752 }
753 send_city_info(NULL, oldcity);
754 }
755
756 if (city_refresh(pcity)) {
758 }
759 send_city_info(NULL, pcity);
760 if (need_game_info) {
761 send_game_info(NULL);
762 send_player_info_c(old_owner, NULL);
763 }
764 if (need_plr_info) {
765 send_player_info_c(pplayer, NULL);
766 }
767 }
768}
769
770/**********************************************************************/
773void api_edit_remove_building(lua_State *L, City *pcity, Building_Type *impr)
774{
776 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
778
779 if (city_has_building(pcity, impr)) {
780 city_remove_improvement(pcity, impr);
781 send_city_info(NULL, pcity);
782
783 if (is_wonder(impr)) {
784 if (is_great_wonder(impr)) {
785 send_game_info(NULL);
786 }
787 send_player_info_c(city_owner(pcity), NULL);
788 }
789 }
790}
791
792/**********************************************************************/
795Player *api_edit_create_player(lua_State *L, const char *username,
796 Nation_Type *pnation, const char *ai)
797{
798 struct player *pplayer = NULL;
799 char buf[128] = "";
800 struct fc_lua *fcl;
801
802 LUASCRIPT_CHECK_STATE(L, NULL);
803 LUASCRIPT_CHECK_ARG_NIL(L, username, 2, string, NULL);
804 if (!ai) {
806 }
807
808 fcl = luascript_get_fcl(L);
809
810 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!", NULL);
811
812 if (game_was_started()) {
813 create_command_newcomer(username, ai, FALSE, pnation, &pplayer,
814 buf, sizeof(buf));
815 } else {
816 create_command_pregame(username, ai, FALSE, &pplayer,
817 buf, sizeof(buf));
818 }
819
820 if (strlen(buf) > 0) {
821 luascript_log(fcl, LOG_NORMAL, "%s", buf);
822 }
823
824 return pplayer;
825}
826
827/**********************************************************************/
830void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
831{
833 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player);
834
835 pplayer->economic.gold = MAX(0, pplayer->economic.gold + amount);
836
837 send_player_info_c(pplayer, NULL);
838}
839
840/**********************************************************************/
847 Tech_Type *ptech, int cost,
848 bool notify,
849 const char *reason)
850{
851 struct research *presearch;
853 Tech_Type *result;
854
855 LUASCRIPT_CHECK_STATE(L, NULL);
856 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
857 LUASCRIPT_CHECK_ARG(L, cost >= -3, 4, "Unknown give_tech() cost value", NULL);
858
859 presearch = research_get(pplayer);
860 if (ptech) {
861 id = advance_number(ptech);
862 } else {
863 id = pick_free_tech(presearch);
864 }
865
866 if (is_future_tech(id)
867 || research_invention_state(presearch, id) != TECH_KNOWN) {
868 if (cost < 0) {
869 if (cost == -1) {
871 } else if (cost == -2) {
873 } else if (cost == -3) {
875 } else {
876
877 cost = 0;
878 }
879 }
880 research_apply_penalty(presearch, id, cost);
881 found_new_tech(presearch, id, FALSE, TRUE);
882 result = advance_by_number(id);
883 script_tech_learned(presearch, pplayer, result, reason);
884
885 if (notify && result != NULL) {
886 const char *adv_name = research_advance_name_translation(presearch, id);
887 char research_name[MAX_LEN_NAME * 2];
888
889 research_pretty_name(presearch, research_name, sizeof(research_name));
890
891 notify_player(pplayer, NULL, E_TECH_GAIN, ftc_server,
892 Q_("?fromscript:You acquire %s."), adv_name);
893 notify_research(presearch, pplayer, E_TECH_GAIN, ftc_server,
894 /* TRANS: "The Greeks ..." or "The members of
895 * team Red ..." */
896 Q_("?fromscript:The %s acquire %s and share this "
897 "advance with you."),
898 nation_plural_for_player(pplayer), adv_name);
899 notify_research_embassies(presearch, NULL, E_TECH_EMBASSY, ftc_server,
900 /* TRANS: "The Greeks ..." or "The members of
901 * team Red ..." */
902 Q_("?fromscript:The %s acquire %s."),
903 research_name, adv_name);
904 }
905
906 return result;
907 } else {
908 return NULL;
909 }
910}
911
912/**********************************************************************/
915bool api_edit_trait_mod_set(lua_State *L, Player *pplayer,
916 const char *tname, const int mod)
917{
918 enum trait tr;
919
921 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, FALSE);
922 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, FALSE);
923
924 tr = trait_by_name(tname, fc_strcasecmp);
925
926 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
927
928 pplayer->ai_common.traits[tr].mod += mod;
929
930 return TRUE;
931}
932
933/**********************************************************************/
936void api_edit_create_owned_extra(lua_State *L, Tile *ptile,
937 const char *name, Player *pplayer)
938{
939 struct extra_type *pextra;
940
942 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
943
944 if (name == NULL) {
945 return;
946 }
947
949
950 if (pextra != NULL) {
951 create_extra(ptile, pextra, pplayer);
954 }
955}
956
957/**********************************************************************/
960void api_edit_create_extra(lua_State *L, Tile *ptile, const char *name)
961{
962 api_edit_create_owned_extra(L, ptile, name, NULL);
963}
964
965/**********************************************************************/
968void api_edit_create_base(lua_State *L, Tile *ptile, const char *name,
969 Player *pplayer)
970{
971 api_edit_create_owned_extra(L, ptile, name, pplayer);
972}
973
974/**********************************************************************/
977void api_edit_create_road(lua_State *L, Tile *ptile, const char *name)
978{
979 api_edit_create_owned_extra(L, ptile, name, NULL);
980}
981
982/**********************************************************************/
985void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name)
986{
987 struct extra_type *pextra;
988
990 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
991
992 if (name == NULL) {
993 return;
994 }
995
997
998 if (pextra != NULL && tile_has_extra(ptile, pextra)) {
999 tile_extra_rm_apply(ptile, pextra);
1000 update_tile_knowledge(ptile);
1002 }
1003}
1004
1005/**********************************************************************/
1008void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label)
1009{
1011 LUASCRIPT_CHECK_SELF(L, ptile);
1012 LUASCRIPT_CHECK_ARG_NIL(L, label, 3, string);
1013
1014 tile_set_label(ptile, label);
1015 if (server_state() >= S_S_RUNNING) {
1016 send_tile_info(NULL, ptile, FALSE);
1017 }
1018}
1019
1020/**********************************************************************/
1023void api_edit_tile_show(lua_State *L, Tile *ptile, Player *pplayer)
1024{
1026 LUASCRIPT_CHECK_SELF(L, ptile);
1027 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player);
1028
1029 map_show_tile(pplayer, ptile);
1030}
1031
1032/**********************************************************************/
1035bool api_edit_tile_hide(lua_State *L, Tile *ptile, Player *pplayer)
1036{
1037 struct city *pcity;
1038
1040 LUASCRIPT_CHECK_SELF(L, ptile, FALSE);
1041 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player, FALSE);
1042
1043 if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
1044 /* Can't hide currently seen tile */
1045 return FALSE;
1046 }
1047
1048 pcity = tile_city(ptile);
1049
1050 if (pcity != NULL) {
1051 trade_partners_iterate(pcity, partner) {
1052 if (really_gives_vision(pplayer, city_owner(partner))) {
1053 /* Can't remove vision about trade partner */
1054 return FALSE;
1055 }
1057 }
1058
1059 dbv_clr(&pplayer->tile_known, tile_index(ptile));
1060
1061 send_tile_info(pplayer->connections, ptile, TRUE);
1062
1063 return TRUE;
1064}
1065
1066/**********************************************************************/
1070 int effect)
1071{
1075 2, "invalid climate change type");
1076 LUASCRIPT_CHECK_ARG(L, effect > 0, 3, "effect must be greater than zero");
1077
1079}
1080
1081/**********************************************************************/
1084Player *api_edit_civil_war(lua_State *L, Player *pplayer, int probability)
1085{
1086 LUASCRIPT_CHECK_STATE(L, NULL);
1087 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
1088 LUASCRIPT_CHECK_ARG(L, probability >= 0 && probability <= 100,
1089 3, "must be a percentage", NULL);
1090
1091 if (!civil_war_possible(pplayer, FALSE, FALSE)) {
1092 return NULL;
1093 }
1094
1095 if (probability == 0) {
1096 /* Calculate chance with normal rules */
1097 if (!civil_war_triggered(pplayer)) {
1098 return NULL;
1099 }
1100 } else {
1101 /* Fixed chance specified by script */
1102 if (fc_rand(100) >= probability) {
1103 return NULL;
1104 }
1105 }
1106
1107 return civil_war(pplayer);
1108}
1109
1110/**********************************************************************/
1113void api_edit_player_victory(lua_State *L, Player *pplayer)
1114{
1116 LUASCRIPT_CHECK_SELF(L, pplayer);
1117
1118 player_status_add(pplayer, PSTATUS_WINNER);
1119}
1120
1121/**********************************************************************/
1124bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile,
1125 int movecost,
1126 Unit *embark_to, bool disembark,
1127 bool conquer_city, bool conquer_extra,
1128 bool enter_hut, bool frighten_hut)
1129{
1132 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
1133 LUASCRIPT_CHECK_ARG(L, movecost >= 0, 4, "Negative move cost!", FALSE);
1134
1136 "Can't both enter and frighten a hut at the same time",
1137 TRUE);
1138
1139 if (!disembark && unit_transported(punit)) {
1140 /* Can't leave the transport. */
1141 return TRUE;
1142 }
1143
1144 if (unit_move_to_tile_test(&(wld.map), punit, ACTIVITY_IDLE,
1145 unit_tile(punit), ptile, TRUE,
1146 FALSE, embark_to, TRUE) != MR_OK) {
1147 /* Can't move to target. Return that unit is still alive. */
1148 return TRUE;
1149 }
1150
1151 return unit_move(punit, ptile, movecost,
1152 embark_to, embark_to != NULL,
1153 conquer_city, conquer_extra,
1155}
1156
1157/**********************************************************************/
1160bool api_edit_unit_move_old(lua_State *L, Unit *punit, Tile *ptile,
1161 int movecost)
1162{
1163 struct city *pcity;
1164
1165 deprecated_semantic_warning("edit.unit_move(unit, moveto, movecost)",
1166 "Unit:move(moveto, movecost)", "3.1");
1167
1170 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
1171 LUASCRIPT_CHECK_ARG(L, movecost >= 0, 4, "Negative move cost!", FALSE);
1172
1173 return unit_move(punit, ptile, movecost,
1174 /* Auto embark kept for backward compatibility. I have
1175 * no objection if you see the old behavior as a bug and
1176 * remove auto embarking completely or for transports
1177 * the unit can't legally board. -- Sveinung */
1178 NULL, TRUE,
1179 /* Backwards compatibility for old scripts in rulesets
1180 * and (scenario) savegames. I have no objection if you
1181 * see the old behavior as a bug and remove auto
1182 * conquering completely or for cities the unit can't
1183 * legally conquer. -- Sveinung */
1184 ((pcity = tile_city(ptile))
1185 && (unit_owner(punit)->ai_common.barbarian_type
1186 != ANIMAL_BARBARIAN)
1188 UCF_CAN_OCCUPY_CITY)
1189 && !unit_has_type_flag(punit, UTYF_CIVILIAN)
1191 city_owner(pcity))),
1192 (extra_owner(ptile) == NULL
1193 || pplayers_at_war(extra_owner(ptile),
1194 unit_owner(punit)))
1196 /* Backwards compatibility: unit_enter_hut() would
1197 * return without doing anything if the unit was
1198 * HUT_NOTHING. Setting this parameter to FALSE makes
1199 * sure unit_enter_hut() isn't called. */
1200 unit_can_do_action_result(punit, ACTRES_HUT_ENTER),
1201 unit_can_do_action_result(punit, ACTRES_HUT_FRIGHTEN));
1202}
1203
1204/**********************************************************************/
1208{
1211
1212 if (punit != NULL) {
1213 punit->stay = TRUE;
1214 }
1215}
1216
1217/**********************************************************************/
1221{
1224
1225 if (punit != NULL) {
1226 punit->stay = FALSE;
1227 }
1228}
1229
1230/**********************************************************************/
1233void api_edit_city_add_history(lua_State *L, City *pcity, int amount)
1234{
1236 LUASCRIPT_CHECK_SELF(L, pcity);
1237
1238 pcity->history += amount;
1239}
1240
1241/**********************************************************************/
1244void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount)
1245{
1247 LUASCRIPT_CHECK_SELF(L, pplayer);
1248
1249 pplayer->history += amount;
1250}
1251
1252/**********************************************************************/
1255void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount)
1256{
1258 LUASCRIPT_CHECK_SELF(L, pplayer);
1259
1260 update_bulbs(pplayer, amount, TRUE);
1261
1262 send_research_info(research_get(pplayer), NULL);
1263}
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:450
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:264
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:627
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:336
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:764
@ 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:3043
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2786
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:2836
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2739
#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:813
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:1001
action_id id
Definition actions.h:382
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:113
#define tile_has_extra(ptile, pextra)
Definition tile.h:150
#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:1948
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:346
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1721
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2417
bool could_unit_be_in_transport(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:695
#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:1178
void transform_unit(struct unit *punit, const struct unit_type *to_unit, int vet_loss)
Definition unittools.c:1566
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2795
bool place_unit(struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
Definition unittools.c:1724
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:1676
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2248
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:3885
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