Mercurial > hg > early-roguelike
comparison rogue3/rings.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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:527e2150eaf0 |
|---|---|
| 1 /* | |
| 2 * routines dealing specifically with rings | |
| 3 * | |
| 4 * @(#)rings.c 3.17 (Berkeley) 6/15/81 | |
| 5 * | |
| 6 * Rogue: Exploring the Dungeons of Doom | |
| 7 * Copyright (C) 1980, 1981 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 <stdlib.h> | |
| 15 #include <string.h> | |
| 16 #include "rogue.h" | |
| 17 | |
| 18 void | |
| 19 ring_on() | |
| 20 { | |
| 21 struct object *obj; | |
| 22 struct linked_list *item; | |
| 23 int ring; | |
| 24 str_t save_max; | |
| 25 char buf[80]; | |
| 26 | |
| 27 item = get_item("put on", RING); | |
| 28 /* | |
| 29 * Make certain that it is somethings that we want to wear | |
| 30 */ | |
| 31 if (item == NULL) | |
| 32 return; | |
| 33 obj = (struct object *) ldata(item); | |
| 34 if (obj->o_type != RING) | |
| 35 { | |
| 36 if (!terse) | |
| 37 msg("It would be difficult to wrap that around a finger"); | |
| 38 else | |
| 39 msg("Not a ring"); | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 /* | |
| 44 * find out which hand to put it on | |
| 45 */ | |
| 46 if (is_current(obj)) | |
| 47 return; | |
| 48 | |
| 49 if (cur_ring[LEFT] == NULL && cur_ring[RIGHT] == NULL) | |
| 50 { | |
| 51 if ((ring = gethand()) < 0) | |
| 52 return; | |
| 53 } | |
| 54 else if (cur_ring[LEFT] == NULL) | |
| 55 ring = LEFT; | |
| 56 else if (cur_ring[RIGHT] == NULL) | |
| 57 ring = RIGHT; | |
| 58 else | |
| 59 { | |
| 60 if (!terse) | |
| 61 msg("You already have a ring on each hand"); | |
| 62 else | |
| 63 msg("Wearing two"); | |
| 64 return; | |
| 65 } | |
| 66 cur_ring[ring] = obj; | |
| 67 | |
| 68 /* | |
| 69 * Calculate the effect it has on the poor guy. | |
| 70 */ | |
| 71 switch (obj->o_which) | |
| 72 { | |
| 73 case R_ADDSTR: | |
| 74 save_max = max_stats.s_str; | |
| 75 chg_str(obj->o_ac); | |
| 76 max_stats.s_str = save_max; | |
| 77 break; | |
| 78 case R_SEEINVIS: | |
| 79 player.t_flags |= CANSEE; | |
| 80 light(&hero); | |
| 81 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
| 82 break; | |
| 83 case R_AGGR: | |
| 84 aggravate(); | |
| 85 break; | |
| 86 } | |
| 87 status(); | |
| 88 | |
| 89 if (obj->o_which >= MAXRINGS) | |
| 90 return; | |
| 91 | |
| 92 if (r_know[obj->o_which] && r_guess[obj->o_which]) | |
| 93 { | |
| 94 free(r_guess[obj->o_which]); | |
| 95 r_guess[obj->o_which] = NULL; | |
| 96 } | |
| 97 else if (!r_know[obj->o_which] && askme && r_guess[obj->o_which] == NULL) | |
| 98 { | |
| 99 mpos = 0; | |
| 100 msg(terse ? "Call it: " : "What do you want to call it? "); | |
| 101 if (get_str(buf, cw) == NORM) | |
| 102 { | |
| 103 r_guess[obj->o_which] = malloc(strlen(buf) + 1); | |
| 104 if (r_guess[obj->o_which] != NULL) | |
| 105 strcpy(r_guess[obj->o_which], buf); | |
| 106 } | |
| 107 msg(""); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 void | |
| 112 ring_off() | |
| 113 { | |
| 114 int ring; | |
| 115 struct object *obj; | |
| 116 | |
| 117 if (cur_ring[LEFT] == NULL && cur_ring[RIGHT] == NULL) | |
| 118 { | |
| 119 if (terse) | |
| 120 msg("No rings"); | |
| 121 else | |
| 122 msg("You aren't wearing any rings"); | |
| 123 return; | |
| 124 } | |
| 125 else if (cur_ring[LEFT] == NULL) | |
| 126 ring = RIGHT; | |
| 127 else if (cur_ring[RIGHT] == NULL) | |
| 128 ring = LEFT; | |
| 129 else | |
| 130 if ((ring = gethand()) < 0) | |
| 131 return; | |
| 132 mpos = 0; | |
| 133 obj = cur_ring[ring]; | |
| 134 if (obj == NULL) | |
| 135 { | |
| 136 msg("Not wearing such a ring"); | |
| 137 return; | |
| 138 } | |
| 139 if (dropcheck(obj)) | |
| 140 msg("Was wearing %s", inv_name(obj, TRUE)); | |
| 141 } | |
| 142 | |
| 143 int | |
| 144 gethand() | |
| 145 { | |
| 146 int c; | |
| 147 | |
| 148 for (;;) | |
| 149 { | |
| 150 if (terse) | |
| 151 msg("Left or Right ring? "); | |
| 152 else | |
| 153 msg("Left hand or right hand? "); | |
| 154 if ((c = readchar(cw)) == 'l' || c == 'L') | |
| 155 return LEFT; | |
| 156 else if (c == 'r' || c == 'R') | |
| 157 return RIGHT; | |
| 158 else if (c == ESCAPE) | |
| 159 return -1; | |
| 160 mpos = 0; | |
| 161 if (terse) | |
| 162 msg("L or R"); | |
| 163 else | |
| 164 msg("Please type L or R"); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 /* | |
| 169 * how much food does this ring use up? | |
| 170 */ | |
| 171 int | |
| 172 ring_eat(int hand) | |
| 173 { | |
| 174 if (cur_ring[hand] == NULL) | |
| 175 return 0; | |
| 176 switch (cur_ring[hand]->o_which) | |
| 177 { | |
| 178 case R_REGEN: | |
| 179 return 2; | |
| 180 case R_SUSTSTR: | |
| 181 return 1; | |
| 182 case R_SEARCH: | |
| 183 return (rnd(100) < 33); | |
| 184 case R_DIGEST: | |
| 185 return -(rnd(100) < 50); | |
| 186 default: | |
| 187 return 0; | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 /* | |
| 192 * print ring bonuses | |
| 193 */ | |
| 194 char * | |
| 195 ring_num(struct object *obj) | |
| 196 { | |
| 197 static char buf[5]; | |
| 198 | |
| 199 if (!(obj->o_flags & ISKNOW)) | |
| 200 return ""; | |
| 201 switch (obj->o_which) | |
| 202 { | |
| 203 case R_PROTECT: | |
| 204 case R_ADDSTR: | |
| 205 case R_ADDDAM: | |
| 206 case R_ADDHIT: | |
| 207 buf[0] = ' '; | |
| 208 strcpy(&buf[1], num(obj->o_ac, 0)); | |
| 209 otherwise: | |
| 210 return ""; | |
| 211 } | |
| 212 return buf; | |
| 213 } |
