LCOV - code coverage report
Current view: top level - omega-rpg-0.90-pa9 - bank.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 109 555 19.6 %
Date: 2017-09-08 22:00:26 Functions: 7 19 36.8 %
Branches: 70 602 11.6 %

           Branch data     Line data    Source code
       1                 :            : /* omega copyright (C) by Laurence Raphael Brothers, 1987,1988,1989 */
       2                 :            : /* bank.c */
       3                 :            : /* new bank -- moved out of site1.c */
       4                 :            : 
       5                 :            : #include <ctype.h>
       6                 :            : #include <limits.h>
       7                 :            : #include <unistd.h>
       8                 :            : #include "glob.h"
       9                 :            : 
      10                 :            : /* swiped from scr.c */
      11                 :            : #if defined(MSDOS_SUPPORTED_ANTIQUE) || defined(AMIGA)
      12                 :            : # define CHARATTR(c) ((c) >> 8)
      13                 :            : #else
      14                 :            : # define CHARATTR(c) ((c) & ~0xff)
      15                 :            : #endif
      16                 :            : 
      17                 :            : /* defined in scr.c */
      18                 :            : extern WINDOW *Bankw;
      19                 :            : 
      20                 :            : /* predefined account info */
      21                 :            : #define CASH_BALANCE 500
      22                 :            : #define CASH_PASSWORD "cash"
      23                 :            : 
      24                 :            : #define NUM_NPC_ACCOUNTS 30
      25                 :            : 
      26                 :            : char * npc_account_passwords [NUM_NPC_ACCOUNTS] =
      27                 :            : {
      28                 :            :   "Duke",
      29                 :            :   "Duke Nukem",
      30                 :            :   "Dukes Ca$h",
      31                 :            :   "SexyNoreen",
      32                 :            :   "ExSuccubus",
      33                 :            :   "Hooker Sue",
      34                 :            :   "JungleGirl",
      35                 :            :   "Satyrical",
      36                 :            :   "Fangless",
      37                 :            :   "Big Daddy",
      38                 :            :   "PraiseEros",
      39                 :            :   "Sonders",
      40                 :            :   "CSRFLP",
      41                 :            :   "Order",
      42                 :            :   "Diner",
      43                 :            :   "LC****",
      44                 :            :   "Eclipse",
      45                 :            :   "The Circle",
      46                 :            :   "College",
      47                 :            :   "FinanceAid",
      48                 :            :   "Librarian",
      49                 :            :   "RTG, Inc.",
      50                 :            :   "Alchemy",
      51                 :            :   "LOD Mercs",
      52                 :            :   "KnightPawn",
      53                 :            :   "Julie",
      54                 :            :   "RampartGym",
      55                 :            :   "Arena",
      56                 :            :   "Slongo",
      57                 :            :   "Bedwyr"
      58                 :            : };
      59                 :            : 
      60                 :            : int npc_account_balances [NUM_NPC_ACCOUNTS] =
      61                 :            : {
      62                 :            :   3000,
      63                 :            :   30000,
      64                 :            :   300000,
      65                 :            :   100000,
      66                 :            :   75000,
      67                 :            :   125000,
      68                 :            :   50000,
      69                 :            :   75000,
      70                 :            :   50000,
      71                 :            :   100000,
      72                 :            :   50000,
      73                 :            :   10000,
      74                 :            :   300000,
      75                 :            :   3000,
      76                 :            :   3000,
      77                 :            :   50000,
      78                 :            :   5000,
      79                 :            :   25000,
      80                 :            :   5000,
      81                 :            :   40000,
      82                 :            :   10000,
      83                 :            :   500000,
      84                 :            :   10000,
      85                 :            :   200000,
      86                 :            :   75000,
      87                 :            :   10000,
      88                 :            :   40000,
      89                 :            :   3000,
      90                 :            :   2000,
      91                 :            :   2000
      92                 :            : };
      93                 :            : 
      94                 :            : static int account_num [NUM_NPC_ACCOUNTS];
      95                 :            : static char * blank_line = "                                               ";
      96                 :            : static int account_number_next;
      97                 :            : static int account_number_incr;
      98                 :            : 
      99                 :            : /* create a new bank account and add it to the bank */
     100                 :          0 : bank_account * bank_create_account (int player, int balance, char *password)
     101                 :            : {
     102                 :            :   bank_account * new_account;
     103                 :            : 
     104                 :            :   /* no-password accounts aren't allowed */
     105         [ #  # ]:          0 :   assert(password);
     106                 :            : 
     107                 :            :   /* allocate space */
     108                 :          0 :   new_account = checkmalloc(sizeof(bank_account));
     109                 :            : 
     110                 :            :   /* copy fields */
     111                 :          0 :   new_account->player = player;
     112                 :          0 :   new_account->balance = balance;
     113                 :          0 :   new_account->next_account = 0;
     114                 :          0 :   new_account->number = account_number_next;
     115                 :          0 :   account_number_next += account_number_incr;
     116                 :            : 
     117                 :            :   /* allocate and copy the password */
     118                 :          0 :   new_account->password = checkmalloc(1 + strlen(password));
     119                 :          0 :   strcpy(new_account->password, password);
     120                 :            : 
     121                 :            :   /* add the new account to the bank */
     122                 :          0 :   new_account->next_account = bank;
     123                 :          0 :   bank = new_account;
     124                 :            : 
     125                 :          0 :   return new_account;
     126                 :            : }
     127                 :            : 
     128                 :          0 : struct object * bank_create_card (int account_number, int type)
     129                 :            : {
     130                 :            :   struct object * card;
     131                 :            : 
     132 [ #  # ][ #  # ]:          0 :   assert(OB_DEBIT_CARD == type || OB_SMART_CARD == type);
     133                 :            : 
     134                 :          0 :   card = checkmalloc(sizeof(struct object));
     135                 :          0 :   *card = Objects[type];
     136                 :          0 :   card->aux = account_number;
     137                 :            : 
     138                 :          0 :   return card;
     139                 :            : }
     140                 :            : 
     141                 :            : /* find an account in the bank, given the password */
     142                 :          0 : bank_account * bank_index_password (char * password)
     143                 :            : {
     144                 :            :   bank_account * account;
     145                 :            : 
     146         [ #  # ]:          0 :   for(account = bank; account; account = account->next_account)
     147         [ #  # ]:          0 :     if (!strcmp(password, account->password)) break;
     148                 :            : 
     149                 :          0 :   return account;
     150                 :            : }
     151                 :            : 
     152                 :            : /* find an account in the bank, given the account number */
     153                 :          1 : bank_account * bank_index_number (int number)
     154                 :            : {
     155                 :            :   bank_account * account;
     156                 :            : 
     157         [ +  - ]:          8 :   for(account = bank; account; account = account->next_account)
     158         [ +  + ]:          8 :     if (number == account->number) break;
     159                 :            : 
     160                 :          1 :   return account;
     161                 :            : }
     162                 :            : 
     163                 :            : /* allow user to type in a new password with simple editing */
     164                 :            : /* returns the length of the typed-in string */
     165                 :          1 : static int input_password (WINDOW *w, int line, int col, char *buf, int allow_esc)
     166                 :            : {
     167                 :            :   int key;
     168                 :          1 :   int pwlen = 0;
     169                 :          1 :   char *cp = buf;
     170                 :            :         
     171                 :            :   while (1)
     172                 :            :     {
     173         [ +  - ]:          8 :       key = mvwgetch(w, line, col + pwlen);
     174                 :            : 
     175         [ +  + ]:          8 :       if ('\n' == key)
     176                 :            :         {
     177                 :          1 :           *cp = '\0';
     178                 :          1 :           break;
     179                 :            :         }
     180 [ -  + ][ #  # ]:          7 :       else if (ESCAPE == key && allow_esc)
     181                 :            :         {
     182                 :          0 :           *buf = ESCAPE;
     183                 :          0 :           return 1;
     184                 :            :         }
     185 [ +  - ][ +  - ]:          7 :       else if (KEY_LEFT == key || DELETE == key || BACKSPACE == key)
                 [ -  + ]
     186                 :            :         {
     187         [ #  # ]:          0 :           if (pwlen > 0)
     188                 :            :             {
     189                 :          0 :               cp--;
     190                 :          0 :               pwlen--;
     191         [ #  # ]:          0 :               mvwaddch(w, line, col + pwlen, ' ');
     192                 :            :             }
     193                 :            :         }
     194 [ +  - ][ +  - ]:          7 :       else if (isprint(key) && pwlen < 10)
     195                 :            :         {
     196         [ +  - ]:          7 :           mvwaddch(w, line, col + pwlen, '*');
     197                 :          7 :           pwlen++;
     198                 :          7 :           *cp++ = key;
     199                 :            :         }
     200                 :            :                 
     201                 :          7 :       wrefresh(w);
     202                 :          7 :     }
     203                 :            :         
     204                 :          1 :   return pwlen;
     205                 :            : }
     206                 :            : 
     207                 :            : /* allow user to type in a signed integer with simple editing */
     208                 :            : /* returns the typed-in integer */
     209                 :          0 : static long input_amount (WINDOW *w, int line, int col)
     210                 :            : {
     211                 :            :   int key;
     212                 :          0 :   int amountlen = 0;
     213                 :          0 :   long amount = 0;
     214                 :          0 :   long sign = 1;
     215                 :            :         
     216                 :            :   while (1)
     217                 :            :     {
     218         [ #  # ]:          0 :       key = mvwgetch(w, line, col + amountlen);
     219                 :            : 
     220         [ #  # ]:          0 :       if ('\n' == key) return sign * amount;
     221                 :            : 
     222 [ #  # ][ #  # ]:          0 :       if (KEY_LEFT == key || DELETE == key || BACKSPACE == key)
                 [ #  # ]
     223                 :            :         {
     224         [ #  # ]:          0 :           if (amountlen > 0)
     225                 :            :             {
     226                 :          0 :               amount /= 10;
     227                 :          0 :               amountlen--;
     228         [ #  # ]:          0 :               mvwaddch(w, line, col + amountlen, ' ');
     229                 :            :             }
     230                 :            :                         
     231         [ #  # ]:          0 :           if (0 == amountlen) sign = 1;
     232                 :            :         }
     233 [ #  # ][ #  # ]:          0 :       else if (0 == amountlen && ('-' ==  key || '+' == key))
                 [ #  # ]
     234                 :            :         {
     235         [ #  # ]:          0 :           mvwaddch(w, line, col + amountlen, key);
     236                 :          0 :           amountlen++;
     237         [ #  # ]:          0 :           if ('-' == key) sign = -1;
     238                 :            :         }
     239 [ #  # ][ #  # ]:          0 :       else if (isdigit(key) && amountlen < 8)
     240                 :            :         {
     241         [ #  # ]:          0 :           mvwaddch(w, line, col + amountlen, key);
     242                 :          0 :           amountlen++;
     243                 :          0 :           amount = 10 * amount + (key - '0');
     244                 :            :         }
     245                 :            :                 
     246                 :          0 :       wrefresh(w);
     247                 :          0 :     }
     248                 :            : }
     249                 :            : 
     250                 :            : /* see if the player wants to open a new account */
     251                 :          1 : static int bank_new_customer (WINDOW *w)
     252                 :            : {
     253                 :            :   int response;
     254                 :            :         
     255         [ +  - ]:          1 :   mvwaddstr(w, 4, 2, blank_line);
     256         [ +  - ]:          1 :   mvwaddstr(w, 4, 2, "Do you have an account with us? [yn] : ");
     257                 :          1 :   wrefresh(w);
     258                 :            : 
     259                 :            :   while (1)
     260                 :            :     {
     261                 :          1 :       response = toupper(wgetch(w));
     262                 :            : 
     263         [ +  - ]:          1 :       if ('Y' == response)
     264                 :            :         {
     265                 :          1 :           waddstr(w, "yes");
     266                 :          1 :           wrefresh(w);
     267                 :          1 :           return FALSE; /* new customer == false */
     268                 :            :         }
     269         [ #  # ]:          0 :       else if ('N' == response)
     270                 :            :         {
     271                 :          0 :           waddstr(w, "no");
     272                 :          0 :           wrefresh(w);
     273                 :          0 :           return TRUE; /* new customer == true */
     274                 :            :         }
     275         [ #  # ]:          0 :       else if (ESCAPE == response)
     276                 :            :         {
     277                 :          0 :           return ABORT;
     278                 :            :         }
     279                 :          0 :     }
     280                 :            : }
     281                 :            : 
     282                 :          0 : static void bank_call_police (void)
     283                 :            : {
     284                 :            :   pml ml;
     285                 :            :   pmt mon;
     286                 :            : 
     287                 :          0 :   cinema_scene("A loud siren goes off!", 0, 0);
     288                 :            : 
     289         [ #  # ]:          0 :   for (ml = Level->mlist; ml; ml = ml->next)
     290                 :            :     {
     291                 :          0 :       mon = ml->m;
     292         [ #  # ]:          0 :       if (GUARD == mon->id)
     293                 :            :         {
     294                 :          0 :           mon->sense *= 2;
     295                 :          0 :           m_status_set(mon, AWAKE);
     296                 :          0 :           m_status_set(mon, HOSTILE);
     297                 :            :         }
     298                 :            :     }
     299                 :          0 : }
     300                 :            : 
     301                 :          1 : static int police_are_hostile (void)
     302                 :            : {
     303                 :            :   pml ml;
     304                 :            :   pmt mon;
     305                 :            : 
     306         [ +  + ]:         22 :   for (ml = Level->mlist; ml; ml = ml->next)
     307                 :            :     {
     308                 :         21 :       mon = ml->m;
     309 [ +  + ][ -  + ]:         21 :       if (GUARD == mon->id && m_statusp(mon, HOSTILE))
     310                 :          0 :         return TRUE;
     311                 :            :     }
     312                 :            : 
     313                 :          1 :   return FALSE;
     314                 :            : }
     315                 :            : 
     316                 :          0 : static pob bank_open_account (WINDOW *w)
     317                 :            : {
     318                 :            :   int idx;
     319                 :            :   int response;
     320                 :            : 
     321         [ #  # ]:          0 :   mvwaddstr(w, 5, 2, blank_line);
     322         [ #  # ]:          0 :   mvwaddstr(w, 5, 2, "Do you want to open an account? [yn] : ");
     323                 :          0 :   wrefresh(w);
     324                 :            : 
     325                 :            :   while (1)
     326                 :            :     {
     327                 :          0 :       response = toupper(wgetch(w));
     328                 :            : 
     329         [ #  # ]:          0 :       if ('Y' == response)
     330                 :            :         {
     331                 :          0 :           waddstr(w, "yes");
     332                 :          0 :           wrefresh(w);
     333                 :          0 :           break;
     334                 :            :         }
     335         [ #  # ]:          0 :       else if ('N' == response)
     336                 :            :         {
     337                 :          0 :           waddstr(w, "no");
     338         [ #  # ]:          0 :           mvwaddstr(w, 7, 2, "        Please remember us in the future       ");
     339         [ #  # ]:          0 :           mvwaddstr(w, 8, 2, "     when you have need of banking services    ");
     340                 :          0 :           wrefresh(w);
     341                 :          0 :           sleep(4);
     342                 :          0 :           return 0;
     343                 :            :         }
     344         [ #  # ]:          0 :       else if (ESCAPE == response)
     345                 :            :         {
     346                 :          0 :           return 0;
     347                 :            :         }
     348                 :          0 :     }
     349                 :            : 
     350                 :            :   while (1)
     351                 :            :     {
     352                 :            :       int pwlen;
     353                 :            :       char pw_buf1 [16];
     354                 :            :       char pw_buf2 [16];
     355                 :            : 
     356         [ #  # ]:          0 :       mvwaddstr(w, 7, 2, "            [ Opening New Account ]            ");
     357                 :            : 
     358                 :            :       while (1)
     359                 :            :         {
     360                 :            :           int cx, cy;
     361                 :            : 
     362         [ #  # ]:          0 :           for (idx = 9; idx < 14; ++idx)
     363         [ #  # ]:          0 :             mvwaddstr(w, idx, 2, blank_line);
     364                 :            : 
     365         [ #  # ]:          0 :           mvwaddstr(w, 9, 2, "Please enter a new password: ");
     366                 :          0 :           wrefresh(w);
     367                 :            :                         
     368 [ #  # ][ #  # ]:          0 :           getyx(w, cy, cx);
     369                 :          0 :           pwlen = input_password(w, 9, cx, pw_buf1, FALSE);
     370         [ #  # ]:          0 :           if (pwlen) break;
     371                 :            :         
     372         [ #  # ]:          0 :           mvwaddstr(w, 11, 2, "Null passwords are not allowed. Try again.");
     373                 :          0 :         }
     374                 :            : 
     375         [ #  # ]:          0 :       mvwaddstr(w, 11, 2, blank_line);
     376                 :            : 
     377                 :            :       while (1)
     378                 :            :         {
     379                 :            :           int cx, cy;
     380                 :            : 
     381         [ #  # ]:          0 :           for (idx = 10; idx < 14; ++idx)
     382         [ #  # ]:          0 :             mvwaddstr(w, idx, 2, blank_line);
     383                 :            : 
     384         [ #  # ]:          0 :           mvwaddstr(w, 10, 2, "Please confirm your password: ");
     385                 :          0 :           wrefresh(w);
     386                 :            :                         
     387 [ #  # ][ #  # ]:          0 :           getyx(w, cy, cx);
     388                 :          0 :           pwlen = input_password(w, 10, cx, pw_buf2, FALSE);
     389         [ #  # ]:          0 :           if (pwlen) break;
     390                 :            :         
     391         [ #  # ]:          0 :           mvwaddstr(w, 12, 2, "Null passwords are not allowed. Try again.");
     392                 :          0 :         }
     393                 :            : 
     394         [ #  # ]:          0 :       if (strcmp(pw_buf1, pw_buf2))
     395                 :            :         {
     396         [ #  # ]:          0 :           mvwaddstr(w, 12, 2, "Passwords didn't match. Restarting...          " );
     397                 :            :         }
     398                 :            :       else
     399                 :            :         {
     400                 :            :           bank_account *account;
     401                 :            : 
     402                 :          0 :           account = bank_index_password(pw_buf1);
     403                 :            : 
     404         [ #  # ]:          0 :           if (account)
     405                 :            :             {
     406         [ #  # ]:          0 :               mvwaddstr(w, 12, 2, "Password not valid. Restarting...              ");
     407                 :            :             }
     408                 :            :           else
     409                 :            :             {
     410                 :            :               int cx, cy;
     411                 :            :               int amount;
     412                 :          0 :               int bad_deposit = 0;
     413                 :            : 
     414         [ #  # ]:          0 :               for (idx = 8; idx < 12; ++idx)
     415         [ #  # ]:          0 :                 mvwaddstr(w, idx, 2, blank_line);
     416                 :            : 
     417         [ #  # ]:          0 :               mvwaddstr(w, 9, 2, "Password validated.                            ");
     418                 :            : 
     419                 :            :               while (1)
     420                 :            :                 {
     421         [ #  # ]:          0 :                   mvwaddstr(w, 11, 2, blank_line);
     422         [ #  # ]:          0 :                   mvwaddstr(w, 11, 2, "Initial deposit amount (min 5 AU): ");
     423                 :          0 :                   wrefresh(w);
     424                 :            :         
     425 [ #  # ][ #  # ]:          0 :                   getyx(w, cy, cx);
     426                 :          0 :                   amount = input_amount(w, cy, cx);
     427                 :            : 
     428         [ #  # ]:          0 :                   if (amount < 0)
     429                 :            :                     {
     430                 :          0 :                       ++bad_deposit;
     431                 :          0 :                       --(Player.alignment);
     432                 :            : 
     433         [ #  # ]:          0 :                       if (1 == bad_deposit)
     434                 :            :                         {
     435         [ #  # ]:          0 :                           mvwaddstr(w, 13, 2, "Nice try, buster!                              ");
     436                 :            :                         }
     437         [ #  # ]:          0 :                       else if (2 == bad_deposit)
     438                 :            :                         {
     439         [ #  # ]:          0 :                           mvwaddstr(w, 13, 2, "Hey loser! Deposit means you pay!              ");
     440                 :            :                         }
     441                 :            :                       else
     442                 :            :                         {
     443         [ #  # ]:          0 :                           mvwaddstr(w, 13, 2, "Ok, you asked for it jerk!                     ");
     444                 :          0 :                           wrefresh(w);
     445                 :          0 :                           bank_call_police();
     446                 :          0 :                           return 0;
     447                 :            :                         }
     448                 :            :                     }
     449         [ #  # ]:          0 :                   else if (amount < 5)
     450                 :            :                     {
     451         [ #  # ]:          0 :                       if (amount >= Player.cash)
     452                 :            :                         {
     453         [ #  # ]:          0 :                           mvwaddstr(w, 13, 2, "Ok, I'll be nice and waive the minimum deposit.");
     454                 :          0 :                           amount = Player.cash;
     455                 :          0 :                           Player.cash = 0;
     456                 :          0 :                           break;
     457                 :            :                         }
     458                 :            : 
     459         [ #  # ]:          0 :                       mvwaddstr(w, 13, 2, "Can't you read? Minimum deposit 5 AU !         ");
     460                 :            :                     }
     461                 :            :                   else
     462                 :            :                     {
     463         [ #  # ]:          0 :                       if (Player.cash < 5)
     464         [ #  # ]:          0 :                         mvwaddstr(w, 13, 2, "Ok, I'll be nice and waive the minimum deposit.");
     465                 :            :                       else
     466         [ #  # ]:          0 :                         mvwaddstr(w, 13, 2, "New account created.                           ");
     467                 :            : 
     468         [ #  # ]:          0 :                       if (amount > Player.cash) amount = Player.cash;
     469                 :          0 :                       Player.cash -= amount;
     470                 :          0 :                       break;
     471                 :            :                     }
     472                 :          0 :                 }
     473                 :            : 
     474                 :          0 :               wrefresh(w);
     475                 :            : 
     476                 :          0 :               account = bank_create_account(TRUE, 0, pw_buf1);
     477                 :          0 :               account->balance = amount;
     478                 :            : 
     479                 :          0 :               Objects[OB_DEBIT_CARD].known = 1;
     480                 :          0 :               return bank_create_card(account->number, OB_DEBIT_CARD);
     481                 :            :             }
     482                 :            :         }
     483                 :            : 
     484                 :          0 :       wrefresh(w);
     485                 :          0 :       sleep(3);
     486                 :          0 :     }
     487                 :            : 
     488                 :            :   return 0;
     489                 :            : }
     490                 :            : 
     491                 :          0 : static void bank_close_accounts (void)
     492                 :            : {
     493                 :            :   bank_account *account;
     494                 :            :   bank_account *next;
     495                 :            :         
     496         [ #  # ]:          0 :   for (account = bank; account; account = next)
     497                 :            :     {
     498                 :          0 :       next = account->next_account;
     499                 :          0 :       free(account->password);
     500                 :          0 :       free(account);
     501                 :            :     }
     502                 :            :         
     503                 :          0 :   bank = 0;
     504                 :          0 : }
     505                 :            : 
     506                 :          0 : static void bank_break (WINDOW *w, pob card)
     507                 :            : {
     508                 :            :   int response;
     509                 :            :   long total_balance;
     510                 :            :   char *cp;
     511                 :            :   bank_account *account;
     512                 :            :         
     513                 :            :   static char *bb_garbage = "^@^@^@^@^@00AD1203BC0F0000FFFFFFFFF";
     514                 :            : 
     515         [ #  # ]:          0 :   if (card->blessing > 0)
     516                 :            :     {
     517         [ #  # ]:          0 :       mvwaddstr(w,  6, 2, "   Hey buddy... That was the wrong password!   ");
     518         [ #  # ]:          0 :       mvwaddstr(w,  7, 2, " I'm supposed to call the cops, but I wouldn't ");
     519         [ #  # ]:          0 :       mvwaddstr(w,  9, 2, "      do that to you! Just try again, ok?      ");
     520                 :          0 :       wrefresh(w);
     521                 :          0 :       --(card->blessing);
     522                 :          0 :       return;
     523                 :            :     }
     524         [ #  # ]:          0 :   else if (card->blessing < 0)
     525                 :            :     {
     526         [ #  # ]:          0 :       mvwaddstr(w,  6, 2, "           Gotcha you reject thief!            ");
     527         [ #  # ]:          0 :       mvwaddstr(w,  7, 2, "    I'm calling the cops! You're gonna fry!    ");
     528         [ #  # ]:          0 :       mvwaddstr(w,  9, 2, " You're going down! I'm loving it! Muahahaha!  ");
     529                 :          0 :       wrefresh(w);
     530                 :          0 :       bank_call_police();
     531                 :          0 :       return;
     532                 :            :     }
     533                 :            : 
     534         [ #  # ]:          0 :   mvwaddstr(w,  6, 2, "       Alert! Alert!  Invalid Password!        ");
     535         [ #  # ]:          0 :   mvwaddstr(w,  7, 2, "        The police are being summoned!         ");
     536         [ #  # ]:          0 :   mvwaddstr(w,  9, 2, "     Please wait for the police to arrive!     ");
     537         [ #  # ]:          0 :   mvwaddstr(w, 11, 2, "       --- Hit Space Bar to Continue ---       ");
     538                 :          0 :   wrefresh(w);
     539                 :            : 
     540                 :          0 :   response = wgetch(w);
     541                 :            : 
     542         [ #  # ]:          0 :   if (' ' == response)
     543                 :            :     {
     544                 :          0 :       Player.alignment += 5;
     545                 :          0 :       bank_call_police();
     546                 :            :     }
     547                 :            :   else
     548                 :            :     {
     549                 :            :       int idx;
     550                 :            : 
     551                 :          0 :       Player.alignment -= 5;
     552                 :            : 
     553         [ #  # ]:          0 :       for (idx = 2; idx < 18; ++idx)
     554         [ #  # ]:          0 :         mvwaddstr(w,  idx, 2, blank_line);
     555                 :            : 
     556                 :          0 :       wrefresh(w);
     557                 :            :                 
     558                 :          0 :       wmove(w, 2, 2);
     559         [ #  # ]:          0 :       for (cp = bb_garbage; *cp; ++cp)
     560                 :            :         {
     561                 :          0 :           waddch(w, *cp);
     562                 :          0 :           wrefresh(w);
     563                 :          0 :           usleep(100000);
     564                 :            :         }
     565                 :            :                 
     566         [ #  # ]:          0 :       mvwaddstr(w, 3, 2, "Error in _get_space(): Illegal character       ");
     567         [ #  # ]:          0 :       mvwaddstr(w, 4, 2, "Aborting bank_call_police().                   ");
     568                 :            : 
     569         [ #  # ]:          0 :       mvwaddstr(w, 5, 2, blank_line);
     570         [ #  # ]:          0 :       mvwaddstr(w, 5, 2, "Attempting warm boot");
     571                 :          0 :       wrefresh(w);
     572                 :            : 
     573         [ #  # ]:          0 :       for (idx = 0; idx < 5; ++idx)
     574                 :            :         {
     575                 :          0 :           waddch(w, '.');
     576                 :          0 :           wrefresh(w);
     577                 :          0 :           sleep(1);
     578                 :            :         }
     579                 :            : 
     580         [ #  # ]:          0 :       mvwaddstr(w, 6, 2, "Warning: Uncaught exception in count_cash()    ");
     581         [ #  # ]:          0 :       mvwaddstr(w, 7, 2, "Warning: Unable to clear command buffer        ");
     582         [ #  # ]:          0 :       mvwaddstr(w, 8, 2, blank_line);
     583         [ #  # ]:          0 :       mvwaddstr(w, 8, 2, "reboot continuing");
     584                 :          0 :       wrefresh(w);
     585                 :            : 
     586         [ #  # ]:          0 :       for (idx = 0; idx < 5; ++idx)
     587                 :            :         {
     588                 :          0 :           waddch(w, '.');
     589                 :          0 :           wrefresh(w);
     590                 :          0 :           sleep(1);
     591                 :            :         }
     592                 :            : 
     593         [ #  # ]:          0 :       mvwaddstr(w,  9, 2, "Reboot complete. Withdrawing 4294967297 AU     ");
     594         [ #  # ]:          0 :       mvwaddstr(w, 10, 2, "Warning: Uncaught exception in withdraw_cash() ");
     595         [ #  # ]:          0 :       mvwaddstr(w, 11, 2, "Warning: Integer overflow ");
     596                 :          0 :       wrefresh(w);
     597                 :            : 
     598         [ #  # ]:          0 :       mvwaddstr(w, 12, 2, blank_line);
     599         [ #  # ]:          0 :       mvwaddstr(w, 12, 2, "Emergency reboot");
     600                 :          0 :       wrefresh(w);
     601                 :            : 
     602         [ #  # ]:          0 :       for (idx = 0; idx < 5; ++idx)
     603                 :            :         {
     604                 :          0 :           waddch(w, '.');
     605                 :          0 :           wrefresh(w);
     606                 :          0 :           sleep(1);
     607                 :            :         }
     608                 :            : 
     609         [ #  # ]:          0 :       mvwaddstr(w, 14, 2, "Registry corrupt! Further execution impossible!");
     610         [ #  # ]:          0 :       mvwaddstr(w, 16, 2, "  Call Microsoft embedded products technical   ");
     611         [ #  # ]:          0 :       mvwaddstr(w, 17, 2, "      support for assistance (10 AU/min)       ");
     612                 :          0 :       wrefresh(w);
     613                 :          0 :       sleep(8);
     614                 :            : 
     615                 :          0 :       total_balance = 0;
     616         [ #  # ]:          0 :       for (account = bank; account; account = account->next_account)
     617                 :            :         {
     618         [ #  # ]:          0 :           if (account->player)
     619                 :          0 :             total_balance += account->balance;
     620                 :            :         }
     621                 :            :                 
     622                 :          0 :       clearmsg();
     623                 :          0 :       print1("The cash machine begins to spew gold pieces!");
     624                 :            : 
     625         [ #  # ]:          0 :       if (total_balance > 0)
     626                 :          0 :         print2("You pick up your entire balance and then some!");
     627                 :            :       else
     628                 :          0 :         print2("You eagerly collect the coins in your purse!");
     629                 :            : 
     630                 :          0 :       Player.cash += (total_balance + 1000 + random_range(1000 + total_balance));
     631                 :            : 
     632                 :          0 :       bank_close_accounts();
     633                 :          0 :       setgamestatus(BANK_BROKEN);
     634                 :          0 :       dataprint();
     635                 :            :     }
     636                 :            : }
     637                 :            : 
     638                 :          1 : static bank_account *bank_password (WINDOW *w, pob * out_card, int * abort)
     639                 :            : {
     640                 :            :   int cy, cx;
     641                 :            :   pob card;
     642                 :            :   bank_account *account;
     643                 :            :   char pw_buf [16];
     644                 :            : 
     645                 :          1 :   account = 0;
     646                 :          1 :   *abort = FALSE;
     647                 :            : 
     648                 :            :   while (1)
     649                 :            :     {
     650                 :            :       int card_idx;
     651                 :            : 
     652         [ +  - ]:          1 :       mvwaddstr(w, 4, 2, "Please insert your card...                     ");
     653                 :          1 :       wrefresh(w);
     654                 :            : 
     655                 :          1 :       card_idx = getitem(THING);
     656         [ -  + ]:          1 :       if (ABORT == card_idx)
     657                 :            :         {
     658                 :          0 :           clearmsg();
     659                 :          0 :           cinema_scene("You realize that you can't use the autoteller without a bank card.", 0, 0);
     660                 :          0 :           *abort = TRUE;
     661                 :          0 :           return 0;
     662                 :            :         }
     663                 :            : 
     664                 :          1 :       card = Player.possessions[card_idx];
     665         [ -  + ]:          1 :       if (!card) return 0;
     666                 :            : 
     667 [ +  - ][ -  + ]:          1 :       if (card->id < OB_DEBIT_CARD || card->id > OB_SMART_CARD)
     668                 :            :         {
     669                 :            :           char tbuf[120];
     670                 :            : 
     671                 :          0 :           sprintf(tbuf, "You seem to have trouble sticking your %s in the slot", itemid(card));
     672                 :          0 :           cinema_scene(tbuf, 0, 0);
     673                 :          0 :           continue;
     674                 :            :         }
     675                 :            :       else
     676                 :            :         {
     677                 :          1 :           clearmsg();
     678                 :          1 :           account = bank_index_number(card->aux);
     679                 :            :         }
     680                 :            : 
     681                 :            :       /* make sure bank redraws if it was covered by inventory in getitem() */
     682         [ +  - ]:          1 :       touchwin(w);
     683                 :            : 
     684         [ +  - ]:          1 :       if (account) break;
     685                 :            : 
     686   [ #  #  #  # ]:          0 :       switch(random_range(4))
     687                 :            :         {
     688                 :            :         default:
     689         [ #  # ]:          0 :           mvwaddstr(w, 4, 2, "Invalid card!                                  "); break;
     690                 :            :         case 1:
     691         [ #  # ]:          0 :           mvwaddstr(w, 4, 2, "Where'd that card come from?                   "); break;
     692                 :            :         case 2:
     693         [ #  # ]:          0 :           mvwaddstr(w, 4, 2, "Ack! Ptui!                                     "); break;
     694                 :            :         case 3:
     695         [ #  # ]:          0 :           mvwaddstr(w, 4, 2, "Hurkkk! I think I'm gonna be sick...           "); break;
     696                 :            :         }
     697                 :            : 
     698                 :          0 :       wrefresh(w);
     699                 :          0 :       cinema_scene("The autoteller spits the card back out", 0, 0);
     700                 :          0 :     }
     701                 :            : 
     702                 :            :   /* provide the card to caller */
     703                 :          1 :   *out_card = card;
     704                 :            : 
     705         [ +  - ]:          1 :   mvwaddstr(w, 4, 2, blank_line);
     706         [ -  + ]:          1 :   if (card->blessing > 0)
     707         [ #  # ]:          0 :     mvwaddstr(w, 4, 2, "Hiya! So what's your password: ");
     708         [ -  + ]:          1 :   else if (card->blessing < 0)
     709         [ #  # ]:          0 :     mvwaddstr(w, 4, 2, "Gimme your #*!&% password: ");
     710                 :            :   else
     711         [ +  - ]:          1 :     mvwaddstr(w, 4, 2, "Enter your account password: ");
     712                 :          1 :   wrefresh(w);
     713                 :            : 
     714 [ +  - ][ +  - ]:          1 :   getyx(w, cy, cx);
     715                 :          1 :   input_password(w, cy, cx, pw_buf, TRUE);
     716                 :            : 
     717         [ -  + ]:          1 :   if (ESCAPE == pw_buf[0])
     718                 :            :     {
     719                 :          0 :       *abort = TRUE;
     720                 :          0 :       return 0;
     721                 :            :     }
     722                 :            : 
     723         [ +  - ]:          1 :   if (0 == strcmp(pw_buf, account->password))
     724                 :            :     {
     725         [ -  + ]:          1 :       if (card->blessing > 0)
     726         [ #  # ]:          0 :         mvwaddstr(w, 4, 2, "WooHoo! That's right buddy!                    ");
     727         [ -  + ]:          1 :       else if (card->blessing < 0)
     728         [ #  # ]:          0 :         mvwaddstr(w, 4, 2, "*$&^! I was gonna bust ya.                     ");
     729                 :            :       else
     730         [ +  - ]:          1 :         mvwaddstr(w, 4, 2, "Password accepted. Working.                    ");
     731                 :          1 :       wrefresh(w);
     732                 :            : 
     733         [ -  + ]:          1 :       if (!account->player) Player.alignment -= 5;
     734                 :            :     }
     735                 :            :   else
     736                 :            :     {
     737                 :          0 :       bank_break(w, card);
     738                 :          0 :       account = 0;
     739                 :            :     }
     740                 :            : 
     741                 :          1 :   return account;
     742                 :            : }
     743                 :            : 
     744                 :          0 : static void bank_deposit (WINDOW *w, bank_account *account, pob card)
     745                 :            : {
     746                 :            :   int cy, cx;
     747                 :            :   long amount;
     748                 :            : 
     749         [ #  # ]:          0 :   mvwaddstr(w, 12, 2, blank_line);
     750         [ #  # ]:          0 :   if (card->blessing > 0)
     751         [ #  # ]:          0 :     mvwaddstr(w, 12, 2, "How much should I look after? ");
     752         [ #  # ]:          0 :   else if (card->blessing < 0)
     753         [ #  # ]:          0 :     mvwaddstr(w, 12, 2, "Cough up: ");
     754                 :            :   else
     755         [ #  # ]:          0 :     mvwaddstr(w, 12, 2, "Amount: ");
     756                 :          0 :   wrefresh(w);
     757                 :            : 
     758 [ #  # ][ #  # ]:          0 :   getyx(w, cy, cx);
     759                 :          0 :   amount = input_amount(w, cy, cx);
     760                 :            : 
     761         [ #  # ]:          0 :   if (amount < 0)
     762                 :            :     {
     763         [ #  # ]:          0 :       if (card->blessing > 0)
     764                 :            :         {
     765         [ #  # ]:          0 :           mvwaddstr(w, 14, 2, "Oh, you actually want to have some money?      ");
     766         [ #  # ]:          0 :           mvwaddstr(w, 15, 2, "Ok Buddy! No Problem!                          ");
     767         [ #  # ]:          0 :           mvwaddstr(w, 16, 2, blank_line);
     768                 :          0 :           amount = abs(amount);
     769         [ #  # ]:          0 :           if (amount > account->balance) amount = account->balance;
     770                 :          0 :           account->balance -= amount;
     771                 :          0 :           Player.cash += amount;
     772                 :            :         }
     773         [ #  # ]:          0 :       else if (card->blessing < 0)
     774                 :            :         {
     775         [ #  # ]:          0 :           mvwaddstr(w, 14, 2, "You're supposed to give ME money, blockhead!   ");
     776         [ #  # ]:          0 :           mvwaddstr(w, 15, 2, "I'll just take it anyway! Muahahahahaha!       ");
     777         [ #  # ]:          0 :           mvwaddstr(w, 16, 2, "Mine! All Mine!                                ");
     778                 :          0 :           account->balance -= 1000;
     779                 :            :         }
     780                 :            :       else
     781                 :            :         {
     782         [ #  # ]:          0 :           mvwaddstr(w, 14, 2, "Unauthorized withdrawal attempt!               ");
     783         [ #  # ]:          0 :           mvwaddstr(w, 15, 2, "A fine in the amount of 250 AU has been        ");
     784         [ #  # ]:          0 :           mvwaddstr(w, 16, 2, "levied against your account.                   ");
     785                 :          0 :           account->balance -= 250;
     786                 :            :         }
     787                 :            :     }
     788         [ #  # ]:          0 :   else if (0 == amount)
     789                 :            :     {
     790         [ #  # ]:          0 :       if (card->blessing > 0)
     791         [ #  # ]:          0 :         mvwaddstr(w, 14, 2, "Changed your mind? No worries pal!             ");
     792         [ #  # ]:          0 :       else if (card->blessing < 0)
     793         [ #  # ]:          0 :         mvwaddstr(w, 14, 2, "Hey! Cough it up jerk! NOW!                    ");
     794                 :            :       else
     795         [ #  # ]:          0 :         mvwaddstr(w, 14, 2, "Transaction Aborted                            ");
     796                 :            : 
     797         [ #  # ]:          0 :       mvwaddstr(w, 15, 2, blank_line);
     798         [ #  # ]:          0 :       mvwaddstr(w, 16, 2, blank_line);
     799                 :            :     }
     800                 :            :   else
     801                 :            :     {
     802                 :          0 :       int fee = 0;
     803                 :            : 
     804         [ #  # ]:          0 :       if (amount > Player.cash) amount = Player.cash;
     805         [ #  # ]:          0 :       mvwaddstr(w, 14, 2, blank_line);
     806                 :            : 
     807         [ #  # ]:          0 :       if (card->blessing > 0)
     808                 :            :         {
     809                 :          0 :           mvwprintw(w, 14, 2, "I'll take good care of %d AU for you!", amount);
     810                 :            :         }
     811         [ #  # ]:          0 :       else if (card->blessing < 0)
     812                 :            :         {
     813                 :          0 :           fee = 1 + random_range(amount) / 2;
     814                 :          0 :           mvwprintw(w, 14, 2, "Minus my fee, that makes %d AU for you...", amount - fee);
     815                 :            :         }
     816                 :            :       else
     817                 :            :         {
     818                 :          0 :           mvwprintw(w, 14, 2, "%d AU deposited", amount);
     819                 :            :         }
     820                 :            : 
     821                 :          0 :       account->balance += (amount - fee);
     822                 :          0 :       Player.cash -= amount;
     823                 :            : 
     824         [ #  # ]:          0 :       mvwaddstr(w, 15, 2, blank_line);
     825         [ #  # ]:          0 :       mvwaddstr(w, 16, 2, blank_line);
     826                 :            :     }
     827                 :            :         
     828                 :          0 :   wrefresh(w);
     829                 :          0 : }
     830                 :            : 
     831                 :          0 : static void bank_withdraw (WINDOW *w, bank_account *account, pob card)
     832                 :            : {
     833                 :            :   int cy, cx;
     834                 :            :   long amount;
     835                 :            : 
     836         [ #  # ]:          0 :   mvwaddstr(w, 12, 2, blank_line);
     837         [ #  # ]:          0 :   if (card->blessing > 0)
     838         [ #  # ]:          0 :     mvwaddstr(w, 12, 2, "How much do you want, pal? ");
     839         [ #  # ]:          0 :   else if (card->blessing < 0)
     840         [ #  # ]:          0 :     mvwaddstr(w, 12, 2, "Grovel for this much: ");
     841                 :            :   else
     842         [ #  # ]:          0 :     mvwaddstr(w, 12, 2, "Amount: ");
     843                 :          0 :   wrefresh(w);
     844                 :            : 
     845 [ #  # ][ #  # ]:          0 :   getyx(w, cy, cx);
     846                 :          0 :   amount = input_amount(w, cy, cx);
     847                 :            : 
     848         [ #  # ]:          0 :   if (amount < 0)
     849                 :            :     {
     850                 :          0 :       amount = abs(amount);
     851         [ #  # ]:          0 :       if (amount > Player.cash) amount = Player.cash;
     852                 :            : 
     853                 :          0 :       Player.cash -= amount;
     854                 :            : 
     855         [ #  # ]:          0 :       mvwaddstr(w, 14, 2, blank_line);
     856         [ #  # ]:          0 :       if (card->blessing > 0)
     857                 :          0 :         mvwprintw(w, 14, 2, "Whoa, thanks for the %d AU!", amount);
     858         [ #  # ]:          0 :       else if (card->blessing < 0)
     859                 :          0 :         mvwprintw(w, 14, 2, "Sucker! %d AU is mine! all mine!", amount);
     860                 :            :       else
     861                 :          0 :         mvwprintw(w, 14, 2, "%d AU deposited", amount);
     862                 :            : 
     863         [ #  # ]:          0 :       mvwaddstr(w, 15, 2, blank_line);
     864         [ #  # ]:          0 :       mvwaddstr(w, 16, 2, blank_line);
     865                 :            : 
     866         [ #  # ]:          0 :       if (card->blessing >= 0)
     867                 :          0 :         account->balance += amount;
     868                 :            :     }
     869         [ #  # ]:          0 :   else if (amount > account->balance)
     870                 :            :     {
     871         [ #  # ]:          0 :       if (card->blessing > 0)
     872                 :            :         {
     873         [ #  # ]:          0 :           mvwaddstr(w, 14, 2, "Golly! You must have typed wrong!              ");
     874         [ #  # ]:          0 :           mvwaddstr(w, 15, 2, "But don't worry, I won't hold it against you!  ");
     875         [ #  # ]:          0 :           mvwaddstr(w, 16, 2, "Just try again pal!                            ");
     876                 :            :         }
     877         [ #  # ]:          0 :       else if (card->blessing < 0)
     878                 :            :         {
     879         [ #  # ]:          0 :           mvwaddstr(w, 14, 2, "What the #&*^* are you trying to pull?!        ");
     880         [ #  # ]:          0 :           mvwaddstr(w, 15, 2, "You're gonna pay for that! Muahahahaha!        ");
     881         [ #  # ]:          0 :           mvwaddstr(w, 16, 2, "Mine! All mine!                                ");
     882                 :          0 :           account->balance -= 1000;
     883                 :            :         }
     884                 :            :       else
     885                 :            :         {
     886         [ #  # ]:          0 :           mvwaddstr(w, 14, 2, "Account overdraft!                             ");
     887         [ #  # ]:          0 :           mvwaddstr(w, 15, 2, "A fine in the amount of 100 AU has been levied ");
     888         [ #  # ]:          0 :           mvwaddstr(w, 16, 2, "against your account.                          ");
     889                 :          0 :           account->balance -= 100;
     890                 :            :         }
     891                 :            :     }
     892                 :            :   else
     893                 :            :     {
     894                 :          0 :       int extra = 0;
     895                 :            : 
     896         [ #  # ]:          0 :       if (card->blessing > 0)
     897                 :            :         {
     898                 :          0 :           extra = 1 + random_range(amount);
     899         [ #  # ]:          0 :           mvwaddstr(w, 14, 2, blank_line);
     900                 :          0 :           mvwprintw(w, 14, 2, "Sure! In fact, how about %d AU more?", extra);
     901                 :            :         }
     902         [ #  # ]:          0 :       else if (card->blessing < 0)
     903                 :            :         {
     904                 :          0 :           extra = -random_range(amount);
     905         [ #  # ]:          0 :           mvwaddstr(w, 14, 2, blank_line);
     906                 :          0 :           mvwprintw(w, 14, 2, "Ok, but I'm keeping %d AU for myself!", -extra);
     907                 :            :         }
     908                 :            :       else
     909                 :            :         {
     910         [ #  # ]:          0 :           mvwaddstr(w, 14, 2, "Transaction accomplished.                      ");
     911                 :            :         }
     912                 :            : 
     913                 :          0 :       account->balance -= amount;
     914                 :          0 :       Player.cash += (amount + extra);
     915                 :            : 
     916         [ #  # ]:          0 :       mvwaddstr(w, 15, 2, blank_line);
     917         [ #  # ]:          0 :       mvwaddstr(w, 16, 2, blank_line);
     918                 :            :     }
     919                 :            : 
     920                 :          0 :   wrefresh(w);
     921                 :          0 : }
     922                 :            : 
     923                 :          1 : static void bank_transaction (WINDOW *w, bank_account *account, pob card)
     924                 :            : {
     925                 :            :   int idx;
     926                 :            :   int cy, cx;
     927                 :            :   short response;
     928                 :            : 
     929                 :            :   while (1)
     930                 :            :     {
     931         [ +  + ]:          9 :       for (idx = 6; idx < 14; ++idx)
     932         [ +  - ]:          8 :         mvwaddstr(w, idx, 2, blank_line);
     933                 :            : 
     934         [ -  + ]:          1 :       if (card->blessing > 0)
     935                 :            :         {
     936         [ #  # ]:          0 :           if (account->balance > 0)
     937                 :          0 :             mvwprintw(w,  6, 2, "Say pal, you've got: %d AU!", account->balance);
     938                 :            :           else
     939                 :          0 :             mvwprintw(w,  6, 2, "Oh my, you've got: %d AU.", account->balance);
     940                 :            : 
     941         [ #  # ]:          0 :           mvwaddstr(w,  8, 2, " D: Let me look after some money for you");
     942         [ #  # ]:          0 :           mvwaddstr(w,  9, 2, " W: Let me give you some money");
     943         [ #  # ]:          0 :           mvwaddstr(w, 10, 2, " E: Say a fond farewell");
     944         [ #  # ]:          0 :           mvwaddstr(w, 12, 2, "What can I do for you buddy? ");
     945                 :            :         }
     946         [ -  + ]:          1 :       else if (card->blessing < 0)
     947                 :            :         {
     948         [ #  # ]:          0 :           if (account->balance > 0)
     949                 :          0 :             mvwprintw(w,  6, 2, "Muahaha! I've got %d AU!", account->balance);
     950         [ #  # ]:          0 :           else if (account->balance < 0)
     951                 :          0 :             mvwprintw(w,  6, 2, "Muahaha! You're owe me %d AU!", -account->balance);
     952                 :            :           else
     953         [ #  # ]:          0 :             mvwaddstr(w,  6, 2, "Nothing for you here, jerk!");
     954                 :            : 
     955         [ #  # ]:          0 :           mvwaddstr(w,  8, 2, " D: Cough up some more dough");
     956         [ #  # ]:          0 :           mvwaddstr(w,  9, 2, " W: Beg me for some change");
     957         [ #  # ]:          0 :           mvwaddstr(w, 10, 2, " E: Beat it!");
     958         [ #  # ]:          0 :           mvwaddstr(w, 12, 2, "What's your pathetic desire? ");
     959                 :            :         }
     960                 :            :       else
     961                 :            :         {
     962                 :          1 :           mvwprintw(w,  6, 2, "Current balance: %d AU", account->balance);
     963         [ +  - ]:          1 :           mvwaddstr(w,  8, 2, " D: Deposit");
     964         [ +  - ]:          1 :           mvwaddstr(w,  9, 2, " W: Withdraw");
     965         [ +  - ]:          1 :           mvwaddstr(w, 10, 2, " E: Exit");
     966         [ +  - ]:          1 :           mvwaddstr(w, 12, 2, "Enter command: ");
     967                 :            :         }
     968                 :          1 :       wrefresh(w);
     969                 :            : 
     970 [ +  - ][ +  - ]:          1 :       getyx(w, cy, cx);
     971         [ +  - ]:          1 :       response = toupper(mvwgetch(w, cy, cx));
     972                 :            : 
     973         [ -  + ]:          1 :       if ('D' == response)
     974                 :            :         {
     975         [ #  # ]:          0 :           for (idx = 9; idx < 14; ++idx)
     976         [ #  # ]:          0 :             mvwaddstr(w, idx, 2, blank_line);
     977                 :            : 
     978                 :          0 :           bank_deposit(w, account, card);
     979                 :            :         }
     980         [ -  + ]:          1 :       else if ('W' == response)
     981                 :            :         {
     982         [ #  # ]:          0 :           mvwaddstr(w, 8, 2, blank_line);
     983         [ #  # ]:          0 :           for (idx = 10; idx < 14; ++idx)
     984         [ #  # ]:          0 :             mvwaddstr(w, idx, 2, blank_line);
     985                 :            : 
     986                 :          0 :           bank_withdraw(w, account, card);
     987                 :            :         }
     988 [ -  + ][ #  # ]:          1 :       else if ('E' == response || ESCAPE == response)
     989                 :            :         {
     990                 :            :           break;
     991                 :            :         }
     992                 :            :       else
     993                 :            :         {
     994                 :          0 :           beep();
     995                 :            : 
     996         [ #  # ]:          0 :           for (idx = 14; idx < 14; ++idx)
     997         [ #  # ]:          0 :             mvwaddstr(w, idx, 2, blank_line);
     998                 :            : 
     999         [ #  # ]:          0 :           if (card->blessing > 0)
    1000         [ #  # ]:          0 :             mvwaddstr(w, 14, 2, "I'm trying, but I don't know what to do!");
    1001         [ #  # ]:          0 :           else if (card->blessing < 0)
    1002         [ #  # ]:          0 :             mvwaddstr(w, 14, 2, "What the hell do you mean, jerk?");
    1003                 :            :           else
    1004         [ #  # ]:          0 :             mvwaddstr(w, 14, 2, "Invalid entry!");
    1005                 :          0 :           wrefresh(w);
    1006                 :            :         }
    1007                 :            : 
    1008                 :          0 :       dataprint();
    1009                 :          0 :     }
    1010                 :          1 : }
    1011                 :            : 
    1012                 :            : /* the bank -- can be broken into (but you knew that, didn't you?) */
    1013                 :          1 : void l_bank (void)
    1014                 :            : {
    1015                 :            :   /* draw bank window from scratch */
    1016                 :          1 :   werase(Bankw);
    1017                 :            : 
    1018         [ +  - ]:          1 :   wattrset(Bankw, CHARATTR(CLR(WHITE)));
    1019                 :          1 :   wborder(Bankw,
    1020                 :            :           ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,
    1021                 :            :           ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER);
    1022                 :            : 
    1023                 :          1 :   wborder(Bankw, '|', '|', '-', '-', '+', '+', '+', '+');
    1024                 :            : 
    1025         [ +  - ]:          1 :   wattrset(Bankw, CHARATTR(CLR(LIGHT_GREEN)));
    1026         [ +  - ]:          1 :   mvwaddstr(Bankw, 2, 2, "         Welcome to The Bank of Rampart        ");
    1027                 :            : 
    1028                 :            :   /* bank working? or not? */
    1029         [ -  + ]:          1 :   if (gamestatusp(BANK_BROKEN))
    1030                 :            :     {
    1031         [ #  # ]:          0 :       mvwaddstr(Bankw, 9, 2, "            Autoteller Out of Order            ");
    1032                 :          0 :       wrefresh(Bankw);
    1033                 :          0 :       cinema_scene("You see a damaged autoteller.", 0, 0);
    1034                 :            :     }
    1035         [ -  + ]:          1 :   else if (police_are_hostile())
    1036                 :            :     {
    1037         [ #  # ]:          0 :       mvwaddstr(Bankw, 9, 2, "      Autoteller Temporarily Unavailable       ");
    1038                 :          0 :       wrefresh(Bankw);
    1039                 :          0 :       cinema_scene("Apparently the bank is closed.", 0, 0);
    1040                 :            :     }
    1041                 :            :   else
    1042                 :            :     {
    1043                 :            :       int is_new_customer;
    1044                 :            : 
    1045                 :            :       /* first, bank asks if user has an account */
    1046                 :            : 
    1047                 :          1 :       cinema_blank();
    1048                 :          1 :       cinema_print_line(0, "The proximity sensor activates the autoteller as you approach.");
    1049                 :            : 
    1050                 :          1 :       is_new_customer = bank_new_customer(Bankw);
    1051                 :            : 
    1052                 :            :           /* if user says no account, maybe he wants to open one */
    1053                 :            : 
    1054         [ -  + ]:          1 :       if (TRUE == is_new_customer)
    1055                 :            :         {
    1056                 :            :           pob card;
    1057                 :          0 :           card = bank_open_account(Bankw);
    1058                 :            : 
    1059         [ #  # ]:          0 :           if (card)
    1060                 :            :             {
    1061                 :            :               int idx;
    1062                 :            : 
    1063                 :          0 :               cinema_scene("The autoteller produces your new bank card...", 0, 0);
    1064                 :          0 :               gain_item(card);
    1065                 :          0 :               is_new_customer = FALSE;
    1066                 :            : 
    1067         [ #  # ]:          0 :               for (idx = 5; idx < 18; ++idx)
    1068         [ #  # ]:          0 :                 mvwaddstr(Bankw, idx, 2, blank_line);
    1069                 :            : 
    1070         [ #  # ]:          0 :               touchwin(Bankw);
    1071                 :            :             }
    1072                 :            :         }
    1073                 :            : 
    1074         [ +  - ]:          1 :       if (FALSE == is_new_customer)
    1075                 :            :         {
    1076                 :            :           pob card;
    1077                 :            :           int abort;
    1078                 :            :           bank_account *account;
    1079                 :            : 
    1080                 :            :           while (1)
    1081                 :            :             {
    1082                 :          1 :               account = bank_password(Bankw, &card, &abort);
    1083                 :            : 
    1084         [ +  - ]:          1 :               if (account)
    1085                 :            :                 {
    1086                 :            :                   int idx;
    1087                 :            : 
    1088                 :          1 :                   bank_transaction(Bankw, account, card);
    1089                 :            : 
    1090         [ -  + ]:          1 :                   if (card->blessing > 0)
    1091         [ #  # ]:          0 :                     mvwaddstr(Bankw, 4, 2, "            Come back anytime Pal!             ");
    1092         [ -  + ]:          1 :                   else if (card->blessing < 0)
    1093         [ #  # ]:          0 :                     mvwaddstr(Bankw, 4, 2, "  Don't bother coming back, you make me sick!  ");
    1094                 :            :                   else
    1095         [ +  - ]:          1 :                     mvwaddstr(Bankw, 4, 2, "  Thank you for choosing The Bank of Rampart!  ");
    1096                 :            : 
    1097         [ +  + ]:         14 :                   for (idx = 5; idx < 18; ++idx)
    1098         [ +  - ]:         13 :                     mvwaddstr(Bankw, idx, 2, blank_line);
    1099                 :            : 
    1100                 :          1 :                   wrefresh(Bankw);
    1101                 :          1 :                   sleep(3);
    1102                 :          1 :                   break;
    1103                 :            :                 }
    1104                 :            :               else
    1105                 :            :                 {
    1106         [ #  # ]:          0 :                   if (abort) break;
    1107         [ #  # ]:          0 :                   if (police_are_hostile()) break;
    1108                 :            :                 }
    1109                 :          0 :             }
    1110                 :            :         }
    1111                 :            :     }
    1112                 :            : 
    1113         [ +  - ]:          1 :   if (!gamestatusp(BANK_BROKEN)) clearmsg();
    1114                 :            : 
    1115                 :          1 :   xredraw();
    1116                 :          1 : }
    1117                 :            : 
    1118                 :          0 : void bank_init (void)
    1119                 :            : {
    1120                 :            :   int i;
    1121                 :            : 
    1122                 :          0 :   account_number_next = random_range(INT_MAX);
    1123                 :          0 :   account_number_incr = 5 + random_range(100);
    1124                 :            : 
    1125                 :          0 :   bank_create_account(FALSE, random_range(CASH_BALANCE), CASH_PASSWORD);
    1126                 :            : 
    1127                 :          0 :   shuffle(account_num, NUM_NPC_ACCOUNTS);
    1128                 :            : 
    1129         [ #  # ]:          0 :   for(i = 0; i < (3 + random_range(6)); ++i)
    1130                 :            :     {
    1131                 :            :       int which;
    1132                 :          0 :       which = account_num[i];
    1133                 :          0 :       bank_create_account(FALSE,
    1134                 :          0 :                           random_range(npc_account_balances[which]),
    1135                 :            :                           npc_account_passwords[which]);
    1136                 :            :     }
    1137                 :          0 : }
    1138                 :            : 
    1139                 :          0 : int bank_random_account_number (void)
    1140                 :            : {
    1141                 :            :   int which;
    1142                 :            :   int num_accounts;
    1143                 :            :   bank_account *account;
    1144                 :            : 
    1145         [ #  # ]:          0 :   if(!bank)
    1146                 :          0 :     return 0;
    1147                 :            : 
    1148                 :          0 :   num_accounts = 0;
    1149         [ #  # ]:          0 :   for (account = bank; account; account = account->next_account)
    1150                 :            :     {
    1151         [ #  # ]:          0 :       if (FALSE == account->player)
    1152                 :          0 :         ++num_accounts;
    1153                 :            :     }
    1154                 :            : 
    1155                 :          0 :   which = random_range(num_accounts);
    1156                 :            : 
    1157                 :          0 :   num_accounts = 0;
    1158         [ #  # ]:          0 :   for (account = bank; account; account = account->next_account)
    1159                 :            :     {
    1160         [ #  # ]:          0 :       if (FALSE == account->player)
    1161                 :            :         {
    1162         [ #  # ]:          0 :           if (which == num_accounts) break;
    1163                 :          0 :           ++num_accounts;
    1164                 :            :         }
    1165                 :            :     }
    1166                 :            : 
    1167                 :          0 :   return account->number;
    1168                 :            : }

Generated by: LCOV version 1.11