ScriptInterpretedAPI.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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.Text;
  29. using Axiom.Math;
  30. using OpenSim.Framework.Console;
  31. using OpenSim.Region.Environment.Interfaces;
  32. using OpenSim.Region.Environment.Scenes;
  33. using Key = libsecondlife.LLUUID;
  34. using Rotation = libsecondlife.LLQuaternion;
  35. using Vector = libsecondlife.LLVector3;
  36. using LSLList = System.Collections.Generic.List<string>;
  37. namespace OpenSim.Region.ExtensionsScriptModule
  38. {
  39. /// <summary>
  40. /// A class inteded to act as an API for LSL-styled interpreted languages
  41. /// </summary>
  42. /// <remarks>Avoid at all costs. This should ONLY be used for LSL.</remarks>
  43. internal class ScriptInterpretedAPI
  44. {
  45. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  46. protected Key m_object;
  47. protected Scene m_scene;
  48. /// <summary>
  49. /// The scene in which this script is acting
  50. /// </summary>
  51. public Scene Scene
  52. {
  53. get { return m_scene; }
  54. }
  55. /// <summary>
  56. /// The id of the object our script is supposed to be acting in
  57. /// </summary>
  58. public Key ObjectID
  59. {
  60. get { return m_object; }
  61. }
  62. /// <summary>
  63. /// The object our script is supposed to be in
  64. /// </summary>
  65. public SceneObjectGroup Task
  66. {
  67. // XXX Casting not ideal, but previous Scene.Objects propery wasn't actually populated, so
  68. // wouldn't have worked anyway.
  69. get { return (SceneObjectGroup)Scene.Entities[ObjectID]; }
  70. }
  71. /// <summary>
  72. /// Creates a new ScriptInterpretedAPI for a specified object
  73. /// </summary>
  74. /// <param name="world">The scene the object is located in</param>
  75. /// <param name="member">The specific member being 'occupied' by the script</param>
  76. public ScriptInterpretedAPI(Scene world, Key member)
  77. {
  78. m_scene = world;
  79. m_object = member;
  80. }
  81. /// <summary>
  82. /// Returns the absolute number of a integer value.
  83. /// </summary>
  84. /// <param name="val">Input</param>
  85. /// <returns>Absolute number of input</returns>
  86. public int osAbs(int val)
  87. {
  88. return Math.Abs(val);
  89. }
  90. public float osAcos(float val)
  91. {
  92. return (float) Math.Acos(val);
  93. }
  94. [Obsolete("Unimplemented")]
  95. public void osAddToLandPassList(Key avatar, float hours)
  96. {
  97. Vector myPosition = Task.AbsolutePosition;
  98. ILandObject myParcel = Scene.LandChannel.getLandObject(myPosition.X, myPosition.Y);
  99. if (myParcel == null)
  100. {
  101. //Dont do anything!
  102. }
  103. m_log.Warn("[script]: " +
  104. "Unimplemented function called by script: osAddToLandPassList(Key avatar, float hours)");
  105. return;
  106. }
  107. [Obsolete("Unimplemented")]
  108. public void osAdjustSoundVolume(float volume)
  109. {
  110. m_log.Warn("[script]: Unimplemented function called by script: osAdjustSoundVolume(float volume)");
  111. return;
  112. }
  113. [Obsolete("Unimplemented")]
  114. public void osAllowInventoryDrop(int add)
  115. {
  116. return;
  117. }
  118. [Obsolete("Unimplemented")]
  119. public float osAngleBetween(Rotation a, Rotation b)
  120. {
  121. Quaternion axA = new Quaternion(a.W, a.X, a.Y, a.Z);
  122. Quaternion axB = new Quaternion(b.W, b.X, b.Y, b.Z);
  123. return 0;
  124. }
  125. [Obsolete("Unimplemented")]
  126. public void osApplyImpulse(Vector force, int local)
  127. {
  128. return;
  129. }
  130. [Obsolete("Unimplemented")]
  131. public void osApplyRotationalImpulse(Vector force, int local)
  132. {
  133. return;
  134. }
  135. public float osAsin(float val)
  136. {
  137. return (float) Math.Asin(val);
  138. }
  139. public float osAtan2(float x, float y)
  140. {
  141. return (float) Math.Atan2(x, y);
  142. }
  143. [Obsolete("Unimplemented")]
  144. public void osAttachToAvatar(Key avatar, int attachmentPoint)
  145. {
  146. return;
  147. }
  148. [Obsolete("Unimplemented")]
  149. public Key osAvatarOnSitTarget()
  150. {
  151. //TODO: Follow this as Children is chanced to be of type entity to support ScenePresences
  152. /*
  153. foreach (KeyValuePair<Key, EntityBase> Child in Task.Children)
  154. {
  155. if (Child.Value is ScenePresence)
  156. {
  157. return Child.Value.uuid;
  158. }
  159. }
  160. */
  161. return Key.Zero;
  162. }
  163. public Rotation osAxes2Rot(Vector fwd, Vector left, Vector up)
  164. {
  165. Quaternion axQ = new Quaternion();
  166. Vector3 axFwd = new Vector3(fwd.X, fwd.Y, fwd.Z);
  167. Vector3 axLeft = new Vector3(left.X, left.Y, left.Z);
  168. Vector3 axUp = new Vector3(up.X, up.Y, up.Z);
  169. axQ.FromAxes(axFwd, axLeft, axUp);
  170. return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
  171. }
  172. public Rotation osAxisAngle2Rot(Vector axis, float angle)
  173. {
  174. Quaternion axQ = Quaternion.FromAngleAxis(angle, new Vector3(axis.X, axis.Y, axis.Z));
  175. return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
  176. }
  177. public string osBase64ToString(string str)
  178. {
  179. Encoding enc = Encoding.UTF8;
  180. return enc.GetString(Convert.FromBase64String(str));
  181. }
  182. [Obsolete("Unimplemented")]
  183. public void osBreakAllLinks()
  184. {
  185. return;
  186. }
  187. [Obsolete("Unimplemented")]
  188. public void osBreakLink()
  189. {
  190. return;
  191. }
  192. public LSLList osCSV2List(string src)
  193. {
  194. LSLList retVal = new LSLList();
  195. retVal.AddRange(src.Split(','));
  196. return retVal;
  197. }
  198. public int osCeil(float val)
  199. {
  200. return (int) Math.Ceiling(val);
  201. }
  202. [Obsolete("Unimplemented")]
  203. public void osCloseRemoteDataChannel(Key channel)
  204. {
  205. return;
  206. }
  207. [Obsolete("Unimplemented")]
  208. public float osCloud(Vector offset)
  209. {
  210. return 0.0f;
  211. }
  212. [Obsolete("Unimplemented")]
  213. public void osCollisionFilter(string name, Key id, int accept)
  214. {
  215. return;
  216. }
  217. [Obsolete("Unimplemented")]
  218. public void osCollisionSprite(string impact_sprite)
  219. {
  220. return;
  221. }
  222. public float osCos(float theta)
  223. {
  224. return (float) Math.Cos(theta);
  225. }
  226. public void osCreateLink(Key target, int parent)
  227. {
  228. if (Scene.Entities[target] is SceneObjectGroup)
  229. Task.LinkToGroup((SceneObjectGroup) Scene.Entities[target]);
  230. return;
  231. }
  232. [Obsolete("Partially Unimplemented")]
  233. public LSLList osDeleteSubList(LSLList src, int start, int end)
  234. {
  235. if (start < 0 || end < 0)
  236. {
  237. throw new Exception("Unsupported at this time.");
  238. }
  239. src.RemoveRange(start, start - end + 1);
  240. return src;
  241. }
  242. [Obsolete("Partially Unimplemented")]
  243. public string osDeleteSubString(string src, int start, int end)
  244. {
  245. if (start < 0 || end < 0)
  246. {
  247. throw new Exception("Unsupported at this time.");
  248. }
  249. return src.Remove(start, start - end + 1);
  250. }
  251. [Obsolete("Unimplemented")]
  252. public void osDetachFromAvatar(Key avatar)
  253. {
  254. return;
  255. }
  256. }
  257. }