updating spell-lists is a thing of the past now

almost everything uses books, except sc_mage
This commit is contained in:
Enno Rehling 2012-05-26 00:33:55 -07:00
parent c73297ba44
commit 9d1b62d463
8 changed files with 81 additions and 70 deletions

View File

@ -3687,6 +3687,32 @@ static void defaultorders(void)
/* ************************************************************ */
#define COMMONSPELLS 1 /* number of new common spells per level */
#define MAXMAGES 128 /* should be enough */
static int faction_getmages(faction * f, unit ** results, int numresults)
{
unit *u;
int maxlevel = 0, n = 0;
for (u = f->units; u; u = u->nextF) {
if (u->number > 0) {
sc_mage *mage = get_mage(u);
if (mage) {
int level = eff_skill(u, SK_MAGIC, u->region);
if (level > maxlevel) {
maxlevel = level;
}
if (n<numresults) {
results[n++] = u;
}
}
}
}
if (n<numresults) {
results[n] = 0;
}
return maxlevel;
}
static void update_spells(void)
{
faction *f;
@ -3694,34 +3720,30 @@ static void update_spells(void)
for (f = factions; f; f = f->next) {
if (f->magiegebiet != M_NONE && !is_monsters(f)) {
unit *mages[MAXMAGES];
unit *u;
int maxlevel = 0, n = 0, i;
for (u = f->units; u; u = u->nextF) {
if (u->number > 0) {
sc_mage *mage = get_mage(u);
if (mage) {
int level = eff_skill(u, SK_MAGIC, u->region);
if (level > maxlevel)
maxlevel = level;
assert(n < MAXMAGES);
mages[n++] = u;
}
}
}
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");
common_spells = get_spellbook(common_school ? common_school : "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 (common_spells) {
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) {
sc_mage *mage = get_mage(mages[i]);
if (mage && mage->spells) {
#ifdef TODO
int level = effskill(mages[i], SK_MAGIC);
show_new_spells(f, level, mage->spellbook);
#endif
}
for (i = 0; i != n; ++i) {
updatespelllist(mages[i]);
}
}
}

View File

@ -511,3 +511,14 @@ struct alliance *f_get_alliance(const struct faction *f)
}
return NULL;
}
struct spellbook * faction_get_spellbook(struct faction *f)
{
if (f->spellbook) {
return f->spellbook;
}
if (f->magiegebiet!=M_GRAY) {
return get_spellbook(magic_school[f->magiegebiet]);
}
return 0;
}

View File

@ -152,6 +152,7 @@ extern "C" {
void faction_setpassword(struct faction *self, const char *password);
boolean valid_race(const struct faction *f, const struct race *rc);
struct spellbook * faction_get_spellbook(struct faction *f);
#ifdef __cplusplus
}
#endif

View File

@ -409,23 +409,18 @@ static boolean already_seen(const faction * f, const spell * sp)
return false;
}
static void update_spells(faction * f, sc_mage * mage, int level, const spellbook *book)
void show_new_spells(faction * f, int level, const spellbook *book)
{
boolean ismonster = is_monsters(f);
quicklist **dst, *ql = book->spells;
if (book) {
quicklist *ql = book->spells;
int qi;
dst = get_spelllist(mage, f);
for (qi = 0; ql; ql_advance(&ql, &qi, 1)) {
spellbook_entry *sbe = (spellbook_entry *) ql_get(ql, qi);
if (sbe->level <= level) {
spell * sp = sbe->sp;
if (!u_hasspell(mage, sp)) {
add_spell(dst, sp);
add_spellname(mage, sp);
}
if (!ismonster && !already_seen(f, sp)) {
if (!already_seen(f, sp)) {
attrib * a = a_new(&at_reportspell);
spellbook_entry * entry = (spellbook_entry *)a->data.v;
entry->level = level;
@ -435,25 +430,6 @@ static void update_spells(faction * f, sc_mage * mage, int level, const spellboo
}
}
}
}
void updatespelllist(unit * u)
{
int sk = eff_skill(u, SK_MAGIC, u->region);
struct sc_mage *mage = get_mage(u);
/* Magier mit M_GRAY bekommen weder Sprüche angezeigt noch
* neue Sprüche in ihre List-of-known-spells. Das sind zb alle alten
* Drachen, die noch den Skill Magie haben, und alle familiars */
if (mage->magietyp != M_GRAY) {
spellbook * book;
book = get_spellbook(magic_school[mage->magietyp]);
update_spells(u->faction, mage, sk, book);
if (FactionSpells()) {
update_spells(u->faction, mage, sk, u->faction->spellbook);
}
}
}
@ -1522,9 +1498,6 @@ void regeneration_magiepunkte(void)
"unit region amount", u, r, regen));
}
set_spellpoints(u, MIN(aura, auramax));
/* Zum letzten Mal Spruchliste aktualisieren */
/*updatespelllist(u); */
}
}
}

View File

@ -255,6 +255,7 @@ typedef struct sc_mage {
int u_hasspell(const sc_mage *mage, const struct spell *sp);
/* prüft, ob der Spruch in der Spruchliste der Einheit steht. */
void pick_random_spells(struct faction *f, int level, struct spellbook * book, int num_spells);
void show_new_spells(struct faction * f, int level, const struct spellbook *book);
void updatespelllist(struct unit *u);
/* fügt alle Zauber des Magiegebietes der Einheit, deren Stufe kleiner
* als das aktuelle Magietalent ist, in die Spruchliste der Einheit

View File

@ -247,7 +247,8 @@ void test_getspell_school(CuTest * tc)
CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang));
book = get_spellbook(magic_school[f->magiegebiet]);
book = faction_get_spellbook(f);
CuAssertPtrNotNull(tc, book);
spellbook_add(book, sp, 1);
CuAssertPtrEquals(tc, sp, unit_getspell(u, "Herp-a-derp", lang));
}

View File

@ -1615,8 +1615,9 @@ int readgame(const char *filename, int mode, int backup)
n = store->r_int(store);
assert(n < MAXREGIONS);
if (rmax < 0)
if (rmax < 0) {
rmax = n;
}
log_printf(stdout, " - Einzulesende Regionen: %d/%d\r", rmax, n);
while (--n >= 0) {
unit **up;
@ -1727,7 +1728,6 @@ int readgame(const char *filename, int mode, int backup)
}
if (mage->spellcount < 0) {
mage->spellcount = 0;
updatespelllist(u);
}
}
}

View File

@ -1742,10 +1742,12 @@ struct spellbook * unit_get_spellbook(const struct unit * u)
{
sc_mage * mage = get_mage(u);
if (mage) {
if (u->faction->spellbook) {
return u->faction->spellbook;
if (mage->spells) {
#ifdef TODO
return mage->spellbook;
#endif
}
return get_spellbook(magic_school[u->faction->magiegebiet]);
return faction_get_spellbook(u->faction);
}
return 0;
}