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

Annotation of early-roguelike/rogue5/init.c, Revision 1.1.1.1

1.1       rubenllo    1: /*
                      2:  * global variable initializaton
                      3:  *
                      4:  * @(#)init.c  4.31 (Berkeley) 02/05/99
                      5:  *
                      6:  * Rogue: Exploring the Dungeons of Doom
                      7:  * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman
                      8:  * All rights reserved.
                      9:  *
                     10:  * See the file LICENSE.TXT for full copyright and licensing information.
                     11:  */
                     12:
                     13: #include <stdlib.h>
                     14: #include <curses.h>
                     15: #include <ctype.h>
                     16: #include <string.h>
                     17: #include "rogue.h"
                     18:
                     19: /*
                     20:  * init_player:
                     21:  *     Roll her up
                     22:  */
                     23: void
                     24: init_player(void)
                     25: {
                     26:     THING *obj;
                     27:
                     28:     pstats = max_stats;
                     29:     food_left = HUNGERTIME;
                     30:     /*
                     31:      * Give him some food
                     32:      */
                     33:     obj = new_item();
                     34:     obj->o_type = FOOD;
                     35:     obj->o_count = 1;
                     36:     add_pack(obj, TRUE);
                     37:     /*
                     38:      * And his suit of armor
                     39:      */
                     40:     obj = new_item();
                     41:     obj->o_type = ARMOR;
                     42:     obj->o_which = RING_MAIL;
                     43:     obj->o_arm = a_class[RING_MAIL] - 1;
                     44:     obj->o_flags |= ISKNOW;
                     45:     obj->o_count = 1;
                     46:     cur_armor = obj;
                     47:     add_pack(obj, TRUE);
                     48:     /*
                     49:      * Give him his weaponry.  First a mace.
                     50:      */
                     51:     obj = new_item();
                     52:     init_weapon(obj, MACE);
                     53:     obj->o_hplus = 1;
                     54:     obj->o_dplus = 1;
                     55:     obj->o_flags |= ISKNOW;
                     56:     add_pack(obj, TRUE);
                     57:     cur_weapon = obj;
                     58:     /*
                     59:      * Now a +1 bow
                     60:      */
                     61:     obj = new_item();
                     62:     init_weapon(obj, BOW);
                     63:     obj->o_hplus = 1;
                     64:     obj->o_flags |= ISKNOW;
                     65:     add_pack(obj, TRUE);
                     66:     /*
                     67:      * Now some arrows
                     68:      */
                     69:     obj = new_item();
                     70:     init_weapon(obj, ARROW);
                     71:     obj->o_count = rnd(15) + 25;
                     72:     obj->o_flags |= ISKNOW;
                     73:     add_pack(obj, TRUE);
                     74: }
                     75:
                     76: /*
                     77:  * Contains defintions and functions for dealing with things like
                     78:  * potions and scrolls
                     79:  */
                     80:
                     81: const char *rainbow[] = {
                     82:     "amber",
                     83:     "aquamarine",
                     84:     "black",
                     85:     "blue",
                     86:     "brown",
                     87:     "clear",
                     88:     "crimson",
                     89:     "cyan",
                     90:     "ecru",
                     91:     "gold",
                     92:     "green",
                     93:     "grey",
                     94:     "magenta",
                     95:     "orange",
                     96:     "pink",
                     97:     "plaid",
                     98:     "purple",
                     99:     "red",
                    100:     "silver",
                    101:     "tan",
                    102:     "tangerine",
                    103:     "topaz",
                    104:     "turquoise",
                    105:     "vermilion",
                    106:     "violet",
                    107:     "white",
                    108:     "yellow",
                    109: };
                    110:
                    111: #define NCOLORS (sizeof rainbow / sizeof (char *))
                    112:
                    113: static const char *sylls[] = {
                    114:     "a", "ab", "ag", "aks", "ala", "an", "app", "arg", "arze", "ash",
                    115:     "bek", "bie", "bit", "bjor", "blu", "bot", "bu", "byt", "comp",
                    116:     "con", "cos", "cre", "dalf", "dan", "den", "do", "e", "eep", "el",
                    117:     "eng", "er", "ere", "erk", "esh", "evs", "fa", "fid", "fri", "fu",
                    118:     "gan", "gar", "glen", "gop", "gre", "ha", "hyd", "i", "ing", "ip",
                    119:     "ish", "it", "ite", "iv", "jo", "kho", "kli", "klis", "la", "lech",
                    120:     "mar", "me", "mi", "mic", "mik", "mon", "mung", "mur", "nej",
                    121:     "nelg", "nep", "ner", "nes", "nes", "nih", "nin", "o", "od", "ood",
                    122:     "org", "orn", "ox", "oxy", "pay", "ple", "plu", "po", "pot",
                    123:     "prok", "re", "rea", "rhov", "ri", "ro", "rog", "rok", "rol", "sa",
                    124:     "san", "sat", "sef", "seh", "shu", "ski", "sna", "sne", "snik",
                    125:     "sno", "so", "sol", "sri", "sta", "sun", "ta", "tab", "tem",
                    126:     "ther", "ti", "tox", "trol", "tue", "turs", "u", "ulk", "um", "un",
                    127:     "uni", "ur", "val", "viv", "vly", "vom", "wah", "wed", "werg",
                    128:     "wex", "whon", "wun", "xo", "y", "yot", "yu", "zant", "zeb", "zim",
                    129:     "zok", "zon", "zum",
                    130: };
                    131:
                    132: const STONE stones[] = {
                    133:     { "agate",          25},
                    134:     { "alexandrite",    40},
                    135:     { "amethyst",       50},
                    136:     { "carnelian",      40},
                    137:     { "diamond",       300},
                    138:     { "emerald",       300},
                    139:     { "germanium",     225},
                    140:     { "granite",         5},
                    141:     { "garnet",                 50},
                    142:     { "jade",          150},
                    143:     { "kryptonite",    300},
                    144:     { "lapis lazuli",   50},
                    145:     { "moonstone",      50},
                    146:     { "obsidian",       15},
                    147:     { "onyx",           60},
                    148:     { "opal",          200},
                    149:     { "pearl",         220},
                    150:     { "peridot",        63},
                    151:     { "ruby",          350},
                    152:     { "sapphire",      285},
                    153:     { "stibotantalite",        200},
                    154:     { "tiger eye",      50},
                    155:     { "topaz",          60},
                    156:     { "turquoise",      70},
                    157:     { "taaffeite",     300},
                    158:     { "zircon",                 80},
                    159: };
                    160:
                    161: #define NSTONES (sizeof stones / sizeof (STONE))
                    162:
                    163: const char *wood[] = {
                    164:     "avocado wood",
                    165:     "balsa",
                    166:     "bamboo",
                    167:     "banyan",
                    168:     "birch",
                    169:     "cedar",
                    170:     "cherry",
                    171:     "cinnibar",
                    172:     "cypress",
                    173:     "dogwood",
                    174:     "driftwood",
                    175:     "ebony",
                    176:     "elm",
                    177:     "eucalyptus",
                    178:     "fall",
                    179:     "hemlock",
                    180:     "holly",
                    181:     "ironwood",
                    182:     "kukui wood",
                    183:     "mahogany",
                    184:     "manzanita",
                    185:     "maple",
                    186:     "oaken",
                    187:     "persimmon wood",
                    188:     "pecan",
                    189:     "pine",
                    190:     "poplar",
                    191:     "redwood",
                    192:     "rosewood",
                    193:     "spruce",
                    194:     "teak",
                    195:     "walnut",
                    196:     "zebrawood",
                    197: };
                    198:
                    199: #define NWOOD (sizeof wood / sizeof (char *))
                    200:
                    201: const char *metal[] = {
                    202:     "aluminum",
                    203:     "beryllium",
                    204:     "bone",
                    205:     "brass",
                    206:     "bronze",
                    207:     "copper",
                    208:     "electrum",
                    209:     "gold",
                    210:     "iron",
                    211:     "lead",
                    212:     "magnesium",
                    213:     "mercury",
                    214:     "nickel",
                    215:     "pewter",
                    216:     "platinum",
                    217:     "steel",
                    218:     "silver",
                    219:     "silicon",
                    220:     "tin",
                    221:     "titanium",
                    222:     "tungsten",
                    223:     "zinc",
                    224: };
                    225:
                    226: #define NMETAL (sizeof metal / sizeof (char *))
                    227:
                    228: int cNWOOD = NWOOD;
                    229: int cNMETAL = NMETAL;
                    230: int cNSTONES = NSTONES;
                    231: int cNCOLORS = NCOLORS;
                    232:
                    233: /*
                    234:  * init_colors:
                    235:  *     Initialize the potion color scheme for this time
                    236:  */
                    237: void
                    238: init_colors(void)
                    239: {
                    240:     int i, j;
                    241:     int used[NCOLORS];
                    242:
                    243:     for (i = 0; i < NCOLORS; i++)
                    244:        used[i] = FALSE;
                    245:     for (i = 0; i < MAXPOTIONS; i++)
                    246:     {
                    247:        do
                    248:            j = rnd(NCOLORS);
                    249:        until (!used[j]);
                    250:        used[j] = TRUE;
                    251:        p_colors[i] = rainbow[j];
                    252:     }
                    253: }
                    254:
                    255: /*
                    256:  * init_names:
                    257:  *     Generate the names of the various scrolls
                    258:  */
                    259: #define MAXNAME        40      /* Max number of characters in a name */
                    260:
                    261: void
                    262: init_names(void)
                    263: {
                    264:     int nsyl;
                    265:     const char *sp;
                    266:     char *cp;
                    267:     int i, nwords;
                    268:
                    269:     for (i = 0; i < MAXSCROLLS; i++)
                    270:     {
                    271:        cp = prbuf;
                    272:        nwords = rnd(3) + 2;
                    273:        while (nwords--)
                    274:        {
                    275:            nsyl = rnd(3) + 1;
                    276:            while (nsyl--)
                    277:            {
                    278:                sp = sylls[rnd((sizeof sylls) / (sizeof (char *)))];
                    279:                if (&cp[strlen(sp)] > &prbuf[MAXNAME])
                    280:                        break;
                    281:                while (*sp)
                    282:                    *cp++ = *sp++;
                    283:            }
                    284:            *cp++ = ' ';
                    285:        }
                    286:        *--cp = '\0';
                    287:        s_names[i] = malloc(strlen(prbuf)+1);
                    288:        if (s_names[i] != NULL)
                    289:                strcpy(s_names[i], prbuf);
                    290:     }
                    291: }
                    292:
                    293: /*
                    294:  * init_stones:
                    295:  *     Initialize the ring stone setting scheme for this time
                    296:  */
                    297: void
                    298: init_stones(void)
                    299: {
                    300:     int used[NSTONES];
                    301:     int i, j;
                    302:
                    303:     for (i = 0; i < NSTONES; i++)
                    304:        used[i] = FALSE;
                    305:     for (i = 0; i < MAXRINGS; i++)
                    306:     {
                    307:        do
                    308:            j = rnd(NSTONES);
                    309:        until (!used[j]);
                    310:        used[j] = TRUE;
                    311:        r_stones[i] = stones[j].st_name;
                    312:        ring_info[i].oi_worth += stones[j].st_value;
                    313:     }
                    314: }
                    315:
                    316: /*
                    317:  * init_materials:
                    318:  *     Initialize the construction materials for wands and staffs
                    319:  */
                    320: void
                    321: init_materials(void)
                    322: {
                    323:     int i, j;
                    324:     const char *str;
                    325:     int metused[NMETAL];
                    326:     int used[NWOOD];
                    327:
                    328:     for (i = 0; i < NWOOD; i++)
                    329:        used[i] = FALSE;
                    330:     for (i = 0; i < NMETAL; i++)
                    331:        metused[i] = FALSE;
                    332:     for (i = 0; i < MAXSTICKS; i++)
                    333:     {
                    334:        for (;;)
                    335:            if (rnd(2) == 0)
                    336:            {
                    337:                j = rnd(NMETAL);
                    338:                if (!metused[j])
                    339:                {
                    340:                    ws_type[i] = "wand";
                    341:                    str = metal[j];
                    342:                    metused[j] = TRUE;
                    343:                    break;
                    344:                }
                    345:            }
                    346:            else
                    347:            {
                    348:                j = rnd(NWOOD);
                    349:                if (!used[j])
                    350:                {
                    351:                    ws_type[i] = "staff";
                    352:                    str = wood[j];
                    353:                    used[j] = TRUE;
                    354:                    break;
                    355:                }
                    356:            }
                    357:        ws_made[i] = str;
                    358:     }
                    359: }
                    360:
                    361: #ifdef MASTER
                    362: # define       NT      NUMTHINGS, "things"
                    363: # define       MP      MAXPOTIONS, "potions"
                    364: # define       MS      MAXSCROLLS, "scrolls"
                    365: # define       MR      MAXRINGS, "rings"
                    366: # define       MWS     MAXSTICKS, "sticks"
                    367: # define       MW      MAXWEAPONS, "weapons"
                    368: # define       MA      MAXARMORS, "armor"
                    369: #else
                    370: # define       NT      NUMTHINGS
                    371: # define       MP      MAXPOTIONS
                    372: # define       MS      MAXSCROLLS
                    373: # define       MR      MAXRINGS
                    374: # define       MWS     MAXSTICKS
                    375: # define       MW      MAXWEAPONS
                    376: # define       MA      MAXARMORS
                    377: #endif
                    378:
                    379: /*
                    380:  * sumprobs:
                    381:  *     Sum up the probabilities for items appearing
                    382:  */
                    383: void
                    384: sumprobs(struct obj_info *info, int bound
                    385: #ifdef MASTER
                    386:        , char *name
                    387: #endif
                    388: )
                    389: {
                    390: #ifdef MASTER
                    391:        struct obj_info *start = info;
                    392: #endif
                    393:     struct obj_info *endp;
                    394:
                    395:     endp = info + bound;
                    396:     while (++info < endp)
                    397:        info->oi_prob += (info - 1)->oi_prob;
                    398: #ifdef MASTER
                    399:     badcheck(name, start, bound);
                    400: #endif
                    401: }
                    402:
                    403: /*
                    404:  * init_probs:
                    405:  *     Initialize the probabilities for the various items
                    406:  */
                    407: void
                    408: init_probs(void)
                    409: {
                    410:     sumprobs(things, NT);
                    411:     sumprobs(pot_info, MP);
                    412:     sumprobs(scr_info, MS);
                    413:     sumprobs(ring_info, MR);
                    414:     sumprobs(ws_info, MWS);
                    415:     sumprobs(weap_info, MW);
                    416:     sumprobs(arm_info, MA);
                    417: }
                    418:
                    419: #ifdef MASTER
                    420: /*
                    421:  * badcheck:
                    422:  *     Check to see if a series of probabilities sums to 100
                    423:  */
                    424: void
                    425: badcheck(const char *name, const struct obj_info *info, int bound)
                    426: {
                    427:     const struct obj_info *end;
                    428:
                    429:     if (info[bound - 1].oi_prob == 100)
                    430:        return;
                    431:     printf("\nBad percentages for %s (bound = %d):\n", name, bound);
                    432:     for (end = &info[bound]; info < end; info++)
                    433:        printf("%3d%% %s\n", info->oi_prob, info->oi_name);
                    434:     printf("[hit RETURN to continue]");
                    435:     fflush(stdout);
                    436:     while (getchar() != '\n')
                    437:        continue;
                    438: }
                    439: #endif
                    440:
                    441: /*
                    442:  * pick_color:
                    443:  *     If he is halucinating, pick a random color name and return it,
                    444:  *     otherwise return the given color.
                    445:  */
                    446: const char *
                    447: pick_color(const char *col)
                    448: {
                    449:     return (on(player, ISHALU) ? rainbow[rnd(NCOLORS)] : col);
                    450: }

CVSweb