Mercurial > hg > early-roguelike
comparison rogue5/rings.c @ 33:f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Mon, 24 May 2010 20:10:59 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 32:2dcd75e6a736 | 33:f502bf60e6e4 |
|---|---|
| 1 /* | |
| 2 * Routines dealing specifically with rings | |
| 3 * | |
| 4 * @(#)rings.c 4.19 (Berkeley) 05/29/83 | |
| 5 * | |
| 6 * Rogue: Exploring the Dungeons of Doom | |
| 7 * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman | |
| 8 * All rights reserved. | |
| 9 * | |
| 10 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 11 */ | |
| 12 | |
| 13 #include <curses.h> | |
| 14 #include "rogue.h" | |
| 15 | |
| 16 /* | |
| 17 * ring_on: | |
| 18 * Put a ring on a hand | |
| 19 */ | |
| 20 | |
| 21 void | |
| 22 ring_on(void) | |
| 23 { | |
| 24 THING *obj; | |
| 25 int ring; | |
| 26 | |
| 27 obj = get_item("put on", RING); | |
| 28 /* | |
| 29 * Make certain that it is somethings that we want to wear | |
| 30 */ | |
| 31 if (obj == NULL) | |
| 32 return; | |
| 33 if (obj->o_type != RING) | |
| 34 { | |
| 35 if (!terse) | |
| 36 msg("it would be difficult to wrap that around a finger"); | |
| 37 else | |
| 38 msg("not a ring"); | |
| 39 return; | |
| 40 } | |
| 41 | |
| 42 /* | |
| 43 * find out which hand to put it on | |
| 44 */ | |
| 45 if (is_current(obj)) | |
| 46 return; | |
| 47 | |
| 48 if (cur_ring[LEFT] == NULL && cur_ring[RIGHT] == NULL) | |
| 49 { | |
| 50 if ((ring = gethand()) < 0) | |
| 51 return; | |
| 52 } | |
| 53 else if (cur_ring[LEFT] == NULL) | |
| 54 ring = LEFT; | |
| 55 else if (cur_ring[RIGHT] == NULL) | |
| 56 ring = RIGHT; | |
| 57 else | |
| 58 { | |
| 59 if (!terse) | |
| 60 msg("you already have a ring on each hand"); | |
| 61 else | |
| 62 msg("wearing two"); | |
| 63 return; | |
| 64 } | |
| 65 cur_ring[ring] = obj; | |
| 66 | |
| 67 /* | |
| 68 * Calculate the effect it has on the poor guy. | |
| 69 */ | |
| 70 switch (obj->o_which) | |
| 71 { | |
| 72 case R_ADDSTR: | |
| 73 chg_str(obj->o_arm); | |
| 74 break; | |
| 75 case R_SEEINVIS: | |
| 76 invis_on(); | |
| 77 break; | |
| 78 case R_AGGR: | |
| 79 aggravate(); | |
| 80 break; | |
| 81 } | |
| 82 | |
| 83 if (!terse) | |
| 84 addmsg("you are now wearing "); | |
| 85 msg("%s (%c)", inv_name(obj, TRUE), obj->o_packch); | |
| 86 } | |
| 87 | |
| 88 /* | |
| 89 * ring_off: | |
| 90 * take off a ring | |
| 91 */ | |
| 92 | |
| 93 void | |
| 94 ring_off(void) | |
| 95 { | |
| 96 int ring; | |
| 97 THING *obj; | |
| 98 | |
| 99 if (cur_ring[LEFT] == NULL && cur_ring[RIGHT] == NULL) | |
| 100 { | |
| 101 if (terse) | |
| 102 msg("no rings"); | |
| 103 else | |
| 104 msg("you aren't wearing any rings"); | |
| 105 return; | |
| 106 } | |
| 107 else if (cur_ring[LEFT] == NULL) | |
| 108 ring = RIGHT; | |
| 109 else if (cur_ring[RIGHT] == NULL) | |
| 110 ring = LEFT; | |
| 111 else | |
| 112 if ((ring = gethand()) < 0) | |
| 113 return; | |
| 114 mpos = 0; | |
| 115 obj = cur_ring[ring]; | |
| 116 if (obj == NULL) | |
| 117 { | |
| 118 msg("not wearing such a ring"); | |
| 119 return; | |
| 120 } | |
| 121 if (dropcheck(obj)) | |
| 122 msg("was wearing %s(%c)", inv_name(obj, TRUE), obj->o_packch); | |
| 123 } | |
| 124 | |
| 125 /* | |
| 126 * gethand: | |
| 127 * Which hand is the hero interested in? | |
| 128 */ | |
| 129 int | |
| 130 gethand(void) | |
| 131 { | |
| 132 int c; | |
| 133 | |
| 134 for (;;) | |
| 135 { | |
| 136 if (terse) | |
| 137 msg("left or right ring? "); | |
| 138 else | |
| 139 msg("left hand or right hand? "); | |
| 140 if ((c = readchar()) == ESCAPE) | |
| 141 return -1; | |
| 142 mpos = 0; | |
| 143 if (c == 'l' || c == 'L') | |
| 144 return LEFT; | |
| 145 else if (c == 'r' || c == 'R') | |
| 146 return RIGHT; | |
| 147 if (terse) | |
| 148 msg("L or R"); | |
| 149 else | |
| 150 msg("please type L or R"); | |
| 151 } | |
| 152 } | |
| 153 | |
| 154 /* | |
| 155 * ring_eat: | |
| 156 * How much food does this ring use up? | |
| 157 */ | |
| 158 int | |
| 159 ring_eat(int hand) | |
| 160 { | |
| 161 THING *ring; | |
| 162 int eat; | |
| 163 int uses[] = { | |
| 164 1, /* R_PROTECT */ 1, /* R_ADDSTR */ | |
| 165 1, /* R_SUSTSTR */ -3, /* R_SEARCH */ | |
| 166 -5, /* R_SEEINVIS */ 0, /* R_NOP */ | |
| 167 0, /* R_AGGR */ -3, /* R_ADDHIT */ | |
| 168 -3, /* R_ADDDAM */ 2, /* R_REGEN */ | |
| 169 -2, /* R_DIGEST */ 0, /* R_TELEPORT */ | |
| 170 1, /* R_STEALTH */ 1 /* R_SUSTARM */ | |
| 171 }; | |
| 172 | |
| 173 if ((ring = cur_ring[hand]) == NULL) | |
| 174 return 0; | |
| 175 if ((eat = uses[ring->o_which]) < 0) | |
| 176 eat = (rnd(-eat) == 0); | |
| 177 if (ring->o_which == R_DIGEST) | |
| 178 eat = -eat; | |
| 179 return eat; | |
| 180 } | |
| 181 | |
| 182 /* | |
| 183 * ring_num: | |
| 184 * Print ring bonuses | |
| 185 */ | |
| 186 const char * | |
| 187 ring_num(const THING *obj) | |
| 188 { | |
| 189 static char buf[10]; | |
| 190 | |
| 191 if (!(obj->o_flags & ISKNOW)) | |
| 192 return ""; | |
| 193 switch (obj->o_which) | |
| 194 { | |
| 195 case R_PROTECT: | |
| 196 case R_ADDSTR: | |
| 197 case R_ADDDAM: | |
| 198 case R_ADDHIT: | |
| 199 sprintf(buf, " [%s]", num(obj->o_arm, 0, RING)); | |
| 200 otherwise: | |
| 201 return ""; | |
| 202 } | |
| 203 return buf; | |
| 204 } |
