diff xrogue/pack.c @ 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 7c1cb43f346e
children
line wrap: on
line diff
--- a/xrogue/pack.c	Tue Mar 08 20:47:57 2016 -0500
+++ b/xrogue/pack.c	Fri Mar 11 17:40:00 2016 -0500
@@ -36,15 +36,7 @@
     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 @@
         /* 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 @@
         /* 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 @@
             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 @@
         /* 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 @@
         /* 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 @@
             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 @@
             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 @@
         /* 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 @@
         /* 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 */