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

Annotation of early-roguelike/arogue5/daemons.c, Revision 1.1

1.1     ! rubenllo    1: /*
        !             2:  * All the daemon and fuse functions are in here
        !             3:  *
        !             4:  * Advanced Rogue
        !             5:  * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
        !             6:  * All rights reserved.
        !             7:  *
        !             8:  * Based on "Rogue: Exploring the Dungeons of Doom"
        !             9:  * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
        !            10:  * All rights reserved.
        !            11:  *
        !            12:  * See the file LICENSE.TXT for full copyright and licensing information.
        !            13:  */
        !            14:
        !            15: #include "curses.h"
        !            16: #include "rogue.h"
        !            17:
        !            18: int between = 0;
        !            19:
        !            20: /*
        !            21:  * doctor:
        !            22:  *     A healing daemon that restors hit points after rest
        !            23:  */
        !            24:
        !            25: void
        !            26: doctor(struct thing *tp)
        !            27: {
        !            28:     register int ohp;
        !            29:     register int limit, new_points;
        !            30:     register struct stats *curp; /* current stats pointer */
        !            31:     register struct stats *maxp; /* max stats pointer */
        !            32:
        !            33:     curp = &(tp->t_stats);
        !            34:     maxp = &(tp->maxstats);
        !            35:     if (curp->s_hpt == maxp->s_hpt) {
        !            36:        tp->t_quiet = 0;
        !            37:        return;
        !            38:     }
        !            39:     tp->t_quiet++;
        !            40:     switch (tp->t_ctype) {
        !            41:        case C_MAGICIAN:
        !            42:            limit = 8 - curp->s_lvl;
        !            43:            new_points = curp->s_lvl - 3;
        !            44:        when C_THIEF:
        !            45:            limit = 8 - curp->s_lvl;
        !            46:            new_points = curp->s_lvl - 2;
        !            47:        when C_CLERIC:
        !            48:            limit = 8 - curp->s_lvl;
        !            49:            new_points = curp->s_lvl - 3;
        !            50:        when C_FIGHTER:
        !            51:            limit = 16 - curp->s_lvl*2;
        !            52:            new_points = curp->s_lvl - 5;
        !            53:        when C_MONSTER:
        !            54:            limit = 16 - curp->s_lvl;
        !            55:            new_points = curp->s_lvl - 6;
        !            56:        otherwise:
        !            57:            debug("what a strange character you are!");
        !            58:            return;
        !            59:     }
        !            60:     ohp = curp->s_hpt;
        !            61:     if (off(*tp, HASDISEASE) && off(*tp, DOROT)) {
        !            62:        if (curp->s_lvl < 8) {
        !            63:            if (tp->t_quiet > limit) {
        !            64:                curp->s_hpt++;
        !            65:                tp->t_quiet = 0;
        !            66:            }
        !            67:        }
        !            68:        else {
        !            69:            if (tp->t_quiet >= 3) {
        !            70:                curp->s_hpt += rnd(new_points)+1;
        !            71:                tp->t_quiet = 0;
        !            72:            }
        !            73:        }
        !            74:     }
        !            75:     if (tp == &player) {
        !            76:        if (ISRING(LEFT_1, R_REGEN)) curp->s_hpt++;
        !            77:        if (ISRING(LEFT_2, R_REGEN)) curp->s_hpt++;
        !            78:        if (ISRING(LEFT_3, R_REGEN)) curp->s_hpt++;
        !            79:        if (ISRING(LEFT_4, R_REGEN)) curp->s_hpt++;
        !            80:        if (ISRING(RIGHT_1, R_REGEN)) curp->s_hpt++;
        !            81:        if (ISRING(RIGHT_2, R_REGEN)) curp->s_hpt++;
        !            82:        if (ISRING(RIGHT_3, R_REGEN)) curp->s_hpt++;
        !            83:        if (ISRING(RIGHT_4, R_REGEN)) curp->s_hpt++;
        !            84:     }
        !            85:     if (on(*tp, ISREGEN))
        !            86:        curp->s_hpt += curp->s_lvl/10 + 1;
        !            87:     if (ohp != curp->s_hpt) {
        !            88:        if (curp->s_hpt >= maxp->s_hpt) {
        !            89:            curp->s_hpt = maxp->s_hpt;
        !            90:            if (off(*tp, WASTURNED) && on(*tp, ISFLEE) && tp != &player) {
        !            91:                turn_off(*tp, ISFLEE);
        !            92:                tp->t_oldpos = tp->t_pos;       /* Start our trek over */
        !            93:            }
        !            94:        }
        !            95:     }
        !            96: }
        !            97:
        !            98: /*
        !            99:  * Swander:
        !           100:  *     Called when it is time to start rolling for wandering monsters
        !           101:  */
        !           102:
        !           103: void
        !           104: swander(void)
        !           105: {
        !           106:     start_daemon(rollwand, 0, BEFORE);
        !           107: }
        !           108:
        !           109: /*
        !           110:  * rollwand:
        !           111:  *     Called to roll to see if a wandering monster starts up
        !           112:  */
        !           113:
        !           114: void
        !           115: rollwand(void)
        !           116: {
        !           117:     if (++between >= 4)
        !           118:     {
        !           119:        /* Theives may not awaken a monster */
        !           120:        if ((roll(1, 6) == 4) &&
        !           121:           ((player.t_ctype != C_THIEF) || (rnd(30) >= dex_compute()))) {
        !           122:            if (levtype != POSTLEV)
        !           123:                wanderer();
        !           124:            kill_daemon(rollwand);
        !           125:            fuse(swander, 0, WANDERTIME, BEFORE);
        !           126:        }
        !           127:        between = 0;
        !           128:     }
        !           129: }
        !           130: /*
        !           131:  * this function is a daemon called each turn when the character is a thief
        !           132:  */
        !           133: void
        !           134: trap_look(void)
        !           135: {
        !           136:     if (rnd(100) < (2*dex_compute() + 5*pstats.s_lvl))
        !           137:        search(TRUE, FALSE);
        !           138: }
        !           139:
        !           140: /*
        !           141:  * unconfuse:
        !           142:  *     Release the poor player from his confusion
        !           143:  */
        !           144:
        !           145: void
        !           146: unconfuse(void)
        !           147: {
        !           148:     turn_off(player, ISHUH);
        !           149:     msg("You feel less confused now");
        !           150: }
        !           151:
        !           152:
        !           153: /*
        !           154:  * unsee:
        !           155:  *     He lost his see invisible power
        !           156:  */
        !           157:
        !           158: void
        !           159: unsee(void)
        !           160: {
        !           161:     if (!ISWEARING(R_SEEINVIS)) {
        !           162:        turn_off(player, CANSEE);
        !           163:        msg("The tingling feeling leaves your eyes");
        !           164:     }
        !           165: }
        !           166:
        !           167: /*
        !           168:  * unstink:
        !           169:  *     Remove to-hit handicap from player
        !           170:  */
        !           171:
        !           172: void
        !           173: unstink(void)
        !           174: {
        !           175:     turn_off(player, HASSTINK);
        !           176: }
        !           177:
        !           178: /*
        !           179:  * unclrhead:
        !           180:  *     Player is no longer immune to confusion
        !           181:  */
        !           182:
        !           183: void
        !           184: unclrhead(void)
        !           185: {
        !           186:     turn_off(player, ISCLEAR);
        !           187:     msg("The blue aura about your head fades away.");
        !           188: }
        !           189:
        !           190: /*
        !           191:  * unphase:
        !           192:  *     Player can no longer walk through walls
        !           193:  */
        !           194:
        !           195: void
        !           196: unphase(void)
        !           197: {
        !           198:     turn_off(player, CANINWALL);
        !           199:     msg("Your dizzy feeling leaves you.");
        !           200:     if (!step_ok(hero.y, hero.x, NOMONST, &player)) death(D_PETRIFY);
        !           201: }
        !           202:
        !           203: /*
        !           204:  * land:
        !           205:  *     Player can no longer fly
        !           206:  */
        !           207:
        !           208: void
        !           209: land(void)
        !           210: {
        !           211:     turn_off(player, ISFLY);
        !           212:     msg("You regain your normal weight");
        !           213:     running = FALSE;
        !           214: }
        !           215:
        !           216: /*
        !           217:  * sight:
        !           218:  *     He gets his sight back
        !           219:  */
        !           220:
        !           221: void
        !           222: sight(void)
        !           223: {
        !           224:     if (on(player, ISBLIND))
        !           225:     {
        !           226:        extinguish(sight);
        !           227:        turn_off(player, ISBLIND);
        !           228:        light(&hero);
        !           229:        msg("The veil of darkness lifts");
        !           230:     }
        !           231: }
        !           232:
        !           233: /*
        !           234:  * res_strength:
        !           235:  *     Restore player's strength
        !           236:  */
        !           237:
        !           238: void
        !           239: res_strength(void)
        !           240: {
        !           241:
        !           242:     /* If lost_str is non-zero, restore that amount of strength,
        !           243:      * else all of it
        !           244:      */
        !           245:     if (lost_str) {
        !           246:        chg_str(lost_str);
        !           247:        lost_str = 0;
        !           248:     }
        !           249:
        !           250:     /* Otherwise, put player at the maximum strength */
        !           251:     else {
        !           252:        pstats.s_str = max_stats.s_str + ring_value(R_ADDSTR);
        !           253:     }
        !           254:
        !           255:     updpack(TRUE);
        !           256: }
        !           257:
        !           258: /*
        !           259:  * nohaste:
        !           260:  *     End the hasting
        !           261:  */
        !           262:
        !           263: void
        !           264: nohaste(void)
        !           265: {
        !           266:     turn_off(player, ISHASTE);
        !           267:     msg("You feel yourself slowing down.");
        !           268: }
        !           269:
        !           270: /*
        !           271:  * noslow:
        !           272:  *     End the slowing
        !           273:  */
        !           274:
        !           275: void
        !           276: noslow(void)
        !           277: {
        !           278:     turn_off(player, ISSLOW);
        !           279:     msg("You feel yourself speeding up.");
        !           280: }
        !           281:
        !           282: /*
        !           283:  * suffocate:
        !           284:  *     If this gets called, the player has suffocated
        !           285:  */
        !           286:
        !           287: void
        !           288: suffocate(void)
        !           289: {
        !           290:     death(D_SUFFOCATION);
        !           291: }
        !           292:
        !           293: /*
        !           294:  * digest the hero's food
        !           295:  */
        !           296: void
        !           297: stomach(void)
        !           298: {
        !           299:     register int oldfood, old_hunger, food_use, i;
        !           300:
        !           301:     old_hunger = hungry_state;
        !           302:     if (food_left <= 0)
        !           303:     {
        !           304:        /*
        !           305:         * the hero is fainting
        !           306:         */
        !           307:        if (no_command || rnd(100) > 20)
        !           308:            return;
        !           309:        no_command = rnd(8)+4;
        !           310:        if (!terse)
        !           311:            addmsg("You feel too weak from lack of food.  ");
        !           312:        msg("You faint");
        !           313:        running = FALSE;
        !           314:        count = 0;
        !           315:        hungry_state = F_FAINT;
        !           316:     }
        !           317:     else
        !           318:     {
        !           319:        oldfood = food_left;
        !           320:        food_use = 0;
        !           321:        for (i=0; i<MAXRELIC; i++) { /* each relic eats an additional food */
        !           322:            if (cur_relic[i])
        !           323:                food_use++;
        !           324:        }
        !           325:        food_use +=    (ring_eat(LEFT_1)  + ring_eat(LEFT_2)  +
        !           326:                        ring_eat(LEFT_3)  + ring_eat(LEFT_4)  +
        !           327:                        ring_eat(RIGHT_1) + ring_eat(RIGHT_2) +
        !           328:                        ring_eat(RIGHT_3) + ring_eat(RIGHT_4) +
        !           329:                        foodlev);
        !           330:        if (food_use < 1)
        !           331:            food_use = 1;
        !           332:        food_left -= food_use;
        !           333:        if (food_left < MORETIME && oldfood >= MORETIME) {
        !           334:            msg("You are starting to feel weak");
        !           335:            running = FALSE;
        !           336:            hungry_state = F_WEAK;
        !           337:        }
        !           338:        else if (food_left < 2 * MORETIME && oldfood >= 2 * MORETIME)
        !           339:        {
        !           340:            msg(terse ? "Getting hungry" : "You are starting to get hungry");
        !           341:            running = FALSE;
        !           342:            hungry_state = F_HUNGRY;
        !           343:        }
        !           344:
        !           345:     }
        !           346:     if (old_hunger != hungry_state)
        !           347:        updpack(TRUE);
        !           348:     wghtchk();
        !           349: }
        !           350: /*
        !           351:  * daemon for curing the diseased
        !           352:  */
        !           353: void
        !           354: cure_disease(void)
        !           355: {
        !           356:     turn_off(player, HASDISEASE);
        !           357:     if (off (player, HASINFEST))
        !           358:        msg(terse ? "You feel yourself improving"
        !           359:                : "You begin to feel yourself improving again");
        !           360: }
        !           361:
        !           362: /*
        !           363:  * daemon for adding back dexterity
        !           364:  */
        !           365: void
        !           366: un_itch(void)
        !           367: {
        !           368:     if (--lost_dext < 1) {
        !           369:        lost_dext = 0;
        !           370:        turn_off(player, HASITCH);
        !           371:     }
        !           372:     res_dexterity(1);
        !           373: }
        !           374: /*
        !           375:  * appear:
        !           376:  *     Become visible again
        !           377:  */
        !           378: void
        !           379: appear(void)
        !           380: {
        !           381:     turn_off(player, ISINVIS);
        !           382:     PLAYER = VPLAYER;
        !           383:     msg("The tingling feeling leaves your body");
        !           384:     light(&hero);
        !           385: }
        !           386: /*
        !           387:  * dust_appear:
        !           388:  *     dust of disappearance wears off
        !           389:  */
        !           390: void
        !           391: dust_appear(void)
        !           392: {
        !           393:     turn_off(player, ISINVIS);
        !           394:     PLAYER = VPLAYER;
        !           395:     msg("You become visible again");
        !           396:     light(&hero);
        !           397: }
        !           398: /*
        !           399:  * unchoke:
        !           400:  *     the effects of "dust of choking and sneezing" wear off
        !           401:  */
        !           402: void
        !           403: unchoke(void)
        !           404: {
        !           405:     if (!find_slot(unconfuse))
        !           406:        turn_off(player, ISHUH);
        !           407:     if (!find_slot(sight))
        !           408:        turn_off(player, ISBLIND);
        !           409:     light(&hero);
        !           410:     msg("Your throat and eyes return to normal");
        !           411: }
        !           412: /*
        !           413:  * make some potion for the guy in the Alchemy jug
        !           414:  */
        !           415: void
        !           416: alchemy(struct object *obj)
        !           417: {
        !           418:     register struct object *tobj = NULL;
        !           419:     register struct linked_list *item;
        !           420:
        !           421:     /*
        !           422:      * verify that the object pointer we have still points to an alchemy
        !           423:      * jug (hopefully the right one!) because the hero could have thrown
        !           424:      * it away
        !           425:      */
        !           426:     for (item = pack; item != NULL; item = next(item)) {
        !           427:        tobj = OBJPTR(item);
        !           428:        if (tobj         == obj         &&
        !           429:            tobj->o_type == MM          &&
        !           430:            tobj->o_which== MM_JUG      &&
        !           431:            tobj->o_ac   == JUG_EMPTY   )
        !           432:                break;
        !           433:     }
        !           434:     if (item == NULL) {        /* not in the pack, check the level */
        !           435:        for (item = lvl_obj; item != NULL; item = next(item)) {
        !           436:            tobj = OBJPTR(item);
        !           437:            if (tobj         == obj             &&
        !           438:                tobj->o_type == MM              &&
        !           439:                tobj->o_which== MM_JUG          &&
        !           440:                tobj->o_ac   == JUG_EMPTY       )
        !           441:                    break;
        !           442:        }
        !           443:     }
        !           444:     if (item == NULL)  /* can't find it.....too bad */
        !           445:        return;
        !           446:
        !           447:     switch(rnd(9)) {
        !           448:        case 0: tobj->o_ac = P_PHASE;
        !           449:        when 1: tobj->o_ac = P_CLEAR;
        !           450:        when 2: tobj->o_ac = P_SEEINVIS;
        !           451:        when 3: tobj->o_ac = P_HEALING;
        !           452:        when 4: tobj->o_ac = P_MFIND;
        !           453:        when 5: tobj->o_ac = P_TFIND;
        !           454:        when 6: tobj->o_ac = P_HASTE;
        !           455:        when 7: tobj->o_ac = P_RESTORE;
        !           456:        when 8: tobj->o_ac = P_FLY;
        !           457:     }
        !           458: }
        !           459: /*
        !           460:  * otto's irresistable dance wears off
        !           461:  */
        !           462:
        !           463: void
        !           464: undance(void)
        !           465: {
        !           466:     turn_off(player, ISDANCE);
        !           467:     msg ("Your feet take a break.....whew!");
        !           468: }
        !           469:
        !           470: /*
        !           471:  * if he has our favorite necklace of strangulation then take damage every turn
        !           472:  */
        !           473: void
        !           474: strangle(void)
        !           475: {
        !           476:      if ((pstats.s_hpt -= 6) <= 0) death(D_STRANGLE);
        !           477: }
        !           478: /*
        !           479:  * if he has on the gauntlets of fumbling he might drop his weapon each turn
        !           480:  */
        !           481: void
        !           482: fumble(void)
        !           483: {
        !           484:     register struct linked_list *item;
        !           485:
        !           486:     if(cur_weapon!=NULL && cur_weapon->o_type!=RELIC && rnd(100)<3) {
        !           487:        for (item = pack; item != NULL; item = next(item)) {
        !           488:            if (OBJPTR(item) == cur_weapon)
        !           489:                break;
        !           490:        }
        !           491:        if (item != NULL) {
        !           492:            drop(item);
        !           493:            running = FALSE;
        !           494:        }
        !           495:     }
        !           496: }
        !           497: /*
        !           498:  * this is called each turn the hero has the ring of searching on
        !           499:  */
        !           500: void
        !           501: ring_search(void)
        !           502: {
        !           503:     search(FALSE, FALSE);
        !           504: }
        !           505: /*
        !           506:  * this is called each turn the hero has the ring of teleportation on
        !           507:  */
        !           508: void
        !           509: ring_teleport(void)
        !           510: {
        !           511:     if (rnd(100) < 2) teleport();
        !           512: }

CVSweb