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. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 static char sccsid[] = "@(#)hit.c 8.1 (Berkeley) 5/31/93";
41 static const char rcsid[] =
42 "$FreeBSD: src/games/rogue/hit.c,v 1.6 1999/11/30 03:49:22 billf Exp $";
48 * This source herein may be modified and/or distributed by anybody who
49 * so desires, with the following restrictions:
50 * 1.) No portion of this notice shall be removed.
51 * 2.) Credit shall not be taken for the creation of this source.
52 * 3.) This code is not to be traded, sold, or used for personal
59 object *fight_monster = 0;
60 char hit_message[80] = "";
62 extern short halluc, blind, cur_level;
63 extern short add_strength, ring_exp, r_rings;
64 extern boolean being_held, interrupted, wizard, con_mon;
69 short damage, hit_chance;
73 if (fight_monster && (monster != fight_monster)) {
76 monster->trow = NO_ROOM;
77 if (cur_level >= (AMULET_LEVEL * 2)) {
80 hit_chance = monster->m_hit_chance;
81 hit_chance -= (((2 * rogue.exp) + (2 * ring_exp)) - r_rings);
89 mn = mon_name(monster);
91 if (!rand_percent(hit_chance)) {
93 sprintf(hit_message + strlen(hit_message), "the %s misses", mn);
94 message(hit_message, 1);
100 sprintf(hit_message + strlen(hit_message), "the %s hit", mn);
101 message(hit_message, 1);
104 if (!(monster->m_flags & STATIONARY)) {
105 damage = get_damage(monster->m_damage, 1);
106 if (cur_level >= (AMULET_LEVEL * 2)) {
107 minus = (float) ((AMULET_LEVEL * 2) - cur_level);
109 minus = (float) get_armor_class(rogue.armor) * 3.00;
110 minus = minus/100.00 * (float) damage;
112 damage -= (short) minus;
114 damage = monster->stationary_damage++;
120 rogue_damage(damage, monster, 0);
122 if (monster->m_flags & SPECIAL_HIT) {
123 special_hit(monster);
127 rogue_hit(monster, force_hit)
131 short damage, hit_chance;
134 if (check_imitator(monster)) {
137 hit_chance = force_hit ? 100 : get_hit_chance(rogue.weapon);
142 if (!rand_percent(hit_chance)) {
143 if (!fight_monster) {
144 (void) strcpy(hit_message, "you miss ");
148 damage = get_weapon_damage(rogue.weapon);
155 if (mon_damage(monster, damage)) { /* still alive? */
156 if (!fight_monster) {
157 (void) strcpy(hit_message, "you hit ");
160 RET: check_gold_seeker(monster);
165 rogue_damage(d, monster, other)
170 if (d >= rogue.hp_current) {
171 rogue.hp_current = 0;
172 print_stats(STAT_HP);
173 killed_by(monster, other);
176 rogue.hp_current -= d;
177 print_stats(STAT_HP);
185 int i = 0, j, n, d, total = 0;
188 n = get_number(ds+i);
189 while (ds[i++] != 'd') ;
190 d = get_number(ds+i);
191 while ((ds[i] != '/') && ds[i]) i++;
193 for (j = 0; j < n; j++) {
195 total += get_rand(1, d);
214 if ((!obj) || (obj->what_is != WEAPON)) {
217 to_hit = get_number(obj->damage) + obj->hit_enchant;
218 while (obj->damage[i++] != 'd') ;
219 damage = get_number(obj->damage + i) + obj->d_enchant;
221 sprintf(new_damage, "%dd%d", to_hit, damage);
223 return(get_damage(new_damage, 1));
232 while ((s[i] >= '0') && (s[i] <= '9')) {
233 total = (10 * total) + (s[i] - '0');
246 while ((s[i] >= '0') && (s[i] <= '9')) {
247 total = (10 * total) + (s[i] - '0');
259 return(get_number(obj->damage) + obj->hit_enchant);
262 damage_for_strength()
266 strength = rogue.str_current + add_strength;
271 if (strength <= 14) {
274 if (strength <= 17) {
277 if (strength <= 18) {
280 if (strength <= 20) {
283 if (strength <= 21) {
286 if (strength <= 30) {
292 mon_damage(monster, damage)
299 monster->hp_to_kill -= damage;
301 if (monster->hp_to_kill <= 0) {
304 dungeon[row][col] &= ~MONSTER;
305 mvaddch(row, col, (int) get_dungeon_char(row, col));
309 mn = mon_name(monster);
310 sprintf(hit_message+strlen(hit_message), "defeated the %s", mn);
311 message(hit_message, 1);
313 add_exp(monster->kill_exp, 1);
314 take_from_pack(monster, &level_monsters);
316 if (monster->m_flags & HOLDS) {
319 free_object(monster);
326 boolean to_the_death;
330 boolean first_miss = 1;
331 short possible_damage;
334 while (!is_direction(ch = rgetchar(), &d)) {
337 message("direction?", 0);
345 row = rogue.row; col = rogue.col;
346 get_dir_rc(d, &row, &col, 0);
348 c = mvinch(row, col);
349 if (((c < 'A') || (c > 'Z')) ||
350 (!can_move(rogue.row, rogue.col, row, col))) {
351 message("I see no monster there", 0);
354 if (!(fight_monster = object_at(&level_monsters, row, col))) {
357 if (!(fight_monster->m_flags & STATIONARY)) {
358 possible_damage = ((get_damage(fight_monster->m_damage, 0) * 2) / 3);
360 possible_damage = fight_monster->stationary_damage - 1;
362 while (fight_monster) {
363 (void) one_move_rogue(ch, 0);
364 if (((!to_the_death) && (rogue.hp_current <= possible_damage)) ||
365 interrupted || (!(dungeon[row][col] & MONSTER))) {
368 monster = object_at(&level_monsters, row, col);
369 if (monster != fight_monster) {
376 get_dir_rc(dir, row, col, allow_off_screen)
379 short allow_off_screen;
383 if (allow_off_screen || (*col > 0)) {
388 if (allow_off_screen || (*row < (DROWS-2))) {
393 if (allow_off_screen || (*row > MIN_ROW)) {
398 if (allow_off_screen || (*col < (DCOLS-1))) {
403 if (allow_off_screen || ((*row > MIN_ROW) && (*col > 0))) {
409 if (allow_off_screen || ((*row > MIN_ROW) && (*col < (DCOLS-1)))) {
415 if (allow_off_screen || ((*row < (DROWS-2)) && (*col < (DCOLS-1)))) {
421 if (allow_off_screen || ((*row < (DROWS-2)) && (*col > 0))) {
429 get_hit_chance(weapon)
430 const object *weapon;
435 hit_chance += 3 * to_hit(weapon);
436 hit_chance += (((2 * rogue.exp) + (2 * ring_exp)) - r_rings);
440 get_weapon_damage(weapon)
441 const object *weapon;
445 damage = get_w_damage(weapon);
446 damage += damage_for_strength();
447 damage += ((((rogue.exp + ring_exp) - r_rings) + 1) / 2);
455 monster->m_flags |= CONFUSED;
456 monster->moves_confused += get_rand(12, 22);
457 message("the monster appears confused", 0);