forked from github/server
we can now pass extra spell parameters to a lua spell.
This commit is contained in:
parent
cf481970e8
commit
efeeba13c2
8 changed files with 103 additions and 29 deletions
|
@ -1690,7 +1690,7 @@ verify_targets(castorder *co, int * invalid, int * resist, int * success)
|
|||
*resist = 0;
|
||||
*success = 0;
|
||||
|
||||
if (sa) {
|
||||
if (sa && sa->length) {
|
||||
/* zuerst versuchen wir vorher nicht gefundene Objekte zu finden.
|
||||
* Wurde ein Objekt durch globalsuche gefunden, obwohl der Zauber
|
||||
* gar nicht global hätte suchen dürften, setzen wir das Objekt
|
||||
|
@ -1994,7 +1994,7 @@ add_spellparameter(region *target_r, unit *u, const char *syntax, const char * c
|
|||
|
||||
/* mindestens ein Ziel (Ziellose Zauber werden nicht
|
||||
* geparst) */
|
||||
if (size==0) {
|
||||
if (minlen && size==0) {
|
||||
/* Fehler: Ziel vergessen */
|
||||
cmistake(u, ord, 203, MSG_MAGIC);
|
||||
return 0;
|
||||
|
@ -2002,6 +2002,10 @@ add_spellparameter(region *target_r, unit *u, const char *syntax, const char * c
|
|||
|
||||
par = malloc(sizeof(spellparameter));
|
||||
par->length = size;
|
||||
if (!size) {
|
||||
par->param = NULL;
|
||||
return par;
|
||||
}
|
||||
par->param = malloc(size * sizeof(spllprm *));
|
||||
|
||||
while (!fail && *c && i<size && param[i]!=NULL) {
|
||||
|
|
|
@ -507,19 +507,22 @@ static void
|
|||
unit_addspell(unit * u, const char * name)
|
||||
{
|
||||
int add = 0;
|
||||
sc_mage * m = get_mage(u);
|
||||
spell_list * slist = spells;
|
||||
spell_list ** starget = NULL;
|
||||
spell * spadd = NULL;
|
||||
while (slist!=NULL) {
|
||||
spell * sp = slist->data;
|
||||
if (strcmp(name, sp->sname)==0) {
|
||||
starget = get_spelllist(get_mage(u), u->faction);
|
||||
if (add) log_error(("two spells are called %s.\n", name));
|
||||
add_spell(starget, sp);
|
||||
starget = get_spelllist(m, u->faction);
|
||||
if (m->magietyp==sp->magietyp) spadd = sp;
|
||||
else if (!spadd) spadd = sp;
|
||||
add = 1;
|
||||
}
|
||||
slist=slist->next;
|
||||
}
|
||||
if (!add) log_error(("spell %s could not be found\n", name));
|
||||
if (!spadd) log_error(("spell %s could not be found\n", name));
|
||||
else add_spell(starget, spadd);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -169,6 +169,18 @@ lc_age(struct attrib * a)
|
|||
return (result!=0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
static void push_param(lua_State * L, char c, spllprm * param)
|
||||
{
|
||||
if (c=='u') tolua_pushusertype(L, param->data.u, "unit");
|
||||
else if (c=='b') tolua_pushusertype(L, param->data.b, "building");
|
||||
else if (c=='s') tolua_pushusertype(L, param->data.sh, "ship");
|
||||
else if (c=='r') tolua_pushusertype(L, param->data.sh, "region");
|
||||
else if (c=='c') tolua_pushstring(L, param->data.s);
|
||||
else {
|
||||
log_error(("unsupported syntax %c.\n", c));
|
||||
lua_pushnil(L);
|
||||
}
|
||||
}
|
||||
|
||||
/** callback to use lua for spell functions */
|
||||
static int
|
||||
|
@ -192,12 +204,30 @@ lua_callspell(castorder *co)
|
|||
lua_pushstring(L, fname);
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_isfunction(L, 1)) {
|
||||
int nparam = 4;
|
||||
tolua_pushusertype(L, co->rt, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, mage, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number)co->level);
|
||||
tolua_pushnumber(L, (lua_Number)co->force);
|
||||
if (co->sp->parameter && co->par->length) {
|
||||
const char * synp = co->sp->parameter;
|
||||
int i = 0;
|
||||
++nparam;
|
||||
lua_newtable(L);
|
||||
while (*synp&&i<co->par->length) {
|
||||
spllprm * param = co->par->param[i];
|
||||
char c = *synp;
|
||||
if (c=='+') {
|
||||
push_param(L, *(synp-1), param);
|
||||
} else {
|
||||
push_param(L, c, param);
|
||||
++synp;
|
||||
}
|
||||
lua_rawseti(L, -2, ++i);
|
||||
}
|
||||
}
|
||||
|
||||
if (lua_pcall(L, 4, 1, 0)!=0) {
|
||||
if (lua_pcall(L, nparam, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("spell(%s) calling '%s': %s.\n",
|
||||
unitname(mage), fname, error));
|
||||
|
|
21
src/scripts/eressea/alp.lua
Normal file
21
src/scripts/eressea/alp.lua
Normal file
|
@ -0,0 +1,21 @@
|
|||
function summon_alp(r, mage, level, force, params)
|
||||
local alp = unit.create(mage.faction, r, 1, "alp")
|
||||
local target = params[1]
|
||||
alp:set_skill("stealth", 7)
|
||||
alp.status = 5 -- FLEE
|
||||
a = attrib.create(alp, { type='alp', target=target })
|
||||
|
||||
|
||||
{
|
||||
/* Wenn der Alp stirbt, den Magier nachrichtigen */
|
||||
add_trigger(&alp->attribs, "destroy", trigger_unitmessage(mage,
|
||||
"trigger_alp_destroy", MSG_EVENT, ML_INFO));
|
||||
/* Wenn Opfer oder Magier nicht mehr existieren, dann stirbt der Alp */
|
||||
add_trigger(&mage->attribs, "destroy", trigger_killunit(alp));
|
||||
add_trigger(&opfer->attribs, "destroy", trigger_killunit(alp));
|
||||
}
|
||||
msg = msg_message("summon_alp_effect", "mage alp target", mage, alp, opfer);
|
||||
r_addmessage(r, mage->faction, msg);
|
||||
msg_release(msg);
|
||||
|
||||
end
|
|
@ -1,4 +1,5 @@
|
|||
require "gates"
|
||||
require "eressea.alp"
|
||||
require "eressea.eternath"
|
||||
require "eressea.wedding-jadee"
|
||||
require "eressea.ponnuki"
|
||||
|
|
|
@ -360,7 +360,6 @@ function test_guard()
|
|||
b.size = 10
|
||||
u2.building = b
|
||||
u3.building = b
|
||||
update_owners()
|
||||
u2:clear_orders()
|
||||
u2:add_order("ATTACKIEREN " .. itoa36(u1.id)) -- you will die...
|
||||
u2:add_item("money", 100)
|
||||
|
@ -551,7 +550,6 @@ function test_control()
|
|||
local b = building.create(r, "castle")
|
||||
u1.building = b
|
||||
u2.building = b
|
||||
update_owners()
|
||||
assert_equal(u1, b.owner)
|
||||
u1:clear_orders()
|
||||
u1:add_order("GIB " .. itoa36(u2.id) .. " KOMMANDO")
|
||||
|
@ -600,7 +598,24 @@ function test_building_other()
|
|||
u2:add_item("stone", 100)
|
||||
u2:clear_orders()
|
||||
u2:add_order("MACHEN BURG " .. itoa36(b.id))
|
||||
update_owners()
|
||||
process_orders()
|
||||
assert_not_equal(10, b.size)
|
||||
end
|
||||
|
||||
function test_roi()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
u.race = "elf"
|
||||
u:set_skill("magic", 10)
|
||||
u:add_item("money", 3010)
|
||||
u.magic = "tybied"
|
||||
u.aura = 200
|
||||
u.ship = s1
|
||||
u:add_spell("create_roi")
|
||||
u:clear_orders()
|
||||
u:add_order("ZAUBERE 'Erschaffe einen Ring der Unsichtbarkeit' ")
|
||||
process_orders()
|
||||
write_reports()
|
||||
assert_equal(1, u:get_item("roi"))
|
||||
end
|
||||
|
|
|
@ -13,24 +13,6 @@ function has_attrib(u, value)
|
|||
return false
|
||||
end
|
||||
|
||||
function test_ror()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
u.race = "elf"
|
||||
u:set_skill("magic", 10)
|
||||
u:add_item("money", 3010)
|
||||
u.magic = "gwyrrd"
|
||||
u.aura = 200
|
||||
u.ship = s1
|
||||
u:add_spell("create_roi")
|
||||
u:clear_orders()
|
||||
u:add_order("ZAUBERE 'Erschaffe einen Ring der Unsichtbarkeit'")
|
||||
process_orders()
|
||||
write_reports()
|
||||
assert_equal(1, u:get_item("roi"))
|
||||
end
|
||||
|
||||
function test_attrib()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
|
|
|
@ -6,6 +6,25 @@ function setup()
|
|||
free_game()
|
||||
end
|
||||
|
||||
function DISABLE_test_alp()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
local u2 = unit.create(f, r, 1)
|
||||
u.race = "elf"
|
||||
u:set_skill("magic", 10)
|
||||
u:add_item("money", 3010)
|
||||
u.magic = "illaun"
|
||||
u.aura = 200
|
||||
u.ship = s1
|
||||
u:add_spell("summon_alp")
|
||||
u:clear_orders()
|
||||
u:add_order("ZAUBERE 'Alp' " .. itoa36(u2.id))
|
||||
process_orders()
|
||||
print(get_turn(), f)
|
||||
write_reports()
|
||||
end
|
||||
|
||||
function test_unit_limit_is_1500()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
|
@ -51,7 +70,6 @@ function test_ship_capacity()
|
|||
u4:clear_orders()
|
||||
u4:add_order("NACH O O")
|
||||
|
||||
update_owners()
|
||||
process_orders()
|
||||
-- print(s.region, u.region, r2)
|
||||
assert_equal(r2.id, u1.region.id, "boat with 5 humans did not move")
|
||||
|
|
Loading…
Reference in a new issue