diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index 0101c2518..1538b4249 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -5,25 +5,117 @@ module("tests.spells", package.seeall, lunit.testcase) function setup() free_game() settings.set("magic.fumble.enable", "0") + settings.set("magic.regeneration.enable", "0") + settings.set("rules.economy.food", "0") end -function test_roi() +function test_create_firesword() local r = region.create(0,0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("create_firesword@eressea.de", "human", "de") local u = unit.create(f, r, 1) - u.race = "elf" - u:set_skill("magic", 10) - u:add_item("money", 3010) - f.magic = "gwyrrd" - u.magic = "gwyrrd" - u.aura = 200 - u.ship = s1 + u:set_skill("magic", 12) + u:add_spell("create_firesword") --- local err = u:add_spell("create_roi") --- assert_equal(0, err) - u:clear_orders() - u:add_order("ZAUBERE 'Erschaffe einen Ring der Unsichtbarkeit' ") - process_orders() - write_reports() + u:cast_spell('create_firesword', 1) + assert_equal(1, u:get_item("firesword")) +end + +function test_create_roi() + local r = region.create(0,0, "plain") + local f = faction.create("create_roi@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_roi') assert_equal(1, u:get_item("roi")) end + +function test_create_roqf() + local r = region.create(0,0, "plain") + local f = faction.create("create_roqf@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_roqf') + assert_equal(1, u:get_item("roqf")) +end + +function test_create_aots() + local r = region.create(0,0, "plain") + local f = faction.create("create_aots@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_aots') + assert_equal(1, u:get_item("aots")) +end + +function test_create_ror() + local r = region.create(0,0, "plain") + local f = faction.create("create_ror@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_ror') + assert_equal(1, u:get_item("ror")) +end + +function test_create_magicherbbag() + local r = region.create(0,0, "plain") + local f = faction.create("create_magicherbbag@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_magicherbbag') + assert_equal(1, u:get_item("magicherbbag")) +end + +function test_create_trollbelt() + local r = region.create(0,0, "plain") + local f = faction.create("create_trollbelt@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_trollbelt') + assert_equal(1, u:get_item("trollbelt")) +end + +function test_create_dreameye() + local r = region.create(0,0, "plain") + local f = faction.create("create_dreameye@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_dreameye') + assert_equal(1, u:get_item("dreameye")) +end + +function test_create_antimagic() + local r = region.create(0,0, "plain") + local f = faction.create("create_antimagic@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_antimagic') + assert_equal(1, u:get_item("antimagic")) +end + +function test_create_runesword() + local r = region.create(0,0, "plain") + local f = faction.create("create_runesword@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_runesword') + assert_equal(1, u:get_item("runesword")) +end + +function test_create_rop() + local r = region.create(0,0, "plain") + local f = faction.create("create_rop@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:set_skill("magic", 10) + + u:cast_spell('create_rop') + assert_equal(1, u:get_item("rop")) +end diff --git a/src/bindings/bindings.c b/src/bindings/bindings.c index f633f7716..228b94ada 100644 --- a/src/bindings/bindings.c +++ b/src/bindings/bindings.c @@ -1070,7 +1070,7 @@ static int tolua_eventbus_register(lua_State * L) { void *sender = tolua_tousertype(L, 1, 0); const char *event = tolua_tostring(L, 2, 0); - event_args *args = malloc(sizeof(event_args)); + event_args *args = (event_args *)malloc(sizeof(event_args)); args->sendertype = sender ? tolua_typename(L, 1) : NULL; lua_pushvalue(L, 3); args->hfunction = luaL_ref(L, LUA_REGISTRYINDEX); @@ -1259,10 +1259,8 @@ int tolua_eressea_open(lua_State * L) tolua_function(L, TOLUA_CAST "itoa36", tolua_itoa36); tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand); tolua_function(L, TOLUA_CAST "get_nmrs", tolua_get_nmrs); - tolua_function(L, TOLUA_CAST "remove_empty_units", - tolua_remove_empty_units); - tolua_function(L, TOLUA_CAST "update_subscriptions", - tolua_update_subscriptions); + tolua_function(L, TOLUA_CAST "remove_empty_units", tolua_remove_empty_units); + tolua_function(L, TOLUA_CAST "update_subscriptions", tolua_update_subscriptions); tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores); tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners); tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill); diff --git a/src/bindings/helpers.c b/src/bindings/helpers.c index 28ee984da..dec73f5f8 100644 --- a/src/bindings/helpers.c +++ b/src/bindings/helpers.c @@ -203,7 +203,7 @@ static int lua_callspell(castorder * co) lua_pushstring(L, fname); lua_rawget(L, LUA_GLOBALSINDEX); - if (lua_isfunction(L, 1)) { + if (lua_isfunction(L, -1)) { int nparam = 4; tolua_pushusertype(L, r, TOLUA_CAST "region"); tolua_pushusertype(L, caster, TOLUA_CAST "unit"); @@ -236,7 +236,8 @@ static int lua_callspell(castorder * co) lua_pop(L, 1); } } else { - log_error("spell(%s) calling '%s': not a function.\n", unitname(caster), fname); + int ltype = lua_type(L, -1); + log_error("spell(%s) calling '%s': not a function, has type %d.\n", unitname(caster), fname, ltype); lua_pop(L, 1); } diff --git a/src/kernel/magic.c b/src/kernel/magic.c index 783ef5cad..581ef4988 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -1452,6 +1452,9 @@ void regeneration_magiepunkte(void) double reg_aura; int regen; double mod; + int regen_enabled = get_param_int(global.parameters, "magic.regeneration.enable", 1); + + if (!regen_enabled) return; for (r = regions; r; r = r->next) { for (u = r->units; u; u = u->next) {