Annotation of researchv10no/games/rogue/things.c, revision 1.1.1.1

1.1       root        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: 
                      8: #include <curses.h>
                      9: #include <ctype.h>
                     10: #include "rogue.h"
                     11: 
                     12: /*
                     13:  * inv_name:
                     14:  *     return the name of something as it would appear in an
                     15:  *     inventory.
                     16:  */
                     17: char *
                     18: inv_name(obj, drop)
                     19: register struct object *obj;
                     20: register bool drop;
                     21: {
                     22:     register char *pb;
                     23: 
                     24:     switch(obj->o_type)
                     25:     {
                     26:        when SCROLL:
                     27:            if (obj->o_count == 1)
                     28:                strcpy(prbuf, "A scroll ");
                     29:            else
                     30:                sprintf(prbuf, "%d scrolls ", obj->o_count);
                     31:            pb = &prbuf[strlen(prbuf)];
                     32:            if (s_know[obj->o_which])
                     33:                sprintf(pb, "of %s", s_magic[obj->o_which].mi_name);
                     34:            else if (s_guess[obj->o_which])
                     35:                sprintf(pb, "called %s", s_guess[obj->o_which]);
                     36:            else
                     37:                sprintf(pb, "titled '%s'", s_names[obj->o_which]);
                     38:         when POTION:
                     39:            if (obj->o_count == 1)
                     40:                strcpy(prbuf, "A potion ");
                     41:            else
                     42:                sprintf(prbuf, "%d potions ", obj->o_count);
                     43:            pb = &prbuf[strlen(prbuf)];
                     44:            if (p_know[obj->o_which])
                     45:                sprintf(pb, "of %s(%s)", p_magic[obj->o_which].mi_name,
                     46:                    p_colors[obj->o_which]);
                     47:            else if (p_guess[obj->o_which])
                     48:                sprintf(pb, "called %s(%s)", p_guess[obj->o_which],
                     49:                    p_colors[obj->o_which]);
                     50:            else if (obj->o_count == 1)
                     51:                sprintf(prbuf, "A%s %s potion",
                     52:                    vowelstr(p_colors[obj->o_which]),
                     53:                    p_colors[obj->o_which]);
                     54:            else
                     55:                sprintf(prbuf, "%d %s potions", obj->o_count,
                     56:                    p_colors[obj->o_which]);
                     57:        when FOOD:
                     58:            if (obj->o_which == 1)
                     59:                if (obj->o_count == 1)
                     60:                    sprintf(prbuf, "A%s %s", vowelstr(fruit), fruit);
                     61:                else
                     62:                    sprintf(prbuf, "%d %ss", obj->o_count, fruit);
                     63:            else
                     64:                if (obj->o_count == 1)
                     65:                    strcpy(prbuf, "Some food");
                     66:                else
                     67:                    sprintf(prbuf, "%d rations of food", obj->o_count);
                     68:        when WEAPON:
                     69:            if (obj->o_count > 1)
                     70:                sprintf(prbuf, "%d ", obj->o_count);
                     71:            else
                     72:                strcpy(prbuf, "A ");
                     73:            pb = &prbuf[strlen(prbuf)];
                     74:            if (obj->o_flags & ISKNOW)
                     75:                sprintf(pb, "%s %s", num(obj->o_hplus, obj->o_dplus),
                     76:                    w_names[obj->o_which]);
                     77:            else
                     78:                sprintf(pb, "%s", w_names[obj->o_which]);
                     79:            if (obj->o_count > 1)
                     80:                strcat(prbuf, "s");
                     81:        when ARMOR:
                     82:            if (obj->o_flags & ISKNOW)
                     83:                sprintf(prbuf, "%s %s",
                     84:                    num(a_class[obj->o_which] - obj->o_ac, 0),
                     85:                    a_names[obj->o_which]);
                     86:            else
                     87:                sprintf(prbuf, "%s", a_names[obj->o_which]);
                     88:        when AMULET:
                     89:            strcpy(prbuf, "The Amulet of Yendor");
                     90:        when STICK:
                     91:            sprintf(prbuf, "A %s ", ws_type[obj->o_which]);
                     92:            pb = &prbuf[strlen(prbuf)];
                     93:            if (ws_know[obj->o_which])
                     94:                sprintf(pb, "of %s%s(%s)", ws_magic[obj->o_which].mi_name,
                     95:                    charge_str(obj), ws_made[obj->o_which]);
                     96:            else if (ws_guess[obj->o_which])
                     97:                sprintf(pb, "called %s(%s)", ws_guess[obj->o_which],
                     98:                    ws_made[obj->o_which]);
                     99:            else
                    100:                sprintf(&prbuf[2], "%s %s", ws_made[obj->o_which],
                    101:                    ws_type[obj->o_which]);
                    102:         when RING:
                    103:            if (r_know[obj->o_which])
                    104:                sprintf(prbuf, "A%s ring of %s(%s)", ring_num(obj),
                    105:                    r_magic[obj->o_which].mi_name, r_stones[obj->o_which]);
                    106:            else if (r_guess[obj->o_which])
                    107:                sprintf(prbuf, "A ring called %s(%s)",
                    108:                    r_guess[obj->o_which], r_stones[obj->o_which]);
                    109:            else
                    110:                sprintf(prbuf, "A%s %s ring", vowelstr(r_stones[obj->o_which]),
                    111:                    r_stones[obj->o_which]);
                    112:        otherwise:
                    113:            debug("Picked up something funny");
                    114:            sprintf(prbuf, "Something bizarre %s", unctrl(obj->o_type));
                    115:     }
                    116:     if (obj == cur_armor)
                    117:        strcat(prbuf, " (being worn)");
                    118:     if (obj == cur_weapon)
                    119:        strcat(prbuf, " (weapon in hand)");
                    120:     if (obj == cur_ring[LEFT])
                    121:        strcat(prbuf, " (on left hand)");
                    122:     else if (obj == cur_ring[RIGHT])
                    123:        strcat(prbuf, " (on right hand)");
                    124:     if (drop && isupper(prbuf[0]))
                    125:        prbuf[0] = tolower(prbuf[0]);
                    126:     else if (!drop && islower(*prbuf))
                    127:        *prbuf = toupper(*prbuf);
                    128:     if (!drop)
                    129:        strcat(prbuf, ".");
                    130:     return prbuf;
                    131: }
                    132: 
                    133: /*
                    134:  * money:
                    135:  *     Add to characters purse
                    136:  */
                    137: money()
                    138: {
                    139:     register struct room *rp;
                    140: 
                    141:     for (rp = rooms; rp < &rooms[MAXROOMS]; rp++)
                    142:        if (ce(hero, rp->r_gold))
                    143:        {
                    144:            if (notify)
                    145:            {
                    146:                if (!terse)
                    147:                    addmsg("You found ");
                    148:                msg("%d gold pieces.", rp->r_goldval);
                    149:            }
                    150:            purse += rp->r_goldval;
                    151:            rp->r_goldval = 0;
                    152:            cmov(rp->r_gold);
                    153:            addch(FLOOR);
                    154:            return;
                    155:        }
                    156:     msg("That gold must have been counterfeit");
                    157: }
                    158: 
                    159: /*
                    160:  * drop:
                    161:  *     put something down
                    162:  */
                    163: drop()
                    164: {
                    165:     register char ch;
                    166:     register struct linked_list *obj, *nobj;
                    167:     register struct object *op;
                    168: 
                    169:     ch = mvwinch(stdscr, hero.y, hero.x);
                    170:     if (ch != FLOOR && ch != PASSAGE)
                    171:     {
                    172:        msg("There is something there already");
                    173:        return;
                    174:     }
                    175:     if ((obj = get_item("drop", 0)) == NULL)
                    176:        return;
                    177:     op = (struct object *) ldata(obj);
                    178:     if (!dropcheck(op))
                    179:        return;
                    180:     /*
                    181:      * Take it out of the pack
                    182:      */
                    183:     if (op->o_count >= 2 && op->o_type != WEAPON)
                    184:     {
                    185:        nobj = new_item(sizeof *op);
                    186:        op->o_count--;
                    187:        op = (struct object *) ldata(nobj);
                    188:        *op = *((struct object *) ldata(obj));
                    189:        op->o_count = 1;
                    190:        obj = nobj;
                    191:        if (op->o_group != 0)
                    192:                inpack++;
                    193:     }
                    194:     else
                    195:        detach(pack, obj);
                    196:     inpack--;
                    197:     /*
                    198:      * Link it into the level object list
                    199:      */
                    200:     attach(lvl_obj, obj);
                    201:     mvaddch(hero.y, hero.x, op->o_type);
                    202:     op->o_pos = hero;
                    203:     msg("Dropped %s", inv_name(op, TRUE));
                    204: }
                    205: 
                    206: /*
                    207:  * do special checks for dropping or unweilding|unwearing|unringing
                    208:  */
                    209: dropcheck(op)
                    210: register struct object *op;
                    211: {
                    212:     str_t save_max;
                    213: 
                    214:     if (op == NULL)
                    215:        return TRUE;
                    216:     if (op != cur_armor && op != cur_weapon
                    217:        && op != cur_ring[LEFT] && op != cur_ring[RIGHT])
                    218:            return TRUE;
                    219:     if (op->o_flags & ISCURSED)
                    220:     {
                    221:        msg("You can't.  It appears to be cursed.");
                    222:        return FALSE;
                    223:     }
                    224:     if (op == cur_weapon)
                    225:        cur_weapon = NULL;
                    226:     else if (op == cur_armor)
                    227:     {
                    228:        waste_time();
                    229:        cur_armor = NULL;
                    230:     }
                    231:     else if (op == cur_ring[LEFT] || op == cur_ring[RIGHT])
                    232:     {
                    233:        switch (op->o_which)
                    234:        {
                    235:            case R_ADDSTR:
                    236:                save_max = max_stats.s_str;
                    237:                chg_str(-op->o_ac);
                    238:                max_stats.s_str = save_max;
                    239:                break;
                    240:            case R_SEEINVIS:
                    241:                player.t_flags &= ~CANSEE;
                    242:                extinguish(unsee);
                    243:                light(&hero);
                    244:                mvwaddch(cw, hero.y, hero.x, PLAYER);
                    245:                break;
                    246:        }
                    247:        cur_ring[op == cur_ring[LEFT] ? LEFT : RIGHT] = NULL;
                    248:     }
                    249:     return TRUE;
                    250: }
                    251: 
                    252: /*
                    253:  * return a new thing
                    254:  */
                    255: struct linked_list *
                    256: new_thing()
                    257: {
                    258:     register struct linked_list *item;
                    259:     register struct object *cur;
                    260:     register int j, k;
                    261: 
                    262:     item = new_item(sizeof *cur);
                    263:     cur = (struct object *) ldata(item);
                    264:     cur->o_hplus = cur->o_dplus = 0;
                    265:     cur->o_damage = cur->o_hurldmg = "0d0";
                    266:     cur->o_ac = 11;
                    267:     cur->o_count = 1;
                    268:     cur->o_group = 0;
                    269:     cur->o_flags = 0;
                    270:     /*
                    271:      * Decide what kind of object it will be
                    272:      * If we haven't had food for a while, let it be food.
                    273:      */
                    274:     switch (no_food > 3 ? 2 : pick_one(things, NUMTHINGS))
                    275:     {
                    276:        when 0:
                    277:            cur->o_type = POTION;
                    278:            cur->o_which = pick_one(p_magic, MAXPOTIONS);
                    279:        when 1:
                    280:            cur->o_type = SCROLL;
                    281:            cur->o_which = pick_one(s_magic, MAXSCROLLS);
                    282:        when 2:
                    283:            no_food = 0;
                    284:            cur->o_type = FOOD;
                    285:            if (rnd(100) > 10)
                    286:                cur->o_which = 0;
                    287:            else
                    288:                cur->o_which = 1;
                    289:        when 3:
                    290:            cur->o_type = WEAPON;
                    291:            cur->o_which = rnd(MAXWEAPONS);
                    292:            init_weapon(cur, cur->o_which);
                    293:            if ((k = rnd(100)) < 10)
                    294:            {
                    295:                cur->o_flags |= ISCURSED;
                    296:                cur->o_hplus -= rnd(3)+1;
                    297:            }
                    298:            else if (k < 15)
                    299:                cur->o_hplus += rnd(3)+1;
                    300:        when 4:
                    301:            cur->o_type = ARMOR;
                    302:            for (j = 0, k = rnd(100); j < MAXARMORS; j++)
                    303:                if (k < a_chances[j])
                    304:                    break;
                    305:            if (j == MAXARMORS)
                    306:            {
                    307:                debug("Picked a bad armor %d", k);
                    308:                j = 0;
                    309:            }
                    310:            cur->o_which = j;
                    311:            cur->o_ac = a_class[j];
                    312:            if ((k = rnd(100)) < 20)
                    313:            {
                    314:                cur->o_flags |= ISCURSED;
                    315:                cur->o_ac += rnd(3)+1;
                    316:            }
                    317:            else if (k < 28)
                    318:                cur->o_ac -= rnd(3)+1;
                    319:        when 5:
                    320:            cur->o_type = RING;
                    321:            cur->o_which = pick_one(r_magic, MAXRINGS);
                    322:            switch (cur->o_which)
                    323:            {
                    324:                when R_ADDSTR:
                    325:                case R_PROTECT:
                    326:                case R_ADDHIT:
                    327:                case R_ADDDAM:
                    328:                    if ((cur->o_ac = rnd(3)) == 0)
                    329:                    {
                    330:                        cur->o_ac = -1;
                    331:                        cur->o_flags |= ISCURSED;
                    332:                    }
                    333:                when R_AGGR:
                    334:                case R_TELEPORT:
                    335:                    cur->o_flags |= ISCURSED;
                    336:            }
                    337:        when 6:
                    338:            cur->o_type = STICK;
                    339:            cur->o_which = pick_one(ws_magic, MAXSTICKS);
                    340:            fix_stick(cur);
                    341:        otherwise:
                    342:            debug("Picked a bad kind of object");
                    343:            wait_for(' ');
                    344:     }
                    345:     return item;
                    346: }
                    347: 
                    348: /*
                    349:  * pick an item out of a list of nitems possible magic items
                    350:  */
                    351: pick_one(magic, nitems)
                    352: register struct magic_item *magic;
                    353: int nitems;
                    354: {
                    355:     register struct magic_item *end;
                    356:     register int i;
                    357:     register struct magic_item *start;
                    358: 
                    359:     start = magic;
                    360:     for (end = &magic[nitems], i = rnd(100); magic < end; magic++)
                    361:        if (i < magic->mi_prob)
                    362:            break;
                    363:     if (magic == end)
                    364:     {
                    365:        if (wizard)
                    366:        {
                    367:            msg("bad pick_one: %d from %d items", i, nitems);
                    368:            for (magic = start; magic < end; magic++)
                    369:                msg("%s: %d%%", magic->mi_name, magic->mi_prob);
                    370:        }
                    371:        magic = start;
                    372:     }
                    373:     return magic - start;
                    374: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.