comparison arogue7/fight.c @ 125:adfa37e67084

Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
author John "Elwin" Edwards
date Fri, 08 May 2015 15:24:40 -0400
parents
children b786053d2f37
comparison
equal deleted inserted replaced
124:d10fc4a065ac 125:adfa37e67084
1 /*
2 * fight.c - All the fighting gets done here
3 *
4 * Advanced Rogue
5 * Copyright (C) 1984, 1985, 1986 Michael Morgan, Ken Dalka and AT&T
6 * All rights reserved.
7 *
8 * Based on "Rogue: Exploring the Dungeons of Doom"
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * All rights reserved.
11 *
12 * See the file LICENSE.TXT for full copyright and licensing information.
13 */
14
15 /*
16 * All the fighting gets done here
17 *
18 */
19
20 #include "curses.h"
21 #include <ctype.h>
22 #include "rogue.h"
23
24 int hit(struct object *weapon, bool see_att, bool see_def, char *er, char *ee, bool back_stab, bool thrown, bool short_msg);
25 #define CONF_DAMAGE -1
26 #define PARAL_DAMAGE -2
27 #define DEST_DAMAGE -3
28 #define DRAIN_DAMAGE -4
29
30 /*
31 * returns true if player has a any chance to hit the monster
32 */
33 player_can_hit(tp, weap)
34 register struct thing *tp;
35 register struct object *weap;
36 {
37 if (off(*tp, CMAGICHIT) && off(*tp, BMAGICHIT) && off(*tp, MAGICHIT))
38 return(TRUE);
39 if (weap && weap->o_type == RELIC)
40 return(TRUE);
41 if (on(*tp, CMAGICHIT) && weap && (weap->o_hplus>2 || weap->o_dplus>2))
42 return(TRUE);
43 if (on(*tp, BMAGICHIT) && weap && (weap->o_hplus>1 || weap->o_dplus>1))
44 return(TRUE);
45 if (on(*tp, MAGICHIT) && weap && (weap->o_hplus>0 || weap->o_dplus>0))
46 return(TRUE);
47 if (player.t_ctype == C_MONK) {
48 if (on(*tp, CMAGICHIT) && pstats.s_lvl > 15)
49 return(TRUE);
50 if (on(*tp, BMAGICHIT) && pstats.s_lvl > 10)
51 return(TRUE);
52 if (on(*tp, MAGICHIT) && pstats.s_lvl > 5)
53 return(TRUE);
54 }
55 return(FALSE);
56 }
57
58 /*
59 * fight:
60 * The player attacks the monster.
61 */
62
63 fight(mp, weap, thrown)
64 register coord *mp;
65 struct object *weap;
66 bool thrown;
67 {
68 register struct thing *tp;
69 register struct linked_list *item;
70 register bool did_hit = TRUE;
71 bool see_def, back_stab = FALSE;
72 register char *mname;
73
74 /*
75 * Find the monster we want to fight
76 */
77 if ((item = find_mons(mp->y, mp->x)) == NULL) {
78 return(FALSE); /* must have killed him already */
79 }
80 tp = THINGPTR(item);
81
82 /*
83 * Since we are fighting, things are not quiet so no healing takes
84 * place. The -1 also tells us that we are in a fight.
85 */
86 player.t_quiet = -1;
87 tp->t_quiet = -1;
88
89 see_def = ((off(*tp, ISINVIS) || on(player, CANSEE)) &&
90 (off(*tp, ISSHADOW) || on(player, CANSEE)) &&
91 (!thrown || cansee(unc(tp->t_pos))));
92
93 mname = see_def ? monster_name(tp) : "something";
94
95 /*
96 * if its in the wall, we can't hit it
97 */
98 if (on(*tp, ISINWALL) && off(player, CANINWALL))
99 return(FALSE);
100
101 if (on(*tp, ISSTONE)) {
102 killed(item, FALSE, FALSE, FALSE);
103 if (see_def)
104 msg("%s shatters into a million pieces!", prname(mname, TRUE));
105 count = 0;
106 return (TRUE);
107 }
108 /*
109 * Let him know it was really a mimic (if it was one).
110 */
111 if (on(*tp, ISDISGUISE) && (tp->t_type != tp->t_disguise) &&
112 off(player, ISBLIND))
113 {
114 if (see_def) {
115 msg("Wait! That's a %s!", mname);
116 turn_off(*tp, ISDISGUISE);
117 }
118 did_hit = thrown;
119 }
120 if (on(*tp, CANSURPRISE) && off(player, ISBLIND) && !ISWEARING(R_ALERT)) {
121 if (see_def) {
122 msg("Wait! There's a %s!", mname);
123 turn_off(*tp, CANSURPRISE);
124 }
125 did_hit = thrown;
126 }
127
128 /*
129 * if he's a thief or assassin and the creature is asleep then he gets
130 * a chance for a backstab
131 */
132 if ((player.t_ctype == C_THIEF || player.t_ctype == C_ASSASIN) &&
133 !thrown &&
134 !on(*tp, NOSTAB) &&
135 !invisible(tp) &&
136 (!on(*tp, ISRUN) || on(*tp, ISHELD) || tp->t_action == A_FREEZE))
137 back_stab = TRUE;
138
139 /*
140 * assassins get an assassination chance, if it fails then its normal
141 * damage
142 */
143 if (back_stab && player.t_ctype == C_ASSASIN) {
144 int chance;
145
146 chance = 50 + (pstats.s_lvl - tp->t_stats.s_lvl) * 5;
147 if (cur_weapon && (cur_weapon->o_flags & ISPOISON))
148 chance += 20;
149 if (roll(1,100) > chance || on(*tp, ISUNIQUE))
150 back_stab = FALSE;
151 }
152
153 runto(tp, &hero);
154
155 /* Let the monster know that the player has missiles! */
156 if (thrown) tp->t_wasshot = TRUE;
157
158 if (did_hit)
159 {
160
161 did_hit = FALSE;
162 if (!can_blink(tp) &&
163 player_can_hit(tp, weap) &&
164 roll_em(&player, tp, weap, thrown, cur_weapon, back_stab))
165 {
166 did_hit = TRUE;
167
168 if (on(*tp, NOMETAL) && weap != NULL &&
169 weap->o_type != RELIC && weap->o_flags & ISMETAL) {
170 msg("Your %s passes right through %s!",
171 weaps[weap->o_which].w_name, prname(mname, FALSE));
172 }
173 else if (weap != NULL && weap->o_type == MISSILE && on(*tp, CARRYBAMULET)) {
174 msg("The magic missile has no affect on %s",
175 prname(mname, FALSE));
176 }
177 else {
178 hit(thrown ? NULL : weap,
179 TRUE, see_def,
180 thrown ? weap_name(weap) : NULL,
181 mname, back_stab, thrown, terse);
182
183 /* See if there are any special effects */
184 if (effect(&player, tp, weap, thrown, TRUE, see_def) != 0)
185 killed(item, FALSE, FALSE, TRUE);
186
187 /*
188 * Merchants just disappear if hit
189 */
190 else if (on(*tp, CANSELL)) {
191 if (see_def)
192 msg("%s disappears with his wares in a flash.",
193 prname(mname, FALSE));
194 killed(item, FALSE, FALSE, FALSE);
195 }
196
197 else if (tp->t_stats.s_hpt <= 0)
198 killed(item, TRUE, TRUE, TRUE);
199
200 else {
201 /* If the victim was charmed, it now gets a saving throw! */
202 if (on(*tp, ISCHARMED) && save(VS_MAGIC, tp, 0)) {
203 msg("The eyes of %s turn clear.", prname(mname, FALSE));
204 turn_off(*tp, ISCHARMED);
205 }
206
207 dsrpt_monster(tp, FALSE, see_def); /* Disrupt a spell? */
208 }
209 }
210 }
211 else {
212 miss(thrown ? NULL : weap,
213 TRUE, see_def,
214 thrown ? weap_name(weap) : NULL,
215 mname, thrown, terse);
216 }
217 }
218 count = 0;
219 return did_hit;
220 }
221
222 /*
223 * attack:
224 * The monster attacks the player
225 */
226
227 attack(mp, weapon, thrown)
228 register struct thing *mp;
229 register struct object *weapon;
230 bool thrown;
231 {
232 register char *mname;
233 register bool see_att, did_hit = FALSE;
234 register struct object *wielded; /* The wielded weapon */
235 struct linked_list *get_wield; /* Linked list header for wielded */
236
237 /*
238 * Since this is an attack, stop running and any healing that was
239 * going on at the time. The -1 also tells us that we're fighting.
240 */
241 running = FALSE;
242 player.t_quiet = -1;
243 mp->t_quiet = -1;
244
245 if (on(*mp, ISDISGUISE) && off(player, ISBLIND))
246 turn_off(*mp, ISDISGUISE);
247
248 see_att = ((off(*mp, ISINVIS) || on(player, CANSEE)) &&
249 (off(*mp, ISSHADOW) || on(player, CANSEE)) &&
250 (!thrown || cansee(unc(mp->t_pos))));
251
252 mname = see_att ? monster_name(mp) : "something";
253
254 /*
255 * Try to find a weapon to wield. Wield_weap will return a
256 * projector if weapon is a projectile (eg. bow for arrow).
257 * If weapon is NULL, it will try to find a suitable weapon.
258 */
259 get_wield = wield_weap(weapon, mp);
260 if (get_wield) wielded = OBJPTR(get_wield);
261 else wielded = NULL;
262
263 /* If we aren't wielding a weapon, wield what we found (could be NULL) */
264 if (weapon == NULL) weapon = wielded;
265
266 if (roll_em(mp, &player, weapon, thrown, wielded, FALSE)) {
267 int death_type; /* From one of the effects of getting hit */
268
269 did_hit = TRUE;
270
271 if (weapon != NULL && weapon->o_type == MISSILE && cur_relic[STONEBONES_AMULET]) {
272 hit(weapon, see_att, TRUE, mname, NULL, FALSE, thrown, terse);
273 msg("Your amulet seems to absorb the magic missile");
274 }
275 else {
276 hit(weapon, see_att, TRUE, mname, NULL, FALSE, thrown, terse);
277 dsrpt_player(); /* see if we disrupted some activity */
278 if (pstats.s_hpt <= 0)
279 death(mp->t_index); /* Bye bye life ... */
280 death_type = effect(mp, &player, weapon, thrown, see_att, TRUE);
281 if (death_type != 0) death(death_type);
282 }
283
284 }
285 else {
286 /* If the thing was trying to surprise, no good */
287 if (on(*mp, CANSURPRISE)) turn_off(*mp, CANSURPRISE);
288
289 /* If it couldn't surprise, let's tell the player. */
290 else miss(weapon, see_att, TRUE, mname, NULL, thrown, terse);
291 }
292 if (fight_flush) md_flushinp();
293 count = 0;
294 status(FALSE);
295 return(did_hit);
296 }
297
298 /*
299 * swing:
300 * returns true if the swing hits
301 */
302
303 swing(class, at_lvl, op_arm, wplus)
304 short class;
305 int at_lvl, op_arm, wplus;
306 {
307 register int res = rnd(20)+1;
308 register int need;
309
310 need = char_class[class].base -
311 char_class[class].factor *
312 ((min(at_lvl, char_class[class].max_lvl) -
313 char_class[class].offset)/char_class[class].range) +
314 (10 - op_arm);
315 if (need > 20 && need <= 25) need = 20;
316
317 return (res+wplus >= need);
318 }
319
320 /*
321 * roll_em:
322 * Roll several attacks
323 */
324
325 roll_em(att_er, def_er, weap, hurl, cur_weapon, back_stab)
326 struct thing *att_er, *def_er;
327 struct object *weap;
328 bool hurl;
329 struct object *cur_weapon;
330 bool back_stab;
331 {
332 register struct stats *att, *def;
333 register char *cp;
334 register int ndice, nsides, nplus, def_arm;
335 bool did_hit = FALSE;
336 int prop_hplus, prop_dplus;
337 int vampiric_damage;
338 char *strchr();
339
340 /* Get statistics */
341 att = &att_er->t_stats;
342 def = &def_er->t_stats;
343
344 prop_hplus = prop_dplus = 0;
345 if (weap == NULL) {
346 static char dmgbuf[20];
347
348 /*
349 * monks damage grows with level
350 */
351 if (att == &pstats && player.t_ctype == C_MONK) {
352 sprintf(dmgbuf, "%dd4", att->s_lvl/3+1);
353 cp = dmgbuf;
354 }
355 else
356 cp = att->s_dmg;
357 }
358 else if (weap->o_type == RELIC) {
359 switch (weap->o_which) {
360 case MUSTY_DAGGER: cp = "1d4+1/1d4+1";
361 when YEENOGHU_FLAIL: cp = "3d6/paralyze/confuse";
362 when HRUGGEK_MSTAR: cp = "3d10";
363 when MING_STAFF: cp = "1d8";
364 when ASMO_ROD: cp = "2d8+1";
365 when ORCUS_WAND: cp = "destroy";
366 when AXE_AKLAD: if (hurl) cp = "1d6/drain";
367 else cp = "3d6/drain";
368 }
369 }
370 else if (hurl) {