From 5547893be7fc619c9d2a8a788f43797bfe124ee8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 May 2012 10:16:39 -0700 Subject: [PATCH] fix create_roi function in E3 --- scripts/tests/spells.lua | 1 + src/gamecode/laws.c | 42 ++++++++++++++++++++++++++++++---------- src/kernel/magic.c | 10 +++++++--- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index 763f67953..f790e58fd 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -18,6 +18,7 @@ function test_roi() u.magic = "tybied" u.aura = 200 u.ship = s1 + -- local err = u:add_spell("create_roi") -- assert_equal(0, err) u:clear_orders() diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 26cb72b36..317def2ca 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -78,6 +78,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include @@ -3713,6 +3714,20 @@ static int faction_getmages(faction * f, unit ** results, int numresults) return maxlevel; } +static void copy_spells(const spellbook * src, spellbook * dst, int maxlevel) +{ + assert(dst); + if (src && src->spells) { + quicklist *ql; + int qi; + for (qi = 0, ql = src->spells; ql; ql_advance(&ql, &qi, 1)) { + spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi); + if (sbe->level<=maxlevel) { + spellbook_add(dst, sbe->sp, sbe->level); + } + } + } +} static void update_spells(void) { faction *f; @@ -3723,17 +3738,24 @@ static void update_spells(void) int i; int maxlevel = faction_getmages(f, mages, MAXMAGES); - if (FactionSpells() && maxlevel > f->max_spelllevel) { - static spellbook * common_spells; - if (!common_spells) { - const char *common_school = get_param(global.parameters, "rules.magic.common"); - if (!common_school) common_school = "common"; - common_spells = get_spellbook(common_school); - if (!common_spells) { - log_error("could not find a book of common spells: '%s'\n", common_school); - } + if (maxlevel && FactionSpells()) { + spellbook * book = get_spellbook(magic_school[f->magiegebiet]); + if (!f->spellbook) { + f->spellbook = create_spellbook(0); + } + copy_spells(book, f->spellbook, maxlevel); + if (maxlevel > f->max_spelllevel) { + static spellbook * common_spells; + if (!common_spells) { + const char *common_school = get_param(global.parameters, "rules.magic.common"); + if (!common_school) common_school = "common"; + common_spells = get_spellbook(common_school); + if (!common_spells) { + log_error("could not find a book of common spells: '%s'\n", common_school); + } + } + pick_random_spells(f, maxlevel, common_spells, COMMONSPELLS); } - pick_random_spells(f, maxlevel, common_spells, COMMONSPELLS); } show_new_spells(f, maxlevel, faction_get_spellbook(f)); for (i=0; i!=MAXMAGES && mages[i]; ++i) { diff --git a/src/kernel/magic.c b/src/kernel/magic.c index b5f7dbb70..9559e2316 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -2477,6 +2477,7 @@ static castorder *cast_cmd(unit * u, order * ord) plane *pl; spellparameter *args = NULL; unit * caster = u; + param_t param; if (LongHunger(u)) { cmistake(u, ord, 224, MSG_MAGIC); @@ -2492,8 +2493,9 @@ static castorder *cast_cmd(unit * u, order * ord) init_tokens(ord); skip_token(); s = getstrtoken(); + param = findparam(s, u->faction->locale); /* für Syntax ' STUFE x REGION y z ' */ - if (findparam(s, u->faction->locale) == P_LEVEL) { + if (param == P_LEVEL) { int p = getint(); level = MIN(p, level); if (level < 1) { @@ -2502,8 +2504,9 @@ static castorder *cast_cmd(unit * u, order * ord) return 0; } s = getstrtoken(); + param = findparam(s, u->faction->locale); } - if (findparam(s, u->faction->locale) == P_REGION) { + if (param == P_REGION) { int t_x = getint(); int t_y = getint(); plane *pl = getplane(u->region); @@ -2518,10 +2521,11 @@ static castorder *cast_cmd(unit * u, order * ord) return 0; } s = getstrtoken(); + param = findparam(s, u->faction->locale); } /* für Syntax ' REGION x y STUFE z ' * hier nach REGION nochmal auf STUFE prüfen */ - if (findparam(s, u->faction->locale) == P_LEVEL) { + if (param == P_LEVEL) { int p = getint(); level = MIN(p, level); if (level < 1) {