1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
|
/**********************************************************************
Freeciv - Copyright (C) 2005 - The Freeciv Project
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
$#ifdef HAVE_CONFIG_H
$#include <config.h>
$#endif
$#include "api_types.h"
$#include "api_actions.h"
$#include "api_find.h"
$#include "api_intl.h"
$#include "api_methods.h"
$#include "api_notify.h"
$#include "api_utilities.h"
$#include "script.h"
/* Classes. */
struct Player_ai {
bool control;
};
struct Player {
const char *name;
Nation_Type *nation;
Player_ai ai;
const int player_no @ id;
};
struct City {
const char *name;
Player *owner;
Tile *tile;
const int id;
};
struct Unit {
Unit_Type *utype;
Player *owner;
int homecity @ homecity_id;
Tile *tile;
const int id;
};
struct Tile {
const int nat_x;
const int nat_y;
Terrain *terrain;
const int index @ id;
};
struct Government {
const int index @ id;
};
struct Nation_Type {
const int index @ id;
};
struct Building_Type {
int build_cost;
const int index @ id;
};
struct Unit_Type {
int build_cost;
const int index @ id;
};
struct Tech_Type {
const int index @ id;
};
struct Terrain {
const int index @ id;
};
/* Class methods. */
int api_methods_player_num_cities
@ methods_player_num_cities (Player *pplayer);
int api_methods_player_num_units
@ methods_player_num_units (Player *pplayer);
bool api_methods_unit_type_has_flag
@ methods_unit_type_has_flag (Unit_Type *punit_type, const char *flag);
bool api_methods_unit_type_has_role
@ methods_unit_type_has_role (Unit_Type *punit_type, const char *role);
bool api_methods_building_type_is_wonder
@ methods_building_type_is_wonder (Building_Type *pbuilding);
bool api_methods_building_type_is_great_wonder
@ methods_building_type_is_great_wonder (Building_Type *pbuilding);
bool api_methods_building_type_is_small_wonder
@ methods_building_type_is_small_wonder (Building_Type *pbuilding);
bool api_methods_building_type_is_improvement
@ methods_building_type_is_improvement (Building_Type *pbuilding);
$[
-- Player methods.
function Player:is_human()
return not self.ai.control
end
function Player:num_cities()
return methods_player_num_cities(self)
end
function Player:num_units()
return methods_player_num_units(self)
end
-- Unit methods.
function Unit:homecity()
return find.city(self.owner, self.homecity_id)
end
-- Building_Type methods.
function Building_Type:build_shield_cost()
return self.build_cost
end
function Building_Type:is_wonder()
return methods_building_type_is_wonder(self)
end
function Building_Type:is_great_wonder()
return methods_building_type_is_great_wonder(self)
end
function Building_Type:is_small_wonder()
return methods_building_type_is_small_wonder(self)
end
function Building_Type:is_improvement()
return methods_building_type_is_improvement(self)
end
-- Unit_Type methods.
function Unit_Type:build_shield_cost()
return self.build_cost
end
function Unit_Type:has_flag(flag)
return methods_unit_type_has_flag(self, flag)
end
function Unit_Type:has_role(role)
return methods_unit_type_has_role(self, role)
end
$]
/* Object find module. */
module find {
Player *api_find_player @ player (int player_id);
City *api_find_city @ city (Player *pplayer, int city_id);
Unit *api_find_unit @ unit (Player *pplayer, int unit_id);
Tile *api_find_tile @ tile (int nat_x, int nat_y);
Government *api_find_government
@ government (int government_id);
Government *api_find_government_by_name
@ government (const char *name_orig);
Nation_Type *api_find_nation_type_by_name
@ nation_type (const char *name_orig);
Nation_Type *api_find_nation_type
@ nation_type (int nation_type_id);
Building_Type *api_find_building_type_by_name
@ building_type (const char *name_orig);
Building_Type *api_find_building_type
@ building_type (int building_type_id);
Unit_Type *api_find_unit_type_by_name
@ unit_type (const char *name_orig);
Unit_Type *api_find_unit_type
@ unit_type (int unit_type_id);
Tech_Type *api_find_tech_type_by_name
@ tech_type (const char *name_orig);
Tech_Type *api_find_tech_type
@ tech_type (int tech_type_id);
Terrain *api_find_terrain_by_name
@ terrain (const char *name_orig);
Terrain *api_find_terrain
@ terrain (int terrain_id);
}
$[
-- Dump the state of user scalar variables to a Lua code string.
function _freeciv_state_dump()
local res = ''
for k, v in pairs(_G) do
if k == '_VERSION' then
-- ignore _VERSION variable.
elseif type(v) == 'boolean'
or type(v) == 'number' then
local rvalue = tostring(v)
res = res .. k .. '=' .. rvalue .. '\n'
elseif type(v) == 'string' then
local rvalue = string.format('%q', v)
res = res .. k .. '=' .. rvalue .. '\n'
elseif type(v) == 'userdata' then
local method = string.lower(tolua.type(v))
res = res .. k .. '=find.' .. method
if method == 'city' or method == 'unit' then
res = res .. '(nil,' .. v.id .. ')'
else
res = res .. '(' .. v.id .. ')'
end
res = res .. '\n'
end
end
return res
end
$]
/* Signal module. */
module signal {
void script_signal_connect @ connect(const char *signal_name,
const char *callback_name);
}
/* Intl module. */
const char *api_intl__ @ _ (const char *string);
const char *api_intl_N_ @ N_ (const char *string);
const char *api_intl_Q_ @ Q_ (const char *string);
const char *api_intl_PL_ @ PL_ (const char *string1, const char *string2,
int n);
/* Notify module. */
module notify {
void api_notify_embassies_msg @ embassies_msg (Player *pplayer,
Tile *ptile,
int event,
const char *message);
void api_notify_event_msg @ event_msg (Player *pplayer, Tile *ptile,
int event, const char *message);
}
/* Notify events module. */
module E {
enum event_type {
E_CITY_CANTBUILD @ CITY_CANTBUILD,
E_CITY_LOST @ CITY_LOST,
E_CITY_LOVE @ CITY_LOVE,
E_CITY_DISORDER @ CITY_DISORDER,
E_CITY_FAMINE @ CITY_FAMINE,
E_CITY_FAMINE_FEARED @ CITY_FAMINE_FEARED,
E_CITY_GROWTH @ CITY_GROWTH,
E_CITY_MAY_SOON_GROW @ CITY_MAY_SOON_GROW,
E_CITY_AQUEDUCT @ CITY_AQUEDUCT,
E_CITY_AQ_BUILDING @ CITY_AQ_BUILDING,
E_CITY_NORMAL @ CITY_NORMAL,
E_CITY_NUKED @ CITY_NUKED,
E_CITY_CMA_RELEASE @ CITY_CMA_RELEASE,
E_CITY_GRAN_THROTTLE @ CITY_GRAN_THROTTLE,
E_CITY_TRANSFER @ CITY_TRANSFER,
E_CITY_BUILD @ CITY_BUILD,
E_CITY_PRODUCTION_CHANGED @ CITY_PRODUCTION_CHANGED,
E_WORKLIST @ WORKLIST,
E_UPRISING @ UPRISING,
E_CIVIL_WAR @ CIVIL_WAR,
E_ANARCHY @ ANARCHY,
E_FIRST_CONTACT @ FIRST_CONTACT,
E_NEW_GOVERNMENT @ NEW_GOVERNMENT,
E_LOW_ON_FUNDS @ LOW_ON_FUNDS,
E_POLLUTION @ POLLUTION,
E_REVOLT_DONE @ REVOLT_DONE,
E_REVOLT_START @ REVOLT_START,
E_SPACESHIP @ SPACESHIP,
E_MY_DIPLOMAT_BRIBE @ MY_DIPLOMAT_BRIBE,
E_DIPLOMATIC_INCIDENT @ DIPLOMATIC_INCIDENT,
E_MY_DIPLOMAT_ESCAPE @ MY_DIPLOMAT_ESCAPE,
E_MY_DIPLOMAT_EMBASSY @ MY_DIPLOMAT_EMBASSY,
E_MY_DIPLOMAT_FAILED @ MY_DIPLOMAT_FAILED,
E_MY_DIPLOMAT_INCITE @ MY_DIPLOMAT_INCITE,
E_MY_DIPLOMAT_POISON @ MY_DIPLOMAT_POISON,
E_MY_DIPLOMAT_SABOTAGE @ MY_DIPLOMAT_SABOTAGE,
E_MY_DIPLOMAT_THEFT @ MY_DIPLOMAT_THEFT,
E_ENEMY_DIPLOMAT_BRIBE @ ENEMY_DIPLOMAT_BRIBE,
E_ENEMY_DIPLOMAT_EMBASSY @ ENEMY_DIPLOMAT_EMBASSY,
E_ENEMY_DIPLOMAT_FAILED @ ENEMY_DIPLOMAT_FAILED,
E_ENEMY_DIPLOMAT_INCITE @ ENEMY_DIPLOMAT_INCITE,
E_ENEMY_DIPLOMAT_POISON @ ENEMY_DIPLOMAT_POISON,
E_ENEMY_DIPLOMAT_SABOTAGE @ ENEMY_DIPLOMAT_SABOTAGE,
E_ENEMY_DIPLOMAT_THEFT @ ENEMY_DIPLOMAT_THEFT,
E_CARAVAN_ACTION @ CARAVAN_ACTION,
E_TUTORIAL @ TUTORIAL,
E_BROADCAST_REPORT @ BROADCAST_REPORT,
E_GAME_END @ GAME_END,
E_GAME_START @ GAME_START,
E_MESSAGE_WALL @ MESSAGE_WALL,
E_NATION_SELECTED @ NATION_SELECTED,
E_DESTROYED @ DESTROYED,
E_REPORT @ REPORT,
E_TURN_BELL @ TURN_BELL,
E_NEXT_YEAR @ NEXT_YEAR,
E_GLOBAL_ECO @ GLOBAL_ECO,
E_NUKE @ NUKE,
E_HUT_BARB @ HUT_BARB,
E_HUT_CITY @ HUT_CITY,
E_HUT_GOLD @ HUT_GOLD,
E_HUT_BARB_KILLED @ HUT_BARB_KILLED,
E_HUT_MERC @ HUT_MERC,
E_HUT_SETTLER @ HUT_SETTLER,
E_HUT_TECH @ HUT_TECH,
E_HUT_BARB_CITY_NEAR @ HUT_BARB_CITY_NEAR,
E_IMP_BUY @ IMP_BUY,
E_IMP_BUILD @ IMP_BUILD,
E_IMP_AUCTIONED @ IMP_AUCTIONED,
E_IMP_AUTO @ IMP_AUTO,
E_IMP_SOLD @ IMP_SOLD,
E_TECH_GAIN @ TECH_GAIN,
E_TECH_LEARNED @ TECH_LEARNED,
E_TREATY_ALLIANCE @ TREATY_ALLIANCE,
E_TREATY_BROKEN @ TREATY_BROKEN,
E_TREATY_CEASEFIRE @ TREATY_CEASEFIRE,
E_TREATY_PEACE @ TREATY_PEACE,
E_TREATY_SHARED_VISION @ TREATY_SHARED_VISION,
E_UNIT_LOST_ATT @ UNIT_LOST_ATT,
E_UNIT_WIN_ATT @ UNIT_WIN_ATT,
E_UNIT_BUY @ UNIT_BUY,
E_UNIT_BUILT @ UNIT_BUILT,
E_UNIT_LOST @ UNIT_LOST,
E_UNIT_WIN @ UNIT_WIN,
E_UNIT_BECAME_VET @ UNIT_BECAME_VET,
E_UNIT_UPGRADED @ UNIT_UPGRADED,
E_UNIT_RELOCATED @ UNIT_RELOCATED,
E_UNIT_ORDERS @ UNIT_ORDERS,
E_WONDER_BUILD @ WONDER_BUILD,
E_WONDER_OBSOLETE @ WONDER_OBSOLETE,
E_WONDER_STARTED @ WONDER_STARTED,
E_WONDER_STOPPED @ WONDER_STOPPED,
E_WONDER_WILL_BE_BUILT @ WONDER_WILL_BE_BUILT,
E_DIPLOMACY @ DIPLOMACY,
E_TREATY_EMBASSY @ TREATY_EMBASSY,
E_BAD_COMMAND @ BAD_COMMAND,
E_SETTING @ SETTING,
E_CHAT_MSG @ CHAT_MSG,
E_CHAT_ERROR @ CHAT_ERROR,
/*
* Note: If you add a new event, make sure you make a similar change
* to the events array in common/events.c using GEN_EV and to
* data/stdsounds.soundspec.
*/
E_LAST @ LAST
};
}
$[
-- Notify module implementation.
function notify.all(...)
notify.event_msg(nil, nil, E.NOEVENT, string.format(unpack(arg)))
end
function notify.player(player, ...)
notify.event_msg(player, nil, E.NOEVENT, string.format(unpack(arg)))
end
function notify.event(player, tile, event, ...)
notify.event_msg(player, tile, event, string.format(unpack(arg)))
end
function notify.embassies(player, ptile, event, ...)
notify.embassies_msg(player, ptile, event, string.format(unpack(arg)))
end
$]
/* Utilities module. */
int api_utilities_random @ random (int min, int max);
/* Actions module. */
Unit *api_actions_create_unit @ create_unit (Player *pplayer, Tile *ptile,
Unit_Type *ptype,
int veteran_level,
City *homecity, int moves_left);
void api_actions_create_city @ create_city (Player *pplayer, Tile *ptile,
const char *name);
void api_actions_change_gold @ change_gold (Player *pplayer, int amount);
bool api_actions_give_technology @ give_technology (Player *pplayer,
Tech_Type *ptech);
|