Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-13-2003, 12:25 AM
Wiz
Dragon
 
Join Date: Feb 2002
Posts: 583
Default Basic Line of Sight

This function will use the nodes in .map files to apply line of sight (prevents wall aggro if used right, among other things). It is not perfect yet, as it tends to fail on thin walls, or walls on top of other floors (such as in unrest or hole), but it's a start.

Code:
bool Mob::CheckLos(Mob* other) {
	if (zone->map == 0)
	{
		return true;
	}
	float tmp_x = GetX();
	float tmp_y = GetY();
	float trg_x = other->GetX();
	float trg_y = other->GetY();
	float perwalk_x = 0.2;
	float perwalk_y = 0.2;
	float dist_x = tmp_x - trg_x;
	if (dist_x < 0)
		dist_x *= -1;
	float dist_y = tmp_y - trg_y;
	if (dist_y < 0)
		dist_y *= -1;
	if (dist_x  < dist_y)
		perwalk_x /= (dist_y/dist_x);
	else if (dist_y < dist_x)
		perwalk_y /= (dist_x/dist_y);
	while (1) {
		if (tmp_x < trg_x)
		{
			if (tmp_x + perwalk_x < trg_x)
				tmp_x += perwalk_x;
			else
				tmp_x = trg_x;
		}
		if (tmp_y < trg_y)
		{
			if (tmp_y + perwalk_y < trg_y)
				tmp_y += perwalk_y;
			else
				tmp_y = trg_y;
		}
		if (tmp_x > trg_x)
		{
			if (tmp_x - perwalk_x > trg_x)
				tmp_x -= perwalk_x;
			else
				tmp_x = trg_x;
		}
		if (tmp_y > trg_y)
		{
			if (tmp_y - perwalk_y > trg_y)
				tmp_y -= perwalk_y;
			else
				tmp_y = trg_y;
		}
		if (tmp_y == trg_y && tmp_x == trg_x)
		{
			return true;
		}
		PNODE pnode = zone->map->SeekNode( zone->map->GetRoot(), tmp_x, tmp_y );
		if (pnode != 0)
		{
			int *iface = zone->map->SeekFace( pnode, tmp_x, tmp_y );
			if (*iface == -1) {
				return false;
			}							
		}
	}
	return true;
}
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 05:28 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3