-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIGHT.C
689 lines (652 loc) · 14.3 KB
/
FIGHT.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
/*
* All the fighting gets done here
*
* @(#)fight.c 1.43 (AI Design) 1/19/85
*/
#include "rogue.h"
#include "curses.h"
/*
* fight:
* The player attacks the monster.
*/
fight(mp, mn, weap, thrown)
register coord *mp;
char mn;
register THING *weap;
bool thrown;
{
register THING *tp;
register char *mname;
/*
* Find the monster we want to fight
*/
if ((tp = moat(mp->y, mp->x)) == 0)
return FALSE;
/*
* Since we are fighting, things are not quiet so no healing takes
* place. Cancel any command counts so player can recover.
*/
count = quiet = 0;
start_run(mp);
/*
* Let him know it was really a mimic (if it was one).
*/
if (tp->t_type == 'X' && tp->t_disguise != 'X' && !on(player, ISBLIND)) {
mn = tp->t_disguise = 'X';
if (thrown)
return FALSE;
msg("wait! That's a Xeroc!");
}
mname = monsters[mn-'A'].m_name;
if (on(player, ISBLIND))
mname = it;
if (roll_em(&player, tp, weap, thrown)||(weap && weap->o_type == POTION)) {
bool did_huh = FALSE;
if (thrown)
thunk(weap, mname, "hits", "hit");
else
hit(NULL, mname);
if (weap->o_type == POTION) {
th_effect(weap, tp);
if (!thrown) {
if (weap->o_count > 1)
weap->o_count--;
else {
detach(pack, weap);
discard(weap);
}
cur_weapon = NULL;
}
}
if (on(player, CANHUH)) {
did_huh = TRUE;
tp->t_flags |= ISHUH;
player.t_flags &= ~CANHUH;
msg("your hands stop glowing red");
}
if (tp->t_stats.s_hpt <= 0)
killed(tp, TRUE);
else if (did_huh && !on(player, ISBLIND))
msg("the %s appears confused", mname);
return TRUE;
}
if (thrown)
thunk(weap, mname, "misses", "missed");
else
miss(NULL, mname);
if (tp->t_type == 'S' && rnd(100) > 25)
slime_split(tp);
return FALSE;
}
/*
* attack:
* The monster attacks the player
*/
attack(mp)
THING *mp;
{
register char *mname;
/*
* Since this is an attack, stop running and any healing that was
* going on at the time.
*/
running = FALSE;
count = quiet = 0;
if (mp->t_type == 'X' && !on(player, ISBLIND))
mp->t_disguise = 'X';
mname = monsters[mp->t_type-'A'].m_name;
if (on(player, ISBLIND))
mname = it;
if (roll_em(mp, &player, NULL, FALSE)) {
hit(mname, NULL);
if (pstats.s_hpt <= 0)
death(mp->t_type); /* Bye bye life ... */
if (!on(*mp, ISCANC))
switch (mp->t_type)
{
when 'A':
/*
* If a rust monster hits, you lose armor, unless
* that armor is leather or there is a magic ring
*/
if (cur_armor != NULL && cur_armor->o_ac < 9
&& cur_armor->o_which != LEATHER)
if (ISWEARING(R_SUSTARM))
msg("the rust vanishes instantly");
else
{
msg("your armor weakens, oh my!");
cur_armor->o_ac++;
}
when 'I':
/*
* When an Ice Monster hits you, you get unfrozen faster
*/
if (no_command > 1)
no_command--;
break;
when 'R':
/*
* Rattlesnakes have poisonous bites
*/
if (!save(VS_POISON))
if (!ISWEARING(R_SUSTSTR))
{
chg_str(-1);
msg("you feel a bite in your leg%s",
noterse(" and now feel weaker"));
}
else
msg("a bite momentarily weakens you");
when 'W':
case 'V':
/*
* Wraiths might drain energy levels, and Vampires
* can steal max_hp
*/
if (rnd(100) < (mp->t_type == 'W' ? 15 : 30))
{
register int fewer;
if (mp->t_type == 'W')
{
if (pstats.s_exp == 0)
death('W'); /* All levels gone */
if (--pstats.s_lvl == 0)
{
pstats.s_exp = 0;
pstats.s_lvl = 1;
}
else
pstats.s_exp = e_levels[pstats.s_lvl-1]+1;
fewer = roll(1, 10);
}
else
fewer = roll(1, 5);
pstats.s_hpt -= fewer;
max_hp -= fewer;
if (pstats.s_hpt < 1)
pstats.s_hpt = 1;
if (max_hp < 1)
death(mp->t_type);
msg("you suddenly feel weaker");
}
when 'F':
/*
* Violet fungi stops the poor guy from moving
*/
player.t_flags |= ISHELD;
sprintf(mp->t_stats.s_dmg,"%dd1",++fung_hit);
when 'L':
{
/*
* Leperachaun steals some gold
*/
register long lastpurse;
lastpurse = purse;
purse -= GOLDCALC;
if (!save(VS_MAGIC))
purse -= GOLDCALC + GOLDCALC + GOLDCALC + GOLDCALC;
if (purse < 0)
purse = 0;
remove(&mp->t_pos, mp, FALSE);
if (purse != lastpurse)
msg("your purse feels lighter");
}
when 'N':
{
register THING *obj, *steal;
register int nobj;
char *she_stole = "she stole %s!";
/*
* Nymph's steal a magic item, look through the pack
* and pick out one we like.
*/
steal = NULL;
for (nobj = 0, obj = pack; obj != NULL; obj = next(obj))
if (obj != cur_armor && obj != cur_weapon
&& obj != cur_ring[LEFT] && obj != cur_ring[RIGHT]
&& is_magic(obj) && rnd(++nobj) == 0)
steal = obj;
if (steal != NULL)
{
remove(&mp->t_pos, mp, FALSE);
inpack--;
if (steal->o_count > 1 && steal->o_group == 0)
{
register int oc;
oc = steal->o_count--;
steal->o_count = 1;
msg(she_stole, inv_name(steal, TRUE));
steal->o_count = oc;
}
else
{
detach(pack, steal);
discard(steal);
msg(she_stole, inv_name(steal, TRUE));
}
}
}
otherwise:
break;
}
}
else if (mp->t_type != 'I')
{
if (mp->t_type == 'F')
{
pstats.s_hpt -= fung_hit;
if (pstats.s_hpt <= 0)
death(mp->t_type); /* Bye bye life ... */
}
miss(mname, NULL);
}
flush_type();
count = 0;
status();
}
/*
* swing:
* Returns true if the swing hits
*/
swing(at_lvl, op_arm, wplus)
int at_lvl, op_arm, wplus;
{
register int res = rnd(20);
register int need = (20 - at_lvl) - op_arm;
return (res + wplus >= need);
}
/*
* check_level:
* Check to see if the guy has gone up a level.
*/
check_level()
{
register int i, add, olevel;
for (i = 0; e_levels[i] != 0; i++)
if (e_levels[i] > pstats.s_exp)
break;
i++;
olevel = pstats.s_lvl;
pstats.s_lvl = i;
if (i > olevel)
{
add = roll(i - olevel, 10);
max_hp += add;
if ((pstats.s_hpt += add) > max_hp)
pstats.s_hpt = max_hp;
msg("and achieve the rank of \"%s\"", he_man[i-1]);
}
}
/*
* roll_em:
* Roll several attacks
*/
roll_em(thatt, thdef, weap, hurl)
THING *thatt, *thdef, *weap;
bool hurl;
{
register struct stats *att, *def;
char *cp;
int ndice, nsides, def_arm;
register bool did_hit = FALSE;
register int hplus;
register int dplus;
register int damage;
char *stpchr();
att = &thatt->t_stats;
def = &thdef->t_stats;
if (weap == NULL)
{
cp = att->s_dmg;
dplus = 0;
hplus = 0;
}
else
{
hplus = weap->o_hplus;
dplus = weap->o_dplus;
/*
* Check for vorpally enchanted weapon
*/
if (thdef->t_type == weap->o_enemy)
{
hplus += 4;
dplus += 4;
}
if (weap == cur_weapon)
{
if (ISRING(LEFT, R_ADDDAM))
dplus += cur_ring[LEFT]->o_ac;
else if (ISRING(LEFT, R_ADDHIT))
hplus += cur_ring[LEFT]->o_ac;
if (ISRING(RIGHT, R_ADDDAM))
dplus += cur_ring[RIGHT]->o_ac;
else if (ISRING(RIGHT, R_ADDHIT))
hplus += cur_ring[RIGHT]->o_ac;
}
cp = weap->o_damage;
if (hurl && (weap->o_flags&ISMISL) && cur_weapon != NULL &&
cur_weapon->o_which == weap->o_launch)
{
cp = weap->o_hurldmg;
hplus += cur_weapon->o_hplus;
dplus += cur_weapon->o_dplus;
}
/*
* Drain a staff of striking
*/
if (weap->o_type == STICK && weap->o_which == WS_HIT
&& --weap->o_charges < 0)
{
cp = weap->o_damage = "0d0";
weap->o_hplus = weap->o_dplus = 0;
weap->o_charges = 0;
}
}
/*
* If the creature being attacked is not running (alseep or held)
* then the attacker gets a plus four bonus to hit.
*/
if (!on(*thdef, ISRUN))
hplus += 4;
def_arm = def->s_arm;
if (def == &pstats)
{
if (cur_armor != NULL)
def_arm = cur_armor->o_ac;
if (ISRING(LEFT, R_PROTECT))
def_arm -= cur_ring[LEFT]->o_ac;
if (ISRING(RIGHT, R_PROTECT))
def_arm -= cur_ring[RIGHT]->o_ac;
}
for (;;)
{
ndice = atoi(cp);
if ((cp = stpchr(cp, 'd')) == NULL)
break;
nsides = atoi(++cp);
if (swing(att->s_lvl, def_arm, hplus + str_plus(att->s_str)))
{
register int proll;
proll = roll(ndice, nsides);
damage = dplus + proll + add_dam(att->s_str);
/*
* special goodies for the commercial version of rogue
*/
if (thdef == &player && max_level == 1)
/*
* make it easier on level one
*/
damage = (damage+1) / 2;
/*
* copy protection goodies
*/
if (thdef == &player)
damage *= 1;
def->s_hpt -= max(0, damage);
did_hit = TRUE;
}
if ((cp = stpchr(cp, '/')) == NULL)
break;
cp++;
}
return did_hit;
}
/*
* prname:
* The print name of a combatant
*/
char *
prname(who, upper)
register char *who;
bool upper;
{
*tbuf = '\0';
if (who == 0)
strcpy(tbuf, you);
else if (on(player, ISBLIND))
strcpy(tbuf, it);
else
{
strcpy(tbuf, "the ");
strcat(tbuf, who);
}
if (upper)
*tbuf = toupper(*tbuf);
return tbuf;
}
/*
* hit:
* Print a message to indicate a succesful hit
*/
hit(er, ee)
register char *er, *ee;
{
register char *s;
addmsg(prname(er, TRUE));
switch ((terse || expert) ? 1 : rnd(4))
{
when 0: s = " scored an excellent hit on ";
when 1: s = " hit ";
when 2: s = (er == 0 ? " have injured " : " has injured ");
when 3: s = (er == 0 ? " swing and hit " : " swings and hits ");
}
msg("%s%s",s,prname(ee, FALSE));
}
/*
* miss:
* Print a message to indicate a poor swing
*/
miss(er, ee)
register char *er, *ee;
{
register char *s;
addmsg(prname(er, TRUE));
switch ((terse || expert) ? 1 : rnd(4))
{
when 0: s = (er == 0 ? " swing and miss" : " swings and misses");
when 1: s = (er == 0 ? " miss" : " misses");
when 2: s = (er == 0 ? " barely miss" : " barely misses");
when 3: s = (er == 0 ? " don't hit" : " doesn't hit");
}
msg("%s %s",s,prname(ee, FALSE));
}
/*
* save_throw:
* See if a creature save against something
*/
save_throw(which, tp)
int which;
THING *tp;
{
register int need;
need = 14 + which - tp->t_stats.s_lvl / 2;
return (roll(1, 20) >= need);
}
/*
* save:
* See if he saves against various nasty things
*/
save(which)
register int which;
{
if (which == VS_MAGIC) {
if (ISRING(LEFT, R_PROTECT))
which -= cur_ring[LEFT]->o_ac;
if (ISRING(RIGHT, R_PROTECT))
which -= cur_ring[RIGHT]->o_ac;
}
return save_throw(which, &player);
}
/*
* str_plus:
* Compute bonus/penalties for strength on the "to hit" roll
*/
str_plus(str)
register str_t str;
{
register int add = 4;
if (str < 8)
return str - 7;
if (str < 31)
add--;
if (str < 21)
add--;
if (str < 19)
add--;
if (str < 17)
add--;
return add;
}
/*
* add_dam:
* Compute additional damage done for exceptionally high or low strength
*/
add_dam(str)
register str_t str;
{
int add = 6;
if (str < 8)
return str - 7;
if (str < 31)
add--;
if (str < 22)
add--;
if (str < 20)
add--;
if (str < 18)
add--;
if (str < 17)
add--;
if (str < 16)
add--;
return add;
}
/*
* raise_level:
* The guy just magically went up a level.
*/
raise_level()
{
pstats.s_exp = e_levels[pstats.s_lvl-1] + 1L;
check_level();
}
/*
* thunk:
* A missile hit or missed a monster
*/
thunk(weap, mname, does, did)
register THING *weap;
register char *mname, *does, *did;
{
if (weap->o_type == WEAPON)
addmsg("the %s %s ", w_names[weap->o_which], does);
else
addmsg("you %s ", did);
if (on(player, ISBLIND))
msg(it);
else
msg("the %s", mname);
}
/*
* remove:
* Remove a monster from the screen
*/
remove(mp, tp, waskill)
register coord *mp;
THING *tp;
bool waskill;
{
register THING *obj, *nexti;
if (tp == NULL)
return;
for (obj = tp->t_pack; obj != NULL; obj = nexti)
{
nexti = next(obj);
bcopy(obj->o_pos,tp->t_pos);
detach(tp->t_pack, obj);
if (waskill)
fall(obj, FALSE);
else
discard(obj);
}
if (_level[INDEX(mp->y,mp->x)] == PASSAGE)
standout();
if (tp->t_oldch == FLOOR && !cansee(mp->y, mp->x))
mvaddch(mp->y, mp->x, ' ');
else if (tp->t_oldch != '@')
mvaddch(mp->y, mp->x, tp->t_oldch);
standend();
detach(mlist, tp);
discard(tp);
}
/*
* is_magic:
* Returns true if an object radiates magic
*/
is_magic(obj)
register THING *obj;
{
switch (obj->o_type)
{
case ARMOR:
return obj->o_ac != a_class[obj->o_which];
case WEAPON:
return obj->o_hplus != 0 || obj->o_dplus != 0;
case POTION:
case SCROLL:
case STICK:
case RING:
case AMULET:
return TRUE;
}
return FALSE;
}
/*
* killed:
* Called to put a monster to death
*/
killed(tp, pr)
THING *tp;
bool pr;
{
pstats.s_exp += tp->t_stats.s_exp;
/*
* If the monster was a violet fungi, un-hold him
*/
switch (tp->t_type)
{
when 'F':
player.t_flags &= ~ISHELD;
f_restor();
when 'L':
{
register THING *gold;
if ((gold = new_item()) == NULL)
return;
gold->o_type = GOLD;
gold->o_goldval = GOLDCALC;
if (save(VS_MAGIC))
gold->o_goldval += GOLDCALC + GOLDCALC + GOLDCALC + GOLDCALC;
attach(tp->t_pack, gold);
}
}
/*
* Get rid of the monster.
*/
remove(&tp->t_pos, tp, TRUE);
if (pr)
{
addmsg("you have defeated ");
if (on(player, ISBLIND))
msg(it);
else
msg("the %s", monsters[tp->t_type-'A'].m_name);
}
/*
* Do adjustments if he went up a level
*/
check_level();
}