Mercurial > hg > early-roguelike
comparison srogue/things.c @ 36:2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Thu, 25 Nov 2010 12:21:41 +0000 |
| parents | |
| children | 984f7d5afb6f |
comparison
equal
deleted
inserted
replaced
| 35:05018c63a721 | 36:2128c7dc8a40 |
|---|---|
| 1 /* | |
| 2 * Contains functions for dealing with things like | |
| 3 * potions and scrolls | |
| 4 * | |
| 5 * @(#)things.c 9.0 (rdk) 7/17/84 | |
| 6 * | |
| 7 * Super-Rogue | |
| 8 * Copyright (C) 1984 Robert D. Kindelberger | |
| 9 * All rights reserved. | |
| 10 * | |
| 11 * Based on "Rogue: Exploring the Dungeons of Doom" | |
| 12 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 13 * All rights reserved. | |
| 14 * | |
| 15 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 16 */ | |
| 17 | |
| 18 #include <ctype.h> | |
| 19 #include "rogue.h" | |
| 20 #include "rogue.ext" | |
| 21 | |
| 22 | |
| 23 /* | |
| 24 * inv_name: | |
| 25 * Return the name of something as it would appear in an inventory. | |
| 26 */ | |
| 27 char * | |
| 28 inv_name(obj, drop) | |
| 29 struct object *obj; | |
| 30 bool drop; | |
| 31 { | |
| 32 reg char *pb, *tn, *pl; | |
| 33 reg int wh, knowit; | |
| 34 char nm[3], *inm, *q; | |
| 35 | |
| 36 wh = obj->o_which; | |
| 37 knowit = FALSE; | |
| 38 if (obj->o_count > 1) | |
| 39 pl = "s"; | |
| 40 else | |
| 41 pl = ""; | |
| 42 if (obj->o_count > 1) | |
| 43 sprintf(nm, "%d", obj->o_count); | |
| 44 else | |
| 45 strcpy(nm, "A"); | |
| 46 tn = obj->o_typname; | |
| 47 q = ""; | |
| 48 switch(obj->o_type) { | |
| 49 case SCROLL: | |
| 50 sprintf(prbuf, "%s %s%s ", nm, tn, pl); | |
| 51 pb = &prbuf[strlen(prbuf)]; | |
| 52 if (s_know[wh] || o_on(obj,ISPOST)) { | |
| 53 knowit = TRUE; | |
| 54 sprintf(pb, "of %s", s_magic[wh].mi_name); | |
| 55 } | |
| 56 else if (s_guess[wh]) | |
| 57 sprintf(pb, "called %s", s_guess[wh]); | |
| 58 else | |
| 59 sprintf(pb, "titled '%s'", s_names[wh]); | |
| 60 when POTION: | |
| 61 sprintf(prbuf, "%s %s%s ", nm, tn, pl); | |
| 62 pb = &prbuf[strlen(prbuf)]; | |
| 63 if (p_know[wh] || o_on(obj, ISPOST)) { | |
| 64 sprintf(pb, "of %s", p_magic[wh].mi_name); | |
| 65 knowit = TRUE; | |
| 66 if (p_know[wh]) { | |
| 67 pb = &prbuf[strlen(prbuf)]; | |
| 68 sprintf(pb,"(%s)",p_colors[wh]); | |
| 69 } | |
| 70 } | |
| 71 else if (p_guess[wh]) | |
| 72 sprintf(pb,"called %s(%s)", p_guess[wh],p_colors[wh]); | |
| 73 else | |
| 74 sprintf(prbuf,"%s%s %s %s%s", nm, vowelstr(p_colors[wh]), | |
| 75 p_colors[wh], tn, pl); | |
| 76 when FOOD: | |
| 77 if (wh == 1) { | |
| 78 if (obj->o_count == 1) | |
| 79 q = vowelstr(fruit); | |
| 80 sprintf(prbuf, "%s%s %s%s", nm, q, fruit, pl); | |
| 81 } | |
| 82 else { | |
| 83 if (obj->o_count == 1) | |
| 84 sprintf(prbuf, "Some %s", tn); | |
| 85 else | |
| 86 sprintf(prbuf, "%s rations of %s", nm, tn); | |
| 87 } | |
| 88 knowit = TRUE; | |
| 89 when WEAPON: | |
| 90 inm = w_magic[wh].mi_name; | |
| 91 strcpy(prbuf, nm); | |
| 92 if (obj->o_count == 1) | |
| 93 q = vowelstr(inm); | |
| 94 pb = &prbuf[strlen(prbuf)]; | |
| 95 if (o_on(obj,ISKNOW | ISPOST)) { | |
| 96 knowit = TRUE; | |
| 97 sprintf(pb, " %s %s", num(obj->o_hplus, obj->o_dplus), inm); | |
| 98 } | |
| 99 else | |
| 100 sprintf(pb, "%s %s", q, inm); | |
| 101 strcat(prbuf, pl); | |
| 102 when ARMOR: | |
| 103 inm = a_magic[wh].mi_name; | |
| 104 if (o_on(obj,ISKNOW | ISPOST)) { | |
| 105 knowit = TRUE; | |
| 106 sprintf(prbuf, "%s %s",num(armors[wh].a_class - obj->o_ac, 0), | |
| 107 inm); | |
| 108 } | |
| 109 else | |
| 110 sprintf(prbuf, "%s", inm); | |
| 111 when AMULET: | |
| 112 strcpy(prbuf, "The Amulet of Yendor"); | |
| 113 when STICK: { | |
| 114 struct rod *rd; | |
| 115 | |
| 116 rd = &ws_stuff[wh]; | |
| 117 sprintf(prbuf, "A %s ", rd->ws_type); | |
| 118 pb = &prbuf[strlen(prbuf)]; | |
| 119 if (ws_know[wh] || o_on(obj, ISPOST)) { | |
| 120 knowit = TRUE; | |
| 121 sprintf(pb,"of %s%s",ws_magic[wh].mi_name,charge_str(obj)); | |
| 122 if (ws_know[wh]) { | |
| 123 pb = &prbuf[strlen(prbuf)]; | |
| 124 sprintf(pb,"(%s)",rd->ws_made); | |
| 125 } | |
| 126 } | |
| 127 else if (ws_guess[wh]) | |
| 128 sprintf(pb, "called %s(%s)", ws_guess[wh], rd->ws_made); | |
| 129 else | |
| 130 sprintf(prbuf, "A%s %s %s", vowelstr(rd->ws_made), | |
| 131 rd->ws_made, rd->ws_type); | |
| 132 } | |
| 133 when RING: | |
| 134 if (r_know[wh] || o_on(obj, ISPOST)) { | |
| 135 knowit = TRUE; | |
| 136 sprintf(prbuf, "A%s %s of %s", ring_num(obj), tn, | |
| 137 r_magic[wh].mi_name); | |
| 138 if (r_know[wh]) { | |
| 139 pb = &prbuf[strlen(prbuf)]; | |
| 140 sprintf(pb,"(%s)", r_stones[wh]); | |
| 141 } | |
| 142 } | |
| 143 else if (r_guess[wh]) | |
| 144 sprintf(prbuf,"A %s called %s(%s)",tn, r_guess[wh], | |
| 145 r_stones[wh]); | |
| 146 else | |
| 147 sprintf(prbuf,"A%s %s %s",vowelstr(r_stones[wh]), | |
| 148 r_stones[wh], tn); | |
| 149 otherwise: | |
| 150 sprintf(prbuf,"Something bizarre %s", unctrl(obj->o_type)); | |
| 151 } | |
| 152 if (obj == cur_armor) | |
| 153 strcat(prbuf, " (being worn)"); | |
| 154 if (obj == cur_weapon) | |
| 155 strcat(prbuf, " (weapon in hand)"); | |
| 156 if (obj == cur_ring[LEFT]) | |
| 157 strcat(prbuf, " (on left hand)"); | |
| 158 else if (obj == cur_ring[RIGHT]) | |
| 159 strcat(prbuf, " (on right hand)"); | |
| 160 if (drop && isupper(prbuf[0])) | |
| 161 prbuf[0] = tolower(prbuf[0]); | |
| 162 else if (!drop && islower(*prbuf)) | |
| 163 *prbuf = toupper(*prbuf); | |
| 164 if (o_on(obj, ISPROT)) | |
| 165 strcat(prbuf, " [!]"); | |
| 166 if (o_on(obj, ISPOST)) | |
| 167 strcat(prbuf, " [$]"); | |
| 168 if (knowit) { | |
| 169 if (o_on(obj, ISCURSED)) | |
| 170 strcat(prbuf, " [-]"); | |
| 171 else if (o_on(obj, ISBLESS)) | |
| 172 strcat(prbuf, " [+]"); | |
| 173 } | |
| 174 if (!drop) | |
| 175 strcat(prbuf, "."); | |
| 176 return prbuf; | |
| 177 } | |
| 178 | |
| 179 /* | |
| 180 * money: | |
| 181 * Add to characters purse | |
| 182 */ | |
| 183 money() | |
| 184 { | |
| 185 reg struct room *rp; | |
| 186 reg struct linked_list *item; | |
| 187 reg struct thing *tp; | |
| 188 | |
| 189 rp = player.t_room; | |
| 190 if (rp != NULL && ce(hero, rp->r_gold)) { | |
| 191 msg("%d gold pieces.", rp->r_goldval); | |
| 192 purse += rp->r_goldval; | |
| 193 rp->r_goldval = 0; | |
| 194 cmov(rp->r_gold); | |
| 195 addch(FLOOR); | |
| 196 /* | |
| 197 * once gold is taken, all monsters will chase him | |
| 198 */ | |
| 199 for (item = mlist; item != NULL; item = next(item)) { | |
| 200 tp = THINGPTR(item); | |
| 201 if (rnd(100) < 70 && tp->t_room == rp && !iswearing(R_STEALTH) | |
| 202 && ((tp->t_flags & (ISMEAN | ISGREED)) || rnd(1000) < 20)) | |
| 203 runto(&tp->t_pos, &hero); | |
| 204 } | |
| 205 } | |
| 206 else | |
| 207 msg("That gold must have been counterfeit."); | |
| 208 } | |
| 209 | |
| 210 | |
| 211 /* | |
| 212 * drop: | |
| 213 * put something down | |
| 214 */ | |
| 215 drop(item) | |
| 216 struct linked_list *item; | |
| 217 { | |
| 218 reg char ch; | |
| 219 reg struct linked_list *ll, *nll; | |
| 220 reg struct object *op; | |
| 221 | |
| 222 if (item == NULL) { | |
| 223 ch = mvinch(hero.y, hero.x); | |
| 224 if (ch != FLOOR && ch != PASSAGE && ch != POOL) { | |
| 225 msg("There is something there already."); | |
| 226 after = FALSE; | |
| 227 return SOMTHERE; | |
| 228 } | |
| 229 if ((ll = get_item("drop", 0)) == NULL) | |
| 230 return FALSE; | |
| 231 } | |
| 232 else { | |
| 233 ll = item; | |
| 234 } | |
| 235 op = OBJPTR(ll); | |
| 236 if (!dropcheck(op)) | |
| 237 return CANTDROP; | |
| 238 /* | |
| 239 * Take it out of the pack | |
| 240 */ | |
| 241 if (op->o_count >= 2 && op->o_type != WEAPON) { | |
| 242 nll = new_item(sizeof *op); | |
| 243 op->o_count--; | |
| 244 op->o_vol = itemvol(op); | |
| 245 op = OBJPTR(nll); | |
| 246 *op = *(OBJPTR(ll)); | |
| 247 op->o_count = 1; | |
| 248 op->o_vol = itemvol(op); | |
| 249 ll = nll; | |
| 250 } | |
| 251 else { | |
| 252 detach(pack, ll); | |
| 253 } | |
| 254 if (ch == POOL) { | |
| 255 msg("%s sinks out of sight.",inv_name(op, TRUE)); | |
| 256 discard(ll); | |
| 257 } | |
| 258 else { /* put on dungeon floor */ | |
| 259 if (levtype == POSTLEV) { | |
| 260 op->o_pos = hero; /* same place as hero */ | |
| 261 fall(ll,FALSE); | |
| 262 if (item == NULL) /* if item wasn't sold */ | |
| 263 msg("Thanks for your donation to the Fiend's flea market."); | |
| 264 } | |
| 265 else { | |
| 266 attach(lvl_obj, ll); | |
| 267 mvaddch(hero.y, hero.x, op->o_type); | |
| 268 op->o_pos = hero; | |
| 269 msg("Dropped %s", inv_name(op, TRUE)); | |
| 270 } | |
| 271 } | |
| 272 updpack(); /* new pack weight */ | |
| 273 return TRUE; | |
| 274 } | |
| 275 | |
| 276 | |
| 277 /* | |
| 278 * dropcheck: | |
| 279 * Do special checks for dropping or unweilding|unwearing|unringing | |
| 280 */ | |
| 281 dropcheck(op) | |
| 282 struct object *op; | |
| 283 { | |
| 284 if (op == NULL) | |
| 285 return TRUE; | |
| 286 if (levtype == POSTLEV) { | |
| 287 if (o_on(op,ISCURSED) && o_on(op,ISKNOW)) { | |
| 288 msg("The trader does not accept shoddy merchandise."); | |
| 289 return FALSE; | |
| 290 } | |
| 291 else { | |
| 292 cur_null(op); /* update cur_weapon, etc */ | |
| 293 return TRUE; | |
| 294 } | |
| 295 } | |
| 296 if (op != cur_armor && op != cur_weapon | |
| 297 && op != cur_ring[LEFT] && op != cur_ring[RIGHT]) | |
| 298 return TRUE; | |
| 299 if (o_on(op,ISCURSED)) { | |
| 300 msg("You can't. It appears to be cursed."); | |
| 301 return FALSE; | |
| 302 } | |
| 303 if (op == cur_weapon) | |
| 304 cur_weapon = NULL; | |
| 305 else if (op == cur_armor) { | |
| 306 waste_time(); | |
| 307 cur_armor = NULL; | |
| 308 } | |
| 309 else if (op == cur_ring[LEFT] || op == cur_ring[RIGHT]) | |
| 310 toss_ring(op); | |
| 311 return TRUE; | |
| 312 } | |
| 313 | |
| 314 | |
| 315 /* | |
| 316 * new_thing: | |
| 317 * Return a new thing | |
| 318 */ | |
| 319 struct linked_list * | |
| 320 new_thing(treas, type, which) | |
| 321 int type, which; | |
| 322 bool treas; | |
| 323 { | |
| 324 struct linked_list *item; | |
| 325 struct magic_item *mi; | |
| 326 struct object *cur; | |
| 327 int chance, whi; | |
| 328 | |
| 329 item = new_item(sizeof *cur); | |
| 330 cur = OBJPTR(item); | |
| 331 basic_init(cur); | |
| 332 if (type == DONTCARE) { | |
| 333 if (++no_food > 4 && !treas) | |
| 334 whi = TYP_FOOD; | |
| 335 else | |
| 336 whi = pick_one(things); | |
| 337 } | |
| 338 else { | |
| 339 whi = getindex(type); | |
| 340 } | |
| 341 mi = thnginfo[whi].mf_magic; | |
| 342 if (which == DONTCARE) { | |
| 343 which = 0; | |
| 344 if (mi != NULL) | |
| 345 which = pick_one(mi); | |
| 346 } | |
| 347 cur->o_typname = things[whi].mi_name; | |
| 348 cur->o_weight = things[whi].mi_wght; | |
| 349 switch (whi) { | |
| 350 case TYP_AMULET: | |
| 351 cur->o_type = AMULET; | |
| 352 cur->o_hplus = 500; | |
| 353 strcpy(cur->o_hurldmg,"80d8"); /* if thrown, WOW!!! */ | |
| 354 cur->o_vol = itemvol(cur); | |
| 355 when TYP_POTION: | |
| 356 cur->o_type = POTION; | |
| 357 cur->o_which = which; | |
| 358 cur->o_count += extras(); | |
| 359 cur->o_vol = itemvol(cur); | |
| 360 when TYP_SCROLL: | |
| 361 cur->o_type = SCROLL; | |
| 362 cur->o_which = which; | |
| 363 cur->o_count += extras(); | |
| 364 cur->o_vol = itemvol(cur); | |
| 365 when TYP_FOOD: | |
| 366 no_food = 0; | |
| 367 initfood(cur); | |
| 368 when TYP_WEAPON: | |
| 369 cur->o_which = which; | |
| 370 init_weapon(cur, which); | |
| 371 if ((chance = rnd(100)) < 10) { | |
| 372 setoflg(cur,ISCURSED); | |
| 373 cur->o_hplus -= rnd(3)+1; | |
| 374 cur->o_dplus -= rnd(3)+1; | |
| 375 } | |
| 376 else if (chance < 15) { | |
| 377 cur->o_hplus += rnd(3)+1; | |
| 378 cur->o_dplus += rnd(3)+1; | |
| 379 } | |
