comparison xrogue/misc.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
comparison
equal deleted inserted replaced
237:2236ef808bcb 238:e1cd27c5464f
22 * changeclass: 22 * changeclass:
23 * Change the player's class to the specified one. 23 * Change the player's class to the specified one.
24 */ 24 */
25 25
26 void 26 void
27 changeclass(long *newclass) 27 changeclass(int newclass)
28 { 28 {
29 if (*newclass == player.t_ctype) { 29 if (newclass == player.t_ctype) {
30 msg("You feel more skillful."); 30 msg("You feel more skillful.");
31 raise_level(); 31 raise_level();
32 } 32 }
33 else { 33 else {
34 /* 34 /*
36 * points and the right level for his exp pts 36 * points and the right level for his exp pts
37 * drop exp pts by 10% 37 * drop exp pts by 10%
38 */ 38 */
39 long save; 39 long save;
40 40
41 msg("You are transformed into a %s! ", char_class[*newclass].name); 41 msg("You are transformed into a %s! ", char_class[newclass].name);
42 42
43 /* 43 /*
44 * if he becomes a thief or an assassin give him studded leather armor 44 * if he becomes a thief or an assassin give him studded leather armor
45 */ 45 */
46 if ((*newclass == C_THIEF || *newclass == C_ASSASSIN) && 46 if ((newclass == C_THIEF || newclass == C_ASSASSIN) &&
47 cur_armor != NULL && cur_armor->o_which != STUDDED_LEATHER) 47 cur_armor != NULL && cur_armor->o_which != STUDDED_LEATHER)
48 cur_armor->o_which = STUDDED_LEATHER; 48 cur_armor->o_which = STUDDED_LEATHER;
49 /* 49 /*
50 * if he becomes a monk he can't wear any armor 50 * if he becomes a monk he can't wear any armor
51 * so give him a cloak of protection 51 * so give him a cloak of protection
52 */ 52 */
53 if (*newclass == C_MONK && cur_armor != NULL) { 53 if (newclass == C_MONK && cur_armor != NULL) {
54 cur_armor->o_ac = armors[cur_armor->o_which].a_class - 54 cur_armor->o_ac = armors[cur_armor->o_which].a_class -
55 cur_armor->o_ac; 55 cur_armor->o_ac;
56 cur_armor->o_type = MM; 56 cur_armor->o_type = MM;
57 cur_armor->o_which = MM_PROTECT; 57 cur_armor->o_which = MM_PROTECT;
58 cur_armor->o_flags &= ~(ISPROT | ISKNOW); 58 cur_armor->o_flags &= ~(ISPROT | ISKNOW);
60 cur_armor = NULL; 60 cur_armor = NULL;
61 } 61 }
62 /* 62 /*
63 * otherwise give him plate armor 63 * otherwise give him plate armor
64 */ 64 */
65 if ((*newclass != C_THIEF || 65 if ((newclass != C_THIEF ||
66 *newclass != C_ASSASSIN || *newclass != C_MONK) && 66 newclass != C_ASSASSIN || newclass != C_MONK) &&
67 cur_armor != NULL && cur_armor->o_which != PLATE_ARMOR) 67 cur_armor != NULL && cur_armor->o_which != PLATE_ARMOR)
68 cur_armor->o_which = PLATE_ARMOR; 68 cur_armor->o_which = PLATE_ARMOR;
69 69
70 /* 70 /*
71 * if he used to be a spell caster of some sort, kill the fuse 71 * if he used to be a spell caster of some sort, kill the fuse
79 extinguish(prayer_recovery); 79 extinguish(prayer_recovery);
80 80
81 /* 81 /*
82 * if he becomes a spell caster of some kind, give him a fuse 82 * if he becomes a spell caster of some kind, give him a fuse
83 */ 83 */
84 if (*newclass == C_MAGICIAN || *newclass == C_RANGER) 84 if (newclass == C_MAGICIAN || newclass == C_RANGER)
85 fuse(spell_recovery, NULL, SPELLTIME, AFTER); 85 fuse(spell_recovery, NULL, SPELLTIME, AFTER);
86 if (*newclass == C_DRUID || *newclass == C_MONK) 86 if (newclass == C_DRUID || newclass == C_MONK)
87 fuse(chant_recovery, NULL, SPELLTIME, AFTER); 87 fuse(chant_recovery, NULL, SPELLTIME, AFTER);
88 if ((*newclass==C_CLERIC || *newclass==C_PALADIN) && !cur_misc[HEIL_ANKH]) 88 if ((newclass==C_CLERIC || newclass==C_PALADIN) && !cur_misc[HEIL_ANKH])
89 fuse(prayer_recovery, NULL, SPELLTIME, AFTER); 89 fuse(prayer_recovery, NULL, SPELLTIME, AFTER);
90 /* 90 /*
91 * if he's changing from a fighter, ranger, or paladin then we 91 * if he's changing from a fighter, ranger, or paladin then we
92 * may have to change his sword since only these types can wield 92 * may have to change his sword since only these types can wield
93 * the two-handed sword. 93 * the two-handed sword.
96 player.t_ctype == C_RANGER || 96 player.t_ctype == C_RANGER ||
97 player.t_ctype == C_PALADIN) && 97 player.t_ctype == C_PALADIN) &&
98 cur_weapon != NULL && cur_weapon->o_type == WEAPON && 98 cur_weapon != NULL && cur_weapon->o_type == WEAPON &&
99 (cur_weapon->o_which == BASWORD || 99 (cur_weapon->o_which == BASWORD ||
100 cur_weapon->o_which == TWOSWORD) && 100 cur_weapon->o_which == TWOSWORD) &&
101 !(*newclass == C_FIGHTER || *newclass == C_RANGER || 101 !(newclass == C_FIGHTER || newclass == C_RANGER ||
102 *newclass == C_PALADIN) && 102 newclass == C_PALADIN) &&
103 cur_weapon->o_which == TWOSWORD) 103 cur_weapon->o_which == TWOSWORD)
104 cur_weapon->o_which = SWORD; 104 cur_weapon->o_which = SWORD;
105 105
106 /* 106 /*
107 * if he's changing from a thief, assassin, fighter, or monk 107 * if he's changing from a thief, assassin, fighter, or monk
111 if ((player.t_ctype == C_THIEF || player.t_ctype == C_ASSASSIN || 111 if ((player.t_ctype == C_THIEF || player.t_ctype == C_ASSASSIN ||
112 player.t_ctype == C_FIGHTER || player.t_ctype == C_MONK) && 112 player.t_ctype == C_FIGHTER || player.t_ctype == C_MONK) &&
113 cur_weapon != NULL && cur_weapon->o_type == WEAPON && 113 cur_weapon != NULL && cur_weapon->o_type == WEAPON &&
114 (cur_weapon->o_which == BASWORD || 114 (cur_weapon->o_which == BASWORD ||
115 cur_weapon->o_which == TWOSWORD) && 115 cur_weapon->o_which == TWOSWORD) &&
116 !(*newclass == C_THIEF || *newclass == C_ASSASSIN || 116 !(newclass == C_THIEF || newclass == C_ASSASSIN ||
117 *newclass == C_MONK) && 117 newclass == C_MONK) &&
118 cur_weapon->o_which == BASWORD) 118 cur_weapon->o_which == BASWORD)
119 cur_weapon->o_which = SWORD; 119 cur_weapon->o_which = SWORD;
120 120
121 /* 121 /*
122 * if he was a thief, assassin, or monk then take out 122 * if he was a thief, assassin, or monk then take out
128 128
129 /* 129 /*
130 * if he becomes a thief, assassin, or monk then add 130 * if he becomes a thief, assassin, or monk then add
131 * the trap_look() daemon 131 * the trap_look() daemon
132 */ 132 */
133 if (*newclass == C_THIEF || *newclass == C_ASSASSIN || 133 if (newclass == C_THIEF || newclass == C_ASSASSIN ||
134 *newclass == C_MONK) 134 newclass == C_MONK)
135 start_daemon(trap_look, NULL, AFTER); 135 start_daemon(trap_look, NULL, AFTER);
136 136
137 /* adjust stats */ 137 /* adjust stats */
138 char_type = player.t_ctype = *newclass; 138 char_type = player.t_ctype = newclass;
139 save = pstats.s_hpt; 139 save = pstats.s_hpt;
140 max_stats.s_hpt = pstats.s_hpt = 0; 140 max_stats.s_hpt = pstats.s_hpt = 0;
141 max_stats.s_lvl = pstats.s_lvl = 0; 141 max_stats.s_lvl = pstats.s_lvl = 0;
142 max_stats.s_lvladj = pstats.s_lvladj = 0; 142 max_stats.s_lvladj = pstats.s_lvladj = 0;
143 max_stats.s_exp = pstats.s_exp + rnd(4); 143 max_stats.s_exp = pstats.s_exp + rnd(4);
1101 * Note that it takes a while to read. 1101 * Note that it takes a while to read.
1102 */ 1102 */
1103 when MM_SKILLS: 1103 when MM_SKILLS:
1104 detach (pack, item); 1104 detach (pack, item);
1105 inpack--; 1105 inpack--;
1106 changeclass(&obj->o_ac); 1106 changeclass(obj->o_ac);
1107 when MM_CRYSTAL: 1107 when MM_CRYSTAL:
1108 { 1108 {
1109 register char *str; 1109 register char *str;
1110 1110
1111 detach (pack, item); 1111 detach (pack, item);