/
tolua_server.pkg
567 lines (492 loc) · 19.1 KB
/
tolua_server.pkg
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
/*****************************************************************************
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.
*****************************************************************************/
/*****************************************************************************
ADVERTISEMENT: do not attempt to change the name of the API functions.
They may be in use in Lua scripts in savefiles, so once released, the
name and signature cannot change shape even in new major versions of
Freeciv, until the relevant save format version can no longer be loaded.
If you really like to change a function name, be sure to keep also the
old one running.
*****************************************************************************/
$#ifdef HAVE_CONFIG_H
$#include <fc_config.h>
$#endif
/* common/scriptcore */
$#include "luascript_types.h"
/* server */
$#include "commands.h"
$#include "console.h"
/* server/scripting */
$#include "api_server_edit.h"
$#include "api_server_base.h"
$#include "api_server_counters.h"
$#include "api_server_luadata.h"
$#include "api_server_notify.h"
$#include "api_server_game_methods.h"
$#include "script_server.h"
/* Server module. */
module server {
bool api_server_save
@ save (lua_State *L, const char *filename);
bool api_server_was_started
@ started (lua_State *L);
int api_server_player_civilization_score
@ civilization_score (lua_State *L, Player *pplayer);
bool api_play_music
@ play_music (lua_State *L, Player *pplayer, const char *tag);
module setting {
const char *api_server_setting_get
@ get (lua_State *L, const char *setting_name);
}
}
module Counter {
void api_counter_increase @ increase (lua_State *L, Counter *c, City *city);
void api_counter_zero @ zero (lua_State *L, Counter *c, City *city);
}
/* Notify module. */
module notify {
void api_notify_embassies_msg
@ embassies_msg (lua_State *L, Player *pplayer, Tile *ptile, int event,
const char *message);
void api_notify_research_msg
@ research_msg (lua_State *L, Player *pplayer, bool include_plr,
int event, const char *message);
void api_notify_research_embassies_msg
@ research_embassies_msg (lua_State *L, Player *pplayer, int event,
const char *message);
void api_notify_event_msg
@ event_msg (lua_State *L, Player *pplayer, Tile *ptile, int event,
const char *message);
}
$[
-- Notify module implementation.
function notify.all(...)
local arg = table.pack(...);
notify.event_msg(nil, nil, E.SCRIPT, string.format(table.unpack(arg)))
end
function notify.player(player, ...)
local arg = table.pack(...);
notify.event_msg(player, nil, E.SCRIPT, string.format(table.unpack(arg)))
end
function notify.event(player, tile, event, ...)
local arg = table.pack(...);
notify.event_msg(player, tile, event, string.format(table.unpack(arg)))
end
function notify.embassies(player, ptile, event, ...)
local arg = table.pack(...);
notify.embassies_msg(player, ptile, event, string.format(table.unpack(arg)))
end
function notify.research(player, selfmsg, event, ...)
local arg = table.pack(...);
notify.research_msg(player, selfmsg, event, string.format(table.unpack(arg)))
end
function notify.research_embassies(player, event, ...)
local arg = table.pack(...);
notify.research_embassies_msg(player, event, string.format(table.unpack(arg)))
end
$]
/* Edit module. */
module edit {
Unit *api_edit_create_unit
@ create_unit (lua_State *L, Player *pplayer, Tile *ptile,
Unit_Type *ptype, int veteran_level, City *homecity,
int moves_left);
Unit *api_edit_create_unit_full
@ create_unit_full (lua_State *L, Player *pplayer, Tile *ptile,
Unit_Type *ptype, int veteran_level, City *homecity,
int moves_left, int hp_left, Unit *ptransport);
bool api_edit_unit_teleport
@ unit_teleport(lua_State *L, Unit *self, Tile *dest,
Unit *embark_to, bool allow_disembark,
bool conquer_city, bool conquer_extra,
bool enter_hut, bool frighten_hut);
void api_edit_unit_kill
@ unit_kill(lua_State *L, Unit *self, const char *reason,
Player *killer);
bool api_edit_change_terrain
@ change_terrain(lua_State *L, Tile *ptile, Terrain *pterr);
bool api_edit_create_city
@ create_city (lua_State *L, Player *pplayer, Tile *ptile,
const char *name);
bool api_edit_transfer_city
@ transfer_city (lua_State *L, City *pcity, Player *new_owner);
void api_edit_remove_city
@ remove_city (lua_State *L, City *pcity);
void api_edit_create_building
@ create_building (lua_State *L, City *pcity, Building_Type *impr);
void api_edit_remove_building
@ remove_building (lua_State *L, City *pcity, Building_Type *impr);
void api_edit_create_owned_extra
@ create_owned_extra (lua_State *L, Tile *ptile,
const char *name, Player *pplayer);
void api_edit_create_extra
@ create_extra (lua_State *L, Tile *ptile, const char *name);
/* Deprecated; use edit.create_owned_extra() */
void api_edit_create_base
@ create_base (lua_State *L, Tile *ptile, const char *name,
Player *pplayer);
/* Deprecated; use edit.create_extra() */
void api_edit_create_road
@ create_road (lua_State *L, Tile *ptile, const char *name);
void api_edit_remove_extra
@ remove_extra (lua_State *L, Tile *ptile, const char *name);
void api_edit_tile_set_label
@ tile_set_label (lua_State *L, Tile *ptile, const char *label);
void api_edit_tile_show
@ tile_show (lua_State *L, Tile *ptile, Player *pplayer);
bool api_edit_tile_hide
@ tile_hide (lua_State *L, Tile *ptile, Player *pplayer);
Player *api_edit_create_player
@ create_player(lua_State *L, const char *username, Nation_Type *nation,
const char *ai);
void api_edit_change_gold
@ change_gold (lua_State *L, Player *pplayer, int amount);
void api_edit_change_infrapoints
@ change_infrapoints (lua_State *L, Player *pplayer, int amount);
/* cost:
* 0 or above - The exact cost % to apply
* -1 - Apply freecost
* -2 - Apply conquercost
* -3 - Apply diplbulbcost */
Tech_Type *api_edit_give_technology
@ give_tech (lua_State *L, Player *pplayer, Tech_Type *ptech,
int cost, bool notify, const char *reason);
bool api_edit_trait_mod_set
@ trait_mod (lua_State *L, Player *pplayer, const char *tname,
const int mod);
bool api_edit_unleash_barbarians
@ unleash_barbarians (lua_State *L, Tile *ptile);
void api_edit_place_partisans
@ place_partisans (lua_State *L, Tile *ptile, Player *pplayer, int count,
int sq_radius);
enum climate_change_type {
CLIMATE_CHANGE_GLOBAL_WARMING @ GLOBAL_WARMING,
CLIMATE_CHANGE_NUCLEAR_WINTER @ NUCLEAR_WINTER
};
void api_edit_climate_change
@ climate_change (lua_State *L, enum climate_change_type type,
int effect);
Player *api_edit_civil_war
@ civil_war(lua_State *L, Player *pplayer, int probability);
void api_edit_unit_turn
@ unit_turn(lua_State *L, Unit *punit, Direction dir);
void api_edit_player_victory
@ player_victory (lua_State *L, Player *self);
bool api_edit_unit_move
@ unit_move(lua_State *L, Unit *self, Tile *moveto, int movecost,
Unit *embark_to, bool allow_disembark,
bool conquer_city, bool conquer_extra,
bool enter_hut, bool frighten_hut);
void api_edit_unit_moving_disallow
@ movement_disallow(lua_State *L, Unit *self);
void api_edit_unit_moving_allow
@ movement_allow(lua_State *L, Unit *self);
bool api_edit_perform_action_unit_vs_city
@ perform_action(lua_State *L, Unit *punit, Action *paction,
City *tgt);
bool api_edit_perform_action_unit_vs_city_impr
@ perform_action(lua_State *L, Unit *punit, Action *paction,
City *tgt, Building_Type *sub_tgt);
bool api_edit_perform_action_unit_vs_city_tech
@ perform_action(lua_State *L, Unit *punit, Action *paction,
City *tgt, Tech_Type *sub_tgt);
bool api_edit_perform_action_unit_vs_unit
@ perform_action(lua_State *L, Unit *punit, Action *paction,
Unit *tgt);
bool api_edit_perform_action_unit_vs_tile
@ perform_action(lua_State *L, Unit *punit, Action *paction,
Tile *tgt);
bool api_edit_perform_action_unit_vs_tile_extra
@ perform_action(lua_State *L, Unit *punit, Action *paction,
Tile *tgt, const char *sub_tgt);
bool api_edit_perform_action_unit_vs_self
@ perform_action(lua_State *L, Unit *punit, Action *paction);
void api_edit_city_add_history
@ add_city_history(lua_State *L, City *self, int amount);
void api_edit_player_add_history
@ add_player_history(lua_State *L, Player *self, int amount);
void api_edit_player_give_bulbs
@ give_bulbs(lua_State *L, Player *self, int amount,
Tech_Type *tech = NULL);
}
/* Luadata module. */
module luadata {
const char *api_luadata_get_str
@ get_str(lua_State *L, const char *field);
}
$[
-- Compatibility functions
-- These top-level functions were exposed prior to Freeciv 2.4. Since then
-- we prefer use of edit.*. Do not add new functions to this section.
function create_unit(player, tile, utype, veteran_level, homecity, moves_left)
log.deprecation_warning("create_unit()", "edit.create_unit()",
"2.4");
return edit.create_unit(player, tile, utype, veteran_level, homecity,
moves_left)
end
function create_unit_full(player, tile, utype, veteran_level, homecity,
moves_left, hp_left, transport)
log.deprecation_warning("create_unit_full()", "edit.create_unit_full()",
"2.4");
return edit.create_unit_full(player, tile, utype, veteran_level, homecity,
moves_left, hp_left, transport)
end
function create_city(player, tile, name)
log.deprecation_warning("create_city()", "edit.create_city()",
"2.4");
edit.create_city (player, tile, name)
end
-- Deprecated; use edit.create_owned_extra()
function create_base(tile, name, player)
-- Out-of-namespace since 2.4
-- edit.create_base() -> edit.create_owned_extra() since 3.0
log.deprecation_warning("create_base()", "edit.create_owned_extra()",
"2.4");
edit.create_base(tile, name, player)
end
function create_player(username, nation)
log.deprecation_warning("create_player()", "edit.create_player()",
"2.4");
return edit.create_player(username, nation, nil)
end
function change_gold(pplayer, amount)
log.deprecation_warning("change_gold()", "edit.change_gold()",
"2.4");
edit.change_gold(pplayer, amount)
end
-- Deprecated; use edit.give_tech()
function give_technology(player, tech, reason)
log.deprecation_warning("give_technology()", "edit.give_tech()",
"2.4");
return edit.give_tech(player, tech, -1, false, reason)
end
-- Deprecated; use edit.give_tech()
function edit.give_technology(player, tech, reason)
log.deprecation_warning("edit.give_technology()", "edit.give_tech()",
"2.6");
return edit.give_tech(player, tech, -1, false, reason)
end
function trait_mod(player, trait, mod)
log.deprecation_warning("trait_mod()", "edit.trait_mod()",
"2.4");
return edit.trait_mod(player, trait, mod)
end
function unleash_barbarians(tile)
log.deprecation_warning("unleash_barbarians()", "edit.unleash_barbarians()",
"2.4");
return edit.unleash_barbarians(tile)
end
function place_partisans(tile, player, count, sq_radius)
log.deprecation_warning("place_partisans()", "edit.place_partisans()",
"2.4");
edit.place_partisans(tile, player, count, sq_radius)
end
-- Server functions for Player module
function Player:create_unit(tile, utype, veteran_level, homecity, moves_left)
return edit.create_unit(self, tile, utype, veteran_level, homecity,
moves_left)
end
function Player:create_unit_full(tile, utype, veteran_level, homecity,
moves_left, hp_left, ptransport)
return edit.create_unit_full(self, tile, utype, veteran_level, homecity,
moves_left, hp_left, ptransport)
end
function Player:civilization_score()
return server.civilization_score(self)
end
function Player:create_city(tile, name)
edit.create_city(self, tile, name)
end
function Player:change_gold(amount)
edit.change_gold(self, amount)
end
function Player:change_infrapoints(amount)
edit.change_infrapoints(self, amount)
end
function Player:give_tech(tech, cost, notify, reason)
return edit.give_tech(self, tech, cost, notify, reason)
end
-- Deprecated; use Player:give_tech()
function Player:give_technology(tech, reason)
log.deprecation_warning("Player:give_technology()", "Player:give_tech()",
"2.6");
return edit.give_tech(self, tech, -1, false, reason)
end
function Player:trait_mod(trait, mod)
return edit.trait_mod(self, trait, mod)
end
function Player:civil_war(probability)
return edit.civil_war(self, probability)
end
function Player:victory()
edit.player_victory(self)
end
function Player:add_history(amount)
edit.add_player_history(self, amount)
end
function Player:give_bulbs(amount, tech)
edit.give_bulbs(self, amount, tech)
end
-- Server functions for City module
function City:remove()
edit.remove_city(self)
end
function City:transfer(new_owner)
edit.transfer_city(self, new_owner)
end
function City:add_history(amount)
edit.add_city_history(self, amount)
end
function City:create_building(impr)
edit.create_building(self, impr)
end
function City:remove_building(impr)
edit.remove_building(self, impr)
end
-- Server functions for Unit module
function Unit:teleport(dest,
embark_to, allow_disembark,
conquer_city, conquer_extra,
enter_hut, frighten_hut)
if allow_disembark == nil then
return edit.unit_teleport(self, dest, nil, false,
false, false, false, false)
else
return edit.unit_teleport(self, dest,
embark_to, allow_disembark,
conquer_city, conquer_extra,
enter_hut, frighten_hut)
end
end
function Unit:perform_action(action, target, sub_target)
if target == nil then
return edit.perform_action(self, action)
elseif sub_target == nil then
return edit.perform_action(self, action, target)
else
return edit.perform_action(self, action, target, sub_target)
end
end
function Unit:turn(direction)
edit.unit_turn(self, direction)
end
function Unit:kill(reason, killer)
edit.unit_kill(self, reason, killer)
end
function Unit:move(moveto, movecost,
embark_to, allow_disembark,
conquer_city, conquer_extra,
enter_hut, frighten_hut)
if allow_disembark == nil then
return edit.unit_move(self, moveto, movecost, nil, false,
false, false, false, false)
else
return edit.unit_move(self, moveto, movecost,
embark_to, allow_disembark,
conquer_city, conquer_extra,
enter_hut, frighten_hut)
end
end
function Unit:movement_disallow()
edit.movement_disallow(self)
end
function Unit:movement_allow()
edit.movement_allow(self)
end
-- Server functions for Tile module
function Tile:create_owned_extra(name, player)
edit.create_owned_extra(self, name, player)
end
function Tile:create_extra(name)
edit.create_extra(self, name)
end
-- Deprecated; use Tile:create_extra()
function Tile:create_base(name, player)
log.deprecation_warning("Tile:create_base()", "Tile:create_owned_extra()",
"3.0");
edit.create_base(self, name, player)
end
-- Deprecated; use Tile:create_extra()
function Tile:create_road(name)
log.deprecation_warning("Tile:create_road()", "Tile:create_extra()",
"2.6");
edit.create_road(self, name)
end
function Tile:remove_extra(name)
edit.remove_extra(self, name)
end
function Tile:change_terrain(terrain)
edit.change_terrain(self, terrain)
end
function Tile:unleash_barbarians()
return edit.unleash_barbarians(self)
end
function Tile:place_partisans(player, count, sq_radius)
edit.place_partisans(self, player, count, sq_radius)
end
function Tile:set_label(label)
edit.tile_set_label(self, label)
end
function Tile:show(player)
edit.tile_show(self, player)
end
function Tile:hide(player)
return edit.tile_hide(self, player)
end
$]
/* Additions to common Player module. */
module Player {
module properties {
int api_methods_player_free_bulbs
@ free_bulbs (lua_State *L, Player *pplayer);
}
int api_methods_player_trait
@ trait (lua_State *L, Player *pplayer, const char *tname);
int api_methods_player_trait_base
@ trait_base (lua_State *L, Player *pplayer, const char *tname);
int api_methods_player_trait_current_mod
@ trait_current_mod (lua_State *L, Player *pplayer, const char *tname);
void api_methods_player_lose
@ lose (lua_State *L, Player *pplayer, Player *looter = NULL);
int api_methods_player_tech_bulbs
@ bulbs_saved (lua_State *L, Player *pplayer, Tech_Type *tech);
}
$[
edit.player_lose = Player.lose
$]
/* server game parameters */
$#define game_server_autoupgrade_veteran_loss (game.server.autoupgrade_veteran_loss)
$#define game_server_upgrade_veteran_loss (game.server.upgrade_veteran_loss)
$#define game_server_multiresearch (game.server.multiresearch)
module game {
extern const int game_server_autoupgrade_veteran_loss @ autoupgrade_veteran_loss;
extern const int game_server_upgrade_veteran_loss @ upgrade_veteran_loss;
extern const bool game_server_multiresearch @ multiresearch;
}
/* Additions to common Nation_Type module. */
module Nation_Type {
int api_methods_nation_trait_min
@ trait_min (lua_State *L, Nation_Type *pnation, const char *tname);
int api_methods_nation_trait_max
@ trait_max (lua_State *L, Nation_Type *pnation, const char *tname);
int api_methods_nation_trait_default
@ trait_default (lua_State *L, Nation_Type *pnation,
const char *tname);
}
/* Additions to common Unit module. */
module Unit {
bool api_edit_unit_upgrade
@ upgrade (lua_State *L, Unit *punit, int vet_loss = 0);
bool api_edit_unit_transform
@ transform (lua_State *L, Unit *punit, Unit_Type *ptype,
int vet_loss = 0);
}