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