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

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

Reply
 
Thread Tools Display Modes
  #1  
Old 12-14-2004, 05:46 AM
mollymillions's Avatar
mollymillions
Hill Giant
 
Join Date: May 2003
Posts: 176
Default Pathing

I have a solution to get MOBs to flee using their grid waypoints only. It seems to work 100% (really!). MOBs that do not have grids assigned will not flee.



Code:
Index: attack.cpp
===================================================================
RCS file: /cvsroot/eqemulator/EQEmuCVS/Source/zone/attack.cpp,v
retrieving revision 1.23
diff -u -w -b -r1.23 attack.cpp
--- attack.cpp	16 Nov 2004 20:06:34 -0000	1.23
+++ attack.cpp	15 Dec 2004 18:27:32 -0000
@@ -1763,6 +1763,19 @@
 		Death(other, damage, spell_id, attack_skill);

 		return;

 	}

+	//Flee if HP low
+	if ( flee_state == fleeStateNotFleeing  && !IsRooted() && GetHPRatio() <= 20){				
+	
+		sint16 gridno = CastToNPC()->GetGrid(); 		
+		if (gridno > 0)  {
+			Mob::CalculateNewWaypoint();	
+			flee_state = fleeStateFleeing;
+		} else {
+			flee_state = fleeStateGridless;
+ 		}
+	}
+
 	APPLAYER* outapp = new APPLAYER(OP_Damage, sizeof(CombatDamage_Struct));

 	//outapp->pBuffer = new uchar[outapp->size];

 	//memset(outapp->pBuffer, 0, sizeof(CombatDamage_Struct)); 					

Index: mob.cpp
===================================================================
RCS file: /cvsroot/eqemulator/EQEmuCVS/Source/zone/mob.cpp,v
retrieving revision 1.17
diff -u -w -b -r1.17 mob.cpp
--- mob.cpp	8 Nov 2004 23:02:06 -0000	1.17
+++ mob.cpp	15 Dec 2004 18:17:58 -0000
@@ -309,6 +309,8 @@
 	cur_wp=0;
 	patrol=0;
 	follow=0;
+	flee_state = fleeStateNotFleeing;
+
 #ifdef ENABLE_FEAR_PATHING
 	fear_state = fearStateNotFeared;
 #endif
@@ -482,6 +484,8 @@
         return 0.0f;
     if (spellbonuses.movementspeed || itembonuses.movementspeed)
         aa_speed += (spellbonuses.movementspeed+itembonuses.movementspeed) / 100.0f;
+	if (GetHPRatio() < 20)
+		return (runspeed * aa_speed * (GetHPRatio()/20));
 
         return (runspeed * aa_speed);
 }
Index: MobAI.cpp
===================================================================
RCS file: /cvsroot/eqemulator/EQEmuCVS/Source/zone/MobAI.cpp,v
retrieving revision 1.7
diff -u -w -b -r1.7 MobAI.cpp
--- MobAI.cpp	8 Nov 2004 23:01:45 -0000	1.7
+++ MobAI.cpp	15 Dec 2004 18:17:58 -0000
@@ -506,6 +506,37 @@
 	}
 #endif
 	
+	if(flee_state == fleeStateFleeing) {
+		
+		//stop fleeing if HP recovered
+		if (GetHPRatio() > 20) {
+			flee_state = fleeStateNotFleeing;
+		}
+		
+		if(IsRooted()) {
+			if(IsMoving()) {
+				SetHeading(CalculateHeadingToTarget(target->GetX(), target->GetY()));				
+				SetRunAnimSpeed(0);
+				SendPosition();
+				SetMoving(false);
+				moved=false;
+			}
+			return;
+		}
+		
+		if(AImovement_timer->Check()) {
+			if (cur_wp_x == GetX() && cur_wp_y == GetY()) {
+				entity_list.OpenDoorsNear(CastToNPC());
+				CalculateNewWaypoint();
+			}	
+
+			CalculateNewPosition2(cur_wp_x, cur_wp_y, cur_wp_z, GetRunspeed(), true);		    
+		}
+
+		return;
+	}
+
 	if (IsEngaged()) 
 	{
 		_ZP(Mob_AI_Process_engaged);
Index: mob.h
===================================================================
RCS file: /cvsroot/eqemulator/EQEmuCVS/Source/zone/mob.h,v
retrieving revision 1.9
diff -u -w -b -r1.9 mob.h
--- mob.h	16 Nov 2004 20:06:37 -0000	1.9
+++ mob.h	15 Dec 2004 18:17:58 -0000
@@ -102,6 +102,15 @@
 				//X,Y,Z are old interactive NPC codes

 };

 

+enum {	//flee states
+
+	fleeStateNotFleeing = 0,	
+	
+	fleeStateFleeing,
+
+	fleeStateGridless
+
+};


 enum {	//fear states

 	fearStateNotFeared = 0,

 	fearStateRunning,

@@ -928,7 +937,7 @@
 	int32	npc_spells_id;

 	AISpells_Struct	AIspells[MAX_AISPELLS]; // expected to be pre-sorted, best at low index

 	HateList hate_list;

-	

+	uint8 flee_state;

 	

 #ifdef ENABLE_FEAR_PATHING

 	void SetFeared(Mob *caster, int32 duration);
Reply With Quote
  #2  
Old 12-14-2004, 08:54 AM
daeken_bb
Discordant
 
Join Date: Mar 2003
Location: Chambersburg, PA
Posts: 469
Default

That is a crazy, crazy hack...

I like it!
__________________
Keep me unemployed and working on OpenEQ, PM me about donating

Check out my deviantART page at http://daeken.deviantart.com/
Reply With Quote
  #3  
Old 12-14-2004, 03:22 PM
Scorpx725
Discordant
 
Join Date: Feb 2003
Location: Wish I knew.
Posts: 251
Default

Wow, very nice job.

I honestly have no clue what that is, but mobs fleeing on their grids is cool.
__________________
* KingMort has left #eqemu
<Richardo> KingDrama has left #EQEMU
<Richardo> the rule my pants!
Reply With Quote
  #4  
Old 12-23-2004, 06:48 PM
mollymillions's Avatar
mollymillions
Hill Giant
 
Join Date: May 2003
Posts: 176
Default

As this is the first mod I've posted, I'm wondering what the consensus on this code is, Good, Bad or just plain Ugly?

-I had to override GetHPRatio to get the correct mob HP calculation (line numbers are approximate):
Code:
zone/mob.h, line 445
	virtual inline float		GetHPRatio() { return max_hp == 0 ? 0 : ((float)cur_hp/max_hp*100); }
-->
	virtual inline float		GetHPRatio() { return max_hp == 0 ? 0 : ((float)cur_hp/max_hp*100); }
	virtual inline float		GetHPRatio(float damage) { return max_hp == 0 ? 0 : ((float)(cur_hp-damage)/max_hp*100); }


zone/attack.cpp, line 1770
	if ( flee_state == fleeStateNotFleeing  &amp;&amp; !IsRooted() &amp;&amp; GetHPRatio() &lt;= 21){		
-->
	if ( flee_state == fleeStateNotFleeing  &amp;&amp; !IsRooted() &amp;&amp; GetHPRatio(damage) &lt; 15){
-Mobs fleeing when HP&lt;20 sucks, changed to 15.
Reply With Quote
Reply


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 07:39 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 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3