2010-08-08 09:40:42 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include "spells/shipcurse.h"
|
|
|
|
|
2012-06-05 06:45:25 +02:00
|
|
|
#include <kernel/equipment.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/race.h>
|
2010-08-08 09:40:42 +02:00
|
|
|
#include <kernel/ship.h>
|
2012-05-26 17:19:30 +02:00
|
|
|
#include <kernel/spellbook.h>
|
2010-08-08 09:40:42 +02:00
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
2012-06-05 06:45:25 +02:00
|
|
|
#include <quicklist.h>
|
2011-02-26 09:30:54 +01:00
|
|
|
|
2010-08-08 09:40:42 +02:00
|
|
|
#include <tolua.h>
|
2014-03-15 19:29:11 +01:00
|
|
|
#include <stdlib.h>
|
2010-08-08 09:40:42 +02:00
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
static int tolua_levitate_ship(lua_State * L)
|
2010-08-08 09:40:42 +02:00
|
|
|
{
|
2011-03-07 08:03:10 +01:00
|
|
|
ship *sh = (ship *) tolua_tousertype(L, 1, 0);
|
|
|
|
unit *mage = (unit *) tolua_tousertype(L, 2, 0);
|
2013-12-31 10:06:28 +01:00
|
|
|
float power = (float)tolua_tonumber(L, 3, 0);
|
2010-08-08 09:40:42 +02:00
|
|
|
int duration = (int)tolua_tonumber(L, 4, 0);
|
|
|
|
int cno = levitate_ship(sh, mage, power, duration);
|
2011-03-07 08:03:10 +01:00
|
|
|
tolua_pushnumber(L, (lua_Number) cno);
|
2010-08-08 09:40:42 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void spawn_undead(void);
|
|
|
|
extern void spawn_dragons(void);
|
2011-03-07 08:03:10 +01:00
|
|
|
extern void plan_monsters(struct faction *f);
|
2010-08-08 09:40:42 +02:00
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
static int tolua_planmonsters(lua_State * L)
|
2010-08-08 09:40:42 +02:00
|
|
|
{
|
2011-03-07 08:03:10 +01:00
|
|
|
faction *f = (faction *) tolua_tousertype(L, 1, get_monsters());
|
2010-08-08 09:40:42 +02:00
|
|
|
if (f) {
|
|
|
|
plan_monsters(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
static int tolua_spawn_dragons(lua_State * L)
|
2010-08-08 09:40:42 +02:00
|
|
|
{
|
|
|
|
spawn_dragons();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
static int tolua_spawn_undead(lua_State * L)
|
2010-08-08 09:40:42 +02:00
|
|
|
{
|
|
|
|
spawn_undead();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:03:10 +01:00
|
|
|
static int fix_familiars(struct lua_State *L)
|
2010-08-08 09:40:42 +02:00
|
|
|
{
|
2011-03-07 08:03:10 +01:00
|
|
|
faction *f;
|
|
|
|
for (f = factions; f; f = f->next) {
|
|
|
|
unit *u;
|
|
|
|
for (u = f->units; u; u = u->nextF) {
|
|
|
|
struct sc_mage *mage = get_mage(u);
|
2010-08-08 09:40:42 +02:00
|
|
|
if (mage && is_familiar(u)) {
|
2012-05-26 17:19:30 +02:00
|
|
|
if (mage->spellbook && mage->magietyp == M_GRAY) {
|
2011-03-07 08:03:10 +01:00
|
|
|
equipment *eq;
|
2010-08-08 09:40:42 +02:00
|
|
|
char buffer[64];
|
|
|
|
|
2012-05-26 17:19:30 +02:00
|
|
|
spellbook_clear(mage->spellbook);
|
|
|
|
free(mage->spellbook);
|
|
|
|
mage->spellbook = 0;
|
2010-08-08 09:40:42 +02:00
|
|
|
|
2014-08-24 21:49:55 +02:00
|
|
|
_snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name);
|
2010-08-08 09:40:42 +02:00
|
|
|
eq = get_equipment(buffer);
|
|
|
|
if (eq) {
|
|
|
|
equip_unit_mask(u, eq, EQUIP_SPELLS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-18 05:45:00 +01:00
|
|
|
void bind_monsters(struct lua_State *L)
|
2010-08-08 09:40:42 +02:00
|
|
|
{
|
|
|
|
tolua_module(L, NULL, 0);
|
|
|
|
tolua_beginmodule(L, NULL);
|
|
|
|
{
|
|
|
|
tolua_function(L, TOLUA_CAST "levitate_ship", tolua_levitate_ship);
|
|
|
|
tolua_function(L, TOLUA_CAST "plan_monsters", tolua_planmonsters);
|
|
|
|
tolua_function(L, TOLUA_CAST "spawn_undead", tolua_spawn_undead);
|
|
|
|
tolua_function(L, TOLUA_CAST "spawn_dragons", tolua_spawn_dragons);
|
|
|
|
tolua_function(L, TOLUA_CAST "fix_familiars", &fix_familiars);
|
|
|
|
}
|
|
|
|
tolua_endmodule(L);
|
|
|
|
}
|