[BACK]Return to potions.c CVS log [TXT][DIR] Up to [contributed] / early-roguelike / xrogue

Annotation of early-roguelike/xrogue/potions.c, Revision 1.1.1.1

1.1       rubenllo    1: /*
                      2:     potions.c - Functions for dealing with potions
                      3:
                      4:     XRogue: Expeditions into the Dungeons of Doom
                      5:     Copyright (C) 1991 Robert Pietkivitch
                      6:     All rights reserved.
                      7:
                      8:     Based on "Advanced Rogue"
                      9:     Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
                     10:     All rights reserved.
                     11:
                     12:     Based on "Rogue: Exploring the Dungeons of Doom"
                     13:     Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
                     14:     All rights reserved.
                     15:
                     16:     See the file LICENSE.TXT for full copyright and licensing information.
                     17: */
                     18:
                     19: #include <stdlib.h>
                     20: #include <curses.h>
                     21: #include "rogue.h"
                     22:
                     23: int add_charisma(int change);
                     24: int add_constitution(int change);
                     25: int add_dexterity(int change);
                     26: int add_intelligence(int change);
                     27: int add_strength(int change);
                     28: int add_wisdom(int change);
                     29:
                     30: void res_charisma(int howmuch);
                     31: void res_constitution(int howmuch);
                     32: void res_dexterity(int howmuch);
                     33: void res_intelligence(int howmuch);
                     34: void res_wisdom(int howmuch);
                     35:
                     36: /*
                     37:  * add_abil is an array of functions used to change attributes.  It must be
                     38:  * ordered according to the attribute definitions in rogue.h.
                     39:  */
                     40:
                     41: int (*add_abil[NUMABILITIES])() = {
                     42:     add_intelligence, add_strength, add_wisdom, add_dexterity,
                     43:     add_constitution, add_charisma
                     44: };
                     45:
                     46: /*
                     47:  * res_abil is an array of functions used to change attributes.  It must be
                     48:  * ordered according to the attribute definitions in rogue.h.
                     49:  */
                     50:
                     51: void (*res_abil[NUMABILITIES])() = {
                     52:     res_intelligence, res_strength, res_wisdom, res_dexterity,
                     53:     res_constitution, res_charisma
                     54: };
                     55:
                     56: /*
                     57:  * Increase player's constitution
                     58:  */
                     59:
                     60: int
                     61: add_constitution(int change)
                     62: {
                     63:     /* Do the potion */
                     64:     if (change < 0) {
                     65:         msg("You feel less healthy now.");
                     66:         pstats.s_const += change;
                     67:         if (pstats.s_const < 1) {
                     68:         pstats.s_hpt = -1;
                     69:         msg("You collapse!  --More--");
                     70:         wait_for(' ');
                     71:             death(D_CONSTITUTION);
                     72:     }
                     73:     }
                     74:     else {
                     75:         msg("You feel healthier now.");
                     76:         pstats.s_const = min(pstats.s_const + change, MAXATT);
                     77:     }
                     78:
                     79:     /* Adjust the maximum */
                     80:     if (max_stats.s_const < pstats.s_const)
                     81:         max_stats.s_const = pstats.s_const;
                     82:
                     83:     return(0);
                     84: }
                     85:
                     86: /*
                     87:  * Increase player's charisma
                     88:  */
                     89:
                     90: int
                     91: add_charisma(int change)
                     92: {
                     93:     /* Do the potion */
                     94:     if (change < 0) msg("You feel less attractive now.");
                     95:     else msg("You feel more attractive now.");
                     96:
                     97:     pstats.s_charisma += change;
                     98:     if (pstats.s_charisma > MAXATT) pstats.s_charisma = MAXATT;
                     99:     else if (pstats.s_charisma < 3) pstats.s_charisma = 3;
                    100:
                    101:     /* Adjust the maximum */
                    102:     if (max_stats.s_charisma < pstats.s_charisma)
                    103:         max_stats.s_charisma = pstats.s_charisma;
                    104:
                    105:     return(0);
                    106: }
                    107:
                    108: /*
                    109:  * Increase player's dexterity
                    110:  */
                    111:
                    112: int
                    113: add_dexterity(int change)
                    114: {
                    115:     int ring_str;       /* Value of ring strengths */
                    116:
                    117:     /* Undo any ring changes */
                    118:     ring_str = ring_value(R_ADDHIT);
                    119:     pstats.s_dext -= ring_str;
                    120:
                    121:     /* Now do the potion */
                    122:     if (change < 0) msg("You feel less dextrous now.");
                    123:     else msg("You feel more dextrous now.  Watch those hands!");
                    124:
                    125:     pstats.s_dext += change;
                    126:     if (pstats.s_dext > MAXATT) pstats.s_dext = MAXATT;
                    127:     else if (pstats.s_dext < 3) pstats.s_dext = 3;
                    128:
                    129:     /* Adjust the maximum */
                    130:     if (max_stats.s_dext < pstats.s_dext)
                    131:         max_stats.s_dext = pstats.s_dext;
                    132:
                    133:     /* Now put back the ring changes */
                    134:     if (ring_str)
                    135:         pstats.s_dext += ring_str;
                    136:
                    137:     return(0);
                    138: }
                    139:
                    140: /*
                    141:  * add_haste:
                    142:  *      add a haste to the player
                    143:  */
                    144:
                    145: void
                    146: add_haste(bool blessed)
                    147: {
                    148:     int hasttime;
                    149:
                    150:     if (player.t_ctype == C_MONK) { /* monks cannot be slowed or hasted */
                    151:         msg(nothing);
                    152:         return;
                    153:     }
                    154:
                    155:     if (blessed) hasttime = HASTETIME*2;
                    156:     else hasttime = HASTETIME;
                    157:
                    158:     if (on(player, ISSLOW)) { /* Is person slow? */
                    159:         extinguish(noslow);
                    160:         noslow();
                    161:
                    162:         if (blessed) hasttime = HASTETIME/2;
                    163:         else return;
                    164:     }
                    165:
                    166:     if (on(player, ISHASTE)) {
                    167:         msg("You faint from exhaustion.");
                    168:         player.t_no_move += movement(&player) * rnd(hasttime);
                    169:         player.t_action = A_FREEZE;
                    170:         lengthen(nohaste, roll(hasttime,hasttime));
                    171:     }
                    172:     else {
                    173:         msg("You feel yourself moving %sfaster.", blessed ? "much " : "");
                    174:         turn_on(player, ISHASTE);
                    175:         fuse(nohaste, NULL, roll(hasttime, hasttime), AFTER);
                    176:     }
                    177: }
                    178:
                    179: /*
                    180:  * Increase player's intelligence
                    181:  */
                    182:
                    183: int
                    184: add_intelligence(int change)
                    185: {
                    186:     int ring_str;       /* Value of ring strengths */
                    187:
                    188:     /* Undo any ring changes */
                    189:     ring_str = ring_value(R_ADDINTEL);
                    190:     pstats.s_intel -= ring_str;
                    191:
                    192:     /* Now do the potion */
                    193:     if (change < 0) msg("You feel slightly less intelligent now.");
                    194:     else msg("You feel more intelligent now.  What a mind!");
                    195:
                    196:     pstats.s_intel += change;
                    197:     if (pstats.s_intel > MAXATT) pstats.s_intel = MAXATT;
                    198:     else if (pstats.s_intel < 3) pstats.s_intel = 3;
                    199:
                    200:     /* Adjust the maximum */
                    201:     if (max_stats.s_intel < pstats.s_intel)
                    202:             max_stats.s_intel = pstats.s_intel;
                    203:
                    204:     /* Now put back the ring changes */
                    205:     if (ring_str)
                    206:         pstats.s_intel += ring_str;
                    207:
                    208:     return(0);
                    209: }
                    210:
                    211: /*
                    212:  * this routine makes the hero move slower
                    213:  */
                    214:
                    215: void
                    216: add_slow(void)
                    217: {
                    218:     /* monks cannot be slowed or hasted */
                    219:     if (player.t_ctype == C_MONK || ISWEARING(R_FREEDOM)) {
                    220:         msg(nothing);
                    221:         return;
                    222:     }
                    223:
                    224:     if (on(player, ISHASTE)) { /* Already sped up */
                    225:         extinguish(nohaste);
                    226:         nohaste();
                    227:     }
                    228:     else {
                    229:         msg("You feel yourself moving %sslower.",
                    230:                 on(player, ISSLOW) ? "even " : "");
                    231:         if (on(player, ISSLOW))
                    232:             lengthen(noslow, roll(HASTETIME,HASTETIME));
                    233:         else {
                    234:             turn_on(player, ISSLOW);
                    235:             fuse(noslow, NULL, roll(HASTETIME,HASTETIME), AFTER);
                    236:         }
                    237:     }
                    238: }
                    239:
                    240: /*
                    241:  * Increase player's strength
                    242:  */
                    243:
                    244: int
                    245: add_strength(int change)
                    246: {
                    247:
                    248:     if (change < 0) {
                    249:         msg("You feel slightly weaker now.");
                    250:         chg_str(change);
                    251:     }
                    252:     else {
                    253:         msg("You feel stronger now.  What bulging muscles!");
                    254:         chg_str(change);
                    255:     }
                    256:     return(0);
                    257: }
                    258:
                    259: /*
                    260:  * Increase player's wisdom
                    261:  */
                    262:
                    263: int
                    264: add_wisdom(int change)
                    265: {
                    266:     int ring_str;       /* Value of ring strengths */
                    267:
                    268:     /* Undo any ring changes */
                    269:     ring_str = ring_value(R_ADDWISDOM);
                    270:     pstats.s_wisdom -= ring_str;
                    271:
                    272:     /* Now do the potion */
                    273:     if (change < 0) msg("You feel slightly less wise now.");
                    274:     else msg("You feel wiser now.  What a sage!");
                    275:
                    276:     pstats.s_wisdom += change;
                    277:     if (pstats.s_wisdom > MAXATT) pstats.s_wisdom = MAXATT;
                    278:     else if (pstats.s_wisdom < 3) pstats.s_wisdom = 3;
                    279:
                    280:     /* Adjust the maximum */
                    281:     if (max_stats.s_wisdom < pstats.s_wisdom)
                    282:         max_stats.s_wisdom = pstats.s_wisdom;
                    283:
                    284:     /* Now put back the ring changes */
                    285:     if (ring_str)
                    286:         pstats.s_wisdom += ring_str;
                    287:
                    288:     return(0);
                    289: }
                    290:
                    291: void
                    292: quaff(int which, int kind, int flags, bool is_potion)
                    293: {
                    294:     register struct object *obj;
                    295:     register struct linked_list *item, *titem;
                    296:     register struct thing *th;
                    297:     bool cursed, blessed;
                    298:
                    299:     blessed = FALSE;
                    300:     cursed = FALSE;
                    301:     item = NULL;
                    302:
                    303:     if (which < 0) {    /* figure out which ourselves */
                    304:         /* This is a potion.  */
                    305:         if (player.t_action != C_QUAFF) {
                    306:             int units;
                    307:
                    308:             item = get_item(pack, "quaff", QUAFFABLE, FALSE, FALSE);
                    309:
                    310:             /*
                    311:              * Make certain that it is somethings that we want to drink
                    312:              */
                    313:             if (item == NULL)
                    314:                 return;
                    315:
                    316:             /* How long does it take to quaff? */
                    317:             units = usage_time(item);
                    318:             if (units < 0) return;
                    319:
                    320:             player.t_using = item;      /* Remember what it is */
                    321:             player.t_no_move = units * movement(&player);
                    322:             if ((OBJPTR(item))->o_type == POTION) player.t_action = C_QUAFF;
                    323:             else player.t_action = C_USE;
                    324:             return;
                    325:         }
                    326:
                    327:         /* We have waited our time, let's quaff the potion */
                    328:         item = player.t_using;
                    329:         player.t_using = NULL;
                    330:         player.t_action = A_NIL;
                    331:
                    332:         obj = OBJPTR(item);
                    333:         /* remove it from the pack */
                    334:         inpack--;
                    335:         detach(pack, item);
                    336:
                    337:         flags = obj->o_flags;
                    338:         which = obj->o_which;
                    339:         kind = obj->o_kind;
                    340:     }
                    341:     cursed = flags & ISCURSED;
                    342:     blessed = flags & ISBLESSED;
                    343:
                    344:     switch(which) {
                    345:         case P_CLEAR:
                    346:             if (cursed) {
                    347:                 confus_player();
                    348:             }
                    349:             else {
                    350:                 if (blessed) {  /* Make player immune for the whole game */
                    351:                     extinguish(unclrhead);  /* If we have a fuse, put it out */
                    352:                     msg("A strong blue aura surrounds your head.");
                    353:                 }
                    354:                 else {  /* Just light a fuse for how long player is safe */
                    355:                     if (off(player, ISCLEAR)) {
                    356:                         fuse(unclrhead, NULL, CLRDURATION, AFTER);
                    357:                         msg("A faint blue aura surrounds your head.");
                    358:                     }
                    359:                     else {  /* If we have a fuse lengthen it, else we
                    360:                              * are permanently clear.
                    361:                              */
                    362:                         if (find_slot(unclrhead) == 0)
                    363:                             msg("Your blue aura continues to glow strongly.");
                    364:                         else {
                    365:                             lengthen(unclrhead, CLRDURATION);
                    366:                             msg("Your blue aura brightens for a moment.");
                    367:                         }
                    368:                     }
                    369:                 }
                    370:                 turn_on(player, ISCLEAR);
                    371:                 /* If player is confused, unconfuse him */
                    372:                 if (on(player, ISHUH)) {
                    373:                     extinguish(unconfuse);
                    374:                     unconfuse();
                    375:                 }
                    376:             }
                    377:         when P_HEALING:
                    378:             if (cursed) {
                    379:                 msg("You feel worse now.");
                    380:                 pstats.s_hpt -= roll(pstats.s_lvl, char_class[player.t_ctype].hit_pts);
                    381:                 if (pstats.s_hpt < 1) {
                    382:             pstats.s_hpt = -1;
                    383:             msg("You're life passes before your eyes..  --More--");
                    384:             wait_for(' ');
                    385:                     death(D_POTION);
                    386:         }
                    387:             }
                    388:             else {
                    389:                 if (blessed) {
                    390:                     pstats.s_hpt += roll(pstats.s_lvl+1, char_class[player.t_ctype].hit_pts);
                    391:                     if (pstats.s_hpt > max_stats.s_hpt) {
                    392:                         pstats.s_hpt = ++max_stats.s_hpt;
                    393:                         pstats.s_hpt = ++max_stats.s_hpt;
                    394:             }
                    395:                     if (on(player, ISHUH)) {
                    396:                         extinguish(unconfuse);
                    397:                         unconfuse();
                    398:                     }
                    399:                 }
                    400:                 else {
                    401:                     pstats.s_hpt += roll(pstats.s_lvl+1, char_class[player.t_ctype].hit_pts/2);
                    402:                     if (pstats.s_hpt > max_stats.s_hpt)
                    403:                         pstats.s_hpt = ++max_stats.s_hpt;
                    404:                 }
                    405:                 msg("You begin to feel %sbetter.",
                    406:                         blessed ? "much " : "");
                    407:                 sight();
                    408:                 if (is_potion) p_know[P_HEALING] = TRUE;
                    409:             }
                    410:         when P_ABIL:
                    411:             /* If it is cursed, we take a point away */
                    412:             if (cursed) {
                    413:                 if (ISWEARING(R_SUSABILITY)) {
                    414:                     msg(nothing);
                    415:                     break;
                    416:                 }
                    417:                 else (*add_abil[kind])(-1);
                    418:             }
                    419:
                    420:             /* Otherwise we add points */
                    421:             else (*add_abil[kind])(blessed ? 3 : 1);
                    422:
                    423:             if (is_potion) p_know[P_ABIL] = TRUE;
                    424:         when P_MFIND:
                    425:             /*
                    426:              * Potion of monster detection, if there are monters, detect them
                    427:              */
                    428:             if (mlist != NULL)
                    429:             {
                    430:                 register struct thing *tp;
                    431:                 register struct linked_list *item;
                    432:
                    433:                 wclear(hw);
                    434:                 for (item=mlist; item!=NULL; item=next(item)) {
                    435:                     tp = THINGPTR(item);
                    436:                     if (on(*tp, NODETECT))
                    437:                         continue;
                    438:                     if (off(*tp, ISRUN))/* turn off only on sleeping ones */
                    439:                         turn_off(*tp, CANSURPRISE);
                    440:                     mvwaddch(hw, tp->t_pos.y, tp->t_pos.x,
                    441:                              monsters[tp->t_index].m_appear);
                    442:                 }
                    443:                 rmmsg();
                    444:                 overlay(hw,cw);
                    445:                 draw(cw);
                    446:                 msg("You begin to sense the presence of monsters.");
                    447:                 if (is_potion) p_know[P_MFIND] = TRUE;
                    448:             }
                    449:             else
                    450:                 msg("You have a strange feeling for a moment, then it passes.");
                    451:         when P_TFIND:
                    452:             /*
                    453:              * Potion of magic detection.  Show the potions and scrolls
                    454:              */
                    455:             {
                    456:                 register struct linked_list *mobj;
                    457:                 register struct object *tp;
                    458:                 bool show;
                    459:
                    460:                 show = FALSE;
                    461:                 wclear(hw);
                    462:                 for (mobj = lvl_obj; mobj != NULL; mobj = next(mobj)) {
                    463:                     tp = OBJPTR(mobj);
                    464:                     if (is_magic(tp)) {
                    465:                         char mag_type=MAGIC;
                    466:
                    467:                         /* Mark cursed items or bad weapons */
                    468:                         if ((tp->o_flags & ISCURSED) ||
                    469:                             (tp->o_type == WEAPON &&
                    470:                              (tp->o_hplus < 0 || tp->o_dplus < 0)))
                    471:                                 mag_type = CMAGIC;
                    472:                         else if ((tp->o_flags & ISBLESSED) ||
                    473:                                  (tp->o_type == WEAPON &&
                    474:                                   (tp->o_hplus > 0 || tp->o_dplus > 0)))
                    475:                                         mag_type = BMAGIC;
                    476:                         show = TRUE;
                    477:                         mvwaddch(hw, tp->o_pos.y, tp->o_pos.x, mag_type);
                    478:                     }
                    479:                 }
                    480:                 for (titem = mlist; titem != NULL; titem = next(titem)) {
                    481:                     register struct linked_list *pitem;
                    482:
                    483:                     th = THINGPTR(titem);
                    484:                     if (on(*th, NODETECT)) continue;
                    485:                     for(pitem = th->t_pack; pitem != NULL; pitem = next(pitem)){
                    486:                         tp = OBJPTR(pitem);
                    487:                         if (is_magic(tp)) {
                    488:                             char mag_type=MAGIC;
                    489:
                    490:                             /* Mark cursed items or bad weapons */
                    491:                             if ((tp->o_flags & ISCURSED) ||
                    492:                                 (tp->o_type == WEAPON &&
                    493:                                  (tp->o_hplus < 0 || tp->o_dplus < 0)))
                    494:                                     mag_type = CMAGIC;
                    495:                             else if ((tp->o_flags & ISBLESSED) ||
                    496:                                      (tp->o_type == WEAPON &&
                    497:                                       (tp->o_hplus > 0 || tp->o_dplus > 0)))
                    498:                                             mag_type = BMAGIC;
                    499:                             show = TRUE;
                    500:                             mvwaddch(hw, th->t_pos.y, th->t_pos.x, mag_type);
                    501:                         }
                    502:                     }
                    503:                 }
                    504:                 if (show) {
                    505:                     if (is_potion) p_know[P_TFIND] = TRUE;
                    506:                     rmmsg();
                    507:                     overlay(hw,cw);
                    508:                     draw(cw);
                    509:                     msg("You sense the presence of magic on this level.");
                    510:                     break;
                    511:                 }
                    512:                 else
                    513:                     msg("You have a strange feeling for a moment, then it passes.");
                    514:             }
                    515:         when P_SEEINVIS:
                    516:             if (cursed) {
                    517:                 if (!find_slot(sight))
                    518:                 {
                    519:                     msg("A cloak of darkness falls around you.");
                    520:                     turn_on(player, ISBLIND);
                    521:                     fuse(sight, NULL, SEEDURATION, AFTER);
                    522:                     light(&hero);
                    523:                 }
                    524:                 else {
                    525:                     msg("The darkness around you thickens. ");
                    526:                     lengthen(sight, SEEDURATION);
                    527:                 }
                    528:             }
                    529:             else {
                    530:                 if (off(player, CANSEE)) {
                    531:                     turn_on(player, CANSEE);
                    532:                     msg("Your eyes begin to tingle.");
                    533:                     fuse(unsee, NULL, blessed ? SEEDURATION*3 :SEEDURATION, AFTER);
                    534:                     light(&hero);
                    535:                 }
                    536:                 else if (find_slot(unsee) != 0) {
                    537:                     msg("You eyes continue to tingle.");
                    538:                     lengthen(unsee, blessed ? SEEDURATION*3 : SEEDURATION);
                    539:         }
                    540:                 sight();
                    541:             }
                    542:         when P_PHASE:
                    543:             if (cursed) {
                    544:                 msg("You can't move.");
                    545:                 player.t_no_move = movement(&player) * FREEZETIME;
                    546:                 player.t_action = A_FREEZE;
                    547:             }
                    548:             else {
                    549:                 int duration;
                    550:
                    551:                 if (blessed) duration = 3;
                    552:                 else duration = 1;
                    553:
                    554:                 if (on(player, CANINWALL))
                    555:                     lengthen(unphase, duration*PHASEDURATION);
                    556:                 else {
                    557:                     fuse(unphase, NULL, duration*PHASEDURATION, AFTER);
                    558:                     turn_on(player, CANINWALL);
                    559:                 }
                    560:                 msg("You feel %slight-headed!",
                    561:                     blessed ? "very " : "");
                    562:             }
                    563:         when P_FLY: {
                    564:             int duration;
                    565:             bool say_message;
                    566:
                    567:             say_message = TRUE;
                    568:
                    569:             if (blessed) duration = 3;
                    570:             else duration = 1;
                    571:
                    572:             if (on(player, ISFLY)) {
                    573:                 if (find_slot(land))
                    574:                     lengthen(land, duration*FLYTIME);
                    575:                 else {
                    576:                     msg("Nothing happens.");    /* Flying by cloak */
                    577:                     say_message = FALSE;
                    578:                 }
                    579:             }
                    580:             else {
                    581:                 fuse(land, NULL, duration*FLYTIME, AFTER);
                    582:                 turn_on(player, ISFLY);
                    583:             }
                    584:             if (say_message) {
                    585:                 if (is_potion) p_know[P_FLY] = TRUE;
                    586:                 msg("You feel %slighter than air!", blessed ? "much " : "");
                    587:             }
                    588:         }
                    589:         when P_RAISE:
                    590:             if (cursed) lower_level(D_POTION);
                    591:             else {
                    592:                 msg("You suddenly feel %smore skillful",
                    593:                         blessed ? "much " : "");
                    594:                 p_know[P_RAISE] = TRUE;
                    595:                 raise_level();
                    596:                 do_panic(0);         /* this startles them */
                    597:                 if (blessed) raise_level();
                    598:             }
                    599:         when P_HASTE:
                    600:             if (cursed) {       /* Slow player down */
                    601:                 add_slow();
                    602:             }
                    603:             else {
                    604:                 add_haste(blessed);
                    605:                 if (is_potion) p_know[P_HASTE] = TRUE;
                    606:             }
                    607:         when P_RESTORE: {
                    608:             register int i, howmuch, strength_tally;
                    609:
                    610:             msg("Hey, this tastes great.  It make you feel %swarm all over.",
                    611:                 blessed ? "really " : "");
                    612:             howmuch = blessed ? 3 : 1;
                    613:
                    614:             for (i=0; i<NUMABILITIES; i++) {
                    615:                 if (i == A_STRENGTH) {
                    616:                     if (lost_str) {
                    617:                         if (lost_str > howmuch) {
                    618:                             lost_str -= howmuch;
                    619:
                    620:                             /*
                    621:                              * Save the lost strength.  We have to set
                    622:                              * temporarilty set it to 0 so that res_strength
                    623:                              * will not restore it.
                    624:                              */
                    625:                             strength_tally = lost_str;
                    626:                             lost_str = 0;
                    627:                             res_strength(howmuch);
                    628:                             lost_str = strength_tally;
                    629:                         }
                    630:                         else {
                    631:                         lost_str = 0;
                    632:                             extinguish(res_strength);
                    633:                             res_strength(howmuch);
                    634:                         }
                    635:                     }
                    636:                     else res_strength(howmuch);
                    637:                 }
                    638:                 else (*res_abil[i])(howmuch);
                    639:             }
                    640:         }
                    641:         when P_INVIS:
                    642:             if (off(player, ISINVIS)) {
                    643:                 turn_on(player, ISINVIS);
                    644:                 msg("You have a tingling feeling all over your body");
                    645:                 fuse(appear, NULL, blessed ? GONETIME*3 : GONETIME, AFTER);
                    646:                 PLAYER = IPLAYER;
                    647:                 light(&hero);
                    648:             }
                    649:             else {
                    650:                 if (find_slot(appear)) {
                    651:                     msg("Your tingling feeling surges.");
                    652:                     lengthen(appear, blessed ? GONETIME*3 : GONETIME);
                    653:                 }
                    654:                 else msg("Nothing happens.");   /* Using cloak */
                    655:             }
                    656:
                    657:         when P_FFIND:
                    658:             {
                    659:                 register struct linked_list *nitem;
                    660:                 register struct object *nobj;
                    661:                 bool show;
                    662:
                    663:                 show = FALSE;
                    664:                 wclear(hw);
                    665:                 for (nitem = lvl_obj; nitem != NULL; nitem = next(nitem)) {
                    666:                     nobj = OBJPTR(nitem);
                    667:                     if (nobj->o_type == FOOD) {
                    668:                         show = TRUE;
                    669:                         mvwaddch(hw, nobj->o_pos.y, nobj->o_pos.x, FOOD);
                    670:                     }
                    671:                 }
                    672:                 for (nitem = mlist; nitem != NULL; nitem = next(nitem)) {
                    673:                     register struct linked_list *pitem;
                    674:                     register struct thing *th;
                    675:
                    676:                     th = THINGPTR(nitem);
                    677:                     if (on(*th, NODETECT)) continue;
                    678:                     for(pitem = th->t_pack; pitem != NULL; pitem = next(pitem)){
                    679:                         nobj = OBJPTR(pitem);
                    680:                         if (nobj->o_type == FOOD) {
                    681:                             show = TRUE;
                    682:                             mvwaddch(hw, th->t_pos.y, th->t_pos.x, FOOD);
                    683:                         }
                    684:                     }
                    685:                 }
                    686:                 if (is_potion) p_know[P_FFIND] = TRUE;
                    687:                 if (show) {
                    688:                     rmmsg();
                    689:                     msg("Your nose tingles.");
                    690:                     rmmsg();
                    691:                     overlay(hw,cw);
                    692:                     draw(cw);
                    693:                     msg("You sense the presence of food on this level.");
                    694:                 }
                    695:                 else
                    696:                     msg("You have a strange feeling for a moment, then it passes.");
                    697:             }
                    698:
                    699:         when P_SKILL:
                    700:             if (cursed) {
                    701:                 msg("You feel less skillful.");
                    702:
                    703:                 /* Does he currently have an artifical skill? */
                    704:                 if (!find_slot(unskill)) {      /* No skill */
                    705:                     pstats.s_lvladj = -2;
                    706:                     pstats.s_lvl += pstats.s_lvladj;
                    707:                     fuse(unskill, NULL, SKILLDURATION, AFTER);
                    708:                 }
                    709:                 else {  /* Has an artifical skill */
                    710:                     /* Is the skill beneficial? */
                    711:                     if (pstats.s_lvladj > 0) {
                    712:                         /* Decrease the previous skill advantage */
                    713:                         pstats.s_lvl -= 2;
                    714:                         pstats.s_lvladj -= 2;
                    715:
                    716:                         /* If there is now a negative skill, lengthen time */
                    717:                         if (pstats.s_lvladj < 0)
                    718:                             lengthen(unskill, SKILLDURATION);
                    719:
                    720:                         /* If there is no skill advantage, unfuse us */
                    721:                         else if (pstats.s_lvladj == 0) extinguish(unskill);
                    722:                     }
                    723:                     else {      /* Already bad */
                    724:                         /* Make it a little worse, and lengthen it */
                    725:                         pstats.s_lvl--;
                    726:                         pstats.s_lvladj--;
                    727:                         lengthen(unskill, SKILLDURATION);
                    728:                     }
                    729:                 }
                    730:
                    731:                 /* Is our level too low now? */
                    732:                 if (pstats.s_lvl < 1) {
                    733:             pstats.s_hpt = -1;
                    734:             msg("You cough, choke, and finally die.  --More--");
                    735:             wait_for(' ');
                    736:             death(D_POTION);
                    737:         }
                    738:             }
                    739:             else {
                    740:                 int adjust;
                    741:
                    742:                 msg("You feel more skillful.");
                    743:                 max_stats.s_hpt++;
                    744:                 pstats.s_hpt++;
                    745:
                    746:                 /* Get the adjustment */
                    747:                 if (blessed)
                    748:                     adjust = rnd(4) + 2;
                    749:                 else
                    750:                     adjust = rnd(2) + 1;
                    751:
                    752:         /* The Fighter likes this */
                    753:             if (player.t_ctype == C_FIGHTER) {
                    754:                     max_stats.s_hpt++;
                    755:                     pstats.s_hpt++;
                    756:                     adjust = rnd(2) + 1;
                    757:             }
                    758:
                    759:                 /* Does he currently have an artifical skill? */
                    760:                 if (!find_slot(unskill)) {
                    761:                     pstats.s_lvladj = adjust;
                    762:                     pstats.s_lvl += pstats.s_lvladj;
                    763:                     fuse(unskill, NULL,
                    764:                          blessed ? SKILLDURATION*2 : SKILLDURATION, AFTER);
                    765:                 }
                    766:                 else {  /* Has an artifical skill */
                    767:                     /* Is the skill detrimental? */
                    768:                     if (pstats.s_lvladj < 0) {
                    769:                         /* Decrease the previous skill advantage */
                    770:                         pstats.s_lvl += adjust;
                    771:                         pstats.s_lvladj += adjust;
                    772:
                    773:                         /* If there is now a positive skill, lengthen time */
                    774:                         if (pstats.s_lvladj < 0)
                    775:                             lengthen(unskill, SKILLDURATION);
                    776:
                    777:                         /* If there is no skill advantage, unfuse us */
                    778:                         else if (pstats.s_lvladj == 0) extinguish(unskill);
                    779:                     }
                    780:                     else {      /* Already good */
                    781:                         /*
                    782:                          * Make the skill the maximum of the current good
                    783:                          * skill and what the adjust would give him.
                    784:                          */
                    785:                         pstats.s_lvl -= pstats.s_lvladj;
                    786:                         pstats.s_lvladj = max(pstats.s_lvladj, adjust);
                    787:                         pstats.s_lvl += pstats.s_lvladj;
                    788:                         lengthen(unskill,
                    789:                                  blessed ? SKILLDURATION*2 : SKILLDURATION);
                    790:                     }
                    791:                 }
                    792:             }
                    793:
                    794:         when P_FIRE: {
                    795:             int duration;
                    796:             bool say_message;
                    797:
                    798:             say_message = TRUE;
                    799:
                    800:             if (blessed) duration = 8;
                    801:             else duration = 3;
                    802:
                    803:             if (on(player, NOFIRE)) {
                    804:             if (cursed) {
                    805:             msg("You quench your thirst. ");
                    806:             say_message = FALSE;
                    807:             }
                    808:                 else if (find_slot(nofire)) {
                    809:                     lengthen(nofire, duration*FIRETIME);
                    810:             msg("Your feeling of fire resistance increases. ");
                    811:             say_message = FALSE;
                    812:         }
                    813:                 else {
                    814:                     msg("You experience heat waves. ");    /* has on a ring */
                    815:                     say_message = FALSE;
                    816:                 }
                    817:             }
                    818:         else if (cursed) {
                    819:         msg("You quench your thirst. ");
                    820:         say_message = FALSE;
                    821:         }
                    822:             else {
                    823:                 fuse(nofire, NULL, duration*FIRETIME, AFTER);
                    824:                 turn_on(player, NOFIRE);
                    825:             }
                    826:             if (say_message)  {
                    827:                 if (is_potion) p_know[P_FIRE] = TRUE;
                    828:                 msg("You feel %sfire resistant", blessed ? "very " : "");
                    829:             }
                    830:         }
                    831:         when P_COLD: {
                    832:             int duration;
                    833:             bool say_message;
                    834:
                    835:             say_message = TRUE;
                    836:
                    837:             if (blessed) duration = 8;
                    838:             else duration = 3;
                    839:
                    840:             if (on(player, NOCOLD)) {
                    841:             if (cursed) {
                    842:             msg("You quench your thirst. ");
                    843:             say_message = FALSE;
                    844:             }
                    845:                 else if (find_slot(nocold)) {
                    846:                     lengthen(nocold, duration*COLDTIME);
                    847:             msg("Your feeling of cold resistance increases. ");
                    848:             say_message = FALSE;
                    849:         }
                    850:                 else {
                    851:                     msg("You feel a cold chill. ");    /* has on a ring */
                    852:                     say_message = FALSE;
                    853:                 }
                    854:             }
                    855:         else if (cursed) {
                    856:         msg("You quench your thirst. ");
                    857:         say_message = FALSE;
                    858:         }
                    859:             else {
                    860:                 fuse(nocold, NULL, duration*COLDTIME, AFTER);
                    861:                 turn_on(player, NOCOLD);
                    862:             }
                    863:             if (say_message)  {
                    864:                 if (is_potion) p_know[P_COLD] = TRUE;
                    865:                 msg("You feel %scold resistant", blessed ? "very " : "");
                    866:             }
                    867:         }
                    868:         when P_LIGHTNING: {
                    869:             int duration;
                    870:             bool say_message;
                    871:
                    872:             say_message = TRUE;
                    873:
                    874:             if (blessed) duration = 8;
                    875:             else duration = 3;
                    876:
                    877:             if (on(player, NOBOLT)) {
                    878:             if (cursed) {
                    879:             msg("You quench your thirst. ");
                    880:             say_message = FALSE;
                    881:             }
                    882:                 else if (find_slot(nobolt)) {
                    883:                     lengthen(nobolt, duration*BOLTTIME);
                    884:             msg("Your blue skin deepens in hue. ");
                    885:             say_message = FALSE;
                    886:         }
                    887:         else msg(nothing);
                    888:             }
                    889:         else if (cursed) {
                    890:         msg("You quench your thirst. ");
                    891:         say_message = FALSE;
                    892:         }
                    893:             else {
                    894:                 fuse(nobolt, NULL, duration*BOLTTIME, AFTER);
                    895:                 turn_on(player, NOBOLT);
                    896:             }
                    897:             if (say_message) {
                    898:                 if (is_potion) p_know[P_LIGHTNING] = TRUE;
                    899:                 msg("Your skin turns %sblue!", blessed ? "very " : "");
                    900:         }
                    901:         }
                    902:         when P_POISON:
                    903:             if (!save(VS_POISON, &player, -2)) {
                    904:                 msg("You feel very sick now.");
                    905:                 pstats.s_hpt /= 2;
                    906:                 if (!ISWEARING(R_SUSABILITY))
                    907:                     pstats.s_const--;
                    908:             }
                    909:             else {
                    910:                 msg("You feel sick now.");
                    911:                 pstats.s_hpt -= (pstats.s_hpt / 3);
                    912:             }
                    913:             if (pstats.s_const < 1 || pstats.s_hpt < 1) {
                    914:         pstats.s_hpt = -1;
                    915:         msg("You didn't survive!  --More--");
                    916:         wait_for(' ');
                    917:                 death(D_POISON);
                    918:         }
                    919:         otherwise:
                    920:             msg("What an odd tasting potion!");
                    921:             return;
                    922:     }
                    923:     status(FALSE);
                    924:     if (is_potion && item && p_know[which] && p_guess[which])
                    925:     {
                    926:         free(p_guess[which]);
                    927:         p_guess[which] = NULL;
                    928:     }
                    929:     else if (is_potion                  &&
                    930:              !p_know[which]             &&
                    931:              item                       &&
                    932:              askme                      &&
                    933:              (flags & ISKNOW) == 0      &&
                    934:              (flags & ISPOST) == 0      &&
                    935:              p_guess[which] == NULL) {
                    936:         nameitem(item, FALSE);
                    937:     }
                    938:     if (item != NULL) o_discard(item);
                    939:     updpack(TRUE, &player);
                    940: }
                    941:
                    942:
                    943: /*
                    944:  * res_dexterity:
                    945:  *      Restore player's dexterity
                    946:  *      if called with zero the restore fully
                    947:  */
                    948:
                    949: void
                    950: res_dexterity(int howmuch)
                    951: {
                    952:     short save_max;
                    953:     int ring_str;
                    954:
                    955:     if (howmuch < 0) return;
                    956:
                    957:     /* Discount the ring value */
                    958:     ring_str = ring_value(R_ADDHIT);
                    959:     pstats.s_dext -= ring_str;
                    960:
                    961:     if (pstats.s_dext < max_stats.s_dext ) {
                    962:         if (howmuch == 0)
                    963:             pstats.s_dext = max_stats.s_dext;
                    964:         else
                    965:             pstats.s_dext = min(pstats.s_dext+howmuch, max_stats.s_dext);
                    966:     }
                    967:
                    968:     /* Redo the rings */
                    969:     if (ring_str) {
                    970:         save_max = max_stats.s_dext;
                    971:         pstats.s_dext += ring_str;
                    972:         max_stats.s_dext = save_max;
                    973:     }
                    974:     return;
                    975: }
                    976:
                    977: /*
                    978:  * res_intelligence:
                    979:  *      Restore player's intelligence
                    980:  */
                    981:
                    982: void
                    983: res_intelligence(int howmuch)
                    984: {
                    985:     short save_max;
                    986:     int ring_str;
                    987:
                    988:     if (howmuch <= 0) return;
                    989:
                    990:     /* Discount the ring value */
                    991:     ring_str = ring_value(R_ADDINTEL);
                    992:     pstats.s_intel -= ring_str;
                    993:
                    994:     pstats.s_intel = min(pstats.s_intel + howmuch, max_stats.s_intel);
                    995:
                    996:     /* Redo the rings */
                    997:     if (ring_str) {
                    998:         save_max = max_stats.s_intel;
                    999:         pstats.s_intel += ring_str;
                   1000:         max_stats.s_intel = save_max;
                   1001:     }
                   1002:     return;
                   1003: }
                   1004:
                   1005: /*
                   1006:  * res_wisdom:
                   1007:  *      Restore player's wisdom
                   1008:  */
                   1009:
                   1010: void
                   1011: res_wisdom(int howmuch)
                   1012: {
                   1013:     short save_max;
                   1014:     int ring_str;
                   1015:
                   1016:     if (howmuch <= 0) return;
                   1017:
                   1018:     /* Discount the ring value */
                   1019:     ring_str = ring_value(R_ADDWISDOM);
                   1020:     pstats.s_wisdom -= ring_str;
                   1021:
                   1022:     pstats.s_wisdom = min(pstats.s_wisdom + howmuch, max_stats.s_wisdom);
                   1023:
                   1024:     /* Redo the rings */
                   1025:     if (ring_str) {
                   1026:         save_max = max_stats.s_wisdom;
                   1027:         pstats.s_wisdom += ring_str;
                   1028:         max_stats.s_wisdom = save_max;
                   1029:     }
                   1030:     return;
                   1031: }
                   1032:
                   1033: /*
                   1034:  * res_constitution:
                   1035:  *      Restore the players constitution.
                   1036:  */
                   1037:
                   1038: void
                   1039: res_constitution(int howmuch)
                   1040: {
                   1041:     if (howmuch > 0)
                   1042:         pstats.s_const = min(pstats.s_const + howmuch, max_stats.s_const);
                   1043:
                   1044:     return;
                   1045: }
                   1046:
                   1047: /*
                   1048:  * res_charisma:
                   1049:  *      Restore the players charisma.
                   1050:  */
                   1051:
                   1052: void
                   1053: res_charisma(int howmuch)
                   1054: {
                   1055:     if (howmuch > 0)
                   1056:         pstats.s_charisma =
                   1057:             min(pstats.s_charisma + howmuch, max_stats.s_charisma);
                   1058:
                   1059:     return;
                   1060: }

CVSweb