summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorDave SIMmONs <simon@lindenlab.com>2011-03-22 15:44:02 -0700
committerDave SIMmONs <simon@lindenlab.com>2011-03-22 15:44:02 -0700
commitbecc9d09970755f9cc0d95c46b9f2d81d5b856b5 (patch)
tree5ed8a71a6daed1df44d02d835bd98b375d868963 /indra
parent1c34f5caff0f074e983a8ef4d89fd08f1210f526 (diff)
Improve LLEventHost API for autopilot and following avatars. Reviewed by Kelly.
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/llagent.cpp11
-rw-r--r--indra/newview/llagent.h2
-rw-r--r--indra/newview/llagentlistener.cpp109
-rw-r--r--indra/newview/llagentlistener.h7
4 files changed, 113 insertions, 16 deletions
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 75acd1a0be..fd5cee2772 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -1326,7 +1326,7 @@ void LLAgent::setAutoPilotTargetGlobal(const LLVector3d &target_global)
//-----------------------------------------------------------------------------
// startFollowPilot()
//-----------------------------------------------------------------------------
-void LLAgent::startFollowPilot(const LLUUID &leader_id)
+void LLAgent::startFollowPilot(const LLUUID &leader_id, BOOL allow_flying, F32 stop_distance)
{
mLeaderID = leader_id;
if ( mLeaderID.isNull() ) return;
@@ -1338,7 +1338,14 @@ void LLAgent::startFollowPilot(const LLUUID &leader_id)
return;
}
- startAutoPilotGlobal(object->getPositionGlobal());
+ startAutoPilotGlobal(object->getPositionGlobal(),
+ std::string(), // behavior_name
+ NULL, // target_rotation
+ NULL, // finish_callback
+ NULL, // callback_data
+ stop_distance,
+ 0.03f, // rotation_threshold
+ allow_flying);
}
diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h
index a45f55f27a..33c05816e2 100644
--- a/indra/newview/llagent.h
+++ b/indra/newview/llagent.h
@@ -481,7 +481,7 @@ public:
void (*finish_callback)(BOOL, void *) = NULL, void *callback_data = NULL,
F32 stop_distance = 0.f, F32 rotation_threshold = 0.03f,
BOOL allow_flying = TRUE);
- void startFollowPilot(const LLUUID &leader_id);
+ void startFollowPilot(const LLUUID &leader_id, BOOL allow_flying = TRUE, F32 stop_distance = 0.5f);
void stopAutoPilot(BOOL user_cancel = FALSE);
void setAutoPilotTargetGlobal(const LLVector3d &target_global);
void autoPilot(F32 *delta_yaw); // Autopilot walking action, angles in radians
diff --git a/indra/newview/llagentlistener.cpp b/indra/newview/llagentlistener.cpp
index 6b12853547..0d30b95074 100644
--- a/indra/newview/llagentlistener.cpp
+++ b/indra/newview/llagentlistener.cpp
@@ -31,6 +31,7 @@
#include "llagentlistener.h"
#include "llagent.h"
+#include "llvoavatar.h"
#include "llcommandhandler.h"
#include "llslurl.h"
#include "llurldispatcher.h"
@@ -79,7 +80,8 @@ LLAgentListener::LLAgentListener(LLAgent &agent)
"[\"stop_distance\"]: target maxiumum distance from target [default: autopilot guess]\n"
"[\"target_rotation\"]: array of [x, y, z, w] quaternion values [default: no target]\n"
"[\"rotation_threshold\"]: target maximum angle from target facing rotation [default: 0.03 radians]\n"
- "[\"behavior_name\"]: name of the autopilot behavior [default: \"\"]",
+ "[\"behavior_name\"]: name of the autopilot behavior [default: \"\"]"
+ "[\"allow_flying\"]: allow flying during autopilot [default: True]",
//"[\"callback_pump\"]: pump to send success/failure and callback data to [default: none]\n"
//"[\"callback_data\"]: data to send back during a callback [default: none]",
&LLAgentListener::startAutoPilot);
@@ -97,7 +99,10 @@ LLAgentListener::LLAgentListener(LLAgent &agent)
&LLAgentListener::getAutoPilot,
LLSDMap("reply", LLSD()));
add("startFollowPilot",
- "Follow [\"leader_id\"] using the autopilot system.",
+ "[\"leader_id\"]: uuid of target to follow using the autopilot system (optional with avatar_name)\n"
+ "[\"avatar_name\"]: avatar name to follow using the autopilot system (optional with leader_id)\n"
+ "[\"allow_flying\"]: allow flying during autopilot [default: True]\n"
+ "[\"stop_distance\"]: target maxiumum distance from target [default: autopilot guess]",
&LLAgentListener::startFollowPilot);
add("setAutoPilotTarget",
"Update target for currently running autopilot:\n"
@@ -213,7 +218,7 @@ void LLAgentListener::getPosition(const LLSD& event) const
}
-void LLAgentListener::startAutoPilot(LLSD const & event) const
+void LLAgentListener::startAutoPilot(LLSD const & event)
{
LLQuaternion target_rotation_value;
LLQuaternion* target_rotation = NULL;
@@ -239,11 +244,20 @@ void LLAgentListener::startAutoPilot(LLSD const & event) const
}
}
+ F32 stop_distance = 0.f;
+ if (event.has("stop_distance"))
+ {
+ stop_distance = event["stop_distance"].asReal();
+ }
+
+ // Clear follow target, this is doing a path
+ mFollowTarget.setNull();
+
mAgent.startAutoPilotGlobal(ll_vector3d_from_sd(event["target_global"]),
event["behavior_name"],
target_rotation,
NULL, NULL,
- event["stop_distance"].asReal(),
+ stop_distance,
rotation_threshold,
allow_flying);
}
@@ -251,11 +265,29 @@ void LLAgentListener::startAutoPilot(LLSD const & event) const
void LLAgentListener::getAutoPilot(const LLSD& event) const
{
LLSD reply = LLSD::emptyMap();
- reply["enabled"] = (LLSD::Boolean) mAgent.getAutoPilot();
+
+ LLSD::Boolean enabled = mAgent.getAutoPilot();
+ reply["enabled"] = enabled;
+
reply["target_global"] = ll_sd_from_vector3d(mAgent.getAutoPilotTargetGlobal());
+
reply["leader_id"] = mAgent.getAutoPilotLeaderID();
+
reply["stop_distance"] = mAgent.getAutoPilotStopDistance();
+
reply["target_distance"] = mAgent.getAutoPilotTargetDist();
+ if (!enabled &&
+ mFollowTarget.notNull())
+ { // Get an actual distance from the target object we were following
+ LLViewerObject * target = gObjectList.findObject(mFollowTarget);
+ if (target)
+ { // Found the target AV, return the actual distance to them as well as their ID
+ LLVector3 difference = target->getPositionRegion() - mAgent.getPositionAgent();
+ reply["target_distance"] = difference.length();
+ reply["leader_id"] = mFollowTarget;
+ }
+ }
+
reply["use_rotation"] = (LLSD::Boolean) mAgent.getAutoPilotUseRotation();
reply["target_facing"] = ll_sd_from_vector3(mAgent.getAutoPilotTargetFacing());
reply["rotation_threshold"] = mAgent.getAutoPilotRotationThreshold();
@@ -265,19 +297,76 @@ void LLAgentListener::getAutoPilot(const LLSD& event) const
sendReply(reply, event);
}
-void LLAgentListener::startFollowPilot(LLSD const & event) const
+void LLAgentListener::startFollowPilot(LLSD const & event)
{
- mAgent.startFollowPilot(event["leader_id"]);
+ LLUUID target_id;
+
+ BOOL allow_flying = TRUE;
+ if (event.has("allow_flying"))
+ {
+ allow_flying = (BOOL) event["allow_flying"].asBoolean();
+ }
+
+ if (event.has("leader_id"))
+ {
+ target_id = event["leader_id"];
+ }
+ else if (event.has("avatar_name"))
+ { // Find the avatar with matching name
+ std::string target_name = event["avatar_name"].asString();
+
+ if (target_name.length() > 0)
+ {
+ S32 num_objects = gObjectList.getNumObjects();
+ S32 cur_index = 0;
+ while (cur_index < num_objects)
+ {
+ LLViewerObject * cur_object = gObjectList.getObject(cur_index++);
+ if (cur_object &&
+ cur_object->asAvatar() &&
+ cur_object->asAvatar()->getFullname() == target_name)
+ { // Found avatar with matching name, extract id and break out of loop
+ target_id = cur_object->getID();
+ break;
+ }
+ }
+ }
+ }
+
+ F32 stop_distance = 0.f;
+ if (event.has("stop_distance"))
+ {
+ stop_distance = event["stop_distance"].asReal();
+ }
+
+ if (target_id.notNull())
+ {
+ if (!allow_flying)
+ {
+ mAgent.setFlying(FALSE);
+ }
+ mFollowTarget = target_id; // Save follow target so we can report distance later
+
+ mAgent.startFollowPilot(target_id, allow_flying, stop_distance);
+ }
}
void LLAgentListener::setAutoPilotTarget(LLSD const & event) const
{
- LLVector3d target_global(ll_vector3d_from_sd(event["target_global"]));
- mAgent.setAutoPilotTargetGlobal(target_global);
+ if (event.has("target_global"))
+ {
+ LLVector3d target_global(ll_vector3d_from_sd(event["target_global"]));
+ mAgent.setAutoPilotTargetGlobal(target_global);
+ }
}
void LLAgentListener::stopAutoPilot(LLSD const & event) const
{
- mAgent.stopAutoPilot(event["user_cancel"]);
+ BOOL user_cancel = FALSE;
+ if (event.has("user_cancel"))
+ {
+ user_cancel = event["user_cancel"].asBoolean();
+ }
+ mAgent.stopAutoPilot(user_cancel);
}
diff --git a/indra/newview/llagentlistener.h b/indra/newview/llagentlistener.h
index 40225c9c63..aadb87db12 100644
--- a/indra/newview/llagentlistener.h
+++ b/indra/newview/llagentlistener.h
@@ -47,14 +47,15 @@ private:
void resetAxes(const LLSD& event) const;
void getAxes(const LLSD& event) const;
void getPosition(const LLSD& event) const;
- void startAutoPilot(const LLSD& event) const;
+ void startAutoPilot(const LLSD& event);
void getAutoPilot(const LLSD& event) const;
- void startFollowPilot(const LLSD& event) const;
+ void startFollowPilot(const LLSD& event);
void setAutoPilotTarget(const LLSD& event) const;
void stopAutoPilot(const LLSD& event) const;
private:
- LLAgent & mAgent;
+ LLAgent & mAgent;
+ LLUUID mFollowTarget;
};
#endif // LL_LLAGENTLISTENER_H