Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/scriptcore/api_game_methods.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
api_game_methods.c
Go to the documentation of this file.
1/*****************************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12*****************************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "deprecations.h"
20
21/* common */
22#include "achievements.h"
23#include "actions.h"
24#include "calendar.h"
25#include "citizens.h"
26#include "culture.h"
27#include "featured_text.h"
28#include "game.h"
29#include "government.h"
30#include "improvement.h"
31#include "map.h"
32#include "movement.h"
33#include "nation.h"
34#include "research.h"
35#include "tech.h"
36#include "terrain.h"
37#include "tile.h"
38#include "unitlist.h"
39#include "unittype.h"
40
41/* common/scriptcore */
42#include "luascript.h"
43
44#include "api_game_methods.h"
45
46
47/**********************************************************************/
50 int api_methods_game_turn(lua_State *L)
51{
52 LUASCRIPT_CHECK_STATE(L, 0);
53
54 return game.info.turn;
55}
56
57/**********************************************************************/
60 int api_methods_game_year(lua_State *L)
61{
62 LUASCRIPT_CHECK_STATE(L, 0);
63
64 return game.info.year;
65}
66
67/**********************************************************************/
70 int api_methods_game_year_fragment(lua_State *L)
71{
72 LUASCRIPT_CHECK_STATE(L, 0);
73
74 return game.info.fragment_count;
75}
76
77/**********************************************************************/
80 const char *api_methods_game_year_text(lua_State *L)
81{
82 LUASCRIPT_CHECK_STATE(L, NULL);
83
84 return calendar_text();
85}
86
87/**********************************************************************/
90 int api_methods_game_turn_deprecated(lua_State *L)
91{
92 LUASCRIPT_CHECK_STATE(L, 0);
93
94 log_deprecation("Deprecated: lua construct \"game:turn\", deprecated since \"3.0\", used. "
95 "Use \"game:current_turn\" instead.");
96
97 if (game.info.turn > 0) {
98 return game.info.turn - 1;
99 }
100
101 return game.info.turn;
102}
103
104/**********************************************************************/
107 const char *api_methods_game_rulesetdir(lua_State *L)
108{
109 return game.server.rulesetdir;
110}
111
112/**********************************************************************/
115 const char *api_methods_game_ruleset_name(lua_State *L)
116{
117 return game.control.name;
118}
119
120/**********************************************************************/
123 bool api_methods_building_type_is_wonder(lua_State *L,
124 Building_Type *pbuilding)
125{
126 LUASCRIPT_CHECK_STATE(L, FALSE);
127 LUASCRIPT_CHECK_SELF(L, pbuilding, FALSE);
128
129 return is_wonder(pbuilding);
130}
131
132/**********************************************************************/
135 bool api_methods_building_type_is_great_wonder(lua_State *L,
136 Building_Type *pbuilding)
137{
138 LUASCRIPT_CHECK_STATE(L, FALSE);
139 LUASCRIPT_CHECK_SELF(L, pbuilding, FALSE);
140
141 return is_great_wonder(pbuilding);
142}
143
144/**********************************************************************/
147 bool api_methods_building_type_is_small_wonder(lua_State *L,
148 Building_Type *pbuilding)
149{
150 LUASCRIPT_CHECK_STATE(L, FALSE);
151 LUASCRIPT_CHECK_SELF(L, pbuilding, FALSE);
152
153 return is_small_wonder(pbuilding);
154}
155
156/**********************************************************************/
159 bool api_methods_building_type_is_improvement(lua_State *L,
160 Building_Type *pbuilding)
161{
162 LUASCRIPT_CHECK_STATE(L, FALSE);
163 LUASCRIPT_CHECK_SELF(L, pbuilding, FALSE);
164
165 return is_improvement(pbuilding);
166}
167
168/**********************************************************************/
171 const char *api_methods_building_type_rule_name(lua_State *L,
172 Building_Type *pbuilding)
173{
174 LUASCRIPT_CHECK_STATE(L, NULL);
175 LUASCRIPT_CHECK_SELF(L, pbuilding, NULL);
176
177 return improvement_rule_name(pbuilding);
178}
179
180/**********************************************************************/
183const char
184 *api_methods_building_type_name_translation(lua_State *L,
185 Building_Type *pbuilding)
186{
187 LUASCRIPT_CHECK_STATE(L, NULL);
188 LUASCRIPT_CHECK_SELF(L, pbuilding, NULL);
189
190 return improvement_name_translation(pbuilding);
191}
192
193/**********************************************************************/
196 bool api_methods_city_has_building(lua_State *L, City *pcity,
197 Building_Type *building)
198{
199 LUASCRIPT_CHECK_STATE(L, FALSE);
200 LUASCRIPT_CHECK_SELF(L, pcity, FALSE);
201 LUASCRIPT_CHECK_ARG_NIL(L, building, 3, Building_Type, FALSE);
202
203 return city_has_building(pcity, building);
204}
205
206/**********************************************************************/
209 int api_methods_city_map_sq_radius(lua_State *L, City *pcity)
210{
211 LUASCRIPT_CHECK_STATE(L, 0);
212 LUASCRIPT_CHECK_SELF(L, pcity, 0);
213
214 return city_map_radius_sq_get(pcity);
215}
216
217/**********************************************************************/
220 int api_methods_city_size_get(lua_State *L, City *pcity)
221{
222 LUASCRIPT_CHECK_STATE(L, 1);
223 LUASCRIPT_CHECK_SELF(L, pcity, 1);
224
225 return city_size_get(pcity);
226}
227
228/**********************************************************************/
231 Tile *api_methods_city_tile_get(lua_State *L, City *pcity)
232{
233 LUASCRIPT_CHECK_STATE(L, NULL);
234 LUASCRIPT_CHECK_SELF(L, pcity, NULL);
235
236 return pcity->tile;
237}
238
239/**********************************************************************/
242 int api_methods_city_inspire_partisans(lua_State *L, City *self,
243 Player *inspirer)
244{
245 bool inspired = FALSE;
246
247 if (!game.info.citizen_nationality) {
248 if (self->original == inspirer) {
249 inspired = TRUE;
250 }
251 } else {
252 if (game.info.citizen_partisans_pct > 0) {
253 if (is_server()) {
254 citizens own = citizens_nation_get(self, inspirer->slot);
255 citizens total = city_size_get(self);
256
257 if (total > 0 && (own * 100 / total) >= game.info.citizen_partisans_pct) {
258 inspired = TRUE;
259 }
260 }
261 /* else is_client() -> don't consider inspired by default. */
262 } else if (self->original == inspirer) {
263 inspired = TRUE;
264 }
265 }
266
267 if (inspired) {
268 /* Cannot use get_city_bonus() as it would use city's current owner
269 * instead of inspirer. */
270 return get_target_bonus_effects(NULL,
271 &(const struct req_context) {
272 .player = inspirer,
273 .city = self,
274 .tile = city_tile(self),
275 },
276 NULL, EFT_INSPIRE_PARTISANS);
277 }
278
279 return 0;
280}
281
282/**********************************************************************/
285 int api_methods_city_culture_get(lua_State *L, City *pcity)
286{
287 LUASCRIPT_CHECK_STATE(L, 0);
288 LUASCRIPT_CHECK_SELF(L, pcity, 0);
289
290 return city_culture(pcity);
291}
292
293/**********************************************************************/
296 bool api_methods_is_city_happy(lua_State *L, City *pcity)
297{
298 LUASCRIPT_CHECK_STATE(L, FALSE);
299 LUASCRIPT_CHECK_SELF(L, pcity, FALSE);
300
301 /* Note: if clients ever have virtual cities or sth, needs amending */
302 return is_server() ? city_happy(pcity) : pcity->client.happy;
303}
304
305/**********************************************************************/
308 bool api_methods_is_city_unhappy(lua_State *L, City *pcity)
309{
310 LUASCRIPT_CHECK_STATE(L, FALSE);
311 LUASCRIPT_CHECK_SELF(L, pcity, FALSE);
312
313 /* Note: if clients ever have virtual cities or sth, needs amending */
314 return is_server() ? city_unhappy(pcity) : pcity->client.unhappy;
315}
316
317/**********************************************************************/
320 bool api_methods_is_city_celebrating(lua_State *L, City *pcity)
321{
322 LUASCRIPT_CHECK_STATE(L, FALSE);
323 LUASCRIPT_CHECK_SELF(L, pcity, FALSE);
324
325 return city_celebrating(pcity);
326}
327
328/**********************************************************************/
331 bool api_methods_is_gov_center(lua_State *L, City *pcity)
332{
333 LUASCRIPT_CHECK_STATE(L, FALSE);
334 LUASCRIPT_CHECK_SELF(L, pcity, FALSE);
335
336 return is_gov_center(pcity);
337}
338
339/**********************************************************************/
342 bool api_methods_is_capital(lua_State *L, City *pcity)
343{
344 LUASCRIPT_CHECK_STATE(L, FALSE);
345 LUASCRIPT_CHECK_SELF(L, pcity, FALSE);
346
347 return is_capital(pcity);
348}
349
350/**********************************************************************/
353 bool api_methods_is_primary_capital(lua_State *L, City *pcity)
354{
355 LUASCRIPT_CHECK_STATE(L, FALSE);
356 LUASCRIPT_CHECK_SELF(L, pcity, FALSE);
357
358 return pcity->capital == CAPITAL_PRIMARY;
359}
360
361/**********************************************************************/
364 const char *api_methods_government_rule_name(lua_State *L,
365 Government *pgovernment)
366{
367 LUASCRIPT_CHECK_STATE(L, NULL);
368 LUASCRIPT_CHECK_SELF(L, pgovernment, NULL);
369
370 return government_rule_name(pgovernment);
371}
372
373/**********************************************************************/
376 const char *api_methods_government_name_translation(lua_State *L,
377 Government *pgovernment)
378{
379 LUASCRIPT_CHECK_STATE(L, NULL);
380 LUASCRIPT_CHECK_SELF(L, pgovernment, NULL);
381
382 return government_name_translation(pgovernment);
383}
384
385/**********************************************************************/
388 const char *api_methods_nation_type_rule_name(lua_State *L,
389 Nation_Type *pnation)
390{
391 LUASCRIPT_CHECK_STATE(L, NULL);
392 LUASCRIPT_CHECK_SELF(L, pnation, NULL);
393
394 return nation_rule_name(pnation);
395}
396
397/**********************************************************************/
400 const char *api_methods_nation_type_name_translation(lua_State *L,
401 Nation_Type *pnation)
402{
403 LUASCRIPT_CHECK_STATE(L, NULL);
404 LUASCRIPT_CHECK_SELF(L, pnation, NULL);
405
406 return nation_adjective_translation(pnation);
407}
408
409/**********************************************************************/
412 const char *api_methods_nation_type_plural_translation(lua_State *L,
413 Nation_Type *pnation)
414{
415 LUASCRIPT_CHECK_STATE(L, NULL);
416 LUASCRIPT_CHECK_SELF(L, pnation, NULL);
417
418 return nation_plural_translation(pnation);
419}
420
421/**********************************************************************/
424 const char *api_methods_player_controlling_gui(lua_State *L,
425 Player *pplayer)
426{
427 struct connection *conn = NULL;
428
429 LUASCRIPT_CHECK_STATE(L, NULL);
430 LUASCRIPT_CHECK_SELF(L, pplayer, NULL);
431
432 conn_list_iterate(pplayer->connections, pconn) {
433 if (!pconn->observer) {
434 conn = pconn;
435 break;
436 }
437 } conn_list_iterate_end;
438
439 if (conn == NULL) {
440 return "None";
441 }
442
443 return gui_type_name(conn->client_gui);
444}
445
446/**********************************************************************/
449 bool api_methods_player_has_wonder(lua_State *L, Player *pplayer,
450 Building_Type *building)
451{
452 LUASCRIPT_CHECK_STATE(L, FALSE);
453 LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
454 LUASCRIPT_CHECK_ARG_NIL(L, building, 3, Building_Type, FALSE);
455
456 return wonder_is_built(pplayer, building);
457}
458
459/**********************************************************************/
462 int api_methods_player_number(lua_State *L, Player *pplayer)
463{
464 LUASCRIPT_CHECK_STATE(L, -1);
465 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
466
467 return player_number(pplayer);
468}
469
470/**********************************************************************/
473 int api_methods_player_num_cities(lua_State *L, Player *pplayer)
474{
475 LUASCRIPT_CHECK_STATE(L, 0);
476 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
477
478 return city_list_size(pplayer->cities);
479}
480
481/**********************************************************************/
484 int api_methods_player_num_units(lua_State *L, Player *pplayer)
485{
486 LUASCRIPT_CHECK_STATE(L, 0);
487 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
488
489 return unit_list_size(pplayer->units);
490}
491
492/**********************************************************************/
495 int api_methods_player_gold(lua_State *L, Player *pplayer)
496{
497 LUASCRIPT_CHECK_STATE(L, 0);
498 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
499
500 return pplayer->economic.gold;
501}
502
503/**********************************************************************/
506 bool api_methods_player_knows_tech(lua_State *L, Player *pplayer,
507 Tech_Type *ptech)
508{
509 LUASCRIPT_CHECK_STATE(L, FALSE);
510 LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
511 LUASCRIPT_CHECK_ARG_NIL(L, ptech, 3, Tech_Type, FALSE);
512
513 return research_invention_state(research_get(pplayer),
514 advance_number(ptech)) == TECH_KNOWN;
515}
516
517/**********************************************************************/
520 int api_methods_player_culture_get(lua_State *L, Player *pplayer)
521{
522 LUASCRIPT_CHECK_STATE(L, 0);
523 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
524
525 return player_culture(pplayer);
526}
527
528/**********************************************************************/
531 bool api_methods_player_has_flag(lua_State *L, Player *pplayer,
532 const char *flag)
533{
534 enum plr_flag_id flag_val;
535
536 LUASCRIPT_CHECK_STATE(L, 0);
537 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
538
539 flag_val = plr_flag_id_by_name(flag, fc_strcasecmp);
540
541 if (plr_flag_id_is_valid(flag_val)) {
542 return player_has_flag(pplayer, flag_val);
543 }
544
545 return FALSE;
546}
547
548/**********************************************************************/
552 Unit_Type *api_methods_player_can_upgrade(lua_State *L, Player *pplayer,
553 Unit_Type *utype)
554{
555 LUASCRIPT_CHECK_STATE(L, NULL);
556 LUASCRIPT_CHECK_SELF(L, pplayer, NULL);
557 LUASCRIPT_CHECK_ARG_NIL(L, utype, 3, Unit_Type, NULL);
558
559 return (Unit_Type *)can_upgrade_unittype(pplayer, utype);
560}
561
562/**********************************************************************/
566 bool api_methods_player_can_build_unit_direct(lua_State *L, Player *pplayer,
567 Unit_Type *utype)
568{
569 LUASCRIPT_CHECK_STATE(L, FALSE);
570 LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
571 LUASCRIPT_CHECK_ARG_NIL(L, utype, 3, Unit_Type, FALSE);
572
573 return can_player_build_unit_direct(pplayer, utype);
574}
575
576/**********************************************************************/
579 bool api_methods_player_can_build_impr_direct(lua_State *L, Player *pplayer,
580 Building_Type *itype)
581{
582 LUASCRIPT_CHECK_STATE(L, FALSE);
583 LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
584 LUASCRIPT_CHECK_ARG_NIL(L, itype, 3, Building_Type, FALSE);
585
586 return can_player_build_improvement_direct(pplayer, itype);
587}
588
589
590/**********************************************************************/
594 bool api_methods_unit_can_upgrade(lua_State *L, Unit *punit, bool is_free)
595{
596
597 return UU_OK == unit_upgrade_test(&(wld.map), punit, is_free);
598}
599
600/**********************************************************************/
604 const char *api_methods_unit_transform_problem(lua_State *L, Unit *punit,
605 Unit_Type *ptype)
606{
607 enum unit_upgrade_result uu;
608
609 LUASCRIPT_CHECK_STATE(L, NULL);
610 LUASCRIPT_CHECK_SELF(L, punit, NULL);
611 LUASCRIPT_CHECK_ARG_NIL(L, ptype, 3, Unit_Type, NULL);
612
613 uu = unit_transform_result(&(wld.map), punit, ptype);
614 switch (uu) {
615 case UU_OK:
616 return NULL;
617 case UU_NOT_ENOUGH_ROOM:
618 return "cargo";
619 case UU_UNSUITABLE_TRANSPORT:
620 return "transport";
621 case UU_NOT_TERRAIN:
622 return "terrain";
623 case UU_NOT_ACTIVITY:
624 return "activity";
625 case UU_NO_UNITTYPE:
626 case UU_NO_MONEY:
627 case UU_NOT_IN_CITY:
628 case UU_NOT_CITY_OWNER:
629 /* should not get here */
630 break;
631 }
632
633 fc_assert_msg(FALSE, "Unexpected unit transform result %i", uu);
634
635 return "\?";
636}
637
638/**********************************************************************/
641 bool api_methods_player_shares_research(lua_State *L, Player *pplayer,
642 Player *aplayer)
643{
644 LUASCRIPT_CHECK_STATE(L, FALSE);
645 LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
646 LUASCRIPT_CHECK_ARG_NIL(L, aplayer, 3, Player, FALSE);
647
648 return research_get(pplayer) == research_get(aplayer);
649}
650
651/**********************************************************************/
654 const char *api_methods_research_rule_name(lua_State *L, Player *pplayer)
655{
656 LUASCRIPT_CHECK_STATE(L, NULL);
657 LUASCRIPT_CHECK_SELF(L, pplayer, NULL);
658
659 return research_rule_name(research_get(pplayer));
660}
661
662/**********************************************************************/
665 const char *api_methods_research_name_translation(lua_State *L,
666 Player *pplayer)
667{
668 static char buf[MAX_LEN_MSG];
669
670 LUASCRIPT_CHECK_STATE(L, NULL);
671 LUASCRIPT_CHECK_SELF(L, pplayer, NULL);
672
673 (void) research_pretty_name(research_get(pplayer), buf, ARRAY_SIZE(buf));
674
675 return buf;
676}
677
678/**********************************************************************/
682lua_Object api_methods_private_list_players(lua_State *L)
683{
684 lua_Object result = 0;
685 int i = 0;
686
687 LUASCRIPT_CHECK_STATE(L, 0);
688 lua_createtable(L, player_count(), 0);
689 result = lua_gettop(L);
690 players_iterate(pplayer) {
691 tolua_pushfieldusertype(L, result, ++i, pplayer, "Player");
692 } players_iterate_end;
693 return result;
694}
695
696/**********************************************************************/
699 Unit_List_Link *api_methods_private_player_unit_list_head(lua_State *L,
700 Player *pplayer)
701{
702 LUASCRIPT_CHECK_STATE(L, NULL);
703 LUASCRIPT_CHECK_SELF(L, pplayer, NULL);
704 return unit_list_head(pplayer->units);
705}
706
707/**********************************************************************/
710 City_List_Link *api_methods_private_player_city_list_head(lua_State *L,
711 Player *pplayer)
712{
713 LUASCRIPT_CHECK_STATE(L, NULL);
714 LUASCRIPT_CHECK_SELF(L, pplayer, NULL);
715
716 return city_list_head(pplayer->cities);
717}
718
719/**********************************************************************/
722 const char *api_methods_tech_type_rule_name(lua_State *L, Tech_Type *ptech)
723{
724 LUASCRIPT_CHECK_STATE(L, NULL);
725 LUASCRIPT_CHECK_SELF(L, ptech, NULL);
726
727 return advance_rule_name(ptech);
728}
729
730/**********************************************************************/
733 const char *api_methods_tech_type_name_translation(lua_State *L,
734 Tech_Type *ptech)
735{
736 LUASCRIPT_CHECK_STATE(L, NULL);
737 LUASCRIPT_CHECK_SELF(L, ptech, NULL);
738
739 return advance_name_translation(ptech);
740}
741
742/**********************************************************************/
745 const char *api_methods_terrain_rule_name(lua_State *L, Terrain *pterrain)
746{
747 LUASCRIPT_CHECK_STATE(L, NULL);
748 LUASCRIPT_CHECK_SELF(L, pterrain, NULL);
749
750 return terrain_rule_name(pterrain);
751}
752
753/**********************************************************************/
756 const char *api_methods_terrain_name_translation(lua_State *L,
757 Terrain *pterrain)
758{
759 LUASCRIPT_CHECK_STATE(L, NULL);
760 LUASCRIPT_CHECK_SELF(L, pterrain, NULL);
761
762 return terrain_name_translation(pterrain);
763}
764
765/**********************************************************************/
768 const char *api_methods_terrain_class_name(lua_State *L, Terrain *pterrain)
769{
770 LUASCRIPT_CHECK_STATE(L, NULL);
771 LUASCRIPT_CHECK_SELF(L, pterrain, NULL);
772
773 return terrain_class_name(terrain_type_terrain_class(pterrain));
774}
775
776/**********************************************************************/
779 const char *api_methods_disaster_rule_name(lua_State *L, Disaster *pdis)
780{
781 LUASCRIPT_CHECK_STATE(L, NULL);
782 LUASCRIPT_CHECK_SELF(L, pdis, NULL);
783
784 return disaster_rule_name(pdis);
785}
786
787/**********************************************************************/
790 const char *api_methods_disaster_name_translation(lua_State *L,
791 Disaster *pdis)
792{
793 LUASCRIPT_CHECK_STATE(L, NULL);
794 LUASCRIPT_CHECK_SELF(L, pdis, NULL);
795
796 return disaster_name_translation(pdis);
797}
798
799/**********************************************************************/
802 const char *api_methods_achievement_rule_name(lua_State *L,
803 Achievement *pach)
804{
805 LUASCRIPT_CHECK_STATE(L, NULL);
806 LUASCRIPT_CHECK_SELF(L, pach, NULL);
807
808 return achievement_rule_name(pach);
809}
810
811/**********************************************************************/
814 const char *api_methods_achievement_name_translation(lua_State *L,
815 Achievement *pach)
816{
817 LUASCRIPT_CHECK_STATE(L, NULL);
818 LUASCRIPT_CHECK_SELF(L, pach, NULL);
819
820 return achievement_name_translation(pach);
821}
822
823/**********************************************************************/
826 const char *api_methods_action_rule_name(lua_State *L, Action *pact)
827{
828 LUASCRIPT_CHECK_STATE(L, NULL);
829 LUASCRIPT_CHECK_SELF(L, pact, NULL);
830
831 return action_id_rule_name(pact->id);
832}
833
834/**********************************************************************/
837 const char *api_methods_action_name_translation(lua_State *L, Action *pact)
838{
839 LUASCRIPT_CHECK_STATE(L, NULL);
840 LUASCRIPT_CHECK_SELF(L, pact, NULL);
841
842 return action_id_name_translation(pact->id);
843}
844
845/**********************************************************************/
848 const char *api_methods_action_target_kind(lua_State *L, Action *pact)
849{
850 struct action *paction;
851
852 LUASCRIPT_CHECK_STATE(L, NULL);
853 LUASCRIPT_CHECK_SELF(L, pact, NULL);
854
855 paction = action_by_number(pact->id);
856 fc_assert_ret_val(paction, "error: no action");
857
858 return action_target_kind_name(action_get_target_kind(paction));
859}
860
861/**********************************************************************/
864 int api_methods_tile_nat_x(lua_State *L, Tile *ptile)
865{
866 LUASCRIPT_CHECK_STATE(L, -1);
867 LUASCRIPT_CHECK_SELF(L, ptile, -1);
868
869 return index_to_native_pos_x(tile_index(ptile));
870}
871
872/**********************************************************************/
875 int api_methods_tile_nat_y(lua_State *L, Tile *ptile)
876{
877 LUASCRIPT_CHECK_STATE(L, -1);
878 LUASCRIPT_CHECK_SELF(L, ptile, -1);
879
880 return index_to_native_pos_y(tile_index(ptile));
881}
882
883/**********************************************************************/
886 int api_methods_tile_map_x(lua_State *L, Tile *ptile)
887{
888 LUASCRIPT_CHECK_STATE(L, -1);
889 LUASCRIPT_CHECK_SELF(L, ptile, -1);
890
891 return index_to_map_pos_x(tile_index(ptile));
892}
893
894/**********************************************************************/
897 int api_methods_tile_map_y(lua_State *L, Tile *ptile)
898{
899 LUASCRIPT_CHECK_STATE(L, -1);
900 LUASCRIPT_CHECK_SELF(L, ptile, -1);
901
902 return index_to_map_pos_y(tile_index(ptile));
903}
904
905/**********************************************************************/
908 City *api_methods_tile_city(lua_State *L, Tile *ptile)
909{
910 LUASCRIPT_CHECK_STATE(L, NULL);
911 LUASCRIPT_CHECK_SELF(L, ptile, NULL);
912
913 return tile_city(ptile);
914}
915
916/**********************************************************************/
919 bool api_methods_tile_city_exists_within_max_city_map(lua_State *L,
920 Tile *ptile,
921 bool may_be_on_center)
922{
923 LUASCRIPT_CHECK_STATE(L, FALSE);
924 LUASCRIPT_CHECK_SELF(L, ptile, FALSE);
925
926 return city_exists_within_max_city_map(ptile, may_be_on_center);
927}
928
929/**********************************************************************/
933 bool api_methods_tile_has_extra(lua_State *L, Tile *ptile,
934 const char *name)
935{
936 LUASCRIPT_CHECK_STATE(L, FALSE);
937 LUASCRIPT_CHECK_SELF(L, ptile, FALSE);
938
939 if (!name) {
940 extra_type_iterate(pextra) {
941 if (tile_has_extra(ptile, pextra)) {
942 return TRUE;
943 }
944 } extra_type_iterate_end;
945
946 return FALSE;
947 } else {
948 struct extra_type *pextra;
949
950 pextra = extra_type_by_rule_name(name);
951
952 return (NULL != pextra && tile_has_extra(ptile, pextra));
953 }
954}
955
956/**********************************************************************/
960 bool api_methods_tile_has_base(lua_State *L, Tile *ptile, const char *name)
961{
962 LUASCRIPT_CHECK_STATE(L, FALSE);
963 LUASCRIPT_CHECK_SELF(L, ptile, FALSE);
964
965 if (!name) {
966 extra_type_by_cause_iterate(EC_BASE, pextra) {
967 if (tile_has_extra(ptile, pextra)) {
968 return TRUE;
969 }
970 } extra_type_by_cause_iterate_end;
971
972 return FALSE;
973 } else {
974 struct extra_type *pextra;
975
976 pextra = extra_type_by_rule_name(name);
977
978 return (NULL != pextra && is_extra_caused_by(pextra, EC_BASE)
979 && tile_has_extra(ptile, pextra));
980 }
981}
982
983/**********************************************************************/
987 bool api_methods_tile_has_road(lua_State *L, Tile *ptile, const char *name)
988{
989 LUASCRIPT_CHECK_STATE(L, FALSE);
990 LUASCRIPT_CHECK_SELF(L, ptile, FALSE);
991
992 if (!name) {
993 extra_type_by_cause_iterate(EC_ROAD, pextra) {
994 if (tile_has_extra(ptile, pextra)) {
995 return TRUE;
996 }
997 } extra_type_by_cause_iterate_end;
998
999 return FALSE;
1000 } else {
1001 struct extra_type *pextra;
1002
1003 pextra = extra_type_by_rule_name(name);
1004
1005 return (NULL != pextra && is_extra_caused_by(pextra, EC_ROAD)
1006 && tile_has_extra(ptile, pextra));
1007 }
1008}
1009
1010/**********************************************************************/
1016 Player *api_methods_tile_extra_owner(lua_State *L,
1017 Tile *ptile, const char *extra_name)
1018{
1019 LUASCRIPT_CHECK_STATE(L, NULL);
1020 LUASCRIPT_CHECK_SELF(L, ptile, NULL);
1021
1022 if (extra_name) {
1023 struct extra_type *pextra;
1024
1025 pextra = extra_type_by_rule_name(extra_name);
1026 LUASCRIPT_CHECK_ARG(L, pextra != NULL, 3, "unknown extra type", NULL);
1027
1028 if (tile_has_extra(ptile, pextra)) {
1029 /* All extras have the same owner. */
1030 return extra_owner(ptile);
1031 } else {
1032 /* The extra isn't there. */
1033 return NULL;
1034 }
1035 } else {
1036 extra_type_iterate(pextra) {
1037 if (tile_has_extra(ptile, pextra)) {
1038 /* All extras have the same owner. */
1039 return extra_owner(ptile);
1040 }
1041 } extra_type_iterate_end;
1042 return NULL;
1043 }
1044}
1045
1046/**********************************************************************/
1049 bool api_methods_enemy_tile(lua_State *L, Tile *ptile, Player *against)
1050{
1051 struct city *pcity;
1052
1053 LUASCRIPT_CHECK_STATE(L, FALSE);
1054 LUASCRIPT_CHECK_SELF(L, ptile, FALSE);
1055
1056 if (is_non_allied_unit_tile(ptile, against)) {
1057 return TRUE;
1058 }
1059
1060 pcity = tile_city(ptile);
1061 if (pcity != NULL && !pplayers_allied(against, city_owner(pcity))) {
1062 return TRUE;
1063 }
1064
1065 return FALSE;
1066}
1067
1068/**********************************************************************/
1071 int api_methods_tile_num_units(lua_State *L, Tile *ptile)
1072{
1073 LUASCRIPT_CHECK_STATE(L, 0);
1074 LUASCRIPT_CHECK_SELF(L, ptile, 0);
1075
1076 return unit_list_size(ptile->units);
1077}
1078
1079/**********************************************************************/
1082 Unit_List_Link *api_methods_private_tile_unit_list_head(lua_State *L,
1083 Tile *ptile)
1084{
1085 LUASCRIPT_CHECK_STATE(L, NULL);
1086 LUASCRIPT_CHECK_SELF(L, ptile, NULL);
1087
1088 return unit_list_head(ptile->units);
1089}
1090
1091/**********************************************************************/
1095 int api_methods_private_tile_next_outward_index(lua_State *L, Tile *pstart,
1096 int tindex, int max_dist)
1097{
1098 int dx, dy;
1099 int newx, newy;
1100 int startx, starty;
1101
1102 LUASCRIPT_CHECK_STATE(L, 0);
1103 LUASCRIPT_CHECK_SELF(L, pstart, 0);
1104
1105 if (tindex < 0) {
1106 return 0;
1107 }
1108
1109 index_to_map_pos(&startx, &starty, tile_index(pstart));
1110
1111 tindex++;
1112 while (tindex < wld.map.num_iterate_outwards_indices) {
1113 if (wld.map.iterate_outwards_indices[tindex].dist > max_dist) {
1114 return -1;
1115 }
1116 dx = wld.map.iterate_outwards_indices[tindex].dx;
1117 dy = wld.map.iterate_outwards_indices[tindex].dy;
1118 newx = dx + startx;
1119 newy = dy + starty;
1120 if (!normalize_map_pos(&(wld.map), &newx, &newy)) {
1121 tindex++;
1122 continue;
1123 }
1124
1125 return tindex;
1126 }
1127
1128 return -1;
1129}
1130
1131/**********************************************************************/
1134 Tile *api_methods_private_tile_for_outward_index(lua_State *L,
1135 Tile *pstart, int tindex)
1136{
1137 int newx, newy;
1138
1139 LUASCRIPT_CHECK_STATE(L, NULL);
1140 LUASCRIPT_CHECK_SELF(L, pstart, NULL);
1141 LUASCRIPT_CHECK_ARG(L,
1142 tindex >= 0 && tindex < wld.map.num_iterate_outwards_indices,
1143 3, "index out of bounds", NULL);
1144
1145 index_to_map_pos(&newx, &newy, tile_index(pstart));
1146 newx += wld.map.iterate_outwards_indices[tindex].dx;
1147 newy += wld.map.iterate_outwards_indices[tindex].dy;
1148
1149 if (!normalize_map_pos(&(wld.map), &newx, &newy)) {
1150 return NULL;
1151 }
1152
1153 return map_pos_to_tile(&(wld.map), newx, newy);
1154}
1155
1156/**********************************************************************/
1159 int api_methods_tile_sq_distance(lua_State *L, Tile *ptile1, Tile *ptile2)
1160{
1161 LUASCRIPT_CHECK_STATE(L, 0);
1162 LUASCRIPT_CHECK_SELF(L, ptile1, 0);
1163 LUASCRIPT_CHECK_ARG_NIL(L, ptile2, 3, Tile, 0);
1164
1165 return sq_map_distance(ptile1, ptile2);
1166}
1167
1168/**********************************************************************/
1175 bool api_methods_unit_city_can_be_built_here(lua_State *L, Unit *punit)
1176{
1177 LUASCRIPT_CHECK_STATE(L, FALSE);
1178 LUASCRIPT_CHECK_SELF(L, punit, FALSE);
1179
1180 return city_can_be_built_here(unit_tile(punit), punit, TRUE);
1181}
1182
1183/**********************************************************************/
1186 Tile *api_methods_unit_tile_get(lua_State *L, Unit *punit)
1187{
1188 LUASCRIPT_CHECK_STATE(L, NULL);
1189 LUASCRIPT_CHECK_SELF(L, punit, NULL);
1190
1191 return unit_tile(punit);
1192}
1193
1194/**********************************************************************/
1197 const Direction *api_methods_unit_orientation_get(lua_State *L,
1198 Unit *punit)
1199{
1200 LUASCRIPT_CHECK_STATE(L, NULL);
1201 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, NULL);
1202
1203 return luascript_dir(punit->facing);
1204}
1205
1206/**********************************************************************/
1209 Unit *api_methods_unit_transporter(lua_State *L, Unit *punit)
1210{
1211 LUASCRIPT_CHECK_STATE(L, NULL);
1212 LUASCRIPT_CHECK_SELF(L, punit, NULL);
1213
1214 return punit->transporter;
1215}
1216
1217/**********************************************************************/
1220 Unit_List_Link *api_methods_private_unit_cargo_list_head(lua_State *L,
1221 Unit *punit)
1222{
1223 LUASCRIPT_CHECK_STATE(L, NULL);
1224 LUASCRIPT_CHECK_SELF(L, punit, NULL);
1225 return unit_list_head(punit->transporting);
1226}
1227
1228/**********************************************************************/
1231 bool api_methods_unit_type_has_flag(lua_State *L, Unit_Type *punit_type,
1232 const char *flag)
1233{
1234 enum unit_type_flag_id id;
1235
1236 LUASCRIPT_CHECK_STATE(L, FALSE);
1237 LUASCRIPT_CHECK_SELF(L, punit_type, FALSE);
1238 LUASCRIPT_CHECK_ARG_NIL(L, flag, 3, string, FALSE);
1239
1240 id = unit_type_flag_id_by_name(flag, fc_strcasecmp);
1241 if (unit_type_flag_id_is_valid(id)) {
1242 return utype_has_flag(punit_type, id);
1243 } else {
1244 luascript_error(L, "Unit type flag \"%s\" does not exist", flag);
1245 return FALSE;
1246 }
1247}
1248
1249/**********************************************************************/
1252 bool api_methods_unit_type_has_role(lua_State *L, Unit_Type *punit_type,
1253 const char *role)
1254{
1255 enum unit_role_id id;
1256
1257 LUASCRIPT_CHECK_STATE(L, FALSE);
1258 LUASCRIPT_CHECK_SELF(L, punit_type, FALSE);
1259 LUASCRIPT_CHECK_ARG_NIL(L, role, 3, string, FALSE);
1260
1261 id = unit_role_id_by_name(role, fc_strcasecmp);
1262 if (unit_role_id_is_valid(id)) {
1263 return utype_has_role(punit_type, id);
1264 } else {
1265 luascript_error(L, "Unit role \"%s\" does not exist", role);
1266 return FALSE;
1267 }
1268}
1269
1270/**********************************************************************/
1273 bool api_methods_unit_type_can_exist_at_tile(lua_State *L,
1274 Unit_Type *punit_type,
1275 Tile *ptile)
1276{
1277 LUASCRIPT_CHECK_STATE(L, FALSE);
1278 LUASCRIPT_CHECK_SELF(L, punit_type, FALSE);
1279 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, FALSE);
1280
1281 return can_exist_at_tile(&(wld.map), punit_type, ptile);
1282}
1283
1284/**********************************************************************/
1287 const char *api_methods_unit_type_rule_name(lua_State *L,
1288 Unit_Type *punit_type)
1289{
1290 LUASCRIPT_CHECK_STATE(L, NULL);
1291 LUASCRIPT_CHECK_SELF(L, punit_type, NULL);
1292
1293 return utype_rule_name(punit_type);
1294}
1295
1296/**********************************************************************/
1299 const char *api_methods_unit_type_name_translation(lua_State *L,
1300 Unit_Type *punit_type)
1301{
1302 LUASCRIPT_CHECK_STATE(L, NULL);
1303 LUASCRIPT_CHECK_SELF(L, punit_type, NULL);
1304
1305 return utype_name_translation(punit_type);
1306}
1307
1308
1309/**********************************************************************/
1312 Unit *api_methods_unit_list_link_data(lua_State *L,
1313 Unit_List_Link *ul_link)
1314{
1315 LUASCRIPT_CHECK_STATE(L, NULL);
1316
1317 return unit_list_link_data(ul_link);
1318}
1319
1320/**********************************************************************/
1323 Unit_List_Link *api_methods_unit_list_next_link(lua_State *L,
1324 Unit_List_Link *ul_link)
1325{
1326 LUASCRIPT_CHECK_STATE(L, NULL);
1327
1328 return unit_list_link_next(ul_link);
1329}
1330
1331/**********************************************************************/
1334 City *api_methods_city_list_link_data(lua_State *L,
1335 City_List_Link *cl_link)
1336{
1337 LUASCRIPT_CHECK_STATE(L, NULL);
1338
1339 return city_list_link_data(cl_link);
1340}
1341
1342/**********************************************************************/
1345 City_List_Link *api_methods_city_list_next_link(lua_State *L,
1346 City_List_Link *cl_link)
1347{
1348 LUASCRIPT_CHECK_STATE(L, NULL);
1349
1350 return city_list_link_next(cl_link);
1351}
1352
1353/**********************************************************************/
1356 const char *api_methods_tile_link(lua_State *L, Tile *ptile)
1357{
1358 LUASCRIPT_CHECK_STATE(L, NULL);
1359 LUASCRIPT_CHECK_SELF(L, ptile, NULL);
1360
1361 return tile_link(ptile);
1362}
1363
1364/**********************************************************************/
1367 const char *api_methods_unit_tile_link(lua_State *L, Unit *punit)
1368{
1369 LUASCRIPT_CHECK_STATE(L, NULL);
1370 LUASCRIPT_CHECK_SELF(L, punit, NULL);
1371
1372 return unit_tile_link(punit);
1373}
1374
1375/**********************************************************************/
1378 const char *api_methods_city_tile_link(lua_State *L, City *pcity)
1379{
1380 LUASCRIPT_CHECK_STATE(L, NULL);
1381 LUASCRIPT_CHECK_SELF(L, pcity, NULL);
1382
1383 return city_tile_link(pcity);
1384}
1385
1386/**********************************************************************/
1389 const char *api_methods_unit_link(lua_State *L, Unit *punit)
1390{
1391 LUASCRIPT_CHECK_STATE(L, NULL);
1392 LUASCRIPT_CHECK_SELF(L, punit, NULL);
1393
1394 return unit_link(punit);
1395}
1396
1397/**********************************************************************/
1400 const char *api_methods_city_link(lua_State *L, City *pcity)
1401{
1402 LUASCRIPT_CHECK_STATE(L, NULL);
1403 LUASCRIPT_CHECK_SELF(L, pcity, NULL);
1404
1405 return city_link(pcity);
1406}
achievement_rule_name
const char * achievement_rule_name(struct achievement *pach)
Definition achievements.c:114
achievement_name_translation
const char * achievement_name_translation(struct achievement *pach)
Definition achievements.c:106
achievements.h
action_id_name_translation
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1910
action_id_rule_name
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1899
action_get_target_kind
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1740
actions.h
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
api_methods_tile_nat_x
int api_methods_tile_nat_x(lua_State *L, Tile *ptile)
Definition api_game_methods.c:864
api_methods_tile_num_units
int api_methods_tile_num_units(lua_State *L, Tile *ptile)
Definition api_game_methods.c:1071
api_methods_is_city_unhappy
bool api_methods_is_city_unhappy(lua_State *L, City *pcity)
Definition api_game_methods.c:308
api_methods_is_gov_center
bool api_methods_is_gov_center(lua_State *L, City *pcity)
Definition api_game_methods.c:331
api_methods_game_rulesetdir
const char * api_methods_game_rulesetdir(lua_State *L)
Definition api_game_methods.c:107
api_methods_unit_type_can_exist_at_tile
bool api_methods_unit_type_can_exist_at_tile(lua_State *L, Unit_Type *punit_type, Tile *ptile)
Definition api_game_methods.c:1273
api_methods_player_num_cities
int api_methods_player_num_cities(lua_State *L, Player *pplayer)
Definition api_game_methods.c:473
api_methods_unit_can_upgrade
bool api_methods_unit_can_upgrade(lua_State *L, Unit *punit, bool is_free)
Definition api_game_methods.c:594
api_methods_player_has_wonder
bool api_methods_player_has_wonder(lua_State *L, Player *pplayer, Building_Type *building)
Definition api_game_methods.c:449
api_methods_unit_list_next_link
Unit_List_Link * api_methods_unit_list_next_link(lua_State *L, Unit_List_Link *ul_link)
Definition api_game_methods.c:1323
api_methods_nation_type_plural_translation
const char * api_methods_nation_type_plural_translation(lua_State *L, Nation_Type *pnation)
Definition api_game_methods.c:412
api_methods_disaster_name_translation
const char * api_methods_disaster_name_translation(lua_State *L, Disaster *pdis)
Definition api_game_methods.c:790
api_methods_unit_list_link_data
Unit * api_methods_unit_list_link_data(lua_State *L, Unit_List_Link *ul_link)
Definition api_game_methods.c:1312
api_methods_tile_nat_y
int api_methods_tile_nat_y(lua_State *L, Tile *ptile)
Definition api_game_methods.c:875
api_methods_private_tile_unit_list_head
Unit_List_Link * api_methods_private_tile_unit_list_head(lua_State *L, Tile *ptile)
Definition api_game_methods.c:1082
api_methods_game_year_fragment
int api_methods_game_year_fragment(lua_State *L)
Definition api_game_methods.c:70
api_methods_city_culture_get
int api_methods_city_culture_get(lua_State *L, City *pcity)
Definition api_game_methods.c:285
api_methods_unit_type_name_translation
const char * api_methods_unit_type_name_translation(lua_State *L, Unit_Type *punit_type)
Definition api_game_methods.c:1299
api_methods_game_ruleset_name
const char * api_methods_game_ruleset_name(lua_State *L)
Definition api_game_methods.c:115
api_methods_building_type_rule_name
const char * api_methods_building_type_rule_name(lua_State *L, Building_Type *pbuilding)
Definition api_game_methods.c:171
api_methods_city_list_link_data
City * api_methods_city_list_link_data(lua_State *L, City_List_Link *cl_link)
Definition api_game_methods.c:1334
api_methods_unit_tile_link
const char * api_methods_unit_tile_link(lua_State *L, Unit *punit)
Definition api_game_methods.c:1367
api_methods_player_can_build_impr_direct
bool api_methods_player_can_build_impr_direct(lua_State *L, Player *pplayer, Building_Type *itype)
Definition api_game_methods.c:579
api_methods_player_num_units
int api_methods_player_num_units(lua_State *L, Player *pplayer)
Definition api_game_methods.c:484
api_methods_tech_type_rule_name
const char * api_methods_tech_type_rule_name(lua_State *L, Tech_Type *ptech)
Definition api_game_methods.c:722
api_methods_tile_map_x
int api_methods_tile_map_x(lua_State *L, Tile *ptile)
Definition api_game_methods.c:886
api_methods_is_city_happy
bool api_methods_is_city_happy(lua_State *L, City *pcity)
Definition api_game_methods.c:296
api_methods_achievement_rule_name
const char * api_methods_achievement_rule_name(lua_State *L, Achievement *pach)
Definition api_game_methods.c:802
api_methods_player_can_upgrade
Unit_Type * api_methods_player_can_upgrade(lua_State *L, Player *pplayer, Unit_Type *utype)
Definition api_game_methods.c:552
api_methods_city_link
const char * api_methods_city_link(lua_State *L, City *pcity)
Definition api_game_methods.c:1400
api_methods_nation_type_name_translation
const char * api_methods_nation_type_name_translation(lua_State *L, Nation_Type *pnation)
Definition api_game_methods.c:400
api_methods_government_rule_name
const char * api_methods_government_rule_name(lua_State *L, Government *pgovernment)
Definition api_game_methods.c:364
api_methods_terrain_rule_name
const char * api_methods_terrain_rule_name(lua_State *L, Terrain *pterrain)
Definition api_game_methods.c:745
api_methods_player_number
int api_methods_player_number(lua_State *L, Player *pplayer)
Definition api_game_methods.c:462
api_methods_private_unit_cargo_list_head
Unit_List_Link * api_methods_private_unit_cargo_list_head(lua_State *L, Unit *punit)
Definition api_game_methods.c:1220
api_methods_player_controlling_gui
const char * api_methods_player_controlling_gui(lua_State *L, Player *pplayer)
Definition api_game_methods.c:424
api_methods_action_name_translation
const char * api_methods_action_name_translation(lua_State *L, Action *pact)
Definition api_game_methods.c:837
api_methods_terrain_class_name
const char * api_methods_terrain_class_name(lua_State *L, Terrain *pterrain)
Definition api_game_methods.c:768
api_methods_player_shares_research
bool api_methods_player_shares_research(lua_State *L, Player *pplayer, Player *aplayer)
Definition api_game_methods.c:641
api_methods_tech_type_name_translation
const char * api_methods_tech_type_name_translation(lua_State *L, Tech_Type *ptech)
Definition api_game_methods.c:733
api_methods_tile_extra_owner
Player * api_methods_tile_extra_owner(lua_State *L, Tile *ptile, const char *extra_name)
Definition api_game_methods.c:1016
api_methods_city_size_get
int api_methods_city_size_get(lua_State *L, City *pcity)
Definition api_game_methods.c:220
api_methods_tile_city
City * api_methods_tile_city(lua_State *L, Tile *ptile)
Definition api_game_methods.c:908
api_methods_government_name_translation
const char * api_methods_government_name_translation(lua_State *L, Government *pgovernment)
Definition api_game_methods.c:376
api_methods_tile_has_extra
bool api_methods_tile_has_extra(lua_State *L, Tile *ptile, const char *name)
Definition api_game_methods.c:933
api_methods_tile_sq_distance
int api_methods_tile_sq_distance(lua_State *L, Tile *ptile1, Tile *ptile2)
Definition api_game_methods.c:1159
api_methods_unit_type_has_role
bool api_methods_unit_type_has_role(lua_State *L, Unit_Type *punit_type, const char *role)
Definition api_game_methods.c:1252
api_methods_tile_link
const char * api_methods_tile_link(lua_State *L, Tile *ptile)
Definition api_game_methods.c:1356
api_methods_player_culture_get
int api_methods_player_culture_get(lua_State *L, Player *pplayer)
Definition api_game_methods.c:520
api_methods_game_turn_deprecated
int api_methods_game_turn_deprecated(lua_State *L)
Definition api_game_methods.c:90
api_methods_achievement_name_translation
const char * api_methods_achievement_name_translation(lua_State *L, Achievement *pach)
Definition api_game_methods.c:814
api_methods_building_type_is_great_wonder
bool api_methods_building_type_is_great_wonder(lua_State *L, Building_Type *pbuilding)
Definition api_game_methods.c:135
api_methods_city_tile_link
const char * api_methods_city_tile_link(lua_State *L, City *pcity)
Definition api_game_methods.c:1378
api_methods_private_tile_next_outward_index
int api_methods_private_tile_next_outward_index(lua_State *L, Tile *pstart, int tindex, int max_dist)
Definition api_game_methods.c:1095
api_methods_unit_tile_get
Tile * api_methods_unit_tile_get(lua_State *L, Unit *punit)
Definition api_game_methods.c:1186
api_methods_tile_has_road
bool api_methods_tile_has_road(lua_State *L, Tile *ptile, const char *name)
Definition api_game_methods.c:987
api_methods_nation_type_rule_name
const char * api_methods_nation_type_rule_name(lua_State *L, Nation_Type *pnation)
Definition api_game_methods.c:388
api_methods_unit_orientation_get
const Direction * api_methods_unit_orientation_get(lua_State *L, Unit *punit)
Definition api_game_methods.c:1197
api_methods_game_turn
int api_methods_game_turn(lua_State *L)
Definition api_game_methods.c:50
api_methods_player_knows_tech
bool api_methods_player_knows_tech(lua_State *L, Player *pplayer, Tech_Type *ptech)
Definition api_game_methods.c:506
api_methods_enemy_tile
bool api_methods_enemy_tile(lua_State *L, Tile *ptile, Player *against)
Definition api_game_methods.c:1049
api_methods_building_type_is_small_wonder
bool api_methods_building_type_is_small_wonder(lua_State *L, Building_Type *pbuilding)
Definition api_game_methods.c:147
api_methods_game_year
int api_methods_game_year(lua_State *L)
Definition api_game_methods.c:60
api_methods_private_tile_for_outward_index
Tile * api_methods_private_tile_for_outward_index(lua_State *L, Tile *pstart, int tindex)
Definition api_game_methods.c:1134
api_methods_game_year_text
const char * api_methods_game_year_text(lua_State *L)
Definition api_game_methods.c:80
api_methods_action_rule_name
const char * api_methods_action_rule_name(lua_State *L, Action *pact)
Definition api_game_methods.c:826
api_methods_disaster_rule_name
const char * api_methods_disaster_rule_name(lua_State *L, Disaster *pdis)
Definition api_game_methods.c:779
api_methods_building_type_name_translation
const char * api_methods_building_type_name_translation(lua_State *L, Building_Type *pbuilding)
Definition api_game_methods.c:184
api_methods_building_type_is_wonder
bool api_methods_building_type_is_wonder(lua_State *L, Building_Type *pbuilding)
Definition api_game_methods.c:123
api_methods_research_name_translation
const char * api_methods_research_name_translation(lua_State *L, Player *pplayer)
Definition api_game_methods.c:665
api_methods_city_inspire_partisans
int api_methods_city_inspire_partisans(lua_State *L, City *self, Player *inspirer)
Definition api_game_methods.c:242
api_methods_city_map_sq_radius
int api_methods_city_map_sq_radius(lua_State *L, City *pcity)
Definition api_game_methods.c:209
api_methods_city_has_building
bool api_methods_city_has_building(lua_State *L, City *pcity, Building_Type *building)
Definition api_game_methods.c:196
api_methods_unit_transform_problem
const char * api_methods_unit_transform_problem(lua_State *L, Unit *punit, Unit_Type *ptype)
Definition api_game_methods.c:604
api_methods_city_list_next_link
City_List_Link * api_methods_city_list_next_link(lua_State *L, City_List_Link *cl_link)
Definition api_game_methods.c:1345
api_methods_unit_type_has_flag
bool api_methods_unit_type_has_flag(lua_State *L, Unit_Type *punit_type, const char *flag)
Definition api_game_methods.c:1231
api_methods_unit_type_rule_name
const char * api_methods_unit_type_rule_name(lua_State *L, Unit_Type *punit_type)
Definition api_game_methods.c:1287
api_methods_building_type_is_improvement
bool api_methods_building_type_is_improvement(lua_State *L, Building_Type *pbuilding)
Definition api_game_methods.c:159
api_methods_tile_city_exists_within_max_city_map
bool api_methods_tile_city_exists_within_max_city_map(lua_State *L, Tile *ptile, bool may_be_on_center)
Definition api_game_methods.c:919
api_methods_player_has_flag
bool api_methods_player_has_flag(lua_State *L, Player *pplayer, const char *flag)
Definition api_game_methods.c:531
api_methods_private_list_players
lua_Object api_methods_private_list_players(lua_State *L)
Definition api_game_methods.c:682
api_methods_unit_city_can_be_built_here
bool api_methods_unit_city_can_be_built_here(lua_State *L, Unit *punit)
Definition api_game_methods.c:1175
api_methods_tile_has_base
bool api_methods_tile_has_base(lua_State *L, Tile *ptile, const char *name)
Definition api_game_methods.c:960
api_methods_player_gold
int api_methods_player_gold(lua_State *L, Player *pplayer)
Definition api_game_methods.c:495
api_methods_research_rule_name
const char * api_methods_research_rule_name(lua_State *L, Player *pplayer)
Definition api_game_methods.c:654
api_methods_is_primary_capital
bool api_methods_is_primary_capital(lua_State *L, City *pcity)
Definition api_game_methods.c:353
api_methods_tile_map_y
int api_methods_tile_map_y(lua_State *L, Tile *ptile)
Definition api_game_methods.c:897
api_methods_private_player_unit_list_head
Unit_List_Link * api_methods_private_player_unit_list_head(lua_State *L, Player *pplayer)
Definition api_game_methods.c:699
api_methods_action_target_kind
const char * api_methods_action_target_kind(lua_State *L, Action *pact)
Definition api_game_methods.c:848
api_methods_private_player_city_list_head
City_List_Link * api_methods_private_player_city_list_head(lua_State *L, Player *pplayer)
Definition api_game_methods.c:710
api_methods_terrain_name_translation
const char * api_methods_terrain_name_translation(lua_State *L, Terrain *pterrain)
Definition api_game_methods.c:756
api_methods_city_tile_get
Tile * api_methods_city_tile_get(lua_State *L, City *pcity)
Definition api_game_methods.c:231
api_methods_unit_link
const char * api_methods_unit_link(lua_State *L, Unit *punit)
Definition api_game_methods.c:1389
api_methods_is_city_celebrating
bool api_methods_is_city_celebrating(lua_State *L, City *pcity)
Definition api_game_methods.c:320
api_methods_is_capital
bool api_methods_is_capital(lua_State *L, City *pcity)
Definition api_game_methods.c:342
api_methods_player_can_build_unit_direct
bool api_methods_player_can_build_unit_direct(lua_State *L, Player *pplayer, Unit_Type *utype)
Definition api_game_methods.c:566
api_methods_unit_transporter
Unit * api_methods_unit_transporter(lua_State *L, Unit *punit)
Definition api_game_methods.c:1209
api_game_methods.h
calendar_text
const char * calendar_text(void)
Definition calendar.c:141
calendar.h
citizens_nation_get
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
citizens.h
city_exists_within_max_city_map
bool city_exists_within_max_city_map(const struct tile *ptile, bool may_be_on_center)
Definition city.c:2074
city_has_building
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1207
is_capital
bool is_capital(const struct city *pcity)
Definition city.c:1544
city_can_be_built_here
bool city_can_be_built_here(const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1451
city_unhappy
bool city_unhappy(const struct city *pcity)
Definition city.c:1591
city_celebrating
bool city_celebrating(const struct city *pcity)
Definition city.c:1610
city_happy
bool city_happy(const struct city *pcity)
Definition city.c:1579
city_map_radius_sq_get
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:131
is_gov_center
bool is_gov_center(const struct city *pcity)
Definition city.c:1552
city_tile
#define city_tile(_pcity_)
Definition city.h:544
city_size_get
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
city_owner
#define city_owner(_pcity_)
Definition city.h:543
self
static struct ai_type * self
Definition classicai.c:46
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:113
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:115
city_culture
int city_culture(const struct city *pcity)
Definition culture.c:29
player_culture
int player_culture(const struct player *plr)
Definition culture.c:46
culture.h
deprecations.h
log_deprecation
#define log_deprecation(message,...)
Definition deprecations.h:35
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
disaster_rule_name
const char * disaster_rule_name(struct disaster_type *pdis)
Definition disaster.c:105
disaster_name_translation
const char * disaster_name_translation(struct disaster_type *pdis)
Definition disaster.c:97
id
int int id
Definition editgui_g.h:28
get_target_bonus_effects
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:691
extra_type_by_rule_name
struct extra_type * extra_type_by_rule_name(const char *name)
Definition extras.c:204
extra_owner
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1068
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:291
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:297
is_extra_caused_by
#define is_extra_caused_by(e, c)
Definition extras.h:196
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:315
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
is_server
static bool is_server(void)
Definition fc_interface.h:69
citizens
unsigned char citizens
Definition fc_types.h:358
city_tile_link
const char * city_tile_link(const struct city *pcity)
Definition featured_text.c:1089
tile_link
const char * tile_link(const struct tile *ptile)
Definition featured_text.c:1106
city_link
const char * city_link(const struct city *pcity)
Definition featured_text.c:1072
unit_link
const char * unit_link(const struct unit *punit)
Definition featured_text.c:1200
unit_tile_link
const char * unit_tile_link(const struct unit *punit)
Definition featured_text.c:1217
featured_text.h
game
struct civ_game game
Definition game.c:57
wld
struct world wld
Definition game.c:58
game.h
government_name_translation
const char * government_name_translation(const struct government *pgovern)
Definition government.c:142
government_rule_name
const char * government_rule_name(const struct government *pgovern)
Definition government.c:132
government.h
can_player_build_improvement_direct
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
Definition improvement.c:659
is_improvement
bool is_improvement(const struct impr_type *pimprove)
Definition improvement.c:783
wonder_is_built
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:857
improvement_rule_name
const char * improvement_rule_name(const struct impr_type *pimprove)
Definition improvement.c:250
is_wonder
bool is_wonder(const struct impr_type *pimprove)
Definition improvement.c:341
is_great_wonder
bool is_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:767
improvement_name_translation
const char * improvement_name_translation(const struct impr_type *pimprove)
Definition improvement.c:241
is_small_wonder
bool is_small_wonder(const struct impr_type *pimprove)
Definition improvement.c:775
improvement.h
name
const char * name
Definition inputfile.c:127
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
luascript_error
int luascript_error(lua_State *L, const char *format,...)
Definition luascript.c:291
luascript_dir
const Direction * luascript_dir(enum direction8 dir)
Definition luascript.c:789
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
City_List_Link
const struct city_list_link City_List_Link
Definition luascript_types.h:69
Direction
enum direction8 Direction
Definition luascript_types.h:57
Unit_List_Link
const struct unit_list_link Unit_List_Link
Definition luascript_types.h:68
sq_map_distance
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:639
map_pos_to_tile
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:417
normalize_map_pos
bool normalize_map_pos(const struct civ_map *nmap, int *x, int *y)
Definition map.c:977
map.h
index_to_native_pos_y
#define index_to_native_pos_y(mindex)
Definition map.h:156
index_to_map_pos_y
static int index_to_map_pos_y(int mindex)
Definition map.h:696
index_to_map_pos_x
static int index_to_map_pos_x(int mindex)
Definition map.h:687
index_to_native_pos_x
#define index_to_native_pos_x(mindex)
Definition map.h:154
index_to_map_pos
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:227
can_exist_at_tile
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:275
movement.h
nation_rule_name
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
nation_adjective_translation
const char * nation_adjective_translation(const struct nation_type *pnation)
Definition nation.c:148
nation_plural_translation
const char * nation_plural_translation(const struct nation_type *pnation)
Definition nation.c:158
nation.h
MAX_LEN_MSG
#define MAX_LEN_MSG
Definition packets.h:43
player_count
int player_count(void)
Definition player.c:808
player_number
int player_number(const struct player *pplayer)
Definition player.c:828
player_has_flag
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1954
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
players_iterate_end
#define players_iterate_end
Definition player.h:535
players_iterate
#define players_iterate(_pplayer)
Definition player.h:530
research_rule_name
const char * research_rule_name(const struct research *presearch)
Definition research.c:141
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:126
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
research_pretty_name
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:167
research.h
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
achievement
Definition achievements.h:26
action
Definition actions.h:379
action::id
action_id id
Definition actions.h:380
advance
Definition tech.h:124
city
Definition city.h:309
city::capital
enum capital_type capital
Definition city.h:317
city::happy
bool happy
Definition city.h:445
city::tile
struct tile * tile
Definition city.h:311
city::unhappy
bool unhappy
Definition city.h:446
city::client
struct city::@17::@20 client
civ_game::server
struct civ_game::@30::@34 server
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::rulesetdir
char rulesetdir[MAX_LEN_NAME]
Definition game.h:236
civ_map::num_iterate_outwards_indices
int num_iterate_outwards_indices
Definition map_types.h:76
civ_map::iterate_outwards_indices
struct iter_index * iterate_outwards_indices
Definition map_types.h:75
connection
Definition connection.h:141
connection::client_gui
enum gui_type client_gui
Definition connection.h:184
disaster_type
Definition disaster.h:46
extra_type
Definition extras.h:85
government
Definition government.h:52
impr_type
Definition improvement.h:68
iter_index::dist
int dist
Definition city.h:102
iter_index::dx
int dx
Definition city.h:102
iter_index::dy
int dy
Definition city.h:102
nation_type
Definition nation.h:97
packet_game_info::citizen_partisans_pct
int citizen_partisans_pct
Definition packets_gen.h:146
packet_game_info::citizen_nationality
bool citizen_nationality
Definition packets_gen.h:143
packet_game_info::fragment_count
int fragment_count
Definition packets_gen.h:245
packet_game_info::turn
int turn
Definition packets_gen.h:241
packet_game_info::year
int year
Definition packets_gen.h:243
packet_ruleset_control::name
char name[MAX_LEN_NAME]
Definition packets_gen.h:1481
player_economic::gold
int gold
Definition player.h:70
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::units
struct unit_list * units
Definition player.h:282
player::connections
struct conn_list * connections
Definition player.h:298
player::economic
struct player_economic economic
Definition player.h:284
player::slot
struct player_slot * slot
Definition player.h:250
req_context
Definition requirements.h:99
terrain
Definition terrain.h:176
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
unit_type
Definition unittype.h:481
unit
Definition unit.h:138
unit::transporting
struct unit_list * transporting
Definition unit.h:184
unit::facing
enum direction8 facing
Definition unit.h:142
unit::transporter
struct unit * transporter
Definition unit.h:183
world::map
struct civ_map map
Definition world_object.h:38
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
advance_name_translation
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
advance_rule_name
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
advance_number
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
tech.h
terrain_name_translation
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
terrain_rule_name
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
terrain_type_terrain_class
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
Definition terrain.c:570
terrain.h
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile.h
tile_index
#define tile_index(_pt_)
Definition tile.h:87
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
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:1936
unit_upgrade_test
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap, const struct unit *punit, bool is_free)
Definition unit.c:1968
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
unit_upgrade_result
unit_upgrade_result
Definition unit.h:60
UU_NO_MONEY
@ UU_NO_MONEY
Definition unit.h:63
UU_NOT_IN_CITY
@ UU_NOT_IN_CITY
Definition unit.h:64
UU_NO_UNITTYPE
@ UU_NO_UNITTYPE
Definition unit.h:62
UU_NOT_TERRAIN
@ UU_NOT_TERRAIN
Definition unit.h:67
UU_UNSUITABLE_TRANSPORT
@ UU_UNSUITABLE_TRANSPORT
Definition unit.h:68
UU_NOT_CITY_OWNER
@ UU_NOT_CITY_OWNER
Definition unit.h:65
UU_NOT_ENOUGH_ROOM
@ UU_NOT_ENOUGH_ROOM
Definition unit.h:66
UU_OK
@ UU_OK
Definition unit.h:61
UU_NOT_ACTIVITY
@ UU_NOT_ACTIVITY
Definition unit.h:69
is_non_allied_unit_tile
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:423
unitlist.h
utype_has_role
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:193
can_upgrade_unittype
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1755
can_player_build_unit_direct
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2015
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
utype_name_translation
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1612
unittype.h
utype_has_flag
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604