deprecate old get_mage implementation.

fix test_familiar_equip with new get_mage.
This commit is contained in:
Enno Rehling 2017-10-06 21:53:07 +02:00
parent 2ce94f2d47
commit f594a908df
17 changed files with 55 additions and 44 deletions

View file

@ -273,7 +273,7 @@ static int tolua_unit_set_guard(lua_State * L)
static const char *unit_getmagic(const unit * u)
{
sc_mage *mage = get_mage(u);
sc_mage *mage = get_mage_depr(u);
return mage ? magic_school[mage->magietyp] : NULL;
}
@ -286,7 +286,7 @@ static int tolua_unit_get_magic(lua_State * L)
static void unit_setmagic(unit * u, const char *type)
{
sc_mage *mage = get_mage(u);
sc_mage *mage = get_mage_depr(u);
int mtype;
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
if (strcmp(magic_school[mtype], type) == 0)
@ -753,7 +753,7 @@ static int tolua_unit_get_items(lua_State * L)
static int tolua_unit_get_spells(lua_State * L)
{
unit *self = (unit *) tolua_tousertype(L, 1, 0);
sc_mage *mage = self ? get_mage(self) : 0;
sc_mage *mage = self ? get_mage_depr(self) : 0;
spellbook *sb = mage ? mage->spellbook : 0;
selist *slist = 0;
if (sb) {

View file

@ -954,7 +954,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
}
/* spells that this unit can cast */
mage = get_mage(u);
mage = get_mage_depr(u);
if (mage) {
int i, maxlevel = effskill(u, SK_MAGIC, 0);
cr_output_spells(out, u, maxlevel);

View file

@ -591,7 +591,7 @@ void give_unit(unit * u, unit * u2, order * ord)
cmistake(u, ord, 155, MSG_COMMERCE);
return;
}
mage = get_mage(u);
mage = get_mage_depr(u);
if (!mage || u2->faction->magiegebiet != mage->magietyp) {
cmistake(u, ord, 157, MSG_COMMERCE);
return;

View file

@ -121,7 +121,7 @@ void equip_unit_mask(struct unit *u, const struct equipment *eq, int mask)
if (eq->spells) {
selist * ql = eq->spells;
int qi;
sc_mage * mage = get_mage(u);
sc_mage * mage = get_mage_depr(u);
for (qi = 0; ql; selist_advance(&ql, &qi, 1)) {
lazy_spell *sbe = (lazy_spell *)selist_get(ql, qi);

View file

@ -39,7 +39,7 @@ static void test_equipment(CuTest * tc)
CuAssertIntEquals(tc, 1, i_get(u->items, it_horses));
CuAssertIntEquals(tc, 5, get_level(u, SK_MAGIC));
mage = get_mage(u);
mage = get_mage_depr(u);
CuAssertPtrNotNull(tc, mage);
CuAssertPtrNotNull(tc, mage->spellbook);
CuAssertTrue(tc, u_hasspell(u, sp));

View file

@ -1791,7 +1791,7 @@ int read_game(gamedata *data)
else {
for (u = f->units; u; u = u->nextF) {
if (data->version < SPELL_LEVEL_VERSION) {
sc_mage *mage = get_mage(u);
sc_mage *mage = get_mage_depr(u);
if (mage) {
faction *f = u->faction;
int skl = effskill(u, SK_MAGIC, 0);

View file

@ -1814,7 +1814,7 @@ void u_setrace(struct unit *u, const struct race *rc)
void unit_add_spell(unit * u, sc_mage * m, struct spell * sp, int level)
{
sc_mage *mage = m ? m : get_mage(u);
sc_mage *mage = m ? m : get_mage_depr(u);
if (!mage) {
log_debug("adding new spell %s to a previously non-mage unit %s\n", sp->sname, unitname(u));
@ -1828,7 +1828,7 @@ void unit_add_spell(unit * u, sc_mage * m, struct spell * sp, int level)
struct spellbook * unit_get_spellbook(const struct unit * u)
{
sc_mage * mage = get_mage(u);
sc_mage * mage = get_mage_depr(u);
if (mage) {
if (mage->spellbook) {
return mage->spellbook;

View file

@ -3387,7 +3387,7 @@ static int faction_getmages(faction * f, unit ** results, int numresults)
for (u = f->units; u; u = u->nextF) {
if (u->number > 0) {
sc_mage *mage = get_mage(u);
sc_mage *mage = get_mage_depr(u);
if (mage) {
int level = effskill(u, SK_MAGIC, 0);
if (level > maxlevel) {
@ -3446,7 +3446,7 @@ static void update_spells(void)
show_new_spells(f, maxlevel, faction_get_spellbook(f));
for (i = 0; i != MAXMAGES && mages[i]; ++i) {
unit * u = mages[i];
sc_mage *mage = get_mage(u);
sc_mage *mage = get_mage_depr(u);
if (mage && mage->spellbook) {
int level = effskill(u, SK_MAGIC, 0);
show_new_spells(f, level, mage->spellbook);

View file

@ -323,10 +323,19 @@ attrib_type at_mage = {
bool is_mage(const unit * u)
{
return get_mage(u) != NULL;
return get_mage_depr(u) != NULL;
}
sc_mage *get_mage(const unit * u)
{
attrib *a = a_find(u->attribs, &at_mage);
if (a) {
return (sc_mage *)a->data.v;
}
return NULL;
}
sc_mage *get_mage_depr(const unit * u)
{
if (has_skill(u, SK_MAGIC)) {
attrib *a = a_find(u->attribs, &at_mage);
@ -334,7 +343,7 @@ sc_mage *get_mage(const unit * u)
return (sc_mage *)a->data.v;
}
}
return (sc_mage *)NULL;
return NULL;
}
/* ------------------------------------------------------------- */
@ -507,7 +516,7 @@ int u_hasspell(const unit *u, const struct spell *sp)
int get_combatspelllevel(const unit * u, int nr)
{
sc_mage *m = get_mage(u);
sc_mage *m = get_mage_depr(u);
assert(nr < MAXCOMBATSPELLS);
if (m) {
@ -525,7 +534,7 @@ const spell *get_combatspell(const unit * u, int nr)
sc_mage *m;
assert(nr < MAXCOMBATSPELLS);
m = get_mage(u);
m = get_mage_depr(u);
if (m) {
return m->combatspells[nr].sp;
}
@ -534,7 +543,7 @@ const spell *get_combatspell(const unit * u, int nr)
void set_combatspell(unit * u, spell * sp, struct order *ord, int level)
{
sc_mage *mage = get_mage(u);
sc_mage *mage = get_mage_depr(u);
int i = -1;
assert(mage || !"trying to set a combat spell for non-mage");
@ -574,7 +583,7 @@ void unset_combatspell(unit * u, spell * sp)
int nr = 0;
int i;
m = get_mage(u);
m = get_mage_depr(u);
if (!m)
return;
@ -610,7 +619,7 @@ int get_spellpoints(const unit * u)
{
sc_mage *m;
m = get_mage(u);
m = get_mage_depr(u);
if (!m)
return 0;
@ -621,7 +630,7 @@ void set_spellpoints(unit * u, int sp)
{
sc_mage *m;
m = get_mage(u);
m = get_mage_depr(u);
if (!m)
return;
@ -638,7 +647,7 @@ int change_spellpoints(unit * u, int mp)
sc_mage *m;
int sp;
m = get_mage(u);
m = get_mage_depr(u);
if (!m) {
return 0;
}
@ -657,7 +666,7 @@ static int get_spchange(const unit * u)
{
sc_mage *m;
m = get_mage(u);
m = get_mage_depr(u);
if (!m)
return 0;
@ -711,7 +720,7 @@ int change_maxspellpoints(unit * u, int csp)
{
sc_mage *m;
m = get_mage(u);
m = get_mage_depr(u);
if (!m) {
return 0;
}
@ -729,7 +738,7 @@ int countspells(unit * u, int step)
sc_mage *m;
int count;
m = get_mage(u);
m = get_mage_depr(u);
if (!m)
return 0;
@ -1313,7 +1322,7 @@ bool fumble(region * r, unit * u, const spell * sp, int cast_grade)
}
/* CHAOSPATZERCHANCE 10 : +10% Chance zu Patzern */
mage = get_mage(u);
mage = get_mage_depr(u);
if (mage->magietyp == M_DRAIG) {
fumble_chance += CHAOSPATZERCHANCE;
}
@ -2238,7 +2247,7 @@ void create_newfamiliar(unit * mage, unit * fam)
snprintf(eqname, sizeof(eqname), "fam_%s", rc->_name);
eq = get_equipment(eqname);
if (eq != NULL) {
equip_items(&fam->items, eq);
equip_unit(fam, eq);
}
else {
log_info("could not perform initialization for familiar %s.\n", rc->_name);

View file

@ -221,6 +221,7 @@ extern "C" {
/* macht die struct unit zu einem neuen Magier: legt die struct u->mage an
* und initialisiert den Magiertypus mit mtyp. */
sc_mage *get_mage(const struct unit *u);
sc_mage *get_mage_depr(const struct unit *u);
/* gibt u->mage zurück, bei nicht-Magiern *NULL */
bool is_mage(const struct unit *u);
/* gibt true, wenn u->mage gesetzt. */

View file

@ -549,7 +549,7 @@ static void test_familiar_equip(CuTest *tc) {
CuAssertPtrNotNull(tc, mage);
CuAssertPtrNotNull(tc, mage->spellbook);
set_level(u, SK_MAGIC, 1);
CuAssertPtrEquals(tc, mage, get_mage(u));
CuAssertPtrEquals(tc, mage, get_mage_depr(u));
CuAssertTrue(tc, u_hasspell(u, sp));
test_cleanup();

View file

@ -1451,7 +1451,7 @@ static int movement_speed(unit * u)
* Nicht kumulativ mit anderen Beschleunigungen! */
if (mp * dk <= BP_WALKING * u_race(u)->speed && is_astral(u->region)
&& is_mage(u)) {
sc_mage *mage = get_mage(u);
sc_mage *mage = get_mage_depr(u);
if (mage->magietyp == M_TYBIED || mage->magietyp == M_ILLAUN) {
mp *= 2;
}

View file

@ -819,8 +819,9 @@ spskill(char *buffer, size_t size, const struct locale * lang,
bufp = STRLCPY(bufp, " ", size);
if (sv->id == SK_MAGIC) {
sc_mage *mage = get_mage(u);
if (mage && mage->magietyp != M_GRAY) {
sc_mage *mage = get_mage_depr(u);
assert(mage);
if (mage->magietyp != M_GRAY) {
bufp = STRLCPY(bufp, LOC(lang, mkname("school",
magic_school[mage->magietyp])), size);
bufp = STRLCPY(bufp, " ", size);

View file

@ -731,7 +731,7 @@ static int sp_transferaura(castorder * co)
int cast_level = co->level;
spellparameter *pa = co->par;
unit *u;
sc_mage *scm_dst, *scm_src = get_mage(mage);
sc_mage *scm_dst, *scm_src = get_mage_depr(mage);
/* wenn kein Ziel gefunden, Zauber abbrechen */
if (pa->param[0]->flag == TARGET_NOTFOUND)
@ -745,7 +745,7 @@ static int sp_transferaura(castorder * co)
/* Wieviel Transferieren? */
aura = pa->param[1]->data.i;
u = pa->param[0]->data.u;
scm_dst = get_mage(u);
scm_dst = get_mage_depr(u);
if (scm_dst == NULL) {
/* "Zu dieser Einheit kann ich keine Aura uebertragen." */
@ -5813,7 +5813,7 @@ int sp_permtransfer(castorder * co)
change_maxspellpoints(mage, -aura);
change_spellpoints(mage, -aura);
if (get_mage(tu)->magietyp == get_mage(mage)->magietyp) {
if (get_mage_depr(tu)->magietyp == get_mage_depr(mage)->magietyp) {
change_maxspellpoints(tu, aura / 2);
}
else {
@ -5936,18 +5936,18 @@ int sp_stealaura(castorder * co)
/* Zieleinheit */
u = pa->param[0]->data.u;
if (!get_mage(u)) {
if (!get_mage_depr(u)) {
ADDMSG(&mage->faction->msgs, msg_message("stealaura_fail", "unit target",
mage, u));
ADDMSG(&u->faction->msgs, msg_message("stealaura_fail_detect", "unit", u));
return 0;
}
taura = (get_mage(u)->spellpoints * (rng_int() % (int)(3 * power) + 1)) / 100;
taura = (get_mage_depr(u)->spellpoints * (rng_int() % (int)(3 * power) + 1)) / 100;
if (taura > 0) {
get_mage(u)->spellpoints -= taura;
get_mage(mage)->spellpoints += taura;
get_mage_depr(u)->spellpoints -= taura;
get_mage_depr(mage)->spellpoints += taura;
/* sprintf(buf, "%s entzieht %s %d Aura.", unitname(mage), unitname(u),
taura); */
ADDMSG(&mage->faction->msgs, msg_message("stealaura_success",

View file

@ -68,7 +68,7 @@ void spy_message(int spy, const unit * u, const unit * target)
ADDMSG(&u->faction->msgs, msg_message("spyreport", "spy target status", u,
target, status));
if (spy > 20) {
sc_mage *mage = get_mage(target);
sc_mage *mage = get_mage_depr(target);
/* for mages, spells and magic school */
if (mage) {
ADDMSG(&u->faction->msgs, msg_message("spyreport_mage", "spy target type", u,

View file

@ -427,8 +427,8 @@ int teach_cmd(unit * teacher, struct order *ord)
if (sk == SK_MAGIC) {
/* ist der Magier schon spezialisiert, so versteht er nur noch
* Lehrer seines Gebietes */
sc_mage *mage1 = get_mage(teacher);
sc_mage *mage2 = get_mage(student);
sc_mage *mage1 = get_mage_depr(teacher);
sc_mage *mage2 = get_mage_depr(student);
if (mage2 && mage1 && mage2->magietyp != M_GRAY
&& mage1->magietyp != mage2->magietyp) {
if (feedback) {
@ -782,7 +782,7 @@ int study_cmd(unit * u, order * ord)
}
}
else if (sk == SK_MAGIC) {
sc_mage *mage = get_mage(u);
sc_mage *mage = get_mage_depr(u);
if (!mage) {
mage = create_mage(u, u->faction->magiegebiet);
}

View file

@ -409,11 +409,11 @@ static void test_study_magic(CuTest *tc) {
study_cmd(u, u->thisorder);
CuAssertIntEquals(tc, M_GWYRRD, f->magiegebiet);
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
CuAssertPtrNotNull(tc, get_mage(u));
CuAssertPtrNotNull(tc, get_mage_depr(u));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error65"));
CuAssertIntEquals(tc, M_GWYRRD, get_mage(u)->magietyp);
CuAssertIntEquals(tc, M_GWYRRD, get_mage_depr(u)->magietyp);
/* the static cost array in study_cost prevents this test:
/* TODO: the static cost array in study_cost prevents this test:
test_clear_messages(f);
config_set("skills.cost.magic", "50");
i_change(&u->items, rtype->itype, 50);