RegionSettings.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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 OpenSimulator 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.Collections.Generic;
  29. using System.IO;
  30. using OpenMetaverse;
  31. using System.Runtime.Serialization;
  32. namespace OpenSim.Framework
  33. {
  34. public struct SpawnPoint
  35. {
  36. public float Yaw;
  37. public float Pitch;
  38. public float Distance;
  39. public void SetLocation(Vector3 pos, Quaternion rot, Vector3 point)
  40. {
  41. // The point is an absolute position, so we need the relative
  42. // location to the spawn point
  43. Vector3 offset = point - pos;
  44. Distance = Vector3.Mag(offset);
  45. // Next we need to rotate this vector into the spawn point's
  46. // coordinate system
  47. rot.W = -rot.W;
  48. offset = offset * rot;
  49. Vector3 dir = Vector3.Normalize(offset);
  50. // Get the bearing (yaw)
  51. Yaw = (float)Math.Atan2(dir.Y, dir.X);
  52. // Get the elevation (pitch)
  53. Pitch = (float)-Math.Atan2(dir.Z, Math.Sqrt(dir.X * dir.X + dir.Y * dir.Y));
  54. }
  55. public Vector3 GetLocation(Vector3 pos, Quaternion rot)
  56. {
  57. Quaternion y = Quaternion.CreateFromEulers(0, 0, Yaw);
  58. Quaternion p = Quaternion.CreateFromEulers(0, Pitch, 0);
  59. Vector3 dir = new Vector3(1, 0, 0) * p * y;
  60. Vector3 offset = dir * (float)Distance;
  61. offset *= rot;
  62. return pos + offset;
  63. }
  64. /// <summary>
  65. /// Returns a string representation of this SpawnPoint.
  66. /// </summary>
  67. /// <returns></returns>
  68. public override string ToString()
  69. {
  70. return string.Format("{0},{1},{2}", Yaw, Pitch, Distance);
  71. }
  72. /// <summary>
  73. /// Generate a SpawnPoint from a string
  74. /// </summary>
  75. /// <param name="str"></param>
  76. public static SpawnPoint Parse(string str)
  77. {
  78. string[] parts = str.Split(',');
  79. if (parts.Length != 3)
  80. throw new ArgumentException("Invalid string: " + str);
  81. SpawnPoint sp = new SpawnPoint();
  82. sp.Yaw = float.Parse(parts[0]);
  83. sp.Pitch = float.Parse(parts[1]);
  84. sp.Distance = float.Parse(parts[2]);
  85. return sp;
  86. }
  87. }
  88. public class RegionSettings
  89. {
  90. public delegate void SaveDelegate(RegionSettings rs);
  91. public event SaveDelegate OnSave;
  92. /// <value>
  93. /// These appear to be terrain textures that are shipped with the client.
  94. /// </value>
  95. public static readonly UUID DEFAULT_TERRAIN_TEXTURE_1 = new UUID("b8d3965a-ad78-bf43-699b-bff8eca6c975");
  96. public static readonly UUID DEFAULT_TERRAIN_TEXTURE_2 = new UUID("abb783e6-3e93-26c0-248a-247666855da3");
  97. public static readonly UUID DEFAULT_TERRAIN_TEXTURE_3 = new UUID("179cdabd-398a-9b6b-1391-4dc333ba321f");
  98. public static readonly UUID DEFAULT_TERRAIN_TEXTURE_4 = new UUID("beb169c7-11ea-fff2-efe5-0f24dc881df2");
  99. public void Save()
  100. {
  101. if (OnSave != null)
  102. OnSave(this);
  103. }
  104. private UUID m_RegionUUID = UUID.Zero;
  105. public UUID RegionUUID
  106. {
  107. get { return m_RegionUUID; }
  108. set { m_RegionUUID = value; }
  109. }
  110. private bool m_BlockTerraform = false;
  111. public bool BlockTerraform
  112. {
  113. get { return m_BlockTerraform; }
  114. set { m_BlockTerraform = value; }
  115. }
  116. private bool m_BlockFly = false;
  117. public bool BlockFly
  118. {
  119. get { return m_BlockFly; }
  120. set { m_BlockFly = value; }
  121. }
  122. private bool m_AllowDamage = false;
  123. public bool AllowDamage
  124. {
  125. get { return m_AllowDamage; }
  126. set { m_AllowDamage = value; }
  127. }
  128. private bool m_RestrictPushing = false;
  129. public bool RestrictPushing
  130. {
  131. get { return m_RestrictPushing; }
  132. set { m_RestrictPushing = value; }
  133. }
  134. private bool m_AllowLandResell = true;
  135. public bool AllowLandResell
  136. {
  137. get { return m_AllowLandResell; }
  138. set { m_AllowLandResell = value; }
  139. }
  140. private bool m_AllowLandJoinDivide = true;
  141. public bool AllowLandJoinDivide
  142. {
  143. get { return m_AllowLandJoinDivide; }
  144. set { m_AllowLandJoinDivide = value; }
  145. }
  146. private bool m_BlockShowInSearch = false;
  147. public bool BlockShowInSearch
  148. {
  149. get { return m_BlockShowInSearch; }
  150. set { m_BlockShowInSearch = value; }
  151. }
  152. private int m_AgentLimit = 40;
  153. public int AgentLimit
  154. {
  155. get { return m_AgentLimit; }
  156. set { m_AgentLimit = value; }
  157. }
  158. private double m_ObjectBonus = 1.0;
  159. public double ObjectBonus
  160. {
  161. get { return m_ObjectBonus; }
  162. set { m_ObjectBonus = value; }
  163. }
  164. private int m_Maturity = 1;
  165. public int Maturity
  166. {
  167. get { return m_Maturity; }
  168. set { m_Maturity = value; }
  169. }
  170. private bool m_DisableScripts = false;
  171. public bool DisableScripts
  172. {
  173. get { return m_DisableScripts; }
  174. set { m_DisableScripts = value; }
  175. }
  176. private bool m_DisableCollisions = false;
  177. public bool DisableCollisions
  178. {
  179. get { return m_DisableCollisions; }
  180. set { m_DisableCollisions = value; }
  181. }
  182. private bool m_DisablePhysics = false;
  183. public bool DisablePhysics
  184. {
  185. get { return m_DisablePhysics; }
  186. set { m_DisablePhysics = value; }
  187. }
  188. private UUID m_TerrainTexture1 = UUID.Zero;
  189. public UUID TerrainTexture1
  190. {
  191. get { return m_TerrainTexture1; }
  192. set
  193. {
  194. if (value == UUID.Zero)
  195. m_TerrainTexture1 = DEFAULT_TERRAIN_TEXTURE_1;
  196. else
  197. m_TerrainTexture1 = value;
  198. }
  199. }
  200. private UUID m_TerrainTexture2 = UUID.Zero;
  201. public UUID TerrainTexture2
  202. {
  203. get { return m_TerrainTexture2; }
  204. set
  205. {
  206. if (value == UUID.Zero)
  207. m_TerrainTexture2 = DEFAULT_TERRAIN_TEXTURE_2;
  208. else
  209. m_TerrainTexture2 = value;
  210. }
  211. }
  212. private UUID m_TerrainTexture3 = UUID.Zero;
  213. public UUID TerrainTexture3
  214. {
  215. get { return m_TerrainTexture3; }
  216. set
  217. {
  218. if (value == UUID.Zero)
  219. m_TerrainTexture3 = DEFAULT_TERRAIN_TEXTURE_3;
  220. else
  221. m_TerrainTexture3 = value;
  222. }
  223. }
  224. private UUID m_TerrainTexture4 = UUID.Zero;
  225. public UUID TerrainTexture4
  226. {
  227. get { return m_TerrainTexture4; }
  228. set
  229. {
  230. if (value == UUID.Zero)
  231. m_TerrainTexture4 = DEFAULT_TERRAIN_TEXTURE_4;
  232. else
  233. m_TerrainTexture4 = value;
  234. }
  235. }
  236. private double m_Elevation1NW = 10;
  237. public double Elevation1NW
  238. {
  239. get { return m_Elevation1NW; }
  240. set { m_Elevation1NW = value; }
  241. }
  242. private double m_Elevation2NW = 60;
  243. public double Elevation2NW
  244. {
  245. get { return m_Elevation2NW; }
  246. set { m_Elevation2NW = value; }
  247. }
  248. private double m_Elevation1NE = 10;
  249. public double Elevation1NE
  250. {
  251. get { return m_Elevation1NE; }
  252. set { m_Elevation1NE = value; }
  253. }
  254. private double m_Elevation2NE = 60;
  255. public double Elevation2NE
  256. {
  257. get { return m_Elevation2NE; }
  258. set { m_Elevation2NE = value; }
  259. }
  260. private double m_Elevation1SE = 10;
  261. public double Elevation1SE
  262. {
  263. get { return m_Elevation1SE; }
  264. set { m_Elevation1SE = value; }
  265. }
  266. private double m_Elevation2SE = 60;
  267. public double Elevation2SE
  268. {
  269. get { return m_Elevation2SE; }
  270. set { m_Elevation2SE = value; }
  271. }
  272. private double m_Elevation1SW = 10;
  273. public double Elevation1SW
  274. {
  275. get { return m_Elevation1SW; }
  276. set { m_Elevation1SW = value; }
  277. }
  278. private double m_Elevation2SW = 60;
  279. public double Elevation2SW
  280. {
  281. get { return m_Elevation2SW; }
  282. set { m_Elevation2SW = value; }
  283. }
  284. private double m_WaterHeight = 20;
  285. public double WaterHeight
  286. {
  287. get { return m_WaterHeight; }
  288. set { m_WaterHeight = value; }
  289. }
  290. private double m_TerrainRaiseLimit = 100;
  291. public double TerrainRaiseLimit
  292. {
  293. get { return m_TerrainRaiseLimit; }
  294. set { m_TerrainRaiseLimit = value; }
  295. }
  296. private double m_TerrainLowerLimit = -100;
  297. public double TerrainLowerLimit
  298. {
  299. get { return m_TerrainLowerLimit; }
  300. set { m_TerrainLowerLimit = value; }
  301. }
  302. private bool m_UseEstateSun = true;
  303. public bool UseEstateSun
  304. {
  305. get { return m_UseEstateSun; }
  306. set { m_UseEstateSun = value; }
  307. }
  308. private bool m_Sandbox = false;
  309. public bool Sandbox
  310. {
  311. get { return m_Sandbox; }
  312. set { m_Sandbox = value; }
  313. }
  314. private Vector3 m_SunVector;
  315. public Vector3 SunVector
  316. {
  317. get { return m_SunVector; }
  318. set { m_SunVector = value; }
  319. }
  320. private UUID m_ParcelImageID;
  321. public UUID ParcelImageID
  322. {
  323. get { return m_ParcelImageID; }
  324. set { m_ParcelImageID = value; }
  325. }
  326. private UUID m_TerrainImageID;
  327. public UUID TerrainImageID
  328. {
  329. get { return m_TerrainImageID; }
  330. set { m_TerrainImageID = value; }
  331. }
  332. private bool m_FixedSun = false;
  333. public bool FixedSun
  334. {
  335. get { return m_FixedSun; }
  336. set { m_FixedSun = value; }
  337. }
  338. private double m_SunPosition = 0.0;
  339. public double SunPosition
  340. {
  341. get { return m_SunPosition; }
  342. set { m_SunPosition = value; }
  343. }
  344. private UUID m_Covenant = UUID.Zero;
  345. public UUID Covenant
  346. {
  347. get { return m_Covenant; }
  348. set { m_Covenant = value; }
  349. }
  350. private int m_CovenantChanged = 0;
  351. public int CovenantChangedDateTime
  352. {
  353. get { return m_CovenantChanged; }
  354. set { m_CovenantChanged = value; }
  355. }
  356. private int m_LoadedCreationDateTime;
  357. public int LoadedCreationDateTime
  358. {
  359. get { return m_LoadedCreationDateTime; }
  360. set { m_LoadedCreationDateTime = value; }
  361. }
  362. public String LoadedCreationDate
  363. {
  364. get
  365. {
  366. TimeSpan ts = new TimeSpan(0, 0, LoadedCreationDateTime);
  367. DateTime stamp = new DateTime(1970, 1, 1) + ts;
  368. return stamp.ToLongDateString();
  369. }
  370. }
  371. public String LoadedCreationTime
  372. {
  373. get
  374. {
  375. TimeSpan ts = new TimeSpan(0, 0, LoadedCreationDateTime);
  376. DateTime stamp = new DateTime(1970, 1, 1) + ts;
  377. return stamp.ToLongTimeString();
  378. }
  379. }
  380. private String m_LoadedCreationID;
  381. public String LoadedCreationID
  382. {
  383. get { return m_LoadedCreationID; }
  384. set { m_LoadedCreationID = value; }
  385. }
  386. // Connected Telehub object
  387. private UUID m_TelehubObject = UUID.Zero;
  388. public UUID TelehubObject
  389. {
  390. get
  391. {
  392. return m_TelehubObject;
  393. }
  394. set
  395. {
  396. m_TelehubObject = value;
  397. }
  398. }
  399. // Our Connected Telehub's SpawnPoints
  400. public List<SpawnPoint> l_SpawnPoints = new List<SpawnPoint>();
  401. // Add a SpawnPoint
  402. // ** These are not region coordinates **
  403. // They are relative to the Telehub coordinates
  404. //
  405. public void AddSpawnPoint(SpawnPoint point)
  406. {
  407. l_SpawnPoints.Add(point);
  408. }
  409. // Remove a SpawnPoint
  410. public void RemoveSpawnPoint(int point_index)
  411. {
  412. l_SpawnPoints.RemoveAt(point_index);
  413. }
  414. // Return the List of SpawnPoints
  415. public List<SpawnPoint> SpawnPoints()
  416. {
  417. return l_SpawnPoints;
  418. }
  419. // Clear the SpawnPoints List of all entries
  420. public void ClearSpawnPoints()
  421. {
  422. l_SpawnPoints.Clear();
  423. }
  424. }
  425. }