LCOV - code coverage report
Current view: top level - omega-rpg-0.90-pa9 - command2.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 149 743 20.1 %
Date: 2017-09-08 22:00:26 Functions: 10 25 40.0 %
Branches: 68 420 16.2 %

           Branch data     Line data    Source code
       1                 :            : /* omega copyright (C) by Laurence Raphael Brothers, 1987,1988,1989 */
       2                 :            : /* command2.c */
       3                 :            : 
       4                 :            : /* This file contains toplevel commands called from command1.c */
       5                 :            : 
       6                 :            : #ifndef MSDOS_SUPPORTED_ANTIQUE
       7                 :            : #include <unistd.h>
       8                 :            : #include <ctype.h>
       9                 :            : #endif
      10                 :            : 
      11                 :            : #include "glob.h"
      12                 :            : 
      13                 :            : /* no op a turn.... */
      14                 :          0 : void rest(void)
      15                 :            : {
      16         [ #  # ]:          0 :   if (random_range(20) == 1) {
      17   [ #  #  #  #  :          0 :     switch(random_range(10)) {
          #  #  #  #  #  
                   #  # ]
      18                 :          0 :       case 0: print3(" Time passes slowly.... "); break;
      19                 :          0 :       case 1: print3(" Tick. Tock. Tick. Tock. "); break;
      20                 :          0 :       case 2: print3(" Ho Hum. "); break;
      21                 :          0 :       case 3: print3(" Beauty Sleep. Well, in your case, Ugly Sleep. "); break;
      22                 :          0 :       case 4: print3(" And with Strange Aeons, even Death may die. "); break;
      23                 :          0 :       case 5: print3(" La Di Da. "); break;
      24                 :          0 :       case 6: print3(" Time keeps on tickin' tickin' -- into the future.... ");
      25                 :          0 :               break;
      26                 :          0 :       case 7: print3(" Boooring! "); break;
      27                 :          0 :       case 8: print3(" You think I like watching you sleep? "); break;
      28                 :          0 :       case 9: print3(" You sure have an early bedtime! "); break;
      29                 :            :     }
      30                 :          0 :     morewait();
      31                 :            :   }
      32                 :          0 : }
      33                 :            : 
      34                 :            : 
      35                 :            : /* read a scroll, book, tome, etc. */
      36                 :          0 : void peruse(void)
      37                 :            : {
      38                 :            :   int index;
      39                 :            :   struct object *obj;
      40                 :            : 
      41                 :          0 :   clearmsg();
      42                 :            : 
      43         [ #  # ]:          0 :   if (Player.status[BLINDED] > 0)
      44                 :          0 :     print3("You're blind -- you can't read!!!");
      45         [ #  # ]:          0 :   else if (Player.status[AFRAID] > 0)
      46                 :          0 :     print3("You are too afraid to stop to read a scroll!");
      47                 :            :   else {
      48                 :          0 :     index = getitem_prompt("Read -- ", SCROLL);
      49         [ #  # ]:          0 :     if (index == ABORT)
      50                 :          0 :       setgamestatus(SKIP_MONSTERS);
      51                 :            :     else {
      52                 :          0 :       obj = Player.possessions[index];
      53         [ #  # ]:          0 :       if (obj->objchar != SCROLL) {
      54                 :          0 :         print3("There's nothing written on ");
      55                 :          0 :         nprint3(itemid(obj));
      56                 :            :       }
      57                 :            :       else {
      58                 :          0 :         nprint1("You carefully unfurl the scroll....");
      59                 :          0 :         morewait();
      60                 :          0 :         item_use(obj);
      61                 :          0 :         dispose_lost_objects(1,obj);
      62                 :            :       }
      63                 :            :     }
      64                 :            :   }
      65                 :          0 : }
      66                 :            : 
      67                 :          0 : void quaff(void)
      68                 :            : {
      69                 :            :   int index;
      70                 :            :   struct object *obj;
      71                 :          0 :   clearmsg();
      72                 :          0 :   index = getitem_prompt("Quaff -- ", POTION);
      73         [ #  # ]:          0 :   if (index == ABORT)
      74                 :          0 :     setgamestatus(SKIP_MONSTERS);
      75                 :            :   else {
      76                 :          0 :     obj = Player.possessions[index];
      77         [ #  # ]:          0 :     if (obj->objchar != POTION) {
      78                 :          0 :       print3("You can't drink ");
      79                 :          0 :       nprint3(itemid(obj));
      80                 :            :     }
      81                 :            :     else {
      82                 :          0 :       print1("You drink it down.... ");
      83                 :          0 :       item_use(obj);
      84                 :          0 :       morewait();
      85                 :          0 :       dispose_lost_objects(1,obj);
      86                 :            :     }
      87                 :            :   }
      88                 :          0 : }
      89                 :            : 
      90                 :          0 : void activate(void)
      91                 :            : {
      92                 :          0 :   int index = ABORT;
      93                 :            :   char response;
      94                 :            : 
      95                 :          0 :   clearmsg();
      96                 :            : 
      97                 :          0 :   print1("Activate -- item [i] or artifact [a] or quit [ESCAPE]?");
      98                 :          0 :   do response = (char) mcigetc();
      99 [ #  # ][ #  # ]:          0 :   while ((response != 'i') && (response != 'a') && (response != ESCAPE));
                 [ #  # ]
     100         [ #  # ]:          0 :   if (response != ESCAPE) {
     101         [ #  # ]:          0 :     if (response == 'i')
     102                 :          0 :       index = getitem_prompt("Activate -- ", THING);
     103         [ #  # ]:          0 :     else if (response == 'a')
     104                 :          0 :       index = getitem_prompt("Activate -- ", ARTIFACT);
     105         [ #  # ]:          0 :     if (index != ABORT) {
     106                 :          0 :       clearmsg();
     107                 :          0 :       print1("You activate it.... ");
     108                 :          0 :       morewait();
     109                 :          0 :       item_use(Player.possessions[index]);
     110                 :            :     }
     111                 :          0 :     else setgamestatus(SKIP_MONSTERS);
     112                 :            :   }
     113                 :          0 :   else setgamestatus(SKIP_MONSTERS);
     114                 :          0 : }
     115                 :            : 
     116                 :            : 
     117                 :          2 : void eat (void)
     118                 :            : {
     119                 :            :   int index;
     120                 :            :   struct object *obj;
     121                 :            : 
     122                 :          2 :   clearmsg();
     123                 :            : 
     124                 :          2 :   index = getitem_prompt("Eat -- ", FOOD);
     125                 :            : 
     126         [ -  + ]:          2 :   if (index == ABORT)
     127                 :            :     {
     128                 :          0 :       setgamestatus(SKIP_MONSTERS);
     129                 :            :     }
     130                 :            :   else
     131                 :            :     {
     132                 :          2 :       obj = Player.possessions[index];
     133 [ -  + ][ #  # ]:          2 :       if ((obj->objchar != FOOD) && (obj->objchar != CORPSE))
     134                 :            :         {
     135                 :          0 :           print3("You can't eat ");
     136                 :          0 :           nprint3(itemid(obj));
     137                 :            :         }
     138                 :            :       else
     139                 :            :         {
     140         [ +  + ]:          2 :           if (obj->usef == I_FOOD) Player.food = max(0, Player.food+obj->aux);
     141                 :          2 :           item_use(obj);
     142                 :          2 :           dispose_lost_objects(1,obj);
     143         [ -  + ]:          2 :           if (Current_Dungeon == E_COUNTRYSIDE)
     144                 :            :             {
     145                 :          0 :               Time += 100;
     146                 :          0 :               hourly_check();
     147                 :            :             }
     148                 :            :         }
     149                 :            :     }
     150                 :            : 
     151                 :          2 :   foodcheck();
     152                 :          2 : }
     153                 :            : 
     154                 :            : 
     155                 :            : /* search all adjacent spots for secrecy */
     156                 :          0 : void search(int *searchval)
     157                 :            : {
     158                 :            :   int i;
     159         [ #  # ]:          0 :   if (Player.status[AFRAID] > 0)
     160                 :          0 :     print3("You are too terror-stricken to stop to search for anything.");
     161                 :            :   else {
     162         [ #  # ]:          0 :     if (!gamestatusp(FAST_MOVE)) {
     163                 :          0 :       setgamestatus(FAST_MOVE);
     164                 :          0 :       *searchval = Searchnum;
     165                 :            :     }
     166         [ #  # ]:          0 :     for (i=0;i<9;i++) 
     167                 :          0 :       searchat(Player.x+Dirs[0][i],Player.y+Dirs[1][i]);
     168                 :          0 :     drawvision(Player.x,Player.y);
     169                 :            :   }
     170                 :          0 : }
     171                 :            : 
     172                 :            : 
     173                 :            : 
     174                 :            : /* pick up a thing where the player is */
     175                 :          4 :  void pickup(void)
     176                 :            :  {
     177         [ +  + ]:          4 :    if (Level->site[Player.x][Player.y].things == NULL)
     178                 :          1 :      print3("There's nothing there!");
     179         [ -  + ]:          3 :    else if (Player.status[SHADOWFORM])
     180                 :          0 :      print3("You can't really interact with the real world in your shadowy state.");
     181                 :            :    else
     182                 :          3 :      pickup_at(Player.x,Player.y);
     183                 :          4 :  }
     184                 :            : 
     185                 :            : 
     186                 :            : #ifndef MSDOS_SUPPORTED_ANTIQUE
     187                 :            : /* floor inventory */
     188                 :          0 : void floor_inv(void)
     189                 :            : {
     190                 :          0 :   pol ol = Level->site[Player.x][Player.y].things;
     191                 :          0 :   setgamestatus(SKIP_MONSTERS);
     192                 :          0 :   menuclear();
     193         [ #  # ]:          0 :   while (ol != NULL) {
     194         [ #  # ]:          0 :     if (ol->thing == NULL) print3("***Error; null thing on things list***");
     195                 :            :     else {
     196                 :          0 :       menuprint(itemid(ol->thing));
     197                 :          0 :       menuprint("\n");
     198                 :            :     }
     199                 :          0 :     ol = ol->next;
     200                 :            :   }
     201                 :          0 :   showmenu();
     202                 :          0 :   morewait();
     203                 :          0 :   xredraw();
     204                 :          0 : }
     205                 :            : #endif
     206                 :            : 
     207                 :            : 
     208                 :          0 : void drop(void)
     209                 :            : {
     210                 :            :   int index,n;
     211                 :            :   
     212                 :          0 :   clearmsg();
     213                 :            : 
     214                 :          0 :   index = getitem_prompt("Drop -- ", CASH);
     215         [ #  # ]:          0 :   if (index == ABORT)
     216                 :          0 :     setgamestatus(SKIP_MONSTERS);
     217                 :            :   else {
     218         [ #  # ]:          0 :     if (index == CASHVALUE) drop_money();
     219   [ #  #  #  # ]:          0 :     else if ((! Player.possessions[index]->used) ||
     220                 :          0 :              (! cursed(Player.possessions[index]))) {
     221         [ #  # ]:          0 :       if (Player.possessions[index]->number == 1) {
     222                 :          0 :         p_drop_at(Player.x,Player.y,1,Player.possessions[index]);
     223                 :          0 :         conform_lost_objects(1,Player.possessions[index]);
     224                 :            :       }
     225                 :            :       else {
     226                 :          0 :         n = getnumber(Player.possessions[index]->number);
     227                 :          0 :         p_drop_at(Player.x,Player.y,n,Player.possessions[index]);
     228                 :          0 :         conform_lost_objects(n,Player.possessions[index]);
     229                 :            :       }
     230                 :            :     }
     231                 :            :     else {
     232                 :          0 :       print3("You can't seem to get rid of: ");
     233                 :          0 :       nprint3(itemid(Player.possessions[index]));
     234                 :            :     }
     235                 :            :   }
     236                 :          0 :   calc_melee();
     237                 :          0 : }
     238                 :            : 
     239                 :            : 
     240                 :            : /* talk to the animals -- learn their languages.... */
     241                 :          2 : void talk(void)
     242                 :            : {
     243                 :          2 :   int dx,dy,index=0;
     244                 :            :   char response;
     245                 :            :   struct monster *m;
     246                 :            : 
     247                 :          2 :   clearmsg();
     248                 :            : 
     249                 :          2 :   print1("Talk --");
     250                 :          2 :   index = getdir();
     251                 :            : 
     252         [ -  + ]:          2 :   if (index == ABORT)
     253                 :          0 :     setgamestatus(SKIP_MONSTERS);
     254                 :            :   else {
     255                 :          2 :     dx = Dirs[0][index];
     256                 :          2 :     dy = Dirs[1][index];
     257                 :            :     
     258 [ +  - ][ -  + ]:          2 :     if ((! inbounds(Player.x+dx, Player.y+dy)) ||
     259                 :          2 :         (Level->site[Player.x+dx][Player.y+dy].creature == NULL)) {
     260                 :          0 :       print3("There's nothing there to talk to!!!");
     261                 :          0 :       setgamestatus(SKIP_MONSTERS);
     262                 :            :     }
     263                 :            :     else {
     264                 :          2 :       m = Level->site[Player.x+dx][Player.y+dy].creature;
     265                 :          2 :       menuclear();
     266                 :          2 :       strcpy(Str1,"     Talk to ");
     267                 :          2 :       strcat(Str1,m->monstring);
     268                 :          2 :       strcat(Str1,":");
     269                 :          2 :       menuprint(Str1);
     270                 :          2 :       menuprint("\na: Greet.");
     271                 :          2 :       menuprint("\nb: Threaten.");
     272                 :          2 :       menuprint("\nc: Surrender.");
     273                 :          2 :       menuprint("\nESCAPE: Clam up.");
     274                 :          2 :       showmenu();
     275                 :          2 :       do response = menugetc();
     276         [ #  # ]:          0 :       while ((response != 'a') &&
     277         [ #  # ]:          0 :              (response != 'b') &&
     278         [ #  # ]:          0 :              (response != 'c') &&
     279         [ -  + ]:          2 :              (response != ESCAPE));
     280   [ +  -  -  - ]:          2 :       switch(response) {
     281                 :          2 :       case 'a': monster_talk(m); break;
     282                 :          0 :       case 'b': threaten(m); break;
     283                 :          0 :       case 'c': surrender(m); break;
     284                 :          0 :       default: setgamestatus(SKIP_MONSTERS); break;
     285                 :            :       }
     286                 :            :     }
     287                 :            :   }
     288                 :          2 :   xredraw();
     289                 :          2 : }
     290                 :            : 
     291                 :            : /* try to deactivate a trap */
     292                 :          0 : void disarm(void)
     293                 :            : {
     294                 :          0 :   int x,y,index=0;
     295                 :            :   pob o;
     296                 :            : 
     297                 :          0 :   clearmsg();
     298                 :          0 :   print1("Disarm -- ");
     299                 :            : 
     300                 :          0 :   index = getdir();
     301                 :            : 
     302         [ #  # ]:          0 :   if (index == ABORT)
     303                 :          0 :     setgamestatus(SKIP_MONSTERS);
     304                 :            :   else {
     305                 :          0 :     x = Dirs[0][index]+Player.x;
     306                 :          0 :     y = Dirs[1][index]+Player.y;
     307                 :            :     
     308         [ #  # ]:          0 :     if (! inbounds(x,y))
     309                 :          0 :       print3("Whoa, off the map...");
     310         [ #  # ]:          0 :     else if (Level->site[x][y].locchar != TRAP)
     311                 :          0 :       print3("You can't see a trap there!");
     312                 :            :     else {
     313         [ #  # ]:          0 :       if (random_range(50+difficulty()*5) < 
     314                 :          0 :           Player.dex*2+Player.level*3+Player.rank[THIEVES]*10) {
     315                 :          0 :         print1("You disarmed the trap!");
     316         [ #  # ]:          0 :         if (random_range(100) < Player.dex+Player.rank[THIEVES]*10) {
     317                 :          0 :           o = ((pob) checkmalloc(sizeof(objtype)));
     318   [ #  #  #  #  :          0 :           switch(Level->site[x][y].p_locf) {
          #  #  #  #  #  
                      # ]
     319                 :            :           case L_TRAP_DART: 
     320                 :          0 :             *o=Objects[OB_TRAP_DART];
     321                 :          0 :             break;
     322                 :            :           case L_TRAP_DISINTEGRATE:
     323                 :          0 :             *o=Objects[OB_TRAP_DISINTEGRATE];
     324                 :          0 :             break;
     325                 :            :           case L_TRAP_SLEEP_GAS:
     326                 :          0 :             *o=Objects[OB_TRAP_SLEEP];
     327                 :          0 :             break;
     328                 :            :           case L_TRAP_TELEPORT:
     329                 :          0 :             *o=Objects[OB_TRAP_TELEPORT];
     330                 :          0 :             break;
     331                 :            :           case L_TRAP_ABYSS:
     332                 :          0 :             *o=Objects[OB_TRAP_ABYSS];
     333                 :          0 :             break;
     334                 :            :           case L_TRAP_FIRE:
     335                 :          0 :             *o=Objects[OB_TRAP_FIRE];
     336                 :          0 :             break;
     337                 :            :           case L_TRAP_SNARE:
     338                 :          0 :             *o=Objects[OB_TRAP_SNARE];
     339                 :          0 :             break;
     340                 :            :           case L_TRAP_ACID:
     341                 :          0 :             *o=Objects[OB_TRAP_ACID];
     342                 :          0 :             break;
     343                 :            :           case L_TRAP_MANADRAIN:
     344                 :          0 :             *o=Objects[OB_TRAP_MANADRAIN];
     345                 :          0 :             break;
     346                 :            :           default:
     347                 :            :             /* DAG can't use free_obj() as object not initialized */
     348                 :          0 :             free(o); 
     349                 :          0 :             o = NULL;
     350                 :          0 :             break;
     351                 :            :           }
     352         [ #  # ]:          0 :           if (o != NULL) {
     353                 :          0 :             print2("You manage to retrieve the trap components!");
     354                 :          0 :             morewait();
     355                 :          0 :             Objects[o->id].known = 1;
     356                 :          0 :             o->known = 1;
     357                 :          0 :             gain_item(o);
     358                 :          0 :             gain_experience(25);
     359                 :            :           }
     360                 :            :         }
     361                 :          0 :         Level->site[x][y].p_locf = L_NO_OP;
     362                 :          0 :         Level->site[x][y].locchar = FLOOR;
     363                 :          0 :         lset(x, y, CHANGED);
     364                 :          0 :         gain_experience(5);
     365                 :            :       }
     366         [ #  # ]:          0 :       else if (random_range(10+difficulty()*2) > Player.dex) {
     367                 :          0 :         print1("You accidentally set off the trap!");
     368                 :          0 :         Player.x = x; Player.y = y;
     369                 :          0 :         p_movefunction(Level->site[x][y].p_locf);
     370                 :            :       }
     371                 :          0 :       else print1("You failed to disarm the trap.");
     372                 :            :     }
     373                 :            :   }
     374                 :          0 : }
     375                 :            : 
     376                 :            : /* is it more blessed to give, or receive? */
     377                 :          1 : void give(void)
     378                 :            : {
     379                 :            :   int index;
     380                 :          1 :   int dx,dy,dindex=0;
     381                 :            :   struct monster *m;
     382                 :            :   pob obj;
     383                 :            : 
     384                 :          1 :   clearmsg();
     385                 :            : 
     386                 :          1 :   print1("Give to monster --");
     387                 :          1 :   dindex = getdir();
     388         [ -  + ]:          1 :   if (dindex == ABORT) 
     389                 :          0 :     setgamestatus(SKIP_MONSTERS);
     390                 :            :   else {
     391                 :          1 :     dx = Dirs[0][dindex];
     392                 :          1 :     dy = Dirs[1][dindex];
     393         [ -  + ]:          1 :     if (! inbounds(Player.x+dx, Player.y+dy))
     394                 :          0 :       print3("Whoa, off the map...");
     395         [ -  + ]:          1 :     else if (Level->site[Player.x+dx][Player.y+dy].creature == NULL) {
     396                 :          0 :       print3("There's nothing there to give something to!!!");
     397                 :          0 :       setgamestatus(SKIP_MONSTERS);
     398                 :            :     }
     399                 :            :     else {
     400                 :          1 :       m = Level->site[Player.x+dx][Player.y+dy].creature;
     401                 :          1 :       clearmsg();
     402                 :          1 :       index = getitem_prompt("Give what? ", CASH);
     403         [ -  + ]:          1 :       if (index == ABORT)
     404                 :          0 :         setgamestatus(SKIP_MONSTERS);
     405         [ +  - ]:          1 :       else if (index == CASHVALUE) give_money(m);
     406         [ #  # ]:          0 :       else if (! cursed(Player.possessions[index])) {
     407                 :          0 :         obj = copy_obj(  Player.possessions[index] );
     408                 :          0 :         obj->used = FALSE;
     409                 :          0 :         conform_lost_objects(1,Player.possessions[index]);
     410                 :          0 :         obj->number = 1;
     411                 :          0 :         print2("Given: ");
     412                 :          0 :         nprint2(itemid(obj));
     413                 :          0 :         morewait();
     414                 :            :         /* WDT bug fix: I moved the print above the givemonster
     415                 :            :          * call.  If that turns out looking ugly, I should change it to
     416                 :            :          * a sprintf or strcat.  At any rate, it was wrong before because
     417                 :            :          * it was accessing an object which had already been freed as part
     418                 :            :          * of givemonster. */
     419                 :          0 :         givemonster(m,obj);
     420                 :          0 :         calc_melee();
     421                 :            :       }
     422                 :            :       else {
     423                 :          0 :         print3("You can't even give away: ");
     424                 :          0 :         nprint3(itemid(Player.possessions[index]));
     425                 :            :       }
     426                 :            :     }
     427                 :            :   }
     428                 :          1 : }
     429                 :            : 
     430                 :            : 
     431                 :            : /* zap a wand, of course */
     432                 :          0 : void zapwand(void)
     433                 :            : {
     434                 :            :   int index;
     435                 :            :   struct object *obj;
     436                 :            : 
     437                 :          0 :   clearmsg();
     438                 :            : 
     439         [ #  # ]:          0 :   if (Player.status[AFRAID] > 0)
     440                 :          0 :     print3("You are so terror-stricken you can't hold a wand straight!");
     441                 :            :   else {
     442                 :          0 :     index = getitem_prompt("Zap -- ", STICK);
     443         [ #  # ]:          0 :     if (index == ABORT)
     444                 :          0 :       setgamestatus(SKIP_MONSTERS);
     445                 :            :     else {
     446                 :          0 :       obj = Player.possessions[index];
     447         [ #  # ]:          0 :       if (obj->objchar != STICK) {
     448                 :          0 :         print3("You can't zap: ");
     449                 :          0 :         nprint3(itemid(obj));
     450                 :            :       }
     451                 :            :       else 
     452         [ #  # ]:          0 :         if (obj->charge < 1) 
     453                 :          0 :           print3("Fizz.... Pflpt. Out of charges. ");
     454                 :            :         else {
     455                 :          0 :           obj->charge--;
     456                 :          0 :           item_use(obj);
     457                 :            :         }
     458                 :            :     }
     459                 :            :   }
     460                 :          0 : }
     461                 :            : 
     462                 :            : /* cast a spell */
     463                 :          0 : void magic(void)
     464                 :            : {
     465                 :            :   int index,drain;
     466                 :          0 :   clearmsg();
     467         [ #  # ]:          0 :   if (Player.status[AFRAID] > 0)
     468                 :          0 :     print3("You are too afraid to concentrate on a spell!");
     469                 :            :   else {
     470                 :          0 :     index = getspell();
     471                 :          0 :     xredraw();
     472         [ #  # ]:          0 :     if (index == ABORT)
     473                 :          0 :       setgamestatus(SKIP_MONSTERS);
     474                 :            :     else {
     475                 :          0 :       drain = Spells[index].powerdrain;
     476         [ #  # ]:          0 :       if (Lunarity == 1) drain = drain / 2;
     477         [ #  # ]:          0 :       else if (Lunarity == -1) drain = drain *2;
     478         [ #  # ]:          0 :       if (drain > Player.mana)
     479 [ #  # ][ #  # ]:          0 :         if (Lunarity == -1 && Player.mana >= drain/2)
     480                 :          0 :           print3("The contrary moon has made that spell too draining! ");
     481                 :            :         else
     482                 :          0 :           print3("You lack the power for that spell! ");
     483                 :            :       else {
     484                 :          0 :         Player.mana -= drain;
     485                 :          0 :         cast_spell(index);
     486                 :            :       }
     487                 :            :     }
     488                 :            :   }
     489                 :          0 :   dataprint();
     490                 :          0 : }
     491                 :            : 
     492                 :            : 
     493                 :            : /* go upstairs ('<' command) */
     494                 :          1 : void upstairs(void)
     495                 :            : {
     496         [ +  - ]:          1 :   if (Level->site[Player.x][Player.y].locchar != STAIRS_UP)
     497                 :          1 :     print3("Not here!");
     498         [ #  # ]:          0 :   else if (Level->site[Player.x][Player.y].p_locf == L_ESCALATOR)
     499                 :          0 :     p_movefunction(Level->site[Player.x][Player.y].p_locf);
     500                 :            :   else {
     501         [ #  # ]:          0 :     if (gamestatusp(MOUNTED))
     502                 :          0 :       print2("You manage to get your horse upstairs.");
     503                 :          0 :     print1("You ascend a level.");
     504         [ #  # ]:          0 :     if (Level->depth <= 1) {
     505         [ #  # ]:          0 :       if (Level->environment == E_SEWERS)
     506                 :          0 :         change_environment(E_CITY);
     507                 :          0 :       else change_environment(E_COUNTRYSIDE);
     508                 :            :     }
     509                 :          0 :     else change_level(Level->depth,Level->depth-1,FALSE);
     510                 :          0 :     roomcheck();
     511                 :            :   }
     512                 :          1 :   setgamestatus(SKIP_MONSTERS);
     513                 :          1 : }
     514                 :            : 
     515                 :            : 
     516                 :            : 
     517                 :            : /* go downstairs ('>' command) */
     518                 :          1 : void downstairs(void)
     519                 :            : {
     520         [ +  - ]:          1 :   if (Level->site[Player.x][Player.y].locchar != STAIRS_DOWN)
     521                 :          1 :     print3("Not here!");
     522 [ #  # ][ #  # ]:          0 :   else if (Level->site[Player.x][Player.y].p_locf == L_ENTER_CIRCLE ||
     523                 :          0 :     Level->site[Player.x][Player.y].p_locf == L_ENTER_COURT)
     524                 :          0 :     p_movefunction(Level->site[Player.x][Player.y].p_locf);
     525                 :            :   else {
     526         [ #  # ]:          0 :     if (gamestatusp(MOUNTED))
     527                 :          0 :       print2("You manage to get your horse downstairs.");
     528         [ #  # ]:          0 :     if (Current_Environment == Current_Dungeon) {
     529                 :          0 :       print1("You descend a level.");
     530                 :          0 :       change_level(Level->depth,Level->depth+1,FALSE);
     531                 :          0 :       roomcheck();
     532                 :            :     }
     533 [ #  # ][ #  # ]:          0 :     else if ((Current_Environment == E_CITY) ||
     534                 :          0 :              (Last_Environment == E_CITY))
     535                 :          0 :       change_environment(E_SEWERS);
     536         [ #  # ]:          0 :     else if (Current_Environment != Current_Dungeon)
     537                 :          0 :       print3("This stairway is deviant. You can't use it.");
     538                 :            :   }
     539                 :          1 :   setgamestatus(SKIP_MONSTERS);
     540                 :          1 : }
     541                 :            : 
     542                 :            : 
     543                 :            : 
     544                 :            : 
     545                 :            : /* set various player options */
     546                 :            : /* have to redefine in odefs for next full recompile */
     547                 :          1 : void setoptions(void)
     548                 :            : {
     549                 :          1 :   int slot = 1,to,done = FALSE;
     550                 :            :   int response;
     551                 :            : 
     552                 :          1 :   clearmsg();
     553                 :          1 :   menuclear();
     554                 :            : 
     555                 :          1 :   display_options();
     556                 :            : 
     557                 :          1 :   move_slot(1,1,NUMOPTIONS);
     558                 :          1 :   clearmsg();
     559                 :          1 :   print1("Currently selected option is preceded by highlit >>");
     560                 :          1 :   print2("Move selected option with '>' and '<', ESCAPE to quit.");
     561                 :            :   do {
     562                 :          2 :     response = mcigetc();
     563   [ -  -  -  -  :          2 :     switch(response) {
          -  -  -  -  -  
                   +  + ]
     564                 :            :     case 'j':
     565                 :            :     case '>':
     566                 :            : #ifdef KEY_DOWN
     567                 :            :     case KEY_DOWN:
     568                 :            : #endif
     569                 :          0 :       to = slot + 1;
     570                 :            : #ifndef COMPRESS_SAVE_FILES
     571         [ #  # ]:          0 :       if (to == 8)      /* COMPRESS_OPTION */
     572                 :          0 :         to = 9;
     573                 :            : #endif
     574                 :          0 :       slot = move_slot(slot,to,NUMOPTIONS+1);
     575                 :          0 :       break;
     576                 :            :     case 'k':
     577                 :            :     case '<':
     578                 :            : #ifdef KEY_UP
     579                 :            :     case KEY_UP:
     580                 :            : #endif
     581                 :          0 :       to = slot - 1;
     582                 :            : #ifndef COMPRESS_SAVE_FILES
     583         [ #  # ]:          0 :       if (to == 8)      /* COMPRESS_OPTION */
     584                 :          0 :         to = 7;
     585                 :            : #endif
     586         [ #  # ]:          0 :       if (to > 0)
     587                 :          0 :         slot = move_slot(slot,to,NUMOPTIONS+1); 
     588                 :          0 :       break;
     589                 :            : #ifdef KEY_HOME
     590                 :            :     case KEY_HOME:
     591                 :          0 :       slot = move_slot(slot,1,NUMOPTIONS+1);
     592                 :          0 :       break;
     593                 :            : #endif
     594                 :            : #ifdef KEY_LL
     595                 :            :     case KEY_LL:
     596                 :          0 :       slot = move_slot(slot,NUMOPTIONS,NUMOPTIONS+1);
     597                 :          0 :       break;
     598                 :            : #endif
     599                 :            :     case 't':
     600         [ #  # ]:          0 :       if (slot <= NUMTFOPTIONS) 
     601                 :          0 :         optionset(pow2(slot-1));
     602         [ #  # ]:          0 :       else if (slot == VERBOSITY_LEVEL)
     603                 :          0 :         Verbosity = TERSE;
     604                 :          0 :       else print3("'T' is meaningless for this option.");
     605                 :          0 :       break;
     606                 :            :     case 'f':
     607         [ #  # ]:          0 :       if (slot <= NUMTFOPTIONS) 
     608                 :          0 :         optionreset(pow2(slot-1));
     609                 :          0 :       else print3("'F' is meaningless for this option.");
     610                 :          0 :       break;
     611                 :            :     case 'm':
     612         [ #  # ]:          0 :       if (slot == VERBOSITY_LEVEL) 
     613                 :          0 :         Verbosity = MEDIUM;
     614                 :          0 :       else print3("'M' is meaningless for this option.");
     615                 :          0 :       break;
     616                 :            :     case 'v':
     617         [ #  # ]:          0 :       if (slot == VERBOSITY_LEVEL) 
     618                 :          0 :         Verbosity = VERBOSE;
     619                 :          0 :       else print3("'V' is meaningless for this option.");
     620                 :          0 :       break;
     621                 :            :     case '1':case '2':case '3':case '4':case '5':
     622                 :            :     case '6':case '7':case '8':case'9':
     623         [ #  # ]:          0 :       if (slot == SEARCH_DURATION)
     624                 :          0 :         Searchnum = response - '0';
     625                 :          0 :       else print3("A number is meaningless for this option.");
     626                 :          0 :       break;
     627                 :            :     case ESCAPE:
     628                 :          1 :       done = TRUE;
     629                 :          1 :       break;
     630                 :          1 :     default: print3("That response is meaningless for this option."); break;
     631                 :            :     }
     632                 :          2 :     display_option_slot(slot);
     633                 :          2 :     move_slot(slot,slot,NUMOPTIONS+1);
     634         [ +  + ]:          2 :   } while (! done);
     635         [ +  - ]:          1 :   if (optionp(SHOW_COLOUR))
     636                 :          1 :     colour_on();
     637                 :            :   else
     638                 :          0 :     colour_off();
     639                 :            : #if !defined(MSDOS_SUPPORTED_ANTIQUE) && !defined(AMIGA)
     640                 :          1 :   xredraw();
     641                 :            : #endif
     642                 :          1 : }
     643                 :            : 
     644                 :            : 
     645                 :            : 
     646                 :            : /* name an item */
     647                 :          0 : void callitem(void)
     648                 :            : {
     649                 :            :   int index;
     650                 :            :   pob obj;
     651                 :            : 
     652                 :          0 :   clearmsg();
     653                 :          0 :   setgamestatus(SKIP_MONSTERS);
     654                 :          0 :   index = getitem_prompt("Call -- ", NULL_ITEM);
     655         [ #  # ]:          0 :   if (index == CASHVALUE) print3("Can't rename cash!");
     656         [ #  # ]:          0 :   else if (index != ABORT) {
     657                 :          0 :     obj = Player.possessions[index];
     658         [ #  # ]:          0 :     if (obj->known)
     659                 :          0 :       print3("That item is already identified!");
     660                 :            :     else {
     661                 :          0 :       print1("Call it:");
     662                 :          0 :       obj->objstr = salloc(msgscanstring());
     663                 :          0 :       clearmsg();
     664                 :          0 :       print2("Also call all similar items by that name? [yn] ");
     665         [ #  # ]:          0 :       if (ynq2() == 'y') {
     666                 :          0 :         Objects[obj->id].objstr = obj->objstr;
     667                 :            :       }
     668                 :            :     }
     669                 :            :   }
     670                 :          0 : }
     671                 :            : 
     672                 :            : 
     673                 :            : /* open a door */
     674                 :          0 : void opendoor(void)
     675                 :            : {
     676                 :            :   int dir;
     677                 :            :   int ox,oy;
     678                 :            : 
     679                 :          0 :   clearmsg();
     680                 :          0 :   print1("Open --");
     681                 :          0 :   dir = getdir();
     682         [ #  # ]:          0 :   if (dir == ABORT)
     683                 :          0 :     setgamestatus(SKIP_MONSTERS);
     684                 :            :   else {
     685                 :          0 :     ox = Player.x + Dirs[0][dir];
     686                 :          0 :     oy = Player.y + Dirs[1][dir];
     687         [ #  # ]:          0 :     if (Level->site[ox][oy].locchar == OPEN_DOOR) {
     688                 :          0 :       print3("That door is already open!");
     689                 :          0 :       setgamestatus(SKIP_MONSTERS);
     690                 :            :     }
     691         [ #  # ]:          0 :     else if (Level->site[ox][oy].locchar == PORTCULLIS) {
     692                 :          0 :       print1("You try to lift the massive steel portcullis....");
     693         [ #  # ]:          0 :       if (random_range(100) < Player.str) {
     694                 :          0 :         print2("Incredible. You bust a gut and lift the portcullis.");
     695                 :          0 :         Level->site[ox][oy].locchar = FLOOR;
     696                 :          0 :         lset(ox, oy, CHANGED);
     697                 :            :       }
     698                 :            :       else {
     699                 :          0 :         print2("Argh. You ruptured yourself.");
     700                 :          0 :         p_damage(Player.str,UNSTOPPABLE,"a portcullis");
     701                 :            :       }
     702                 :            :     }
     703 [ #  # ][ #  # ]:          0 :     else if ((Level->site[ox][oy].locchar != CLOSED_DOOR) || 
     704                 :          0 :              loc_statusp(ox,oy,SECRET)) {
     705                 :          0 :       print3("You can't open that!");
     706                 :          0 :       setgamestatus(SKIP_MONSTERS);
     707                 :            :     }
     708         [ #  # ]:          0 :     else if (Level->site[ox][oy].aux == LOCKED) 
     709                 :          0 :       print3("That door seems to be locked.");
     710                 :            :     else {
     711                 :          0 :       Level->site[ox][oy].locchar = OPEN_DOOR;
     712                 :          0 :       lset(ox, oy, CHANGED);
     713                 :            :     }
     714                 :            :   }
     715                 :          0 : }
     716                 :            : 
     717                 :            : 
     718                 :            : /* Try to destroy some location */
     719                 :          0 : void bash_location(void)
     720                 :            : {
     721                 :            :   int dir;
     722                 :            :   int ox,oy;
     723                 :            : 
     724                 :          0 :   clearmsg();
     725                 :          0 :   print1("Bashing --");
     726                 :          0 :   dir = getdir();
     727         [ #  # ]:          0 :   if (dir == ABORT)
     728                 :          0 :     setgamestatus(SKIP_MONSTERS);
     729                 :            :   else {
     730                 :          0 :     ox = Player.x + Dirs[0][dir];
     731                 :          0 :     oy = Player.y + Dirs[1][dir];
     732 [ #  # ][ #  # ]:          0 :     if ((Current_Environment == E_CITY) &&
     733         [ #  # ]:          0 :         (ox == 0) &&
     734                 :            :         (oy == 0)) {
     735                 :          0 :       print1("Back Door WIZARD Mode!");
     736                 :          0 :       print2("You will invalidate your score if you proceed.");
     737                 :          0 :       morewait();
     738         [ #  # ]:          0 :       if (cinema_confirm("You are about to enable WIZARD Mode.")=='y') {
     739                 :          0 :         print2("You feel like a cheater.");
     740                 :          0 :         setgamestatus(CHEATED);
     741                 :            :       }
     742                 :          0 :       else print2("A sudden tension goes out of the air....");
     743                 :            :     }
     744                 :            :     else {
     745         [ #  # ]:          0 :       if (Level->site[ox][oy].locchar == WALL) {
     746                 :          0 :         print1("You hurl yourself at the wall!");
     747                 :          0 :         p_damage(Player.str,NORMAL_DAMAGE,"a suicidal urge");
     748                 :            :       }
     749         [ #  # ]:          0 :       else if (Level->site[ox][oy].locchar == OPEN_DOOR) {
     750                 :          0 :         print1("You hurl yourself through the open door!");
     751                 :          0 :         print2("Yaaaaah! ... thud.");
     752                 :          0 :         morewait();
     753                 :          0 :         Player.x = ox;
     754                 :          0 :         Player.y = oy;
     755                 :          0 :         p_damage(3,UNSTOPPABLE,"silliness");
     756                 :          0 :         p_movefunction(Level->site[Player.x][Player.y].p_locf);
     757                 :          0 :         setgamestatus(SKIP_MONSTERS); /* monsters are surprised... */
     758                 :            :       }
     759         [ #  # ]:          0 :       else if (Level->site[ox][oy].locchar == CLOSED_DOOR) {
     760         [ #  # ]:          0 :         if (loc_statusp(ox,oy,SECRET)) {
     761                 :          0 :           print1("You found a secret door!");
     762                 :          0 :           lreset(ox,oy,SECRET);
     763                 :          0 :           lset(ox, oy, CHANGED);
     764                 :            :         }
     765         [ #  # ]:          0 :         if (Level->site[ox][oy].aux == LOCKED) {
     766         [ #  # ]:          0 :           if (random_range(50+difficulty()*10) < Player.str) {
     767                 :          0 :             Player.x = ox;
     768                 :          0 :             Player.y = oy;
     769                 :          0 :             print2("You blast the door off its hinges!");
     770                 :          0 :             Level->site[ox][oy].locchar = FLOOR;
     771                 :          0 :             lset(ox, oy, CHANGED);
     772                 :          0 :             p_movefunction(Level->site[Player.x][Player.y].p_locf);
     773                 :          0 :             setgamestatus(SKIP_MONSTERS); /* monsters are surprised... */
     774                 :            :           }
     775                 :            :           else {
     776                 :          0 :             print1("Crash! The door holds.");
     777         [ #  # ]:          0 :             if (random_range(30) > Player.str)
     778         [ #  # ]:          0 :               p_damage(max(1,statmod(Player.str)),UNSTOPPABLE,"a door");
     779                 :            :           }
     780                 :            :         }
     781                 :            :         else {
     782                 :          0 :           Player.x = ox;
     783                 :          0 :           Player.y = oy;
     784                 :          0 :           print2("You bash open the door!");
     785         [ #  # ]:          0 :           if (random_range(30) > Player.str)
     786                 :          0 :             p_damage(1,UNSTOPPABLE,"a door");
     787                 :          0 :           Level->site[ox][oy].locchar = OPEN_DOOR;
     788                 :          0 :           lset(ox, oy, CHANGED);
     789                 :          0 :           p_movefunction(Level->site[Player.x][Player.y].p_locf);
     790                 :          0 :           setgamestatus(SKIP_MONSTERS); /* monsters are surprised... */
     791                 :            :         }
     792                 :            :       }
     793         [ #  # ]:          0 :       else if (Level->site[ox][oy].locchar == STATUE) {
     794                 :          0 :         statue_random(ox,oy);
     795                 :            :       }
     796         [ #  # ]:          0 :       else if (Level->site[ox][oy].locchar == PORTCULLIS) {
     797                 :          0 :         print1("Really, you don't have a prayer.");
     798         [ #  # ]:          0 :         if (random_range(1000) < Player.str) {
     799                 :          0 :           print2("The portcullis flies backwards into a thousand fragments.");
     800                 :          0 :           print3("Wow. What a stud.");
     801                 :          0 :           gain_experience(100);
     802                 :          0 :           Level->site[ox][oy].locchar = FLOOR;
     803                 :          0 :           Level->site[ox][oy].p_locf = L_NO_OP;
     804                 :          0 :           lset(ox, oy, CHANGED);
     805                 :            :         }
     806                 :            :         else {
     807                 :          0 :           print2("You only hurt yourself on the 3'' thick steel bars.");
     808                 :          0 :           p_damage(Player.str,UNSTOPPABLE,"a portcullis");
     809                 :            :         }
     810                 :            :       }
     811         [ #  # ]:          0 :       else if (Level->site[ox][oy].locchar == ALTAR) {
     812 [ #  # ][ #  # ]:          0 :         if ((Player.patron > 0)&&(Level->site[ox][oy].aux == Player.patron)) {
     813                 :          0 :           print1("You have a vision! An awesome angel hovers over the altar.");
     814                 :          0 :           print2("The angel says: 'You twit, don't bash your own altar!'");
     815                 :          0 :           print3("The angel slaps you upside the head for your presumption.");
     816                 :          0 :           p_damage(Player.hp-1,UNSTOPPABLE,"an annoyed angel");
     817                 :            :         }
     818         [ #  # ]:          0 :         else if (Level->site[ox][oy].aux == 0) {
     819                 :          0 :           print1("The feeble powers of the minor godling are not enough to");
     820                 :          0 :           print2("protect his altar! The altar crumbles away to dust.");
     821                 :          0 :           print3("You feel almost unbearably smug.");
     822                 :          0 :           Level->site[ox][oy].locchar = RUBBLE;
     823                 :          0 :           Level->site[ox][oy].p_locf = L_RUBBLE;
     824                 :          0 :           lset(ox, oy, CHANGED);
     825                 :          0 :           gain_experience(5);
     826                 :            :         }
     827                 :            :         else {
     828                 :          0 :           print1("You have successfully annoyed a major deity. Good job.");
     829                 :          0 :           print2("Zzzzap! A bolt of godsfire strikes!");
     830         [ #  # ]:          0 :           if (Player.rank[PRIESTHOOD] > 0) 
     831                 :          0 :             print3("Your own deity's aegis defends you from the bolt!");
     832                 :          0 :           p_damage(max(0,random_range(100)-Player.rank[PRIESTHOOD]*20),
     833                 :            :                    UNSTOPPABLE,
     834                 :            :                    "a bolt of godsfire");
     835         [ #  # ]:          0 :           if (Player.rank[PRIESTHOOD]*20+Player.pow+Player.level >
     836                 :          0 :               random_range(200)) {
     837                 :          0 :             morewait();
     838                 :          0 :             print1("The altar crumbles...");
     839                 :          0 :             Level->site[ox][oy].locchar = RUBBLE;
     840                 :          0 :             Level->site[ox][oy].p_locf = L_RUBBLE;
     841                 :          0 :             lset(ox, oy, CHANGED);
     842                 :          0 :             morewait();
     843         [ #  # ]:          0 :             if (Player.rank[PRIESTHOOD]) {
     844                 :          0 :               print2("You sense your deity's pleasure with you.");
     845                 :          0 :               morewait();
     846                 :          0 :               print3("You are surrounded by a golden glow.");
     847                 :          0 :               cleanse(1);
     848                 :          0 :               heal(10);
     849                 :            :             }
     850                 :          0 :             gain_experience(500);
     851                 :            :           }
     852                 :            :         }
     853                 :            :       }
     854                 :            :       else {
     855                 :          0 :         print3("You restrain yourself from total silliness.");
     856                 :          0 :         setgamestatus(SKIP_MONSTERS);
     857                 :            :       }
     858                 :            :     }
     859                 :            :   }
     860                 :          0 : }
     861                 :            : 
     862                 :            : 
     863                 :            : /* attempt destroy an item */
     864                 :          0 : void bash_item(void)
     865                 :            : {
     866                 :            :   int item;
     867                 :            :   pob obj;
     868                 :            : 
     869                 :          0 :   clearmsg();
     870                 :          0 :   item = getitem_prompt("Destroy an item -- ", NULL_ITEM);
     871         [ #  # ]:          0 :   if (item == ABORT) 
     872                 :          0 :      setgamestatus(SKIP_MONSTERS);
     873         [ #  # ]:          0 :   else if (item == CASHVALUE) 
     874                 :            :   {
     875                 :          0 :      print3("You can't destroy cash!");
     876                 :          0 :      setgamestatus(SKIP_MONSTERS);
     877                 :            :   }
     878                 :            :   else
     879                 :            :   {
     880                 :          0 :     obj = Player.possessions[item];
     881         [ #  # ]:          0 :     if (Player.str+random_range(20) > obj->fragility+random_range(20)) {
     882                 :            :       /* damage_item() can free object, but need these after... */ 
     883                 :            :       int oid;
     884                 :            :       unsigned char olevel;
     885                 :          0 :       olevel = obj->level;
     886                 :          0 :       oid = obj->id;
     887         [ #  # ]:          0 :       if ( damage_item(obj) )
     888                 :            :       {
     889         [ #  # ]:          0 :         if ( OB_POTION_CHAOS == oid )
     890                 :            :         {
     891                 :          0 :           Player.alignment += random_range(10);
     892         [ #  # ]:          0 :           if ( Player.alignment < 0 )
     893                 :            :           {
     894                 :          0 :             print2("You feel a sense of inner constraint!");
     895                 :          0 :             gain_experience(olevel * olevel * 5);
     896                 :            :           } 
     897                 :            :           else
     898                 :          0 :             print2("You feel wonderfully lawful!");
     899                 :            :           
     900                 :            :           /* In either case, chaotic or lawful, destroying a PoCh is
     901                 :            :            * lawful. */
     902                 :          0 :           Player.alignment += random_range(10);
     903                 :            :         } 
     904         [ #  # ]:          0 :         else if ( OB_SCROLL_LAW == oid )
     905                 :            :         {
     906                 :          0 :           Player.alignment -= random_range(10);
     907         [ #  # ]:          0 :           if ( Player.alignment < 0 )
     908                 :            :           {
     909                 :          0 :             print2("You feel deliciously chaotic!");
     910                 :          0 :             gain_experience(olevel * olevel * 5);
     911                 :            :           } 
     912                 :            :           else
     913                 :          0 :             print2("You feel a sense of inner turmoil!");
     914                 :          0 :           Player.alignment -= random_range(10);
     915                 :            :         }
     916         [ #  # ]:          0 :         else if (Player.alignment < 0) 
     917                 :            :         {
     918                 :          0 :           print2("That was fun....");
     919                 :          0 :           gain_experience(olevel * olevel * 5);
     920                 :            :         }
     921                 :            :       } 
     922                 :            :     }
     923                 :            :     else {
     924         [ #  # ]:          0 :       if (obj->objchar == WEAPON) {
     925                 :          0 :         print2("The weapon turned in your hand -- you hit yourself!");
     926                 :          0 :         p_damage(random_range(obj->dmg+abs(obj->plus)),
     927                 :            :                  NORMAL_DAMAGE,
     928                 :            :                  "a failure at vandalism");
     929                 :            :       }
     930         [ #  # ]:          0 :       else if (obj->objchar == ARTIFACT) {
     931                 :          0 :         print2("Uh Oh -- Now you've gotten it angry....");
     932                 :          0 :         p_damage(obj->level*10,
     933                 :            :                  UNSTOPPABLE,
     934                 :            :                  "an enraged artifact");
     935                 :            :       }
     936                 :            :       else {
     937                 :          0 :         print2("Ouch! Damn thing refuses to break...");
     938                 :          0 :         p_damage(1,UNSTOPPABLE,"a failure at vandalism");
     939                 :            :       }
     940                 :            :     }
     941                 :            :   }
     942                 :          0 : }
     943                 :            : 
     944                 :            : 
     945                 :            : /* guess what this does */
     946                 :            : /* if force is true, exiting due to some problem - don't bomb out */
     947                 :          1 : void save(int compress, int force)
     948                 :            : {
     949                 :            :   char fname[100];
     950                 :          1 :   int pos, ok = TRUE;
     951                 :            : 
     952                 :          1 :   clearmsg();
     953         [ -  + ]:          1 :   if (gamestatusp(ARENA_MODE)) {
     954         [ #  # ]:          0 :     if (force) {
     955                 :          0 :       resetgamestatus(ARENA_MODE);
     956                 :          0 :       change_environment(E_CITY);
     957                 :            :     }
     958                 :            :     else {
     959                 :          0 :       print3("Can't save the game in the arena!");
     960                 :          0 :       setgamestatus(SKIP_MONSTERS);
     961                 :          0 :       ok = FALSE;
     962                 :            :     }
     963                 :            :   }
     964         [ -  + ]:          1 :   else if (Current_Environment == E_ABYSS) {
     965         [ #  # ]:          0 :     if (force)
     966                 :          0 :       change_environment(E_COUNTRYSIDE);
     967                 :            :     else {
     968                 :          0 :       print3("Can't save the game in the Adept's Challenge!");
     969                 :          0 :       setgamestatus(SKIP_MONSTERS);
     970                 :          0 :       ok = FALSE;
     971                 :            :     }
     972                 :            :   }
     973         [ -  + ]:          1 :   else if (Current_Environment == E_TACTICAL_MAP) {
     974         [ #  # ]:          0 :     if (force)
     975                 :          0 :       change_environment(E_COUNTRYSIDE);
     976                 :            :     else {
     977                 :            :       /* WDT MARK!  I understand this, but it's wrong. */
     978                 :          0 :       print3("Can't save the game in the tactical map!");
     979                 :          0 :       setgamestatus(SKIP_MONSTERS);
     980                 :          0 :       ok = FALSE;
     981                 :            :     }
     982                 :            :   }
     983 [ +  - ][ +  - ]:          1 :   if (!force && ok) {
     984                 :          1 :     ok = (cinema_confirm("You're about to save and exit.") == 'y');
     985                 :            :   }
     986 [ +  - ][ +  - ]:          1 :   if (force || ok) {
     987                 :          1 :     sprintf(Str1, "Enter savefile name [default %s]: ", SaveFileName );
     988                 :          1 :     print1(Str1);
     989                 :          1 :     strcpy(fname,msgscanstring());
     990         [ -  + ]:          1 :     if (fname[0] == '\0') {
     991                 :            :       /* no file name entered, use default.  DAG */
     992                 :          0 :       strcpy( fname, SaveFileName );
     993                 :            :     }
     994                 :            : #ifdef MSDOS
     995                 :            :     for (pos = 0; fname[pos] && isalnum(fname[pos]); pos++)
     996                 :            :       ;
     997                 :            : #else
     998 [ +  + ][ +  - ]:          7 :     for (pos = 0; fname[pos] && isprint(fname[pos]) && !isspace(fname[pos]);
                 [ +  - ]
     999                 :          6 :       pos++)
    1000                 :            :       ;
    1001                 :            : #endif
    1002         [ -  + ]:          1 :     if (fname[pos]) {
    1003                 :          0 :       sprintf(Str1, "Illegal character '%c' in filename - Save aborted.", fname[pos]);
    1004                 :          0 :       print1(Str1);
    1005                 :          0 :       ok = FALSE;
    1006                 :            :     }
    1007                 :            : #ifdef MSDOS
    1008                 :            :     if (strlen(fname) > FNAME_MAX_LEN)
    1009                 :            :     {
    1010                 :            :       /* WDT -- copied from SYSV block below. */
    1011                 :            :       sprintf(Str1, "Save name longer than %d characters - Save aborted.",
    1012                 :            :         FNAME_MAX_LEN);
    1013                 :            :       print1(Str1);
    1014                 :            :       ok = FALSE;
    1015                 :            :     }
    1016                 :            : #else
    1017                 :            : # ifdef SYSV
    1018                 :            :     if (strlen(fname) > FNAME_MAX_LEN - EXT_LENGTH - 1)
    1019                 :            :     {
    1020                 :            :       sprintf(Str1, "Save name longer than %d characters - Save aborted.",
    1021                 :            :         FNAME_MAX_LEN - EXT_LENGTH - 1);
    1022                 :            :       print1(Str1);
    1023                 :            :       ok = FALSE;
    1024                 :            :     }
    1025                 :            : # endif
    1026                 :            : #endif
    1027         [ +  - ]:          1 :     if (ok) {
    1028         [ +  - ]:          1 :       if (save_game(compress,fname)) {
    1029                 :          1 :         endgraf();
    1030                 :          1 :         printf("Bye!\n");
    1031                 :          1 :         exit(0);
    1032                 :            :       }
    1033                 :            :       else
    1034                 :          0 :         print1("Internal error -- unable to save.");
    1035                 :            :     }
    1036                 :            :   }
    1037         [ #  # ]:          0 :   if (force) {
    1038                 :          0 :     morewait();
    1039                 :          0 :     clearmsg();
    1040                 :          0 :     print1("The game is quitting - you will lose your character.");
    1041                 :          0 :     print2("Try to save again? ");
    1042         [ #  # ]:          0 :     if (ynq2() == 'y')
    1043                 :          0 :       save(compress, force);
    1044                 :            :   }
    1045                 :          0 :   setgamestatus(SKIP_MONSTERS); /* if we get here, we failed to save */
    1046                 :          0 : }
    1047                 :            : 
    1048                 :            : /* close a door */
    1049                 :          0 : void closedoor(void)
    1050                 :            : {
    1051                 :            :   int dir;
    1052                 :            :   int ox,oy;
    1053                 :            : 
    1054                 :          0 :   clearmsg();
    1055                 :            : 
    1056                 :          0 :   print1("Close --");
    1057                 :          0 :   dir = getdir();
    1058         [ #  # ]:          0 :   if (dir == ABORT)
    1059                 :          0 :     setgamestatus(SKIP_MONSTERS);
    1060                 :            :   else {
    1061                 :          0 :     ox = Player.x + Dirs[0][dir];
    1062                 :          0 :     oy = Player.y + Dirs[1][dir];
    1063         [ #  # ]:          0 :     if (Level->site[ox][oy].locchar == CLOSED_DOOR) {
    1064                 :          0 :       print3("That door is already closed!");
    1065                 :          0 :       setgamestatus(SKIP_MONSTERS);
    1066                 :            :     }
    1067         [ #  # ]:          0 :     else if (Level->site[ox][oy].locchar != OPEN_DOOR) {
    1068                 :          0 :       print3("You can't close that!");
    1069                 :          0 :       setgamestatus(SKIP_MONSTERS);
    1070                 :            :     }
    1071                 :          0 :     else Level->site[ox][oy].locchar = CLOSED_DOOR;
    1072                 :          0 :     lset(ox, oy, CHANGED);
    1073                 :            :   }
    1074                 :          0 : }
    1075                 :            : 
    1076                 :            : /* handle a h,j,k,l, etc. */
    1077                 :        348 : void moveplayer(int dx, int dy)
    1078                 :            : {
    1079         [ +  + ]:        348 :   if (p_moveable(Player.x+dx,Player.y+dy)) {
    1080                 :            :       
    1081         [ -  + ]:        329 :     if (Player.status[IMMOBILE] > 0) {
    1082                 :          0 :       resetgamestatus(FAST_MOVE);
    1083                 :          0 :       print3("You are unable to move");
    1084                 :            :     }
    1085   [ -  +  #  # ]:        329 :     else if ((Player.maxweight < Player.itemweight) && 
    1086         [ #  # ]:          0 :              random_range(2) &&
    1087                 :          0 :              (! Player.status[LEVITATING])) {
    1088         [ #  # ]:          0 :       if (gamestatusp(MOUNTED)) {
    1089                 :          0 :         print1("Your horse refuses to carry you and your pack another step!");
    1090                 :          0 :         print2("Your steed bucks wildly and throws you off!");
    1091                 :          0 :         p_damage(10,UNSTOPPABLE,"a cruelly abused horse");
    1092                 :          0 :         resetgamestatus(MOUNTED);
    1093                 :          0 :         summon(-1,HORSE);
    1094                 :            :       }
    1095                 :            :       else {
    1096                 :          0 :         p_damage(1,UNSTOPPABLE,"a rupture");
    1097                 :          0 :         print3("The weight of your pack drags you down. You can't move.");
    1098                 :            :       }
    1099                 :            :     }
    1100                 :            :     else {
    1101                 :        329 :       Player.x += dx;
    1102                 :        329 :       Player.y += dy;
    1103                 :        329 :       p_movefunction(Level->site[Player.x][Player.y].p_locf);
    1104                 :            :       
    1105                 :            :       /* causes moves to take effectively 30 seconds in town without
    1106                 :            :          monsters being sped up compared to player */
    1107 [ +  + ][ +  + ]:        329 :       if ((Current_Environment == E_CITY) ||
    1108                 :        168 :           (Current_Environment == E_VILLAGE)) {
    1109                 :        165 :         twiddle = ! twiddle;
    1110         [ +  + ]:        165 :         if (twiddle) {
    1111                 :         83 :           Time++;
    1112         [ +  + ]:         83 :           if (Time % 10 == 0) tenminute_check();
    1113                 :         74 :           else minute_status_check();
    1114                 :            :         }
    1115                 :            :       }
    1116                 :            : 
    1117                 :            :       /* this test protects against player entering countryside and still
    1118                 :            :       having effects from being on the Level, a kluge, but hey,... */
    1119                 :            : 
    1120         [ +  + ]:        329 :       if (Current_Environment != E_COUNTRYSIDE) {
    1121         [ -  + ]:        326 :         if (gamestatusp(FAST_MOVE))
    1122 [ #  # ][ #  # ]:          0 :           if ((Level->site[Player.x][Player.y].things != NULL) ||
    1123         [ #  # ]:          0 :               (optionp(RUNSTOP) && 
    1124                 :          0 :                loc_statusp(Player.x,Player.y,STOPS)))
    1125                 :          0 :             resetgamestatus(FAST_MOVE);
    1126 [ +  + ][ -  + ]:        326 :         if ((Level->site[Player.x][Player.y].things != NULL) &&
    1127                 :          2 :             (optionp(PICKUP)))
    1128                 :        329 :           pickup();
    1129                 :            :       }
    1130                 :            :     }
    1131                 :            :   }
    1132         [ -  + ]:         19 :   else if (gamestatusp(FAST_MOVE)) {
    1133                 :          0 :     drawvision(Player.x,Player.y);
    1134                 :          0 :     resetgamestatus(FAST_MOVE);
    1135                 :            :   }
    1136                 :        348 : }
    1137                 :            : 
    1138                 :            : 
    1139                 :            : /* handle a h,j,k,l, etc. */
    1140                 :         32 : void movepincountry(int dx, int dy)
    1141                 :            : {
    1142                 :         32 :   int i,takestime = TRUE;
    1143   [ -  +  #  # ]:         32 :   if ((Player.maxweight < Player.itemweight) && 
    1144         [ #  # ]:          0 :       random_range(2) &&
    1145                 :          0 :       (! Player.status[LEVITATING])) {
    1146         [ #  # ]:          0 :     if (gamestatusp(MOUNTED)) {
    1147                 :          0 :       print1("Your horse refuses to carry you and your pack another step!");
    1148                 :          0 :       print2("Your steed bucks wildly and throws you off!");
    1149                 :          0 :       p_damage(10,UNSTOPPABLE,"a cruelly abused horse");
    1150                 :          0 :       resetgamestatus(MOUNTED);
    1151                 :          0 :       morewait();
    1152                 :          0 :       print1("With a shrill neigh of defiance, your former steed gallops");
    1153                 :          0 :       print2("off into the middle distance....");
    1154         [ #  # ]:          0 :       if (Player.packptr != 0) {
    1155                 :          0 :         morewait();
    1156                 :          0 :         print1("You remember (too late) that the contents of your pack");
    1157                 :          0 :         print2("were kept in your steed's saddlebags!");
    1158         [ #  # ]:          0 :         for(i=0;i<MAXPACK;i++) {
    1159         [ #  # ]:          0 :           if (Player.pack[i] != NULL)
    1160                 :          0 :             free_obj( Player.pack[i], TRUE );
    1161                 :          0 :           Player.pack[i] = NULL;
    1162                 :            :         }
    1163                 :          0 :         Player.packptr = 0;
    1164                 :          0 :         calc_melee();
    1165                 :            :       }
    1166                 :            :     }
    1167                 :            :     else {
    1168                 :          0 :       p_damage(1,UNSTOPPABLE,"a rupture");
    1169                 :          0 :       print3("The weight of your pack drags you down. You can't move.");
    1170                 :            :     }
    1171                 :            :   }
    1172                 :            :   else {
    1173         [ -  + ]:         32 :     if (gamestatusp(LOST)) {
    1174                 :          0 :       print3("Being lost, you strike out randomly....");
    1175                 :          0 :       morewait();
    1176                 :          0 :       dx = random_range(3)-1;
    1177                 :          0 :       dy = random_range(3)-1;
    1178                 :            :     }
    1179         [ +  + ]:         32 :     if (p_country_moveable(Player.x+dx,Player.y+dy)) {
    1180         [ -  + ]:         31 :       if (Player.status[IMMOBILE] > 0) 
    1181                 :          0 :         print3("You are unable to move");
    1182                 :            :       else {
    1183                 :         31 :         Player.x += dx;
    1184                 :         31 :         Player.y += dy;
    1185 [ -  + ][ #  # ]:         31 :         if ((! gamestatusp(MOUNTED))&&(Player.possessions[O_BOOTS] != NULL)) {
    1186         [ #  # ]:          0 :           if (Player.possessions[O_BOOTS]->usef == I_BOOTS_7LEAGUE) {
    1187                 :          0 :             takestime = FALSE;
    1188         [ #  # ]:          0 :             if (Player.possessions[O_BOOTS]->blessing < 0) {
    1189                 :          0 :               print1("Whooah! -- Your boots launch you into the sky....");
    1190                 :          0 :               print2("You come down in a strange location....");
    1191                 :          0 :               setPlayerXY( random_range(COUNTRY_WIDTH), random_range(COUNTRY_LENGTH));      
    1192                 :          0 :               morewait();
    1193                 :          0 :               clearmsg();
    1194                 :          0 :               print1("Your boots disintegrate with a malicious giggle...");
    1195                 :          0 :               dispose_lost_objects(1,Player.possessions[O_BOOTS]);
    1196                 :            :             }
    1197         [ #  # ]:          0 :             else if (Player.possessions[O_BOOTS]->known != 2) {
    1198                 :          0 :               print1("Wow! Your boots take you 7 leagues in a single stride!");
    1199                 :          0 :               Player.possessions[O_BOOTS]->known = 2;
    1200                 :            :             }
    1201                 :            :           }
    1202                 :            :         }
    1203 [ -  + ][ #  # ]:         31 :         if (gamestatusp(LOST) && (Precipitation < 1) &&
                 [ #  # ]
    1204                 :          0 :           c_statusp(Player.x, Player.y, SEEN)) {
    1205                 :          0 :           print3("Ah! Now you know where you are!");
    1206                 :          0 :           morewait();
    1207                 :          0 :           resetgamestatus(LOST);
    1208                 :            :         }
    1209         [ -  + ]:         31 :         else if (gamestatusp(LOST)) {
    1210                 :          0 :           print3("You're still lost.");
    1211                 :          0 :           morewait();
    1212                 :            :         }
    1213         [ -  + ]:         31 :         if (Precipitation > 0) Precipitation--;
    1214                 :         31 :         c_set(Player.x, Player.y, SEEN);
    1215                 :         31 :         terrain_check(takestime);
    1216                 :            :       }
    1217                 :            :     }
    1218                 :            :   }
    1219                 :         32 : }

Generated by: LCOV version 1.11