Freeciv-3.3: /fast/freeciv/nightly/main/server/scripting/api_server_edit.c Source File

Freeciv-3.3

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 "rand.h"
20
21/* common */
22#include "map.h"
23#include "movement.h"
24#include "research.h"
25#include "unittype.h"
26
27/* common/scriptcore */
28#include "api_game_find.h"
29#include "luascript.h"
30
31/* server */
32#include "aiiface.h"
33#include "barbarian.h"
34#include "citytools.h"
35#include "cityturn.h" /* city_refresh() auto_arrange_workers() */
36#include "console.h" /* enum rfc_status */
37#include "gamehand.h"
38#include "maphand.h"
39#include "notify.h"
40#include "plrhand.h"
41#include "srv_main.h" /* game_was_started() */
42#include "stdinhand.h"
43#include "techtools.h"
44#include "unithand.h"
45#include "unittools.h"
46
47/* server/scripting */
48#include "script_server.h"
49
50/* server/generator */
51#include "mapgen_utils.h"
52
53#include "api_server_edit.h"
54
55
56/**********************************************************************/
59 bool api_edit_unleash_barbarians(lua_State *L, Tile *ptile)
60{
61 LUASCRIPT_CHECK_STATE(L, FALSE);
62 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, FALSE);
63
64 return unleash_barbarians(ptile);
65}
66
67/**********************************************************************/
71static bool
72ur_transform_unit(struct unit *punit, const struct unit_type *to_unit,
73 int vet_loss)
74{
75 if (UU_OK == unit_transform_result(&(wld.map), punit, to_unit)) {
76 /* Avoid getting overt veteranship if a user requests increasing it */
77 if (vet_loss < 0) {
78 int vl = utype_veteran_levels(to_unit);
79
80 vl = punit->veteran - vl + 1;
81 if (vl >= 0) {
82 vet_loss = 0;
83 } else {
84 vet_loss = MAX(vet_loss, vl);
85 }
86 }
87 transform_unit(punit, to_unit, vet_loss);
88 return TRUE;
89 } else {
90 return FALSE;
91 }
92}
93
94/**********************************************************************/
97 void api_edit_place_partisans(lua_State *L, Tile *ptile, Player *pplayer,
98 int count, int sq_radius)
99{
100 LUASCRIPT_CHECK_STATE(L);
101 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
102 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player);
103 LUASCRIPT_CHECK_ARG(L, 0 <= sq_radius, 5, "radius must be positive");
104 LUASCRIPT_CHECK(L, 0 < num_role_units(L_PARTISAN),
105 "no partisans in ruleset");
106
107 return place_partisans(ptile, pplayer, count, sq_radius);
108}
109
110/**********************************************************************/
113 Unit *api_edit_create_unit(lua_State *L, Player *pplayer, Tile *ptile,
114 Unit_Type *ptype, int veteran_level,
115 City *homecity, int moves_left)
116{
117 return api_edit_create_unit_full(L, pplayer, ptile, ptype, veteran_level,
118 homecity, moves_left, -1, NULL);
119}
120
121/**********************************************************************/
124 Unit *api_edit_create_unit_full(lua_State *L, Player *pplayer,
125 Tile *ptile,
126 Unit_Type *ptype, int veteran_level,
127 City *homecity, int moves_left,
128 int hp_left,
129 Unit *ptransport)
130{
131 struct fc_lua *fcl;
132 struct city *pcity;
133 struct unit *punit;
134#ifndef FREECIV_NDEBUG
135 bool placed;
136#endif
137
138 LUASCRIPT_CHECK_STATE(L, NULL);
139 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
140 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, NULL);
141
142 fcl = luascript_get_fcl(L);
143
144 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!", NULL);
145
146 if (ptype == NULL
147 || ptype < unit_type_array_first() || ptype > unit_type_array_last()) {
148 return NULL;
149 }
150
151 if (is_non_allied_unit_tile(ptile, pplayer,
152 utype_has_flag(ptype, UTYF_FLAGLESS))) {
153 luascript_log(fcl, LOG_ERROR, "create_unit_full: tile is occupied by "
154 "enemy unit");
155 return NULL;
156 }
157
158 pcity = tile_city(ptile);
159 if (pcity != NULL && !pplayers_allied(pplayer, city_owner(pcity))) {
160 luascript_log(fcl, LOG_ERROR, "create_unit_full: tile is occupied by "
161 "enemy city");
162 return NULL;
163 }
164
165 if (utype_player_already_has_this_unique(pplayer, ptype)) {
166 luascript_log(fcl, LOG_ERROR,
167 "create_unit_full: player already has unique unit");
168 return NULL;
169 }
170
171 punit = unit_virtual_prepare(pplayer, ptile, ptype, veteran_level,
172 homecity ? homecity->id : 0,
173 moves_left, hp_left);
174 if (ptransport) {
175 /* The unit maybe can't freely load into the transport
176 * but must be able to be in it, see can_unit_load() */
177 int ret = same_pos(ptile, unit_tile(ptransport))
178 && could_unit_be_in_transport(punit, ptransport);
179
180 if (!ret) {
181 unit_virtual_destroy(punit);
182 luascript_log(fcl, LOG_ERROR, "create_unit_full: '%s' cannot transport "
183 "'%s' here",
184 utype_rule_name(unit_type_get(ptransport)),
185 utype_rule_name(ptype));
186 return NULL;
187 }
188 } else if (!can_exist_at_tile(&(wld.map), ptype, ptile)) {
189 unit_virtual_destroy(punit);
190 luascript_log(fcl, LOG_ERROR, "create_unit_full: '%s' cannot exist at "
191 "tile", utype_rule_name(ptype));
192 return NULL;
193 }
194
195#ifndef FREECIV_NDEBUG
196 placed =
197#endif
198 place_unit(punit, pplayer, homecity, ptransport, TRUE);
199 fc_assert_action(placed, unit_virtual_destroy(punit); punit = NULL);
200
201 return punit;
202}
203
204/**********************************************************************/
207 bool api_edit_unit_teleport(lua_State *L, Unit *punit, Tile *dest,
208 Unit *embark_to, bool allow_disembark,
209 bool conquer_city, bool conquer_extra,
210 bool enter_hut, bool frighten_hut)
211{
212 bool alive;
213
214 LUASCRIPT_CHECK_STATE(L, FALSE);
215 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
216 LUASCRIPT_CHECK_ARG_NIL(L, dest, 3, Tile, FALSE);
217
218 LUASCRIPT_CHECK(L, !(enter_hut && frighten_hut),
219 "Can't both enter and frighten a hut at the same time",
220 TRUE);
221
222 if (!allow_disembark && unit_transported(punit)) {
223 /* Can't leave the transport. */
224 return TRUE;
225 }
226
227 if (unit_teleport_to_tile_test(&(wld.map), punit, ACTIVITY_IDLE,
228 unit_tile(punit), dest, FALSE,
229 embark_to, TRUE) != MR_OK) {
230 /* Can't teleport to target. Return that unit is still alive. */
231 return TRUE;
232 }
233
234 /* Teleport first so destination is revealed even if unit dies */
235 alive = unit_move(punit, dest, 0,
236 embark_to, embark_to != NULL,
237 conquer_city, conquer_extra,
238 enter_hut, frighten_hut);
239 if (alive) {
240 struct player *owner = unit_owner(punit);
241 struct city *pcity = tile_city(dest);
242
243 if (!can_unit_exist_at_tile(&(wld.map), punit, dest)
244 && !unit_transported(punit)) {
245 wipe_unit(punit, ULR_NONNATIVE_TERR, NULL);
246 return FALSE;
247 }
248 if (is_non_allied_unit_tile(dest, owner,
249 unit_has_type_flag(punit, UTYF_FLAGLESS))
250 || (pcity != NULL
251 && !pplayers_allied(city_owner(pcity), owner))) {
252 wipe_unit(punit, ULR_STACK_CONFLICT, NULL);
253 return FALSE;
254 }
255 }
256
257 return alive;
258}
259
260/***********************************************************************/
263 bool api_edit_perform_action_unit_vs_city(lua_State *L, Unit *punit,
264 Action *paction, City *tgt)
265{
266 LUASCRIPT_CHECK_STATE(L, FALSE);
267 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
268 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
269 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, City, FALSE);
270
271 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
272 fc_assert_ret_val(action_get_target_kind(paction) == ATK_CITY, FALSE);
273 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
274 if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
275 return unit_perform_action(unit_owner(punit), punit->id,
276 tgt->id, IDENTITY_NUMBER_ZERO, "",
277 paction->id, ACT_REQ_RULES);
278 } else {
279 /* Action not enabled */
280 return FALSE;
281 }
282}
283
284/***********************************************************************/
287 bool api_edit_perform_action_unit_vs_city_impr(lua_State *L, Unit *punit,
288 Action *paction, City *tgt,
289 Building_Type *sub_tgt)
290{
291 LUASCRIPT_CHECK_STATE(L, FALSE);
292 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
293 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
294 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, City, FALSE);
295 LUASCRIPT_CHECK_ARG_NIL(L, sub_tgt, 5, Building_Type, FALSE);
296
297 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
298 fc_assert_ret_val(action_get_target_kind(paction) == ATK_CITY, FALSE);
299 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
300 if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
301 return unit_perform_action(unit_owner(punit), punit->id,
302 tgt->id, sub_tgt->item_number, "",
303 paction->id, ACT_REQ_RULES);
304 } else {
305 /* Action not enabled */
306 return FALSE;
307 }
308}
309
310/***********************************************************************/
313 bool api_edit_perform_action_unit_vs_city_tech(lua_State *L, Unit *punit,
314 Action *paction, City *tgt,
315 Tech_Type *sub_tgt)
316{
317 LUASCRIPT_CHECK_STATE(L, FALSE);
318 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
319 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
320 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, City, FALSE);
321 LUASCRIPT_CHECK_ARG_NIL(L, sub_tgt, 5, Tech_Type, FALSE);
322
323 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
324 fc_assert_ret_val(action_get_target_kind(paction) == ATK_CITY, FALSE);
325 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
326 if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
327 return unit_perform_action(unit_owner(punit), punit->id,
328 tgt->id, sub_tgt->item_number, "",
329 paction->id, ACT_REQ_RULES);
330 } else {
331 /* Action not enabled */
332 return FALSE;
333 }
334}
335
336/***********************************************************************/
339 bool api_edit_perform_action_unit_vs_unit(lua_State *L, Unit *punit,
340 Action *paction, Unit *tgt)
341{
342 const struct civ_map *nmap = &(wld.map);
343
344 LUASCRIPT_CHECK_STATE(L, FALSE);
345 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
346 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
347 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, Unit, FALSE);
348
349 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
350 fc_assert_ret_val(action_get_target_kind(paction) == ATK_UNIT, FALSE);
351 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
352 if (is_action_enabled_unit_on_unit(nmap, paction->id, punit, tgt)) {
353 return unit_perform_action(unit_owner(punit), punit->id,
354 tgt->id, IDENTITY_NUMBER_ZERO, "",
355 paction->id, ACT_REQ_RULES);
356 } else {
357 /* Action not enabled */
358 return FALSE;
359 }
360}
361
362/***********************************************************************/
365 bool api_edit_perform_action_unit_vs_tile(lua_State *L, Unit *punit,
366 Action *paction, Tile *tgt)
367{
368 bool enabled = FALSE;
369 const struct civ_map *nmap = &(wld.map);
370
371 LUASCRIPT_CHECK_STATE(L, FALSE);
372 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
373 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
374 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, Tile, FALSE);
375
376 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
377 switch (action_get_target_kind(paction)) {
378 case ATK_UNITS:
379 enabled = is_action_enabled_unit_on_stack(nmap, paction->id, punit, tgt);
380 break;
381 case ATK_TILE:
382 enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
383 tgt, NULL);
384 break;
385 case ATK_EXTRAS:
386 enabled = is_action_enabled_unit_on_extras(nmap, paction->id, punit,
387 tgt, NULL);
388 break;
389 case ATK_CITY:
390 /* Not handled here. */
391 fc_assert(action_get_target_kind(paction) != ATK_CITY);
392 break;
393 case ATK_UNIT:
394 /* Not handled here. */
395 fc_assert(action_get_target_kind(paction) != ATK_UNIT);
396 break;
397 case ATK_SELF:
398 /* Not handled here. */
399 fc_assert(action_get_target_kind(paction) != ATK_SELF);
400 break;
401 case ATK_COUNT:
402 /* Should not exist */
403 fc_assert(action_get_target_kind(paction) != ATK_COUNT);
404 break;
405 }
406
407 if (enabled) {
408 return unit_perform_action(unit_owner(punit), punit->id,
409 tile_index(tgt), IDENTITY_NUMBER_ZERO,
410 city_name_suggestion(unit_owner(punit), tgt),
411 paction->id, ACT_REQ_RULES);
412 } else {
413 /* Action not enabled */
414 return FALSE;
415 }
416}
417
418/***********************************************************************/
421 bool api_edit_perform_action_unit_vs_tile_extra(lua_State *L, Unit *punit,
422 Action *paction, Tile *tgt,
423 const char *sub_tgt)
424{
425 struct extra_type *sub_target;
426 bool enabled = FALSE;
427 const struct civ_map *nmap = &(wld.map);
428
429 LUASCRIPT_CHECK_STATE(L, FALSE);
430 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
431 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
432 LUASCRIPT_CHECK_ARG_NIL(L, tgt, 4, Tile, FALSE);
433 LUASCRIPT_CHECK_ARG_NIL(L, sub_tgt, 5, string, FALSE);
434
435 sub_target = extra_type_by_rule_name(sub_tgt);
436 LUASCRIPT_CHECK_ARG(L, sub_target != NULL, 5, "No such extra", FALSE);
437
438 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
439 switch (action_get_target_kind(paction)) {
440 case ATK_UNITS:
441 enabled = is_action_enabled_unit_on_stack(nmap, paction->id, punit, tgt);
442 break;
443 case ATK_TILE:
444 enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
445 tgt, sub_target);
446 break;
447 case ATK_EXTRAS:
448 enabled = is_action_enabled_unit_on_extras(nmap, paction->id, punit,
449 tgt, sub_target);
450 break;
451 case ATK_CITY:
452 /* Not handled here. */
453 fc_assert(action_get_target_kind(paction) != ATK_CITY);
454 break;
455 case ATK_UNIT:
456 /* Not handled here. */
457 fc_assert(action_get_target_kind(paction) != ATK_UNIT);
458 break;
459 case ATK_SELF:
460 /* Not handled here. */
461 fc_assert(action_get_target_kind(paction) != ATK_SELF);
462 break;
463 case ATK_COUNT:
464 /* Should not exist */
465 fc_assert(action_get_target_kind(paction) != ATK_COUNT);
466 break;
467 }
468
469 if (enabled) {
470 return unit_perform_action(unit_owner(punit), punit->id,
471 tile_index(tgt), sub_target->id,
472 city_name_suggestion(unit_owner(punit), tgt),
473 paction->id, ACT_REQ_RULES);
474 } else {
475 /* Action not enabled */
476 return FALSE;
477 }
478}
479
480/***********************************************************************/
483 bool api_edit_perform_action_unit_vs_self(lua_State *L, Unit *punit,
484 Action *paction)
485{
486 const struct civ_map *nmap = &(wld.map);
487
488 LUASCRIPT_CHECK_STATE(L, FALSE);
489 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
490 LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
491
492 fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
493 fc_assert_ret_val(action_get_target_kind(paction) == ATK_SELF, FALSE);
494 fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
495 if (is_action_enabled_unit_on_self(nmap, paction->id, punit)) {
496 return unit_perform_action(unit_owner(punit), punit->id,
497 IDENTITY_NUMBER_ZERO, IDENTITY_NUMBER_ZERO,
498 "",
499 paction->id, ACT_REQ_RULES);
500 } else {
501 /* Action not enabled */
502 return FALSE;
503 }
504}
505
506/**********************************************************************/
509 void api_edit_unit_turn(lua_State *L, Unit *punit, Direction dir)
510{
511 LUASCRIPT_CHECK_STATE(L);
512 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit);
513
514 if (direction8_is_valid(dir)) {
515 punit->facing = dir;
516
517 send_unit_info(NULL, punit);
518 } else {
519 log_error("Illegal direction %d for unit from lua script", dir);
520 }
521}
522
523/**********************************************************************/
527 bool api_edit_unit_upgrade(lua_State *L, Unit *punit, int vet_loss)
528{
529 const struct unit_type *ptype;
530
531 LUASCRIPT_CHECK_STATE(L, FALSE);
532 LUASCRIPT_CHECK_SELF(L, punit, FALSE);
533
534 ptype = can_upgrade_unittype(unit_owner(punit), unit_type_get(punit));
535 if (!ptype) {
536 return FALSE;
537 }
538 return ur_transform_unit(punit, ptype, vet_loss);
539}
540
541/**********************************************************************/
545 bool api_edit_unit_transform(lua_State *L, Unit *punit, Unit_Type *ptype,
546 int vet_loss)
547{
548 LUASCRIPT_CHECK_STATE(L, FALSE);
549 LUASCRIPT_CHECK_SELF(L, punit, FALSE);
550 LUASCRIPT_CHECK_ARG_NIL(L, ptype, 3, Unit_Type, FALSE);
551
552 return ur_transform_unit(punit, ptype, vet_loss);
553}
554
555/**********************************************************************/
558 void api_edit_unit_kill(lua_State *L, Unit *punit, const char *reason,
559 Player *killer)
560{
561 enum unit_loss_reason loss_reason;
562
563 LUASCRIPT_CHECK_STATE(L);
564 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit);
565 LUASCRIPT_CHECK_ARG_NIL(L, reason, 3, string);
566
567 loss_reason = unit_loss_reason_by_name(reason, fc_strcasecmp);
568
569 LUASCRIPT_CHECK_ARG(L, unit_loss_reason_is_valid(loss_reason), 3,
570 "Invalid unit loss reason");
571
572 wipe_unit(punit, loss_reason, killer);
573}
574
575/**********************************************************************/
578 bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr)
579{
580 struct terrain *old_terrain;
581
582 LUASCRIPT_CHECK_STATE(L, FALSE);
583 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, FALSE);
584 LUASCRIPT_CHECK_ARG_NIL(L, pterr, 3, Terrain, FALSE);
585
586 old_terrain = tile_terrain(ptile);
587
588 if (old_terrain == pterr
589 || (terrain_has_flag(pterr, TER_NO_CITIES)
590 && tile_city(ptile) != NULL)) {
591 return FALSE;
592 }
593
594 tile_change_terrain(ptile, pterr);
595 fix_tile_on_terrain_change(ptile, old_terrain, FALSE);
596 if (need_to_reassign_continents(old_terrain, pterr)) {
597 assign_continent_numbers();
598
599 /* FIXME: adv / ai phase handling like in check_terrain_change() */
600
601 send_all_known_tiles(NULL);
602 }
603
604 update_tile_knowledge(ptile);
605
606 tile_change_side_effects(ptile, TRUE);
607
608 return TRUE;
609}
610
611/**********************************************************************/
614 bool api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile,
615 const char *name)
616{
617 LUASCRIPT_CHECK_STATE(L, FALSE);
618 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, FALSE);
619 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
620
621 /* TODO: Allow initial citizen to be of nationality other than owner */
622 return create_city_for_player(pplayer, ptile, name);
623}
624
625/**********************************************************************/
628 void api_edit_remove_city(lua_State *L, City *pcity)
629{
630 LUASCRIPT_CHECK_STATE(L);
631 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
632
633 remove_city(pcity);
634}
635
636/**********************************************************************/
639 bool api_edit_transfer_city(lua_State *L, City *pcity, Player *new_owner)
640{
641 LUASCRIPT_CHECK_STATE(L, FALSE);
642 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City, FALSE);
643 LUASCRIPT_CHECK_ARG_NIL(L, new_owner, 3, Player, FALSE);
644
645 return transfer_city(new_owner, pcity, FALSE, FALSE, FALSE, FALSE, FALSE);
646}
647
648/**********************************************************************/
651 void api_edit_create_building(lua_State *L, City *pcity, Building_Type *impr)
652{
653 LUASCRIPT_CHECK_STATE(L);
654 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
655 LUASCRIPT_CHECK_ARG_NIL(L, impr, 3, Building_Type);
656 /* FIXME: may "Special" impr be buildable? */
657 LUASCRIPT_CHECK_ARG(L, !is_special_improvement(impr), 3,
658 "It is a special item, not a city building");
659
660 if (!city_has_building(pcity, impr)) {
661 bool need_game_info = FALSE;
662 bool need_plr_info = FALSE;
663 struct player *old_owner = NULL, *pplayer = city_owner(pcity);
664 struct city *oldcity;
665
666 oldcity = build_or_move_building(pcity, impr, &old_owner);
667 if (oldcity) {
668 need_plr_info = TRUE;
669 }
670 if (old_owner && old_owner != pplayer) {
671 /* Great wonders make more changes. */
672 need_game_info = TRUE;
673 }
674
675 if (oldcity) {
676 if (city_refresh(oldcity)) {
677 auto_arrange_workers(oldcity);
678 }
679 send_city_info(NULL, oldcity);
680 }
681
682 if (city_refresh(pcity)) {
683 auto_arrange_workers(pcity);
684 }
685 send_city_info(NULL, pcity);
686 if (need_game_info) {
687 send_game_info(NULL);
688 send_player_info_c(old_owner, NULL);
689 }
690 if (need_plr_info) {
691 send_player_info_c(pplayer, NULL);
692 }
693 }
694}
695
696/**********************************************************************/
699 void api_edit_remove_building(lua_State *L, City *pcity, Building_Type *impr)
700{
701 LUASCRIPT_CHECK_STATE(L);
702 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
703 LUASCRIPT_CHECK_ARG_NIL(L, impr, 3, Building_Type);
704
705 if (city_has_building(pcity, impr)) {
706 city_remove_improvement(pcity, impr);
707 send_city_info(NULL, pcity);
708
709 if (is_wonder(impr)) {
710 if (is_great_wonder(impr)) {
711 send_game_info(NULL);
712 }
713 send_player_info_c(city_owner(pcity), NULL);
714 }
715 }
716}
717
718/**********************************************************************/
721 Player *api_edit_create_player(lua_State *L, const char *username,
722 Nation_Type *pnation, const char *ai)
723{
724 struct player *pplayer = NULL;
725 char buf[128] = "";
726 struct fc_lua *fcl;
727
728 LUASCRIPT_CHECK_STATE(L, NULL);
729 LUASCRIPT_CHECK_ARG_NIL(L, username, 2, string, NULL);
730 if (!ai) {
731 ai = default_ai_type_name();
732 }
733
734 fcl = luascript_get_fcl(L);
735
736 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!", NULL);
737
738 if (game_was_started()) {
739 create_command_newcomer(username, ai, FALSE, pnation, &pplayer,
740 buf, sizeof(buf));
741 } else {
742 create_command_pregame(username, ai, FALSE, &pplayer,
743 buf, sizeof(buf));
744 }
745
746 if (strlen(buf) > 0) {
747 luascript_log(fcl, LOG_NORMAL, "%s", buf);
748 }
749
750 return pplayer;
751}
752
753/**********************************************************************/
756 void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
757{
758 LUASCRIPT_CHECK_STATE(L);
759 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player);
760
761 pplayer->economic.gold = MAX(0, pplayer->economic.gold + amount);
762
763 send_player_info_c(pplayer, NULL);
764}
765
766/**********************************************************************/
769 void api_edit_change_infrapoints(lua_State *L, Player *pplayer, int amount)
770{
771 LUASCRIPT_CHECK_STATE(L);
772 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player);
773
774 pplayer->economic.infra_points
775 = MAX(0, pplayer->economic.infra_points + amount);
776
777 send_player_info_c(pplayer, NULL);
778}
779
780/**********************************************************************/
786 Tech_Type *api_edit_give_technology(lua_State *L, Player *pplayer,
787 Tech_Type *ptech, int cost,
788 bool notify,
789 const char *reason)
790{
791 struct research *presearch;
792 Tech_type_id id;
793 Tech_Type *result;
794
795 LUASCRIPT_CHECK_STATE(L, NULL);
796 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
797 LUASCRIPT_CHECK_ARG(L, cost >= -3, 4, "Unknown give_tech() cost value", NULL);
798
799 presearch = research_get(pplayer);
800 if (ptech) {
801 id = advance_number(ptech);
802 } else {
803 id = pick_free_tech(presearch);
804 }
805
806 if (is_future_tech(id)
807 || research_invention_state(presearch, id) != TECH_KNOWN) {
808 if (cost < 0) {
809 if (cost == -1) {
810 cost = game.server.freecost;
811 } else if (cost == -2) {
812 cost = game.server.conquercost;
813 } else if (cost == -3) {
814 cost = game.server.diplbulbcost;
815 } else {
816
817 cost = 0;
818 }
819 }
820 research_apply_penalty(presearch, id, cost);
821 found_new_tech(presearch, id, FALSE, TRUE);
822 result = advance_by_number(id);
823 script_tech_learned(presearch, pplayer, result, reason);
824
825 if (notify && result != NULL) {
826 const char *adv_name = research_advance_name_translation(presearch, id);
827 char research_name[MAX_LEN_NAME * 2];
828
829 research_pretty_name(presearch, research_name, sizeof(research_name));
830
831 notify_player(pplayer, NULL, E_TECH_GAIN, ftc_server,
832 Q_("?fromscript:You acquire %s."), adv_name);
833 notify_research(presearch, pplayer, E_TECH_GAIN, ftc_server,
834 /* TRANS: "The Greeks ..." or "The members of
835 * team Red ..." */
836 Q_("?fromscript:The %s acquire %s and share this "
837 "advance with you."),
838 nation_plural_for_player(pplayer), adv_name);
839 notify_research_embassies(presearch, NULL, E_TECH_EMBASSY, ftc_server,
840 /* TRANS: "The Greeks ..." or "The members of
841 * team Red ..." */
842 Q_("?fromscript:The %s acquire %s."),
843 research_name, adv_name);
844 }
845
846 return result;
847 } else {
848 return NULL;
849 }
850}
851
852/**********************************************************************/
855 bool api_edit_trait_mod_set(lua_State *L, Player *pplayer,
856 const char *tname, const int mod)
857{
858 enum trait tr;
859
860 LUASCRIPT_CHECK_STATE(L, -1);
861 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, FALSE);
862 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, FALSE);
863
864 tr = trait_by_name(tname, fc_strcasecmp);
865
866 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
867
868 pplayer->ai_common.traits[tr].mod += mod;
869
870 return TRUE;
871}
872
873/**********************************************************************/
876 void api_edit_create_owned_extra(lua_State *L, Tile *ptile,
877 const char *name, Player *pplayer)
878{
879 struct extra_type *pextra;
880
881 LUASCRIPT_CHECK_STATE(L);
882 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
883
884 if (name == NULL) {
885 return;
886 }
887
888 pextra = extra_type_by_rule_name(name);
889
890 if (pextra != NULL) {
891 create_extra(ptile, pextra, pplayer);
892 update_tile_knowledge(ptile);
893 tile_change_side_effects(ptile, TRUE);
894 }
895}
896
897/**********************************************************************/
900 void api_edit_create_extra(lua_State *L, Tile *ptile, const char *name)
901{
902 api_edit_create_owned_extra(L, ptile, name, NULL);
903}
904
905/**********************************************************************/
908 void api_edit_create_base(lua_State *L, Tile *ptile, const char *name,
909 Player *pplayer)
910{
911 api_edit_create_owned_extra(L, ptile, name, pplayer);
912}
913
914/**********************************************************************/
917 void api_edit_create_road(lua_State *L, Tile *ptile, const char *name)
918{
919 api_edit_create_owned_extra(L, ptile, name, NULL);
920}
921
922/**********************************************************************/
925 void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name)
926{
927 struct extra_type *pextra;
928
929 LUASCRIPT_CHECK_STATE(L);
930 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
931
932 if (name == NULL) {
933 return;
934 }
935
936 pextra = extra_type_by_rule_name(name);
937
938 if (pextra != NULL && tile_has_extra(ptile, pextra)) {
939 tile_extra_rm_apply(ptile, pextra);
940 update_tile_knowledge(ptile);
941 tile_change_side_effects(ptile, TRUE);
942 }
943}
944
945/**********************************************************************/
948 void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label)
949{
950 LUASCRIPT_CHECK_STATE(L);
951 LUASCRIPT_CHECK_SELF(L, ptile);
952 LUASCRIPT_CHECK_ARG_NIL(L, label, 3, string);
953
954 tile_set_label(ptile, label);
955 if (server_state() >= S_S_RUNNING) {
956 send_tile_info(NULL, ptile, FALSE);
957 }
958}
959
960/**********************************************************************/
963 void api_edit_tile_show(lua_State *L, Tile *ptile, Player *pplayer)
964{
965 LUASCRIPT_CHECK_STATE(L);
966 LUASCRIPT_CHECK_SELF(L, ptile);
967 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player);
968
969 map_show_tile(pplayer, ptile);
970}
971
972/**********************************************************************/
975 bool api_edit_tile_hide(lua_State *L, Tile *ptile, Player *pplayer)
976{
977 struct city *pcity;
978
979 LUASCRIPT_CHECK_STATE(L, FALSE);
980 LUASCRIPT_CHECK_SELF(L, ptile, FALSE);
981 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player, FALSE);
982
983 if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
984 /* Can't hide currently seen tile */
985 return FALSE;
986 }
987
988 pcity = tile_city(ptile);
989
990 if (pcity != NULL) {
991 trade_partners_iterate(pcity, partner) {
992 if (really_gives_vision(pplayer, city_owner(partner))) {
993 /* Can't remove vision about trade partner */
994 return FALSE;
995 }
996 } trade_partners_iterate_end;
997 }
998
999 dbv_clr(&pplayer->tile_known, tile_index(ptile));
1000
1001 send_tile_info(pplayer->connections, ptile, TRUE);
1002
1003 return TRUE;
1004}
1005
1006/**********************************************************************/
1009 void api_edit_climate_change(lua_State *L, enum climate_change_type type,
1010 int effect)
1011{
1012 LUASCRIPT_CHECK_STATE(L);
1013 LUASCRIPT_CHECK_ARG(L, type == CLIMATE_CHANGE_GLOBAL_WARMING
1014 || type == CLIMATE_CHANGE_NUCLEAR_WINTER,
1015 2, "invalid climate change type");
1016 LUASCRIPT_CHECK_ARG(L, effect > 0, 3, "effect must be greater than zero");
1017
1018 climate_change(type == CLIMATE_CHANGE_GLOBAL_WARMING, effect);
1019}
1020
1021/**********************************************************************/
1024 Player *api_edit_civil_war(lua_State *L, Player *pplayer, int probability)
1025{
1026 LUASCRIPT_CHECK_STATE(L, NULL);
1027 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
1028 LUASCRIPT_CHECK_ARG(L, probability >= 0 && probability <= 100,
1029 3, "must be a percentage", NULL);
1030
1031 if (!civil_war_possible(pplayer, FALSE, FALSE)) {
1032 return NULL;
1033 }
1034
1035 if (probability == 0) {
1036 /* Calculate chance with normal rules */
1037 if (!civil_war_triggered(pplayer)) {
1038 return NULL;
1039 }
1040 } else {
1041 /* Fixed chance specified by script */
1042 if (fc_rand(100) >= probability) {
1043 return NULL;
1044 }
1045 }
1046
1047 return civil_war(pplayer);
1048}
1049
1050/**********************************************************************/
1053 void api_edit_player_victory(lua_State *L, Player *pplayer)
1054{
1055 LUASCRIPT_CHECK_STATE(L);
1056 LUASCRIPT_CHECK_SELF(L, pplayer);
1057
1058 player_status_add(pplayer, PSTATUS_WINNER);
1059}
1060
1061/**********************************************************************/
1064 bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile,
1065 int movecost,
1066 Unit *embark_to, bool disembark,
1067 bool conquer_city, bool conquer_extra,
1068 bool enter_hut, bool frighten_hut)
1069{
1070 LUASCRIPT_CHECK_STATE(L, FALSE);
1071 LUASCRIPT_CHECK_SELF(L, punit, FALSE);
1072 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
1073 LUASCRIPT_CHECK_ARG(L, movecost >= 0, 4, "Negative move cost!", FALSE);
1074
1075 LUASCRIPT_CHECK(L, !(enter_hut && frighten_hut),
1076 "Can't both enter and frighten a hut at the same time",
1077 TRUE);
1078
1079 if (!disembark && unit_transported(punit)) {
1080 /* Can't leave the transport. */
1081 return TRUE;
1082 }
1083
1084 if (unit_move_to_tile_test(&(wld.map), punit, ACTIVITY_IDLE,
1085 unit_tile(punit), ptile, TRUE,
1086 FALSE, embark_to, TRUE) != MR_OK) {
1087 /* Can't move to target. Return that unit is still alive. */
1088 return TRUE;
1089 }
1090
1091 return unit_move(punit, ptile, movecost,
1092 embark_to, embark_to != NULL,
1093 conquer_city, conquer_extra,
1094 enter_hut, frighten_hut);
1095}
1096
1097/**********************************************************************/
1100 void api_edit_unit_moving_disallow(lua_State *L, Unit *punit)
1101{
1102 LUASCRIPT_CHECK_STATE(L);
1103 LUASCRIPT_CHECK_SELF(L, punit);
1104
1105 if (punit != NULL) {
1106 punit->stay = TRUE;
1107 }
1108}
1109
1110/**********************************************************************/
1113 void api_edit_unit_moving_allow(lua_State *L, Unit *punit)
1114{
1115 LUASCRIPT_CHECK_STATE(L);
1116 LUASCRIPT_CHECK_SELF(L, punit);
1117
1118 if (punit != NULL) {
1119 punit->stay = FALSE;
1120 }
1121}
1122
1123/**********************************************************************/
1126 void api_edit_city_add_history(lua_State *L, City *pcity, int amount)
1127{
1128 LUASCRIPT_CHECK_STATE(L);
1129 LUASCRIPT_CHECK_SELF(L, pcity);
1130
1131 pcity->history += amount;
1132}
1133
1134/**********************************************************************/
1137 void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount)
1138{
1139 LUASCRIPT_CHECK_STATE(L);
1140 LUASCRIPT_CHECK_SELF(L, pplayer);
1141
1142 pplayer->history += amount;
1143}
1144
1145/**********************************************************************/
1156 void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount,
1157 Tech_Type *tech)
1158{
1159 struct research *presearch;
1160
1161 LUASCRIPT_CHECK_STATE(L);
1162 LUASCRIPT_CHECK_SELF(L, pplayer);
1163 presearch = research_get(pplayer);
1164 fc_assert_ret(presearch);
1165
1166 if (!tech) {
1167 update_bulbs(pplayer, amount, TRUE, TRUE);
1168
1169 send_research_info(presearch, NULL);
1170 } else if (advance_number(tech) == presearch->researching) {
1171 update_bulbs(pplayer, amount, TRUE, FALSE);
1172 /* Clean the saved tech to get no surprizes switching */
1173 presearch->researching_saved = A_UNKNOWN;
1174
1175 send_research_info(presearch, NULL);
1176 } else {
1177 /* Sometimes we may set negative bulbs, it's normal though lurking */
1178 if (game.server.multiresearch) {
1179 presearch->inventions[advance_number(tech)].bulbs_researched_saved
1180 += amount;
1181 /* Currently, multiresearch data are not sent to clients */
1182 } else {
1183 int oldb = presearch->bulbs_researched;
1184
1185 /* NOTE: We can set a tech we already know / can't research here.
1186 * Probably it's safe as we can't switch into it any way. */
1187 if (presearch->researching_saved != advance_number(tech)) {
1188 presearch->researching_saved = advance_number(tech);
1189 presearch->bulbs_researching_saved
1190 = amount + presearch->free_bulbs;
1191 } else {
1192 presearch->bulbs_researching_saved
1193 += amount + presearch->free_bulbs;
1194 }
1195 /* For consistency, modify current bulbs alongside
1196 * (sometimes getting into "overresearch" situation, but ok) */
1197 presearch->bulbs_researched = amount
1198 - amount * game.server.techpenalty / 100 + presearch->free_bulbs;
1199 if (oldb != presearch->bulbs_researched) {
1200 send_research_info(presearch, NULL);
1201 }
1202 }
1203 }
1204}
action_get_actor_kind
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1073
is_action_enabled_unit_on_stack
bool is_action_enabled_unit_on_stack(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile)
Definition actions.c:3217
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:3293
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:3052
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:3129
action_get_target_kind
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1083
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:3442
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:3370
action_has_result
#define action_has_result(_act_, _res_)
Definition actions.h:175
default_ai_type_name
const char * default_ai_type_name(void)
Definition aiiface.c:264
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:72
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:421
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:365
api_edit_climate_change
void api_edit_climate_change(lua_State *L, enum climate_change_type type, int effect)
Definition api_server_edit.c:1009
api_edit_player_give_bulbs
void api_edit_player_give_bulbs(lua_State *L, Player *pplayer, int amount, Tech_Type *tech)
Definition api_server_edit.c:1156
api_edit_unit_moving_allow
void api_edit_unit_moving_allow(lua_State *L, Unit *punit)
Definition api_server_edit.c:1113
api_edit_remove_city
void api_edit_remove_city(lua_State *L, City *pcity)
Definition api_server_edit.c:628
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:855
api_edit_unleash_barbarians
bool api_edit_unleash_barbarians(lua_State *L, Tile *ptile)
Definition api_server_edit.c:59
api_edit_remove_building
void api_edit_remove_building(lua_State *L, City *pcity, Building_Type *impr)
Definition api_server_edit.c:699
api_edit_player_victory
void api_edit_player_victory(lua_State *L, Player *pplayer)
Definition api_server_edit.c:1053
api_edit_create_extra
void api_edit_create_extra(lua_State *L, Tile *ptile, const char *name)
Definition api_server_edit.c:900
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:113
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:339
api_edit_player_add_history
void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount)
Definition api_server_edit.c:1137
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:786
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:287
api_edit_create_building
void api_edit_create_building(lua_State *L, City *pcity, Building_Type *impr)
Definition api_server_edit.c:651
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:124
api_edit_transfer_city
bool api_edit_transfer_city(lua_State *L, City *pcity, Player *new_owner)
Definition api_server_edit.c:639
api_edit_change_terrain
bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr)
Definition api_server_edit.c:578
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:876
api_edit_tile_show
void api_edit_tile_show(lua_State *L, Tile *ptile, Player *pplayer)
Definition api_server_edit.c:963
api_edit_unit_kill
void api_edit_unit_kill(lua_State *L, Unit *punit, const char *reason, Player *killer)
Definition api_server_edit.c:558
api_edit_tile_hide
bool api_edit_tile_hide(lua_State *L, Tile *ptile, Player *pplayer)
Definition api_server_edit.c:975
api_edit_unit_turn
void api_edit_unit_turn(lua_State *L, Unit *punit, Direction dir)
Definition api_server_edit.c:509
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:97
api_edit_remove_extra
void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name)
Definition api_server_edit.c:925
api_edit_tile_set_label
void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label)
Definition api_server_edit.c:948
api_edit_create_road
void api_edit_create_road(lua_State *L, Tile *ptile, const char *name)
Definition api_server_edit.c:917
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:263
api_edit_city_add_history
void api_edit_city_add_history(lua_State *L, City *pcity, int amount)
Definition api_server_edit.c:1126
api_edit_create_city
bool api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile, const char *name)
Definition api_server_edit.c:614
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:207
api_edit_unit_moving_disallow
void api_edit_unit_moving_disallow(lua_State *L, Unit *punit)
Definition api_server_edit.c:1100
api_edit_unit_upgrade
bool api_edit_unit_upgrade(lua_State *L, Unit *punit, int vet_loss)
Definition api_server_edit.c:527
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:1064
api_edit_change_infrapoints
void api_edit_change_infrapoints(lua_State *L, Player *pplayer, int amount)
Definition api_server_edit.c:769
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:483
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:721
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:545
api_edit_change_gold
void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
Definition api_server_edit.c:756
api_edit_civil_war
Player * api_edit_civil_war(lua_State *L, Player *pplayer, int probability)
Definition api_server_edit.c:1024
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:313
api_edit_create_base
void api_edit_create_base(lua_State *L, Tile *ptile, const char *name, Player *pplayer)
Definition api_server_edit.c:908
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:272
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:1236
city_remove_improvement
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3367
city_owner
#define city_owner(_pcity_)
Definition city.h:563
city_name_suggestion
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Definition citytools.c:453
send_city_info
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2351
build_or_move_building
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:3002
remove_city
void remove_city(struct city *pcity)
Definition citytools.c:1702
create_city_for_player
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name)
Definition citytools.c:1674
transfer_city
bool transfer_city(struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
Definition citytools.c:1072
citytools.h
auto_arrange_workers
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:365
city_refresh
bool city_refresh(struct city *pcity)
Definition cityturn.c:158
cityturn.h
incite_cost
char * incite_cost
Definition comments.c:74
console.h
conquer_city
static void conquer_city(QVariant data1, QVariant data2)
Definition dialogs.cpp:1854
enter_hut
static void enter_hut(QVariant data1, QVariant data2)
Definition dialogs.cpp:2665
frighten_hut
static void frighten_hut(QVariant data1, QVariant data2)
Definition dialogs.cpp:2695
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:74
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:74
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:212
Tech_type_id
int Tech_type_id
Definition fc_types.h:381
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
IDENTITY_NUMBER_ZERO
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:92
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:61
wld
struct world wld
Definition game.c:62
send_game_info
void send_game_info(struct conn_list *dest)
Definition gamehand.c:910
gamehand.h
owner
struct city * owner
Definition citydlg.c:226
type
GType type
Definition repodlgs.c:1313
is_special_improvement
bool is_special_improvement(const struct impr_type *pimprove)
Definition improvement.c:797
is_wonder
bool is_wonder(const struct impr_type *pimprove)
Definition improvement.c:343
is_great_wonder
bool is_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:772
name
const char * name
Definition inputfile.c:127
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
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:410
luascript_get_fcl
struct fc_lua * luascript_get_fcl(lua_State *L)
Definition luascript.c:367
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:59
same_pos
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:950
map.h
assign_continent_numbers
void assign_continent_numbers(void)
Definition mapgen_utils.c:452
mapgen_utils.h
really_gives_vision
bool really_gives_vision(struct player *me, struct player *them)
Definition maphand.c:345
send_tile_info
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:491
send_all_known_tiles
void send_all_known_tiles(struct conn_list *dest)
Definition maphand.c:444
need_to_reassign_continents
bool need_to_reassign_continents(const struct terrain *oldter, const struct terrain *newter)
Definition maphand.c:1942
climate_change
void climate_change(bool warming, int effect)
Definition maphand.c:133
create_extra
void create_extra(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition maphand.c:2561
map_show_tile
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:775
tile_change_side_effects
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2729
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:927
fix_tile_on_terrain_change
void fix_tile_on_terrain_change(struct tile *ptile, struct terrain *oldter, bool extend_rivers)
Definition maphand.c:1980
update_tile_knowledge
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1446
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:289
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:629
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:318
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:774
movement.h
MR_OK
@ MR_OK
Definition movement.h:35
nation_plural_for_player
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
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_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
player_status_add
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3219
civil_war_triggered
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2960
send_player_info_c
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
civil_war
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:3010
civil_war_possible
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2913
plrhand.h
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:56
research_advance_name_translation
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:273
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
research_pretty_name
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:169
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:354
server_state
enum server_states server_state(void)
Definition srv_main.c:338
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:811
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:995
stdinhand.h
action
Definition actions.h:106
advance
Definition tech.h:124
ai_trait::mod
int mod
Definition traits.h:39
city
Definition city.h:320
city::history
int history
Definition city.h:410
city::id
int id
Definition city.h:326
civ_game::multiresearch
bool multiresearch
Definition game.h:163
civ_game::diplbulbcost
int diplbulbcost
Definition game.h:139
civ_game::conquercost
int conquercost
Definition game.h:136
civ_game::freecost
int freecost
Definition game.h:148
civ_game::server
struct civ_game::@31::@35 server
civ_game::techpenalty
int techpenalty
Definition game.h:196
civ_map
Definition map_types.h:71
effect
Definition effects.h:40
extra_type
Definition extras.h:88
extra_type::id
int id
Definition extras.h:89
fc_lua
Definition luascript.h:44
impr_type
Definition improvement.h:50
nation_type
Definition nation.h:98
player_ai::traits
struct ai_trait * traits
Definition player.h:126
player_economic::infra_points
int infra_points
Definition player.h:67
player_economic::gold
int gold
Definition player.h:63
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:310
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:316
research
Definition research.h:39
terrain
Definition terrain.h:75
tile
Definition tile.h:50
unit_type
Definition unittype.h:507
unit
Definition unit.h:140
unit::moves_left
int moves_left
Definition unit.h:152
unit::id
int id
Definition unit.h:147
unit::stay
bool stay
Definition unit.h:208
unit::facing
enum direction8 facing
Definition unit.h:144
unit::homecity
int homecity
Definition unit.h:148
unit::veteran
int veteran
Definition unit.h:154
veteran_level
Definition unittype.h:493
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:186
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
A_UNKNOWN
#define A_UNKNOWN
Definition tech.h:49
found_new_tech
void found_new_tech(struct research *presearch, Tech_type_id tech_found, bool was_discovery, bool saving_bulbs)
Definition techtools.c:347
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:1387
send_research_info
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
script_tech_learned
void script_tech_learned(struct research *presearch, struct player *originating_plr, struct advance *tech, const char *reason)
Definition techtools.c:84
update_bulbs
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech, bool free_bulbs)
Definition techtools.c:654
techtools.h
terrain_has_flag
#define terrain_has_flag(terr, flag)
Definition terrain.h:176
tile_change_terrain
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:496
tile_extra_rm_apply
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:601
tile_set_label
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1097
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_index
#define tile_index(_pt_)
Definition tile.h:89
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:111
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:148
trade_partners_iterate_end
#define trade_partners_iterate_end
Definition traderoutes.h:167
trade_partners_iterate
#define trade_partners_iterate(c, p)
Definition traderoutes.h:162
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:1994
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1767
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2483
could_unit_be_in_transport
bool could_unit_be_in_transport(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:692
unit_tile
#define unit_tile(_pu)
Definition unit.h:397
unit_owner
#define unit_owner(_pu)
Definition unit.h:396
UU_OK
@ UU_OK
Definition unit.h:62
is_non_allied_unit_tile
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer, bool everyone_non_allied)
Definition unit.h:433
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:3337
unithand.h
place_partisans
void place_partisans(struct tile *pcenter, struct player *powner, int count, int sq_radius)
Definition unittools.c:1162
transform_unit
void transform_unit(struct unit *punit, const struct unit_type *to_unit, int vet_loss)
Definition unittools.c:1554
send_unit_info
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2878
place_unit
bool place_unit(struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
Definition unittools.c:1714
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:1666
wipe_unit
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2140
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:4075
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:2203
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:1927
can_upgrade_unittype
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1703
utype_veteran_levels
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2613
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
unit_type_array_last
const struct unit_type * unit_type_array_last(void)
Definition unittype.c:69
unittype.h
utype_has_flag
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624