forked from github/server
updating spell-lists is a thing of the past now
almost everything uses books, except sc_mage
This commit is contained in:
parent
c73297ba44
commit
9d1b62d463
|
@ -3687,6 +3687,32 @@ static void defaultorders(void)
|
||||||
/* ************************************************************ */
|
/* ************************************************************ */
|
||||||
#define COMMONSPELLS 1 /* number of new common spells per level */
|
#define COMMONSPELLS 1 /* number of new common spells per level */
|
||||||
#define MAXMAGES 128 /* should be enough */
|
#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)
|
static void update_spells(void)
|
||||||
{
|
{
|
||||||
faction *f;
|
faction *f;
|
||||||
|
@ -3694,34 +3720,30 @@ static void update_spells(void)
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
if (f->magiegebiet != M_NONE && !is_monsters(f)) {
|
if (f->magiegebiet != M_NONE && !is_monsters(f)) {
|
||||||
unit *mages[MAXMAGES];
|
unit *mages[MAXMAGES];
|
||||||
unit *u;
|
int i;
|
||||||
int maxlevel = 0, n = 0, i;
|
int maxlevel = faction_getmages(f, mages, MAXMAGES);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FactionSpells() && maxlevel > f->max_spelllevel) {
|
if (FactionSpells() && 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");
|
||||||
common_spells = get_spellbook(common_school ? common_school : "common");
|
if (!common_school) common_school = "common";
|
||||||
}
|
common_spells = get_spellbook(common_school);
|
||||||
if (common_spells) {
|
if (!common_spells) {
|
||||||
pick_random_spells(f, maxlevel, common_spells, COMMONSPELLS);
|
log_error("could not find a book of common spells: '%s'\n", common_school);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
pick_random_spells(f, maxlevel, common_spells, COMMONSPELLS);
|
||||||
}
|
}
|
||||||
for (i = 0; i != n; ++i) {
|
show_new_spells(f, maxlevel, faction_get_spellbook(f));
|
||||||
updatespelllist(mages[i]);
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -511,3 +511,14 @@ struct alliance *f_get_alliance(const struct faction *f)
|
||||||
}
|
}
|
||||||
return NULL;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -152,6 +152,7 @@ extern "C" {
|
||||||
void faction_setpassword(struct faction *self, const char *password);
|
void faction_setpassword(struct faction *self, const char *password);
|
||||||
boolean valid_race(const struct faction *f, const struct race *rc);
|
boolean valid_race(const struct faction *f, const struct race *rc);
|
||||||
|
|
||||||
|
struct spellbook * faction_get_spellbook(struct faction *f);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -409,50 +409,26 @@ static boolean already_seen(const faction * f, const spell * sp)
|
||||||
return false;
|
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);
|
if (book) {
|
||||||
quicklist **dst, *ql = book->spells;
|
quicklist *ql = book->spells;
|
||||||
int qi;
|
int qi;
|
||||||
|
|
||||||
dst = get_spelllist(mage, f);
|
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;
|
||||||
spell * sp = sbe->sp;
|
|
||||||
|
|
||||||
if (!u_hasspell(mage, sp)) {
|
if (!already_seen(f, sp)) {
|
||||||
add_spell(dst, sp);
|
attrib * a = a_new(&at_reportspell);
|
||||||
add_spellname(mage, sp);
|
spellbook_entry * entry = (spellbook_entry *)a->data.v;
|
||||||
|
entry->level = level;
|
||||||
|
entry->sp = sp;
|
||||||
|
a_add(&f->attribs, a);
|
||||||
|
a_add(&f->attribs, a_new(&at_seenspell))->data.v = sp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!ismonster && !already_seen(f, sp)) {
|
|
||||||
attrib * a = a_new(&at_reportspell);
|
|
||||||
spellbook_entry * entry = (spellbook_entry *)a->data.v;
|
|
||||||
entry->level = level;
|
|
||||||
entry->sp = sp;
|
|
||||||
a_add(&f->attribs, a);
|
|
||||||
a_add(&f->attribs, a_new(&at_seenspell))->data.v = sp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
"unit region amount", u, r, regen));
|
||||||
}
|
}
|
||||||
set_spellpoints(u, MIN(aura, auramax));
|
set_spellpoints(u, MIN(aura, auramax));
|
||||||
|
|
||||||
/* Zum letzten Mal Spruchliste aktualisieren */
|
|
||||||
/*updatespelllist(u); */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,6 +255,7 @@ typedef struct sc_mage {
|
||||||
int u_hasspell(const sc_mage *mage, const struct spell *sp);
|
int u_hasspell(const sc_mage *mage, const struct spell *sp);
|
||||||
/* prüft, ob der Spruch in der Spruchliste der Einheit steht. */
|
/* 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 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);
|
void updatespelllist(struct unit *u);
|
||||||
/* fügt alle Zauber des Magiegebietes der Einheit, deren Stufe kleiner
|
/* fügt alle Zauber des Magiegebietes der Einheit, deren Stufe kleiner
|
||||||
* als das aktuelle Magietalent ist, in die Spruchliste der Einheit
|
* als das aktuelle Magietalent ist, in die Spruchliste der Einheit
|
||||||
|
|
|
@ -247,7 +247,8 @@ void test_getspell_school(CuTest * tc)
|
||||||
|
|
||||||
CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang));
|
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);
|
spellbook_add(book, sp, 1);
|
||||||
CuAssertPtrEquals(tc, sp, unit_getspell(u, "Herp-a-derp", lang));
|
CuAssertPtrEquals(tc, sp, unit_getspell(u, "Herp-a-derp", lang));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1615,8 +1615,9 @@ int readgame(const char *filename, int mode, int backup)
|
||||||
|
|
||||||
n = store->r_int(store);
|
n = store->r_int(store);
|
||||||
assert(n < MAXREGIONS);
|
assert(n < MAXREGIONS);
|
||||||
if (rmax < 0)
|
if (rmax < 0) {
|
||||||
rmax = n;
|
rmax = n;
|
||||||
|
}
|
||||||
log_printf(stdout, " - Einzulesende Regionen: %d/%d\r", rmax, n);
|
log_printf(stdout, " - Einzulesende Regionen: %d/%d\r", rmax, n);
|
||||||
while (--n >= 0) {
|
while (--n >= 0) {
|
||||||
unit **up;
|
unit **up;
|
||||||
|
@ -1727,7 +1728,6 @@ int readgame(const char *filename, int mode, int backup)
|
||||||
}
|
}
|
||||||
if (mage->spellcount < 0) {
|
if (mage->spellcount < 0) {
|
||||||
mage->spellcount = 0;
|
mage->spellcount = 0;
|
||||||
updatespelllist(u);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1742,10 +1742,12 @@ struct spellbook * unit_get_spellbook(const struct unit * u)
|
||||||
{
|
{
|
||||||
sc_mage * mage = get_mage(u);
|
sc_mage * mage = get_mage(u);
|
||||||
if (mage) {
|
if (mage) {
|
||||||
if (u->faction->spellbook) {
|
if (mage->spells) {
|
||||||
return u->faction->spellbook;
|
#ifdef TODO
|
||||||
|
return mage->spellbook;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return get_spellbook(magic_school[u->faction->magiegebiet]);
|
return faction_get_spellbook(u->faction);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue