Freeciv-3.1: /fast/freeciv/nightly/S3_1/server/scripting/api_server_edit.c Source File

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/**********************************************************************/
60 static void deprecated_semantic_warning(const char *call, const char *aka,
61 const char *deprecated_since)
62{
63 if (are_deprecation_warnings_enabled()) {
64 log_deprecation_always(
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/**********************************************************************/
102 bool api_edit_unleash_barbarians(lua_State *L, Tile *ptile)
103{
104 LUASCRIPT_CHECK_STATE(L, FALSE);
105 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, FALSE);
106
107 return unleash_barbarians(ptile);
108}
109
110/**********************************************************************/
113 void api_edit_place_partisans(lua_State *L, Tile *ptile, Player *pplayer,
114 int count, int sq_radius)
115{
116 LUASCRIPT_CHECK_STATE(L);
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/**********************************************************************/
129 Unit *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/**********************************************************************/
140 Unit *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)) {
181 luascript_log(fcl, LOG_ERROR,
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) {
196 unit_virtual_destroy(punit);
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)) {
204 unit_virtual_destroy(punit);
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);
214 fc_assert_action(placed, unit_virtual_destroy(punit); punit = NULL);
215
216 return punit;
217}
218
219/**********************************************************************/
222 bool 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
229 LUASCRIPT_CHECK_STATE(L, FALSE);
230 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
231 LUASCRIPT_CHECK_ARG_NIL(L, dest, 3, Tile, FALSE);
232
233 LUASCRIPT_CHECK(L, !(enter_hut && frighten_hut),
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,
253 enter_hut, frighten_hut);
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 }
263 if (is_non_allied_unit_tile(dest, owner)
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/**********************************************************************/
276 bool 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
284 LUASCRIPT_CHECK_STATE(L, FALSE);
285 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
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)
303 && uclass_has_flag(unit_class_get(punit),
304 UCF_CAN_OCCUPY_CITY)
305 && !unit_has_type_flag(punit, UTYF_CIVILIAN)
306 && pplayers_at_war(unit_owner(punit),
307 city_owner(pcity))),
308 (extra_owner(dest) == NULL
309 || pplayers_at_war(extra_owner(dest),
310 unit_owner(punit)))
311 && tile_has_claimable_base(dest, unit_type_get(punit)),
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 }
325 if (is_non_allied_unit_tile(dest, owner)
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/***********************************************************************/
338 bool api_edit_perform_action_unit_vs_city(lua_State *L, Unit *punit,
339 Action *paction, City *tgt)
340{
341 LUASCRIPT_CHECK_STATE(L, FALSE);
342 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
343 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
344 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, City, 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)) {
350 return unit_perform_action(unit_owner(punit), punit->id,
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/***********************************************************************/
362 bool api_edit_perform_action_unit_vs_city_impr(lua_State *L, Unit *punit,
363 Action *paction, City *tgt,
364 Building_Type *sub_tgt)
365{
366 LUASCRIPT_CHECK_STATE(L, FALSE);
367 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
368 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
369 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, City, FALSE);
370 LUASCRIPT_CHECK_ARG_NIL(L, sub_tgt, 5, Building_Type, 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)) {
376 return unit_perform_action(unit_owner(punit), punit->id,
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/***********************************************************************/
388 bool api_edit_perform_action_unit_vs_city_tech(lua_State *L, Unit *punit,
389 Action *paction, City *tgt,
390 Tech_Type *sub_tgt)
391{
392 LUASCRIPT_CHECK_STATE(L, FALSE);
393 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
394 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
395 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, City, 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)) {
402 return unit_perform_action(unit_owner(punit), punit->id,
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/***********************************************************************/
414 bool api_edit_perform_action_unit_vs_unit(lua_State *L, Unit *punit,
415 Action *paction, Unit *tgt)
416{
417 const struct civ_map *nmap = &(wld.map);
418
419 LUASCRIPT_CHECK_STATE(L, FALSE);
420 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
421 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
422 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, Unit, 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)) {
428 return unit_perform_action(unit_owner(punit), punit->id,
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/***********************************************************************/
440 bool api_edit_perform_action_unit_vs_tile(lua_State *L, Unit *punit,
441 Action *paction, Tile *tgt)
442{
443 bool enabled = FALSE;
444 const struct civ_map *nmap = &(wld.map);
445
446 LUASCRIPT_CHECK_STATE(L, FALSE);
447 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
448 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
449 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, Tile, 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) {
483 return unit_perform_action(unit_owner(punit), punit->id,
484 tile_index(tgt), IDENTITY_NUMBER_ZERO,
485 city_name_suggestion(unit_owner(punit), tgt),
486 paction->id, ACT_REQ_RULES);
487 } else {
488 /* Action not enabled */
489 return FALSE;
490 }
491}
492
493/***********************************************************************/
496 bool api_edit_perform_action_unit_vs_tile_extra(lua_State *L, Unit *punit,
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
504 LUASCRIPT_CHECK_STATE(L, FALSE);
505 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
506 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
507 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, Tile, 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) {
545 return unit_perform_action(unit_owner(punit), punit->id,
546 tile_index(tgt), sub_target->id,
547 city_name_suggestion(unit_owner(punit), tgt),
548 paction->id, ACT_REQ_RULES);
549 } else {
550 /* Action not enabled */
551 return FALSE;
552 }
553}
554
555/***********************************************************************/
558 bool api_edit_perform_action_unit_vs_self(lua_State *L, Unit *punit,
559 Action *paction)
560{
561 const struct civ_map *nmap = &(wld.map);
562
563 LUASCRIPT_CHECK_STATE(L, FALSE);
564 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
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)) {
571 return unit_perform_action(unit_owner(punit), punit->id,
572 IDENTITY_NUMBER_ZERO, IDENTITY_NUMBER_ZERO,
573 "",
574 paction->id, ACT_REQ_RULES);
575 } else {
576 /* Action not enabled */
577 return FALSE;
578 }
579}
580
581/**********************************************************************/
584 void api_edit_unit_turn(lua_State *L, Unit *punit, Direction dir)
585{
586 LUASCRIPT_CHECK_STATE(L);
587 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit);
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/**********************************************************************/
602 bool api_edit_unit_upgrade(lua_State *L, Unit *punit, int vet_loss)
603{
604 const struct unit_type *ptype;
605
606 LUASCRIPT_CHECK_STATE(L, FALSE);
607 LUASCRIPT_CHECK_SELF(L, punit, FALSE);
608
609 ptype = can_upgrade_unittype(unit_owner(punit), unit_type_get(punit));
610 if (!ptype) {
611 return FALSE;
612 }
613 return ur_transform_unit(punit, ptype, vet_loss);
614}
615
616/**********************************************************************/
620 bool api_edit_unit_transform(lua_State *L, Unit *punit, Unit_Type *ptype,
621 int vet_loss)
622{
623 LUASCRIPT_CHECK_STATE(L, FALSE);
624 LUASCRIPT_CHECK_SELF(L, punit, FALSE);
625 LUASCRIPT_CHECK_ARG_NIL(L, ptype, 3, Unit_Type, FALSE);
626
627 return ur_transform_unit(punit, ptype, vet_loss);
628}
629
630/**********************************************************************/
633 void api_edit_unit_kill(lua_State *L, Unit *punit, const char *reason,
634 Player *killer)
635{
636 enum unit_loss_reason loss_reason;
637
638 LUASCRIPT_CHECK_STATE(L);
639 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit);
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/**********************************************************************/
653 bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr)
654{
655 struct terrain *old_terrain;
656
657 LUASCRIPT_CHECK_STATE(L, FALSE);
658 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, FALSE);
659 LUASCRIPT_CHECK_ARG_NIL(L, pterr, 3, Terrain, 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)) {
672 assign_continent_numbers();
673
674 /* FIXME: adv / ai phase handling like in check_terrain_change() */
675
676 send_all_known_tiles(NULL);
677 }
678
679 update_tile_knowledge(ptile);
680
681 tile_change_side_effects(ptile, TRUE);
682
683 return TRUE;
684}
685
686/**********************************************************************/
689 bool api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile,
690 const char *name)
691{
692 LUASCRIPT_CHECK_STATE(L, FALSE);
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/**********************************************************************/
703 void api_edit_remove_city(lua_State *L, City *pcity)
704{
705 LUASCRIPT_CHECK_STATE(L);
706 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
707
708 remove_city(pcity);
709}
710
711/**********************************************************************/
714 void api_edit_create_building(lua_State *L, City *pcity, Building_Type *impr)
715{
716 LUASCRIPT_CHECK_STATE(L);
717 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
718 LUASCRIPT_CHECK_ARG_NIL(L, impr, 3, Building_Type);
719 /* FIXME: may "Special" impr be buildable? */
720 LUASCRIPT_CHECK_ARG(L, !is_special_improvement(impr), 3,
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)) {
746 auto_arrange_workers(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/**********************************************************************/
762 void api_edit_remove_building(lua_State *L, City *pcity, Building_Type *impr)
763{
764 LUASCRIPT_CHECK_STATE(L);
765 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
766 LUASCRIPT_CHECK_ARG_NIL(L, impr, 3, Building_Type);
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/**********************************************************************/
784 Player *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) {
794 ai = default_ai_type_name();
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/**********************************************************************/
819 void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
820{
821 LUASCRIPT_CHECK_STATE(L);
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/**********************************************************************/
835 Tech_Type *api_edit_give_technology(lua_State *L, Player *pplayer,
836 Tech_Type *ptech, int cost,
837 bool notify,
838 const char *reason)
839{
840 struct research *presearch;
841 Tech_type_id id;
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) {
859 cost = game.server.freecost;
860 } else if (cost == -2) {
861 cost = game.server.conquercost;
862 } else if (cost == -3) {
863 cost = game.server.diplbulbcost;
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/**********************************************************************/
904 bool api_edit_trait_mod_set(lua_State *L, Player *pplayer,
905 const char *tname, const int mod)
906{
907 enum trait tr;
908
909 LUASCRIPT_CHECK_STATE(L, -1);
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/**********************************************************************/
925 void api_edit_create_owned_extra(lua_State *L, Tile *ptile,
926 const char *name, Player *pplayer)
927{
928 struct extra_type *pextra;
929
930 LUASCRIPT_CHECK_STATE(L);
931 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
932
933 if (name == NULL) {
934 return;
935 }
936
937 pextra = extra_type_by_rule_name(name);
938
939 if (pextra != NULL) {
940 create_extra(ptile, pextra, pplayer);
941 update_tile_knowledge(ptile);
942 tile_change_side_effects(ptile, TRUE);
943 }
944}
945
946/**********************************************************************/
949 void 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/**********************************************************************/
957 void 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/**********************************************************************/
966 void 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/**********************************************************************/
974 void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name)
975{
976 struct extra_type *pextra;
977
978 LUASCRIPT_CHECK_STATE(L);
979 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
980
981 if (name == NULL) {
982 return;
983 }
984
985 pextra = extra_type_by_rule_name(name);
986
987 if (pextra != NULL && tile_has_extra(ptile, pextra)) {
988 tile_extra_rm_apply(ptile, pextra);
989 update_tile_knowledge(ptile);
990 tile_change_side_effects(ptile, TRUE);
991 }
992}
993
994/**********************************************************************/
997 void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label)
998{
999 LUASCRIPT_CHECK_STATE(L);
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/**********************************************************************/
1012 void api_edit_tile_show(lua_State *L, Tile *ptile, Player *pplayer)
1013{
1014 LUASCRIPT_CHECK_STATE(L);
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/**********************************************************************/
1024 bool api_edit_tile_hide(lua_State *L, Tile *ptile, Player *pplayer)
1025{
1026 struct city *pcity;
1027
1028 LUASCRIPT_CHECK_STATE(L, FALSE);
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 }
1045 } trade_partners_iterate_end;
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/**********************************************************************/
1058 void api_edit_climate_change(lua_State *L, enum climate_change_type type,
1059 int effect)
1060{
1061 LUASCRIPT_CHECK_STATE(L);
1062 LUASCRIPT_CHECK_ARG(L, type == CLIMATE_CHANGE_GLOBAL_WARMING
1063 || type == CLIMATE_CHANGE_NUCLEAR_WINTER,
1064 2, "invalid climate change type");
1065 LUASCRIPT_CHECK_ARG(L, effect > 0, 3, "effect must be greater than zero");
1066
1067 climate_change(type == CLIMATE_CHANGE_GLOBAL_WARMING, effect);
1068}
1069
1070/**********************************************************************/
1073 Player *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/**********************************************************************/
1102 void api_edit_player_victory(lua_State *L, Player *pplayer)
1103{
1104 LUASCRIPT_CHECK_STATE(L);
1105 LUASCRIPT_CHECK_SELF(L, pplayer);
1106
1107 player_status_add(pplayer, PSTATUS_WINNER);
1108}
1109
1110/**********************************************************************/
1113 bool 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{
1119 LUASCRIPT_CHECK_STATE(L, FALSE);
1120 LUASCRIPT_CHECK_SELF(L, punit, FALSE);
1121 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
1122 LUASCRIPT_CHECK_ARG(L, movecost >= 0, 4, "Negative move cost!", FALSE);
1123
1124 LUASCRIPT_CHECK(L, !(enter_hut && frighten_hut),
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,
1143 enter_hut, frighten_hut);
1144}
1145
1146/**********************************************************************/
1149 bool 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
1157 LUASCRIPT_CHECK_STATE(L, FALSE);
1158 LUASCRIPT_CHECK_SELF(L, punit, FALSE);
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)
1176 && uclass_has_flag(unit_class_get(punit),
1177 UCF_CAN_OCCUPY_CITY)
1178 && !unit_has_type_flag(punit, UTYF_CIVILIAN)
1179 && pplayers_at_war(unit_owner(punit),
1180 city_owner(pcity))),
1181 (extra_owner(ptile) == NULL
1182 || pplayers_at_war(extra_owner(ptile),
1183 unit_owner(punit)))
1184 && tile_has_claimable_base(ptile, unit_type_get(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/**********************************************************************/
1196 void api_edit_unit_moving_disallow(lua_State *L, Unit *punit)
1197{
1198 LUASCRIPT_CHECK_STATE(L);
1199 LUASCRIPT_CHECK_SELF(L, punit);
1200
1201 if (punit != NULL) {
1202 punit->stay = TRUE;
1203 }
1204}
1205
1206/**********************************************************************/
1209 void api_edit_unit_moving_allow(lua_State *L, Unit *punit)
1210{
1211 LUASCRIPT_CHECK_STATE(L);
1212 LUASCRIPT_CHECK_SELF(L, punit);
1213
1214 if (punit != NULL) {
1215 punit->stay = FALSE;
1216 }
1217}
1218
1219/**********************************************************************/
1222 void api_edit_city_add_history(lua_State *L, City *pcity, int amount)
1223{
1224 LUASCRIPT_CHECK_STATE(L);
1225 LUASCRIPT_CHECK_SELF(L, pcity);
1226
1227 pcity->history += amount;
1228}
1229
1230/**********************************************************************/
1233 void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount)
1234{
1235 LUASCRIPT_CHECK_STATE(L);
1236 LUASCRIPT_CHECK_SELF(L, pplayer);
1237
1238 pplayer->history += amount;
1239}
1240
1241/**********************************************************************/
1244 void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount)
1245{
1246 LUASCRIPT_CHECK_STATE(L);
1247 LUASCRIPT_CHECK_SELF(L, pplayer);
1248
1249 update_bulbs(pplayer, amount, TRUE);
1250
1251 send_research_info(research_get(pplayer), NULL);
1252}
action_get_actor_kind
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1730
is_action_enabled_unit_on_tile
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
is_action_enabled_unit_on_units
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
is_action_enabled_unit_on_city
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
is_action_enabled_unit_on_unit
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
action_get_target_kind
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1740
is_action_enabled_unit_on_self
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
is_action_enabled_unit_on_extras
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
action_has_result
#define action_has_result(_act_, _res_)
Definition actions.h:448
default_ai_type_name
const char * default_ai_type_name(void)
Definition aiiface.c:262
aiiface.h
api_game_find.h
ur_transform_unit
static bool ur_transform_unit(struct unit *punit, const struct unit_type *to_unit, int vet_loss)
Definition api_server_edit.c:77
api_edit_perform_action_unit_vs_tile_extra
bool api_edit_perform_action_unit_vs_tile_extra(lua_State *L, Unit *punit, Action *paction, Tile *tgt, const char *sub_tgt)
Definition api_server_edit.c:496
api_edit_perform_action_unit_vs_tile
bool api_edit_perform_action_unit_vs_tile(lua_State *L, Unit *punit, Action *paction, Tile *tgt)
Definition api_server_edit.c:440
api_edit_climate_change
void api_edit_climate_change(lua_State *L, enum climate_change_type type, int effect)
Definition api_server_edit.c:1058
api_edit_unit_moving_allow
void api_edit_unit_moving_allow(lua_State *L, Unit *punit)
Definition api_server_edit.c:1209
deprecated_semantic_warning
static void deprecated_semantic_warning(const char *call, const char *aka, const char *deprecated_since)
Definition api_server_edit.c:60
api_edit_remove_city
void api_edit_remove_city(lua_State *L, City *pcity)
Definition api_server_edit.c:703
api_edit_trait_mod_set
bool api_edit_trait_mod_set(lua_State *L, Player *pplayer, const char *tname, const int mod)
Definition api_server_edit.c:904
api_edit_unleash_barbarians
bool api_edit_unleash_barbarians(lua_State *L, Tile *ptile)
Definition api_server_edit.c:102
api_edit_remove_building
void api_edit_remove_building(lua_State *L, City *pcity, Building_Type *impr)
Definition api_server_edit.c:762
api_edit_player_victory
void api_edit_player_victory(lua_State *L, Player *pplayer)
Definition api_server_edit.c:1102
api_edit_create_extra
void api_edit_create_extra(lua_State *L, Tile *ptile, const char *name)
Definition api_server_edit.c:949
api_edit_create_unit
Unit * api_edit_create_unit(lua_State *L, Player *pplayer, Tile *ptile, Unit_Type *ptype, int veteran_level, City *homecity, int moves_left)
Definition api_server_edit.c:129
api_edit_perform_action_unit_vs_unit
bool api_edit_perform_action_unit_vs_unit(lua_State *L, Unit *punit, Action *paction, Unit *tgt)
Definition api_server_edit.c:414
api_edit_player_add_history
void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount)
Definition api_server_edit.c:1233
api_edit_give_technology
Tech_Type * api_edit_give_technology(lua_State *L, Player *pplayer, Tech_Type *ptech, int cost, bool notify, const char *reason)
Definition api_server_edit.c:835
api_edit_perform_action_unit_vs_city_impr
bool api_edit_perform_action_unit_vs_city_impr(lua_State *L, Unit *punit, Action *paction, City *tgt, Building_Type *sub_tgt)
Definition api_server_edit.c:362
api_edit_create_building
void api_edit_create_building(lua_State *L, City *pcity, Building_Type *impr)
Definition api_server_edit.c:714
api_edit_create_unit_full
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)
Definition api_server_edit.c:140
api_edit_player_give_bulbs
void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount)
Definition api_server_edit.c:1244
api_edit_change_terrain
bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr)
Definition api_server_edit.c:653
api_edit_create_owned_extra
void api_edit_create_owned_extra(lua_State *L, Tile *ptile, const char *name, Player *pplayer)
Definition api_server_edit.c:925
api_edit_tile_show
void api_edit_tile_show(lua_State *L, Tile *ptile, Player *pplayer)
Definition api_server_edit.c:1012
api_edit_unit_kill
void api_edit_unit_kill(lua_State *L, Unit *punit, const char *reason, Player *killer)
Definition api_server_edit.c:633
api_edit_tile_hide
bool api_edit_tile_hide(lua_State *L, Tile *ptile, Player *pplayer)
Definition api_server_edit.c:1024
api_edit_unit_turn
void api_edit_unit_turn(lua_State *L, Unit *punit, Direction dir)
Definition api_server_edit.c:584
api_edit_place_partisans
void api_edit_place_partisans(lua_State *L, Tile *ptile, Player *pplayer, int count, int sq_radius)
Definition api_server_edit.c:113
api_edit_remove_extra
void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name)
Definition api_server_edit.c:974
api_edit_tile_set_label
void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label)
Definition api_server_edit.c:997
api_edit_create_road
void api_edit_create_road(lua_State *L, Tile *ptile, const char *name)
Definition api_server_edit.c:966
api_edit_unit_move_old
bool api_edit_unit_move_old(lua_State *L, Unit *punit, Tile *ptile, int movecost)
Definition api_server_edit.c:1149
api_edit_perform_action_unit_vs_city
bool api_edit_perform_action_unit_vs_city(lua_State *L, Unit *punit, Action *paction, City *tgt)
Definition api_server_edit.c:338
api_edit_city_add_history
void api_edit_city_add_history(lua_State *L, City *pcity, int amount)
Definition api_server_edit.c:1222
api_edit_create_city
bool api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile, const char *name)
Definition api_server_edit.c:689
api_edit_unit_teleport
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)
Definition api_server_edit.c:222
api_edit_unit_moving_disallow
void api_edit_unit_moving_disallow(lua_State *L, Unit *punit)
Definition api_server_edit.c:1196
api_edit_unit_teleport_old
bool api_edit_unit_teleport_old(lua_State *L, Unit *punit, Tile *dest)
Definition api_server_edit.c:276
api_edit_unit_upgrade
bool api_edit_unit_upgrade(lua_State *L, Unit *punit, int vet_loss)
Definition api_server_edit.c:602
api_edit_unit_move
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)
Definition api_server_edit.c:1113
api_edit_perform_action_unit_vs_self
bool api_edit_perform_action_unit_vs_self(lua_State *L, Unit *punit, Action *paction)
Definition api_server_edit.c:558
api_edit_create_player
Player * api_edit_create_player(lua_State *L, const char *username, Nation_Type *pnation, const char *ai)
Definition api_server_edit.c:784
api_edit_unit_transform
bool api_edit_unit_transform(lua_State *L, Unit *punit, Unit_Type *ptype, int vet_loss)
Definition api_server_edit.c:620
api_edit_change_gold
void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
Definition api_server_edit.c:819
api_edit_civil_war
Player * api_edit_civil_war(lua_State *L, Player *pplayer, int probability)
Definition api_server_edit.c:1073
api_edit_perform_action_unit_vs_city_tech
bool api_edit_perform_action_unit_vs_city_tech(lua_State *L, Unit *punit, Action *paction, City *tgt, Tech_Type *sub_tgt)
Definition api_server_edit.c:388
api_edit_create_base
void api_edit_create_base(lua_State *L, Tile *ptile, const char *name, Player *pplayer)
Definition api_server_edit.c:957
api_server_edit.h
climate_change_type
climate_change_type
Definition api_server_edit.h:23
CLIMATE_CHANGE_GLOBAL_WARMING
@ CLIMATE_CHANGE_GLOBAL_WARMING
Definition api_server_edit.h:24
CLIMATE_CHANGE_NUCLEAR_WINTER
@ CLIMATE_CHANGE_NUCLEAR_WINTER
Definition api_server_edit.h:25
unleash_barbarians
bool unleash_barbarians(struct tile *ptile)
Definition barbarian.c:271
barbarian.h
dbv_clr
void dbv_clr(struct dbv *pdbv, int bit)
Definition bitvector.c:167
city_has_building
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1212
city_remove_improvement
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3280
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_name_suggestion
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Definition citytools.c:451
send_city_info
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2320
build_or_move_building
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:2925
remove_city
void remove_city(struct city *pcity)
Definition citytools.c:1677
create_city_for_player
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name)
Definition citytools.c:1649
citytools.h
auto_arrange_workers
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:368
city_refresh
bool city_refresh(struct city *pcity)
Definition cityturn.c:161
cityturn.h
console.h
are_deprecation_warnings_enabled
bool are_deprecation_warnings_enabled(void)
Definition deprecations.c:43
deprecations.h
log_deprecation_always
#define log_deprecation_always(message,...)
Definition deprecations.h:51
conquer_city
static void conquer_city(QVariant data1, QVariant data2)
Definition dialogs.cpp:1831
enter_hut
static void enter_hut(QVariant data1, QVariant data2)
Definition dialogs.cpp:2570
frighten_hut
static void frighten_hut(QVariant data1, QVariant data2)
Definition dialogs.cpp:2600
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
cost
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
id
int int id
Definition editgui_g.h:28
extra_type_by_rule_name
struct extra_type * extra_type_by_rule_name(const char *name)
Definition extras.c:204
extra_owner
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1068
Tech_type_id
int Tech_type_id
Definition fc_types.h:347
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
IDENTITY_NUMBER_ZERO
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
Q_
#define Q_(String)
Definition fcintl.h:70
ftc_server
const struct ft_color ftc_server
Definition featured_text.c:77
game
struct civ_game game
Definition game.c:57
wld
struct world wld
Definition game.c:58
send_game_info
void send_game_info(struct conn_list *dest)
Definition gamehand.c:905
gamehand.h
owner
struct city * owner
Definition citydlg.c:219
type
GType type
Definition repodlgs.c:1312
is_special_improvement
bool is_special_improvement(const struct impr_type *pimprove)
Definition improvement.c:792
is_wonder
bool is_wonder(const struct impr_type *pimprove)
Definition improvement.c:341
is_great_wonder
bool is_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:767
name
const char * name
Definition inputfile.c:127
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
fc_assert_action
#define fc_assert_action(condition, action)
Definition log.h:187
LOG_ERROR
@ LOG_ERROR
Definition log.h:30
LOG_NORMAL
@ LOG_NORMAL
Definition log.h:32
log_error
#define log_error(message,...)
Definition log.h:103
luascript_log
void luascript_log(struct fc_lua *fcl, enum log_level level, const char *format,...)
Definition luascript.c:409
luascript_get_fcl
struct fc_lua * luascript_get_fcl(lua_State *L)
Definition luascript.c:366
luascript.h
LUASCRIPT_CHECK_STATE
#define LUASCRIPT_CHECK_STATE(L,...)
Definition luascript.h:117
LUASCRIPT_CHECK_SELF
#define LUASCRIPT_CHECK_SELF(L, value,...)
Definition luascript.h:146
LUASCRIPT_CHECK_ARG_NIL
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition luascript.h:138
LUASCRIPT_CHECK_ARG
#define LUASCRIPT_CHECK_ARG(L, check, narg, msg,...)
Definition luascript.h:131
LUASCRIPT_CHECK
#define LUASCRIPT_CHECK(L, check, msg,...)
Definition luascript.h:124
Direction
enum direction8 Direction
Definition luascript_types.h:57
same_pos
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:938
map.h
assign_continent_numbers
void assign_continent_numbers(void)
Definition mapgen_utils.c:449
mapgen_utils.h
really_gives_vision
bool really_gives_vision(struct player *me, struct player *them)
Definition maphand.c:342
send_tile_info
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:488
send_all_known_tiles
void send_all_known_tiles(struct conn_list *dest)
Definition maphand.c:441
need_to_reassign_continents
bool need_to_reassign_continents(const struct terrain *oldter, const struct terrain *newter)
Definition maphand.c:1921
climate_change
void climate_change(bool warming, int effect)
Definition maphand.c:130
create_extra
void create_extra(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition maphand.c:2540
map_show_tile
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:760
tile_change_side_effects
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2708
map_is_known_and_seen
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:900
fix_tile_on_terrain_change
void fix_tile_on_terrain_change(struct tile *ptile, struct terrain *oldter, bool extend_rivers)
Definition maphand.c:1959
update_tile_knowledge
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1427
maphand.h
can_exist_at_tile
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:275
unit_move_to_tile_test
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
can_unit_exist_at_tile
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:304
unit_teleport_to_tile_test
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
movement.h
MR_OK
@ MR_OK
Definition movement.h:33
nation_plural_for_player
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
notify_research
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:394
notify_player
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:292
notify_research_embassies
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:434
notify.h
pplayers_at_war
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1364
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
player_status_add
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3042
civil_war_triggered
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2785
send_player_info_c
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1000
civil_war
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:2835
civil_war_possible
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2738
plrhand.h
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:34
research_advance_name_translation
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:271
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:126
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
research_pretty_name
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:167
research.h
script_server.h
MAX
#define MAX(x, y)
Definition shared.h:54
game_was_started
bool game_was_started(void)
Definition srv_main.c:339
server_state
enum server_states server_state(void)
Definition srv_main.c:323
srv_main.h
create_command_newcomer
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
create_command_pregame
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
stdinhand.h
action
Definition actions.h:379
action::id
action_id id
Definition actions.h:380
advance
Definition tech.h:124
advance::item_number
Tech_type_id item_number
Definition tech.h:125
ai_trait::mod
int mod
Definition traits.h:39
call
Definition agents.c:49
city
Definition city.h:309
city::history
int history
Definition city.h:393
city::id
int id
Definition city.h:315
civ_game::server
struct civ_game::@30::@34 server
civ_game::diplbulbcost
int diplbulbcost
Definition game.h:138
civ_game::conquercost
int conquercost
Definition game.h:135
civ_game::freecost
int freecost
Definition game.h:147
civ_map
Definition map_types.h:71
effect
Definition effects.h:340
extra_type
Definition extras.h:85
extra_type::id
int id
Definition extras.h:86
fc_lua
Definition luascript.h:44
impr_type
Definition improvement.h:68
impr_type::item_number
Impr_type_id item_number
Definition improvement.h:69
nation_type
Definition nation.h:97
player_ai::traits
struct ai_trait * traits
Definition player.h:132
player_economic::gold
int gold
Definition player.h:70
player
Definition player.h:249
player::ai_common
struct player_ai ai_common
Definition player.h:288
player::tile_known
struct dbv tile_known
Definition player.h:306
player::connections
struct conn_list * connections
Definition player.h:298
player::economic
struct player_economic economic
Definition player.h:284
player::history
int history
Definition player.h:312
research
Definition research.h:39
terrain
Definition terrain.h:176
tile
Definition tile.h:49
unit_type
Definition unittype.h:481
unit
Definition unit.h:138
unit::moves_left
int moves_left
Definition unit.h:150
unit::id
int id
Definition unit.h:145
unit::stay
bool stay
Definition unit.h:205
unit::facing
enum direction8 facing
Definition unit.h:142
unit::homecity
int homecity
Definition unit.h:146
unit::veteran
int veteran
Definition unit.h:152
veteran_level
Definition unittype.h:467
world::map
struct civ_map map
Definition world_object.h:38
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
advance_by_number
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
is_future_tech
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
advance_number
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
found_new_tech
void found_new_tech(struct research *presearch, Tech_type_id tech_found, bool was_discovery, bool saving_bulbs)
Definition techtools.c:327
research_apply_penalty
void research_apply_penalty(struct research *presearch, Tech_type_id tech, int penalty_percent)
Definition techtools.c:67
pick_free_tech
Tech_type_id pick_free_tech(struct research *presearch)
Definition techtools.c:1360
send_research_info
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
update_bulbs
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech)
Definition techtools.c:643
script_tech_learned
void script_tech_learned(struct research *presearch, struct player *originating_plr, struct advance *tech, const char *reason)
Definition techtools.c:84
techtools.h
terrain_has_flag
#define terrain_has_flag(terr, flag)
Definition terrain.h:269
tile_has_claimable_base
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:209
tile_change_terrain
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:473
tile_extra_rm_apply
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:578
tile_set_label
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1080
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_index
#define tile_index(_pt_)
Definition tile.h:87
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:109
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
trade_partners_iterate_end
#define trade_partners_iterate_end
Definition traderoutes.h:165
trade_partners_iterate
#define trade_partners_iterate(c, p)
Definition traderoutes.h:160
unit_transform_result
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:1942
unit_can_do_action_result
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:341
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1715
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2411
could_unit_be_in_transport
bool could_unit_be_in_transport(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:687
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
UU_OK
@ UU_OK
Definition unit.h:61
is_non_allied_unit_tile
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:423
unit_perform_action
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:3173
unithand.h
place_partisans
void place_partisans(struct tile *pcenter, struct player *powner, int count, int sq_radius)
Definition unittools.c:1181
transform_unit
void transform_unit(struct unit *punit, const struct unit_type *to_unit, int vet_loss)
Definition unittools.c:1569
send_unit_info
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2798
place_unit
bool place_unit(struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
Definition unittools.c:1727
unit_virtual_prepare
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:1679
wipe_unit
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2251
unit_move
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
unittools.h
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
unit_type_array_first
struct unit_type * unit_type_array_first(void)
Definition unittype.c:58
num_role_units
int num_role_units(int role)
Definition unittype.c:2251
utype_player_already_has_this_unique
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1979
can_upgrade_unittype
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1755
utype_veteran_levels
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2661
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
unit_class_get
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2546
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
unit_type_array_last
const struct unit_type * unit_type_array_last(void)
Definition unittype.c:69
unittype.h
uclass_has_flag
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:753