ScriptInterpretedAPI.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Reflection;
  29. using System.Text;
  30. using Axiom.Math;
  31. using log4net;
  32. using OpenSim.Region.Environment.Interfaces;
  33. using OpenSim.Region.Environment.Scenes;
  34. using Key = libsecondlife.LLUUID;
  35. using Rotation = libsecondlife.LLQuaternion;
  36. using Vector = libsecondlife.LLVector3;
  37. using LSLList = System.Collections.Generic.List<string>;
  38. namespace OpenSim.Region.ExtensionsScriptModule
  39. {
  40. /// <summary>
  41. /// A class inteded to act as an API for LSL-styled interpreted languages
  42. /// </summary>
  43. /// <remarks>Avoid at all costs. This should ONLY be used for LSL.</remarks>
  44. internal class ScriptInterpretedAPI
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. protected Key m_object;
  48. protected Scene m_scene;
  49. /// <summary>
  50. /// The scene in which this script is acting
  51. /// </summary>
  52. public Scene Scene
  53. {
  54. get { return m_scene; }
  55. }
  56. /// <summary>
  57. /// The id of the object our script is supposed to be acting in
  58. /// </summary>
  59. public Key ObjectID
  60. {
  61. get { return m_object; }
  62. }
  63. /// <summary>
  64. /// The object our script is supposed to be in
  65. /// </summary>
  66. public SceneObjectGroup Task
  67. {
  68. // XXX Casting not ideal, but previous Scene.Objects propery wasn't actually populated, so
  69. // wouldn't have worked anyway.
  70. get { return (SceneObjectGroup)Scene.Entities[ObjectID]; }
  71. }
  72. /// <summary>
  73. /// Creates a new ScriptInterpretedAPI for a specified object
  74. /// </summary>
  75. /// <param name="world">The scene the object is located in</param>
  76. /// <param name="member">The specific member being 'occupied' by the script</param>
  77. public ScriptInterpretedAPI(Scene world, Key member)
  78. {
  79. m_scene = world;
  80. m_object = member;
  81. }
  82. /// <summary>
  83. /// Returns the absolute number of a integer value.
  84. /// </summary>
  85. /// <param name="val">Input</param>
  86. /// <returns>Absolute number of input</returns>
  87. public int osAbs(int val)
  88. {
  89. return Math.Abs(val);
  90. }
  91. public float osAcos(float val)
  92. {
  93. return (float) Math.Acos(val);
  94. }
  95. [Obsolete("Unimplemented")]
  96. public void osAddToLandPassList(Key avatar, float hours)
  97. {
  98. Vector myPosition = Task.AbsolutePosition;
  99. ILandObject myParcel = Scene.LandChannel.getLandObject(myPosition.X, myPosition.Y);
  100. if (myParcel == null)
  101. {
  102. //Dont do anything!
  103. }
  104. m_log.Warn("[script]: " +
  105. "Unimplemented function called by script: osAddToLandPassList(Key avatar, float hours)");
  106. return;
  107. }
  108. [Obsolete("Unimplemented")]
  109. public void osAdjustSoundVolume(float volume)
  110. {
  111. m_log.Warn("[script]: Unimplemented function called by script: osAdjustSoundVolume(float volume)");
  112. return;
  113. }
  114. [Obsolete("Unimplemented")]
  115. public void osAllowInventoryDrop(int add)
  116. {
  117. return;
  118. }
  119. [Obsolete("Unimplemented")]
  120. public float osAngleBetween(Rotation a, Rotation b)
  121. {
  122. Quaternion axA = new Quaternion(a.W, a.X, a.Y, a.Z);
  123. Quaternion axB = new Quaternion(b.W, b.X, b.Y, b.Z);
  124. return 0;
  125. }
  126. [Obsolete("Unimplemented")]
  127. public void osApplyImpulse(Vector force, int local)
  128. {
  129. return;
  130. }
  131. [Obsolete("Unimplemented")]
  132. public void osApplyRotationalImpulse(Vector force, int local)
  133. {
  134. return;
  135. }
  136. public float osAsin(float val)
  137. {
  138. return (float) Math.Asin(val);
  139. }
  140. public float osAtan2(float x, float y)
  141. {
  142. return (float) Math.Atan2(x, y);
  143. }
  144. [Obsolete("Unimplemented")]
  145. public void osAttachToAvatar(Key avatar, int attachmentPoint)
  146. {
  147. return;
  148. }
  149. [Obsolete("Unimplemented")]
  150. public Key osAvatarOnSitTarget()
  151. {
  152. //TODO: Follow this as Children is chanced to be of type entity to support ScenePresences
  153. /*
  154. foreach (KeyValuePair<Key, EntityBase> Child in Task.Children)
  155. {
  156. if (Child.Value is ScenePresence)
  157. {
  158. return Child.Value.uuid;
  159. }
  160. }
  161. */
  162. return Key.Zero;
  163. }
  164. public Rotation osAxes2Rot(Vector fwd, Vector left, Vector up)
  165. {
  166. Quaternion axQ = new Quaternion();
  167. Vector3 axFwd = new Vector3(fwd.X, fwd.Y, fwd.Z);
  168. Vector3 axLeft = new Vector3(left.X, left.Y, left.Z);
  169. Vector3 axUp = new Vector3(up.X, up.Y, up.Z);
  170. axQ.FromAxes(axFwd, axLeft, axUp);
  171. return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
  172. }
  173. public Rotation osAxisAngle2Rot(Vector axis, float angle)
  174. {
  175. Quaternion axQ = Quaternion.FromAngleAxis(angle, new Vector3(axis.X, axis.Y, axis.Z));
  176. return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
  177. }
  178. public string osBase64ToString(string str)
  179. {
  180. Encoding enc = Encoding.UTF8;
  181. return enc.GetString(Convert.FromBase64String(str));
  182. }
  183. [Obsolete("Unimplemented")]
  184. public void osBreakAllLinks()
  185. {
  186. return;
  187. }
  188. [Obsolete("Unimplemented")]
  189. public void osBreakLink()
  190. {
  191. return;
  192. }
  193. public LSLList osCSV2List(string src)
  194. {
  195. LSLList retVal = new LSLList();
  196. retVal.AddRange(src.Split(','));
  197. return retVal;
  198. }
  199. public int osCeil(float val)
  200. {
  201. return (int) Math.Ceiling(val);
  202. }
  203. [Obsolete("Unimplemented")]
  204. public void osCloseRemoteDataChannel(Key channel)
  205. {
  206. return;
  207. }
  208. [Obsolete("Unimplemented")]
  209. public float osCloud(Vector offset)
  210. {
  211. return 0.0f;
  212. }
  213. [Obsolete("Unimplemented")]
  214. public void osCollisionFilter(string name, Key id, int accept)
  215. {
  216. return;
  217. }
  218. [Obsolete("Unimplemented")]
  219. public void osCollisionSprite(string impact_sprite)
  220. {
  221. return;
  222. }
  223. public float osCos(float theta)
  224. {
  225. return (float) Math.Cos(theta);
  226. }
  227. public void osCreateLink(Key target, int parent)
  228. {
  229. if (Scene.Entities[target] is SceneObjectGroup)
  230. Task.LinkToGroup((SceneObjectGroup) Scene.Entities[target]);
  231. return;
  232. }
  233. [Obsolete("Partially Unimplemented")]
  234. public LSLList osDeleteSubList(LSLList src, int start, int end)
  235. {
  236. if (start < 0 || end < 0)
  237. {
  238. throw new Exception("Unsupported at this time.");
  239. }
  240. src.RemoveRange(start, start - end + 1);
  241. return src;
  242. }
  243. [Obsolete("Partially Unimplemented")]
  244. public string osDeleteSubString(string src, int start, int end)
  245. {
  246. if (start < 0 || end < 0)
  247. {
  248. throw new Exception("Unsupported at this time.");
  249. }
  250. return src.Remove(start, start - end + 1);
  251. }
  252. [Obsolete("Unimplemented")]
  253. public void osDetachFromAvatar(Key avatar)
  254. {
  255. return;
  256. }
  257. }
  258. }