arogue7, xrogue: improve the handling of the arguments to fuses.

fuse() now expects a pointer as the argument to a fuse function.  If
this is one of the functions that takes int, fuse() follows the pointer
and stores that value in the f_list slot, in the integer field of the
argument union.  When the fuse goes off, do_fuses() recognizes the
function and passes it the integer field instead of the pointer.

This has the disadvantage of hard-coding the functions that require int
in daemon.c, but since the int is copied into f_list, it no longer has
to be in static or global memory, which simplifies several files.
This commit is contained in:
John "Elwin" Edwards 2016-03-11 17:40:00 -05:00
parent dafa5cc722
commit 758c6b1bf0
21 changed files with 147 additions and 124 deletions

View file

@ -172,7 +172,10 @@ fuse(void (*dfunc)(), void *arg, int time, int type)
if (wire != NULL) {
wire->d_type = type;
wire->d_func = dfunc;
wire->d_arg.vp = arg;
if (dfunc == changeclass || dfunc == res_strength)
wire->d_arg.i = *(int *) arg;
else
wire->d_arg.vp = arg;
wire->d_time = time;
fusecnt += 1; /* update count */
}
@ -220,26 +223,28 @@ extinguish(void (*dfunc)())
void
do_fuses(int flag)
{
struct delayed_action *wire;
int i;
struct delayed_action *wire;
int i;
/*
* Step though the list
*/
for (i = 0; i < MAXFUSES; i++) {
wire = &f_list[i];
/*
* Step though the list
*/
for (i = 0; i < MAXFUSES; i++) {
wire = &f_list[i];
/*
* Decrementing counters and starting things we want. We also need
* to remove the fuse from the list once it has gone off.
*/
if(flag == wire->d_type && wire->d_time > 0 &&
if(flag == wire->d_type && wire->d_time > 0 &&
--wire->d_time == 0) {
wire->d_type = EMPTY;
if (wire->d_func != NULL)
(*wire->d_func)(wire->d_arg.vp);
fusecnt -= 1;
}
wire->d_type = EMPTY;
if (*wire->d_func == changeclass || *wire->d_func == res_strength)
(*wire->d_func)(wire->d_arg.i);
else if (wire->d_func != NULL)
(*wire->d_func)(wire->d_arg.vp);
fusecnt -= 1;
}
}
}
/*

View file

@ -323,8 +323,10 @@ effect(struct thing *att, struct thing *def, struct object *weap, bool thrown,
msg("You cringe at %s's chilling touch.",
prname(attname, FALSE));
chg_str(-1);
if (lost_str++ == 0)
fuse(res_strength, NULL, CHILLTIME, AFTER);
if (lost_str++ == 0) {
int temp_arg = 0;
fuse(res_strength, &temp_arg, CHILLTIME, AFTER);
}
else lengthen(res_strength, CHILLTIME);
}
}
@ -548,11 +550,12 @@ effect(struct thing *att, struct thing *def, struct object *weap, bool thrown,
else {
int odor_str = -(rnd(6)+1);
int temp_arg2 = 0;
msg("You are overcome by a foul odor!");
if (lost_str == 0) {
chg_str(odor_str);
fuse(res_strength, NULL, SMELLTIME, AFTER);
fuse(res_strength, &temp_arg2, SMELLTIME, AFTER);
lost_str -= odor_str;
}
else lengthen(res_strength, SMELLTIME);

View file

@ -966,7 +966,6 @@ killed(struct linked_list *item, bool pr, bool points, bool treasure)
register struct linked_list *pitem, *nexti, *mitem;
char *monst;
int adj; /* used for hit point adj. below. */
long temp;
tp = THINGPTR(item);
@ -1029,8 +1028,7 @@ killed(struct linked_list *item, bool pr, bool points, bool treasure)
if (roll(1,100) < killed_chance) {
msg("You had a feeling this was going to happen... ");
msg("**POOF** ");
temp = C_ASSASSIN; /* make him pay */
changeclass(&temp);
changeclass(C_ASSASSIN); /* make him pay */
}
else {
switch (rnd(9)) {

View file

@ -24,9 +24,9 @@
*/
void
changeclass(long *newclass)
changeclass(int newclass)
{
if (*newclass == player.t_ctype) {
if (newclass == player.t_ctype) {
msg("You feel more skillful.");
raise_level();
}
@ -38,19 +38,19 @@ changeclass(long *newclass)
*/
long save;
msg("You are transformed into a %s! ", char_class[*newclass].name);
msg("You are transformed into a %s! ", char_class[newclass].name);
/*
* if he becomes a thief or an assassin give him studded leather armor
*/
if ((*newclass == C_THIEF || *newclass == C_ASSASSIN) &&
if ((newclass == C_THIEF || newclass == C_ASSASSIN) &&
cur_armor != NULL && cur_armor->o_which != STUDDED_LEATHER)
cur_armor->o_which = STUDDED_LEATHER;
/*
* if he becomes a monk he can't wear any armor
* so give him a cloak of protection
*/
if (*newclass == C_MONK && cur_armor != NULL) {
if (newclass == C_MONK && cur_armor != NULL) {
cur_armor->o_ac = armors[cur_armor->o_which].a_class -
cur_armor->o_ac;
cur_armor->o_type = MM;
@ -62,8 +62,8 @@ changeclass(long *newclass)
/*
* otherwise give him plate armor
*/
if ((*newclass != C_THIEF ||
*newclass != C_ASSASSIN || *newclass != C_MONK) &&
if ((newclass != C_THIEF ||
newclass != C_ASSASSIN || newclass != C_MONK) &&
cur_armor != NULL && cur_armor->o_which != PLATE_ARMOR)
cur_armor->o_which = PLATE_ARMOR;
@ -81,11 +81,11 @@ changeclass(long *newclass)
/*
* if he becomes a spell caster of some kind, give him a fuse
*/
if (*newclass == C_MAGICIAN || *newclass == C_RANGER)
if (newclass == C_MAGICIAN || newclass == C_RANGER)
fuse(spell_recovery, NULL, SPELLTIME, AFTER);
if (*newclass == C_DRUID || *newclass == C_MONK)
if (newclass == C_DRUID || newclass == C_MONK)
fuse(chant_recovery, NULL, SPELLTIME, AFTER);
if ((*newclass==C_CLERIC || *newclass==C_PALADIN) && !cur_misc[HEIL_ANKH])
if ((newclass==C_CLERIC || newclass==C_PALADIN) && !cur_misc[HEIL_ANKH])
fuse(prayer_recovery, NULL, SPELLTIME, AFTER);
/*
* if he's changing from a fighter, ranger, or paladin then we
@ -98,8 +98,8 @@ changeclass(long *newclass)
cur_weapon != NULL && cur_weapon->o_type == WEAPON &&
(cur_weapon->o_which == BASWORD ||
cur_weapon->o_which == TWOSWORD) &&
!(*newclass == C_FIGHTER || *newclass == C_RANGER ||
*newclass == C_PALADIN) &&
!(newclass == C_FIGHTER || newclass == C_RANGER ||
newclass == C_PALADIN) &&
cur_weapon->o_which == TWOSWORD)
cur_weapon->o_which = SWORD;
@ -113,8 +113,8 @@ changeclass(long *newclass)
cur_weapon != NULL && cur_weapon->o_type == WEAPON &&
(cur_weapon->o_which == BASWORD ||
cur_weapon->o_which == TWOSWORD) &&
!(*newclass == C_THIEF || *newclass == C_ASSASSIN ||
*newclass == C_MONK) &&
!(newclass == C_THIEF || newclass == C_ASSASSIN ||
newclass == C_MONK) &&
cur_weapon->o_which == BASWORD)
cur_weapon->o_which = SWORD;
@ -130,12 +130,12 @@ changeclass(long *newclass)
* if he becomes a thief, assassin, or monk then add
* the trap_look() daemon
*/
if (*newclass == C_THIEF || *newclass == C_ASSASSIN ||
*newclass == C_MONK)
if (newclass == C_THIEF || newclass == C_ASSASSIN ||
newclass == C_MONK)
start_daemon(trap_look, NULL, AFTER);
/* adjust stats */
char_type = player.t_ctype = *newclass;
char_type = player.t_ctype = newclass;
save = pstats.s_hpt;
max_stats.s_hpt = pstats.s_hpt = 0;
max_stats.s_lvl = pstats.s_lvl = 0;
@ -1103,7 +1103,7 @@ use_mm(int which)
when MM_SKILLS:
detach (pack, item);
inpack--;
changeclass(&obj->o_ac);
changeclass(obj->o_ac);
when MM_CRYSTAL:
{
register char *str;

View file

@ -36,15 +36,7 @@ add_pack(struct linked_list *item, bool silent)
register struct object *obj, *op = NULL;
register bool exact, from_floor;
bool giveflag = 0;
static long cleric = C_CLERIC,
monk = C_MONK,
magician = C_MAGICIAN,
assassin = C_ASSASSIN,
druid = C_DRUID,
thief = C_THIEF,
fighter = C_FIGHTER,
ranger = C_RANGER,
paladin = C_PALADIN;
int newclass;
if (item == NULL)
{
@ -263,8 +255,10 @@ picked_up:
/* start a fuse to change player into a paladin */
if (quest_item != HEIL_ANKH) {
msg("You hear a strange, distant hypnotic calling... ");
if (player.t_ctype != C_PALADIN && obj->o_which ==HEIL_ANKH)
fuse(changeclass, &paladin, roll(8, 8), AFTER);
if (player.t_ctype != C_PALADIN && obj->o_which ==HEIL_ANKH) {
newclass = C_PALADIN;
fuse(changeclass, &newclass, roll(8, 8), AFTER);
}
}
/* A cloak must be worn. */
@ -287,8 +281,10 @@ picked_up:
/* start a fuse to change player into a monk */
if (quest_item != EMORI_CLOAK) {
msg("You suddenly become calm and quiet. ");
if (player.t_ctype != C_MONK && obj->o_which == EMORI_CLOAK)
fuse(changeclass, &monk, roll(8, 8), AFTER);
if (player.t_ctype != C_MONK && obj->o_which == EMORI_CLOAK) {
newclass = C_MONK;
fuse(changeclass, &newclass, roll(8, 8), AFTER);
}
}
/* The amulet must be worn. */
@ -312,7 +308,8 @@ picked_up:
if (player.t_ctype != C_MAGICIAN &&
obj->o_which == STONEBONES_AMULET) {
msg("You sense approaching etheric forces... ");
fuse(changeclass, &magician, roll(8, 8), AFTER);
newclass = C_MAGICIAN;
fuse(changeclass, &newclass, roll(8, 8), AFTER);
}
}
@ -331,8 +328,10 @@ picked_up:
/* start a fuse to change player into an assassin */
if (quest_item != EYE_VECNA) {
msg("Your blood rushes and you begin to sweat profusely... ");
if (player.t_ctype != C_ASSASSIN && obj->o_which == EYE_VECNA)
fuse(changeclass, &assassin, roll(8, 8), AFTER);
if (player.t_ctype != C_ASSASSIN && obj->o_which == EYE_VECNA) {
newclass = C_ASSASSIN;
fuse(changeclass, &newclass, roll(8, 8), AFTER);
}
}
when QUILL_NAGROM:
@ -340,8 +339,10 @@ picked_up:
/* start a fuse to change player into a druid */
if (quest_item != QUILL_NAGROM) {
msg("You begin to see things differently... ");
if (player.t_ctype != C_DRUID && obj->o_which == QUILL_NAGROM)
fuse(changeclass, &druid, roll(8, 8), AFTER);
if (player.t_ctype != C_DRUID && obj->o_which == QUILL_NAGROM) {
newclass = C_DRUID;
fuse(changeclass, &newclass, roll(8, 8), AFTER);
}
}
/* Weapons will insist on being wielded. */
@ -362,7 +363,8 @@ picked_up:
if (player.t_ctype != C_THIEF &&
obj->o_which == MUSTY_DAGGER) {
msg("You look about furtively. ");
fuse(changeclass, &thief, roll(8, 8), AFTER);
newclass = C_THIEF;
fuse(changeclass, &newclass, roll(8, 8), AFTER);
}
}
/* start a fuse to change player into a fighter */
@ -370,7 +372,8 @@ picked_up:
if (player.t_ctype != C_FIGHTER &&
obj->o_which == AXE_AKLAD) {
msg("Your bones feel strengthened. ");
fuse(changeclass, &fighter, roll(8, 8), AFTER);
newclass = C_FIGHTER;
fuse(changeclass, &newclass, roll(8, 8), AFTER);
}
}
if (cur_weapon != NULL) {
@ -405,8 +408,10 @@ picked_up:
/* start a fuse to change player into a ranger */
if (quest_item != BRIAN_MANDOLIN) {
msg("You are transfixed with empathy. ");
if (player.t_ctype != C_RANGER && obj->o_which == BRIAN_MANDOLIN)
fuse(changeclass, &ranger, roll(8, 8), AFTER);
if (player.t_ctype != C_RANGER && obj->o_which == BRIAN_MANDOLIN) {
newclass = C_RANGER;
fuse(changeclass, &newclass, roll(8, 8), AFTER);
}
}
/* add to the music */
@ -415,8 +420,10 @@ picked_up:
/* start a fuse to change player into a cleric */
if (quest_item != GERYON_HORN) {
msg("You follow their calling. ");
if (player.t_ctype != C_CLERIC && obj->o_which == GERYON_HORN)
fuse(changeclass, &cleric, roll(8, 8), AFTER);
if (player.t_ctype != C_CLERIC && obj->o_which == GERYON_HORN) {
newclass = C_CLERIC;
fuse(changeclass, &newclass, roll(8, 8), AFTER);
}
}
/* the card can not be picked up, it must be traded for */

View file

@ -1245,7 +1245,7 @@ int can_shoot(coord *er, coord *ee, coord *shoot_dir);
bool cansee(int y, int x);
void carry_obj(struct thing *mp, int chance);
void cast(void);
void changeclass(long *newclass);
void changeclass(int newclass);
void chant(void);
void chant_recovery(void);
void chase(struct thing *tp, coord *ee, struct room *rer, struct room *ree,