Mercurial > hg > early-roguelike
comparison rogue3/things.c @ 0:527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
| author | edwarj4 |
|---|---|
| date | Tue, 13 Oct 2009 13:33:34 +0000 |
| parents | |
| children | 0250220d8cdd |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:527e2150eaf0 |
|---|---|
| 1 /* | |
| 2 * Contains functions for dealing with things like | |
| 3 * potions and scrolls | |
| 4 * | |
| 5 * @(#)things.c 3.37 (Berkeley) 6/15/81 | |
| 6 * | |
| 7 * Rogue: Exploring the Dungeons of Doom | |
| 8 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 9 * All rights reserved. | |
| 10 * | |
| 11 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 12 */ | |
| 13 | |
| 14 #include "curses.h" | |
| 15 #include <ctype.h> | |
| 16 #include <string.h> | |
| 17 #include "rogue.h" | |
| 18 | |
| 19 /* | |
| 20 * inv_name: | |
| 21 * return the name of something as it would appear in an | |
| 22 * inventory. | |
| 23 */ | |
| 24 char * | |
| 25 inv_name(struct object *obj, int drop) | |
| 26 { | |
| 27 char *pb; | |
| 28 | |
| 29 switch(obj->o_type) | |
| 30 { | |
| 31 case SCROLL: | |
| 32 if (obj->o_count == 1) | |
| 33 strcpy(prbuf, "A scroll "); | |
| 34 else | |
| 35 sprintf(prbuf, "%d scrolls ", obj->o_count); | |
| 36 pb = &prbuf[strlen(prbuf)]; | |
| 37 if (s_know[obj->o_which]) | |
| 38 sprintf(pb, "of %s", s_magic[obj->o_which].mi_name); | |
| 39 else if (s_guess[obj->o_which]) | |
| 40 sprintf(pb, "called %s", s_guess[obj->o_which]); | |
| 41 else | |
| 42 sprintf(pb, "titled '%s'", s_names[obj->o_which]); | |
| 43 when POTION: | |
| 44 if (obj->o_count == 1) | |
| 45 strcpy(prbuf, "A potion "); | |
| 46 else | |
| 47 sprintf(prbuf, "%d potions ", obj->o_count); | |
| 48 pb = &prbuf[strlen(prbuf)]; | |
| 49 if (p_know[obj->o_which]) | |
| 50 sprintf(pb, "of %s(%s)", p_magic[obj->o_which].mi_name, | |
| 51 p_colors[obj->o_which]); | |
| 52 else if (p_guess[obj->o_which]) | |
| 53 sprintf(pb, "called %s(%s)", p_guess[obj->o_which], | |
| 54 p_colors[obj->o_which]); | |
| 55 else if (obj->o_count == 1) | |
| 56 sprintf(prbuf, "A%s %s potion", | |
| 57 vowelstr(p_colors[obj->o_which]), | |
| 58 p_colors[obj->o_which]); | |
| 59 else | |
| 60 sprintf(prbuf, "%d %s potions", obj->o_count, | |
| 61 p_colors[obj->o_which]); | |
| 62 when FOOD: | |
| 63 if (obj->o_which == 1) | |
| 64 if (obj->o_count == 1) | |
| 65 sprintf(prbuf, "A%s %s", vowelstr(fruit), fruit); | |
| 66 else | |
| 67 sprintf(prbuf, "%d %ss", obj->o_count, fruit); | |
| 68 else | |
| 69 if (obj->o_count == 1) | |
| 70 strcpy(prbuf, "Some food"); | |
| 71 else | |
| 72 sprintf(prbuf, "%d rations of food", obj->o_count); | |
| 73 when WEAPON: | |
| 74 if (obj->o_count > 1) | |
| 75 sprintf(prbuf, "%d ", obj->o_count); | |
| 76 else | |
| 77 strcpy(prbuf, "A "); | |
| 78 pb = &prbuf[strlen(prbuf)]; | |
| 79 if (obj->o_flags & ISKNOW) | |
| 80 sprintf(pb, "%s %s", num(obj->o_hplus, obj->o_dplus), | |
| 81 w_names[obj->o_which]); | |
| 82 else | |
| 83 sprintf(pb, "%s", w_names[obj->o_which]); | |
| 84 if (obj->o_count > 1) | |
| 85 strcat(prbuf, "s"); | |
| 86 when ARMOR: | |
| 87 if (obj->o_flags & ISKNOW) | |
| 88 sprintf(prbuf, "%s %s", | |
| 89 num(a_class[obj->o_which] - obj->o_ac, 0), | |
| 90 a_names[obj->o_which]); | |
| 91 else | |
| 92 sprintf(prbuf, "%s", a_names[obj->o_which]); | |
| 93 when AMULET: | |
| 94 strcpy(prbuf, "The Amulet of Yendor"); | |
| 95 when STICK: | |
| 96 sprintf(prbuf, "A %s ", ws_type[obj->o_which]); | |
| 97 pb = &prbuf[strlen(prbuf)]; | |
| 98 if (ws_know[obj->o_which]) | |
| 99 sprintf(pb, "of %s%s(%s)", ws_magic[obj->o_which].mi_name, | |
| 100 charge_str(obj), ws_made[obj->o_which]); | |
| 101 else if (ws_guess[obj->o_which]) | |
| 102 sprintf(pb, "called %s(%s)", ws_guess[obj->o_which], | |
| 103 ws_made[obj->o_which]); | |
| 104 else | |
| 105 sprintf(&prbuf[2], "%s %s", ws_made[obj->o_which], | |
| 106 ws_type[obj->o_which]); | |
| 107 when RING: | |
| 108 if (r_know[obj->o_which]) | |
| 109 sprintf(prbuf, "A%s ring of %s(%s)", ring_num(obj), | |
| 110 r_magic[obj->o_which].mi_name, r_stones[obj->o_which]); | |
| 111 else if (r_guess[obj->o_which]) | |
| 112 sprintf(prbuf, "A ring called %s(%s)", | |
| 113 r_guess[obj->o_which], r_stones[obj->o_which]); | |
| 114 else | |
| 115 sprintf(prbuf, "A%s %s ring", vowelstr(r_stones[obj->o_which]), | |
| 116 r_stones[obj->o_which]); | |
| 117 otherwise: | |
| 118 debug("Picked up something funny"); | |
| 119 sprintf(prbuf, "Something bizarre %s", unctrl(obj->o_type)); | |
| 120 } | |
| 121 if (obj == cur_armor) | |
| 122 strcat(prbuf, " (being worn)"); | |
| 123 if (obj == cur_weapon) | |
| 124 strcat(prbuf, " (weapon in hand)"); | |
| 125 if (obj == cur_ring[LEFT]) | |
| 126 strcat(prbuf, " (on left hand)"); | |
| 127 else if (obj == cur_ring[RIGHT]) | |
| 128 strcat(prbuf, " (on right hand)"); | |
| 129 if (drop && isupper(prbuf[0])) | |
| 130 prbuf[0] = tolower(prbuf[0]); | |
| 131 else if (!drop && islower(*prbuf)) | |
| 132 *prbuf = toupper(*prbuf); | |
| 133 if (!drop) | |
| 134 strcat(prbuf, "."); | |
| 135 return prbuf; | |
| 136 } | |
| 137 | |
| 138 /* | |
| 139 * money: | |
| 140 * Add to characters purse | |
| 141 */ | |
| 142 void | |
| 143 money() | |
| 144 { | |
| 145 struct room *rp; | |
| 146 | |
| 147 for (rp = rooms; rp <= &rooms[MAXROOMS-1]; rp++) | |
| 148 if (ce(hero, rp->r_gold)) | |
| 149 { | |
| 150 if (notify) | |
| 151 { | |
| 152 if (!terse) | |
| 153 addmsg("You found "); | |
| 154 msg("%d gold pieces.", rp->r_goldval); | |
| 155 } | |
| 156 purse += rp->r_goldval; | |
| 157 rp->r_goldval = 0; | |
| 158 cmov(rp->r_gold); | |
| 159 addch(FLOOR); | |
| 160 return; | |
| 161 } | |
| 162 msg("That gold must have been counterfeit"); | |
| 163 } | |
| 164 | |
| 165 /* | |
| 166 * drop: | |
| 167 * put something down | |
| 168 */ | |
| 169 void | |
| 170 drop() | |
| 171 { | |
| 172 int ch; | |
| 173 struct linked_list *obj, *nobj; | |
| 174 struct object *op; | |
| 175 | |
| 176 ch = mvwinch(stdscr, hero.y, hero.x); | |
| 177 if (ch != FLOOR && ch != PASSAGE) | |
| 178 { | |
| 179 msg("There is something there already"); | |
| 180 return; | |
| 181 } | |
| 182 if ((obj = get_item("drop", 0)) == NULL) | |
| 183 return; | |
| 184 op = (struct object *) ldata(obj); | |
| 185 if (!dropcheck(op)) | |
| 186 return; | |
| 187 /* | |
| 188 * Take it out of the pack | |
| 189 */ | |
| 190 if (op->o_count >= 2 && op->o_type != WEAPON) | |
| 191 { | |
| 192 nobj = new_item(sizeof *op); | |
| 193 op->o_count--; | |
| 194 op = (struct object *) ldata(nobj); | |
| 195 *op = *((struct object *) ldata(obj)); | |
| 196 op->o_count = 1; | |
| 197 obj = nobj; | |
