home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume11 / larn / part09 / moreobj.c < prev    next >
C/C++ Source or Header  |  1991-01-03  |  12KB  |  561 lines

  1. /* moreobj.c        Larn is copyrighted 1986 by Noah Morgan.
  2.  
  3.    Routines in this file:
  4.  
  5.    oaltar()
  6.    othrone()
  7.    odeadthrone()
  8.    ochest()
  9.    ofountain()
  10.    fntchange()
  11.    fch()
  12.    drink_fountain()
  13.    wash_fountain()
  14.    enter()
  15.    remove_gems()
  16.    sit_on_throne()
  17.    kick_stairs()
  18.    up_stairs()
  19.    down_stairs()
  20.    open_something()
  21.    close_something()
  22.    desecrate_altar()
  23.    pray_at_altar()
  24. */
  25. #include "header.h"
  26.  
  27. /*
  28.     subroutine to process an altar object
  29. */
  30. oaltar()
  31.     {
  32.     unsigned long k;
  33.  
  34.     lprcat("\nDo you (p) pray  (d) desecrate"); iopts();
  35.     while (1) switch(ttgetch())
  36.         {
  37.         case 'p':   
  38.         lprcat(" pray\nDo you (m) give money or (j) just pray? ");
  39.             while (1) switch(ttgetch())
  40.                 {
  41.                 case 'j': 
  42.             lprcat("\n");
  43.             act_just_pray();
  44.             return;
  45.  
  46.                 case 'm': 
  47.             act_donation_pray();
  48.             return;
  49.  
  50.                 case '\33':   
  51.             return;
  52.                 };
  53.  
  54.         case 'd': 
  55.         lprcat(" desecrate");
  56.         act_desecrate_altar();
  57.         return;
  58.  
  59.         case 'i':
  60.         case '\33': 
  61.         ignore();
  62.         act_ignore_altar();
  63.             return;
  64.         };
  65.     }
  66.  
  67. /*
  68.     subroutine to process a throne object
  69. */
  70. othrone(arg)
  71.     int arg;
  72.     {
  73.  
  74.     lprcat("\nDo you (p) pry off jewels, (s) sit down"); iopts();
  75.     while (1)
  76.       {
  77.       while (1) switch(ttgetch())
  78.         {
  79.         case 'p':   
  80.             lprcat(" pry off");  
  81.             act_remove_gems( arg );
  82.             return;
  83.  
  84.         case 's':   
  85.             lprcat(" sit down");  
  86.             act_sit_throne( arg );
  87.             return;
  88.  
  89.         case 'i':
  90.         case '\33': ignore(); return;
  91.         };
  92.       }
  93.     }
  94.  
  95. odeadthrone()
  96.     {
  97.  
  98.     lprcat("\nDo you (s) sit down"); iopts();
  99.     while (1)
  100.       {
  101.       while (1) switch(ttgetch())
  102.         {
  103.         case 's':   
  104.             lprcat(" sit down");  
  105.             act_sit_throne(1);
  106.             return;
  107.  
  108.         case 'i':
  109.         case '\33': ignore(); return;
  110.         };
  111.       }
  112.     }
  113.  
  114. /*
  115.     subroutine to process a chest object
  116. */
  117. ochest()
  118.     {
  119.     lprcat("\nDo you (t) take it, (o) try to open it"); iopts();
  120.     while (1)
  121.       {
  122.       switch(ttgetch())
  123.         {
  124.     case 'o':
  125.         lprcat(" open it");
  126.         act_open_chest( playerx, playery );
  127.         return;
  128.  
  129.     case 't':
  130.         lprcat(" take");
  131.         if (take(OCHEST,iarg[playerx][playery])==0)
  132.         item[playerx][playery]=know[playerx][playery]=0;
  133.         return;
  134.  
  135.         case 'i':
  136.         case '\33': ignore(); return;
  137.         };
  138.       }
  139.     }
  140.  
  141. /*
  142.     process a fountain object
  143. */
  144. ofountain()
  145.     {
  146.     cursors();
  147.     lprcat("\nDo you (d) drink, (w) wash yourself"); iopts();
  148.     while (1) switch(ttgetch())
  149.         {
  150.         case 'd':
  151.             act_drink_fountain();
  152.             return;
  153.  
  154.         case '\33':
  155.         case 'i':   
  156.             ignore();  
  157.             return;
  158.  
  159.         case 'w':   
  160.             act_wash_fountain();
  161.             return;
  162.         }
  163.     }
  164.  
  165. /*
  166.     a subroutine to raise or lower character levels
  167.     if x > 0 they are raised   if x < 0 they are lowered
  168. */
  169. fntchange(how)
  170.     int how;
  171.     {
  172.     register long j;
  173.     lprc('\n');
  174.     switch(rnd(9))
  175.         {
  176.         case 1: 
  177.             lprcat("Your strength");        
  178.             fch(how,&c[STRENGTH]);     break;
  179.         case 2:
  180.             lprcat("Your intelligence");    
  181.             fch(how,&c[INTELLIGENCE]);     break;
  182.         case 3:
  183.             lprcat("Your wisdom");          
  184.             fch(how,&c[WISDOM]);     break;
  185.         case 4: 
  186.             lprcat("Your constitution");    
  187.             fch(how,&c[CONSTITUTION]);     break;
  188.         case 5:
  189.             lprcat("Your dexterity");
  190.             fch(how,&c[DEXTERITY]);     break;
  191.         case 6:
  192.             lprcat("Your charm");
  193.             fch(how,&c[CHARISMA]);     break;
  194.         case 7: 
  195.             j=rnd(level+1);
  196.             if (how < 0)
  197.                 {
  198.                 lprintf("You lose %d hit point",(long)j);
  199.                 if (j>1) lprcat("s!"); else lprc('!');
  200.                 losemhp((int)j);
  201.                 }
  202.             else
  203.                 { lprintf("You gain %d hit point",(long)j);  if (j>1) lprcat("s!"); else lprc('!'); raisemhp((int)j); }
  204.             bottomline();       break;
  205.  
  206.         case 8: j=rnd(level+1);
  207.                 if (how > 0)
  208.                     {
  209.                     lprintf("You just gained %d spell",(long)j);  raisemspells((int)j);
  210.                     if (j>1) lprcat("s!"); else lprc('!');
  211.                     }
  212.                 else
  213.                     {
  214.                     lprintf("You just lost %d spell",(long)j);  losemspells((int)j);
  215.                     if (j>1) lprcat("s!"); else lprc('!');
  216.                     }
  217.                 bottomline();       break;
  218.  
  219.         case 9: j = 5*rnd((level+1)*(level+1));
  220.                 if (how < 0)
  221.                     {
  222.                     lprintf("You just lost %d experience point",(long)j);
  223.                     if (j>1) lprcat("s!"); else lprc('!'); loseexperience((long)j);
  224.                     }
  225.                 else
  226.                     {
  227.                     lprintf("You just gained %d experience point",(long)j);
  228.                     if (j>1) lprcat("s!"); else lprc('!'); raiseexperience((long)j);
  229.                     }
  230.                 break;
  231.         }
  232.     cursors();
  233.     }
  234.  
  235. /*
  236.     subroutine to process an up/down of a character attribute for ofountain
  237. */
  238. static fch(how,x)
  239.     int how;
  240.     long *x;
  241.     {
  242.     if (how < 0)     { lprcat(" went down by one!");    --(*x); }
  243.         else         { lprcat(" went up by one!");  (*x)++; }
  244.     bottomline();
  245.     }
  246.  
  247. /*
  248.     For command mode.  Perform drinking at a fountain.
  249. */
  250. drink_fountain()
  251.     {
  252.     cursors() ;
  253.     if (item[playerx][playery] == ODEADFOUNTAIN)
  254.         lprcat("\nThere is no water to drink!") ;
  255.  
  256.     else if (item[playerx][playery] != OFOUNTAIN)
  257.         lprcat("\nI see no fountain to drink from here!") ;
  258.  
  259.     else 
  260.         act_drink_fountain();
  261.     return;
  262.     }
  263.  
  264. /*
  265.     For command mode.  Perform washing (tidying up) at a fountain.
  266. */
  267. wash_fountain()
  268.     {
  269.     cursors() ;
  270.     if (item[playerx][playery] == ODEADFOUNTAIN)
  271.         lprcat("\nThere is no water to wash in!") ;
  272.  
  273.     else if (item[playerx][playery] != OFOUNTAIN)
  274.         lprcat("\nI see no fountain to wash at here!") ;
  275.  
  276.     else
  277.         act_wash_fountain();
  278.     return;
  279.     }
  280.  
  281. /*
  282.     For command mode.  Perform entering a building.
  283. */
  284. enter()
  285.     {
  286.     cursors() ;
  287.     switch ( item[playerx][playery] )
  288.         {
  289.         case OSCHOOL:
  290.             oschool();
  291.             break ;
  292.  
  293.         case OBANK:
  294.             obank() ;
  295.             break ;
  296.  
  297.         case OBANK2:
  298.             obank2() ;
  299.             break ;
  300.  
  301.         case ODNDSTORE:
  302.             dndstore() ;
  303.             break ;
  304.  
  305.         case OENTRANCE:
  306.             newcavelevel( 1 );
  307.             playerx = 33 ;
  308.             playery = MAXY - 2 ;
  309.             item[33][MAXY - 1] = know[33][MAXY - 1] = mitem[33][MAXY - 1] = 0 ;
  310.             draws( 0, MAXX, 0, MAXY ); 
  311.             showcell(playerx, playery);         /* to show around player */
  312.             bot_linex() ;
  313.             break ;
  314.  
  315.         case OTRADEPOST:
  316.             otradepost();
  317.             break;
  318.  
  319.         case OLRS:
  320.             olrs();
  321.             break;
  322.  
  323.         case OHOME:
  324.             ohome();
  325.             break;
  326.  
  327.         default :
  328.             lprcat("\nThere is no place to enter here!\n");
  329.             break;
  330.         }
  331.     }
  332.  
  333. /*
  334.     For command mode.  Perform removal of gems from a jeweled throne.
  335. */
  336. remove_gems ( )
  337.     {
  338.     
  339.     cursors();
  340.     if (item[playerx][playery] == ODEADTHRONE)
  341.         lprcat("\nThere are no gems to remove!");
  342.     
  343.     else if (item[playerx][playery] == OTHRONE)
  344.         act_remove_gems(0);
  345.  
  346.     else if (item[playerx][playery] == OTHRONE2)
  347.         act_remove_gems(1);
  348.  
  349.     else
  350.         lprcat("\nI see no throne here to remove gems from!");
  351.     return;
  352.     }
  353.  
  354. /*
  355.     For command mode.  Perform sitting on a throne.
  356. */
  357. sit_on_throne( )
  358.     {
  359.  
  360.     cursors();
  361.     if (item[playerx][playery] == OTHRONE)
  362.         act_sit_throne(0);
  363.     
  364.     else if ((item[playerx][playery] == OTHRONE2) ||
  365.              (item[playerx][playery] == ODEADTHRONE))
  366.         act_sit_throne(1);
  367.     
  368.     else
  369.         lprcat("\nI see no throne to sit on here!");
  370.  
  371.     return;
  372.     }
  373.  
  374. /*
  375.     For command mode.  Checks that the player is actually standing at a set
  376.     of stairs before letting him kick them.
  377. */
  378. kick_stairs()
  379.     {
  380.     cursors();
  381.     if (item[playerx][playery] != OSTAIRSUP &&
  382.     item[playerx][playery] != OSTAIRSDOWN)
  383.     lprcat("\nI see no stairs to kick here!");
  384.  
  385.     else
  386.     act_kick_stairs();
  387.     }
  388.  
  389. /*
  390.     For command mode.  Checks that player is actually standing at a set up
  391.     up stairs or volcanic shaft.  
  392. */
  393. up_stairs()
  394.     {
  395.     cursors();
  396.     if (item[playerx][playery] == OSTAIRSDOWN)
  397.     lprcat("\nThe stairs don't go up!");
  398.  
  399.     else if (item[playerx][playery] == OVOLUP)
  400.     act_up_shaft();
  401.  
  402.     else if (item[playerx][playery] != OSTAIRSUP)
  403.     lprcat("\nI see no way to go up here!");
  404.  
  405.     else
  406.     act_up_stairs();
  407.     }
  408.  
  409. /*
  410.     For command mode.  Checks that player is actually standing at a set of
  411.     down stairs or volcanic shaft.
  412. */
  413. down_stairs()
  414.     {
  415.     cursors();
  416.     if (item[playerx][playery] == OSTAIRSUP)
  417.     lprcat("\nThe stairs don't go down!");
  418.  
  419.     else if (item[playerx][playery] == OVOLDOWN)
  420.     act_down_shaft();
  421.  
  422.     else if (item[playerx][playery] != OSTAIRSDOWN)
  423.     lprcat("\nI see no way to go down here!");
  424.  
  425.     else
  426.     act_down_stairs();
  427.     }
  428.  
  429. /*
  430.     For command mode.  Perform opening an object (door, chest).
  431. */
  432. open_something( )
  433.     {
  434.     int x,y;    /* direction to open */
  435.     char tempc; /* result of prompting to open a chest */
  436.  
  437.     cursors();
  438.     /* check for confusion.
  439.     */
  440.     if (c[CONFUSE])
  441.         {
  442.         lprcat("You're too confused!");
  443.         beep();
  444.         return;
  445.         }
  446.  
  447.     /* check for player standing on a chest.  If he is, prompt for and
  448.        let him open it.  If player ESCs from prompt, quit the Open
  449.        command.
  450.     */
  451.     if (item[playerx][playery] == OCHEST)
  452.         {
  453.         lprcat("There is a chest here.  Open it?");
  454.         if ((tempc = getyn()) == 'y')
  455.             {
  456.             act_open_chest( playerx, playery );
  457.             return;
  458.             }
  459.         else if (tempc != 'n' )
  460.             return;
  461.         }
  462.  
  463.     /* get direction of object to open.  test 'openability' of object
  464.        indicated, call common command/prompt mode routines to actually open.
  465.     */
  466.     dirsub( &x, &y );
  467.     switch( item[x][y] )
  468.         {
  469.         case OOPENDOOR:
  470.             lprcat("The door is already open!");
  471.             beep();
  472.             break;
  473.  
  474.         case OCHEST:
  475.             act_open_chest( x, y );
  476.             break;
  477.  
  478.         case OCLOSEDDOOR:
  479.             act_open_door( x, y );
  480.             break;
  481.  
  482.         default:
  483.             lprcat("You can't open that!");
  484.             beep();
  485.             break;
  486.         }
  487.     }
  488.  
  489. /*
  490.     For command mode.  Perform the action of closing something (door).
  491. */
  492. close_something()
  493.     {
  494.     int x,y;
  495.  
  496.     cursors();
  497.     /* check for confusion.
  498.     */
  499.     if (c[CONFUSE])
  500.         {
  501.         lprcat("You're too confused!");
  502.         beep();
  503.         return;
  504.         }
  505.  
  506.     /* get direction of object to close.  test 'closeability' of object
  507.        indicated.
  508.     */
  509.     dirsub( &x, &y );
  510.     switch( item[x][y] )
  511.         {
  512.         case OCLOSEDDOOR:
  513.             lprcat("The door is already closed!");
  514.             beep();
  515.             break;
  516.  
  517.         case OOPENDOOR:
  518.         if (mitem[x][y])
  519.         {
  520.             lprcat("Theres a monster in the way!");
  521.             return;
  522.         }
  523.             item[x][y] = OCLOSEDDOOR;
  524.             know[x][y] = 0 ;
  525.             iarg[x][y] = 0 ;
  526.             break;
  527.  
  528.         default:
  529.             lprcat("You can't close that!");
  530.             beep();
  531.             break;
  532.         }
  533.     }
  534.  
  535. /*
  536.     For command mode.  Perform the act of descecrating an altar.
  537. */
  538. desecrate_altar()
  539.     {
  540.     cursors();
  541.     if (item[playerx][playery] == OALTAR)
  542.     act_desecrate_altar();
  543.     else
  544.     lprcat("\nI see no altar to desecrate here!");
  545.     }
  546.  
  547. /*
  548.     For command mode.  Perform the act of praying at an altar.
  549. */
  550. pray_at_altar()
  551.     {
  552.     extern char prayed ;
  553.  
  554.     cursors();
  555.     if (item[playerx][playery] != OALTAR)
  556.         lprcat("\nI see no altar to pray at here!");
  557.     else
  558.     act_donation_pray();
  559.     prayed = 1 ;
  560.     }
  561.