From 5ffdaa8142da27c68f467f26c4f28129865b7bf9 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 12:59:55 -0700 Subject: Moved huge conditional out of InStateChasing(), improving readability Squashed a warning. --- src/Mobs/AggressiveMonster.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/Mobs/AggressiveMonster.cpp') diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 0901f85a9..cafa7ee74 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -37,7 +37,7 @@ void cAggressiveMonster::InStateChasing(float a_Dt) } } - if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ())) + if (!IsMovingToTargetPosition()) { MoveToPosition(m_Target->GetPosition()); } @@ -106,3 +106,18 @@ void cAggressiveMonster::Attack(float a_Dt) +bool cAggressiveMonster::IsMovingToTargetPosition() +{ + float epsilon = 0.000000000001; + //Difference between destination x and target x is negligable (to 10^-12 precision) + if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon) + { + return false; + } + //Difference between destination z and target z is negligable (to 10^-12 precision) + else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon) + { + return false; + } + return true; +} -- cgit v1.2.3 From aef2c8ec628aa2522364da1333bc5158e55ac6a2 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 09:21:49 -0700 Subject: Further refactored, Reverted Minecart change Other small changes. --- src/Mobs/AggressiveMonster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Mobs/AggressiveMonster.cpp') diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index cafa7ee74..3e5f72dbf 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -109,12 +109,12 @@ void cAggressiveMonster::Attack(float a_Dt) bool cAggressiveMonster::IsMovingToTargetPosition() { float epsilon = 0.000000000001; - //Difference between destination x and target x is negligable (to 10^-12 precision) + // Difference between destination x and target x is negligible (to 10^-12 precision) if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon) { return false; } - //Difference between destination z and target z is negligable (to 10^-12 precision) + // Difference between destination z and target z is negligible (to 10^-12 precision) else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon) { return false; -- cgit v1.2.3 From e2194e6e9083b54914deac3a5a6c2e3e4d262990 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 15:32:14 -0700 Subject: Added static const, initialized fields. --- src/Mobs/AggressiveMonster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Mobs/AggressiveMonster.cpp') diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 3e5f72dbf..4997952be 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -108,7 +108,7 @@ void cAggressiveMonster::Attack(float a_Dt) bool cAggressiveMonster::IsMovingToTargetPosition() { - float epsilon = 0.000000000001; + static const float epsilon = 0.000000000001; // Difference between destination x and target x is negligible (to 10^-12 precision) if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon) { -- cgit v1.2.3 From 9dc9713a9c3015d2b67fc18fc2fb8f3b5ce8d734 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Apr 2014 23:12:52 +0200 Subject: Fixed warnings. --- src/Mobs/AggressiveMonster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Mobs/AggressiveMonster.cpp') diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 4997952be..447bf3549 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -108,14 +108,14 @@ void cAggressiveMonster::Attack(float a_Dt) bool cAggressiveMonster::IsMovingToTargetPosition() { - static const float epsilon = 0.000000000001; + static const float epsilon = 0.000000000001f; // Difference between destination x and target x is negligible (to 10^-12 precision) if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon) { return false; } // Difference between destination z and target z is negligible (to 10^-12 precision) - else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon) + else if (fabsf((float)m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon) { return false; } -- cgit v1.2.3