Mercurial > hg > early-roguelike
comparison arogue7/weapons.c @ 125:adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
| author | John "Elwin" Edwards |
|---|---|
| date | Fri, 08 May 2015 15:24:40 -0400 |
| parents | |
| children | b786053d2f37 |
comparison
equal
deleted
inserted
replaced
| 124:d10fc4a065ac | 125:adfa37e67084 |
|---|---|
| 1 /* | |
| 2 * weapons.c - Functions for dealing with problems brought about by weapons | |
| 3 * | |
| 4 * Advanced Rogue | |
| 5 * Copyright (C) 1984, 1985, 1986 Michael Morgan, Ken Dalka and AT&T | |
| 6 * All rights reserved. | |
| 7 * | |
| 8 * Based on "Rogue: Exploring the Dungeons of Doom" | |
| 9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 10 * All rights reserved. | |
| 11 * | |
| 12 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 13 */ | |
| 14 | |
| 15 /* | |
| 16 * Functions for dealing with problems brought about by weapons | |
| 17 * | |
| 18 */ | |
| 19 | |
| 20 #include "curses.h" | |
| 21 #include <ctype.h> | |
| 22 #include "rogue.h" | |
| 23 | |
| 24 boomerang(ydelta, xdelta, item, tp) | |
| 25 int ydelta, xdelta; | |
| 26 register struct linked_list *item; | |
| 27 register struct thing *tp; | |
| 28 { | |
| 29 register struct object *obj; | |
| 30 struct thing midpoint; | |
| 31 coord oldpos; | |
| 32 | |
| 33 obj = OBJPTR(item); | |
| 34 oldpos = obj->o_pos; | |
| 35 | |
| 36 /* | |
| 37 * make it appear to fly at the target | |
| 38 */ | |
| 39 do_motion(obj, ydelta, xdelta, tp); | |
| 40 hit_monster(unc(obj->o_pos), obj, tp); | |
| 41 | |
| 42 /* | |
| 43 * Now let's make it fly back to the wielder. We need to | |
| 44 * use midpoint to fool do_motion into thinking the action | |
| 45 * starts there. Do_motion only looks at the t_pos field. | |
| 46 */ | |
| 47 midpoint.t_pos = obj->o_pos; /* Simulate a new start position */ | |
| 48 do_motion(obj, -ydelta, -xdelta, &midpoint); | |
| 49 | |
| 50 obj->o_pos = oldpos; | |
| 51 } | |
| 52 | |
| 53 /* | |
| 54 * do the actual motion on the screen done by an object traveling | |
| 55 * across the room. Note that we should not look at any field in | |
| 56 * tp other than t_pos unless we change boomerang(). | |
| 57 */ | |
| 58 do_motion(obj, ydelta, xdelta, tp) | |
| 59 register struct object *obj; | |
| 60 register int ydelta, xdelta; | |
| 61 register struct thing *tp; | |
| 62 { | |
| 63 | |
| 64 /* | |
| 65 * Come fly with us ... | |
| 66 */ | |
| 67 obj->o_pos = tp->t_pos; | |
| 68 for (; ;) { | |
| 69 register int ch; | |
| 70 /* | |
| 71 * Erase the old one | |
| 72 */ | |
| 73 if (!ce(obj->o_pos, tp->t_pos) && | |
| 74 cansee(unc(obj->o_pos)) && | |
| 75 mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') { | |
| 76 mvwaddch(cw, obj->o_pos.y, obj->o_pos.x, show(obj->o_pos.y, obj->o_pos.x)); | |
| 77 } | |
| 78 /* | |
| 79 * Get the new position | |
| 80 */ | |
| 81 obj->o_pos.y += ydelta; | |
| 82 obj->o_pos.x += xdelta; | |
| 83 if (shoot_ok(ch = winat(obj->o_pos.y, obj->o_pos.x)) && ch != DOOR && !ce(obj->o_pos, hero)) { | |
| 84 /* | |
| 85 * It hasn't hit anything yet, so display it | |
| 86 * If it alright. | |
| 87 */ | |
| 88 if (cansee(unc(obj->o_pos)) && | |
| 89 mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') { | |
| 90 mvwaddch(cw, obj->o_pos.y, obj->o_pos.x, obj->o_type); | |
| 91 draw(cw); | |
| 92 } | |
| 93 continue; | |
| 94 } | |
| 95 | |
| 96 /* | |
| 97 * Did we stop because of a monster or the hero? If we did | |
| 98 * not, we want to move our position back one because we could | |
| 99 * not actually make it this far. | |
| 100 */ | |
| 101 if (!isalpha(ch) && | |
| 102 !(obj->o_pos.y == hero.y && obj->o_pos.x == hero.x)) { | |
| 103 obj->o_pos.y -= ydelta; | |
| 104 obj->o_pos.x -= xdelta; | |
| 105 } | |
| 106 | |
| 107 break; | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 | |
| 112 /* | |
| 113 * fall: | |
| 114 * Drop an item someplace around here. | |
| 115 */ | |
| 116 | |
| 117 fall(item, pr) | |
| 118 register struct linked_list *item; | |
| 119 bool pr; | |
| 120 { | |
| 121 register struct object *obj; | |
| 122 register struct room *rp; | |
| 123 register int i; | |
| 124 struct object *tobj; | |
| 125 struct linked_list *titem; | |
| 126 coord *fpos; | |
| 127 | |
| 128 obj = OBJPTR(item); | |
| 129 /* | |
| 130 * try to drop the item, look up to 3 squares away for now | |
| 131 */ | |
| 132 for (i=1; i<4; i++) { | |
| 133 if ((fpos = fallpos(&obj->o_pos, FALSE, i)) != NULL) | |
| 134 break; | |
| 135 } | |
| 136 | |
| 137 if (fpos != NULL) { | |
| 138 if (obj->o_group) { /* try to add groups together */ | |
| 139 for(titem=lvl_obj; titem!=NULL; titem=next(titem)) { | |
| 140 tobj = OBJPTR(titem); | |
| 141 if (tobj->o_group == obj->o_group && | |
| 142 tobj->o_pos.y == fpos->y && | |
| 143 tobj->o_pos.x == fpos->x) { | |
| 144 tobj->o_count += obj->o_count; | |
| 145 o_discard(item); | |
| 146 return; | |
| 147 } | |
| 148 } | |
| 149 } | |
| 150 mvaddch(fpos->y, fpos->x, obj->o_type); | |
| 151 obj->o_pos = *fpos; | |
| 152 if ((rp = roomin(&hero)) != NULL && | |
| 153 lit_room(rp)) { | |
| 154 light(&hero); | |
| 155 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
| 156 } | |
| 157 attach(lvl_obj, item); | |
| 158 return; | |
| 159 } | |
| 160 if (pr) { | |
| 161 msg("The %s vanishes as it hits the ground.", | |
| 162 weaps[obj->o_which].w_name); | |
| 163 } | |
| 164 o_discard(item); | |
| 165 } | |
| 166 | |
| 167 | |
| 168 /* | |
| 169 * Does the missile hit the monster | |
| 170 */ | |
| 171 | |
| 172 hit_monster(y, x, obj, tp) | |
| 173 register int y, x; | |
| 174 struct object *obj; | |
| 175 register struct thing *tp; | |
| 176 { | |
| 177 static coord mp; | |
| 178 | |
