Freeciv-3.2
Loading...
Searching...
No Matches
api_game_find.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/* common */
19#include "counters.h"
20#include "idex.h"
21#include "map.h"
22#include "movement.h"
23
24/* common/scriptcore */
25#include "luascript.h"
26
27#include "api_game_find.h"
28
29/**********************************************************************/
38
39/**********************************************************************/
43{
45
46 return player_by_number(player_id);
47}
48
49/**********************************************************************/
52City *api_find_city(lua_State *L, Player *pplayer, int city_id)
53{
55
56 if (pplayer) {
57 return player_city_by_number(pplayer, city_id);
58 } else {
59 return idex_lookup_city(&wld, city_id);
60 }
61}
62
63/**********************************************************************/
66Unit *api_find_unit(lua_State *L, Player *pplayer, int unit_id)
67{
69
70 if (pplayer) {
71 return player_unit_by_number(pplayer, unit_id);
72 } else {
73 return idex_lookup_unit(&wld, unit_id);
74 }
75}
76
77/**********************************************************************/
81 Unit_Type *ptype, Tile *ptile)
82{
84 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
87
88 {
89 struct unit *ptransport;
90 struct unit *pvirt = unit_virtual_create(pplayer, NULL, ptype, 0);
91 unit_tile_set(pvirt, ptile);
92 pvirt->homecity = 0;
95 return ptransport;
96 }
97}
98
99/**********************************************************************/
104 Player *pplayer)
105{
106 int role_or_flag;
107
110
112
116 return NULL;
117 }
118 }
119
120 if (pplayer) {
122 } else if (num_role_units(role_or_flag) > 0) {
123 return get_role_unit(role_or_flag, 0);
124 } else {
125 return NULL;
126 }
127}
128
129/**********************************************************************/
138
139/**********************************************************************/
143{
145
146 return index_to_tile(&(wld.map), tindex);
147}
148
149/**********************************************************************/
158
159/**********************************************************************/
170
171/**********************************************************************/
180
181/**********************************************************************/
192
193/**********************************************************************/
197{
199
200 return action_by_number(act_id);
201}
202
203/**********************************************************************/
214
215/**********************************************************************/
224
225/**********************************************************************/
236
237/**********************************************************************/
246
247/**********************************************************************/
257
258/**********************************************************************/
267
268/**********************************************************************/
278
279/**********************************************************************/
288
289/**********************************************************************/
299
300/**********************************************************************/
309
310/**********************************************************************/
320
321/**********************************************************************/
330
331/**********************************************************************/
341
342/**********************************************************************/
346{
348
349 return luascript_dir((enum direction8) id);
350}
351
352/**********************************************************************/
361
362/**********************************************************************/
372
373/**********************************************************************/
382
383/**********************************************************************/
393
394/**********************************************************************/
398{
399 static char *p = "";
400
402
403 return p;
404}
struct achievement * achievement_by_number(int id)
struct achievement * achievement_by_rule_name(const char *name)
struct action * action_by_rule_name(const char *name)
Definition actions.c:1840
static struct action * action_by_number(action_id act_id)
Definition actions.h:635
Nation_Type * api_find_nation_type(lua_State *L, int nation_type_id)
Tile * api_find_tile(lua_State *L, int nat_x, int nat_y)
Unit_Type * api_find_unit_type(lua_State *L, int unit_type_id)
Government * api_find_government_by_name(lua_State *L, const char *name_orig)
Player * api_find_player(lua_State *L, int player_id)
Achievement * api_find_achievement_by_name(lua_State *L, const char *name_orig)
Achievement * api_find_achievement(lua_State *L, int achievement_id)
Unit_Type * api_find_role_unit_type(lua_State *L, const char *role_name, Player *pplayer)
const Direction * api_find_direction(lua_State *L, int id)
Action * api_find_action_type_by_name(lua_State *L, const char *name)
Tile * api_find_tile_by_index(lua_State *L, int tindex)
Building_Type * api_find_building_type_by_name(lua_State *L, const char *name_orig)
Nation_Type * api_find_nation_type_by_name(lua_State *L, const char *name_orig)
Disaster * api_find_disaster(lua_State *L, int disaster_id)
Tech_Type * api_find_tech_type_by_name(lua_State *L, const char *name_orig)
Government * api_find_government(lua_State *L, int government_id)
Disaster * api_find_disaster_by_name(lua_State *L, const char *name_orig)
Counter * api_find_counter(lua_State *L, int counter_id)
Building_Type * api_find_building_type(lua_State *L, int building_type_id)
Action * api_find_action_type_by_id(lua_State *L, int id)
Action * api_find_action_by_name(lua_State *L, const char *name_orig)
Nonexistent * api_find_nonexistent(lua_State *L)
Player * api_find_player_by_name(lua_State *L, const char *name)
Unit * api_find_transport_unit(lua_State *L, Player *pplayer, Unit_Type *ptype, Tile *ptile)
Tech_Type * api_find_tech_type(lua_State *L, int tech_type_id)
City * api_find_city(lua_State *L, Player *pplayer, int city_id)
Unit * api_find_unit(lua_State *L, Player *pplayer, int unit_id)
Action * api_find_action(lua_State *L, action_id act_id)
Terrain * api_find_terrain(lua_State *L, int terrain_id)
Terrain * api_find_terrain_by_name(lua_State *L, const char *name_orig)
Counter * api_find_counter_by_name(lua_State *L, const char *name)
Unit_Type * api_find_unit_type_by_name(lua_State *L, const char *name_orig)
char * incite_cost
Definition comments.c:75
struct counter * counter_by_rule_name(const char *name)
Definition counters.c:115
struct counter * counter_by_id(int id)
Definition counters.c:82
int counter_id(struct counter *pcount)
Definition counters.c:105
struct disaster_type * disaster_by_rule_name(const char *name)
Definition disaster.c:114
struct disaster_type * disaster_by_number(Disaster_type_id id)
Definition disaster.c:87
int action_id
Definition fc_types.h:389
struct world wld
Definition game.c:63
struct government * government_by_number(const Government_type_id gov)
Definition government.c:103
struct government * government_by_rule_name(const char *name)
Definition government.c:55
struct city * idex_lookup_city(struct world *iworld, int id)
Definition idex.c:133
struct unit * idex_lookup_unit(struct world *iworld, int id)
Definition idex.c:146
struct impr_type * improvement_by_number(const Impr_type_id id)
struct impr_type * improvement_by_rule_name(const char *name)
const char * name
Definition inputfile.c:127
const Direction * luascript_dir(enum direction8 dir)
Definition luascript.c:789
#define LUASCRIPT_CHECK_STATE(L,...)
Definition luascript.h:117
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition luascript.h:138
enum direction8 Direction
void Nonexistent
#define nat_x
#define nat_y
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:456
struct tile * native_pos_to_tile(const struct civ_map *nmap, int nat_x, int nat_y)
Definition map.c:443
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:475
struct nation_type * nation_by_rule_name(const char *name)
Definition nation.c:121
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1229
struct player * player_by_number(const int player_id)
Definition player.c:849
struct player * player_by_name(const char *name)
Definition player.c:881
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1203
Definition city.h:320
Definition tile.h:50
Definition unit.h:138
struct civ_map map
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
struct advance * advance_by_rule_name(const char *name)
Definition tech.c:200
struct terrain * terrain_by_rule_name(const char *name)
Definition terrain.c:186
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:156
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Definition unit.c:1624
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1729
void unit_tile_set(struct unit *punit, struct tile *ptile)
Definition unit.c:1255
struct unit * transporter_for_unit(const struct unit *pcargo)
Definition unit.c:1912
struct unit_type * unit_type_by_rule_name(const char *name)
Definition unittype.c:1767
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2253
int num_role_units(int role)
Definition unittype.c:2203
struct unit_type * best_role_unit_for_player(const struct player *pplayer, int role)
Definition unittype.c:2298
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:112