protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
{
int idx = 0;
int idxStart = 0;
try
{
while (idx < rules.Length)
{
++rulesParsed;
int code = rules.GetLSLIntegerItem(idx++);
int remain = rules.Length - idx;
idxStart = idx;
switch (code)
{
case ScriptBaseClass.PRIM_POSITION:
case ScriptBaseClass.PRIM_POS_LOCAL:
if (remain < 1)
return new LSL_List();
try
{
sp.OffsetPosition = rules.GetVector3Item(idx++);
}
catch(InvalidCastException)
{
if (code == ScriptBaseClass.PRIM_POSITION)
{
Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
}
else
{
Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
}
return new LSL_List();
}
break;
case ScriptBaseClass.PRIM_ROTATION:
if (remain < 1)
return new LSL_List();
Quaternion inRot;
try
{
inRot = rules.GetQuaternionItem(idx++);
}
catch(InvalidCastException)
{
Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
return new LSL_List();
}
SceneObjectPart parentPart = sp.ParentPart;
if (parentPart != null)
sp.Rotation = m_host.GetWorldRotation() * inRot;
break;
case ScriptBaseClass.PRIM_ROT_LOCAL:
if (remain < 1)
return new LSL_List();
try
{
sp.Rotation = rules.GetQuaternionItem(idx++);
}
catch(InvalidCastException)
{
Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
return new LSL_List();
}
break;
case ScriptBaseClass.PRIM_TYPE:
Error(originFunc, "PRIM_TYPE disallowed on agent");
return new LSL_List();
case ScriptBaseClass.PRIM_OMEGA:
Error(originFunc, "PRIM_OMEGA disallowed on agent");
return new LSL_List();
case ScriptBaseClass.PRIM_LINK_TARGET:
if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
return new LSL_List();
return rules.GetSublist(idx, -1);
default:
Error(originFunc,
string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart));
return new LSL_List();
}
}
}
catch (InvalidCastException e)
{
Error(
originFunc,
string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
}
return new LSL_List();
}