aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp58
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.cpp1
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.h13
3 files changed, 71 insertions, 1 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index 722f86a2392..93fe943b26b 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -2217,6 +2217,64 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
sGameEventMgr->StartEvent(eventId, true);
break;
}
+ case SMART_ACTION_START_CLOSEST_WAYPOINT:
+ {
+ uint32 waypoints[SMART_ACTION_PARAM_COUNT];
+ waypoints[0] = e.action.closestWaypointFromList.wp1;
+ waypoints[1] = e.action.closestWaypointFromList.wp2;
+ waypoints[2] = e.action.closestWaypointFromList.wp3;
+ waypoints[3] = e.action.closestWaypointFromList.wp4;
+ waypoints[4] = e.action.closestWaypointFromList.wp5;
+ waypoints[5] = e.action.closestWaypointFromList.wp6;
+ float distanceToClosest = std::numeric_limits<float>::max();
+ WayPoint* closestWp = NULL;
+
+ ObjectList* targets = GetTargets(e, unit);
+ if (targets)
+ {
+ for (ObjectList::iterator itr = targets->begin(); itr != targets->end(); ++itr)
+ {
+ if (Creature* target = (*itr)->ToCreature())
+ {
+ if (IsSmart(target))
+ {
+ for (uint8 i = 0; i < SMART_ACTION_PARAM_COUNT; i++)
+ {
+ if (!waypoints[i])
+ continue;
+
+ WPPath* path = sSmartWaypointMgr->GetPath(waypoints[i]);
+
+ if (!path || path->empty())
+ continue;
+
+ WPPath::const_iterator itrWp = path->find(0);
+
+ if (itrWp != path->end())
+ {
+ if (WayPoint* wp = itrWp->second)
+ {
+ float distToThisPath = target->GetDistance(wp->x, wp->y, wp->z);
+
+ if (distToThisPath < distanceToClosest)
+ {
+ distanceToClosest = distToThisPath;
+ closestWp = wp;
+ }
+ }
+ }
+ }
+
+ if (closestWp)
+ CAST_AI(SmartAI, target->AI())->StartPath(false, closestWp->id, true);
+ }
+ }
+ }
+
+ delete targets;
+ }
+ break;
+ }
default:
TC_LOG_ERROR("sql.sql", "SmartScript::ProcessAction: Entry %d SourceType %u, Event %u, Unhandled Action type %u", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
break;
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
index 2e8453904a1..7b7e4fce7ea 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
@@ -1008,6 +1008,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
}
break;
}
+ case SMART_ACTION_START_CLOSEST_WAYPOINT:
case SMART_ACTION_FOLLOW:
case SMART_ACTION_SET_ORIENTATION:
case SMART_ACTION_STORE_TARGET_LIST:
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
index c79deb5d960..296c3161845 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
@@ -529,8 +529,9 @@ enum SMART_ACTION
SMART_ACTION_REMOVE_POWER = 110, // PowerType, newPower
SMART_ACTION_GAME_EVENT_STOP = 111, // GameEventId
SMART_ACTION_GAME_EVENT_START = 112, // GameEventId
+ SMART_ACTION_START_CLOSEST_WAYPOINT = 113, // wp1, wp2, wp3, wp4, wp5, wp6, wp7
- SMART_ACTION_END = 113
+ SMART_ACTION_END = 114
};
struct SmartAction
@@ -987,6 +988,16 @@ struct SmartAction
uint32 id;
} gameEventStart;
+ struct
+ {
+ uint32 wp1;
+ uint32 wp2;
+ uint32 wp3;
+ uint32 wp4;
+ uint32 wp5;
+ uint32 wp6;
+ } closestWaypointFromList;
+
//! Note for any new future actions
//! All parameters must have type uint32