Sanity check added before calculating distance.

This commit is contained in:
KayenEQ 2014-11-28 05:42:36 -05:00
parent 94a0cb3522
commit ac0933719a
3 changed files with 10 additions and 3 deletions

View File

@ -468,6 +468,7 @@ typedef struct
float origin_x;
float origin_y;
float origin_z;
float sanitycheck;
uint32 ranged_id;
uint32 ammo_id;
int ammo_slot;

View File

@ -297,6 +297,7 @@ Mob::Mob(const char* in_name,
ProjectileAtk[i].origin_x = 0.0f;
ProjectileAtk[i].origin_y = 0.0f;
ProjectileAtk[i].origin_z = 0.0f;
ProjectileAtk[i].sanitycheck = 0.0f;
ProjectileAtk[i].ranged_id = 0;
ProjectileAtk[i].ammo_id = 0;
ProjectileAtk[i].ammo_slot = 0;

View File

@ -1075,9 +1075,14 @@ void Mob::ProjectileAttack()
Mob* target = entity_list.GetMobID(ProjectileAtk[i].target_id);
if (target && target->IsMoving()){ //Only recalculate hit increment if target moving
float distance = target->CalculateDistance(ProjectileAtk[i].origin_x, ProjectileAtk[i].origin_y, ProjectileAtk[i].origin_z);
float hit = 60.0f + (distance / 1.8f); //Calcuation: 60 = Animation Lag, 1.8 = Speed modifier for speed of (4)
ProjectileAtk[i].hit_increment = static_cast<uint16>(hit);
//Due to frequency that we need to check increment the targets position variables may not be updated even if moving. Do a simple check before calculating distance.
if (ProjectileAtk[i].sanitycheck != target->GetX() * target->GetY()){
ProjectileAtk[i].sanitycheck = target->GetX() * target->GetY();
float distance = target->CalculateDistance(ProjectileAtk[i].origin_x, ProjectileAtk[i].origin_y, ProjectileAtk[i].origin_z);
float hit = 60.0f + (distance / 1.8f); //Calcuation: 60 = Animation Lag, 1.8 = Speed modifier for speed of (4)
ProjectileAtk[i].hit_increment = static_cast<uint16>(hit);
}
}
if (ProjectileAtk[i].hit_increment <= ProjectileAtk[i].increment){