2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)hit.c 8.1 (Berkeley) 5/31/93
33 * $FreeBSD: src/games/rogue/hit.c,v 1.6 1999/11/30 03:49:22 billf Exp $
39 * This source herein may be modified and/or distributed by anybody who
40 * so desires, with the following restrictions:
41 * 1.) No portion of this notice shall be removed.
42 * 2.) Credit shall not be taken for the creation of this source.
43 * 3.) This code is not to be traded, sold, or used for personal
50 extern short halluc
, blind
, cur_level
;
51 extern short add_strength
, ring_exp
, r_rings
;
52 extern boolean being_held
, interrupted
, wizard
, con_mon
;
54 static short damage_for_strength(void);
55 static int get_w_damage(const object
*);
56 static int to_hit(const object
*);
58 object
*fight_monster
= NULL
;
59 char hit_message
[80] = "";
62 mon_hit(object
*monster
)
64 short damage
, hit_chance
;
68 if (fight_monster
&& (monster
!= fight_monster
)) {
71 monster
->trow
= NO_ROOM
;
72 if (cur_level
>= (AMULET_LEVEL
* 2)) {
75 hit_chance
= monster
->m_hit_chance
;
76 hit_chance
-= (((2 * rogue
.exp
) + (2 * ring_exp
)) - r_rings
);
84 mn
= mon_name(monster
);
86 if (!rand_percent(hit_chance
)) {
88 sprintf(hit_message
+ strlen(hit_message
), "the %s misses", mn
);
89 message(hit_message
, 1);
95 sprintf(hit_message
+ strlen(hit_message
), "the %s hit", mn
);
96 message(hit_message
, 1);
99 if (!(monster
->m_flags
& STATIONARY
)) {
100 damage
= get_damage(monster
->m_damage
, 1);
101 if (cur_level
>= (AMULET_LEVEL
* 2)) {
102 minus
= (float)((AMULET_LEVEL
* 2) - cur_level
);
104 minus
= (float)get_armor_class(rogue
.armor
) * 3.00;
105 minus
= minus
/ 100.00 * (float)damage
;
107 damage
-= (short)minus
;
109 damage
= monster
->stationary_damage
++;
115 rogue_damage(damage
, monster
, 0);
117 if (monster
->m_flags
& SPECIAL_HIT
) {
118 special_hit(monster
);
123 rogue_hit(object
*monster
, boolean force_hit
)
125 short damage
, hit_chance
;
128 if (check_imitator(monster
)) {
131 hit_chance
= force_hit
? 100 : get_hit_chance(rogue
.weapon
);
136 if (!rand_percent(hit_chance
)) {
137 if (!fight_monster
) {
138 strcpy(hit_message
, "you miss ");
142 damage
= get_weapon_damage(rogue
.weapon
);
149 if (mon_damage(monster
, damage
)) { /* still alive? */
150 if (!fight_monster
) {
151 strcpy(hit_message
, "you hit ");
154 RET
: check_gold_seeker(monster
);
160 rogue_damage(short d
, object
*monster
, short other
)
162 if (d
>= rogue
.hp_current
) {
163 rogue
.hp_current
= 0;
164 print_stats(STAT_HP
);
165 killed_by(monster
, other
);
168 rogue
.hp_current
-= d
;
169 print_stats(STAT_HP
);
174 get_damage(const char *ds
, boolean r
)
176 int i
= 0, j
, n
, d
, total
= 0;
179 n
= get_number(ds
+i
);
180 while (ds
[i
++] != 'd')
182 d
= get_number(ds
+i
);
183 while ((ds
[i
] != '/') && ds
[i
])
186 for (j
= 0; j
< n
; j
++) {
188 total
+= get_rand(1, d
);
201 get_w_damage(const object
*obj
)
207 if ((!obj
) || (obj
->what_is
!= WEAPON
)) {
210 t_hit
= get_number(obj
->damage
) + obj
->hit_enchant
;
211 while (obj
->damage
[i
++] != 'd')
213 damage
= get_number(obj
->damage
+ i
) + obj
->d_enchant
;
215 sprintf(new_damage
, "%dd%d", t_hit
, damage
);
217 return(get_damage(new_damage
, 1));
221 get_number(const char *s
)
226 while ((s
[i
] >= '0') && (s
[i
] <= '9')) {
227 total
= (10 * total
) + (s
[i
] - '0');
234 lget_number(const char *s
)
239 while ((s
[i
] >= '0') && (s
[i
] <= '9')) {
240 total
= (10 * total
) + (s
[i
] - '0');
247 to_hit(const object
*obj
)
252 return(get_number(obj
->damage
) + obj
->hit_enchant
);
256 damage_for_strength(void)
260 strength
= rogue
.str_current
+ add_strength
;
265 if (strength
<= 14) {
268 if (strength
<= 17) {
271 if (strength
<= 18) {
274 if (strength
<= 20) {
277 if (strength
<= 21) {
280 if (strength
<= 30) {
287 mon_damage(object
*monster
, short damage
)
292 monster
->hp_to_kill
-= damage
;
294 if (monster
->hp_to_kill
<= 0) {
297 dungeon
[row
][col
] &= ~MONSTER
;
298 mvaddch(row
, col
, (int)get_dungeon_char(row
, col
));
300 fight_monster
= NULL
;
302 mn
= mon_name(monster
);
303 sprintf(hit_message
+strlen(hit_message
), "defeated the %s", mn
);
304 message(hit_message
, 1);
306 add_exp(monster
->kill_exp
, 1);
307 take_from_pack(monster
, &level_monsters
);
309 if (monster
->m_flags
& HOLDS
) {
312 free_object(monster
);
319 fight(boolean to_the_death
)
323 boolean first_miss
= 1;
324 short possible_damage
;
327 while (!is_direction(ch
= rgetchar(), &d
)) {
330 message("direction?", 0);
338 row
= rogue
.row
; col
= rogue
.col
;
339 get_dir_rc(d
, &row
, &col
, 0);
341 c
= mvinch(row
, col
);
342 if (((c
< 'A') || (c
> 'Z')) ||
343 (!can_move(rogue
.row
, rogue
.col
, row
, col
))) {
344 message("I see no monster there", 0);
347 if (!(fight_monster
= object_at(&level_monsters
, row
, col
))) {
350 if (!(fight_monster
->m_flags
& STATIONARY
)) {
351 possible_damage
= ((get_damage(fight_monster
->m_damage
, 0) * 2) / 3);
353 possible_damage
= fight_monster
->stationary_damage
- 1;
355 while (fight_monster
) {
356 one_move_rogue(ch
, 0);
357 if (((!to_the_death
) && (rogue
.hp_current
<= possible_damage
)) ||
358 interrupted
|| (!(dungeon
[row
][col
] & MONSTER
))) {
359 fight_monster
= NULL
;
361 monster
= object_at(&level_monsters
, row
, col
);
362 if (monster
!= fight_monster
) {
363 fight_monster
= NULL
;
370 get_dir_rc(short dir
, short *row
, short *col
, short allow_off_screen
)
374 if (allow_off_screen
|| (*col
> 0)) {
379 if (allow_off_screen
|| (*row
< (DROWS
-2))) {
384 if (allow_off_screen
|| (*row
> MIN_ROW
)) {
389 if (allow_off_screen
|| (*col
< (DCOLS
-1))) {
394 if (allow_off_screen
|| ((*row
> MIN_ROW
) && (*col
> 0))) {
400 if (allow_off_screen
|| ((*row
> MIN_ROW
) && (*col
< (DCOLS
-1)))) {
406 if (allow_off_screen
|| ((*row
< (DROWS
-2)) && (*col
< (DCOLS
-1)))) {
412 if (allow_off_screen
|| ((*row
< (DROWS
-2)) && (*col
> 0))) {
421 get_hit_chance(const object
*weapon
)
426 hit_chance
+= 3 * to_hit(weapon
);
427 hit_chance
+= (((2 * rogue
.exp
) + (2 * ring_exp
)) - r_rings
);
432 get_weapon_damage(const object
*weapon
)
436 damage
= get_w_damage(weapon
);
437 damage
+= damage_for_strength();
438 damage
+= ((((rogue
.exp
+ ring_exp
) - r_rings
) + 1) / 2);
443 s_con_mon(object
*monster
)
446 monster
->m_flags
|= CONFUSED
;
447 monster
->moves_confused
+= get_rand(12, 22);
448 message("the monster appears confused", 0);