~ubuntu-branches/debian/sid/freeciv/sid

« back to all changes in this revision

Viewing changes to server/scripting/api_find.c

  • Committer: Package Import Robot
  • Author(s): Clint Adams, Karl Goetz, Clint Adams
  • Date: 2011-08-28 22:40:00 UTC
  • mfrom: (1.2.19 upstream)
  • Revision ID: package-import@ubuntu.com-20110828224000-j2r1erewlem25dox
Tags: 2.3.0-1
[ Karl Goetz ]
* New upstream version.
* Fix themes_sdl_use_system_fonts.diff to apply cleanly on 2.3.0
* Massage work_around_unity_induced_breakage.diff to get it
  applying to the new codebase (The patch assumes commits made
  after 2.3.0 was tagged upstream).

[ Clint Adams ]
* Fudge build system to think there is no libtool mismatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include <config.h>
16
16
#endif
17
17
 
 
18
/* common */
18
19
#include "idex.h"
 
20
#include "movement.h"
19
21
 
 
22
/* server/scripting */
20
23
#include "api_find.h"
21
24
#include "script.h"
22
25
 
26
29
**************************************************************************/
27
30
Player *api_find_player(int player_id)
28
31
{
29
 
  return valid_player_by_number(player_id);
 
32
  return player_by_number(player_id);
30
33
}
31
34
 
32
35
/**************************************************************************
35
38
City *api_find_city(Player *pplayer, int city_id)
36
39
{
37
40
  if (pplayer) {
38
 
    return player_find_city_by_id(pplayer, city_id);
 
41
    return player_city_by_number(pplayer, city_id);
39
42
  } else {
40
43
    return idex_lookup_city(city_id);
41
44
  }
47
50
Unit *api_find_unit(Player *pplayer, int unit_id)
48
51
{
49
52
  if (pplayer) {
50
 
    return player_find_unit_by_id(pplayer, unit_id);
 
53
    return player_unit_by_number(pplayer, unit_id);
51
54
  } else {
52
55
    return idex_lookup_unit(unit_id);
53
56
  }
54
57
}
55
58
 
 
59
/**************************************************************************
 
60
  Return a unit that can transport ptype at a given ptile.
 
61
**************************************************************************/
 
62
Unit *api_find_transport_unit(Player *pplayer, Unit_Type *ptype,
 
63
                              Tile *ptile)
 
64
{
 
65
  SCRIPT_CHECK_ARG_NIL(pplayer, 1, Player, NULL);
 
66
  SCRIPT_CHECK_ARG_NIL(ptype, 2, Unit_Type, NULL);
 
67
  SCRIPT_CHECK_ARG_NIL(ptile, 3, Tile, NULL);
 
68
 
 
69
  {
 
70
    struct unit *ptransport;
 
71
    struct unit *pvirt = create_unit_virtual(pplayer, NULL, ptype, 0);
 
72
    pvirt->tile = ptile;
 
73
    pvirt->homecity = 0;
 
74
    ptransport = transport_from_tile(pvirt, ptile);
 
75
    destroy_unit_virtual(pvirt);
 
76
    return ptransport;
 
77
  }
 
78
}
 
79
 
56
80
/************************************************************************** 
57
81
  Return a unit type for given role.
58
82
**************************************************************************/
59
83
Unit_Type *api_find_role_unit_type(const char *role_name, Player *pplayer)
60
84
{
61
 
  SCRIPT_ASSERT(NULL != role_name, NULL);
62
 
 
63
 
  {
64
 
    enum unit_role_id role = find_unit_role_by_rule_name(role_name);
65
 
 
66
 
    if (role == L_LAST) {
67
 
      return NULL;
68
 
    }
69
 
 
70
 
    if (pplayer) {
71
 
      return best_role_unit_for_player(pplayer, role);
72
 
    } else if (num_role_units(role) > 0) {
73
 
      return get_role_unit(role, 0);
74
 
    } else {
75
 
      return NULL;
76
 
    }
 
85
  enum unit_role_id role;
 
86
  SCRIPT_CHECK_ARG_NIL(role_name, 1, string, NULL);
 
87
 
 
88
  role = unit_role_by_rule_name(role_name);
 
89
 
 
90
  if (role == L_LAST) {
 
91
    return NULL;
 
92
  }
 
93
 
 
94
  if (pplayer) {
 
95
    return best_role_unit_for_player(pplayer, role);
 
96
  } else if (num_role_units(role) > 0) {
 
97
    return get_role_unit(role, 0);
 
98
  } else {
 
99
    return NULL;
77
100
  }
78
101
}
79
102
 
106
129
**************************************************************************/
107
130
Government *api_find_government_by_name(const char *name_orig)
108
131
{
109
 
  SCRIPT_ASSERT(NULL != name_orig, NULL);
110
 
  return find_government_by_rule_name(name_orig);
 
132
  SCRIPT_CHECK_ARG_NIL(name_orig, 1, string, NULL);
 
133
  return government_by_rule_name(name_orig);
111
134
}
112
135
 
113
136
/**************************************************************************
123
146
**************************************************************************/
124
147
Nation_Type *api_find_nation_type_by_name(const char *name_orig)
125
148
{
126
 
  SCRIPT_ASSERT(NULL != name_orig, NULL);
127
 
  return find_nation_by_rule_name(name_orig);
 
149
  SCRIPT_CHECK_ARG_NIL(name_orig, 1, string, NULL);
 
150
  return nation_by_rule_name(name_orig);
128
151
}
129
152
 
130
153
/**************************************************************************
140
163
**************************************************************************/
141
164
Building_Type *api_find_building_type_by_name(const char *name_orig)
142
165
{
143
 
  SCRIPT_ASSERT(NULL != name_orig, NULL);
144
 
  return find_improvement_by_rule_name(name_orig);
 
166
  SCRIPT_CHECK_ARG_NIL(name_orig, 1, string, NULL);
 
167
  return improvement_by_rule_name(name_orig);
145
168
}
146
169
 
147
170
/**************************************************************************
157
180
**************************************************************************/
158
181
Unit_Type *api_find_unit_type_by_name(const char *name_orig)
159
182
{
160
 
  SCRIPT_ASSERT(NULL != name_orig, NULL);
161
 
  return find_unit_type_by_rule_name(name_orig);
 
183
  SCRIPT_CHECK_ARG_NIL(name_orig, 1, string, NULL);
 
184
  return unit_type_by_rule_name(name_orig);
162
185
}
163
186
 
164
187
/**************************************************************************
174
197
**************************************************************************/
175
198
Tech_Type *api_find_tech_type_by_name(const char *name_orig)
176
199
{
177
 
  SCRIPT_ASSERT(NULL != name_orig, NULL);
178
 
  return find_advance_by_rule_name(name_orig);
 
200
  SCRIPT_CHECK_ARG_NIL(name_orig, 1, string, NULL);
 
201
  return advance_by_rule_name(name_orig);
179
202
}
180
203
 
181
204
/**************************************************************************
191
214
**************************************************************************/
192
215
Terrain *api_find_terrain_by_name(const char *name_orig)
193
216
{
194
 
  SCRIPT_ASSERT(NULL != name_orig, NULL);
195
 
  return find_terrain_by_rule_name(name_orig);
 
217
  SCRIPT_CHECK_ARG_NIL(name_orig, 1, string, NULL);
 
218
  return terrain_by_rule_name(name_orig);
196
219
}
197
220
 
198
221
/**************************************************************************