diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index ce45c49c6..763f67953 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -14,11 +14,12 @@ function test_roi() u.race = "elf" u:set_skill("magic", 10) u:add_item("money", 3010) + f.magic = "tybied" u.magic = "tybied" u.aura = 200 u.ship = s1 - local err = u:add_spell("create_roi") - assert_equal(0, err) +-- 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() diff --git a/src/bindings/bind_faction.c b/src/bindings/bind_faction.c index 97abfa521..665af06d6 100644 --- a/src/bindings/bind_faction.c +++ b/src/bindings/bind_faction.c @@ -117,6 +117,28 @@ static int tolua_faction_set_id(lua_State * L) return 1; } +static int tolua_faction_get_magic(lua_State * L) +{ + faction *self = (faction *) tolua_tousertype(L, 1, 0); + lua_pushstring(L, magic_school[self->magiegebiet]); + return 1; +} + +static int tolua_faction_set_magic(lua_State * L) +{ + faction *self = (faction *) tolua_tousertype(L, 1, 0); + const char *type = tolua_tostring(L, 2, 0); + magic_t mtype; + + for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) { + if (strcmp(magic_school[mtype], type) == 0) { + self->magiegebiet = mtype; + break; + } + } + return 0; +} + static int tolua_faction_get_age(lua_State * L) { faction *self = (faction *) tolua_tousertype(L, 1, 0); @@ -498,6 +520,8 @@ void tolua_faction_open(lua_State * L) tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance, tolua_faction_set_alliance); tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL); + tolua_variable(L, TOLUA_CAST "magic", &tolua_faction_get_magic, + tolua_faction_set_magic); tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age, tolua_faction_set_age); tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options, diff --git a/src/kernel/unit.c b/src/kernel/unit.c index d8ca679d8..f4b58fd59 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1745,6 +1745,7 @@ struct spellbook * unit_get_spellbook(struct unit * u) if (u->faction->spellbook) { return u->faction->spellbook; } + return get_spellbook(magic_school[u->faction->magiegebiet]); } return 0; } \ No newline at end of file