Mercurial > hg > early-roguelike
comparison arogue5/weapons.c @ 63:0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Thu, 09 Aug 2012 22:58:48 +0000 |
| parents | |
| children | c49f7927b0fa |
comparison
equal
deleted
inserted
replaced
| 62:0ef99244acb8 | 63:0ed67132cf10 |
|---|---|
| 1 /* | |
| 2 * Functions for dealing with problems brought about by weapons | |
| 3 * | |
| 4 * Advanced Rogue | |
| 5 * Copyright (C) 1984, 1985 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 #include "curses.h" | |
| 16 #include <ctype.h> | |
| 17 #include "rogue.h" | |
| 18 | |
| 19 | |
| 20 | |
| 21 /* | |
| 22 * do the actual motion on the screen done by an object traveling | |
| 23 * across the room | |
| 24 */ | |
| 25 do_motion(obj, ydelta, xdelta, tp) | |
| 26 register struct object *obj; | |
| 27 register int ydelta, xdelta; | |
| 28 register struct thing *tp; | |
| 29 { | |
| 30 | |
| 31 /* | |
| 32 * Come fly with us ... | |
| 33 */ | |
| 34 obj->o_pos = tp->t_pos; | |
| 35 for (; ;) { | |
| 36 register int ch; | |
| 37 /* | |
| 38 * Erase the old one | |
| 39 */ | |
| 40 if (!ce(obj->o_pos, tp->t_pos) && | |
| 41 cansee(unc(obj->o_pos)) && | |
| 42 mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') { | |
| 43 mvwaddch(cw, obj->o_pos.y, obj->o_pos.x, show(obj->o_pos.y, obj->o_pos.x)); | |
| 44 } | |
| 45 /* | |
| 46 * Get the new position | |
| 47 */ | |
| 48 obj->o_pos.y += ydelta; | |
| 49 obj->o_pos.x += xdelta; | |
| 50 if (shoot_ok(ch = winat(obj->o_pos.y, obj->o_pos.x)) && ch != DOOR && !ce(obj->o_pos, hero)) { | |
| 51 /* | |
| 52 * It hasn't hit anything yet, so display it | |
| 53 * If it alright. | |
| 54 */ | |
| 55 if (cansee(unc(obj->o_pos)) && | |
| 56 mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') { | |
| 57 mvwaddch(cw, obj->o_pos.y, obj->o_pos.x, obj->o_type); | |
| 58 draw(cw); | |
| 59 } | |
| 60 continue; | |
| 61 } | |
| 62 break; | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 | |
| 67 /* | |
| 68 * fall: | |
| 69 * Drop an item someplace around here. | |
| 70 */ | |
| 71 | |
| 72 fall(item, pr) | |
| 73 register struct linked_list *item; | |
| 74 bool pr; | |
| 75 { | |
| 76 register struct object *obj; | |
| 77 register struct room *rp; | |
| 78 register int i; | |
| 79 coord *fpos = NULL; | |
| 80 | |
| 81 obj = OBJPTR(item); | |
| 82 /* | |
| 83 * try to drop the item, look up to 3 squares away for now | |
| 84 */ | |
| 85 for (i=1; i<4; i++) { | |
| 86 if ((fpos = fallpos(&obj->o_pos, FALSE, i)) != NULL) | |
| 87 break; | |
| 88 } | |
| 89 | |
| 90 if (fpos != NULL) { | |
| 91 mvaddch(fpos->y, fpos->x, obj->o_type); | |
| 92 obj->o_pos = *fpos; | |
| 93 if ((rp = roomin(&hero)) != NULL && | |
| 94 lit_room(rp)) { | |
| 95 light(&hero); | |
| 96 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
| 97 } | |
| 98 attach(lvl_obj, item); | |
| 99 return; | |
| 100 } | |
| 101 | |
| 102 | |
| 103 if (pr) { | |
| 104 if (obj->o_type == WEAPON) /* BUGFIX: Identification trick */ | |
| 105 msg("The %s vanishes as it hits the ground.", | |
| 106 weaps[obj->o_which].w_name); | |
| 107 else | |
| 108 msg("%s vanishes as it hits the ground.", inv_name(obj,TRUE)); | |
| 109 } | |
| 110 o_discard(item); | |
| 111 } | |
| 112 | |
| 113 | |
| 114 /* | |
| 115 * Does the missile hit the monster | |
| 116 */ | |
| 117 | |
| 118 hit_monster(y, x, obj, tp) | |
| 119 register int y, x; | |
| 120 struct object *obj; | |
| 121 register struct thing *tp; | |
| 122 { | |
| 123 static coord mp; | |
| 124 | |
| 125 mp.y = y; | |
| 126 mp.x = x; | |
| 127 if (tp == &player) { | |
| 128 /* Make sure there is a monster where it landed */ | |
| 129 if (!isalpha(mvwinch(mw, y, x))) { | |
| 130 return(FALSE); | |
| 131 } | |
| 132 return(fight(&mp, obj, TRUE)); | |
| 133 } else { | |
| 134 if (!ce(mp, hero)) { | |
| 135 return(FALSE); | |
| 136 } | |
| 137 return(attack(tp, obj, TRUE)); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 /* | |
| 142 * init_weapon: | |
| 143 * Set up the initial goodies for a weapon | |
| 144 */ | |
| 145 | |
| 146 init_weapon(weap, type) | |
| 147 register struct object *weap; | |
| 148 char type; | |
| 149 { | |
| 150 register struct init_weps *iwp; | |
| 151 | |
| 152 iwp = &weaps[type]; | |
| 153 strcpy(weap->o_damage,iwp->w_dam); | |
| 154 strcpy(weap->o_hurldmg,iwp->w_hrl); | |
| 155 weap->o_launch = iwp->w_launch; | |
| 156 weap->o_flags = iwp->w_flags; | |
| 157 weap->o_weight = iwp->w_wght; | |
| 158 if (weap->o_flags & ISMANY) { | |
| 159 weap->o_count = rnd(8) + 8; | |
| 160 weap->o_group = newgrp(); | |
| 161 } else { | |
| 162 weap->o_count = 1; | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 /* | |
| 167 * missile: | |
| 168 * Fire a missile in a given direction | |
| 169 */ | |
| 170 | |
| 171 missile(ydelta, xdelta, item, tp) | |
| 172 int ydelta, xdelta; | |
| 173 register struct linked_list *item; | |
| 174 register struct thing *tp; | |
| 175 { | |
| 176 register struct object *obj; | |
| 177 register struct linked_list *nitem; | |
| 178 char ch; | |
| 179 | |
| 180 /* | |
| 181 * Get which thing we are hurling | |
| 182 */ | |
| 183 if (item == NULL) { | |
| 184 return; | |
| 185 } | |
| 186 obj = OBJPTR(item); | |
| 187 | |
| 188 #if 0 /* Do we really want to make this check */ | |
| 189 if (is_current(obj)) { /* Are we holding it? */ | |
| 190 msg(terse ? "Holding it." : "You are already holding it."); | |
| 191 return; | |
| 192 } | |
| 193 #endif | |
| 194 | |
| 195 if (!dropcheck(obj)) return; /* Can we get rid of it? */ | |
| 196 | |
| 197 if(!(obj->o_flags & ISMISL)) { | |
| 198 for(;;) { | |
| 199 msg(terse ? "Really throw? (y or n): " | |
| 200 : "Do you really want to throw %s? (y or n): ", | |
| 201 inv_name(obj, TRUE)); | |
| 202 mpos = 0; | |
| 203 ch = readchar(); | |
| 204 if (ch == 'n' || ch == ESCAPE) { | |
| 205 after = FALSE; | |
| 206 return; | |
| 207 } | |
| 208 if (ch == 'y') | |
| 209 break; | |
| 210 } | |
| 211 } | |
| 212 /* | |
| 213 * Get rid of the thing. If it is a non-multiple item object, or | |
| 214 * if it is the last thing, just drop it. Otherwise, create a new | |
| 215 * item with a count of one. | |
| 216 */ | |
| 217 if (obj->o_count < 2) { | |
| 218 detach(tp->t_pack, item); | |
| 219 if (tp->t_pack == pack) { | |
| 220 inpack--; | |
| 221 } | |
| 222 } | |
| 223 else { | |
| 224 obj->o_count--; | |
| 225 nitem = (struct linked_list *) new_item(sizeof *obj); | |
| 226 obj = OBJPTR(nitem); | |
| 227 *obj = *(OBJPTR(item)); | |
| 228 obj->o_count = 1; | |
| 229 item = nitem; | |
| 230 } | |
| 231 updpack (FALSE); | |
| 232 do_motion(obj, ydelta, xdelta, tp); | |
| 233 /* | |
| 234 * AHA! Here it has hit something. If it is a wall or a door, | |
| 235 * or if it misses (combat) the monster, put it on the floor | |
| 236 */ | |
| 237 if (!hit_monster(unc(obj->o_pos), obj, tp)) { | |
| 238 fall(item, TRUE); | |
| 239 } | |
| 240 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
| 241 } | |
| 242 | |
| 243 /* | |
| 244 * num: | |
| 245 * Figure out the plus number for armor/weapons | |
| 246 */ | |
| 247 | |
| 248 char * | |
| 249 num(n1, n2) | |
| 250 register int n1, n2; | |
| 251 { | |
| 252 static char numbuf[LINELEN]; | |
| 253 | |
| 254 if (n1 == 0 && n2 == 0) { | |
| 255 return "+0"; | |
| 256 } | |
| 257 if (n2 == 0) { | |
| 258 sprintf(numbuf, "%s%d", n1 < 0 ? "" : "+", n1); | |
| 259 } else { | |
| 260 sprintf(numbuf, "%s%d, %s%d", n1 < 0 ? "" : "+", n1, n2 < 0 ? "" : "+", n2); | |
| 261 } | |
| 262 return(numbuf); | |
| 263 } | |
| 264 | |
| 265 /* | |
| 266 * wield: | |
| 267 * Pull out a certain weapon | |
| 268 */ | |
| 269 | |
| 270 wield() | |
| 271 { | |
| 272 register struct linked_list *item; | |
| 273 register struct object *obj, *oweapon; | |
| 274 | |
| 275 if ((oweapon = cur_weapon) != NULL) { | |
| 276 if (!dropcheck(cur_weapon)) { | |
| 277 cur_weapon = oweapon; | |
| 278 return; | |
| 279 } | |
| 280 if (terse) | |
| 281 addmsg("Was "); | |
| 282 else | |
| 283 addmsg("You were "); | |
| 284 msg("wielding %s", inv_name(oweapon, TRUE)); | |
| 285 } | |
| 286 if ((item = get_item(pack, "wield", WIELDABLE)) == NULL) { | |
| 287 after = FALSE; | |
| 288 return; | |
| 289 } | |
| 290 obj = OBJPTR(item); | |
| 291 if (is_current(obj)) { | |
| 292 msg("Item in use."); | |
| 293 after = FALSE; | |
| 294 return; | |
| 295 } | |
| 296 if (player.t_ctype != C_FIGHTER && | |
| 297 obj->o_type == WEAPON && | |
| 298 (obj->o_which == TWOSWORD || obj->o_which == BASWORD)) { | |
| 299 msg("Only fighters can wield a %s", weaps[obj->o_which].w_name); | |
| 300 return; | |
| 301 } | |
| 302 if (terse) { | |
| 303 addmsg("W"); | |
| 304 } else { | |
| 305 addmsg("You are now w"); | |
| 306 } | |
| 307 msg("ielding %s", inv_name(obj, TRUE)); | |
| 308 cur_weapon = obj; | |
| 309 } | |
| 310 |
