-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer.c
2008 lines (1762 loc) · 47.2 KB
/
player.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
/* =============================================================================
* PROGRAM: ularn
* FILENAME: player.c
*
* DESCRIPTION:
* This module contains functions to maintain information about the player
* and to process the effects of various actions.
*
* =============================================================================
* EXPORTED VARIABLES
*
* char_class : The name of the player's selected class
* class_num : The number to identify the character class
* ramboflag : Is the character rambo?
* sex : Character's gender
* wizard : The wizard flag
* cheat : Has the player cheated
* char_picked : The character class letter picked
* playerx : The player's current x coordiante
* playery : The player's current y coordinate
* lastpx : The player's previous x coordinate
* lastpy : The player's previous y coordiante
* initialtime : The time play started
* gtime : The clock for the game
* outstanding_taxes : The taxes owed from the score file
* c : The character attributes array
* cbak : The last displayed attributes array
* iven : The inventory items
* ivenarg : The inventory item args
* class : The character class (level) strings
* skill : Experience required for each level
* potionknown : Array indicating potions discovered
* spelknow : Array indicating spells learnt by the player
*
* =============================================================================
* EXPORTED FUNCTIONS
*
* identify_class : Identify the class from the class name
* makeplayer : Make a new player
* moveplayer : Move the player
* player_has_item : Check if the player has a particular item
* raiselevel : Raise experience level
* loselevel : Lose an experience level
* raiseexperience : Increase experience
* loseexperience : Decrease experience
* losehp : Lose hitpoints
* losemhp : Lower max hitpoints
* raisehp : Raise hitpoints
* raisemhp : Increase max hitpoints
* raisespells : Raise spell points
* raisemspells : Raise max spell points
* losespells : Lose spell points
* losemspells : Decrease max spell points
* positionplayer : Position the player on a level
* recalc : Recalculate AC and WC
* take : Take an item
* drop_object : Drop an object
* adjustivenarg : Adjust the ivenarg for an item the player is carrying
* enchantarmour : Enchant armour being worn
* enchweapon : Enchant item being wielded
* pocketfull : Check if pockets are full
* nearbymonst : Check if the player is near a monster
* stealsomething : Steal an item from the player
* emptyhanded : Check if the player is empty handed
* creategem : Creat a gem by the player
* adjustcvalues : Adjust attributes when dropping/losing an item
* packweight : Get the weight of the player's inventory
* adjust_ability : Adjust an ability score
* regen : Regen player for passing of a turn
* removecurse : Remove curses inflicted upon player
* adjusttime : Adjust time base effects for the passage of time
* write_player : Write the player data to the save file
* read_player : Read the player data from the save file
*
* =============================================================================
*/
#include "ularn_game.h"
#include "ularn_win.h"
#include "ularn_ask.h"
#include "header.h"
#include "saveutils.h"
#include "scores.h"
#include "player.h"
#include "monster.h"
#include "dungeon.h"
#include "dungeon_obj.h"
#include "scroll.h"
#include "potion.h"
#include "spell.h"
#include "show.h"
#include "itm.h"
/* =============================================================================
* Exported variables
*/
/*
* class[c[LEVEL]-1] gives the correct name of the player's experience level
*/
static char aa1[] = " mighty evil master";
static char aa2[] = "apprentice demi-god";
static char aa3[] = " minor demi-god ";
static char aa4[] = " major demi-god ";
static char aa5[] = " minor deity ";
static char aa6[] = " major deity ";
static char aa7[] = " novice guardian ";
static char aa8[] = "apprentice guardian";
static char aa9[] = " The Creator ";
char *class[] =
{
" novice explorer ", "apprentice explorer", " practiced explorer", /* -3*/
" expert explorer ", " novice adventurer ", " adventurer ", /* -6*/
"apprentice conjurer", " conjurer ", " master conjurer ", /* -9*/
" apprentice mage ", " mage ", " experienced mage ", /* -12*/
" master mage ", " apprentice warlord", " novice warlord ", /* -15*/
" expert warlord ", " master warlord ", " apprentice gorgon ", /* -18*/
" gorgon ", " practiced gorgon ", " master gorgon ", /* -21*/
" demi-gorgon ", " evil master ", " great evil master ", /* -24*/
aa1, aa1, aa1, /* -27*/
aa1, aa1, aa1, /* -30*/
aa1, aa1, aa1, /* -33*/
aa1, aa1, aa1, /* -36*/
aa1, aa1, aa1, /* -39*/
aa2, aa2, aa2, /* -42*/
aa2, aa2, aa2, /* -45*/
aa2, aa2, aa2, /* -48*/
aa3, aa3, aa3, /* -51*/
aa3, aa3, aa3, /* -54*/
aa3, aa3, aa3, /* -57*/
aa4, aa4, aa4, /* -60*/
aa4, aa4, aa4, /* -63*/
aa4, aa4, aa4, /* -66*/
aa5, aa5, aa5, /* -69*/
aa5, aa5, aa5, /* -72*/
aa5, aa5, aa5, /* -75*/
aa6, aa6, aa6, /* -78*/
aa6, aa6, aa6, /* -81*/
aa6, aa6, aa6, /* -84*/
aa7, aa7, aa7, /* -87*/
aa8, aa8, aa8, /* -90*/
aa8, aa8, aa8, /* -93*/
" earth guardian ", " air guardian ", " fire guardian ", /* -96*/
" water guardian ", " time guardian ", " ethereal guardian ", /* -99*/
aa9, aa9, aa9, /* -102*/
};
/*
* table of experience needed to be a certain level of player
* skill[c[LEVEL]] is the experience required to attain the next level
*/
#define MEG 1000000
long skill[] = {
0, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, /* 1-11 */
10240, 20480, 40960, 100000, 200000, 400000, 700000, 1 * MEG, /* 12-19 */
2 * MEG, 3 * MEG, 4 * MEG, 5 * MEG, 6 * MEG, 8 * MEG, 10 * MEG, /* 20-26 */
12 * MEG, 14 * MEG, 16 * MEG, 18 * MEG, 20 * MEG, 22 * MEG, 24 * MEG, 26 * MEG, 28 * MEG, /* 27-35 */
30 * MEG, 32 * MEG, 34 * MEG, 36 * MEG, 38 * MEG, 40 * MEG, 42 * MEG, 44 * MEG, 46 * MEG, /* 36-44 */
48 * MEG, 50 * MEG, 52 * MEG, 54 * MEG, 56 * MEG, 58 * MEG, 60 * MEG, 62 * MEG, 64 * MEG, /* 45-53 */
66 * MEG, 68 * MEG, 70 * MEG, 72 * MEG, 74 * MEG, 76 * MEG, 78 * MEG, 80 * MEG, 82 * MEG, /* 54-62 */
84 * MEG, 86 * MEG, 88 * MEG, 90 * MEG, 92 * MEG, 94 * MEG, 96 * MEG, 98 * MEG, 100 * MEG, /* 63-71 */
105 * MEG, 110 * MEG, 115 * MEG, 120 * MEG, 125 * MEG, 130 * MEG, 135 * MEG, 140 * MEG, /* 72-79 */
145 * MEG, 150 * MEG, 155 * MEG, 160 * MEG, 165 * MEG, 170 * MEG, 175 * MEG, 180 * MEG, /* 80-87 */
185 * MEG, 190 * MEG, 195 * MEG, 200 * MEG, 210 * MEG, 220 * MEG, 230 * MEG, 240 * MEG, /* 88-95 */
260 * MEG, 280 * MEG, 300 * MEG, 320 * MEG, 340 * MEG, 370 * MEG /* 96-101*/
};
#undef MEG
/*
* Exported variables
*/
char hitflag = 0; /* flag for if player has been hit when running */
char hit2flag = 0; /* flag for if player has been hit when running */
char hit3flag = 0; /* flag for if player has been hit flush input*/
char char_class[20]; /* character class */
int class_num; /* character class number */
char ramboflag = 0;
char sex = 1; /* default is man, 0=woman */
char wizard = 0; /* the wizard mode flag */
char cheat = 0; /* 1 if the player has fudged save file */
char char_picked; /* the character chosen */
int playerx, playery; /* the room on the present level of the player*/
int lastpx, lastpy; /* 0 --- MAXX-1 or 0 --- MAXY-1 */
time_t initialtime = 0; /* time playing began */
long gtime = 0; /* the clock for the game */
long outstanding_taxes = 0; /* present tax bill from score file */
long c[ATTRIBUTE_COUNT]; /* Character description array */
long cbak[ATTRIBUTE_COUNT]; /* Backup array for detecting changes */
char iven[IVENSIZE]; /* inventory for player */
short ivenarg[IVENSIZE]; /* inventory args for player */
int potionknown[MAXPOTION];
int scrollknown[MAXSCROLL];
int spelknow[SPELL_COUNT];
/* =============================================================================
* Local variables
*/
#define MAXPLEVEL 100 /* maximum player level allowed */
/*
* Haste step to keep track of frations of moves when hasted
*/
static int HasteStep = 0;
/*
* Character fields affected by the passage of time
*/
#define TIME_CHANGED_COUNT 28
static AttributeType time_change[TIME_CHANGED_COUNT] =
{
HERO,
ALTPRO,
PROTECTIONTIME,
DEXCOUNT,
STRCOUNT,
GIANTSTR,
CHARMCOUNT,
INVISIBILITY,
CANCELLATION,
HASTESELF,
AGGRAVATE,
SCAREMONST,
STEALTH,
AWARENESS,
HOLDMONST,
HASTEMONST,
FIRERESISTANCE,
GLOBE,
SPIRITPRO,
UNDEADPRO,
HALFDAM,
SEEINVISIBLE,
ITCHING,
CLUMSINESS,
WTW,
COKED,
BLINDCOUNT,
CONFUSE
};
/*
* Character fields for curses
*/
#define CURSE_COUNT 10
static AttributeType curse[CURSE_COUNT] =
{
BLINDCOUNT,
CONFUSE,
AGGRAVATE,
HASTEMONST,
ITCHING,
LAUGHING,
DRAINSTRENGTH,
CLUMSINESS,
INFEEBLEMENT,
HALFDAM
};
#define MAX_CLASSES 8
#define MAX_INITIAL_SPELLS 2
#define MAX_INITIAL_ITEMS 3
struct InitialClassDataType {
char *ClassName;
long Attr[6];
int InitialSP;
int InitialHP;
SpellType KnownSpells[MAX_INITIAL_SPELLS];
int Item[MAX_INITIAL_ITEMS];
int ItemArg[MAX_INITIAL_ITEMS];
int WearItem;
int WieldItem;
};
static struct InitialClassDataType InitialClassData[MAX_CLASSES] =
{
{
"Ogre", /* Class name */
{ 18, 4, 6, 16, 6, 4 }, /* STR, INT, WIS, CON, DEX, CHA */
1, 16, /* SP, HP */
{ SPELL_MLE, SPELL_COUNT }, /* Spells */
{ OPOTION, OPOTION, ONOTHING }, /* Items */
{ -6, -6, 0 }, /* Item args */
-1, -1 /* Wear, Wield*/
},
{
"Wizard", /* Class name */
{ 8, 16, 16, 6, 6, 8 }, /* STR, INT, WIS, CON, DEX, CHA */
2, 8, /* SP, HP */
{ SPELL_MLE, SPELL_CHM }, /* Spells */
{ OPOTION, OSCROLL, OSCROLL }, /* Items */
{ PTREASURE, -6, -6 }, /* Item args */
-1, -1 /* Wear, Wield */
},
{
"Klingon", /* Class name */
{ 14, 12, 4, 12, 8, 3 }, /* STR, INT, WIS, CON, DEX, CHA */
1, 14, /* SP, HP */
{ SPELL_SSP, SPELL_COUNT }, /* Spells */
{ OSTUDLEATHER, OPOTION, ONOTHING }, /* Items */
{ 0, -6, 0 }, /* Item args */
0, -1 /* Wear, Wield */
},
{
"Elf", /* Class name */
{ 8, 14, 12, 8, 8, 14 }, /* STR, INT, WIS, CON, DEX, CHA */
2, 8, /* SP, HP */
{ SPELL_MLE, SPELL_COUNT }, /* Spells */
{ OLEATHER, OSCROLL, ONOTHING }, /* Items */
{ 0, -6, 0 }, /* Item args */
0, -1 /* Wear, Wield */
},
{
"Rogue", /* Class name */
{ 8, 12, 8, 10, 14, 6 }, /* STR, INT, WIS, CON, DEX, CHA */
1, 12, /* SP, HP */
{ SPELL_MLE, SPELL_COUNT }, /* Spells */
{ OLEATHER, ODAGGER, OSCROLL }, /* Items */
{ 0, 0, SSTEALTH }, /* Item args */
0, 1 /* Wield, wear */
},
{
"Adventurer", /* Class name */
{ 12, 12, 12, 12, 12, 12 }, /* STR, INT, WIS, CON, DEX, CHA */
1, 10, /* SP, HP */
{ SPELL_PRO, SPELL_MLE }, /* Spells */
{ OLEATHER, ODAGGER, ONOTHING }, /* Items */
{ 0, 0, 0 }, /* Item args */
0, 1 /* Wear, Wield */
},
{
"Dwarf", /* Class name */
{ 16, 6, 8, 16, 4, 4 }, /* STR, INT, WIS, CON, DEX, CHA */
1, 12, /* SP, HP */
{ SPELL_PRO, SPELL_COUNT }, /* Spells */
{ OSPEAR, ONOTHING, ONOTHING }, /* Items */
{ 0, 0, 0 }, /* Item args */
-1, 0 /* Wear, Wield */
},
{
"Rambo", /* Class name */
{ 3, 3, 3, 3, 3, 3 }, /* STR, INT, WIS, CON, DEX, CHA */
0, 1, /* SP, HP */
{ SPELL_MLE, SPELL_COUNT }, /* Spells */
{ OLANCE, ONOTHING, ONOTHING }, /* Items */
{ 0, 0, 0 }, /* Item args */
-1, 0 /* Wear, Wield */
}
};
/* =============================================================================
* Local functions
*/
/* =============================================================================
* FUNCTION: pick_char
*
* DESCRIPTION:
* Pick the player's character class and set initial attributes and inventory.
*
* PARAMETERS:
*
* foo : This is the character selection specified in the ularn opts file.
* If no character is specified then this should be set to 0.
* If a character is selected then this should be set to the key
* selection for the character ('a' .. 'h').
*
* RETURN VALUE:
*
* None.
*/
static void pick_char(int foo)
{
int i;
int j;
set_display(DISPLAY_TEXT);
nosignal = 1; /* disable signals */
if (foo == 0) {
ClearText();
MoveCursor(29, 1);
Standout("The Addiction of VLarn\n\n");
Print("Pick a character class...\n\n");
Print("\ta) Ogre - Exceptional strength, but thick as a brick\n");
Print("\n");
Print("\tb) Wizard - Smart, good at magic, but very weak\n");
Print("\n");
Print("\tc) Klingon - Strong and average IQ, but unwise & very ugly\n");
Print("\n");
Print("\td) Elf - OK at magic, but a mediocre fighter\n");
Print("\n");
Print("\te) Rogue - Nimble and smart, but only average strength\n");
Print("\n");
Print("\tf) Adventurer - Jack of all trades, master of none\n");
Print("\n");
Print("\tg) Dwarf - Strong and healthy, but not good at magic\n");
Print("\n");
Print("\th) Rambo - A special challenge.\n");
Print("\t Bad at everything, but has a lance of death");
MoveCursor(1, 24);
i = get_prompt_input("So, what are ya? ", "abcdefgh", 1);
}else {
//
// Character selected in ops
//
i = foo;
c[SHIELD] = c[WEAR] = c[WIELD] = -1;
}
i = i - 'a';
class_num = i;
strcpy(char_class, InitialClassData[i].ClassName);
c[SPELLMAX] = InitialClassData[i].InitialSP;
c[SPELLS] = InitialClassData[i].InitialSP;
c[HPMAX] = InitialClassData[i].InitialHP;
c[HP] = InitialClassData[i].InitialHP;;
for (j = ABILITY_FIRST; j <= ABILITY_LAST; j++)
c[j] = InitialClassData[i].Attr[j - ABILITY_FIRST];
for (j = 0; j < MAX_INITIAL_SPELLS; j++)
if (InitialClassData[i].KnownSpells[j] < SPELL_COUNT)
spelknow[InitialClassData[i].KnownSpells[j]] = 1;
for (j = 0; j < MAX_INITIAL_ITEMS; j++) {
iven[j] = (char)InitialClassData[i].Item[j];
if (iven[j] == OLANCE) {
c[LANCEDEATH] = 1;
ramboflag = 1;
}
if (InitialClassData[i].ItemArg[j] >= 0)
ivenarg[j] = (short)InitialClassData[i].ItemArg[j];
else
ivenarg[j] = (short)rund(-InitialClassData[i].ItemArg[j]);
}
c[WEAR] = InitialClassData[i].WearItem;
c[WIELD] = InitialClassData[i].WieldItem;
nosignal = 0;
} /* end pick_char */
/* =============================================================================
* Exported functions
*/
/* =============================================================================
* FUNCTION: identify_class
*/
char identify_class(char *class_str)
{
int cls;
int found;
int i;
int len;
char class_cmp_str[20];
if (class_str == NULL)
/* no class string specified */
return 0;
len = strlen(class_str);
for (i = 0; i < len; i++)
class_str[i] = (char)tolower(class_str[i]);
cls = 0;
found = 0;
while ((cls < MAX_CLASSES) && (!found)) {
strcpy(class_cmp_str, InitialClassData[cls].ClassName);
len = strlen(class_cmp_str);
for (i = 0; i < len; i++)
class_cmp_str[i] = (char)tolower(class_cmp_str[i]);
if (strcmp(class_str, class_cmp_str) == 0)
found = 1;
else
cls++;
}
if (cls < MAX_CLASSES)
return (char)('a' + cls);
else
return 0;
}
/* =============================================================================
* FUNCTION: makeplayer
*/
void makeplayer(void)
{
int i;
/*
* Clear the player's attributes
*/
for (i = 0; i < ATTRIBUTE_COUNT; i++) {
c[i] = 0;
cbak[i] = 0;
}
/*
* Clear the player's inventory
*/
for (i = 0; i < IVENSIZE; i++) {
iven[i] = ONOTHING;
ivenarg[i] = 0;
}
/* Clear spells, potions and scrolls known */
for (i = 0; i < MAXPOTION; i++)
potionknown[i] = 0;
for (i = 0; i < MAXSCROLL; i++)
scrollknown[i] = 0;
for (i = 0; i < SPELL_COUNT; i++)
spelknow[i] = 0;
c[LEVEL] = 1; /* player starts at level one */
c[REGENCOUNTER] = 16;
c[ECOUNTER] = 96; /* start regeneration correctly */
c[SHIELD] = -1;
c[WEAR] = -1;
c[WIELD] = -1;
if (char_picked >= 'a' && char_picked <= 'h')
/* Class specified on command line */
pick_char(char_picked);
else
/* Ask for the class */
pick_char(0);
/*
* Position the player in the home level
*/
playerx = (char)rnd(MAXX - 2);
playery = (char)rnd(MAXY - 2);
lastpx = 0;
lastpy = 0;
/* time clock starts at zero */
gtime = 0;
cbak[SPELLS] = -50;
recalc();
}
/* =============================================================================
* FUNCTION: moveplayer
*/
int moveplayer(int dir)
{
int k, m, i, j;
if (c[CONFUSE]) {
if (c[LEVEL] < rnd(30)) {
dir = rund(9); /*if confused any dir*/
}
}
k = playerx + diroffx[dir];
m = playery + diroffy[dir];
if ((k < 0) || (k >= MAXX) || (m < 0) || (m >= MAXY)) {
nomove = 1;
yrepcount = 0;
return 0;
}
i = item[k][m];
j = mitem[k][m].mon;
/* hit a wall */
if ((i == OWALL) && (c[WTW] == 0)) {
nomove = 1;
yrepcount = 0;
return 0;
}
/* Can't move onto closed doors if using the enhanced interface */
if ((enhance_interface) && (i == OCLOSEDDOOR)) {
nomove = 1;
yrepcount = 0;
return 0;
}
if ((k == 33) && (m == MAXY - 1) && (level == 1)) {
newcavelevel(0);
/*
* Returning to the home level from the dungeon, so find the
* dungeon entrance and locate the player at the dungeon entrance.
*/
for (k = 0; k < MAXX; k++) {
for (m = 0; m < MAXY; m++) {
if (item[k][m] == OENTRANCE) {
playerx = (char)k;
playery = (char)m;
positionplayer();
drawscreen();
return 0;
}
}
}
}
if (j > 0) {
hitmonster(k, m);
yrepcount = 0;
return 0;
} /* hit a monster*/
lastpx = playerx;
lastpy = playery;
playerx = (char)k;
playery = (char)m;
if ((i != ONOTHING) &&
(i != OTRAPARROWIV) &&
(i != OIVTELETRAP) &&
(i != OIVDARTRAP) &&
(i != OIVTRAPDOOR)) {
yrepcount = 0;
return 0;
}else
return 1;
}
/* =============================================================================
* FUNCTION: player_has_item
*/
int player_has_item(int Item)
{
int i;
int have_item;
have_item = 0;
for (i = 0; i < IVENSIZE; i++)
if (iven[i] == Item)
have_item = 1;
return have_item;
}
/* =============================================================================
* FUNCTION: raiselevel
*/
void raiselevel(void)
{
if (c[LEVEL] < MAXPLEVEL)
raiseexperience((long)(skill[c[LEVEL]] - c[EXPERIENCE]));
}
/* =============================================================================
* FUNCTION: loselevel
*/
void loselevel(void)
{
if (c[LEVEL] > 1)
loseexperience((long)(c[EXPERIENCE] - skill[c[LEVEL] - 1] + 1));
}
/* =============================================================================
* FUNCTION: raiseexperience
*/
void raiseexperience(long x)
{
int i, tmp;
i = c[LEVEL];
c[EXPERIENCE] += x;
while (c[EXPERIENCE] >= skill[c[LEVEL]] && (c[LEVEL] < MAXPLEVEL)) {
tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1;
c[LEVEL]++;
raisemhp((int)(rnd(3) + rnd((tmp > 0)?tmp:1)));
raisemspells((int)rund(3));
if (c[LEVEL] < 7 - c[HARDGAME])
raisemhp((int)(c[CONSTITUTION] >> 2));
}
if (c[LEVEL] != i) {
/* Alert the player to level up */
UlarnBeep();
Printf("\nWelcome to level %d!", (long)c[LEVEL]);
/* if we changed levels */
switch ((int)c[LEVEL]) {
case 94: /* earth guardian */
c[WTW] = 99999L;
break;
case 95: /* air guardian */
c[INVISIBILITY] = 99999L;
break;
case 96: /* fire guardian */
c[FIRERESISTANCE] = 99999L;
break;
case 97: /* water guardian */
c[CANCELLATION] = 99999L;
break;
case 98: /* time guardian */
c[HASTESELF] = 99999L;
break;
case 99: /* ethereal guardian */
c[STEALTH] = 99999L;
c[SPIRITPRO] = 99999L;
break;
case 100:
Print("\nYou are now The Creator!");
{
int i, j;
for (i = 0; i < MAXY; i++) for (j = 0; j < MAXX; j++) know[j][i] = item[j][i];
for (i = 0; i < SPELL_COUNT; i++) spelknow[i] = 1;
for (i = 0; i < MAXSCROLL; i++) scrollknown[i] = 1;
for (i = 0; i < MAXPOTION; i++) potionknown[i] = 1;
}
break;
default:
break;
}
}
UpdateStatusAndEffects();
}
/* =============================================================================
* FUNCTION: loseexperience
*/
void loseexperience(long x)
{
int i, tmp;
i = c[LEVEL];
c[EXPERIENCE] -= x;
if (c[EXPERIENCE] < 0) c[EXPERIENCE] = 0;
while (c[EXPERIENCE] < skill[c[LEVEL] - 1]) {
if (--c[LEVEL] <= 1) c[LEVEL] = 1; /* down one level */
tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1; /* lose hpoints */
losemhp((int)rnd((tmp > 0)?tmp:1)); /* lose hpoints */
if (c[LEVEL] < 7 - c[HARDGAME]) losemhp((int)(c[CONSTITUTION] >> 2));
losemspells((int)rund(3)); /* lose spells */
}
if (i != c[LEVEL])
Printf("\nYou went down to level %d!", (long)c[LEVEL]);
recalc();
UpdateStatus();
}
/* =============================================================================
* FUNCTION: losehp
*/
void losehp(DiedReasonType Reason, int x)
{
if ((c[HP] -= x) <= 0) {
UlarnBeep();
Print("\nAlas, you have died.\n");
Print("\n");
nap(3000);
if ((Reason == DIED_MONSTER) && (last_monst_id == MONST_NONE))
Reason = DIED_UNSEEN_ATTACKER;
died(Reason, last_monst_id);
}
}
/* =============================================================================
* FUNCTION: losemhp
*/
void losemhp(int x)
{
c[HP] -= x;
if (c[HP] < 1) c[HP] = 1;
c[HPMAX] -= x;
if (c[HPMAX] < 1) c[HPMAX] = 1;
}
/* =============================================================================
* FUNCTION: raisehp
*/
void raisehp(int x)
{
if ((c[HP] += x) > c[HPMAX])
c[HP] = c[HPMAX];
}
/* =============================================================================
* FUNCTION: raisemhp
*/
void raisemhp(int x)
{
c[HPMAX] += x;
c[HP] += x;
}
/* =============================================================================
* FUNCTION: raisespells
*/
void raisespells(int x)
{
if ((c[SPELLS] += x) > c[SPELLMAX])
c[SPELLS] = c[SPELLMAX];
}
/* =============================================================================
* FUNCTION: raisemspells
*/
void raisemspells(int x)
{
c[SPELLMAX] += x;
c[SPELLS] += x;
}
/* =============================================================================
* FUNCTION: losespells
*/
void losespells(int x)
{
if ((c[SPELLS] -= x) < 0)
c[SPELLS] = 0;
}
/* =============================================================================
* FUNCTION: losemspells
*/
void losemspells(int x)
{
if ((c[SPELLMAX] -= x) < 0)
c[SPELLMAX] = 0;
if ((c[SPELLS] -= x) < 0)
c[SPELLS] = 0;
}
/* =============================================================================
* FUNCTION: positionplayer
*/
void positionplayer(void)
{
int x, y;
int cx = 0, cy = 0;
int dist, closest;
if ((item[playerx][playery] == ONOTHING) &&
(mitem[playerx][playery].mon == MONST_NONE))
/* location is clear, so nothing to do */
return;
closest = 10000;
for (x = 0; x < MAXX; x++) {
for (y = 0; y < MAXY; y++) {
if ((item[x][y] == ONOTHING) &&
(mitem[x][y].mon == MONST_NONE)) {
/*
* This location is empty, so see how far it is from the desired
* location.
*/
dist = (playerx - x) * (playerx - x) + (playery - y) * (playery - y);
if (dist < closest) {
/* This is the closest location found so far */
cx = x;
cy = y;
closest = dist;
}
}
}
}
if (closest == 10000)
Print("Failure in positionplayer\n");
else{
playerx = cx;
playery = cy;
}
}
/* =============================================================================
* FUNCTION: recalc
*/
void recalc(void)
{
int i;
c[AC] = c[MOREDEFENSES];
if (c[WEAR] >= 0) {
switch (iven[c[WEAR]]) {
case OSHIELD:
c[AC] += 2 + ivenarg[c[WEAR]];
break;
case OLEATHER:
c[AC] += 2 + ivenarg[c[WEAR]];
break;
case OSTUDLEATHER:
c[AC] += 3 + ivenarg[c[WEAR]];
break;
case ORING:
c[AC] += 5 + ivenarg[c[WEAR]];
break;
case OCHAIN:
c[AC] += 6 + ivenarg[c[WEAR]];
break;
case OSPLINT:
c[AC] += 7 + ivenarg[c[WEAR]];
break;
case OPLATE:
c[AC] += 9 + ivenarg[c[WEAR]];
break;
case OPLATEARMOR:
c[AC] += 10 + ivenarg[c[WEAR]];
break;
case OSSPLATE:
c[AC] += 12 + ivenarg[c[WEAR]];
break;
case OELVENCHAIN:
c[AC] += 15 + ivenarg[c[WEAR]];
break;
default:
break;
}
}
if (c[SHIELD] >= 0 && iven[c[SHIELD]] == OSHIELD)
c[AC] += 2 + ivenarg[c[SHIELD]];
c[LANCEDEATH] = 0;
if (c[WIELD] < 0)
c[WCLASS] = 0;
else{
i = ivenarg[c[WIELD]];
switch (iven[c[WIELD]]) {
case ODAGGER:
c[WCLASS] = 3 + i;
break;
case OBELT:
c[WCLASS] = 7 + i;
break;
case OSHIELD:
c[WCLASS] = 8 + i;
break;
case OPSTAFF:
case OSPEAR:
c[WCLASS] = 10 + i;
break;
case OFLAIL:
c[WCLASS] = 14 + i;
break;
case OBATTLEAXE:
c[WCLASS] = 17 + i;
break;
case OLANCE:
c[LANCEDEATH] = 1;
c[WCLASS] = 20 + i;
break;
case OLONGSWORD:
case OVORPAL:
c[WCLASS] = 22 + i;
break;
case O2SWORD:
c[WCLASS] = 26 + i;
break;
case OSWORDofSLASHING:
c[WCLASS] = 30 + i;
break;
case OSLAYER:
c[WCLASS] = 30 + i;
break;