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

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

1.1     ! rubenllo    1: /*
        !             2:  * global variable initializaton
        !             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 <ctype.h>
        !            17: #include <string.h>
        !            18: #include <stdlib.h>
        !            19: #include "rogue.h"
        !            20: #include "mach_dep.h"
        !            21:
        !            22:
        !            23: char *rainbow[NCOLORS] = {
        !            24:
        !            25: "amber",               "aquamarine",           "beige",
        !            26: "black",               "blue",                 "brown",
        !            27: "clear",               "crimson",              "ecru",
        !            28: "gold",                        "green",                "grey",
        !            29: "indigo",              "khaki",                "lavender",
        !            30: "magenta",             "orange",               "pink",
        !            31: "plaid",               "purple",               "red",
        !            32: "silver",              "saffron",              "scarlet",
        !            33: "tan",                 "tangerine",            "topaz",
        !            34: "turquoise",           "vermilion",            "violet",
        !            35: "white",               "yellow",
        !            36: };
        !            37:
        !            38: char *sylls[NSYLLS] = {
        !            39:     "a",   "ab",  "ag",  "aks", "ala", "an",  "ankh","app", "arg", "arze",
        !            40:     "ash", "ban", "bar", "bat", "bek", "bie", "bin", "bit", "bjor",
        !            41:     "blu", "bot", "bu",  "byt", "comp","con", "cos", "cre", "dalf",
        !            42:     "dan", "den", "do",  "e",   "eep", "el",  "eng", "er",  "ere", "erk",
        !            43:     "esh", "evs", "fa",  "fid", "for", "fri", "fu",  "gan", "gar",
        !            44:     "glen","gop", "gre", "ha",  "he",  "hyd", "i",   "ing", "ion", "ip",
        !            45:     "ish", "it",  "ite", "iv",  "jo",  "kho", "kli", "klis","la",  "lech",
        !            46:     "man", "mar", "me",  "mi",  "mic", "mik", "mon", "mung","mur",
        !            47:     "nej", "nelg","nep", "ner", "nes", "nes", "nih", "nin", "o",   "od",
        !            48:     "ood", "org", "orn", "ox",  "oxy", "pay", "pet", "ple", "plu", "po",
        !            49:     "pot", "prok","re",  "rea", "rhov","ri",  "ro",  "rog", "rok", "rol",
        !            50:     "sa",  "san", "sat", "see", "sef", "seh", "shu", "ski", "sna",
        !            51:     "sne", "snik","sno", "so",  "sol", "sri", "sta", "sun", "ta",
        !            52:     "tab", "tem", "ther","ti",  "tox", "trol","tue", "turs","u",
        !            53:     "ulk", "um",  "un",  "uni", "ur",  "val", "viv", "vly", "vom", "wah",
        !            54:     "wed", "werg","wex", "whon","wun", "xo",  "y",   "yot", "yu",
        !            55:     "zant","zap", "zeb", "zim", "zok", "zon", "zum",
        !            56: };
        !            57:
        !            58: char *stones[NSTONES] = {
        !            59:        "agate",                "alexandrite",          "amethyst",
        !            60:        "azurite",              "bloodstone",           "cairngorm",
        !            61:        "carnelian",            "chalcedony",           "chrysoberyl",
        !            62:        "chrysolite",           "chrysoprase",          "citrine",
        !            63:        "coral",                "diamond",              "emerald",
        !            64:        "garnet",               "heliotrope",           "hematite",
        !            65:        "hyacinth",             "jacinth",              "jade",
        !            66:        "jargoon",              "jasper",               "kryptonite",
        !            67:        "lapus lazuli",         "malachite",            "mocca stone",
        !            68:        "moonstone",            "obsidian",             "olivine",
        !            69:        "onyx",                 "opal",                 "pearl",
        !            70:        "peridot",              "quartz",               "rhodochrosite",
        !            71:        "rhodolite",            "ruby",                 "sapphire",
        !            72:        "sardonyx",             "serpintine",           "spinel",
        !            73:        "tiger eye",            "topaz",                "tourmaline",
        !            74:        "turquoise",            "zircon",
        !            75: };
        !            76:
        !            77: char *wood[NWOOD] = {
        !            78:        "avocado wood", "balsa",        "banyan",       "birch",
        !            79:        "cedar",        "cherry",       "cinnibar",     "dogwood",
        !            80:        "driftwood",    "ebony",        "eucalyptus",   "hemlock",
        !            81:        "ironwood",     "mahogany",     "manzanita",    "maple",
        !            82:        "oak",          "pine",         "redwood",      "rosewood",
        !            83:        "teak",         "walnut",       "zebra wood",   "persimmon wood",
        !            84: };
        !            85:
        !            86: char *metal[NMETAL] = {
        !            87:        "aluminium",    "bone",         "brass",        "bronze",
        !            88:        "copper",       "chromium",     "iron",         "lead",
        !            89:        "magnesium",    "pewter",       "platinum",     "silver",
        !            90:        "steel",        "tin",          "titanium",     "zinc",
        !            91: };
        !            92:
        !            93:
        !            94:
        !            95: 
        !            96: /*
        !            97:  * make sure all the percentages specified in the tables add up to the
        !            98:  * right amounts
        !            99:  */
        !           100: void
        !           101: badcheck(char *name, struct magic_item *magic, int bound)
        !           102: {
        !           103:     register struct magic_item *end;
        !           104:
        !           105:     if (magic[bound - 1].mi_prob == 1000)
        !           106:        return;
        !           107:     printf("\nBad percentages for %s:\n", name);
        !           108:     for (end = &magic[bound] ; magic < end ; magic++)
        !           109:        printf("%4d%% %s\n", magic->mi_prob, magic->mi_name);
        !           110:     printf(retstr);
        !           111:     fflush(stdout);
        !           112:     while (getchar() != '\n')
        !           113:        continue;
        !           114: }
        !           115: 
        !           116: /*
        !           117:  * init_colors:
        !           118:  *     Initialize the potion color scheme for this time
        !           119:  */
        !           120:
        !           121: void
        !           122: init_colors(void)
        !           123: {
        !           124:     register int i, j;
        !           125:     bool used[NCOLORS];
        !           126:
        !           127:     for(i = 0; i < NCOLORS; i++)
        !           128:         used[i] = FALSE;
        !           129:
        !           130:     for (i = 0 ; i < MAXPOTIONS ; i++)
        !           131:     {
        !           132:        do
        !           133:            j = rnd(NCOLORS);
        !           134:         until (!used[j]);
        !           135:         used[j] = TRUE;
        !           136:        p_colors[i] = rainbow[j];
        !           137:        p_know[i] = FALSE;
        !           138:        p_guess[i] = NULL;
        !           139:        if (i > 0)
        !           140:                p_magic[i].mi_prob += p_magic[i-1].mi_prob;
        !           141:     }
        !           142:     badcheck("potions", p_magic, MAXPOTIONS);
        !           143: }
        !           144: 
        !           145: /*
        !           146:  * init_materials:
        !           147:  *     Initialize the construction materials for wands and staffs
        !           148:  */
        !           149:
        !           150: void
        !           151: init_materials(void)
        !           152: {
        !           153:     register int i, j;
        !           154:     register char *str;
        !           155:     bool metused[NMETAL], woodused[NWOOD];
        !           156:
        !           157:     for(i = 0; i < NWOOD; i++)
        !           158:         woodused[i] = FALSE;
        !           159:
        !           160:     for(i = 0; i < NMETAL; i++)
        !           161:         metused[i] = FALSE;
        !           162:
        !           163:     for (i = 0 ; i < MAXSTICKS ; i++)
        !           164:     {
        !           165:         for (;;)
        !           166:            if (rnd(100) > 50)
        !           167:            {
        !           168:                 j = rnd(NMETAL);
        !           169:
        !           170:                 if (!metused[j])
        !           171:                 {
        !           172:                     ws_type[i] = "wand";
        !           173:                     str = metal[j];
        !           174:                     metused[j] = TRUE;
        !           175:                     break;
        !           176:                 }
        !           177:             }
        !           178:             else
        !           179:             {
        !           180:                 j = rnd(NWOOD);
        !           181:
        !           182:                 if (!woodused[j])
        !           183:                 {
        !           184:                     ws_type[i] = "staff";
        !           185:                     str = wood[j];
        !           186:                     woodused[j] = TRUE;
        !           187:                     break;
        !           188:                 }
        !           189:             }
        !           190:
        !           191:         ws_made[i] = str;
        !           192:        ws_know[i] = FALSE;
        !           193:        ws_guess[i] = NULL;
        !           194:        if (i > 0)
        !           195:                ws_magic[i].mi_prob += ws_magic[i-1].mi_prob;
        !           196:     }
        !           197:     badcheck("sticks", ws_magic, MAXSTICKS);
        !           198: }
        !           199: 
        !           200: /*
        !           201:  * do any initialization for miscellaneous magic
        !           202:  */
        !           203:
        !           204: void
        !           205: init_misc(void)
        !           206: {
        !           207:     register int i;
        !           208:
        !           209:     for (i=0; i < MAXMM; i++) {
        !           210:        m_know[i] = FALSE;
        !           211:        m_guess[i] = NULL;
        !           212:        if (i > 0)
        !           213:            m_magic[i].mi_prob += m_magic[i-1].mi_prob;
        !           214:     }
        !           215:
        !           216:     badcheck("miscellaneous magic", m_magic, MAXMM);
        !           217: }
        !           218:
        !           219: 
        !           220: /*
        !           221:  * init_names:
        !           222:  *     Generate the names of the various scrolls
        !           223:  */
        !           224:
        !           225: void
        !           226: init_names(void)
        !           227: {
        !           228:     register int nsyl;
        !           229:     register char *cp, *sp;
        !           230:     register int i, nwords;
        !           231:
        !           232:     for (i = 0 ; i < MAXSCROLLS ; i++)
        !           233:     {
        !           234:        cp = prbuf;
        !           235:        nwords = rnd(COLS/20) + 1 + (COLS > 40 ? 1 : 0);
        !           236:        while(nwords--)
        !           237:        {
        !           238:            nsyl = rnd(3)+1;
        !           239:            while(nsyl--)
        !           240:            {
        !           241:                sp = sylls[rnd((sizeof sylls) / (sizeof (char *)))];
        !           242:                while(*sp)
        !           243:                    *cp++ = *sp++;
        !           244:            }
        !           245:            *cp++ = ' ';
        !           246:        }
        !           247:        *--cp = '\0';
        !           248:        s_names[i] = (char *) new(strlen(prbuf)+1);
        !           249:        s_know[i] = FALSE;
        !           250:        s_guess[i] = NULL;
        !           251:        strcpy(s_names[i], prbuf);
        !           252:        if (i > 0)
        !           253:                s_magic[i].mi_prob += s_magic[i-1].mi_prob;
        !           254:     }
        !           255:     badcheck("scrolls", s_magic, MAXSCROLLS);
        !           256: }
        !           257: 
        !           258: /*
        !           259:  * init_player:
        !           260:  *     roll up the rogue
        !           261:  */
        !           262:
        !           263: void
        !           264: init_player(void)
        !           265: {
        !           266:     int stat_total, ch = 0, wpt = 0, i, j;
        !           267:     struct linked_list *weap_item, *armor_item, *food_item;
        !           268:     struct object *obj;
        !           269:     char *class;
        !           270:
        !           271:     weap_item = armor_item = NULL;
        !           272:
        !           273:     if (char_type == -1) {
        !           274:        /* See what type character will be */
        !           275:        wclear(hw);
        !           276:        touchwin(hw);
        !           277:        mvwaddstr(hw,2,0,"[1] Fighter\n[2] Magician\n[3] Cleric\n[4] Thief");
        !           278:        mvwaddstr(hw, 0, 0, "What character class do you desire? ");
        !           279:        draw(hw);
        !           280:        char_type = (wgetch(hw) - '0');
        !           281:        while (char_type < 1 || char_type > 4) {
        !           282:            mvwaddstr(hw,0,0,"Please enter a character type between 1 and 4: ");
        !           283:            draw(hw);
        !           284:            char_type = (wgetch(hw) - '0');
        !           285:        }
        !           286:        char_type--;
        !           287:     }
        !           288:     player.t_ctype = char_type;
        !           289:     player.t_quiet = 0;
        !           290:     pack = NULL;
        !           291:
        !           292: #ifdef WIZARD
        !           293:     /*
        !           294:      * allow me to describe a super character
        !           295:      */
        !           296:     if (wizard && md_getuid() == AUTHOR && strcmp(getenv("SUPER"),"YES") == 0) {
        !           297:            pstats.s_str = 25;
        !           298:            pstats.s_intel = 25;
        !           299:            pstats.s_wisdom = 25;
        !           300:            pstats.s_dext = 25;
        !           301:            pstats.s_const = 25;
        !           302:            pstats.s_charisma = 25;
        !           303:            pstats.s_exp = 7500000L;
        !           304:            pstats.s_lvl = 20;
        !           305:            pstats.s_hpt = 500;
        !           306:            pstats.s_carry = totalenc();
        !           307:            strcpy(pstats.s_dmg,"3d4");
        !           308:            if (player.t_ctype == C_FIGHTER)
        !           309:                weap_item = spec_item(WEAPON, TWOSWORD, 5, 5);
        !           310:            else
        !           311:                weap_item = spec_item(WEAPON, SWORD, 5, 5);
        !           312:            obj = OBJPTR(weap_item);
        !           313:            obj->o_flags |= ISKNOW;
        !           314:            add_pack(weap_item, TRUE, NULL);
        !           315:            cur_weapon = obj;
        !           316:            j = PLATE_ARMOR;
        !           317:            if (player.t_ctype == C_THIEF)
        !           318:                j = STUDDED_LEATHER;
        !           319:            armor_item = spec_item(ARMOR, j, 10, 0);
        !           320:            obj = OBJPTR(armor_item);
        !           321:            obj->o_flags |= (ISKNOW | ISPROT);
        !           322:            obj->o_weight = armors[j].a_wght;
        !           323:            add_pack(armor_item, TRUE, NULL);
        !           324:            cur_armor = obj;
        !           325:            purse += 10000;
        !           326:     }
        !           327:     else
        !           328: #endif
        !           329:
        !           330:     {
        !           331:        wclear(hw);
        !           332:        do {
        !           333:            if (armor_item != NULL) {
        !           334:                o_discard(armor_item);
        !           335:                armor_item = NULL;
        !           336:            }
        !           337:            if (weap_item != NULL) {
        !           338:                o_discard(weap_item);
        !           339:                weap_item = NULL;
        !           340:            }
        !           341:            pstats.s_lvl = 1;
        !           342:            pstats.s_exp = 0L;
        !           343:            pstats.s_hpt = 12 + rnd(10);
        !           344:            pstats.s_str = 7 + rnd(5);
        !           345:            pstats.s_intel = 7 + rnd(5);
        !           346:            pstats.s_wisdom = 7 + rnd(5);
        !           347:            pstats.s_dext = 7 + rnd(5);
        !           348:            pstats.s_const = 14 + rnd(5);
        !           349:            pstats.s_charisma = 7 + rnd(5);
        !           350:
        !           351:            /* Now for the special ability */
        !           352:            switch (char_type) {
        !           353:                case C_FIGHTER:  pstats.s_str   = (rnd(10) == 7) ? 18 : 16;
        !           354:                when C_MAGICIAN: pstats.s_intel = (rnd(10) == 7) ? 18 : 16;
        !           355:                when C_CLERIC:   pstats.s_wisdom= (rnd(10) == 7) ? 18 : 16;
        !           356:                when C_THIEF:    pstats.s_dext  = (rnd(10) == 7) ? 18 : 16;
        !           357:            }
        !           358:            strcpy(pstats.s_dmg,"1d4");
        !           359:            stat_total =pstats.s_str  + pstats.s_intel + pstats.s_wisdom +
        !           360:                        pstats.s_dext + pstats.s_const;
        !           361:            /*
        !           362:             * since the player can re-roll stats at will, keep the maximum
        !           363:             * to some reasonable limit
        !           364:             */
        !           365:            if (stat_total > MAXSTATS)
        !           366:                pstats.s_const -= (stat_total - MAXSTATS);
        !           367:            pstats.s_carry = totalenc();
        !           368:
        !           369:            /*
        !           370:             * Give the rogue his weaponry.
        !           371:             */
        !           372:            do {
        !           373:                i = rnd(8);     /* number of acceptable weapons */
        !           374:                switch(i) {
        !           375:                    case 0: ch = 25; wpt = MACE;
        !           376:                    when 1: ch = 25; wpt = SWORD;
        !           377:                    when 2: ch = 20; wpt = BATTLEAXE;
        !           378:                    when 3: ch = 20; wpt = TRIDENT;
        !           379:                    when 4: ch = 20; wpt = SPETUM;
        !           380:                    when 5: ch = 20; wpt = BARDICHE;
        !           381:                    when 6: ch = 15; wpt = PIKE;
        !           382:                    when 7: ch = 20; wpt = HALBERD;
        !           383:                }
        !           384:            } while(rnd(100) > ch);
        !           385:            if (player.t_ctype == C_FIGHTER)
        !           386:                wpt = TWOSWORD;
        !           387:            weap_item = spec_item(WEAPON, wpt, rnd(2), rnd(2)+1);
        !           388:            obj = OBJPTR(weap_item);
        !           389:            obj->o_flags |= ISKNOW;
        !           390:            /*
        !           391:             * And his suit of armor.......
        !           392:             * Thieves can only wear leather armor
        !           393:             * fighters get better armor on an average
        !           394:             */
        !           395:            if (player.t_ctype == C_THIEF)
        !           396:                j = STUDDED_LEATHER;
        !           397:            else {
        !           398:                if (player.t_ctype == C_FIGHTER)
        !           399:                    i = 50 + rnd(50);
        !           400:                else
        !           401:                    i = rnd(100);
        !           402:                j = 0;
        !           403:                while (armors[j].a_prob < i)
        !           404:                    j++;
        !           405:            }
        !           406:            armor_item = spec_item(ARMOR, j, 0, 0);
        !           407:            obj = OBJPTR(armor_item);
        !           408:            obj->o_flags |= ISKNOW;
        !           409:            obj->o_weight = armors[j].a_wght;
        !           410:            switch(player.t_ctype) {
        !           411:                case C_FIGHTER: class = "fighter";
        !           412:                when C_MAGICIAN:class = "magic user";
        !           413:                when C_CLERIC:  class = "cleric";
        !           414:                when C_THIEF:   class = "thief";
        !           415:                otherwise:      class = "unknown";
        !           416:            }
        !           417:            wmove(hw, 2, 0);
        !           418:            wprintw(hw, "You have rolled a %s with the following attributes:",class);
        !           419:            wmove(hw,4,0);
        !           420:            wprintw(hw, "    Int: %2d", pstats.s_intel);
        !           421:            wprintw(hw, "    Str: %2d", pstats.s_str);
        !           422:            wprintw(hw, "    Wis: %2d", pstats.s_wisdom);
        !           423:            wprintw(hw, "    Dex: %2d", pstats.s_dext);
        !           424:            wprintw(hw, "  Const: %2d", pstats.s_const);
        !           425:            wclrtoeol(hw);
        !           426:            wmove(hw, 6, 0);
        !           427:            wprintw(hw, "     Hp: %2d", pstats.s_hpt);
        !           428:            wclrtoeol(hw);
        !           429:            mvwaddstr(hw, 8, 5, inv_name(OBJPTR(weap_item), FALSE));
        !           430:            wclrtoeol(hw);
        !           431:            mvwaddstr(hw, 9, 5, inv_name(OBJPTR(armor_item), FALSE));
        !           432:            wclrtoeol(hw);
        !           433:            mvwaddstr(hw,0,0,"Would you like to re-roll the character? ");
        !           434:            draw(hw);
        !           435:        } while(wgetch(hw) == 'y');
        !           436:
        !           437:        obj = OBJPTR(weap_item);
        !           438:        add_pack(weap_item, TRUE, NULL);
        !           439:        cur_weapon = obj;
        !           440:        obj = OBJPTR(armor_item);
        !           441:        add_pack(armor_item, TRUE, NULL);
        !           442:        cur_armor = obj;
        !           443:     }
        !           444:     /*
        !           445:      * Give him some food
        !           446:      */
        !           447:     food_item = spec_item(FOOD, 0, 0, 0);
        !           448:     obj = OBJPTR(food_item);
        !           449:     obj->o_weight = things[TYP_FOOD].mi_wght;
        !           450:     add_pack(food_item, TRUE, NULL);
        !           451:     pstats.s_arm = 10;
        !           452:     max_stats = pstats;
        !           453: }
        !           454:
        !           455:
        !           456:
        !           457:
        !           458: 
        !           459:
        !           460: /*
        !           461:  * init_stones:
        !           462:  *     Initialize the ring stone setting scheme for this time
        !           463:  */
        !           464:
        !           465: void
        !           466: init_stones(void)
        !           467: {
        !           468:     register int i, j;
        !           469:     bool used[NSTONES];
        !           470:
        !           471:     for (i = 0; i < NSTONES; i++)
        !           472:         used[i] = FALSE;
        !           473:
        !           474:     for (i = 0 ; i < MAXRINGS ; i++)
        !           475:     {
        !           476:        do
        !           477:             j = rnd(NSTONES);
        !           478:         until (!used[j]);
        !           479:
        !           480:         used[j] = TRUE;
        !           481:        r_stones[i] = stones[j];
        !           482:        r_know[i] = FALSE;
        !           483:        r_guess[i] = NULL;
        !           484:        if (i > 0)
        !           485:                r_magic[i].mi_prob += r_magic[i-1].mi_prob;
        !           486:     }
        !           487:     badcheck("rings", r_magic, MAXRINGS);
        !           488: }
        !           489: 
        !           490: /*
        !           491:  * init_things
        !           492:  *     Initialize the probabilities for types of things
        !           493:  */
        !           494: void
        !           495: init_things(void)
        !           496: {
        !           497:     register struct magic_item *mp;
        !           498:
        !           499:     for (mp = &things[1] ; mp < &things[NUMTHINGS] ; mp++)
        !           500:        mp->mi_prob += (mp-1)->mi_prob;
        !           501:     badcheck("things", things, NUMTHINGS);
        !           502: }
        !           503:
        !           504:

CVSweb