diff --git a/scripts/eressea/main.lua b/scripts/eressea/main.lua index 300a58e7e..060fdbf8c 100644 --- a/scripts/eressea/main.lua +++ b/scripts/eressea/main.lua @@ -1,5 +1,13 @@ require "multis" +function apply_fixes() + local turn = get_turn() + if config.game=="eressea" and turn>654 and turn<662 then + print("Fixing familiars") + fix_familiars() + end +end + function process(orders) local confirmed_multis = { } local suspected_multis = { } @@ -8,6 +16,7 @@ function process(orders) print("could not read game") return -1 end + apply_fixes() init_summary() -- kill multi-players (external script) diff --git a/src/bindings.c b/src/bindings.c index 05796f20e..3dfafcc56 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -51,6 +51,37 @@ tolua_spawn_undead(lua_State * L) return 0; } +static int +fix_familiars(struct lua_State * L) +{ + faction * f; + for (f=factions;f;f=f->next) { + unit * u; + for (u=f->units;u;u=u->nextF) { + struct sc_mage * mage = get_mage(u); + if (mage && is_familiar(u)) { + if (mage->spells && mage->magietyp==M_GRAY) { + equipment * eq; + char buffer[64]; + + while (mage->spells) { + spell_list * slist = mage->spells; + mage->spells = mage->spells->next; + free(slist); + } + + snprintf(buffer, sizeof(buffer), "%s_familiar", u->race->_name[0]); + eq = get_equipment(buffer); + if (eq) { + equip_unit_mask(u, eq, EQUIP_SPELLS); + } + } + } + } + } + return 0; +} + void bind_eressea(struct lua_State * L) { @@ -61,6 +92,7 @@ bind_eressea(struct lua_State * L) tolua_function(L, TOLUA_CAST "plan_monsters", tolua_planmonsters); tolua_function(L, TOLUA_CAST "spawn_undead", tolua_spawn_undead); tolua_function(L, TOLUA_CAST "spawn_dragons", tolua_spawn_dragons); + tolua_function(L, TOLUA_CAST "fix_familiars", &fix_familiars); } tolua_endmodule(L); }