kill tybied in E3, make common spells the source for random choices

This commit is contained in:
Enno Rehling 2012-05-26 14:19:35 -07:00
parent 2103c1725e
commit 62a91f4558
6 changed files with 51 additions and 24 deletions

View file

@ -14,8 +14,8 @@ function test_roi()
u.race = "elf" u.race = "elf"
u:set_skill("magic", 10) u:set_skill("magic", 10)
u:add_item("money", 3010) u:add_item("money", 3010)
f.magic = "tybied" f.magic = "gwyrrd"
u.magic = "tybied" u.magic = "gwyrrd"
u.aura = 200 u.aura = 200
u.ship = s1 u.ship = s1

View file

@ -3730,6 +3730,7 @@ static void copy_spells(const spellbook * src, spellbook * dst, int maxlevel)
} }
} }
} }
static void update_spells(void) static void update_spells(void)
{ {
faction *f; faction *f;
@ -3747,15 +3748,7 @@ static void update_spells(void)
} }
copy_spells(book, f->spellbook, maxlevel); copy_spells(book, f->spellbook, maxlevel);
if (maxlevel > f->max_spelllevel) { if (maxlevel > f->max_spelllevel) {
static spellbook * common_spells; spellbook * common_spells = get_spellbook(magic_school[M_COMMON]);
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);
} }
} }

View file

@ -245,6 +245,14 @@ void read_spells(struct quicklist **slistp, magic_t mtype,
} }
} }
int get_spell_level_mage(const spell * sp, void * cbdata)
{
sc_mage *mage = (sc_mage *)cbdata;
spellbook *book = get_spellbook(magic_school[mage->magietyp]);
spellbook_entry *sbe = spellbook_get(book, sp);
return sbe ? sbe->level : 0;
}
static int read_mage(attrib * a, void *owner, struct storage *store) static int read_mage(attrib * a, void *owner, struct storage *store)
{ {
int i, mtype; int i, mtype;
@ -291,9 +299,9 @@ static int read_mage(attrib * a, void *owner, struct storage *store)
} }
} }
if (mage->magietyp==M_GRAY) { if (mage->magietyp==M_GRAY) {
read_spellbook(&mage->spellbook, store); read_spellbook(&mage->spellbook, store, get_spell_level_mage, mage);
} else { } else {
read_spellbook(0, store); read_spellbook(0, store, 0, mage);
} }
return AT_READ_OK; return AT_READ_OK;
} }
@ -420,15 +428,14 @@ void show_new_spells(faction * f, int level, const spellbook *book)
for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { for (qi = 0; ql; ql_advance(&ql, &qi, 1)) {
spellbook_entry *sbe = (spellbook_entry *) ql_get(ql, qi); spellbook_entry *sbe = (spellbook_entry *) ql_get(ql, qi);
if (sbe->level <= level) { if (sbe->level <= level) {
spell * sp = sbe->sp;
if (!already_seen(f, sp)) { if (!already_seen(f, sbe->sp)) {
attrib * a = a_new(&at_reportspell); attrib * a = a_new(&at_reportspell);
spellbook_entry * entry = (spellbook_entry *)a->data.v; spellbook_entry * entry = (spellbook_entry *)a->data.v;
entry->level = level; entry->level = sbe->level;
entry->sp = sp; entry->sp = sbe->sp;
a_add(&f->attribs, a); a_add(&f->attribs, a);
a_add(&f->attribs, a_new(&at_seenspell))->data.v = sp; a_add(&f->attribs, a_new(&at_seenspell))->data.v = sbe->sp;
} }
} }
} }

View file

@ -1204,12 +1204,36 @@ static ally **addally(const faction * f, ally ** sfp, int aid, int state)
return &sf->next; return &sf->next;
} }
void read_spellbook(spellbook **bookp, struct storage *store) int get_spell_level_faction(const spell * sp, void * cbdata)
{ {
int level; static spellbook * common = 0;
for (level=0;;++level) { spellbook * book;
faction * f = (faction *)cbdata;
spellbook_entry * sbe;
book = get_spellbook(magic_school[f->magiegebiet]);
if (book) {
sbe = spellbook_get(book, sp);
if (sbe) return sbe->level;
}
if (!common) {
common = get_spellbook(magic_school[M_COMMON]);
}
sbe = spellbook_get(common, sp);
if (sbe) {
return sbe->level;
} else {
log_error("read_spellbook: faction '%s' has a spell with unknown level: '%s'", factionname(f), sp->sname);
}
return 0;
}
void read_spellbook(spellbook **bookp, struct storage *store, int (*get_level)(const spell * sp, void *), void * cbdata)
{
for (;;) {
spell *sp = 0; spell *sp = 0;
char spname[64]; char spname[64];
int level = 0;
if (store->version < SPELLNAME_VERSION) { if (store->version < SPELLNAME_VERSION) {
int i = store->r_int(store); int i = store->r_int(store);
@ -1233,6 +1257,9 @@ void read_spellbook(spellbook **bookp, struct storage *store)
level = store->r_int(store); level = store->r_int(store);
} }
if (sp) { if (sp) {
if (level<=0 && get_level) {
level = get_level(sp, cbdata);
}
if (!*bookp) { if (!*bookp) {
*bookp = create_spellbook(0); *bookp = create_spellbook(0);
} }
@ -1395,7 +1422,7 @@ faction *readfaction(struct storage * store)
read_groups(store, f); read_groups(store, f);
f->spellbook = 0; f->spellbook = 0;
if (store->version >= REGIONOWNER_VERSION) { if (store->version >= REGIONOWNER_VERSION) {
read_spellbook(FactionSpells() ? &f->spellbook : 0, store); read_spellbook(FactionSpells() ? &f->spellbook : 0, store, get_spell_level_faction, (void *)f);
} }
return f; return f;
} }

View file

@ -47,7 +47,7 @@ extern "C" {
extern void read_items(struct storage *store, struct item **it); extern void read_items(struct storage *store, struct item **it);
extern void write_items(struct storage *store, struct item *it); extern void write_items(struct storage *store, struct item *it);
extern void read_spellbook(struct spellbook **bookp, struct storage *store); extern void read_spellbook(struct spellbook **bookp, struct storage *store, int (*get_level)(const struct spell * sp, void *), void * cbdata);
extern void write_spellbook(const struct spellbook *book, struct storage *store); extern void write_spellbook(const struct spellbook *book, struct storage *store);
extern void write_unit(struct storage *store, const struct unit *u); extern void write_unit(struct storage *store, const struct unit *u);

View file

@ -20,7 +20,7 @@ void spellbook_add(spellbook *sb, struct spell * sp, int level)
{ {
spellbook_entry * sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry)); spellbook_entry * sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry));
assert(sb); assert(sb && level>0);
sbe->sp = sp; sbe->sp = sp;
sbe->level = level; sbe->level = level;
ql_push(&sb->spells, sbe); ql_push(&sb->spells, sbe);