Mercurial > hg > early-roguelike
annotate rogue5/potions.c @ 110:5f51f7d9805f
arogue5: fix some save/restore-related crashes.
The save/restore code took the pointer intended as an argument for the
doctor() daemon and wrote it to the savefile as an int. I don't know
why it took so long to fail horribly. The problem has been avoided by
replacing the value with &player when restoring. That seems to be the
only argument ever actually used.
The code also writes only four bytes for an unsigned long; if
sizeof(long) == 8, it casts to unsigned int first. It failed to do the
cast when reading back, with the result that four bytes were read and
the other half of the number was effectively uninitialized.
It apparently works now, but the save/restore code ought still to be
regarded as decidedly unfortunate.
author | John "Elwin" Edwards |
---|---|
date | Mon, 06 Jan 2014 15:57:17 -0500 |
parents | f502bf60e6e4 |
children | 696277507a2e |
rev | line source |
---|---|
33
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
1 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
2 * Function(s) for dealing with potions |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
3 * |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
4 * @(#)potions.c 4.46 (Berkeley) 06/07/83 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
5 * |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
6 * Rogue: Exploring the Dungeons of Doom |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
7 * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
8 * All rights reserved. |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
9 * |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
10 * See the file LICENSE.TXT for full copyright and licensing information. |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
11 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
12 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
13 #include <curses.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
14 #include <ctype.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
15 #include "rogue.h" |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
16 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
17 typedef struct PACT |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
18 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
19 const int pa_flags; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
20 void (*pa_daemon)(); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
21 const int pa_time; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
22 const char *pa_high, *pa_straight; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
23 } PACT; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
24 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
25 static const PACT p_actions[] = |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
26 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
27 { ISHUH, unconfuse, HUHDURATION, /* P_CONFUSE */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
28 "what a tripy feeling!", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
29 "wait, what's going on here. Huh? What? Who?" }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
30 { ISHALU, come_down, SEEDURATION, /* P_LSD */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
31 "Oh, wow! Everything seems so cosmic!", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
32 "Oh, wow! Everything seems so cosmic!" }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
33 { 0, NULL, 0 }, /* P_POISON */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
34 { 0, NULL, 0 }, /* P_STRENGTH */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
35 { CANSEE, unsee, SEEDURATION, /* P_SEEINVIS */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
36 prbuf, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
37 prbuf }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
38 { 0, NULL, 0 }, /* P_HEALING */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
39 { 0, NULL, 0 }, /* P_MFIND */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
40 { 0, NULL, 0 }, /* P_TFIND */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
41 { 0, NULL, 0 }, /* P_RAISE */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
42 { 0, NULL, 0 }, /* P_XHEAL */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
43 { 0, NULL, 0 }, /* P_HASTE */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
44 { 0, NULL, 0 }, /* P_RESTORE */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
45 { ISBLIND, sight, SEEDURATION, /* P_BLIND */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
46 "oh, bummer! Everything is dark! Help!", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
47 "a cloak of darkness falls around you" }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
48 { ISLEVIT, land, HEALTIME, /* P_LEVIT */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
49 "oh, wow! You're floating in the air!", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
50 "you start to float in the air" } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
51 }; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
52 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
53 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
54 * quaff: |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
55 * Quaff a potion from the pack |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
56 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
57 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
58 void |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
59 quaff(void) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
60 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
61 THING *obj, *tp, *mp; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
62 int discardit = FALSE; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
63 int show, trip; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
64 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
65 obj = get_item("quaff", POTION); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
66 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
67 * Make certain that it is somethings that we want to drink |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
68 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
69 if (obj == NULL) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
70 return; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
71 if (obj->o_type != POTION) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
72 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
73 if (!terse) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
74 msg("yuk! Why would you want to drink that?"); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
75 else |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
76 msg("that's undrinkable"); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
77 return; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
78 } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
79 if (obj == cur_weapon) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
80 cur_weapon = NULL; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
81 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
82 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
83 * Calculate the effect it has on the poor guy. |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
84 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
85 trip = on(player, ISHALU); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
86 discardit = (obj->o_count == 1); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
87 leave_pack(obj, FALSE, FALSE); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
88 switch (obj->o_which) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
89 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
90 case P_CONFUSE: |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
91 do_pot(P_CONFUSE, !trip); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
92 when P_POISON: |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
93 pot_info[P_POISON].oi_know = TRUE; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
94 if (ISWEARING(R_SUSTSTR)) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
95 msg("you feel momentarily sick"); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
96 else |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
97 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
98 chg_str(-(rnd(3) + 1)); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
99 msg("you feel very sick now"); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
100 come_down(); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
101 } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
102 when P_HEALING: |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
103 pot_info[P_HEALING].oi_know = TRUE; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
104 if ((pstats.s_hpt += roll(pstats.s_lvl, 4)) > max_hp) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
105 pstats.s_hpt = ++max_hp; |