Exemple #1
0
/**
 * get_hero_KK_best - get the index of the hero with the best KK value
 *
 * Returns the index of the hero with the highest unmodified KK value.
 * The hero must be alive and in the current group.
 */
unsigned short get_hero_KK_best() {
	signed short retval;
	Bit8u *hero_i;
	signed short i;
	signed short kk_val = -1;

	hero_i = get_hero(0);

	for (i = 0; i <= 6; i++, hero_i += 0x6da) {
		if ((host_readb(hero_i + 0x21) != 0) &&
				/* check class */
			(host_readb(hero_i + 0x87) == ds_readb(CURRENT_GROUP)) &&
				/* check if in group */
			(!hero_dead(hero_i)) &&
				/* check if not dead */
			(host_readbs(hero_i + 0x47) > kk_val)) {
				/* check if KK is the highest */

				kk_val = host_readbs(hero_i + 0x47);
				retval = i;
			}
	}

	return retval;
}
Exemple #2
0
/* dead animal Orvil<->Skjal */
void tevent_063(void)
{
	Bit8u *hero;
	signed short vomiter;
	signed short proof;
	signed short i;
	signed short max;

	max = 9999;

	/* intro message */
	GUI_output(get_city(0xb8));

	hero = get_hero(0);

	for (i = 0; i <= 6; i++, hero += 0x6da) {

		if (host_readb(hero + 0x21) == 0)
			continue;

		if (host_readb(hero + 0x87) != ds_readb(CURRENT_GROUP))
			continue;

		if (hero_dead(hero))
			continue;

		/* MU+0 */
		proof = test_attrib(hero, 0, 0);

		if (proof < max) {
			max = proof;
			vomiter = i;
		}
	}

	hero = get_hero(vomiter);

	sprintf((char*)Real2Host(ds_readd(DTP2)),
		(char*)get_city(0xbc),
		(char*)hero + 0x10);

	/* print who vomits */
	GUI_output(Real2Host(ds_readd(DTP2)));

	/* LE - 2 */
	sub_hero_le(hero, 2);

	i = get_free_mod_slot();

	/* MU -2 for 24 hours */
	set_mod_slot(i, 0x1fa40, hero + 0x35, -2, (signed char)vomiter);

	/* outro message */
	GUI_output(get_city(0xc0));
}
Exemple #3
0
/**
 * hero_disease_test - the hero may get a disease
 * @hero:	the hero which may gets diseased
 * @disease:	the kind of disease
 * @probability: the probability to get diseased in percent
 */
void hero_disease_test(Bit8u *hero, unsigned short disease, signed short probability) {

#ifdef M302de_ORIGINAL_BUGFIX
	/* not a real BUG, but very useless */
	if (host_readb(hero + 0x21) == 0)
		return;
#endif

	/* check the probability and if hero is diseased*/
	if (random_schick(100) <= probability &&
		host_readb(hero + disease * 5 + 0xae) != 0xff) {

		hero_gets_diseased(hero, disease);
	}
}
Exemple #4
0
/**
 *	hero_get_sober	-	makes a drunken hero sober
 *	@hero:	pointer to the hero
 *
 */
void hero_get_sober(Bit8u *hero) {
	/* This is checked twice */
	/* Is hero drunken ? */
	if (host_readb(hero + 0xa1) == 0)
		return;

#if !defined(__BORLANDC__)
	D1_INFO("%s ist wieder nuechtern\n", (char*)hero + 0x10);
#endif

	/* set hero sober */
	host_writeb(hero + 0xa1, 0);

	/* Reset good attributes */
	sub_ptr_bs(hero + 0x35, 1);
	add_ptr_bs(hero + 0x38, 1);
	add_ptr_bs(hero + 0x3b, 1);
	add_ptr_bs(hero + 0x3e, 1);
	add_ptr_bs(hero + 0x41, 1);
	sub_ptr_bs(hero + 0x44, 1);
	sub_ptr_bs(hero + 0x47, 1);

	/* Reset bad attributes */
	sub_ptr_bs(hero + 0x4a, 1);
	add_ptr_bs(hero + 0x4d, 1);
	add_ptr_bs(hero + 0x50, 1);
	sub_ptr_bs(hero + 0x53, 1);
	add_ptr_bs(hero + 0x56, 1);
	sub_ptr_bs(hero + 0x59, 1);
	sub_ptr_bs(hero + 0x5c, 1);

	if (ds_readb(0x2845) == 20)
		ds_writew(0x2846, 1);
}
Exemple #5
0
static INLINE Bitu  hostRead(HostPt off ) {
	if ( sizeof( Size ) == 1)
		return host_readb( off );
	else if ( sizeof( Size ) == 2)
		return host_readw( off );
	else if ( sizeof( Size ) == 4)
		return host_readd( off );
	return 0;
}
Exemple #6
0
void hero_disappear(Bit8u *hero, unsigned short pos, signed char type)
{

	/* decrement the number of heroes */
	ds_writeb(0x2d3c, ds_readb(0x2d3c) - 1);

	/* load a new savegame if no hero is present */
	if (ds_readb(0x2d3c) == 0)
		ds_writew(0xc3c1, 1);

	/* decrement group counter */
	ds_writeb(0x2d36 + ds_readb(CURRENT_GROUP),
		ds_readb(0x2d36 + ds_readb(CURRENT_GROUP)) - 1);

	/* write type to character sheet */
	host_writeb(hero + 0x88, type);

	/* reset position in group */
	host_writeb(hero + 0x8a, 0);

	if (pos == 6) {
		/* NPC */
		save_npc(0xe2 + host_readb(hero + 0x89));

		/* reset NPC timer */
		ds_writeb(0x3602 + host_readb(hero + 0x89), 0xff);
	} else {
		/* Regular Hero */
		write_chr_temp(pos);
	}

	/* set typus to 0 */
	host_writeb(hero + 0x21, 0);

	if (type != -2) {
		draw_main_screen();
		init_ani(2);
		ds_writew(0x2846, 1);
	}

	/* set flag to check all heros */
	ds_writeb(CHECK_PARTY, 1);
}
Exemple #7
0
/**
 * count_heroes_in_group() - counts the heroes in the current group
 *
 * Returns how many alive heros are in the group.
 */
signed short count_heroes_in_group(void)
{
	Bit8u *hero_i;
	signed short i;
	signed short retval;

	retval = 0;

	for (hero_i = get_hero(0), i = 0; i <= 6; i++, hero_i += 0x6da) {
		/* Check class, group and dead */
		if ((host_readb(hero_i + 0x21) != 0) &&
			(host_readb(hero_i + 0x87) == ds_readb(CURRENT_GROUP)) &&
			(!hero_dead(hero_i))) {

			retval++;
		}
	}

	return retval;
}
Exemple #8
0
/**
 *	check_heros_KK
 *	@val:	value to compare KK with
 *
 *	This function, like hero_check_KK_unused, is buggy!
 *	It does not check if the first slot is a valid hero.
 */
short check_heros_KK(short val) {

	Bit8u *hero;
	signed short sum;

	hero = get_hero(0);

	/* Orig-BUG: not checked if hero is valid */
	sum = host_readbs(hero + 0x47) + host_readbs(hero + 0x48);

	hero = get_hero(1);

	/* check class, group and dead status of hero in slot 2*/
	if (host_readb(hero + 0x21) && host_readb(hero + 0x87) == ds_readb(CURRENT_GROUP) && (!hero_dead(hero))) {
		sum += host_readbs(hero + 0x47) + host_readbs(hero + 0x48);
	}

#if !defined(__BORLANDC__)
	D1_INFO("Pruefe KK der ersten beiden Helden (%d) >= %d: ", sum, val);
	D1_INFO("%s\n", sum >= val ? "gelungen" : "mislungen");
#endif

	return (sum >= val) ? 1 : 0;
}
Exemple #9
0
/* Borlandified and identical */
void passages_init(void)
{
	signed short si;
	signed short i;
	Bit8u *p = p_datseg + 0x6f00;


	for (i = 0; i < 45; p += 8, i++) {

		host_writeb(p + 4, (unsigned char)random_interval(0, host_readbs(p + 3)));
		host_writeb(p + 7, (unsigned char)random_interval(70, 130));

		si = random_schick(100);

		if (!host_readbs(p + 5)) {

			/* Hochseerouten */
			host_writeb(p + 6, si <= 50 ? 0 : (si <= 80 ? 1 : (si <= 95 ? 2 : 3)));

		} else {

			/* Seerouten */
			host_writeb(p + 6, si <= 10 ? 4 : (si <= 40 ? 5 : (si <= 80 ? 6 : 7)));
		}

#if !defined(__BORLANDC__)
	D1_LOG("%16s - %16s: %d %d %d %d %d %d\n",
		(char*)get_ltx((host_readb(p + 0) + 0xeb) * 4),
		(char*)get_ltx((host_readb(p + 1) + 0xeb) * 4),
		host_readb(p + 2),
		host_readb(p + 3),
		host_readb(p + 4),
		host_readb(p + 5),
		host_readb(p + 6),
		host_readb(p + 7));
#endif
	}
}
Exemple #10
0
/**
 * hero_gets_diseased - diseases a hero
 * @hero:	the hero which gets diseased
 * @disease:	the kind of disease
 */
void hero_gets_diseased(Bit8u *hero, unsigned short disease)
{
#ifdef M302de_ORIGINAL_BUGFIX
	/* not a real BUG, but very useless */
	if (host_readb(hero + 0x21) == 0)
		return;
#endif

	if (!hero_dead(hero)) {
#if !defined(__BORLANDC__)
		D1_INFO("%s erkrankt an %s\n",
			(char*)hero + 0x10,
			(char*)get_ltx((disease + 0x193) * 4));
#endif

		host_writeb(hero + disease * 5 + 0xae, 0xff);
		host_writeb(hero + disease * 5 + 0xaf, 0x00);
		host_writeb(hero + disease * 5 + 0xb0, 0x00);
		host_writeb(hero + disease * 5 + 0xb1, 0x00);
		host_writeb(hero + disease * 5 + 0xb2, 0x00);
	}
}
Exemple #11
0
static INLINE Bit8u Fetchb() {
	Bit8u temp=host_readb(core.cseip);
	core.cseip+=1;
	return temp;
}
Exemple #12
0
/**
 * select_hero_ok_forced() - menu for selecting a hero
 * @title:	titlestring for the menu
 *
 * Returns: index of the hero or -1 (ESC).
 * Remark: The available heros must be in the group, pass check_hero() and
 *		you are forced to select a hero.
 */
signed short select_hero_ok_forced(Bit8u *title)
{
	/* Hack for
	signed short dst[7] = {0, 0, 0, 0, 0, 0, 0};
	*/
#if !defined (__BORLANDC__)
	struct helper dst = {{0, 0, 0, 0, 0, 0, 0}};
#else
	struct helper dst = *(((struct helper*)(p_datseg + SEG047_INIT3)));
#endif
	signed short cnt;
	signed short bak_1;
	signed short bak_2;
	signed short bak_3;
	RealPt hero;
	register signed short i;
	register signed short answer;

	bak_1 = ds_readw(TEXTBOX_WIDTH);
	ds_writew(TEXTBOX_WIDTH, 3);
	cnt = 0;

	for (hero = (RealPt)ds_readd(HEROS), i = 0; i <= 6; i++, hero += 0x6da) {

		if (host_readb(Real2Host(hero) + 0x21) != 0 &&
			host_readb(Real2Host(hero) + 0x87) == ds_readb(CURRENT_GROUP) &&
			check_hero(Real2Host(hero)) &&
				/* TODO: find out what that means */
				ds_readbs(0x64a2) != i) {

			/* save pointer to the name of the hero */
			ds_writed(0xbf95 + cnt * 4, (Bit32u)(hero + 0x10));
			dst.v[cnt] = i;
			cnt++;
		}
	}

	ds_writeb(0x64a2, -1);

	if (cnt != 0) {
		do {
			bak_2 = ds_readw(0x2ca2);
			bak_3 = ds_readw(0x2ca4);

			ds_writew(0x2ca2, ds_writew(0x2ca4, 0));

			answer = GUI_radio(title, (signed char)cnt,
				Real2Host(ds_readd(0xbf95)),
				Real2Host(ds_readd(0xbf99)),
				Real2Host(ds_readd(0xbf9d)),
				Real2Host(ds_readd(0xbfa1)),
				Real2Host(ds_readd(0xbfa5)),
				Real2Host(ds_readd(0xbfa9)),
				Real2Host(ds_readd(0xbfad))) - 1;

			ds_writew(0x2ca2, bak_2);
			ds_writew(0x2ca4, bak_3);

		} while (answer == -2);

		ds_writew(SKILLED_HERO_POS, -1);
		ds_writew(TEXTBOX_WIDTH, bak_1);

		return dst.v[answer];
	} else {

		ds_writew(SKILLED_HERO_POS, -1);
		return 0;
	}
}
Exemple #13
0
/* Borlandified and identical */
void seg044_002f(signed short v1, Bit8u *p, signed short v2, signed short target, signed short caster,
								signed short v5)
{
	signed short l1;
	signed short x_target, y_target;
	signed short x_caster, y_caster;
	signed short dir;
	signed short l2, l3;	/* indicees to lp2 */
	Bit8u *lp1;		/* mostly written */
	Bit8u *lp2;		/* read only */

	signed short dir2;


	/* get a pointer from an array where the Monster-ID serves as index */
	lp2 = Real2Host(ds_readd(0x2555 + host_readbs(p + 1) * 4));

	FIG_search_obj_on_cb((signed char)caster, &x_caster, &y_caster);
	FIG_search_obj_on_cb((signed char)target, &x_target, &y_target);

#if !defined(__BORLANDC__)
	/* BE-fix */
	x_caster = host_readws((Bit8u*)&x_caster);
	y_caster = host_readws((Bit8u*)&y_caster);
	x_target = host_readws((Bit8u*)&x_target);
	x_target = host_readws((Bit8u*)&y_target);
#endif
	if (x_target == x_caster) {
		if (y_caster < y_target)
			dir = 1;
		else
			dir = 3;
	} else {
		if (x_caster < x_target)
			dir = 2;
		else
			dir = 0;
	}

	if ((signed char)caster == (signed char)target)
		dir = host_readbs(p + 0x27);

	/* this is true if a monster attacks a hero */
	l1 = (v2 == 4) ? 29 : 16;

	lp1 = p_datseg + 0xd8cf + v1 * 0xf3;

	/* this is true if a monster attacks a hero */
	l1 += (v2 == 4) ? dir : host_readbs(p + 0x27);

	ds_writeb(0xd8ce + v1 * 0xf3, get_seq_header(host_readws(lp2 + l1 * 2)));

	ds_writeb(0xd9c0 + v1 * 0xf3, host_readbs(p + 1));

	if ((host_readbs(p + 0x27) != dir) && (v2 == 4)) {

		ds_writeb(0xd8ce + v1 * 0xf3, 0);
		l3 = l2 = -1;

		dir2 = host_readbs(p + 0x27);
		l3 = dir2;
		dir2++;
		if (dir2 == 4)
			dir2 = 0;

		if (dir2 != dir) {

			l2 = dir2;
			dir2++;
			if (dir2 == 4)
				dir2 = 0;
			if (dir2 != dir) {
				l3 = host_readbs(p + 0x27) + 4;
				l2 = -1;
			}
		}

		host_writebs(p + 0x27, (signed char)dir);

		lp1 += copy_ani_seq(lp1, host_readws(lp2 + l3 * 2), 1);

		if (l2 != -1)
			lp1 += copy_ani_seq(lp1, host_readws(lp2 + l2 * 2), 1);

		host_writeb(lp1, 0xfc);
		lp1++;

		host_writeb(lp1, get_seq_header(host_readws(lp2 + l1 * 2)));
		lp1++;

		host_writeb(lp1, 0);
		lp1++;
	}

	lp1 += copy_ani_seq(lp1, host_readws(lp2 + l1 * 2), 1);

	if (((ds_readw(0xe3a8) != 0) && (v5 == 0)) ||
		((ds_readw(0xe3a6) != 0) && (v5 == 1))) {

		host_writeb(lp1, 0xfc);
		lp1++;

		host_writeb(lp1, get_seq_header(host_readws(lp2 + 0x28)));
		lp1++;

		host_writeb(lp1, 0);
		lp1++;

		lp1 += copy_ani_seq(lp1, host_readws(lp2 + 0x28), 1);
	}

	host_writeb(lp1, 0xff);

	/* check if the moster sprite ID needs two fields */
	if (is_in_byte_array(host_readb(p + 1),	p_datseg + TWO_FIELDED_SPRITE_ID)) {
		memcpy(p_datseg + 0xdab4 + v1 * 0xf3, p_datseg + 0xd8ce + v1 * 0xf3, 0xf3);
	}

}
Exemple #14
0
/* Borlandified and identical */
void FIG_prepare_enemy_fight_ani(signed short a1, Bit8u *enemy, signed short f_action, signed short fid_attacker, signed short fid_target, signed short a7)
{
	signed short l1;
	signed short attacker_x;
	signed short attacker_y;
	signed short target_x;
	signed short target_y;
	signed short dir;
	signed short l7;
	signed short l8;
	signed short l9;
	signed short i;
	Bit8u *p1;
	Bit8u *p2;
	Bit8u *p3;			/* only user for two sprited figures */
	Bit8u *p4;			/* read only */
	signed short weapon_type;

	/* initialize with bare hands */
	weapon_type = -1;

	/* every enemy with the gfx_id < 22 has a sword type weapon */
	if (host_readbs(enemy + 1) < 22) {
		weapon_type = 2;
	}

	/* This byte is unknown atm */
	if (host_readbs(enemy + 0x30) != 0) {
		weapon_type = -1;
	}

	/* read a pointer from the datseg with the gfx_id as offset, read only */
	p4 = Real2Host(ds_readd(0x2555 + host_readbs(enemy + 1) * 4));

	/* find both actors on the chessboard */
	FIG_search_obj_on_cb((signed char)fid_target, &target_x, &target_y);
	FIG_search_obj_on_cb((signed char)fid_attacker, &attacker_x, &attacker_y);

#if !defined(__BORLANDC__)
	/* BE-fix */
	target_x = host_readws((Bit8u*)&target_x);
	target_y = host_readws((Bit8u*)&target_y);
	attacker_x = host_readws((Bit8u*)&attacker_x);
	attacker_y = host_readws((Bit8u*)&attacker_y);
#endif
	/* find out which direction the action will have */
	if (attacker_x == target_x) {
		if (target_y < attacker_y) {
			dir = 1;
		} else {
			dir = 3;
		}
	} else {
		if (target_x < attacker_x) {
			dir = 2;
		} else {
			dir = 0;
		}
	}



	l1 = (f_action == 2) ? 21 :			/* melee attack */
		25;

	if ((host_readbs(enemy + 1) == 8) ||
		(host_readbs(enemy + 1) == 9) ||
		(host_readbs(enemy + 1) == 19) ||
		(host_readbs(enemy + 1) == 20))
	{
		weapon_type = -1;
		l1 = (f_action == 2) ? 45 : 49;
	}

	if (f_action == 15) {
		l1 = 33;
		weapon_type = -1;
	}

	l1 += dir;

	p1 = p_datseg + 0xd8cf + a1 * 0xf3;
	p2 = p_datseg + 0xdc9b + a1 * 0xf3;


	ds_writeb(0xd8ce + 0xf3 * a1, get_seq_header(host_readws(p4 + l1 * 2)));
	ds_writeb(0xd9c0 + 0xf3 * a1, host_readbs(enemy + 1));

	/* first the enemy may turn */
	if ((host_readbs(enemy + 0x27) != dir) &&
		(	((f_action == 2) || (f_action == 15) ||
			((f_action == 100) && !ds_readbs(0xd82d + (signed char)fid_attacker))) ||
			((ds_readw(0xe3ac) != 0) && (a7 == 0)) ||
			((ds_readw(0xe3aa) != 0) && (a7 == 1))))
		{

		ds_writeb(0xd8ce + a1 * 0xf3, 0);

		/* find out the new direction */
		l8 = l7 = -1;

		/* try to turn right 90 degrees */
		l9 = host_readbs(enemy + 0x27);
		l8 = l9;
		l9++;

		if (l9 == 4) {
			l9 = 0;
		}

		if (l9 != dir) {
			l7 = l9;
			l9++;
			if (l9 == 4) {
				l9 = 0;
			}

			if (l9 != dir) {
				l8 = host_readbs(enemy + 0x27) + 4;
				l7 = -1;
			}
		}


		/* set the new direction in enemy sheet */
		host_writebs(enemy + 0x27, (signed char)dir);

		/* only if the turn is 90 degree */
		if (l7 == -1) {
			/* do not move for 2 frames */
			for (i = 0; i < 2; i++) {
				host_writeb(p1++, 0xfb);
				host_writeb(p1++, 0);
				host_writeb(p1++, 0);
			}
		}

		p1 += copy_ani_seq(p1, host_readws(p4 + l8 * 2), 1);

		if (l7 != -1) {
			p1 += copy_ani_seq(p1, host_readws(p4 + l7 * 2), 1);
		}

		host_writeb(p1++, 0xfc);
		host_writeb(p1++, get_seq_header(host_readws(p4 + l1 * 2)));
		host_writeb(p1++, 0);
	} else {
		/* do not move for 5 frames */
		for (i = 0; i < 5; i++) {
			host_writeb(p1++, 0xfb);
			host_writeb(p1++, 0);
			host_writeb(p1++, 0);
		}
	}

	if ((f_action == 2) || (f_action == 15) ||
		((f_action == 100) && !ds_readbs(0xd82d + (signed char)fid_attacker)))
	{
		p1 += copy_ani_seq(p1, host_readws(p4 + l1 *2), 1);

		if (weapon_type != -1) {

			/* do not move for 5 frames */
			for (i = 0; i < 5; i++) {
				host_writeb(p2++, 0xfb);
				host_writeb(p2++, 0);
				host_writeb(p2++, 0);
			}

			/* copy the weapon ani */
			p2 += copy_ani_seq(p2,
				ds_readws(0x25fe +
					(	ds_readbs(0x268e + host_readbs(enemy + 1)) * 48 +
						weapon_type * 16 +
						((f_action == 2) ? 0 : 1) * 8 +
						host_readbs(enemy + 0x27) * 2
					)
				), 3);
		}
	}

	if (((ds_readws(0xe3ac) != 0) && (a7 == 0)) ||
		((ds_readws(0xe3aa) != 0) && (a7 == 1))) {

			p1 += copy_ani_seq(p1, host_readws(p4 + l1 * 2), 1);

			if (weapon_type != -1) {

				/* copy the weapon ani */
				p2 += copy_ani_seq(p2,
					ds_readws(0x25fe +
					((ds_readbs(0x268e + host_readbs(enemy + 1)) * 48 + weapon_type * 16) +
					((f_action == 2) ? 0 : 1) * 8 + host_readbs(enemy + 0x27) * 2)), 3);
			}
	}

	if ( ((ds_readws(0xe3a8) != 0) && (a7 == 0)) ||
		((ds_readws(0xe3a6) != 0) && (a7 == 1)))
	{
		host_writeb(p1++, 0xfc);
		host_writeb(p1++, get_seq_header(host_readws(p4 + 0x28)));
		host_writeb(p1++, 0);

		p1 += copy_ani_seq(p1, host_readws(p4 + 0x28), 1);
	}

	FIG_set_0e(host_readbs(enemy + 0x26), (signed char)a1);
	/* terminate figure animation array */
	host_writebs(p1, -1);

	/* does this sprite need two fields */
	if (is_in_byte_array(host_readb(enemy + 1), p_datseg + TWO_FIELDED_SPRITE_ID))	{

		memcpy(p_datseg + 0xdab4 + a1 * 0xf3, p_datseg + 0xd8ce + a1 * 0xf3, 0xf3);

		p3 = Real2Host(FIG_get_ptr(host_readbs(enemy + 0x26)));

		FIG_set_0e(ds_readbs(0xe35a + host_readbs(p3 + 0x13)), a1 + 2);
	}

	if (weapon_type != -1) {
		FIG_set_0f(host_readbs(enemy + 0x26), a1 + 4);
		/* terminate weapon animation array */
		host_writeb(p2, 0xff);
	}

	if (f_action == 100) {
		ds_writeb(0xd82d + (signed char)fid_attacker, 1);
	}
}
Exemple #15
0
/* Borlandified and identical */
void FIG_prepare_hero_fight_ani(signed short a1, Bit8u *hero, signed short weapon_type, signed short f_action, signed short fid_attacker, signed short fid_target, signed short a7)
{
	signed short l1;
	signed short attacker_x;
	signed short attacker_y;
	signed short target_x;
	signed short target_y;
	signed short dir;
	signed short l7;
	signed short l8;
	signed short l9;
	signed short l10;
	Bit8u *p1;
	Bit8u *p2;
	signed short weapon;
	Bit8u *p3;

	p3 = Real2Host(ds_readd(0x2555 + host_readbs(hero + 0x9b) * 4));
	weapon = host_readws(hero + 0x1c0);

	if ((signed char)fid_target != 0) {
		FIG_search_obj_on_cb((signed char)fid_target, &target_x, &target_y);
		FIG_search_obj_on_cb((signed char)fid_attacker, &attacker_x, &attacker_y);

#if !defined(__BORLANDC__)
		/* BE-fix */
		target_x = host_readws((Bit8u*)&target_x);
		target_y = host_readws((Bit8u*)&target_y);
		attacker_x = host_readws((Bit8u*)&attacker_x);
		attacker_y = host_readws((Bit8u*)&attacker_y);
#endif
		if (attacker_x == target_x) {
			if (target_y < attacker_y) {
				dir = 1;
			} else {
				dir = 3;
			}
		} else {
			if (target_x < attacker_x) {
				dir = 2;
			} else {
				dir = 0;
			}
		}
	} else {
		dir = host_readbs(hero + 0x82);
	}

	if ((weapon_type == -1) || ((host_readbs(hero + 0x21) == 9) && (weapon == 0x85))) {

		l1 = (f_action == 2) ? 45 :			/* melee attack */
			(f_action == 102) ? 41 :		/* drink potion */
			(f_action == 103) ? 53 :		/* cast spell */
			49;

	} else {
		l1 = (f_action == 2) ?  21:			/* melee attack */
			(f_action == 102) ? 41 :		/* drink potion */
			(f_action == 103) ? 53 :		/* cast spell */
			(f_action != 15) ? 25 :
			(weapon_type == 3) ? 33 :
			(weapon_type == 4) ? 57 :
			61;
	}

	l1 += dir;
	p1 = p_datseg + 0xd8cf + 0xf3 * a1;
	p2 = p_datseg + 0xdc9b + 0xf3 * a1;

	ds_writeb(0xd8ce + 0xf3 * a1, get_seq_header(host_readws(p3 + l1 * 2)));
	ds_writeb(0xd9c0 + 0xf3 * a1, host_readbs(hero + 0x9b));

	if (check_hero(hero) && (host_readbs(hero + 0x82) != dir) &&

		((f_action == 2) || (f_action == 15) || (f_action == 103) ||
			((f_action == 100) && !ds_readbs(0xd84a + (signed char)fid_attacker)) ||
			((ds_readws(0xe3ac) != 0) && (a7 == 0)) ||
			((ds_readws(0xe3aa) != 0) && (a7 == 1))))
	{

			ds_writeb(0xd8ce + a1 * 0xf3, 0);
			l8 = l7 = -1;
			l9 = host_readbs(hero + 0x82);
			l8 = l9;
			l9++;

			if (l9 == 4) {
				l9 = 0;
			}

			if (l9 != dir) {
				l7 = l9;
				l9++;
				if (l9 == 4) {
					l9 = 0;
				}

				if (l9 != dir) {
					l8 = host_readbs(hero + 0x82) + 4;
					l7 = -1;
				}
			}

			host_writeb(hero + 0x82, (signed char)dir);

			if (l7 == -1) {
				for (l10 = 0; l10 < 2; l10++) {
					host_writeb(p1++, 0xfb);
					host_writeb(p1++, 0);
					host_writeb(p1++, 0);
				}
			}

			p1 += copy_ani_seq(p1, host_readws(p3 + l8 * 2), 2);

			if (l7 != -1) {
				p1 += copy_ani_seq(p1, host_readws(p3 + l7 * 2), 2);
			}

			host_writeb(p1++, 0xfc);
			host_writeb(p1++, get_seq_header(host_readws(p3 + l1 * 2)));
			host_writeb(p1++, 0);
	} else {
		for (l10 = 0; l10 < 5; l10++) {
			host_writeb(p1++, 0xfb);
			host_writeb(p1++, 0);
			host_writeb(p1++, 0);
		}
	}

	if ((check_hero(hero) && (f_action == 2)) ||
		((f_action == 15) || (f_action == 102) || (f_action == 103) ||
			((f_action == 100) && !ds_readbs(0xd84a + (signed char)fid_attacker))))
	{
		p1 += copy_ani_seq(p1, host_readws(p3 + l1 *2), 2);

		if ((weapon_type != -1) && (weapon_type < 3) &&
			(host_readb(hero + 0x21) != 9) &&
			(host_readb(hero + 0x21) != 8))
		{
			for (l10 = 0; l10 < 5; l10++) {
				host_writeb(p2++, 0xfb);
				host_writeb(p2++, 0);
				host_writeb(p2++, 0);
			}

			p2 += copy_ani_seq(p2,
				ds_readw(0x25fe +
				((ds_readbs(0x268e + host_readbs(hero + 0x9b)) * 48 + weapon_type * 16) +
				((f_action == 2) ? 0 : 1) * 8 + host_readbs(hero + 0x82) * 2)), 3);
		}
	}

	if ((check_hero(hero) && ds_readw(0xe3ac) != 0 && a7 == 0) ||
		((ds_readw(0xe3aa) != 0) && (a7 == 1))) {

			p1 += copy_ani_seq(p1, host_readws(p3 + l1 * 2), 2);

			if ((weapon_type != -1) && (weapon_type < 3) &&
				(host_readb(hero + 0x21) != 9) &&
				(host_readb(hero + 0x21) != 8))
			{
				p2 += copy_ani_seq(p2,
					ds_readw(0x25fe +
					((ds_readbs(0x268e + host_readbs(hero + 0x9b)) * 48 + weapon_type * 16) +
					((f_action == 2) ? 0 : 1) * 8 + host_readbs(hero + 0x82) * 2)), 3);
			}
	}

	if ( ((ds_readw(0xe3a8) != 0) && (a7 == 0)) ||
		((ds_readw(0xe3a6) != 0) && (a7 == 1)))
	{
		host_writeb(p1++, 0xfc);
		host_writeb(p1++, get_seq_header(host_readws(p3 + 0x28)));
		host_writeb(p1++, 0);

		p1 += copy_ani_seq(p1, host_readws(p3 + 0x28), 2);
	}

	if (check_hero(hero) ||
		((ds_readw(0xe3a8) != 0) && (a7 == 0)) ||
		((ds_readw(0xe3a6) != 0) && (a7 == 1)))
	{
		FIG_set_0e(host_readb(hero + 0x81), (signed char)a1);
		host_writebs(p1, -1);

		if ( (weapon_type != -1) && (weapon_type < 3) &&
			(host_readb(hero + 0x21) != 9) &&
			(host_readb(hero + 0x21) != 8))
		{
			FIG_set_0f(host_readb(hero + 0x81), a1 + 4);
			host_writeb(p2, 0xff);
		}
	}

	host_writeb(p1, 0xff);
	if (f_action == 100) {
		ds_writeb(0xd84a + (signed char)fid_attacker, 1);
	}
}