From 62cee4d29f9b058aa203d86d3b175a339e4fe53f Mon Sep 17 00:00:00 2001 From: nos4r2zod Date: Sun, 27 Sep 2009 13:56:37 +0300 Subject: [PATCH] [8542] Correct formulas for destinantion coords calculation for implicit target types 72, 73, 89 Signed-off-by: Ambal --- src/game/SharedDefines.h | 6 +++--- src/game/Spell.cpp | 14 +++++++++----- src/shared/revision_nr.h | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/game/SharedDefines.h b/src/game/SharedDefines.h index 9da3f0812..7a94e32cf 100644 --- a/src/game/SharedDefines.h +++ b/src/game/SharedDefines.h @@ -1051,9 +1051,9 @@ enum Targets TARGET_SINGLE_FRIEND_2 = 57, TARGET_AREAEFFECT_PARTY_AND_CLASS = 61, TARGET_DUELVSPLAYER_COORDINATES = 63, - TARGET_BEHIND_VICTIM = 65, // uses in teleport behind spells, caster/target dependent from spell effect - TARGET_RANDOM_NEARBY_LOC = 72, // uses in teleport onto nearby locations - TARGET_RANDOM_NEARBY_LOC_LR = 73, // the same as TARGET_RANDOM_NEARBY_LOC but with larger ranges + TARGET_BEHIND_VICTIM = 65, // used in teleport behind spells, caster/target dependent from spell effect + TARGET_RANDOM_NEARBY_LOC = 72, // used in teleport onto nearby locations + TARGET_RANDOM_CIRCUMFERENCE_POINT = 73, TARGET_DYNAMIC_OBJECT_COORDINATES = 76, TARGET_SINGLE_ENEMY = 77, TARGET_POINT_AT_NORTH = 78, // 78-85 possible _COORDINATES at radius with pi/4 step around target in unknown order, N? diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 3f1877d04..36e6b611b 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -1314,10 +1314,12 @@ void Spell::SetTargetMap(uint32 effIndex,uint32 targetMode,UnitList& TagUnitMap) switch(targetMode) { case TARGET_RANDOM_NEARBY_LOC: - case TARGET_RANDOM_NEARBY_LOC_LR: + radius *= sqrt(rand_norm()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates. + case TARGET_RANDOM_CIRCUMFERENCE_POINT: { - float dest_x = m_caster->GetPositionX() + irand(-radius, radius); - float dest_y = m_caster->GetPositionY() + irand(-radius, radius); + float angle = 2.0 * M_PI * rand_norm(); + float dest_x = m_caster->GetPositionX() + cos(angle) * radius; + float dest_y = m_caster->GetPositionY() + sin(angle) * radius; float dest_z = m_caster->GetMap()->GetHeight(dest_x, dest_y, MAX_HEIGHT); m_targets.setDestination(dest_x, dest_y, dest_z); @@ -1326,8 +1328,10 @@ void Spell::SetTargetMap(uint32 effIndex,uint32 targetMode,UnitList& TagUnitMap) } case TARGET_RANDOM_NEARBY_DEST: { - float dest_x = m_targets.m_destX + irand(-radius, radius); - float dest_y = m_targets.m_destY + irand(-radius, radius); + radius *= sqrt(rand_norm()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates. + float angle = 2.0 * M_PI * rand_norm(); + float dest_x = m_targets.m_destX + cos(angle) * radius; + float dest_y = m_targets.m_destY + sin(angle) * radius; float dest_z = m_caster->GetMap()->GetHeight(dest_x, dest_y, MAX_HEIGHT); m_targets.setDestination(dest_x, dest_y, dest_z); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index b49806524..3e82e1243 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8541" + #define REVISION_NR "8542" #endif // __REVISION_NR_H__