fix create_roi function in E3

This commit is contained in:
Enno Rehling 2012-05-26 10:16:39 -07:00
parent 8a27917f27
commit 5547893be7
3 changed files with 40 additions and 13 deletions

View File

@ -18,6 +18,7 @@ function test_roi()
u.magic = "tybied" u.magic = "tybied"
u.aura = 200 u.aura = 200
u.ship = s1 u.ship = s1
-- local err = u:add_spell("create_roi") -- local err = u:add_spell("create_roi")
-- assert_equal(0, err) -- assert_equal(0, err)
u:clear_orders() u:clear_orders()

View File

@ -78,6 +78,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/lists.h> #include <util/lists.h>
#include <util/log.h> #include <util/log.h>
#include <util/parser.h> #include <util/parser.h>
#include <util/quicklist.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/sql.h> #include <util/sql.h>
@ -3713,6 +3714,20 @@ static int faction_getmages(faction * f, unit ** results, int numresults)
return maxlevel; 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) static void update_spells(void)
{ {
faction *f; faction *f;
@ -3723,7 +3738,13 @@ static void update_spells(void)
int i; int i;
int maxlevel = faction_getmages(f, mages, MAXMAGES); int maxlevel = faction_getmages(f, mages, MAXMAGES);
if (FactionSpells() && maxlevel > f->max_spelllevel) { 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; static spellbook * common_spells;
if (!common_spells) { if (!common_spells) {
const char *common_school = get_param(global.parameters, "rules.magic.common"); const char *common_school = get_param(global.parameters, "rules.magic.common");
@ -3735,6 +3756,7 @@ static void update_spells(void)
} }
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)); show_new_spells(f, maxlevel, faction_get_spellbook(f));
for (i=0; i!=MAXMAGES && mages[i]; ++i) { for (i=0; i!=MAXMAGES && mages[i]; ++i) {
unit * u = mages[i]; unit * u = mages[i];

View File

@ -2477,6 +2477,7 @@ static castorder *cast_cmd(unit * u, order * ord)
plane *pl; plane *pl;
spellparameter *args = NULL; spellparameter *args = NULL;
unit * caster = u; unit * caster = u;
param_t param;
if (LongHunger(u)) { if (LongHunger(u)) {
cmistake(u, ord, 224, MSG_MAGIC); cmistake(u, ord, 224, MSG_MAGIC);
@ -2492,8 +2493,9 @@ static castorder *cast_cmd(unit * u, order * ord)
init_tokens(ord); init_tokens(ord);
skip_token(); skip_token();
s = getstrtoken(); s = getstrtoken();
param = findparam(s, u->faction->locale);
/* für Syntax ' STUFE x REGION y z ' */ /* für Syntax ' STUFE x REGION y z ' */
if (findparam(s, u->faction->locale) == P_LEVEL) { if (param == P_LEVEL) {
int p = getint(); int p = getint();
level = MIN(p, level); level = MIN(p, level);
if (level < 1) { if (level < 1) {
@ -2502,8 +2504,9 @@ static castorder *cast_cmd(unit * u, order * ord)
return 0; return 0;
} }
s = getstrtoken(); 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_x = getint();
int t_y = getint(); int t_y = getint();
plane *pl = getplane(u->region); plane *pl = getplane(u->region);
@ -2518,10 +2521,11 @@ static castorder *cast_cmd(unit * u, order * ord)
return 0; return 0;
} }
s = getstrtoken(); s = getstrtoken();
param = findparam(s, u->faction->locale);
} }
/* für Syntax ' REGION x y STUFE z ' /* für Syntax ' REGION x y STUFE z '
* hier nach REGION nochmal auf STUFE prüfen */ * hier nach REGION nochmal auf STUFE prüfen */
if (findparam(s, u->faction->locale) == P_LEVEL) { if (param == P_LEVEL) {
int p = getint(); int p = getint();
level = MIN(p, level); level = MIN(p, level);
if (level < 1) { if (level < 1) {