Mercurial > hg > early-roguelike
comparison arogue7/things.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 * things.c - functions for dealing with things like potions and scrolls | |
| 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 * Contains functions for dealing with things like | |
| 17 * potions and scrolls | |
| 18 * | |
| 19 */ | |
| 20 | |
| 21 #include "curses.h" | |
| 22 #include <ctype.h> | |
| 23 #include "rogue.h" | |
| 24 | |
| 25 /* | |
| 26 * print out the number of charges on a stick | |
| 27 */ | |
| 28 char * | |
| 29 charge_str(obj) | |
| 30 register struct object *obj; | |
| 31 { | |
| 32 static char buf[20]; | |
| 33 | |
| 34 if (!(obj->o_flags & ISKNOW)) | |
| 35 buf[0] = '\0'; | |
| 36 else if (terse) | |
| 37 sprintf(buf, " [%d]", obj->o_charges); | |
| 38 else | |
| 39 sprintf(buf, " [%d charges]", obj->o_charges); | |
| 40 return buf; | |
| 41 } | |
| 42 /* | |
| 43 * inv_name: | |
| 44 * return the name of something as it would appear in an | |
| 45 * inventory. | |
| 46 */ | |
| 47 char * | |
| 48 inv_name(obj, drop) | |
| 49 register struct object *obj; | |
| 50 bool drop; | |
| 51 { | |
| 52 register char *pb; | |
| 53 | |
| 54 pb = prbuf; | |
| 55 pb[0] = '\0'; | |
| 56 switch(obj->o_type) { | |
| 57 case SCROLL: | |
| 58 if (obj->o_count == 1) | |
| 59 sprintf(pb, "A %sscroll ", blesscurse(obj->o_flags)); | |
| 60 else | |
| 61 sprintf(pb, "%d %sscrolls ", | |
| 62 obj->o_count, blesscurse(obj->o_flags)); | |
| 63 pb = &pb[strlen(pb)]; | |
| 64 if (s_know[obj->o_which] || (obj->o_flags & ISPOST)) | |
| 65 sprintf(pb, "of %s", s_magic[obj->o_which].mi_name); | |
| 66 else if (s_guess[obj->o_which]) | |
| 67 sprintf(pb, "named %s", s_guess[obj->o_which]); | |
| 68 else | |
| 69 sprintf(pb, "titled '%s'", s_names[obj->o_which]); | |
| 70 when POTION: | |
| 71 if (obj->o_count == 1) | |
| 72 sprintf(pb, "A %spotion ", blesscurse(obj->o_flags)); | |
| 73 else | |
| 74 sprintf(pb, "%d %spotions ", | |
| 75 obj->o_count, blesscurse(obj->o_flags)); | |
| 76 pb = &pb[strlen(pb)]; | |
| 77 if (p_know[obj->o_which]) | |
| 78 sprintf(pb, "of %s (%s)", p_magic[obj->o_which].mi_name, | |
| 79 p_kind(obj)); | |
| 80 else if (obj->o_flags & ISPOST) | |
| 81 sprintf(pb, "of %s", p_magic[obj->o_which].mi_name); | |
| 82 else if (p_guess[obj->o_which]) | |
| 83 sprintf(pb, "named %s (%s)", p_guess[obj->o_which], | |
| 84 p_colors[obj->o_which]); | |
| 85 else { | |
| 86 pb = prbuf; | |
| 87 if (obj->o_count == 1) | |
| 88 sprintf(pb, "A%s %s potion", | |
| 89 vowelstr(p_colors[obj->o_which]), | |
| 90 p_colors[obj->o_which]); | |
| 91 else | |
| 92 sprintf(pb, "%d %s potions", | |
| 93 obj->o_count, p_colors[obj->o_which]); | |
| 94 } | |
| 95 when FOOD: | |
| 96 if (obj->o_count == 1) | |
| 97 sprintf(pb, "A%s %s", vowelstr(foods[obj->o_which].mi_name), | |
| 98 foods[obj->o_which].mi_name); | |
| 99 else | |
| 100 sprintf(pb, "%d %ss", obj->o_count,foods[obj->o_which].mi_name); | |
| 101 when WEAPON: | |
| 102 if (obj->o_count > 1) | |
| 103 sprintf(pb, "%d ", obj->o_count); | |
| 104 else | |
| 105 strcpy(pb, "A "); | |
| 106 pb = &pb[strlen(pb)]; | |
| 107 if (obj->o_flags & ISKNOW) { | |
| 108 strcat(pb, num(obj->o_hplus, obj->o_dplus)); | |
| 109 strcat (pb, " "); | |
| 110 } | |
| 111 strcat(pb, weaps[obj->o_which].w_name); | |
| 112 if (obj->o_count > 1) | |
| 113 strcat(pb, "s"); | |
| 114 if (obj == cur_weapon) | |
| 115 strcat(pb, " (weapon in hand)"); | |
| 116 if (obj->o_flags & ISPOISON) | |
| 117 strcat(pb, " {Poisoned}"); | |
| 118 when ARMOR: | |
| 119 if (obj->o_flags & ISKNOW) { | |
| 120 strcat(pb, num(armors[obj->o_which].a_class - obj->o_ac, 0)); | |
| 121 strcat(pb, " "); | |
| 122 } | |
| 123 strcat(pb, armors[obj->o_which].a_name); | |
| 124 if (obj == cur_armor) | |
| 125 strcat(pb, " (being worn)"); | |
| 126 when STICK: | |
| 127 sprintf(pb, "A %s%s ", | |
| 128 blesscurse(obj->o_flags), ws_type[obj->o_which]); | |
| 129 pb = &pb[strlen(pb)]; | |
| 130 if (ws_know[obj->o_which] || obj->o_flags & ISKNOW) | |
| 131 sprintf(pb, "of %s%s (%s)", ws_magic[obj->o_which].mi_name, | |
| 132 charge_str(obj), ws_made[obj->o_which]); | |
| 133 else if (obj->o_flags & ISPOST) | |
| 134 sprintf(pb, "of %s", ws_magic[obj->o_which].mi_name); | |
| 135 else if (ws_guess[obj->o_which]) | |
| 136 sprintf(pb, "named %s (%s)", ws_guess[obj->o_which], | |
| 137 ws_made[obj->o_which]); | |
| 138 else { | |
| 139 pb = prbuf; | |
| 140 sprintf(pb, "A %s %s", ws_made[obj->o_which], | |
| 141 ws_type[obj->o_which]); | |
| 142 } | |
| 143 if (obj == cur_weapon) | |
| 144 strcat(prbuf, " (weapon in hand)"); | |
| 145 when RING: | |
| 146 if (r_know[obj->o_which] || obj->o_flags & ISKNOW) | |
| 147 sprintf(pb, "A%s ring of %s (%s)", ring_num(obj), | |
| 148 r_magic[obj->o_which].mi_name, r_stones[obj->o_which]); | |
| 149 else if (obj->o_flags & ISPOST) | |
| 150 sprintf(pb, "A ring of %s", r_magic[obj->o_which].mi_name); | |
| 151 else if (r_guess[obj->o_which]) | |
| 152 sprintf(pb, "A ring named %s (%s)", | |
| 153 r_guess[obj->o_which], r_stones[obj->o_which]); | |
| 154 else | |
| 155 sprintf(pb, "A%s %s ring", vowelstr(r_stones[obj->o_which]), | |
| 156 r_stones[obj->o_which]); | |
| 157 if (obj == cur_ring[LEFT_1] || obj == cur_ring[LEFT_2] || | |
| 158 obj == cur_ring[LEFT_3] || obj == cur_ring[LEFT_4]) | |
| 159 strcat(pb, " (on left hand)"); | |
| 160 if (obj == cur_ring[RIGHT_1] || obj == cur_ring[RIGHT_2] || | |
| 161 obj == cur_ring[RIGHT_3] || obj == cur_ring[RIGHT_4]) | |
| 162 strcat(pb, " (on right hand)"); | |
| 163 when RELIC: | |
| 164 if (obj->o_flags & ISKNOW) | |
| 165 switch(obj->o_which) { | |
| 166 case QUILL_NAGROM: | |
| 167 sprintf(pb, "%s%s", rel_magic[obj->o_which].mi_name, | |
| 168 charge_str(obj)); | |
| 169 otherwise: | |
| 170 strcpy(pb, rel_magic[obj->o_which].mi_name); | |
| 171 } | |
| 172 else switch(obj->o_which) { | |
| 173 case MUSTY_DAGGER: | |
| 174 strcpy(pb, "Two very fine daggers marked MDDE"); | |
| 175 when EMORI_CLOAK: | |
| 176 strcpy(pb, "A silk cloak"); | |
| 177 when HEIL_ANKH: | |
| 178 strcpy(pb, "A golden ankh"); | |
| 179 when MING_STAFF: | |
| 180 strcpy(pb, "A finely carved staff"); | |
| 181 when ORCUS_WAND: | |
| 182 strcpy(pb, "A sparkling ivory wand"); | |
| 183 when ASMO_ROD: | |
| 184 strcpy(pb, "A glistening ebony rod"); | |
| 185 when YENDOR_AMULET: | |
| 186 strcpy(pb, "A silver amulet"); | |
| 187 when STONEBONES_AMULET: | |
| 188 strcpy(pb, "A stone amulet"); | |
| 189 when BRIAN_MANDOLIN: | |
| 190 strcpy(pb, "A gleaming mandolin"); | |
| 191 when HRUGGEK_MSTAR: | |
| 192 strcpy(pb, "A huge morning star"); | |
| 193 when AXE_AKLAD: | |
| 194 strcpy(pb, "A jewel encrusted axe"); | |
| 195 when QUILL_NAGROM: | |
| 196 strcpy(pb, "A bright white feather"); | |
| 197 when GERYON_HORN: | |
| 198 strcpy(pb, "A jet black horn"); | |
| 199 when YEENOGHU_FLAIL: | |
| 200 strcpy(pb, "A shimmering flail"); | |
| 201 when SURTUR_RING: | |
| 202 strcpy(pb, "A fiery red ring"); | |
| 203 otherwise: | |
| 204 strcpy(pb, "A magical item"); | |
| 205 } | |
| 206 | |
| 207 /* Take care of wielding and wearing */ | |
| 208 switch (obj->o_which) { | |
| 209 case EMORI_CLOAK: | |
| 210 if (cur_armor == NULL && cur_misc[WEAR_CLOAK] == NULL) | |
| 211 strcat(pb, " (being worn)"); | |
| 212 if (obj->o_charges) | |
| 213 strcat(pb, " [charged]"); | |
| 214 else | |
| 215 strcat(pb, " [discharged]"); | |
| 216 when HEIL_ANKH: | |
| 217 if (cur_relic[HEIL_ANKH]) strcat(pb, " (in hand)"); | |
| 218 when EYE_VECNA: | |
| 219 if (cur_relic[EYE_VECNA]) strcat(pb, " (in eye socket)"); | |
| 220 when STONEBONES_AMULET: | |
| 221 if (cur_relic[STONEBONES_AMULET]) | |
| 222 strcat(pb, " (in chest)"); | |
| 223 when YENDOR_AMULET: | |
| 224 if (cur_relic[YENDOR_AMULET]) | |
| 225 strcat(pb, " (in chest)"); | |
| 226 when MUSTY_DAGGER: | |
| 227 case HRUGGEK_MSTAR: | |
| 228 case AXE_AKLAD: | |
| 229 case YEENOGHU_FLAIL: | |
| 230 case MING_STAFF: | |
| 231 case ASMO_ROD: | |
| 232 case ORCUS_WAND: | |
| 233 if (cur_weapon == obj) strcat(pb, " (weapon in hand)"); | |
| 234 when SURTUR_RING: | |
| 235 if (cur_relic[SURTUR_RING]) | |
| 236 strcat(pb, " (in nose)"); | |
| 237 } | |
| 238 when MM: | |
| 239 if (m_know[obj->o_which]) | |
| 240 strcpy(pb, misc_name(obj)); | |
| 241 else { | |
| 242 switch (obj->o_which) { | |
| 243 case MM_JUG: | |
| 244 case MM_BEAKER: | |
| 245 strcpy(pb, "A bottle"); | |
| 246 when MM_KEOGHTOM: | |
| 247 strcpy(pb, "A jar"); | |
| 248 when MM_JEWEL: | |
| 249 strcpy(pb, "An amulet"); | |
| 250 when MM_BOOK: | |
| 251 case MM_SKILLS: | |
| 252 strcpy(pb, "A book"); | |
| 253 when MM_ELF_BOOTS: | |
| 254 case MM_DANCE: | |
| 255 strcpy(pb, "A pair of boots"); | |
| 256 when MM_BRACERS: | |
| 257 strcpy(pb, "A pair of bracers"); | |
| 258 when MM_OPEN: | |
| 259 case MM_HUNGER: | |
| 260 strcpy(pb, "A chime"); | |
| 261 when MM_DISP: | |
| 262 case MM_R_POWERLESS: | |
| 263 case MM_PROTECT: | |
| 264 strcpy(pb, "A cloak"); | |
| 265 when MM_DRUMS: | |
| 266 strcpy(pb, "A set of drums"); | |
| 267 when MM_DISAPPEAR: | |
| 268 case MM_CHOKE: | |
| 269 strcpy(pb, "A pouch of dust"); | |
| 270 when MM_G_DEXTERITY: | |
| 271 case MM_G_OGRE: | |
| 272 case MM_FUMBLE: | |
| 273 strcpy(pb, "A pair of gauntlets"); | |
| 274 when MM_ADAPTION: | |
| 275 case MM_STRANGLE: | |
| 276 strcpy(pb, "A necklace"); | |
| 277 otherwise: | |
| 278 strcpy(pb, "A magical item"); | |
| 279 } | |
| 280 if (m_guess[obj->o_which]) { | |
| 281 strcat(pb, " named: "); | |
| 282 strcat(pb, m_guess[obj->o_which]); | |
| 283 } | |
| 284 } | |
| 285 if (obj == cur_misc[WEAR_BOOTS] || | |
| 286 obj == cur_misc[WEAR_BRACERS] || | |
| 287 obj == cur_misc[WEAR_CLOAK] || | |
| 288 obj == cur_misc[WEAR_GAUNTLET] || | |
| 289 obj == cur_misc[WEAR_NECKLACE] || | |
| 290 obj == cur_misc[WEAR_JEWEL]) | |
| 291 strcat(pb, " (being worn)"); | |
| 292 when GOLD: | |
| 293 sprintf(pb, "%d Pieces of Gold", obj->o_count); | |
| 294 otherwise: | |
| 295 debug("Picked up something funny"); | |
| 296 sprintf(pb, "Something bizarre %s", unctrl(obj->o_type)); | |
| 297 } | |
| 298 | |
| 299 /* Is it marked? */ | |
| 300 if (obj->o_mark[0]) { | |
| 301 pb = &pb[strlen(pb)]; | |
| 302 sprintf(pb, " <%s>", obj->o_mark); | |
| 303 } | |
| 304 | |
| 305 if (obj->o_flags & ISPROT) | |
| 306 strcat(pb, " [protected]"); | |
| 307 if (drop && isupper(prbuf[0])) | |
| 308 prbuf[0] = tolower(prbuf[0]); | |
| 309 else if (!drop && islower(*prbuf)) | |
| 310 *prbuf = toupper(*prbuf); | |
| 311 if (!drop) | |
| 312 strcat(pb, "."); | |
| 313 /* | |
| 314 * Truncate if long. Use cols-4 to offset the "pack letter" of a normal | |
| 315 * inventory listing. | |
| 316 */ | |
| 317 prbuf[cols-4] = '\0'; | |
| 318 return prbuf; | |
| 319 } | |
| 320 | |
| 321 /* | |
| 322 * weap_name: | |
| 323 * Return the name of a weapon. | |
| 324 */ | |
| 325 char * | |
| 326 weap_name(obj) | |
| 327 register struct object *obj; | |
| 328 { | |
| 329 switch (obj->o_type) { | |
| 330 case WEAPON: | |
| 331 return(weaps[obj->o_which].w_name); | |
| 332 when MISSILE: | |
| 333 return(ws_magic[obj->o_which].mi_name); | |
| 334 when RELIC: | |
| 335 switch (obj->o_which) { | |
| 336 case MUSTY_DAGGER: | |
| 337 return("daggers"); | |
| 338 when YEENOGHU_FLAIL: | |
| 339 return("flail"); | |
| 340 when AXE_AKLAD: | |
| 341 return("axe"); | |
| 342 when HRUGGEK_MSTAR: | |
| 343 return("morning star"); | |
| 344 when MING_STAFF: | |
| 345 return("staff"); | |
| 346 when ORCUS_WAND: | |
| 347 return("wand"); | |
| 348 when ASMO_ROD: | |
| 349 return("rod"); | |
| 350 } | |
| 351 } | |
| 352 return("weapon"); | |
| 353 } | |
| 354 | |
| 355 /* | |
| 356 * drop: | |
| 357 * put something down | |
| 358 */ | |
| 359 drop(item) | |
| 360 struct linked_list *item; | |
| 361 { | |
| 362 register char ch; | |
| 363 register struct linked_list *obj, *nobj; | |
| 364 register struct object *op; | |
| 365 | |
