[net.sources.games] special_hit.c from rogue clone

warren@ll-xn.ARPA (Warren J. Lavallee) (03/26/86)

As requested....

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	special_hit.c
# This archive created: Wed Mar 26 15:10:42 1986
# By:	Warren J. Lavallee
export PATH; PATH=/bin:$PATH
echo shar: extracting "'special_hit.c'" '(9963 characters)'
if test -f 'special_hit.c'
then
	echo shar: will not over-write existing file "'special_hit.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'special_hit.c'
	X#include <curses.h>
	X#include "object.h"
	X#include "move.h"
	X#include "monster.h"
	X
	Xshort   being_held;
	X
	Xextern short    current_level,
	X                max_level,
	X                has_amulet,
	X                detect_monster;
	Xextern int  level_points[];
	X
	Xspecial_hit (monster)
	Xobject * monster;
	X{
	X    switch (monster -> ichar) {
	X	case 'A': 
	X	    rust (monster);
	X	    break;
	X	case 'F': 
	X	    being_held = 1;
	X	    break;
	X	case 'I': 
	X	    freeze (monster);
	X	    break;
	X	case 'L': 
	X	    steal_gold (monster);
	X	    break;
	X	case 'N': 
	X	    steal_item (monster);
	X	    break;
	X	case 'R': 
	X	    sting (monster);
	X	    break;
	X	case 'V': 
	X	    drain_life ();
	X	    break;
	X	case 'W': 
	X	    drain_level ();
	X	    break;
	X    }
	X}
	X
	Xrust (monster)
	Xobject * monster;
	X{
	X    if (!rogue.armor || (get_armor_class (rogue.armor) <= 1) ||
	X	    (rogue.armor -> which_kind == LEATHER)) {
	X	return;
	X    }
	X    if (rogue.armor -> is_protected) {
	X	if (!monster -> identified) {
	X	    message ("The rust vanishes instantly", 0);
	X	    monster -> identified = 1;
	X	}
	X    }
	X    else {
	X	rogue.armor -> damage_enchantment--;
	X	message ("Your armor weakens", 0);
	X	print_stats ();
	X    }
	X}
	X
	Xfreeze (monster)
	Xobject * monster;
	X{
	X    short   freeze_percent = 99;
	X    short   i,
	X            n;
	X
	X    if (rand_percent (12))
	X	return;
	X
	X    freeze_percent -= (rogue.strength_current + (rogue.strength_current / 2));
	X    freeze_percent -= rogue.exp * 4;
	X    freeze_percent -= (get_armor_class (rogue.armor) * 5);
	X    freeze_percent -= (rogue.hp_max / 3);
	X
	X    if (freeze_percent > 10) {
	X	monster -> identified = 1;
	X	message ("You are frozen", 1);
	X
	X	n = get_rand (5, 9);
	X	for (i = 0; i < n; i++) {
	X	    move_monsters ();
	X	}
	X	if (rand_percent (freeze_percent)) {
	X	    for (i = 0; i < 50; i++) {
	X		move_monsters ();
	X	    }
	X	    killed_by ((object *) 0, HYPOTHERMIA);
	X	}
	X	message ("You can move again", 1);
	X	monster -> identified = 0;
	X    }
	X}
	X
	Xsteal_gold (monster)
	Xobject * monster;
	X{
	X    int     amount;
	X
	X    if (rand_percent (15))
	X	return;
	X
	X    if (rogue.gold > 50) {
	X	amount = rogue.gold > 1000 ? get_rand (8, 15) : get_rand (2, 5);
	X	amount = rogue.gold / amount;
	X    }
	X    else {
	X	amount = rogue.gold / 2;
	X    }
	X    amount += (get_rand (0, 2) - 1) * (rogue.exp + current_level);
	X    if ((amount <= 0) && (rogue.gold > 0)) {
	X	amount = rogue.gold;
	X    }
	X
	X    if (amount > 0) {
	X	rogue.gold -= amount;
	X	message ("Your purse feels lighter", 0);
	X	print_stats ();
	X    }
	X    disappear (monster);
	X}
	X
	Xsteal_item (monster)
	Xobject * monster;
	X{
	X    object * obj;
	X    short   i,
	X            n,
	X            has_something = 0;
	X    char    description[80];
	X
	X    if (rand_percent (15))
	X	return;
	X
	X    obj = rogue.pack.next_object;
	X
	X    if (!obj) {
	X	goto DSPR;
	X    }
	X    while (obj) {
	X	if ((obj != rogue.armor) && (obj != rogue.weapon)) {
	X	    has_something = 1;
	X	    break;
	X	}
	X	obj = obj -> next_object;
	X    }
	X    if (!has_something)
	X	goto DSPR;
	X
	X    n = get_rand (0, MAX_PACK_COUNT);
	X    obj = rogue.pack.next_object;
	X
	X    for (i = 0; i <= n; i++) {
	X	obj = obj -> next_object;
	X	while (!obj || (obj == rogue.weapon) || (obj == rogue.armor)) {
	X	    if (!obj) {
	X		obj = rogue.pack.next_object;
	X	    }
	X	    else {
	X		obj = obj -> next_object;
	X	    }
	X	}
	X    }
	X    strcpy (description, "She stole ");
	X    get_description (obj, description + 10);
	X    message (description, 0);
	X
	X    if (obj -> what_is == AMULET) {
	X	has_amulet = 0;
	X    }
	X    vanish (obj, 0);
	XDSPR: disappear (monster);
	X}
	X
	Xdisappear (monster)
	Xobject * monster;
	X{
	X    short   row,
	X            col;
	X
	X    row = monster -> row;
	X    col = monster -> col;
	X
	X    remove_mask (row, col, MONSTER);
	X    if (can_see (row, col)) {
	X	mvaddch (row, col, get_room_char (screen[row][col], row, col));
	X    }
	X    remove_from_pack (monster, &level_monsters);
	X    free (monster);
	X}
	X
	Xcough_up (monster)
	Xobject * monster;
	X{
	X    object * obj, *get_an_object (), *get_rand_object ();
	X    short   row,
	X            col,
	X            i,
	X            j,
	X            n;
	X
	X    if (current_level < max_level) {
	X	return;
	X    }
	X
	X    switch (monster -> ichar) {
	X	case 'L': 
	X	    obj = get_an_object ();
	X	    obj -> what_is = GOLD;
	X	    obj -> quantity = get_rand (9, 599);
	X	    break;
	X	default: 
	X	    if (rand_percent (monster -> which_kind)) {
	X		obj = get_rand_object ();
	X		break;
	X	    }
	X	    return;
	X    }
	X    row = monster -> row;
	X    col = monster -> col;
	X
	X    for (n = 0; n <= 5; n++) {
	X	for (i = -n; i <= n; i++) {
	X	    if (try_to_cough (row + n, col + i, obj)) {
	X		return;
	X	    }
	X	    if (try_to_cough (row - n, col + i, obj)) {
	X		return;
	X	    }
	X	}
	X	for (i = -n; i <= n; i++) {
	X	    if (try_to_cough (row + i, col - n, obj)) {
	X		return;
	X	    }
	X	    if (try_to_cough (row + i, col + n, obj)) {
	X		return;
	X	    }
	X	}
	X    }
	X    free (obj);
	X}
	X
	Xtry_to_cough (row, col, obj)
	Xshort   row,
	X        col;
	Xobject * obj;
	X{
	X    if ((row < MIN_ROW) || (row > (LINES - 2)) || (col < 0) || (col > (COLS - 1))) {
	X	return (0);
	X    }
	X    if ((!(screen[row][col] & IS_OBJECT)) &&
	X	    (screen[row][col] & (TUNNEL | FLOOR | DOOR)) &&
	X	    !(screen[row][col] & MONSTER)) {
	X	put_object_at (obj, row, col);
	X	mvaddch (row, col, get_room_char (screen[row][col], row, col));
	X	refresh ();
	X	return (1);
	X    }
	X    return (0);
	X}
	X
	Xorc_gold (monster)
	Xobject * monster;
	X{
	X    short   i,
	X            j,
	X            row,
	X            col,
	X            rn,
	X            s;
	X
	X    if (monster -> identified) {
	X	return (0);
	X    }
	X    if ((rn = get_room_number (monster -> row, monster -> col)) < 0) {
	X	return (0);
	X    }
	X    for (i = rooms[rn].top_row + 1;
	X	    i < rooms[rn].bottom_row; i++) {
	X	for (j = rooms[rn].left_col + 1;
	X		j < rooms[rn].right_col; j++) {
	X	    if ((screen[i][j] & GOLD) &&
	X		    !(screen[i][j] & MONSTER)) {
	X		monster -> m_flags |= CAN_GO;
	X		s = monster_can_go (monster, i, j);
	X		monster -> m_flags &= (~CAN_GO);
	X		if (s) {
	X		    move_monster_to (monster, i, j);
	X		    monster -> m_flags |= IS_ASLEEP;
	X		    monster -> m_flags &= (~WAKENS);
	X		    monster -> identified = 1;
	X		    return (1);
	X		}
	X		monster -> identified = 1;
	X		monster -> m_flags |= CAN_GO;
	X		mv_monster (monster, i, j);
	X		monster -> m_flags &= (~CAN_GO);
	X		monster -> identified = 0;
	X		return (1);
	X	    }
	X	}
	X    }
	X    return (0);
	X}
	X
	Xcheck_orc (monster)
	Xobject * monster;
	X{
	X    if (monster -> ichar == 'O') {
	X	monster -> identified = 1;
	X    }
	X}
	X
	Xcheck_xeroc (monster)
	Xobject * monster;
	X{
	X    char   *monster_name ();
	X    char    msg[80];
	X
	X    if ((monster -> ichar == 'X') && monster -> identified) {
	X	wake_up (monster);
	X	monster -> identified = 0;
	X	mvaddch (monster -> row, monster -> col,
	X		get_room_char (screen[monster -> row][monster -> col],
	X		    monster -> row, monster -> col));
	X	check_message ();
	X	sprintf (msg, "Wait, that's a %s!", monster_name (monster));
	X	message (msg, 1);
	X	return (1);
	X    }
	X    return (0);
	X}
	X
	Xhiding_xeroc (row, col)
	Xregister short  row,
	X                col;
	X{
	X    object * object_at (), *monster;
	X
	X    if ((current_level < XEROC1) || (current_level > XEROC2) ||
	X	    !(screen[row][col] & MONSTER)) {
	X	return (0);
	X    }
	X    monster = object_at (&level_monsters, row, col);
	X
	X    if ((monster -> ichar == 'X') && monster -> identified) {
	X	return (1);
	X    }
	X    return (0);
	X}
	X
	Xsting (monster)
	Xobject * monster;
	X{
	X    short   ac,
	X            sting_chance = 35;
	X    char    msg[80],
	X           *monster_name ();
	X
	X    if (rogue.strength_current < 5)
	X	return;
	X
	X    ac = get_armor_class (rogue.armor);
	X
	X    sting_chance += (6 * (6 - ac));
	X
	X    if (rogue.exp > 8) {
	X	sting_chance -= (6 * (rogue.exp - 8));
	X    }
	X
	X    if (sting_chance > 100) {
	X	sting_chance = 100;
	X    }
	X    else
	X	if (sting_chance <= 0) {
	X	    sting_chance = 1;
	X	}
	X    if (rand_percent (sting_chance)) {
	X	sprintf (msg, "the %s's bite has weakened you",
	X		monster_name (monster));
	X	message (msg, 0);
	X	rogue.strength_current--;
	X	print_stats ();
	X    }
	X}
	X
	Xdrain_level () {
	X    if (!rand_percent (20) || (rogue.exp <= 7)) {
	X	return;
	X    }
	X    rogue.exp_points = level_points[rogue.exp - 2] - get_rand (10, 50);
	X    rogue.exp -= 2;
	X    add_exp (1);
	X}
	X
	Xdrain_life () {
	X    if (!rand_percent (25) || (rogue.hp_max <= 30) || (rogue.hp_current < 10)) {
	X	return;
	X    }
	X    message ("You feel weaker", 0);
	X    rogue.hp_max--;
	X    rogue.hp_current--;
	X    if (rand_percent (50)) {
	X	if (rogue.strength_current >= 5) {
	X	    rogue.strength_current--;
	X	    if (rand_percent (50)) {
	X		rogue.strength_max--;
	X	    }
	X	}
	X    }
	X    print_stats ();
	X}
	X
	Xm_confuse (monster)
	Xobject * monster;
	X{
	X    char    msg[80];
	X    char   *monster_name ();
	X
	X    if (monster -> identified) {
	X	return (0);
	X    }
	X    if (!can_see (monster -> row, monster -> col)) {
	X	return (0);
	X    }
	X    if (rand_percent (45)) {
	X	monster -> identified = 1;
	X	return (0);
	X    }
	X    if (rand_percent (55)) {
	X	monster -> identified = 1;
	X	sprintf (msg, "The gaze of the %s has confused you",
	X		monster_name (monster));
	X	message (msg, 1);
	X	confuse ();
	X	return (1);
	X    }
	X    return (0);
	X}
	X
	Xflame_broil (monster)
	Xobject * monster;
	X{
	X    short   row,
	X            col;
	X
	X    if (!can_see (monster -> row, monster -> col)) {
	X	return (0);
	X    }
	X    if (rand_percent (50)) {
	X	return (0);
	X    }
	X    if (!rogue_is_around (monster -> row, monster -> col)) {
	X
	X	row = monster -> row;
	X	col = monster -> col;
	X	get_closer (&row, &col, rogue.row, rogue.col);
	X	standout ();
	X	do {
	X	    mvaddch (row, col, '*');
	X	    refresh ();
	X	    get_closer (&row, &col, rogue.row, rogue.col);
	X	} while ((row != rogue.row) || (col != rogue.col));
	X	standend ();
	X	row = monster -> row;
	X	col = monster -> col;
	X	get_closer (&row, &col, rogue.row, rogue.col);
	X	do {
	X	    mvaddch (row, col, get_room_char (screen[row][col],
	X			row, col));
	X	    refresh ();
	X	    get_closer (&row, &col, rogue.row, rogue.col);
	X	} while ((row != rogue.row) || (col != rogue.col));
	X    }
	X    monster_hit (monster, "flame");
	X    return (1);
	X}
	X
	Xget_closer (row, col, trow, tcol)
	Xshort  *row,
	X       *col;
	Xshort   trow,
	X        tcol;
	X{
	X    if (*row < trow) {
	X	(*row)++;
	X    }
	X    else
	X	if (*row > trow) {
	X	    (*row)--;
	X	}
	X    if (*col < tcol) {
	X	(*col)++;
	X    }
	X    else
	X	if (*col > tcol) {
	X	    (*col)--;
	X	}
	X}
SHAR_EOF
if test 9963 -ne "`wc -c < 'special_hit.c'`"
then
	echo shar: error transmitting "'special_hit.c'" '(should have been 9963 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
-- 
##############################################################################
# All that is gold does not glitter,	    # ARPA: warren@ll-xn.arpa        #
#  Not all those who wander are lost;	    # UUCP: seismo!ll-xn!warren      #
# The old that is strong does not whither,  # CSNET:ll-xn%warren@CSNET-RELAY #
#  Deep roots are not reached by the frost. # BITNET:ll-xn%warren@WISCVM     #
# 			-- Bilbo	    #				     #
##############################################################################