Mercurial > hg > early-roguelike
comparison xrogue/potions.c @ 142:6b5fbd7c3ece
Merge arogue7 and xrogue trees.
| author | John "Elwin" Edwards |
|---|---|
| date | Tue, 12 May 2015 21:39:39 -0400 |
| parents | ce0cf824c192 |
| children | f54901b9c39b |
comparison
equal
deleted
inserted
replaced
| 132:66b0263af424 | 142:6b5fbd7c3ece |
|---|---|
| 1 /* | |
| 2 potions.c - Functions for dealing with potions | |
| 3 | |
| 4 XRogue: Expeditions into the Dungeons of Doom | |
| 5 Copyright (C) 1991 Robert Pietkivitch | |
| 6 All rights reserved. | |
| 7 | |
| 8 Based on "Advanced Rogue" | |
| 9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
| 10 All rights reserved. | |
| 11 | |
| 12 Based on "Rogue: Exploring the Dungeons of Doom" | |
| 13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 14 All rights reserved. | |
| 15 | |
| 16 See the file LICENSE.TXT for full copyright and licensing information. | |
| 17 */ | |
| 18 | |
| 19 #include <stdlib.h> | |
| 20 #include <curses.h> | |
| 21 #include "rogue.h" | |
| 22 | |
| 23 /* | |
| 24 * add_abil is an array of functions used to change attributes. It must be | |
| 25 * ordered according to the attribute definitions in rogue.h. | |
| 26 */ | |
| 27 | |
| 28 int (*add_abil[NUMABILITIES])() = { | |
| 29 add_intelligence, add_strength, add_wisdom, add_dexterity, | |
| 30 add_constitution, add_charisma | |
| 31 }; | |
| 32 | |
| 33 /* | |
| 34 * res_abil is an array of functions used to change attributes. It must be | |
| 35 * ordered according to the attribute definitions in rogue.h. | |
| 36 */ | |
| 37 | |
| 38 int (*res_abil[NUMABILITIES])() = { | |
| 39 res_intelligence, res_strength, res_wisdom, res_dexterity, | |
| 40 res_constitution, res_charisma | |
| 41 }; | |
| 42 | |
| 43 /* | |
| 44 * Increase player's constitution | |
| 45 */ | |
| 46 | |
| 47 int | |
| 48 add_constitution(change) | |
| 49 int change; | |
| 50 { | |
| 51 /* Do the potion */ | |
| 52 if (change < 0) { | |
| 53 msg("You feel less healthy now."); | |
| 54 pstats.s_const += change; | |
| 55 if (pstats.s_const < 1) { | |
| 56 pstats.s_hpt = -1; | |
| 57 msg("You collapse! --More--"); | |
| 58 wait_for(' '); | |
| 59 death(D_CONSTITUTION); | |
| 60 } | |
| 61 } | |
| 62 else { | |
| 63 msg("You feel healthier now."); | |
| 64 pstats.s_const = min(pstats.s_const + change, MAXATT); | |
| 65 } | |
| 66 | |
| 67 /* Adjust the maximum */ | |
| 68 if (max_stats.s_const < pstats.s_const) | |
| 69 max_stats.s_const = pstats.s_const; | |
| 70 | |
| 71 return(0); | |
| 72 } | |
| 73 | |
| 74 /* | |
| 75 * Increase player's charisma | |
| 76 */ | |
| 77 | |
| 78 int | |
| 79 add_charisma(change) | |
| 80 int change; | |
| 81 { | |
| 82 /* Do the potion */ | |
| 83 if (change < 0) msg("You feel less attractive now."); | |
| 84 else msg("You feel more attractive now."); | |
| 85 | |
| 86 pstats.s_charisma += change; | |
| 87 if (pstats.s_charisma > MAXATT) pstats.s_charisma = MAXATT; | |
| 88 else if (pstats.s_charisma < 3) pstats.s_charisma = 3; | |
| 89 | |
| 90 /* Adjust the maximum */ | |
| 91 if (max_stats.s_charisma < pstats.s_charisma) | |
| 92 max_stats.s_charisma = pstats.s_charisma; | |
| 93 | |
| 94 return(0); | |
| 95 } | |
| 96 | |
| 97 /* | |
| 98 * Increase player's dexterity | |
| 99 */ | |
| 100 | |
| 101 int | |
| 102 add_dexterity(change) | |
| 103 int change; | |
| 104 { | |
| 105 int ring_str; /* Value of ring strengths */ | |
| 106 | |
| 107 /* Undo any ring changes */ | |
| 108 ring_str = ring_value(R_ADDHIT); | |
| 109 pstats.s_dext -= ring_str; | |
| 110 | |
| 111 /* Now do the potion */ | |
| 112 if (change < 0) msg("You feel less dextrous now."); | |
| 113 else msg("You feel more dextrous now. Watch those hands!"); | |
| 114 | |
| 115 pstats.s_dext += change; | |
| 116 if (pstats.s_dext > MAXATT) pstats.s_dext = MAXATT; | |
| 117 else if (pstats.s_dext < 3) pstats.s_dext = 3; | |
| 118 | |
| 119 /* Adjust the maximum */ | |
| 120 if (max_stats.s_dext < pstats.s_dext) | |
| 121 max_stats.s_dext = pstats.s_dext; | |
| 122 | |
| 123 /* Now put back the ring changes */ | |
| 124 if (ring_str) | |
| 125 pstats.s_dext += ring_str; | |
| 126 | |
| 127 return(0); | |
| 128 } | |
| 129 | |
| 130 /* | |
| 131 * add_haste: | |
| 132 * add a haste to the player | |
| 133 */ | |
| 134 | |
| 135 add_haste(blessed) | |
| 136 bool blessed; | |
| 137 { | |
| 138 int hasttime; | |
| 139 | |
| 140 if (player.t_ctype == C_MONK) { /* monks cannot be slowed or hasted */ | |
| 141 msg(nothing); | |
| 142 return; | |
| 143 } | |
| 144 | |
| 145 if (blessed) hasttime = HASTETIME*2; | |
| 146 else hasttime = HASTETIME; | |
| 147 | |
| 148 if (on(player, ISSLOW)) { /* Is person slow? */ | |
| 149 extinguish(noslow); | |
| 150 noslow(); | |
| 151 | |
| 152 if (blessed) hasttime = HASTETIME/2; | |
| 153 else return; | |
| 154 } | |
| 155 | |
| 156 if (on(player, ISHASTE)) { | |
| 157 msg("You faint from exhaustion."); | |
| 158 player.t_no_move += movement(&player) * rnd(hasttime); | |
| 159 player.t_action = A_FREEZE; | |
| 160 lengthen(nohaste, roll(hasttime,hasttime)); | |
| 161 } | |
| 162 else { | |
| 163 msg("You feel yourself moving %sfaster.", blessed ? "much " : ""); | |
| 164 turn_on(player, ISHASTE); | |
| 165 fuse(nohaste, (VOID *)NULL, roll(hasttime, hasttime), AFTER); | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 /* | |
| 170 * Increase player's intelligence | |
| 171 */ | |
| 172 | |
| 173 int | |
| 174 add_intelligence(change) | |
| 175 int change; | |
| 176 { | |
| 177 int ring_str; /* Value of ring strengths */ | |
| 178 | |
| 179 /* Undo any ring changes */ | |
| 180 ring_str = ring_value(R_ADDINTEL); | |
| 181 pstats.s_intel -= ring_str; | |
| 182 | |
| 183 /* Now do the potion */ | |
| 184 if (change < 0) msg("You feel slightly less intelligent now."); | |
| 185 else msg("You feel more intelligent now. What a mind!"); | |
| 186 | |
| 187 pstats.s_intel += change; | |
| 188 if (pstats.s_intel > MAXATT) pstats.s_intel = MAXATT; | |
| 189 else if (pstats.s_intel < 3) pstats.s_intel = 3; | |
| 190 | |
| 191 /* Adjust the maximum */ | |
| 192 if (max_stats.s_intel < pstats.s_intel) | |
| 193 max_stats.s_intel = pstats.s_intel; | |
| 194 | |
| 195 /* Now put back the ring changes */ | |
| 196 if (ring_str) | |
| 197 pstats.s_intel += ring_str; | |
| 198 | |
| 199 return(0); | |
| 200 } | |
| 201 | |
| 202 /* | |
| 203 * this routine makes the hero move slower | |
| 204 */ | |
| 205 | |
| 206 add_slow() | |
| 207 { | |
| 208 /* monks cannot be slowed or hasted */ | |
| 209 if (player.t_ctype == C_MONK || ISWEARING(R_FREEDOM)) { | |
| 210 msg(nothing); | |
| 211 return; | |
| 212 } | |
| 213 | |
| 214 if (on(player, ISHASTE)) { /* Already sped up */ | |
| 215 extinguish(nohaste); | |
| 216 nohaste(); | |
| 217 } | |
| 218 else { | |
| 219 msg("You feel yourself moving %sslower.", | |
| 220 on(player, ISSLOW) ? "even " : ""); | |
| 221 if (on(player, ISSLOW)) | |
| 222 lengthen(noslow, roll(HASTETIME,HASTETIME)); | |
| 223 else { | |
| 224 turn_on(player, ISSLOW); | |
| 225 fuse(noslow, (VOID *)NULL, roll(HASTETIME,HASTETIME), AFTER); | |
| 226 } | |
| 227 } | |
| 228 } | |
| 229 | |
| 230 /* | |
| 231 * Increase player's strength | |
| 232 */ | |
| 233 | |
| 234 int | |
| 235 add_strength(change) | |
| 236 int change; | |
| 237 { | |
| 238 | |
| 239 if (change < 0) { | |
| 240 msg("You feel slightly weaker now."); | |
| 241 chg_str(change); | |
| 242 } | |
| 243 else { | |
| 244 msg("You feel stronger now. What bulging muscles!"); | |
| 245 chg_str(change); | |
| 246 } | |
| 247 return(0); | |
| 248 } | |
| 249 | |
| 250 /* | |
| 251 * Increase player's wisdom | |
| 252 */ | |
| 253 | |
| 254 int | |
| 255 add_wisdom(change) | |
| 256 int change; | |
| 257 { | |
| 258 int ring_str; /* Value of ring strengths */ | |
| 259 | |
| 260 /* Undo any ring changes */ | |
| 261 ring_str = ring_value(R_ADDWISDOM); | |
| 262 pstats.s_wisdom -= ring_str; | |
| 263 | |
| 264 /* Now do the potion */ | |
| 265 if (change < 0) msg("You feel slightly less wise now."); | |
| 266 else msg("You feel wiser now. What a sage!"); | |
| 267 | |
| 268 pstats.s_wisdom += change; | |
| 269 if (pstats.s_wisdom > MAXATT) pstats.s_wisdom = MAXATT; | |
| 270 else if (pstats.s_wisdom < 3) pstats.s_wisdom = 3; | |
| 271 | |
| 272 /* Adjust the maximum */ | |
| 273 if (max_stats.s_wisdom < pstats.s_wisdom) | |
| 274 max_stats.s_wisdom = pstats.s_wisdom; | |
| 275 | |
| 276 /* Now put back the ring changes */ | |
| 277 if (ring_str) | |
| 278 pstats.s_wisdom += ring_str; | |
| 279 | |
| 280 return(0); | |
| 281 } | |
| 282 | |
| 283 quaff(which, kind, flags, is_potion) | |
| 284 int which; | |
| 285 int kind; | |
| 286 int flags; | |
| 287 bool is_potion; | |
| 288 { | |
| 289 register struct object *obj; | |
| 290 register struct linked_list *item, *titem; | |
| 291 register struct thing *th; | |
| 292 bool cursed, blessed; | |
| 293 | |
| 294 blessed = FALSE; | |
| 295 cursed = FALSE; | |
| 296 item = NULL; | |
| 297 | |
| 298 if (which < 0) { /* figure out which ourselves */ | |
| 299 /* This is a potion. */ | |
| 300 if (player.t_action != C_QUAFF) { | |
| 301 int units; | |
| 302 | |
| 303 item = get_item(pack, "quaff", QUAFFABLE, FALSE, FALSE); | |
| 304 | |
| 305 /* | |
| 306 * Make certain that it is somethings that we want to drink | |
| 307 */ | |
| 308 if (item == NULL) | |
| 309 return; | |
| 310 | |
| 311 /* How long does it take to quaff? */ | |
| 312 units = usage_time(item); | |
| 313 if (units < 0) return; | |
| 314 | |
| 315 player.t_using = item; /* Remember what it is */ | |
| 316 player.t_no_move = units * movement(&player); | |
| 317 if ((OBJPTR(item))->o_type == POTION) player.t_action = C_QUAFF; | |
| 318 else player.t_action = C_USE; | |
| 319 return; | |
| 320 } | |
| 321 | |
| 322 /* We have waited our time, let's quaff the potion */ | |
| 323 item = player.t_using; | |
| 324 player.t_using = NULL; | |
| 325 player.t_action = A_NIL; | |
| 326 | |
| 327 obj = OBJPTR(item); | |
| 328 /* remove it from the pack */ | |
| 329 inpack--; | |
| 330 detach(pack, item); | |
| 331 | |
| 332 flags = obj->o_flags; | |
| 333 which = obj->o_which; | |
| 334 kind = obj->o_kind; | |
| 335 } | |
| 336 cursed = flags & ISCURSED; | |
| 337 blessed = flags & ISBLESSED; | |
| 338 | |
| 339 switch(which) { | |
| 340 case P_CLEAR: | |
| 341 if (cursed) { | |
| 342 confus_player(); | |
| 343 } | |
| 344 else { | |
| 345 if (blessed) { /* Make player immune for the whole game */ | |
| 346 extinguish(unclrhead); /* If we have a fuse, put it out */ | |
| 347 msg("A strong blue aura surrounds your head."); | |
| 348 } | |
| 349 else { /* Just light a fuse for how long player is safe */ | |
| 350 if (off(player, ISCLEAR)) { | |
| 351 fuse(unclrhead, (VOID *)NULL, CLRDURATION, AFTER); | |
| 352 msg("A faint blue aura surrounds your head."); | |
| 353 } | |
| 354 else { /* If we have a fuse lengthen it, else we | |
| 355 * are permanently clear. | |
| 356 */ | |
| 357 if (find_slot(unclrhead) == 0) | |
| 358 msg("Your blue aura continues to glow strongly."); | |
| 359 else { | |
| 360 lengthen(unclrhead, CLRDURATION); | |
| 361 msg("Your blue aura brightens for a moment."); | |
| 362 } | |
| 363 } | |
| 364 } | |
| 365 turn_on(player, ISCLEAR); | |
| 366 /* If player is confused, unconfuse him */ | |
| 367 if (on(player, ISHUH)) { | |
| 368 extinguish(unconfuse); | |
| 369 unconfuse(); | |
| 370 } | |
| 371 } | |
| 372 when P_HEALING: | |
| 373 if (cursed) { | |
| 374 msg("You feel worse now."); | |
| 375 pstats.s_hpt -= roll(pstats.s_lvl, char_class[player.t_ctype].hit_pts); |
