annotate rogue4/weapons.c @ 114:a5433ba4cabf

arogue5: fix some daemon-related pointer/int casting. Daemons and fuses take a single argument, nominally an int but either ignored or unsafely cast to a pointer. Its type has now been changed to void*. The save/restore code no longer tries to store this argument in the savefile. For doctor(), this is not a problem, because player is the only argument it is ever given as a daemon. However, alchemy() will fail to do anything when passed NULL. Fixing this would be complicated but possible. Summary: the code is slightly safer, but alchemy jugs are guaranteed to stop working after save and restore, instead of just extremely likely.
author John "Elwin" Edwards
date Fri, 28 Mar 2014 10:57:03 -0700
parents 9535a08ddc39
children 1b73a8641b37
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
1 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
2 * Functions for dealing with problems brought about by weapons
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
3 *
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
4 * @(#)weapons.c 4.14 (Berkeley) 4/6/82
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
5 *
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
6 * Rogue: Exploring the Dungeons of Doom
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
7 * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
8 * All rights reserved.
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
9 *
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
10 * See the file LICENSE.TXT for full copyright and licensing information.
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
11 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
13 #include <curses.h>
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
14 #include <ctype.h>
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
15 #include <string.h>
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
16 #include "rogue.h"
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
17
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
18 #define NONE 100
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
19
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
20 static struct init_weps {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
21 char *iw_dam; /* Damage when wielded */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
22 char *iw_hrl; /* Damage when thrown */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
23 char iw_launch; /* Launching weapon */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
24 int iw_flags; /* Miscellaneous flags */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
25 } init_dam[MAXWEAPONS] = {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
26 "2d4", "1d3", NONE, 0, /* Mace */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
27 "3d4", "1d2", NONE, 0, /* Long sword */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
28 "1d1", "1d1", NONE, 0, /* Bow */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
29 "1d1", "2d3", BOW, ISMANY|ISMISL, /* Arrow */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
30 "1d6", "1d4", NONE, ISMISL, /* Dagger */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
31 "4d4", "1d2", NONE, 0, /* 2h sword */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
32 "1d1", "1d3", NONE, ISMANY|ISMISL, /* Dart */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
33 "1d1", "1d1", NONE, 0, /* Crossbow */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
34 "1d2", "2d5", CROSSBOW, ISMANY|ISMISL, /* Crossbow bolt */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
35 "2d3", "1d6", NONE, ISMISL, /* Spear */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
36 };
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
37
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
38 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
39 * missile:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
40 * Fire a missile in a given direction
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
41 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
42 missile(ydelta, xdelta)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
43 int ydelta, xdelta;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
44 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
45 register THING *obj, *nitem;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
46
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
47 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
48 * Get which thing we are hurling
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
49 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
50 if ((obj = get_item("throw", WEAPON)) == NULL)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
51 return;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
52 if (!dropcheck(obj) || is_current(obj))
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
53 return;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
54 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
55 * Get rid of the thing. If it is a non-multiple item object, or
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
56 * if it is the last thing, just drop it. Otherwise, create a new
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
57 * item with a count of one.
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
58 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
59 if (obj->o_count < 2)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
60 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
61 detach(pack, obj);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
62 inpack--;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
63 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
64 else
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
65 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
66 obj->o_count--;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
67 if (obj->o_group == 0)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
68 inpack--;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
69 nitem = new_item();
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
70 *nitem = *obj;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
71 nitem->o_count = 1;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
72 obj = nitem;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
73 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
74 do_motion(obj, ydelta, xdelta);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
75 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
76 * AHA! Here it has hit something. If it is a wall or a door,
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
77 * or if it misses (combat) the monster, put it on the floor
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
78 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
79 if (moat(obj->o_pos.y, obj->o_pos.x) == NULL
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
80 || !hit_monster(unc(obj->o_pos), obj))
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
81 fall(obj, TRUE);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
82 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
83
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
84 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
85 * do_motion:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
86 * Do the actual motion on the screen done by an object traveling
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
87 * across the room
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
88 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
89 do_motion(obj, ydelta, xdelta)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
90 register THING *obj;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
91 register int ydelta, xdelta;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
92 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
93 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
94 * Come fly with us ...
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
95 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
96 obj->o_pos = hero;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
97 for (;;)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
98 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
99 register int ch;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
100
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
101 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
102 * Erase the old one
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
103 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset