home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / HACKSRC.ZIP / U_INIT.C < prev    next >
C/C++ Source or Header  |  1985-10-16  |  8KB  |  359 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* u_init.c - version 1.0.3 */
  3.  
  4. #include <stdio.h>
  5. #include <signal.h>
  6. #include "hack.h"
  7. #define Strcpy    (void) strcpy
  8. #define    Strcat    (void) strcat
  9. #define    UNDEF_TYP    0
  10. #define    UNDEF_SPE    '\177'
  11. extern struct obj *addinv();
  12. extern char *eos();
  13. extern char plname[];
  14. extern boolean female;
  15.  
  16. struct you zerou;
  17. char pl_character[PL_CSIZ];
  18. char *(roles[]) = {    /* must all have distinct first letter */
  19.             /* roles[4] may be changed to -man */
  20.     "Tourist", "Speleologist", "Fighter", "Knight",
  21.     "Cave-man", "Wizard"
  22. };
  23. #define    NR_OF_ROLES    SIZE(roles)
  24. char rolesyms[NR_OF_ROLES + 1];        /* filled by u_init() */
  25.  
  26. struct trobj {
  27.     uchar trotyp;
  28.     schar trspe;
  29.     char trolet;
  30.     Bitfield(trquan,6);
  31.     Bitfield(trknown,1);
  32. };
  33.  
  34. #ifdef WIZARD
  35. struct trobj Extra_objs[] = {
  36.     { 0, 0, 0, 0, 0 },
  37.     { 0, 0, 0, 0, 0 }
  38. };
  39. #endif WIZARD
  40.  
  41. struct trobj Cave_man[] = {
  42.     { MACE, 1, WEAPON_SYM, 1, 1 },
  43.     { BOW, 1, WEAPON_SYM, 1, 1 },
  44.     { ARROW, 0, WEAPON_SYM, 25, 1 },    /* quan is variable */
  45.     { LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
  46.     { 0, 0, 0, 0, 0}
  47. };
  48.  
  49. struct trobj Fighter[] = {
  50.     { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 },
  51.     { RING_MAIL, 0, ARMOR_SYM, 1, 1 },
  52.     { 0, 0, 0, 0, 0 }
  53. };
  54.  
  55. struct trobj Knight[] = {
  56.     { LONG_SWORD, 0, WEAPON_SYM, 1, 1 },
  57.     { SPEAR, 2, WEAPON_SYM, 1, 1 },
  58.     { RING_MAIL, 1, ARMOR_SYM, 1, 1 },
  59.     { HELMET, 0, ARMOR_SYM, 1, 1 },
  60.     { SHIELD, 0, ARMOR_SYM, 1, 1 },
  61.     { PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1 },
  62.     { 0, 0, 0, 0, 0 }
  63. };
  64.  
  65. struct trobj Speleologist[] = {
  66.     { STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
  67.     { UNDEF_TYP, 0, POTION_SYM, 2, 0 },
  68.     { FOOD_RATION, 0, FOOD_SYM, 3, 1 },
  69.     { PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0 },
  70.     { ICE_BOX, 0, TOOL_SYM, 1, 0 },
  71.     { 0, 0, 0, 0, 0}
  72. };
  73.  
  74. struct trobj Tinopener[] = {
  75.     { CAN_OPENER, 0, TOOL_SYM, 1, 1 },
  76.     { 0, 0, 0, 0, 0 }
  77. };
  78.  
  79. struct trobj Tourist[] = {
  80.     { UNDEF_TYP, 0, FOOD_SYM, 10, 1 },
  81.     { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 },
  82.     { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 },
  83.     { DART, 2, WEAPON_SYM, 25, 1 },    /* quan is variable */
  84.     { 0, 0, 0, 0, 0 }
  85. };
  86.  
  87. struct trobj Wizard[] = {
  88.     { ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1 },
  89.     { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 },
  90.     { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 },
  91.     { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 },
  92.     { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 },
  93.     { 0, 0, 0, 0, 0 }
  94. };
  95.  
  96. u_init(){
  97. register int i;
  98. char exper = 'y', pc;
  99. extern char readchar();
  100.     if(female)        /* should have been set in HACKOPTIONS */
  101.         roles[4] = "Cave-woman";
  102.     for(i = 0; i < NR_OF_ROLES; i++)
  103.         rolesyms[i] = roles[i][0];
  104.     rolesyms[i] = 0;
  105.  
  106.     if(pc = pl_character[0]) {
  107.         if('a' <= pc && pc <= 'z') pc += 'A'-'a';
  108.         if((i = role_index(pc)) >= 0)
  109.             goto got_suffix;    /* implies experienced */
  110.         printf("\nUnknown role: %c\n", pc);
  111.         pl_character[0] = pc = 0;
  112.     }
  113.  
  114.     printf("\nAre you an experienced player? [ny] ");
  115.  
  116.     while(!index("ynYN \n\004", (exper = readchar())))
  117.         bell();
  118.     if(exper == '\004')        /* Give him an opportunity to get out */
  119.         end_of_input();
  120.     printf("%c\n", exper);        /* echo */
  121.     if(index("Nn \n", exper)) {
  122.         exper = 0;
  123.         goto beginner;
  124.     }
  125.  
  126.     printf("\nTell me what kind of character you are:\n");
  127.     printf("Are you");
  128.     for(i = 0; i < NR_OF_ROLES; i++) {
  129.         printf(" a %s", roles[i]);
  130.         if(i == 2)            /* %% */
  131.             printf(",\n\t");
  132.         else if(i < NR_OF_ROLES - 2)
  133.             printf(",");
  134.         else if(i == NR_OF_ROLES - 2)
  135.             printf(" or");
  136.     }
  137.     printf("? [%s] ", rolesyms);
  138.  
  139.     while(pc = readchar()) {
  140.         if('a' <= pc && pc <= 'z') pc += 'A'-'a';
  141.         if((i = role_index(pc)) >= 0) {
  142.             printf("%c\n", pc);    /* echo */
  143.             (void) fflush(stdout);    /* should be seen */
  144.             break;
  145.         }
  146.         if(pc == '\n')
  147.             break;
  148.         if(pc == '\004')    /* Give him the opportunity to get out */
  149.             end_of_input();
  150.         bell();
  151.     }
  152.     if(pc == '\n')
  153.         pc = 0;
  154.  
  155. beginner:
  156.     if(!pc) {
  157.         printf("\nI'll choose a character for you.\n");
  158.         i = rn2(NR_OF_ROLES);
  159.         pc = rolesyms[i];
  160.         printf("This game you will be a%s %s.\n",
  161.             exper ? "n experienced" : "",
  162.             roles[i]);
  163.         getret();
  164.         /* give him some feedback in case mklev takes much time */
  165.         (void) putchar('\n');
  166.         (void) fflush(stdout);
  167.     }
  168.     if(exper) {
  169.         roles[i][0] = pc;
  170.     }
  171.  
  172. got_suffix:
  173.  
  174.     (void) strncpy(pl_character, roles[i], PL_CSIZ-1);
  175.     pl_character[PL_CSIZ-1] = 0;
  176.     flags.beginner = 1;
  177.     u = zerou;
  178.     u.usym = '@';
  179.     u.ulevel = 1;
  180.     init_uhunger();
  181. #ifdef QUEST
  182.     u.uhorizon = 6;
  183. #endif QUEST
  184.     uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain =
  185.     uleft = uright = 0;
  186.  
  187.     switch(pc) {
  188.     case 'c':
  189.     case 'C':
  190.         Cave_man[2].trquan = 12 + rnd(9)*rnd(9);
  191.         u.uhp = u.uhpmax = 16;
  192.         u.ustr = u.ustrmax = 18;
  193.         ini_inv(Cave_man);
  194.         break;
  195.     case 't':
  196.     case 'T':
  197.         Tourist[3].trquan = 20 + rnd(20);
  198.         u.ugold = u.ugold0 = rnd(1000);
  199.         u.uhp = u.uhpmax = 10;
  200.         u.ustr = u.ustrmax = 8;
  201.         ini_inv(Tourist);
  202.         if(!rn2(25)) ini_inv(Tinopener);
  203.         break;
  204.     case 'w':
  205.     case 'W':
  206.         for(i=1; i<=4; i++) if(!rn2(5))
  207.             Wizard[i].trquan += rn2(3) - 1;
  208.         u.uhp = u.uhpmax = 15;
  209.         u.ustr = u.ustrmax = 16;
  210.         ini_inv(Wizard);
  211.         break;
  212.     case 's':
  213.     case 'S':
  214.         Fast = INTRINSIC;
  215.         Stealth = INTRINSIC;
  216.         u.uhp = u.uhpmax = 12;
  217.         u.ustr = u.ustrmax = 10;
  218.         ini_inv(Speleologist);
  219.         if(!rn2(10)) ini_inv(Tinopener);
  220.         break;
  221.     case 'k':
  222.     case 'K':
  223.         u.uhp = u.uhpmax = 12;
  224.         u.ustr = u.ustrmax = 10;
  225.         ini_inv(Knight);
  226.         break;
  227.     case 'f':
  228.     case 'F':
  229.         u.uhp = u.uhpmax = 14;
  230.         u.ustr = u.ustrmax = 17;
  231.         ini_inv(Fighter);
  232.         break;
  233.     default:    /* impossible */
  234.         u.uhp = u.uhpmax = 12;
  235.         u.ustr = u.ustrmax = 16;
  236.     }
  237.     find_ac();
  238.     if(!rn2(20)) {
  239.         register int d = rn2(7) - 2;    /* biased variation */
  240.         u.ustr += d;
  241.         u.ustrmax += d;
  242.     }
  243.  
  244. #ifdef WIZARD
  245.     if(wizard) wiz_inv();
  246. #endif WIZARD
  247.  
  248.     /* make sure he can carry all he has - especially for T's */
  249.     while(inv_weight() > 0 && u.ustr < 118)
  250.         u.ustr++, u.ustrmax++;
  251. }
  252.  
  253. ini_inv(trop) register struct trobj *trop; {
  254. register struct obj *obj;
  255. extern struct obj *mkobj();
  256.     while(trop->trolet) {
  257.         obj = mkobj(trop->trolet);
  258.         obj->known = trop->trknown;
  259.         /* not obj->dknown = 1; - let him look at it at least once */
  260.         obj->cursed = 0;
  261.         if(obj->olet == WEAPON_SYM){
  262.             obj->quan = trop->trquan;
  263.             trop->trquan = 1;
  264.         }
  265.         if(trop->trspe != UNDEF_SPE)
  266.             obj->spe = trop->trspe;
  267.         if(trop->trotyp != UNDEF_TYP)
  268.             obj->otyp = trop->trotyp;
  269.         else
  270.             if(obj->otyp == WAN_WISHING)    /* gitpyr!robert */
  271.                 obj->otyp = WAN_DEATH;
  272.         obj->owt = weight(obj);    /* defined after setting otyp+quan */
  273.         obj = addinv(obj);
  274.         if(obj->olet == ARMOR_SYM){
  275.             switch(obj->otyp){
  276.             case SHIELD:
  277.                 if(!uarms) setworn(obj, W_ARMS);
  278.                 break;
  279.             case HELMET:
  280.                 if(!uarmh) setworn(obj, W_ARMH);
  281.                 break;
  282.             case PAIR_OF_GLOVES:
  283.                 if(!uarmg) setworn(obj, W_ARMG);
  284.                 break;
  285.             case ELVEN_CLOAK:
  286.                 if(!uarm2)
  287.                     setworn(obj, W_ARM);
  288.                 break;
  289.             default:
  290.                 if(!uarm) setworn(obj, W_ARM);
  291.             }
  292.         }
  293.         if(obj->olet == WEAPON_SYM)
  294. #ifndef PYRAMID_BUG
  295.             if(!uwep) setuwep(obj);
  296. #else
  297.         if(trop->trquan) {        /* check if zero first */
  298.             --trop->trquan;
  299.             if(trop->trquan)
  300.                 continue;    /* make a similar object */
  301.         }
  302. #endif PYRAMID_BUG
  303.         if(--trop->trquan) continue;    /* make a similar object */
  304.         trop++;
  305.     }
  306. }
  307.  
  308. #ifdef WIZARD
  309. wiz_inv(){
  310. register struct trobj *trop = &Extra_objs[0];
  311. extern char *getenv();
  312. register char *ep = getenv("INVENT");
  313. register int type;
  314.     while(ep && *ep) {
  315.         type = atoi(ep);
  316.         ep = index(ep, ',');
  317.         if(ep) while(*ep == ',' || *ep == ' ') ep++;
  318.         if(type <= 0 || type > NROFOBJECTS) continue;
  319.         trop->trotyp = type;
  320.         trop->trolet = objects[type].oc_olet;
  321.         trop->trspe = 4;
  322.         trop->trknown = 1;
  323.         trop->trquan = 1;
  324.         ini_inv(trop);
  325.     }
  326.     /* give him a wand of wishing by default */
  327.     trop->trotyp = WAN_WISHING;
  328.     trop->trolet = WAND_SYM;
  329.     trop->trspe = 20;
  330.     trop->trknown = 1;
  331.     trop->trquan = 1;
  332.     ini_inv(trop);
  333. }
  334. #endif WIZARD
  335.  
  336. plnamesuffix() {
  337. register char *p;
  338.     if(p = rindex(plname, '-')) {
  339.         *p = 0;
  340.         pl_character[0] = p[1];
  341.         pl_character[1] = 0;
  342.         if(!plname[0]) {
  343.             askname();
  344.             plnamesuffix();
  345.         }
  346.     }
  347. }
  348.  
  349. role_index(pc)
  350. char pc;
  351. {        /* must be called only from u_init() */
  352.         /* so that rolesyms[] is defined */
  353.     register char *cp;
  354.  
  355.     if(cp = index(rolesyms, pc))
  356.         return(cp - rolesyms);
  357.     return(-1);
  358. }
  359.