Annotation of researchv10no/games/rogue/init.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * global variable initializaton
        !             3:  *
        !             4:  * @(#)init.c  3.33 (Berkeley) 6/15/81
        !             5:  */
        !             6: 
        !             7: #include <curses.h>
        !             8: #include <ctype.h>
        !             9: #include "rogue.h"
        !            10: 
        !            11: bool playing = TRUE, running = FALSE, wizard = FALSE;
        !            12: bool notify = TRUE, fight_flush = FALSE, terse = FALSE, door_stop = FALSE;
        !            13: bool jump = FALSE, slow_invent = FALSE, firstmove = FALSE, askme = FALSE;
        !            14: bool amulet = FALSE, in_shell = FALSE;
        !            15: struct linked_list *lvl_obj = NULL, *mlist = NULL;
        !            16: struct object *cur_weapon = NULL;
        !            17: int mpos = 0, no_move = 0, no_command = 0, level = 1, purse = 0, inpack = 0;
        !            18: int total = 0, no_food = 0, count = 0, fung_hit = 0, quiet = 0;
        !            19: int food_left = HUNGERTIME, group = 1, hungry_state = 0;
        !            20: int lastscore = -1;
        !            21: 
        !            22: #define ___ 1
        !            23: #define _x {1,1}
        !            24: struct monster monsters[26] = {
        !            25:        /* Name          CARRY  FLAG    str, exp, lvl, amr, hpt, dmg */
        !            26:        { "giant ant",   0,     ISMEAN, { _x, 10,   2,   3, ___, "1d6" } },
        !            27:        { "bat",         0,     0,      { _x,  1,   1,   3, ___, "1d2" } },
        !            28:        { "centaur",     15,    0,      { _x, 15,   4,   4, ___, "1d6/1d6" } },
        !            29:        { "dragon",      100,   ISGREED,{ _x,9000, 10,  -1, ___, "1d8/1d8/3d10" } },
        !            30:        { "floating eye",0,     0,      { _x,  5,   1,   9, ___, "0d0" } },
        !            31:        { "violet fungi",0,     ISMEAN, { _x, 85,   8,   3, ___, "000d0" } },
        !            32:        { "gnome",       10,    0,      { _x,  8,   1,   5, ___, "1d6" } },
        !            33:        { "hobgoblin",   0,     ISMEAN, { _x,  3,   1,   5, ___, "1d8" } },
        !            34:        { "invisible stalker",0,ISINVIS,{ _x,120,   8,   3, ___, "4d4" } },
        !            35:        { "jackal",      0,     ISMEAN, { _x,  2,   1,   7, ___, "1d2" } },
        !            36:        { "kobold",      0,     ISMEAN, { _x,  1,   1,   7, ___, "1d4" } },
        !            37:        { "leprechaun",  0,     0,      { _x, 10,   3,   8, ___, "1d1" } },
        !            38:        { "mimic",       30,    0,      { _x,140,   7,   7, ___, "3d4" } },
        !            39:        { "nymph",       100,   0,      { _x, 40,   3,   9, ___, "0d0" } },
        !            40:        { "orc",         15,    ISBLOCK,{ _x,  5,   1,   6, ___, "1d8" } },
        !            41:        { "purple worm", 70,    0,      { _x,7000, 15,   6, ___, "2d12/2d4" } },
        !            42:        { "quasit",      30,    ISMEAN, { _x, 35,   3,   2, ___, "1d2/1d2/1d4" } },
        !            43:        { "rust monster",0,     ISMEAN, { _x, 25,   5,   2, ___, "0d0/0d0" } },
        !            44:        { "snake",       0,     ISMEAN, { _x,  3,   1,   5, ___, "1d3" } },
        !            45:        { "troll",       50,    ISREGEN|ISMEAN,{ _x, 55,   6,   4, ___, "1d8/1d8/2d6" } },
        !            46:        { "umber hulk",  40,    ISMEAN, { _x,130,   8,   2, ___, "3d4/3d4/2d5" } },
        !            47:        { "vampire",     20,    ISREGEN|ISMEAN,{ _x,380,   8,   1, ___, "1d10" } },
        !            48:        { "wraith",      0,     0,      { _x, 55,   5,   4, ___, "1d6" } },
        !            49:        { "xorn",        0,     ISMEAN, { _x,120,   7,  -2, ___, "1d3/1d3/1d3/4d6" } },
        !            50:        { "yeti",        30,    0,      { _x, 50,   4,   6, ___, "1d6/1d6" } },
        !            51:        { "zombie",      0,     ISMEAN, { _x,  7,   2,   8, ___, "1d8" } }
        !            52: };
        !            53: #undef ___
        !            54: 
        !            55: /*
        !            56:  * init_player:
        !            57:  *     roll up the rogue
        !            58:  */
        !            59: 
        !            60: init_player()
        !            61: {
        !            62:     pstats.s_lvl = 1;
        !            63:     pstats.s_exp = 0L;
        !            64:     max_hp = pstats.s_hpt = 12;
        !            65:     pstats.s_str.st_str = 17;
        !            66:     pstats.s_str.st_add = 0;
        !            67:     pstats.s_dmg = "1d4";
        !            68:     pstats.s_arm = 10;
        !            69:     max_stats = pstats;
        !            70:     pack = NULL;
        !            71: }
        !            72: 
        !            73: /*
        !            74:  * Contains defintions and functions for dealing with things like
        !            75:  * potions and scrolls
        !            76:  */
        !            77: 
        !            78: static char *rainbow[] = {
        !            79:     "Red",
        !            80:     "Blue",
        !            81:     "Green",
        !            82:     "Yellow",
        !            83:     "Black",
        !            84:     "Brown",
        !            85:     "Orange",
        !            86:     "Pink",
        !            87:     "Purple",
        !            88:     "Grey",
        !            89:     "White",
        !            90:     "Silver",
        !            91:     "Gold",
        !            92:     "Violet",
        !            93:     "Clear",
        !            94:     "Vermilion",
        !            95:     "Ecru",
        !            96:     "Turquoise",
        !            97:     "Magenta",
        !            98:     "Amber",
        !            99:     "Topaz",
        !           100:     "Plaid",
        !           101:     "Tan",
        !           102:     "Tangerine"
        !           103: };
        !           104: 
        !           105: #define NCOLORS (sizeof rainbow / sizeof (char *))
        !           106: 
        !           107: static char *sylls[] = {
        !           108:     "a", "ab", "ag", "aks", "ala", "an", "ankh", "app", "arg", "arze",
        !           109:     "ash", "ban", "bar", "bat", "bek", "bie", "bin", "bit", "bjor",
        !           110:     "blu", "bot", "bu", "byt", "comp", "con", "cos", "cre", "dalf",
        !           111:     "dan", "den", "do", "e", "eep", "el", "eng", "er", "ere", "erk",
        !           112:     "esh", "evs", "fa", "fid", "for", "fri", "fu", "gan", "gar",
        !           113:     "glen", "gop", "gre", "ha", "he", "hyd", "i", "ing", "ion", "ip",
        !           114:     "ish", "it", "ite", "iv", "jo", "kho", "kli", "klis", "la", "lech",
        !           115:     "man", "mar", "me", "mi", "mic", "mik", "mon", "mung", "mur",
        !           116:     "nej", "nelg", "nep", "ner", "nes", "nes", "nih", "nin", "o", "od",
        !           117:     "ood", "org", "orn", "ox", "oxy", "pay", "pet", "ple", "plu", "po",
        !           118:     "pot", "prok", "re", "rea", "rhov", "ri", "ro", "rog", "rok", "rol",
        !           119:     "sa", "san", "sat", "see", "sef", "seh", "shu", "ski", "sna",
        !           120:     "sne", "snik", "sno", "so", "sol", "sri", "sta", "sun", "ta",
        !           121:     "tab", "tem", "ther", "ti", "tox", "trol", "tue", "turs", "u",
        !           122:     "ulk", "um", "un", "uni", "ur", "val", "viv", "vly", "vom", "wah",
        !           123:     "wed", "werg", "wex", "whon", "wun", "xo", "y", "yot", "yu",
        !           124:     "zant", "zap", "zeb", "zim", "zok", "zon", "zum",
        !           125: };
        !           126: 
        !           127: static char *stones[] = {
        !           128:     "Agate",
        !           129:     "Alexandrite",
        !           130:     "Amethyst",
        !           131:     "Carnelian",
        !           132:     "Diamond",
        !           133:     "Emerald",
        !           134:     "Granite",
        !           135:     "Jade",
        !           136:     "Kryptonite",
        !           137:     "Lapus lazuli",
        !           138:     "Moonstone",
        !           139:     "Obsidian",
        !           140:     "Onyx",
        !           141:     "Opal",
        !           142:     "Pearl",
        !           143:     "Ruby",
        !           144:     "Saphire",
        !           145:     "Tiger eye",
        !           146:     "Topaz",
        !           147:     "Turquoise",
        !           148: };
        !           149: 
        !           150: #define NSTONES (sizeof stones / sizeof (char *))
        !           151: 
        !           152: static char *wood[] = {
        !           153:     "Avocado wood",
        !           154:     "Balsa",
        !           155:     "Banyan",
        !           156:     "Birch",
        !           157:     "Cedar",
        !           158:     "Cherry",
        !           159:     "Cinnibar",
        !           160:     "Driftwood",
        !           161:     "Ebony",
        !           162:     "Eucalyptus",
        !           163:     "Hemlock",
        !           164:     "Ironwood",
        !           165:     "Mahogany",
        !           166:     "Manzanita",
        !           167:     "Maple",
        !           168:     "Oak",
        !           169:     "Persimmon wood",
        !           170:     "Redwood",
        !           171:     "Rosewood",
        !           172:     "Teak",
        !           173:     "Walnut",
        !           174:     "Zebra wood",
        !           175: };
        !           176: 
        !           177: #define NWOOD (sizeof wood / sizeof (char *))
        !           178: 
        !           179: static char *metal[] = {
        !           180:     "Aluminium",
        !           181:     "Bone",
        !           182:     "Brass",
        !           183:     "Bronze",
        !           184:     "Copper",
        !           185:     "Iron",
        !           186:     "Lead",
        !           187:     "Pewter",
        !           188:     "Steel",
        !           189:     "Tin",
        !           190:     "Zinc",
        !           191: };
        !           192: 
        !           193: #define NMETAL (sizeof metal / sizeof (char *))
        !           194: 
        !           195: struct magic_item things[NUMTHINGS] = {
        !           196:     { 0,                       27 },   /* potion */
        !           197:     { 0,                       27 },   /* scroll */
        !           198:     { 0,                       18 },   /* food */
        !           199:     { 0,                        9 },   /* weapon */
        !           200:     { 0,                        9 },   /* armor */
        !           201:     { 0,                        5 },   /* ring */
        !           202:     { 0,                        5 },   /* stick */
        !           203: };
        !           204: 
        !           205: struct magic_item s_magic[MAXSCROLLS] = {
        !           206:     { "monster confusion",      8, 170 },
        !           207:     { "magic mapping",          5, 180 },
        !           208:     { "light",                 10, 100 },
        !           209:     { "hold monster",           2, 200 },
        !           210:     { "sleep",                  5,  50 },
        !           211:     { "enchant armor",          8, 130 },
        !           212:     { "identify",              21, 100 },
        !           213:     { "scare monster",          4, 180 },
        !           214:     { "gold detection",                 4, 110 },
        !           215:     { "teleportation",          7, 175 },
        !           216:     { "enchant weapon",                10, 150 },
        !           217:     { "create monster",                 5,  75 },
        !           218:     { "remove curse",           8, 105 },
        !           219:     { "aggravate monsters",     1,  60 },
        !           220:     { "blank paper",            1,  50 },
        !           221:     { "genocide",               1, 200 },
        !           222: };
        !           223: 
        !           224: struct magic_item p_magic[MAXPOTIONS] = {
        !           225:     { "confusion",              8,  50 },
        !           226:     { "paralysis",             10,  50 },
        !           227:     { "poison",                         8,  50 },
        !           228:     { "gain strength",         15, 150 },
        !           229:     { "see invisible",          2, 170 },
        !           230:     { "healing",               15, 130 },
        !           231:     { "monster detection",      6, 120 },
        !           232:     { "magic detection",        6, 105 },
        !           233:     { "raise level",            2, 220 },
        !           234:     { "extra healing",          5, 180 },
        !           235:     { "haste self",             4, 200 },
        !           236:     { "restore strength",      14, 120 },
        !           237:     { "blindness",              4,  50 },
        !           238:     { "thirst quenching",       1,  50 },
        !           239: };
        !           240: 
        !           241: struct magic_item r_magic[MAXRINGS] = {
        !           242:     { "protection",             9, 200 },
        !           243:     { "add strength",           9, 200 },
        !           244:     { "sustain strength",       5, 180 },
        !           245:     { "searching",             10, 200 },
        !           246:     { "see invisible",         10, 175 },
        !           247:     { "adornment",              1, 100 },
        !           248:     { "aggravate monster",     11, 100 },
        !           249:     { "dexterity",              8, 220 },
        !           250:     { "increase damage",        8, 220 },
        !           251:     { "regeneration",           4, 260 },
        !           252:     { "slow digestion",                 9, 240 },
        !           253:     { "telportation",           9, 100 },
        !           254:     { "stealth",                7, 100 },
        !           255: };
        !           256: 
        !           257: struct magic_item ws_magic[MAXSTICKS] = {
        !           258:     { "light",                 12, 120 },
        !           259:     { "striking",               9, 115 },
        !           260:     { "lightning",              3, 200 },
        !           261:     { "fire",                   3, 200 },
        !           262:     { "cold",                   3, 200 },
        !           263:     { "polymorph",             15, 210 },
        !           264:     { "magic missile",         10, 170 },
        !           265:     { "haste monster",          9,  50 },
        !           266:     { "slow monster",          11, 220 },
        !           267:     { "drain life",             9, 210 },
        !           268:     { "nothing",                1,  70 },
        !           269:     { "teleport away",          5, 140 },
        !           270:     { "teleport to",            5,  60 },
        !           271:     { "cancellation",           5, 130 },
        !           272: };
        !           273: 
        !           274: int a_class[MAXARMORS] = {
        !           275:     8,
        !           276:     7,
        !           277:     7,
        !           278:     6,
        !           279:     5,
        !           280:     4,
        !           281:     4,
        !           282:     3,
        !           283: };
        !           284: 
        !           285: char *a_names[MAXARMORS] = {
        !           286:     "leather armor",
        !           287:     "ring mail",
        !           288:     "studded leather armor",
        !           289:     "scale mail",
        !           290:     "chain mail",
        !           291:     "splint mail",
        !           292:     "banded mail",
        !           293:     "plate mail",
        !           294: };
        !           295: 
        !           296: int a_chances[MAXARMORS] = {
        !           297:     20,
        !           298:     35,
        !           299:     50,
        !           300:     63,
        !           301:     75,
        !           302:     85,
        !           303:     95,
        !           304:     100
        !           305: };
        !           306: 
        !           307: /*
        !           308:  * init_things
        !           309:  *     Initialize the probabilities for types of things
        !           310:  */
        !           311: init_things()
        !           312: {
        !           313:     register struct magic_item *mp;
        !           314: 
        !           315:     for (mp = &things[1]; mp < &things[NUMTHINGS]; mp++)
        !           316:        mp->mi_prob += (mp-1)->mi_prob;
        !           317:     badcheck("things", things, NUMTHINGS);
        !           318: }
        !           319: 
        !           320: /*
        !           321:  * init_colors:
        !           322:  *     Initialize the potion color scheme for this time
        !           323:  */
        !           324: 
        !           325: init_colors()
        !           326: {
        !           327:     register int i;
        !           328:     register char *str;
        !           329: 
        !           330:     for (i = 0; i < MAXPOTIONS; i++)
        !           331:     {
        !           332:        do
        !           333:            str = rainbow[rnd(NCOLORS)];
        !           334:        until (isupper(*str));
        !           335:        *str = tolower(*str);
        !           336:        p_colors[i] = str;
        !           337:        p_know[i] = FALSE;
        !           338:        p_guess[i] = NULL;
        !           339:        if (i > 0)
        !           340:                p_magic[i].mi_prob += p_magic[i-1].mi_prob;
        !           341:     }
        !           342:     badcheck("potions", p_magic, MAXPOTIONS);
        !           343: }
        !           344: 
        !           345: /*
        !           346:  * init_names:
        !           347:  *     Generate the names of the various scrolls
        !           348:  */
        !           349: 
        !           350: init_names()
        !           351: {
        !           352:     register int nsyl;
        !           353:     register char *cp, *sp;
        !           354:     register int i, nwords;
        !           355: 
        !           356:     for (i = 0; i < MAXSCROLLS; i++)
        !           357:     {
        !           358:        cp = prbuf;
        !           359:        nwords = rnd(4)+2;
        !           360:        while(nwords--)
        !           361:        {
        !           362:            nsyl = rnd(3)+1;
        !           363:            while(nsyl--)
        !           364:            {
        !           365:                sp = sylls[rnd((sizeof sylls) / (sizeof (char *)))];
        !           366:                while(*sp)
        !           367:                    *cp++ = *sp++;
        !           368:            }
        !           369:            *cp++ = ' ';
        !           370:        }
        !           371:        *--cp = '\0';
        !           372:        s_names[i] = (char *) new(strlen(prbuf)+1);
        !           373:        s_know[i] = FALSE;
        !           374:        s_guess[i] = NULL;
        !           375:        strcpy(s_names[i], prbuf);
        !           376:        if (i > 0)
        !           377:                s_magic[i].mi_prob += s_magic[i-1].mi_prob;
        !           378:     }
        !           379:     badcheck("scrolls", s_magic, MAXSCROLLS);
        !           380: }
        !           381: 
        !           382: /*
        !           383:  * init_stones:
        !           384:  *     Initialize the ring stone setting scheme for this time
        !           385:  */
        !           386: 
        !           387: init_stones()
        !           388: {
        !           389:     register int i;
        !           390:     register char *str;
        !           391: 
        !           392:     for (i = 0; i < MAXRINGS; i++)
        !           393:     {
        !           394:        do
        !           395:            str = stones[rnd(NSTONES)];
        !           396:        until (isupper(*str));
        !           397:        *str = tolower(*str);
        !           398:        r_stones[i] = str;
        !           399:        r_know[i] = FALSE;
        !           400:        r_guess[i] = NULL;
        !           401:        if (i > 0)
        !           402:                r_magic[i].mi_prob += r_magic[i-1].mi_prob;
        !           403:     }
        !           404:     badcheck("rings", r_magic, MAXRINGS);
        !           405: }
        !           406: 
        !           407: /*
        !           408:  * init_materials:
        !           409:  *     Initialize the construction materials for wands and staffs
        !           410:  */
        !           411: 
        !           412: init_materials()
        !           413: {
        !           414:     register int i;
        !           415:     register char *str;
        !           416: 
        !           417:     for (i = 0; i < MAXSTICKS; i++)
        !           418:     {
        !           419:        do
        !           420:            if (rnd(100) > 50)
        !           421:            {
        !           422:                str = metal[rnd(NMETAL)];
        !           423:                if (isupper(*str))
        !           424:                        ws_type[i] = "wand";
        !           425:            }
        !           426:            else
        !           427:            {
        !           428:                str = wood[rnd(NWOOD)];
        !           429:                if (isupper(*str))
        !           430:                        ws_type[i] = "staff";
        !           431:            }
        !           432:        until (isupper(*str));
        !           433:        *str = tolower(*str);
        !           434:        ws_made[i] = str;
        !           435:        ws_know[i] = FALSE;
        !           436:        ws_guess[i] = NULL;
        !           437:        if (i > 0)
        !           438:                ws_magic[i].mi_prob += ws_magic[i-1].mi_prob;
        !           439:     }
        !           440:     badcheck("sticks", ws_magic, MAXSTICKS);
        !           441: }
        !           442: 
        !           443: badcheck(name, magic, bound)
        !           444: char *name;
        !           445: register struct magic_item *magic;
        !           446: register int bound;
        !           447: {
        !           448:     register struct magic_item *end;
        !           449: 
        !           450:     if (magic[bound - 1].mi_prob == 100)
        !           451:        return;
        !           452:     printf("\nBad percentages for %s:\n", name);
        !           453:     for (end = &magic[bound]; magic < end; magic++)
        !           454:        printf("%3d%% %s\n", magic->mi_prob, magic->mi_name);
        !           455:     printf("[hit RETURN to continue]");
        !           456:     fflush(stdout);
        !           457:     while (getchar() != '\n')
        !           458:        continue;
        !           459: }
        !           460: 
        !           461: struct h_list helpstr[] = {
        !           462:     '?',       "       prints help",
        !           463:     '/',       "       identify object",
        !           464:     'h',       "       left",
        !           465:     'j',       "       down",
        !           466:     'k',       "       up",
        !           467:     'l',       "       right",
        !           468:     'y',       "       up & left",
        !           469:     'u',       "       up & right",
        !           470:     'b',       "       down & left",
        !           471:     'n',       "       down & right",
        !           472:     'H',       "       run left",
        !           473:     'J',       "       run down",
        !           474:     'K',       "       run up",
        !           475:     'L',       "       run right",
        !           476:     'Y',       "       run up & left",
        !           477:     'U',       "       run up & right",
        !           478:     'B',       "       run down & left",
        !           479:     'N',       "       run down & right",
        !           480:     't',       "<dir>  throw something",
        !           481:     'f',       "<dir>  forward until find something",
        !           482:     'p',       "<dir>  zap a wand in a direction",
        !           483:     'z',       "       zap a wand or staff",
        !           484:     '>',       "       go down a staircase",
        !           485:     's',       "       search for trap/secret door",
        !           486:     ' ',       "       (space) rest for a while",
        !           487:     'i',       "       inventory",
        !           488:     'I',       "       inventory single item",
        !           489:     'q',       "       quaff potion",
        !           490:     'r',       "       read paper",
        !           491:     'e',       "       eat food",
        !           492:     'w',       "       wield a weapon",
        !           493:     'W',       "       wear armor",
        !           494:     'T',       "       take armor off",
        !           495:     'P',       "       put on ring",
        !           496:     'R',       "       remove ring",
        !           497:     'd',       "       drop object",
        !           498:     'c',       "       call object",
        !           499:     'o',       "       examine/set options",
        !           500:     CTRL(L),   "       redraw screen",
        !           501:     CTRL(R),   "       repeat last message",
        !           502:     ESCAPE,    "       cancel command",
        !           503:     'v',       "       print program version number",
        !           504:     '!',       "       shell escape",
        !           505:     'S',       "       save game",
        !           506:     'Q',       "       quit",
        !           507:     0, 0
        !           508: };

unix.superglobalmegacorp.com

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