Freeciv21
Develop your civilization from humble roots to a global empire
api_server_edit.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9  */
10 
11 // utility
12 #include "city.h"
13 #include "cityturn.h"
14 #include "fcintl.h"
15 #include "rand.h"
16 
17 // common
18 #include "movement.h"
19 #include "research.h"
20 #include "unittype.h"
21 /* common/scriptcore */
22 #include "api_game_find.h"
23 #include "luascript.h"
24 
25 // server
26 #include "aiiface.h"
27 #include "barbarian.h"
28 #include "citytools.h"
29 #include "console.h" // enum rfc_status
30 #include "maphand.h"
31 #include "notify.h"
32 #include "plrhand.h"
33 #include "srv_main.h" // game_was_started()
34 #include "stdinhand.h"
35 #include "techtools.h"
36 #include "unittools.h"
37 
38 /* server/generator */
39 #include "mapgen_utils.h"
40 
41 #include "api_server_edit.h"
42 
46 bool api_edit_unleash_barbarians(lua_State *L, Tile *ptile)
47 {
48  LUASCRIPT_CHECK_STATE(L, false);
49  LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, false);
50 
51  return unleash_barbarians(ptile);
52 }
53 
57 void api_edit_place_partisans(lua_State *L, Tile *ptile, Player *pplayer,
58  int count, int sq_radius)
59 {
61  LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
62  LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 3, Player);
63  LUASCRIPT_CHECK_ARG(L, 0 <= sq_radius, 5, "radius must be positive");
64  LUASCRIPT_CHECK(L, 0 < num_role_units(L_PARTISAN),
65  "no partisans in ruleset");
66 
67  return place_partisans(ptile, pplayer, count, sq_radius);
68 }
69 
73 Unit *api_edit_create_unit(lua_State *L, Player *pplayer, Tile *ptile,
74  Unit_Type *ptype, int veteran_level,
75  City *homecity, int moves_left)
76 {
77  return api_edit_create_unit_full(L, pplayer, ptile, ptype, veteran_level,
78  homecity, moves_left, -1, nullptr);
79 }
80 
84 Unit *api_edit_create_unit_full(lua_State *L, Player *pplayer, Tile *ptile,
85  Unit_Type *ptype, int veteran_level,
86  City *homecity, int moves_left, int hp_left,
87  Unit *ptransport)
88 {
89  struct fc_lua *fcl;
90  struct city *pcity;
91 
92  LUASCRIPT_CHECK_STATE(L, nullptr);
93  LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, nullptr);
94  LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, nullptr);
95 
97 
98  LUASCRIPT_CHECK(L, fcl != nullptr, "Undefined Freeciv21 lua state!",
99  nullptr);
100 
101  if (ptype == nullptr || ptype < unit_type_array_first()
102  || ptype > unit_type_array_last()) {
103  return nullptr;
104  }
105 
106  if (ptransport) {
107  // Extensive check to see if transport and unit are compatible
108  int ret;
109  struct unit *pvirt =
110  unit_virtual_create(pplayer, nullptr, ptype, veteran_level);
111  unit_tile_set(pvirt, ptile);
112  pvirt->homecity = homecity ? homecity->id : 0;
113  ret = can_unit_load(pvirt, ptransport);
114  unit_virtual_destroy(pvirt);
115  if (!ret) {
117  "create_unit_full: '%s' cannot transport "
118  "'%s' here",
119  utype_rule_name(unit_type_get(ptransport)),
120  utype_rule_name(ptype));
121  return nullptr;
122  }
123  } else if (!can_exist_at_tile(&(wld.map), ptype, ptile)) {
125  "create_unit_full: '%s' cannot exist at "
126  "tile",
127  utype_rule_name(ptype));
128  return nullptr;
129  }
130 
131  if (is_non_allied_unit_tile(ptile, pplayer)) {
133  "create_unit_full: tile is occupied by "
134  "enemy unit");
135  return nullptr;
136  }
137 
138  pcity = tile_city(ptile);
139  if (pcity != nullptr && !pplayers_allied(pplayer, city_owner(pcity))) {
141  "create_unit_full: tile is occupied by "
142  "enemy city");
143  return nullptr;
144  }
145 
146  return create_unit_full(pplayer, ptile, ptype, veteran_level,
147  homecity ? homecity->id : 0, moves_left, hp_left,
148  ptransport);
149 }
150 
154 bool api_edit_unit_teleport(lua_State *L, Unit *punit, Tile *dest)
155 {
156  bool alive;
157  struct city *pcity;
158 
159  LUASCRIPT_CHECK_STATE(L, false);
160  LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, false);
161  LUASCRIPT_CHECK_ARG_NIL(L, dest, 3, Tile, false);
162 
163  // Teleport first so destination is revealed even if unit dies
164  alive = unit_move(
165  punit, dest, 0,
166  /* Auto embark kept for backward compatibility. I have
167  * no objection if you see the old behavior as a bug and
168  * remove auto embarking completely or for transports
169  * the unit can't legally board. -- Sveinung */
170  nullptr, true,
171  /* Backwards compatibility for old scripts in rulesets
172  * and (scenario) savegames. I have no objection if you
173  * see the old behavior as a bug and remove auto
174  * conquering completely or for cities the unit can't
175  * legally conquer. -- Sveinung */
176  ((pcity = tile_city(dest))
177  && (unit_owner(punit)->ai_common.barbarian_type != ANIMAL_BARBARIAN)
178  && uclass_has_flag(unit_class_get(punit), UCF_CAN_OCCUPY_CITY)
179  && !unit_has_type_flag(punit, UTYF_CIVILIAN)
180  && pplayers_at_war(unit_owner(punit), city_owner(pcity))));
181  if (alive) {
182  struct player *owner = unit_owner(punit);
183 
184  if (!can_unit_exist_at_tile(&(wld.map), punit, dest)) {
185  wipe_unit(punit, ULR_NONNATIVE_TERR, nullptr);
186  return false;
187  }
188  if (is_non_allied_unit_tile(dest, owner)
189  || (pcity && !pplayers_allied(city_owner(pcity), owner))) {
190  wipe_unit(punit, ULR_STACK_CONFLICT, nullptr);
191  return false;
192  }
193  }
194 
195  return alive;
196 }
197 
201 void api_edit_unit_turn(lua_State *L, Unit *punit, Direction dir)
202 {
204  LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit);
205 
206  if (direction8_is_valid(dir)) {
207  punit->facing = dir;
208 
209  send_unit_info(nullptr, punit);
210  } else {
211  qCritical("Illegal direction %d for unit from lua script", dir);
212  }
213 }
214 
218 void api_edit_unit_kill(lua_State *L, Unit *punit, const char *reason,
219  Player *killer)
220 {
221  enum unit_loss_reason loss_reason;
222 
224  LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit);
225  LUASCRIPT_CHECK_ARG_NIL(L, reason, 3, string);
226 
227  loss_reason = unit_loss_reason_by_name(reason, fc_strcasecmp);
228 
229  LUASCRIPT_CHECK_ARG(L, unit_loss_reason_is_valid(loss_reason), 3,
230  "Invalid unit loss reason");
231 
232  wipe_unit(punit, loss_reason, killer);
233 }
234 
238 bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr)
239 {
240  struct terrain *old_terrain;
241 
242  LUASCRIPT_CHECK_STATE(L, false);
243  LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, false);
244  LUASCRIPT_CHECK_ARG_NIL(L, pterr, 3, Terrain, false);
245 
246  old_terrain = tile_terrain(ptile);
247 
248  if (old_terrain == pterr
249  || (terrain_has_flag(pterr, TER_NO_CITIES)
250  && tile_city(ptile) != nullptr)) {
251  return false;
252  }
253 
254  tile_change_terrain(ptile, pterr);
255  fix_tile_on_terrain_change(ptile, old_terrain, false);
256  if (need_to_reassign_continents(old_terrain, pterr)) {
258  send_all_known_tiles(nullptr);
259  }
260 
261  update_tile_knowledge(ptile);
262 
263  return true;
264 }
265 
269 void api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile,
270  const char *name)
271 {
273  LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player);
274  LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile);
275 
276  if (!name || name[0] == '\0') {
277  name = city_name_suggestion(pplayer, ptile);
278  }
279 
280  // TODO: Allow initial citizen to be of nationality other than owner
281  create_city(pplayer, ptile, name, pplayer);
282 }
283 
287 void api_edit_resize_city(lua_State *L, City *pcity, int size,
288  const char *reason)
289 {
291  LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City);
292 
293  LUASCRIPT_CHECK(L, size > 0 && size < MAX_CITY_SIZE, "Invalid city size");
294 
295  city_change_size(pcity, size, city_owner(pcity), reason);
296 }
297 
301 Player *api_edit_create_player(lua_State *L, const char *username,
302  Nation_Type *pnation, const char *ai)
303 {
304  struct player *pplayer = nullptr;
305  char buf[128] = "";
306  struct fc_lua *fcl;
307 
308  LUASCRIPT_CHECK_STATE(L, nullptr);
309  LUASCRIPT_CHECK_ARG_NIL(L, username, 2, string, nullptr);
310  if (!ai) {
311  ai = default_ai_type_name();
312  }
313 
314  fcl = luascript_get_fcl(L);
315 
316  LUASCRIPT_CHECK(L, fcl != nullptr, "Undefined Freeciv21 lua state!",
317  nullptr);
318 
319  if (game_was_started()) {
320  create_command_newcomer(username, ai, false, pnation, &pplayer, buf,
321  sizeof(buf));
322  } else {
323  create_command_pregame(username, ai, false, &pplayer, buf, sizeof(buf));
324  }
325 
326  if (strlen(buf) > 0) {
327  luascript_log(fcl, LOG_NORMAL, "%s", buf);
328  }
329 
330  return pplayer;
331 }
332 
336 void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
337 {
339  LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player);
340 
341  pplayer->economic.gold = MAX(0, pplayer->economic.gold + amount);
342 }
343 
350 Tech_Type *api_edit_give_technology(lua_State *L, Player *pplayer,
351  Tech_Type *ptech, int cost, bool notify,
352  const char *reason)
353 {
354  struct research *presearch;
355  Tech_type_id id;
356  Tech_Type *result;
357 
358  LUASCRIPT_CHECK_STATE(L, nullptr);
359  LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, nullptr);
360  LUASCRIPT_CHECK_ARG(L, cost >= -3, 4, "Unknown give_tech() cost value",
361  nullptr);
362 
363  presearch = research_get(pplayer);
364  if (ptech) {
365  id = advance_number(ptech);
366  } else {
367  id = pick_free_tech(presearch);
368  }
369 
370  if (is_future_tech(id)
371  || research_invention_state(presearch, id) != TECH_KNOWN) {
372  if (cost < 0) {
373  if (cost == -1) {
374  cost = game.server.freecost;
375  } else if (cost == -2) {
376  cost = game.server.conquercost;
377  } else if (cost == -3) {
378  cost = game.server.diplbulbcost;
379  }
380  }
381  research_apply_penalty(presearch, id, cost);
382  found_new_tech(presearch, id, false, true);
383  result = advance_by_number(id);
384  script_tech_learned(presearch, pplayer, result, reason);
385 
386  if (notify && result != nullptr) {
387  QString adv_name = research_advance_name_translation(presearch, id);
388  char research_name[MAX_LEN_NAME * 2];
389 
390  research_pretty_name(presearch, research_name, sizeof(research_name));
391 
392  notify_player(pplayer, nullptr, E_TECH_GAIN, ftc_server,
393  Q_("?fromscript:You acquire %s."),
394  qUtf8Printable(adv_name));
395  notify_research(presearch, pplayer, E_TECH_GAIN, ftc_server,
396  /* TRANS: "The Greeks ..." or "The members of
397  * team Red ..." */
398  Q_("?fromscript:The %s acquire %s and share this "
399  "advance with you."),
400  nation_plural_for_player(pplayer),
401  qUtf8Printable(adv_name));
402  notify_research_embassies(presearch, nullptr, E_TECH_EMBASSY,
403  ftc_server,
404  /* TRANS: "The Greeks ..." or "The members of
405  * team Red ..." */
406  Q_("?fromscript:The %s acquire %s."),
407  research_name, qUtf8Printable(adv_name));
408  }
409 
410  return result;
411  } else {
412  return nullptr;
413  }
414 }
415 
419 bool api_edit_trait_mod_set(lua_State *L, Player *pplayer, const char *tname,
420  const int mod)
421 {
422  enum trait tr;
423 
424  LUASCRIPT_CHECK_STATE(L, -1);
425  LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, false);
426  LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, false);
427 
428  tr = trait_by_name(tname, fc_strcasecmp);
429 
430  LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
431 
432  pplayer->ai_common.traits[tr].mod += mod;
433 
434  return true;
435 }
436 
440 void api_edit_create_owned_extra(lua_State *L, Tile *ptile, const char *name,
441  Player *pplayer)
442 {
443  struct extra_type *pextra;
444 
446  LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
447 
448  if (!name) {
449  return;
450  }
451 
452  pextra = extra_type_by_rule_name(name);
453 
454  if (pextra) {
455  create_extra(ptile, pextra, pplayer);
456  update_tile_knowledge(ptile);
457  }
458 }
459 
463 void api_edit_create_extra(lua_State *L, Tile *ptile, const char *name)
464 {
465  api_edit_create_owned_extra(L, ptile, name, nullptr);
466 }
467 
471 void api_edit_create_base(lua_State *L, Tile *ptile, const char *name,
472  Player *pplayer)
473 {
474  api_edit_create_owned_extra(L, ptile, name, pplayer);
475 }
476 
480 void api_edit_create_road(lua_State *L, Tile *ptile, const char *name)
481 {
482  api_edit_create_owned_extra(L, ptile, name, nullptr);
483 }
484 
488 void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name)
489 {
490  struct extra_type *pextra;
491 
493  LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile);
494 
495  if (!name) {
496  return;
497  }
498 
499  pextra = extra_type_by_rule_name(name);
500 
501  if (pextra != nullptr && tile_has_extra(ptile, pextra)) {
502  tile_extra_rm_apply(ptile, pextra);
503  update_tile_knowledge(ptile);
504  }
505 }
506 
510 void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label)
511 {
513  LUASCRIPT_CHECK_SELF(L, ptile);
514  LUASCRIPT_CHECK_ARG_NIL(L, label, 3, string);
515 
516  tile_set_label(ptile, label);
517  if (server_state() >= S_S_RUNNING) {
518  send_tile_info(nullptr, ptile, false);
519  }
520 }
521 
525 void api_edit_climate_change(lua_State *L, enum climate_change_type type,
526  int effect)
527 {
532  2, "invalid climate change type");
533  LUASCRIPT_CHECK_ARG(L, effect > 0, 3, "effect must be greater than zero");
534 
536 }
537 
541 Player *api_edit_civil_war(lua_State *L, Player *pplayer, int probability)
542 {
543  LUASCRIPT_CHECK_STATE(L, nullptr);
544  LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, nullptr);
545  LUASCRIPT_CHECK_ARG(L, probability >= 0 && probability <= 100, 3,
546  "must be a percentage", nullptr);
547 
548  if (!civil_war_possible(pplayer, false, false)) {
549  return nullptr;
550  }
551 
552  if (probability == 0) {
553  // Calculate chance with normal rules
554  if (!civil_war_triggered(pplayer)) {
555  return nullptr;
556  }
557  } else {
558  // Fixed chance specified by script
559  if (fc_rand(100) >= probability) {
560  return nullptr;
561  }
562  }
563 
564  return civil_war(pplayer);
565 }
566 
570 void api_edit_player_victory(lua_State *L, Player *pplayer)
571 {
573  LUASCRIPT_CHECK_SELF(L, pplayer);
574 
575  player_status_add(pplayer, PSTATUS_WINNER);
576 }
577 
581 bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile, int movecost)
582 {
583  struct city *pcity;
584 
585  LUASCRIPT_CHECK_STATE(L, false);
586  LUASCRIPT_CHECK_SELF(L, punit, false);
587  LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, false);
588  LUASCRIPT_CHECK_ARG(L, movecost >= 0, 4, "Negative move cost!", false);
589 
590  return unit_move(
591  punit, ptile, movecost,
592  /* Auto embark kept for backward compatibility. I have
593  * no objection if you see the old behavior as a bug and
594  * remove auto embarking completely or for transports
595  * the unit can't legally board. -- Sveinung */
596  nullptr, true,
597  /* Backwards compatibility for old scripts in rulesets
598  * and (scenario) savegames. I have no objection if you
599  * see the old behavior as a bug and remove auto
600  * conquering completely or for cities the unit can't
601  * legally conquer. -- Sveinung */
602  ((pcity = tile_city(ptile))
603  && (unit_owner(punit)->ai_common.barbarian_type != ANIMAL_BARBARIAN)
604  && uclass_has_flag(unit_class_get(punit), UCF_CAN_OCCUPY_CITY)
605  && !unit_has_type_flag(punit, UTYF_CIVILIAN)
606  && pplayers_at_war(unit_owner(punit), city_owner(pcity))));
607 }
608 
612 void api_edit_unit_moving_disallow(lua_State *L, Unit *punit)
613 {
615  LUASCRIPT_CHECK_SELF(L, punit);
616 
617  if (punit != nullptr) {
618  punit->stay = true;
619  }
620 }
621 
625 void api_edit_unit_moving_allow(lua_State *L, Unit *punit)
626 {
628  LUASCRIPT_CHECK_SELF(L, punit);
629 
630  if (punit != nullptr) {
631  punit->stay = false;
632  }
633 }
634 
638 void api_edit_city_add_history(lua_State *L, City *pcity, int amount)
639 {
641  LUASCRIPT_CHECK_SELF(L, pcity);
642 
643  pcity->history += amount;
644 }
645 
649 void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount)
650 {
652  LUASCRIPT_CHECK_SELF(L, pplayer);
653 
654  pplayer->history += amount;
655 }
const char * default_ai_type_name()
Return name of default ai type.
Definition: aiiface.cpp:265
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)
Create a new unit.
void api_edit_climate_change(lua_State *L, enum climate_change_type type, int effect)
Global climate change.
Player * api_edit_create_player(lua_State *L, const char *username, Nation_Type *pnation, const char *ai)
Create a new player.
void api_edit_resize_city(lua_State *L, City *pcity, int size, const char *reason)
Resizes a city.
void api_edit_unit_moving_allow(lua_State *L, Unit *punit)
Allow unit to move.
bool api_edit_trait_mod_set(lua_State *L, Player *pplayer, const char *tname, const int mod)
Modify player's trait value.
bool api_edit_unleash_barbarians(lua_State *L, Tile *ptile)
Unleash barbarians on a tile, for example from a hut.
Player * api_edit_civil_war(lua_State *L, Player *pplayer, int probability)
Provoke a civil war.
void api_edit_player_victory(lua_State *L, Player *pplayer)
Make player winner of the scenario.
void api_edit_create_extra(lua_State *L, Tile *ptile, const char *name)
Create a new extra.
void api_edit_player_add_history(lua_State *L, Player *pplayer, int amount)
Add history to a player.
bool api_edit_unit_teleport(lua_State *L, Unit *punit, Tile *dest)
Teleport unit to destination tile.
bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr)
Change terrain on tile.
void api_edit_create_owned_extra(lua_State *L, Tile *ptile, const char *name, Player *pplayer)
Create a new owned extra.
Unit * api_edit_create_unit(lua_State *L, Player *pplayer, Tile *ptile, Unit_Type *ptype, int veteran_level, City *homecity, int moves_left)
Create a new unit.
void api_edit_unit_kill(lua_State *L, Unit *punit, const char *reason, Player *killer)
Kill the unit.
void api_edit_unit_turn(lua_State *L, Unit *punit, Direction dir)
Change unit orientation.
void api_edit_place_partisans(lua_State *L, Tile *ptile, Player *pplayer, int count, int sq_radius)
Place partisans for a player around a tile (normally around a city).
void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name)
Remove extra from tile, if present.
void api_edit_tile_set_label(lua_State *L, Tile *ptile, const char *label)
Set tile label text.
void api_edit_create_road(lua_State *L, Tile *ptile, const char *name)
Add a new road.
Tech_Type * api_edit_give_technology(lua_State *L, Player *pplayer, Tech_Type *ptech, int cost, bool notify, const char *reason)
Give pplayer technology ptech.
void api_edit_city_add_history(lua_State *L, City *pcity, int amount)
Add history to a city.
bool api_edit_unit_move(lua_State *L, Unit *punit, Tile *ptile, int movecost)
Move a unit.
void api_edit_unit_moving_disallow(lua_State *L, Unit *punit)
Prohibit unit from moving.
void api_edit_create_city(lua_State *L, Player *pplayer, Tile *ptile, const char *name)
Create a new city.
void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
Change pplayer's gold by amount.
void api_edit_create_base(lua_State *L, Tile *ptile, const char *name, Player *pplayer)
Create a new base.
climate_change_type
@ CLIMATE_CHANGE_GLOBAL_WARMING
@ CLIMATE_CHANGE_NUCLEAR_WINTER
bool unleash_barbarians(struct tile *ptile)
Unleash barbarians means give barbarian player some units and move them out of the hut,...
Definition: barbarian.cpp:248
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
#define MAX_CITY_SIZE
Definition: city.h:79
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Come up with a default name when a new city is about to be built.
Definition: citytools.cpp:451
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Creates real city.
Definition: citytools.cpp:1512
bool city_change_size(struct city *pcity, citizens size, struct player *nationality, const char *reason)
Change the city size.
Definition: cityturn.cpp:1067
struct extra_type * extra_type_by_rule_name(const char *name)
Returns extra type matching rule name or nullptr if there is no extra type with such name.
Definition: extras.cpp:183
int Tech_type_id
Definition: fc_types.h:294
#define MAX_LEN_NAME
Definition: fc_types.h:61
#define Q_(String)
Definition: fcintl.h:53
const struct ft_color ftc_server
struct civ_game game
Definition: game.cpp:47
struct world wld
Definition: game.cpp:48
const char * name
Definition: inputfile.cpp:118
constexpr auto LOG_ERROR
Definition: log.h:23
constexpr auto LOG_NORMAL
Definition: log.h:25
void luascript_log(struct fc_lua *fcl, QtMsgType level, const char *format,...)
Print a message to the selected output handle.
Definition: luascript.cpp:428
struct fc_lua * luascript_get_fcl(lua_State *L)
Get the freeciv lua struct from a lua state.
Definition: luascript.cpp:315
#define LUASCRIPT_CHECK_STATE(L,...)
Definition: luascript.h:110
#define LUASCRIPT_CHECK_SELF(L, value,...)
Definition: luascript.h:139
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition: luascript.h:131
#define LUASCRIPT_CHECK_ARG(L, check, narg, msg,...)
Definition: luascript.h:124
#define LUASCRIPT_CHECK(L, check, msg,...)
Definition: luascript.h:117
enum direction8 Direction
void assign_continent_numbers()
Assigns continent and ocean numbers to all tiles, and set map.num_continents and map....
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Send tile information to all the clients in dest which know and see the tile.
Definition: maphand.cpp:485
void send_all_known_tiles(struct conn_list *dest)
Send all tiles known to specified clients.
Definition: maphand.cpp:436
bool need_to_reassign_continents(const struct terrain *oldter, const struct terrain *newter)
Returns TRUE if the terrain change from 'oldter' to 'newter' may require expensive reassignment of co...
Definition: maphand.cpp:1819
void climate_change(bool warming, int effect)
Do a climate change.
Definition: maphand.cpp:123
void create_extra(struct tile *ptile, const extra_type *pextra, struct player *pplayer)
Create extra to tile.
Definition: maphand.cpp:2405
void fix_tile_on_terrain_change(struct tile *ptile, struct terrain *oldter, bool extend_rivers)
Handles local side effects for a terrain change (tile and its surroundings).
Definition: maphand.cpp:1856
void update_tile_knowledge(struct tile *ptile)
Update playermap knowledge for everybody who sees the tile, and send a packet to everyone whose info ...
Definition: maphand.cpp:1395
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Return TRUE iff a unit of the given unit type can "exist" at this location.
Definition: movement.cpp:236
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Return TRUE iff the unit can "exist" at this location.
Definition: movement.cpp:267
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
Definition: nation.cpp:155
void notify_research(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Sends a message to all players that share research.
Definition: notify.cpp:386
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Similar to notify_conn_packet (see also), but takes player as "destination".
Definition: notify.cpp:284
void notify_research_embassies(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Sends a message to all players that have embassies with someone who shares research.
Definition: notify.cpp:426
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players can attack each other.
Definition: player.cpp:1317
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
Definition: player.cpp:1334
void player_status_add(struct player *plr, enum player_status pstatus)
Add a status flag to a player.
Definition: plrhand.cpp:3145
struct player * civil_war(struct player *pplayer)
Capturing a nation's primary capital is a devastating blow.
Definition: plrhand.cpp:2942
bool civil_war_triggered(struct player *pplayer)
civil_war_triggered: The capture of a primary capital is not a sure fire way to throw and empire into...
Definition: plrhand.cpp:2890
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Check if civil war is possible for a player.
Definition: plrhand.cpp:2843
#define fc_rand(_size)
Definition: rand.h:16
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
Definition: research.cpp:110
QString research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Store the translated name of the given tech (including A_FUTURE) in 'buf'.
Definition: research.cpp:257
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
Definition: research.cpp:609
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Set in 'buf' the name of the research owner.
Definition: research.cpp:163
static void static sol::state * fcl
Lua virtual machine state.
Definition: script_fcdb.cpp:48
#define MAX(x, y)
Definition: shared.h:48
size_t size
Definition: specvec.h:64
bool game_was_started()
Returns iff the game was started once upon a time.
Definition: srv_main.cpp:251
enum server_states server_state()
Return current server state.
Definition: srv_main.cpp:238
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)
Try to add a player to a running game in the following order:
Definition: stdinhand.cpp:780
enum rfc_status create_command_pregame(const char *name, const char *ai, bool check, struct player **newplayer, char *buf, size_t buflen)
Create player in pregame.
Definition: stdinhand.cpp:946
Definition: tech.h:113
Definition: city.h:291
int history
Definition: city.h:379
struct civ_game::@28::@32 server
std::vector< ai_trait > traits
Definition: player.h:119
Definition: player.h:231
struct player_ai ai_common
Definition: player.h:270
struct player_economic economic
Definition: player.h:266
int history
Definition: player.h:300
Definition: tile.h:42
Definition: unit.h:134
int moves_left
Definition: unit.h:147
bool stay
Definition: unit.h:202
enum direction8 facing
Definition: unit.h:138
int homecity
Definition: unit.h:142
struct civ_map map
Definition: world_object.h:21
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89
bool is_future_tech(Tech_type_id tech)
Is the given tech a future tech.
Definition: tech.cpp:268
struct advance * advance_by_number(const Tech_type_id atype)
Return the advance for the given advance index.
Definition: tech.cpp:94
Tech_type_id advance_number(const struct advance *padvance)
Return the advance index.
Definition: tech.cpp:85
void found_new_tech(struct research *presearch, Tech_type_id tech_found, bool was_discovery, bool saving_bulbs)
Players sharing the research have got a new technology (from somewhere).
Definition: techtools.cpp:341
void research_apply_penalty(struct research *presearch, Tech_type_id tech, int penalty_percent)
Apply a penalty to the research.
Definition: techtools.cpp:59
Tech_type_id pick_free_tech(struct research *presearch)
Choose a free tech.
Definition: techtools.cpp:1380
void script_tech_learned(struct research *presearch, struct player *originating_plr, struct advance *tech, const char *reason)
Emit script signal(s) for player/team learning new tech.
Definition: techtools.cpp:77
#define terrain_has_flag(terr, flag)
Definition: terrain.h:260
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Change the terrain to the given type.
Definition: tile.cpp:491
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Remove extra and adjust other extras accordingly.
Definition: tile.cpp:605
bool tile_set_label(struct tile *ptile, const char *label)
Sets label for tile.
Definition: tile.cpp:1104
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
Definition: tile.cpp:72
#define tile_terrain(_tile)
Definition: tile.h:93
#define tile_has_extra(ptile, pextra)
Definition: tile.h:130
bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit can be loaded into the transporter.
Definition: unit.cpp:693
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
Definition: unit.cpp:1252
void unit_virtual_destroy(struct unit *punit)
Free the memory used by virtual unit.
Definition: unit.cpp:1588
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Create a virtual unit skeleton.
Definition: unit.cpp:1490
void unit_tile_set(struct unit *punit, struct tile *ptile)
Set the tile location of the unit.
Definition: unit.cpp:1200
#define unit_owner(_pu)
Definition: unit.h:370
bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost, struct unit *embark_to, bool find_embark_target, bool conquer_city_allowed)
Moves a unit.
Definition: unittools.cpp:3878
void place_partisans(struct tile *pcenter, struct player *powner, int count, int sq_radius)
Place partisans for powner around pcenter (normally around a city).
Definition: unittools.cpp:1180
void send_unit_info(struct conn_list *dest, struct unit *punit)
Send the unit to the players who need the info.
Definition: unittools.cpp:2808
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Remove the unit, and passengers if it is a carrying any.
Definition: unittools.cpp:2248
struct unit * create_unit_full(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left, int hp_left, struct unit *ptrans)
Creates a unit, and set it's initial values, and put it into the right lists.
Definition: unittools.cpp:1789
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114
struct unit_type * unit_type_array_first()
Return the first item of unit_types.
Definition: unittype.cpp:52
const struct unit_type * unit_type_array_last()
Return the last item of unit_types.
Definition: unittype.cpp:63
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
Definition: unittype.cpp:1274
int num_role_units(int role)
How many unit types have specified role/flag.
Definition: unittype.cpp:1866
struct unit_class * unit_class_get(const struct unit *punit)
Returns unit class pointer for a unit.
Definition: unittype.cpp:2151
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
Definition: unittype.cpp:176
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition: unittype.h:704