distinguish global variables that get written to savefile
The g? structs had a mix of variables that were written to
the savefile, and those that were not.
For better clarity and to distinguish those that end up in
the savefile, relocate some g? variables that get written
directly to the savefile into different structs.
This updates EDITLEVEL, although technically it probably
didn't need to, since savefile contents are not changing.
Details:
gb.bases -> svb.bases
gb.bbubbles -> svb.bbubbles
gb.branches -> svb.branches
gc.context -> svc.context
gd.disco -> svd.disco
gd.dndest -> svd.dndest
gd.doors -> svd.doors
gd.doors_alloc -> svd.doors_alloc
gd.dungeon_topology -> svd.dungeon_topology
gd.dungeons -> svd.dungeons
ge.exclusion_zones -> sve.exclusion_zones
gh.hackpid -> svh.hackpid
gi.inv_pos -> svi.inv_pos
gk.killer -> svk.killer
gl.lastseentyp -> svl.lastseentyp
gl.level -> svl.level
gl.level_info -> svl.level_info
gm.mapseenchn -> svm.mapseenchn
gm.moves -> svm.moves
gm.mvitals -> svm.mvitals
gn.n_dgns -> svn.n_dgns
gn.n_regions -> svn.n_regions
gn.nroom -> svn.nroom
go.oracle_cnt -> svo.oracle_cnt
gp.pl_character -> svp.pl_character
gp.pl_fruit -> svp.pl_fruit
gp.plname -> svp.plname
gp.program_state -> svp.program_state
gq.quest_status -> svq.quest_status
gr.rooms -> svr.rooms
gs.sp_levchn -> svs.sp_levchn
gs.spl_book -> svs.spl_book
gt.timer_id -> svt.timer_id
gt.tune -> svt.tune
gu.updest -> svu.updest
gx.xmax -> svx.xmax
gx.xmin -> svx.xmin
gy.ymax -> svy.ymax
gy.ymin -> svy.ymin
Related note:
There are some pointer variables that are heads of chains that were not
moved from 'g?' to 'sv?', because they are not actually written to the
savefile directly, but the objects/monst/trap/lightsource/timer in the
chains they point to are. That can be changed, if desired.
Examples: gi.invent, gm.migrating_objs, gb.billobjs, gm.migrating_mons,
gf.ftrap, gl.light_base, gt.timer_base
This commit is contained in:
146
src/spell.c
146
src/spell.c
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "hack.h"
|
||||
|
||||
/* spellmenu arguments; 0 thru n-1 used as gs.spl_book[] index when swapping */
|
||||
/* spellmenu arguments; 0 thru n-1 used as svs.spl_book[] index when swapping */
|
||||
#define SPELLMENU_CAST (-2)
|
||||
#define SPELLMENU_VIEW (-1)
|
||||
#define SPELLMENU_SORT (MAXSPELL) /* special menu entry */
|
||||
@@ -18,9 +18,9 @@
|
||||
initialization; spell memory is decremented at the end of each turn,
|
||||
including the turn on which the spellbook is read; without the extra
|
||||
increment, the hero used to get cheated out of 1 turn of retention */
|
||||
#define incrnknow(spell, x) (gs.spl_book[spell].sp_know = KEEN + (x))
|
||||
#define incrnknow(spell, x) (svs.spl_book[spell].sp_know = KEEN + (x))
|
||||
|
||||
#define spellev(spell) gs.spl_book[spell].sp_lev
|
||||
#define spellev(spell) svs.spl_book[spell].sp_lev
|
||||
#define spellname(spell) OBJ_NAME(objects[spellid(spell)])
|
||||
#define spellet(spell) \
|
||||
((char) ((spell < 26) ? ('a' + spell) : ('A' + spell - 26)))
|
||||
@@ -200,7 +200,7 @@ confused_book(struct obj *spellbook)
|
||||
gone = TRUE;
|
||||
} else {
|
||||
You("find yourself reading the %s line over and over again.",
|
||||
spellbook == gc.context.spbook.book ? "next" : "first");
|
||||
spellbook == svc.context.spbook.book ? "next" : "first");
|
||||
}
|
||||
return gone;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ deadbook(struct obj *book2)
|
||||
arti_cursed = TRUE;
|
||||
}
|
||||
if (otmp->otyp == BELL_OF_OPENING
|
||||
&& (gm.moves - otmp->age) < 5L) { /* you rang it recently */
|
||||
&& (svm.moves - otmp->age) < 5L) { /* you rang it recently */
|
||||
if (!otmp->cursed)
|
||||
arti2_primed = TRUE;
|
||||
else
|
||||
@@ -342,7 +342,7 @@ void
|
||||
book_cursed(struct obj *book)
|
||||
{
|
||||
if (book->cursed && gm.multi >= 0
|
||||
&& go.occupation == learn && gc.context.spbook.book == book) {
|
||||
&& go.occupation == learn && svc.context.spbook.book == book) {
|
||||
pline("%s shut!", Tobjnam(book, "slam"));
|
||||
set_bknown(book, 1);
|
||||
stop_occupation();
|
||||
@@ -358,25 +358,25 @@ learn(void)
|
||||
short booktype;
|
||||
char splname[BUFSZ];
|
||||
boolean costly = TRUE, faded_to_blank = FALSE;
|
||||
struct obj *book = gc.context.spbook.book;
|
||||
struct obj *book = svc.context.spbook.book;
|
||||
|
||||
/* JDS: lenses give 50% faster reading; 33% smaller read time */
|
||||
if (gc.context.spbook.delay && ublindf
|
||||
if (svc.context.spbook.delay && ublindf
|
||||
&& ublindf->otyp == LENSES && rn2(2))
|
||||
gc.context.spbook.delay++;
|
||||
svc.context.spbook.delay++;
|
||||
if (Confusion) { /* became confused while learning */
|
||||
(void) confused_book(book);
|
||||
gc.context.spbook.book = 0; /* no longer studying */
|
||||
gc.context.spbook.o_id = 0;
|
||||
nomul(gc.context.spbook.delay); /* remaining delay is uninterrupted */
|
||||
svc.context.spbook.book = 0; /* no longer studying */
|
||||
svc.context.spbook.o_id = 0;
|
||||
nomul(svc.context.spbook.delay); /* remaining delay is uninterrupted */
|
||||
gm.multi_reason = "reading a book";
|
||||
gn.nomovemsg = 0;
|
||||
gc.context.spbook.delay = 0;
|
||||
svc.context.spbook.delay = 0;
|
||||
return 0;
|
||||
}
|
||||
if (gc.context.spbook.delay) {
|
||||
/* not if (gc.context.spbook.delay++), so at end delay == 0 */
|
||||
gc.context.spbook.delay++;
|
||||
if (svc.context.spbook.delay) {
|
||||
/* not if (svc.context.spbook.delay++), so at end delay == 0 */
|
||||
svc.context.spbook.delay++;
|
||||
return 1; /* still busy */
|
||||
}
|
||||
exercise(A_WIS, TRUE); /* you're studying. */
|
||||
@@ -422,8 +422,8 @@ learn(void)
|
||||
/* reset spestudied as if polymorph had taken place */
|
||||
book->spestudied = rn2(book->spestudied);
|
||||
} else {
|
||||
gs.spl_book[i].sp_id = booktype;
|
||||
gs.spl_book[i].sp_lev = objects[booktype].oc_level;
|
||||
svs.spl_book[i].sp_id = booktype;
|
||||
svs.spl_book[i].sp_lev = objects[booktype].oc_level;
|
||||
incrnknow(i, 1);
|
||||
book->spestudied++;
|
||||
if (!i)
|
||||
@@ -449,15 +449,15 @@ learn(void)
|
||||
if (book->cursed) { /* maybe a demon cursed it */
|
||||
if (cursed_book(book)) {
|
||||
useup(book);
|
||||
gc.context.spbook.book = 0;
|
||||
gc.context.spbook.o_id = 0;
|
||||
svc.context.spbook.book = 0;
|
||||
svc.context.spbook.o_id = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (costly)
|
||||
check_unpaid(book);
|
||||
gc.context.spbook.book = 0;
|
||||
gc.context.spbook.o_id = 0;
|
||||
svc.context.spbook.book = 0;
|
||||
svc.context.spbook.o_id = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ study_book(struct obj *spellbook)
|
||||
int dullbook = rnd(25) - ACURR(A_WIS);
|
||||
|
||||
/* adjust chance if hero stayed awake, got interrupted, retries */
|
||||
if (gc.context.spbook.delay && spellbook == gc.context.spbook.book)
|
||||
if (svc.context.spbook.delay && spellbook == svc.context.spbook.book)
|
||||
dullbook -= rnd(objects[booktype].oc_level);
|
||||
|
||||
if (dullbook > 0) {
|
||||
@@ -492,10 +492,10 @@ study_book(struct obj *spellbook)
|
||||
}
|
||||
}
|
||||
|
||||
if (gc.context.spbook.delay && !confused
|
||||
&& spellbook == gc.context.spbook.book
|
||||
if (svc.context.spbook.delay && !confused
|
||||
&& spellbook == svc.context.spbook.book
|
||||
/* handle the sequence: start reading, get interrupted, have
|
||||
gc.context.spbook.book become erased somehow, resume reading it */
|
||||
svc.context.spbook.book become erased somehow, resume reading it */
|
||||
&& booktype != SPE_BLANK_PAPER) {
|
||||
You("continue your efforts to %s.",
|
||||
(booktype == SPE_NOVEL) ? "read the novel" : "memorize the spell");
|
||||
@@ -534,20 +534,20 @@ study_book(struct obj *spellbook)
|
||||
switch (objects[booktype].oc_level) {
|
||||
case 1:
|
||||
case 2:
|
||||
gc.context.spbook.delay = -objects[booktype].oc_delay;
|
||||
svc.context.spbook.delay = -objects[booktype].oc_delay;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
gc.context.spbook.delay = -(objects[booktype].oc_level - 1)
|
||||
svc.context.spbook.delay = -(objects[booktype].oc_level - 1)
|
||||
* objects[booktype].oc_delay;
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
gc.context.spbook.delay =
|
||||
svc.context.spbook.delay =
|
||||
-objects[booktype].oc_level * objects[booktype].oc_delay;
|
||||
break;
|
||||
case 7:
|
||||
gc.context.spbook.delay = -8 * objects[booktype].oc_delay;
|
||||
svc.context.spbook.delay = -8 * objects[booktype].oc_delay;
|
||||
break;
|
||||
default:
|
||||
impossible("Unknown spellbook level %d, book %d;",
|
||||
@@ -602,10 +602,10 @@ study_book(struct obj *spellbook)
|
||||
if (too_hard) {
|
||||
boolean gone = cursed_book(spellbook);
|
||||
|
||||
nomul(gc.context.spbook.delay); /* study time */
|
||||
nomul(svc.context.spbook.delay); /* study time */
|
||||
gm.multi_reason = "reading a book";
|
||||
gn.nomovemsg = 0;
|
||||
gc.context.spbook.delay = 0;
|
||||
svc.context.spbook.delay = 0;
|
||||
if (gone || !rn2(3)) {
|
||||
if (!gone)
|
||||
pline_The("spellbook crumbles to dust!");
|
||||
@@ -618,10 +618,10 @@ study_book(struct obj *spellbook)
|
||||
if (!confused_book(spellbook)) {
|
||||
spellbook->in_use = FALSE;
|
||||
}
|
||||
nomul(gc.context.spbook.delay);
|
||||
nomul(svc.context.spbook.delay);
|
||||
gm.multi_reason = "reading a book";
|
||||
gn.nomovemsg = 0;
|
||||
gc.context.spbook.delay = 0;
|
||||
svc.context.spbook.delay = 0;
|
||||
return 1;
|
||||
}
|
||||
spellbook->in_use = FALSE;
|
||||
@@ -630,9 +630,9 @@ study_book(struct obj *spellbook)
|
||||
spellbook->otyp == SPE_BOOK_OF_THE_DEAD ? "recite" : "memorize");
|
||||
}
|
||||
|
||||
gc.context.spbook.book = spellbook;
|
||||
if (gc.context.spbook.book)
|
||||
gc.context.spbook.o_id = gc.context.spbook.book->o_id;
|
||||
svc.context.spbook.book = spellbook;
|
||||
if (svc.context.spbook.book)
|
||||
svc.context.spbook.o_id = svc.context.spbook.book->o_id;
|
||||
set_occupation(learn, "studying", 0);
|
||||
return 1;
|
||||
}
|
||||
@@ -642,9 +642,9 @@ study_book(struct obj *spellbook)
|
||||
void
|
||||
book_disappears(struct obj *obj)
|
||||
{
|
||||
if (obj == gc.context.spbook.book) {
|
||||
gc.context.spbook.book = (struct obj *) 0;
|
||||
gc.context.spbook.o_id = 0;
|
||||
if (obj == svc.context.spbook.book) {
|
||||
svc.context.spbook.book = (struct obj *) 0;
|
||||
svc.context.spbook.o_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,10 +654,10 @@ book_disappears(struct obj *obj)
|
||||
void
|
||||
book_substitution(struct obj *old_obj, struct obj *new_obj)
|
||||
{
|
||||
if (old_obj == gc.context.spbook.book) {
|
||||
gc.context.spbook.book = new_obj;
|
||||
if (gc.context.spbook.book)
|
||||
gc.context.spbook.o_id = gc.context.spbook.book->o_id;
|
||||
if (old_obj == svc.context.spbook.book) {
|
||||
svc.context.spbook.book = new_obj;
|
||||
if (svc.context.spbook.book)
|
||||
svc.context.spbook.o_id = svc.context.spbook.book->o_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -814,7 +814,7 @@ docast(void)
|
||||
|
||||
if (getspell(&spell_no)) {
|
||||
cmdq_add_key(CQ_REPEAT, spellet(spell_no));
|
||||
return spelleffects(gs.spl_book[spell_no].sp_id, FALSE, FALSE);
|
||||
return spelleffects(svs.spl_book[spell_no].sp_id, FALSE, FALSE);
|
||||
}
|
||||
return ECMD_FAIL;
|
||||
}
|
||||
@@ -860,8 +860,8 @@ skill_based_spellbook_id(void)
|
||||
int booktype;
|
||||
const uchar spbook_class = (uchar) SPBOOK_CLASS;
|
||||
|
||||
for (booktype = gb.bases[spbook_class];
|
||||
booktype < gb.bases[spbook_class + 1];
|
||||
for (booktype = svb.bases[spbook_class];
|
||||
booktype < svb.bases[spbook_class + 1];
|
||||
booktype++) {
|
||||
int known_up_to_level;
|
||||
int skill = spell_skilltype(booktype);
|
||||
@@ -1051,9 +1051,9 @@ cast_chain_lightning(void)
|
||||
otherwise other monsters witnessing this would treat
|
||||
it as seeing hero attack a peaceful; mimic will be
|
||||
exposed; forcefight makes hider unhide */
|
||||
gc.context.forcefight++;
|
||||
svc.context.forcefight++;
|
||||
wakeup(mon, FALSE);
|
||||
gc.context.forcefight--;
|
||||
svc.context.forcefight--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1701,14 +1701,14 @@ tport_spell(int what)
|
||||
save_tport.tport_indx = MAXSPELL;
|
||||
} else if (what == UNHIDESPELL) {
|
||||
/*assert( save_tport.savespell.sp_id == SPE_TELEPORT_AWAY );*/
|
||||
gs.spl_book[save_tport.tport_indx] = save_tport.savespell;
|
||||
svs.spl_book[save_tport.tport_indx] = save_tport.savespell;
|
||||
save_tport.tport_indx = MAXSPELL; /* burn bridge... */
|
||||
} else if (what == ADD_SPELL) {
|
||||
save_tport.savespell = gs.spl_book[i];
|
||||
save_tport.savespell = svs.spl_book[i];
|
||||
save_tport.tport_indx = i;
|
||||
gs.spl_book[i].sp_id = SPE_TELEPORT_AWAY;
|
||||
gs.spl_book[i].sp_lev = objects[SPE_TELEPORT_AWAY].oc_level;
|
||||
gs.spl_book[i].sp_know = KEEN;
|
||||
svs.spl_book[i].sp_id = SPE_TELEPORT_AWAY;
|
||||
svs.spl_book[i].sp_lev = objects[SPE_TELEPORT_AWAY].oc_level;
|
||||
svs.spl_book[i].sp_know = KEEN;
|
||||
return REMOVESPELL; /* operation needed to reverse */
|
||||
}
|
||||
} else { /* spellid(i) == SPE_TELEPORT_AWAY */
|
||||
@@ -1716,12 +1716,12 @@ tport_spell(int what)
|
||||
save_tport.tport_indx = MAXSPELL;
|
||||
} else if (what == REMOVESPELL) {
|
||||
/*assert( i == save_tport.tport_indx );*/
|
||||
gs.spl_book[i] = save_tport.savespell;
|
||||
svs.spl_book[i] = save_tport.savespell;
|
||||
save_tport.tport_indx = MAXSPELL;
|
||||
} else if (what == HIDE_SPELL) {
|
||||
save_tport.savespell = gs.spl_book[i];
|
||||
save_tport.savespell = svs.spl_book[i];
|
||||
save_tport.tport_indx = i;
|
||||
gs.spl_book[i].sp_id = NO_SPELL;
|
||||
svs.spl_book[i].sp_id = NO_SPELL;
|
||||
return UNHIDESPELL; /* operation needed to reverse */
|
||||
}
|
||||
}
|
||||
@@ -1737,8 +1737,8 @@ losespells(void)
|
||||
int n, nzap, i;
|
||||
|
||||
/* in case reading has been interrupted earlier, discard context */
|
||||
gc.context.spbook.book = 0;
|
||||
gc.context.spbook.o_id = 0;
|
||||
svc.context.spbook.book = 0;
|
||||
svc.context.spbook.o_id = 0;
|
||||
/* count the number of known spells */
|
||||
for (n = 0; n < MAXSPELL; ++n)
|
||||
if (spellid(n) == NO_SPELL)
|
||||
@@ -1844,13 +1844,13 @@ spell_cmp(const genericptr vptr1, const genericptr vptr2)
|
||||
/*
|
||||
* gather up all of the possible parameters except spell name
|
||||
* in advance, even though some might not be needed:
|
||||
* indx. = spl_orderindx[] index into gs.spl_book[];
|
||||
* otyp. = gs.spl_book[] index into objects[];
|
||||
* indx. = spl_orderindx[] index into svs.spl_book[];
|
||||
* otyp. = svs.spl_book[] index into objects[];
|
||||
* levl. = spell level;
|
||||
* skil. = skill group aka spell class.
|
||||
*/
|
||||
int indx1 = *(int *) vptr1, indx2 = *(int *) vptr2,
|
||||
otyp1 = gs.spl_book[indx1].sp_id, otyp2 = gs.spl_book[indx2].sp_id,
|
||||
otyp1 = svs.spl_book[indx1].sp_id, otyp2 = svs.spl_book[indx2].sp_id,
|
||||
levl1 = objects[otyp1].oc_level, levl2 = objects[otyp2].oc_level,
|
||||
skil1 = objects[otyp1].oc_skill, skil2 = objects[otyp2].oc_skill;
|
||||
|
||||
@@ -1926,13 +1926,13 @@ sortspells(void)
|
||||
if (gs.spl_sortmode == SORTRETAINORDER) {
|
||||
struct spell tmp_book[MAXSPELL];
|
||||
|
||||
/* sort gs.spl_book[] rather than spl_orderindx[];
|
||||
/* sort svs.spl_book[] rather than spl_orderindx[];
|
||||
this also updates the index to reflect the new ordering (we
|
||||
could just free it since that ordering becomes the default) */
|
||||
for (i = 0; i < MAXSPELL; i++)
|
||||
tmp_book[i] = gs.spl_book[gs.spl_orderindx[i]];
|
||||
tmp_book[i] = svs.spl_book[gs.spl_orderindx[i]];
|
||||
for (i = 0; i < MAXSPELL; i++)
|
||||
gs.spl_book[i] = tmp_book[i], gs.spl_orderindx[i] = i;
|
||||
svs.spl_book[i] = tmp_book[i], gs.spl_orderindx[i] = i;
|
||||
gs.spl_sortmode = SORTBY_LETTER; /* reset */
|
||||
return;
|
||||
}
|
||||
@@ -2010,9 +2010,9 @@ dovspell(void)
|
||||
if (!dospellmenu(qbuf, splnum, &othnum))
|
||||
break;
|
||||
|
||||
spl_tmp = gs.spl_book[splnum];
|
||||
gs.spl_book[splnum] = gs.spl_book[othnum];
|
||||
gs.spl_book[othnum] = spl_tmp;
|
||||
spl_tmp = svs.spl_book[splnum];
|
||||
svs.spl_book[splnum] = svs.spl_book[othnum];
|
||||
svs.spl_book[othnum] = spl_tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2032,7 +2032,7 @@ DISABLE_WARNING_FORMAT_NONLITERAL
|
||||
staticfn boolean
|
||||
dospellmenu(
|
||||
const char *prompt,
|
||||
int splaction, /* SPELLMENU_CAST, SPELLMENU_VIEW, or gs.spl_book[] index */
|
||||
int splaction, /* SPELLMENU_CAST, SPELLMENU_VIEW, or svs.spl_book[] index */
|
||||
int *spell_no)
|
||||
{
|
||||
winid tmpwin;
|
||||
@@ -2304,8 +2304,8 @@ initialspell(struct obj *obj)
|
||||
/* initial inventory shouldn't contain duplicate spellbooks */
|
||||
impossible("Spell %s already known.", OBJ_NAME(objects[otyp]));
|
||||
} else {
|
||||
gs.spl_book[i].sp_id = otyp;
|
||||
gs.spl_book[i].sp_lev = objects[otyp].oc_level;
|
||||
svs.spl_book[i].sp_id = otyp;
|
||||
svs.spl_book[i].sp_lev = objects[otyp].oc_level;
|
||||
incrnknow(i, 0);
|
||||
}
|
||||
return;
|
||||
@@ -2358,8 +2358,8 @@ force_learn_spell(short otyp)
|
||||
}
|
||||
/* for a going-stale or forgotten spell the sp_id and sp_lev assignments
|
||||
are redundant but harmless; for an unknown spell, they're essential */
|
||||
gs.spl_book[i].sp_id = otyp;
|
||||
gs.spl_book[i].sp_lev = objects[otyp].oc_level;
|
||||
svs.spl_book[i].sp_id = otyp;
|
||||
svs.spl_book[i].sp_lev = objects[otyp].oc_level;
|
||||
incrnknow(i, 0); /* set spl_book[i].sp_know to KEEN; unlike when learning
|
||||
* a spell by reading its book, we don't need to add 1 */
|
||||
return spellet(i);
|
||||
|
||||
Reference in New Issue
Block a user