diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index bec715853..2f8085239 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -2,3 +2,4 @@ require 'tests.e2.shiplanding' require 'tests.e2.e2features' require 'tests.e2.movement' require 'tests.e2.guard' +require 'tests.e2.spells' diff --git a/scripts/tests/e2/spells.lua b/scripts/tests/e2/spells.lua new file mode 100644 index 000000000..2eb54c406 --- /dev/null +++ b/scripts/tests/e2/spells.lua @@ -0,0 +1,28 @@ +require "lunit" + +module("tests.e2.spells", package.seeall, lunit.testcase) + +function setup() + eressea.free_game() + eressea.settings.set("nmr.removenewbie", "0") + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("NewbieImmunity", "0") + eressea.settings.set("rules.economy.food", "4") +end + +function test_shapeshift() + local r = region.create(42, 0, "plain") + local f = faction.create("noreply@eressea.de", "demon", "de") + local u1 = unit.create(f, r, 1) + local u2 = unit.create(f, r, 1) + u1:clear_orders() + u1.magic = "gray" + u1:set_skill("magic", 2) + u1.aura = 1 + u1:add_spell("shapeshift") + u1:add_order("ZAUBERE STUFE 1 Gestaltwandlung " .. itoa36(u2.id) .. " Goblin") + process_orders() + assert_equal(f.race, u2.race) + s = u2:show() + assert_equal("1 Goblin", string.sub(s, string.find(s, "1 Goblin"))) +end diff --git a/src/battle.c b/src/battle.c index 1720e222a..c1a01257f 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1868,7 +1868,7 @@ static void do_extra_spell(troop at, const att * a) else { int level = a->level; assert(a->level > 0); - cast_combatspell(at, sp, level, level * MagicPower()); + cast_combatspell(at, sp, level, MagicPower((float)level)); } } diff --git a/src/bind_unit.c b/src/bind_unit.c index 5e06cab37..6c254f699 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -20,6 +20,7 @@ without prior permission by the authors of Eressea. #include "alchemy.h" #include "bindings.h" #include "move.h" +#include "reports.h" /* attributes includes */ #include @@ -57,6 +58,17 @@ without prior permission by the authors of Eressea. #include #include +static int tolua_bufunit(lua_State * L) { + char buf[8192]; + unit *self = (unit *)tolua_tousertype(L, 1, 0); + int mode = (int)tolua_tonumber(L, 2, see_unit); + if (!self) return 0; + + bufunit(self->faction, self, 0, mode, buf, sizeof(buf)); + tolua_pushstring(L, buf); + return 1; + +} static int tolua_unit_get_objects(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); @@ -533,7 +545,7 @@ static void unit_castspell(unit * u, const char *name, int level) } else { castorder co; - create_castorder(&co, u, 0, sp, u->region, level, level * MagicPower(), 0, 0, 0); + create_castorder(&co, u, 0, sp, u->region, level, MagicPower((float)level), 0, 0, 0); sp->cast(&co); free_castorder(&co); } @@ -1058,6 +1070,7 @@ void tolua_unit_open(lua_State * L) #ifdef BSON_ATTRIB tolua_variable(L, TOLUA_CAST "attribs", &tolua_unit_get_attribs, 0); #endif + tolua_function(L, TOLUA_CAST "show", &tolua_bufunit); } tolua_endmodule(L); } diff --git a/src/magic.c b/src/magic.c index 72fe72a25..c271fb85f 100644 --- a/src/magic.c +++ b/src/magic.c @@ -117,14 +117,17 @@ static float MagicRegeneration(void) return value; } -float MagicPower(void) +float MagicPower(float force) { static float value = -1.0; + if (force <= 0) { + return 0; + } if (value < 0) { const char *str = get_param(global.parameters, "magic.power"); value = str ? (float)atof(str) : 1.0f; } - return value; + return _max(value * force, 1.0f); } static int a_readicastle(attrib * a, void *owner, struct storage *store) @@ -1074,7 +1077,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order } } - force = force * MagicPower(); + force = MagicPower(force); return _max(force, 0); } diff --git a/src/magic.h b/src/magic.h index 1494b0170..eee7b86fe 100644 --- a/src/magic.h +++ b/src/magic.h @@ -360,7 +360,7 @@ extern "C" { extern void write_spells(struct quicklist *slist, struct storage *store); extern void read_spells(struct quicklist **slistp, magic_t mtype, struct storage *store); - extern float MagicPower(void); + float MagicPower(float force); extern struct spellbook * get_spellbook(const char * name); extern void free_spellbooks(void);