rogue

Ken Arnold's Rogue
git clone https://git.woozle.org/neale/rogue.git

Neale Pickett  ·  2011-10-13

netmap.c

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