changeset 238:e1cd27c5464f

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.
author John "Elwin" Edwards
date Fri, 11 Mar 2016 17:40:00 -0500
parents 2236ef808bcb
children 837044d2c362
files arogue7/daemon.c arogue7/daemons.c arogue7/effects.c arogue7/encumb.c arogue7/fight.c arogue7/main.c arogue7/misc.c arogue7/monsters.c arogue7/pack.c arogue7/potions.c arogue7/rings.c arogue7/rogue.h arogue7/sticks.c arogue7/util.c arogue7/wear.c xrogue/daemon.c xrogue/effects.c xrogue/fight.c xrogue/misc.c xrogue/pack.c xrogue/rogue.h
diffstat 21 files changed, 147 insertions(+), 124 deletions(-) [+]
line wrap: on
line diff
--- a/arogue7/daemon.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/arogue7/daemon.c	Fri Mar 11 17:40:00 2016 -0500
@@ -95,7 +95,7 @@
  *	Start a daemon, takes a function.
  */
 void
-start_daemon(void (*func)(), int arg, int type)
+start_daemon(void (*func)(), void *arg, int type)
 {
 	reg struct delayed_action *dev;
 
@@ -103,7 +103,7 @@
 	if (dev != NULL) {
 		dev->d_type = type;
 		dev->d_func = func;
-		dev->d_.arg = arg;
+		dev->d_.varg = arg;
 		dev->d_time = DAEMON;
 		demoncnt += 1;			/* update count */
 	}
@@ -154,7 +154,7 @@
 	 * Executing each one, giving it the proper arguments
 	 */
 		if (dev->d_type == flag && dev->d_time == DAEMON)
-			(*dev->d_func)(dev->d_.arg);
+			(*dev->d_func)(dev->d_.varg);
 }
 
 
@@ -163,7 +163,7 @@
  *	Start a fuse to go off in a certain number of turns
  */
 void
-fuse(void (*func)(), int arg, int time, int type)
+fuse(void (*func)(), void *arg, int time, int type)
 {
 	reg struct delayed_action *wire;
 
@@ -171,7 +171,10 @@
 	if (wire != NULL) {
 		wire->d_type = type;
 		wire->d_func = func;
-		wire->d_.arg = arg;
+		if (func == changeclass || func == res_strength)
+			wire->d_.arg = *(int *) arg;
+		else
+			wire->d_.varg = arg;
 		wire->d_time = time;
 		fusecnt += 1;			/* update count */
 	}
@@ -232,8 +235,10 @@
 	    if(flag == wire->d_type && wire->d_time > 0	&&
 	      --wire->d_time == 0) {
 		wire->d_type = EMPTY;
-		if (wire->d_func != NULL)
+		if (wire->d_func == changeclass || wire->d_func == res_strength)
 		    (*wire->d_func)(wire->d_.arg);
+		else if (wire->d_func != NULL)
+		    (*wire->d_func)(wire->d_.varg);
 		fusecnt -= 1;
 	    }
 	}
--- a/arogue7/daemons.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/arogue7/daemons.c	Fri Mar 11 17:40:00 2016 -0500
@@ -111,7 +111,7 @@
 void
 swander(void)
 {
-    start_daemon(rollwand, 0, BEFORE);
+    start_daemon(rollwand, NULL, BEFORE);
 }
 
 /*
@@ -134,7 +134,7 @@
 	    if (levtype != POSTLEV)
 	        wanderer();
 	    kill_daemon(rollwand);
-	    fuse(swander, 0, WANDERTIME, BEFORE);
+	    fuse(swander, NULL, WANDERTIME, BEFORE);
 	}
 	between = 0;
     }
@@ -663,7 +663,7 @@
     time = SPELLTIME - max(17-pstats.s_intel, 0);
     time = max(time, 5);
     if (spell_power > 0) spell_power--;
-    fuse(spell_recovery, 0, time, AFTER);
+    fuse(spell_recovery, NULL, time, AFTER);
 }
 /*
  * give the hero back some prayer points
@@ -676,7 +676,7 @@
     time = SPELLTIME - max(17-pstats.s_wisdom, 0);
     time = max(time, 5);
     if (pray_time > 0) pray_time--;
-    fuse(prayer_recovery, 0, time, AFTER);
+    fuse(prayer_recovery, NULL, time, AFTER);
 }
 /*
  * give the hero back some chant points
@@ -689,5 +689,5 @@
     time = SPELLTIME - max(17-pstats.s_wisdom, 0);
     time = max(time, 5);
     if (chant_time > 0) chant_time--;
-    fuse(chant_recovery, 0, time, AFTER);
+    fuse(chant_recovery, NULL, time, AFTER);
 }
--- a/arogue7/effects.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/arogue7/effects.c	Fri Mar 11 17:40:00 2016 -0500
@@ -294,7 +294,7 @@
 		    if (on(player, HASSTINK)) lengthen(unstink, STINKTIME);
 		    else {
 			turn_on(player, HASSTINK);
-			fuse(unstink, 0, STINKTIME, AFTER);
+			fuse(unstink, NULL, STINKTIME, AFTER);
 		    }
 		}
 	    }
@@ -308,8 +308,10 @@
 		    msg("You cringe at %s's chilling touch.",
 				prname(attname, FALSE));
 		    chg_str(-1);
-		    if (lost_str++ == 0)
-			fuse(res_strength, 0, CHILLTIME, AFTER);
+		    if (lost_str++ == 0) {
+			int fuse_arg = 0;
+			fuse(res_strength, &fuse_arg, CHILLTIME, AFTER);
+		    }
 		    else lengthen(res_strength, CHILLTIME);
 		}
 	    }
@@ -344,7 +346,7 @@
 		    }
 		    else {
 			turn_on(*def, HASDISEASE);
-			fuse(cure_disease, 0, roll(HEALTIME,SICKTIME), AFTER);
+			fuse(cure_disease, NULL, roll(HEALTIME,SICKTIME), AFTER);
 			msg(terse ? "You have been diseased."
 			    : "You have contracted a disease!");
 		    }
@@ -478,7 +480,7 @@
 		    turn_off(*att, CANDANCE);
 		    turn_on(*def, ISDANCE);
 		    msg("You begin to dance uncontrollably!");
-		    fuse(undance, 0, roll(2,4), AFTER);
+		    fuse(undance, NULL, roll(2,4), AFTER);
 	    }
 
 	    /*
@@ -491,7 +493,7 @@
 		(find_slot(suffocate) == 0)) {
 		turn_on(*att, DIDSUFFOCATE);
 		msg("%s is beginning to suffocate you.", prname(attname, TRUE));
-		fuse(suffocate, 0, roll(9,3), AFTER);
+		fuse(suffocate, NULL, roll(9,3), AFTER);
 	    }
 
 	    /*
@@ -530,11 +532,11 @@
 		    msg("You smell an unpleasant odor.");
 		else {
 		    int odor_str = -(rnd(6)+1);
-
+		    int fuse_arg2 = 0;
 		    msg("You are overcome by a foul odor.");
 		    if (lost_str == 0) {
 			chg_str(odor_str);
-			fuse(res_strength, 0, SMELLTIME, AFTER);
+			fuse(res_strength, &fuse_arg2, SMELLTIME, AFTER);
 			lost_str -= odor_str;
 		    }
 		    else lengthen(res_strength, SMELLTIME);
--- a/arogue7/encumb.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/arogue7/encumb.c	Fri Mar 11 17:40:00 2016 -0500
@@ -174,7 +174,7 @@
 	    ch = CCHAR( mvwinch(stdscr, hero.y, hero.x) );
 	    if((ch != FLOOR && ch != PASSAGE)) {
 		extinguish(wghtchk);
-		fuse(wghtchk,TRUE,1,AFTER);
+		fuse(wghtchk, NULL, 1, AFTER);
 		inwhgt = FALSE;
 		return;
 	    }
--- a/arogue7/fight.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/arogue7/fight.c	Fri Mar 11 17:40:00 2016 -0500
@@ -538,7 +538,7 @@
 			if (find_slot(unconfuse))
 			    lengthen(unconfuse, HUHDURATION);
 			else
-			    fuse(unconfuse, 0, HUHDURATION, AFTER);
+			    fuse(unconfuse, NULL, HUHDURATION, AFTER);
 			turn_on(player, ISHUH);
 		    }
 		    else msg("You feel dizzy, but it quickly passes.");
--- a/arogue7/main.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/arogue7/main.c	Fri Mar 11 17:40:00 2016 -0500
@@ -393,18 +393,18 @@
      * Start up daemons and fuses
      */
     start_daemon(doctor, &player, AFTER);
-    fuse(swander, 0, WANDERTIME, AFTER);
+    fuse(swander, NULL, WANDERTIME, AFTER);
     if (player.t_ctype == C_MAGICIAN || player.t_ctype == C_RANGER)
-	    fuse(spell_recovery, 0, SPELLTIME, AFTER);
+	    fuse(spell_recovery, NULL, SPELLTIME, AFTER);
     if (player.t_ctype == C_DRUID || player.t_ctype == C_RANGER)
-	    fuse(chant_recovery, 0, SPELLTIME, AFTER);
+	    fuse(chant_recovery, NULL, SPELLTIME, AFTER);
     if (player.t_ctype == C_CLERIC || player.t_ctype == C_PALADIN)
-	    fuse(prayer_recovery, 0, SPELLTIME, AFTER);
-    start_daemon(stomach, 0, AFTER);
+	    fuse(prayer_recovery, NULL, SPELLTIME, AFTER);
+    start_daemon(stomach, NULL, AFTER);
     if (player.t_ctype == C_THIEF	||
 	player.t_ctype == C_ASSASIN	||
 	player.t_ctype == C_MONK)
-	    start_daemon(trap_look, 0, AFTER);
+	    start_daemon(trap_look, NULL, AFTER);
 
     /* Does this character have any special knowledge? */
     switch (player.t_ctype) {
--- a/arogue7/misc.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/arogue7/misc.c	Fri Mar 11 17:40:00 2016 -0500
@@ -81,11 +81,11 @@