PDA

View Full Version : Pathing


mollymillions
12-14-2004, 05:46 AM
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.




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.movementsp eed) / 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);

daeken_bb
12-14-2004, 08:54 AM
That is a crazy, crazy hack...

I like it! :D

Scorpx725
12-14-2004, 03:22 PM
Wow, very nice job.

I honestly have no clue what that is, but mobs fleeing on their grids is cool.

mollymillions
12-23-2004, 06:48 PM
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):

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 && !IsRooted() && GetHPRatio() <= 21){
-->
if ( flee_state == fleeStateNotFleeing && !IsRooted() && GetHPRatio(damage) < 15){


-Mobs fleeing when HP<20 sucks, changed to 15.