EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Development (https://www.eqemulator.org/forums/forumdisplay.php?f=590)
-   -   GetReciprocalHeading() (https://www.eqemulator.org/forums/showthread.php?t=29097)

joligario 08-01-2009 08:54 AM

GetReciprocalHeading()
 
Code:

2182 float Mob::GetReciprocalHeading(Mob* target) {
2183 float Result = 0;
2184
2185 if(target) {
2186 float h = target->GetHeading();
2187
2188 if(h > 0.0 && h < 128.0)
2189 Result = h + 128.0;
2190 else if(h > 128.0 && h < 256)
2191 Result = h - 128.0;
2192 else if(h == 128.0)
2193 Result = 255.9;
2194 else
2195 Result = h;
2196 }
2197
2198 return Result;
2199 }

Just a note for the author of this code:

First off, great idea! Just 2 questions, though. What if the heading is already 0.0 and wouldn't it be easier to just do a mod?

Code:

float Mob::GetReciprocalHeading(Mob* target) {
  float Result = 0;

  if(target) {
    float h = target->GetHeading();
    Result = (h + 128.0) % 256;
  }

  return Result;
}


WildcardX 08-01-2009 12:28 PM

Thanks. Yours looks cleaner. Obviously, I should have spent more time paying attention in math class :-) I'm trying it out in branch now along with some new code to get bot rogue's and rogue pet's to position themselves behind a mob they are attacking.


All times are GMT -4. The time now is 12:14 PM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.