diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index 5cd7e9884..109ece8aa 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -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 && idata; 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 diff --git a/src/eressea/tolua/helpers.c b/src/eressea/tolua/helpers.c index 4c3c20a25..91c472ad2 100644 --- a/src/eressea/tolua/helpers.c +++ b/src/eressea/tolua/helpers.c @@ -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&&ipar->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)); diff --git a/src/scripts/eressea/alp.lua b/src/scripts/eressea/alp.lua new file mode 100644 index 000000000..7c28869ac --- /dev/null +++ b/src/scripts/eressea/alp.lua @@ -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 diff --git a/src/scripts/eressea/modules.lua b/src/scripts/eressea/modules.lua index 9fe92afce..2a212dc38 100644 --- a/src/scripts/eressea/modules.lua +++ b/src/scripts/eressea/modules.lua @@ -1,4 +1,5 @@ require "gates" +require "eressea.alp" require "eressea.eternath" require "eressea.wedding-jadee" require "eressea.ponnuki" diff --git a/src/scripts/tests/common.lua b/src/scripts/tests/common.lua index b9d94d9e1..cc91c45f3 100644 --- a/src/scripts/tests/common.lua +++ b/src/scripts/tests/common.lua @@ -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 diff --git a/src/scripts/tests/e3a.lua b/src/scripts/tests/e3a.lua index 28872b72d..e51962278 100644 --- a/src/scripts/tests/e3a.lua +++ b/src/scripts/tests/e3a.lua @@ -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") diff --git a/src/scripts/tests/eressea.lua b/src/scripts/tests/eressea.lua index 276042eac..a9151465e 100644 --- a/src/scripts/tests/eressea.lua +++ b/src/scripts/tests/eressea.lua @@ -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")