RegionSettings.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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. public UUID CacheID { get; set; } = UUID.Random();
  111. private bool m_BlockTerraform = false;
  112. public bool BlockTerraform
  113. {
  114. get { return m_BlockTerraform; }
  115. set { m_BlockTerraform = value; }
  116. }
  117. private bool m_BlockFly = false;
  118. public bool BlockFly
  119. {
  120. get { return m_BlockFly; }
  121. set { m_BlockFly = value; }
  122. }
  123. private bool m_AllowDamage = false;
  124. public bool AllowDamage
  125. {
  126. get { return m_AllowDamage; }
  127. set { m_AllowDamage = value; }
  128. }
  129. private bool m_RestrictPushing = false;
  130. public bool RestrictPushing
  131. {
  132. get { return m_RestrictPushing; }
  133. set { m_RestrictPushing = value; }
  134. }
  135. private bool m_AllowLandResell = true;
  136. public bool AllowLandResell
  137. {
  138. get { return m_AllowLandResell; }
  139. set { m_AllowLandResell = value; }
  140. }
  141. private bool m_AllowLandJoinDivide = true;
  142. public bool AllowLandJoinDivide
  143. {
  144. get { return m_AllowLandJoinDivide; }
  145. set { m_AllowLandJoinDivide = value; }
  146. }
  147. private bool m_BlockShowInSearch = false;
  148. public bool BlockShowInSearch
  149. {
  150. get { return m_BlockShowInSearch; }
  151. set { m_BlockShowInSearch = value; }
  152. }
  153. private int m_AgentLimit = 40;
  154. public int AgentLimit
  155. {
  156. get { return m_AgentLimit; }
  157. set { m_AgentLimit = value; }
  158. }
  159. private double m_ObjectBonus = 1.0;
  160. public double ObjectBonus
  161. {
  162. get { return m_ObjectBonus; }
  163. set { m_ObjectBonus = value; }
  164. }
  165. private int m_Maturity = 0;
  166. public int Maturity
  167. {
  168. get { return m_Maturity; }
  169. set { m_Maturity = value; }
  170. }
  171. private bool m_DisableScripts = false;
  172. public bool DisableScripts
  173. {
  174. get { return m_DisableScripts; }
  175. set { m_DisableScripts = value; }
  176. }
  177. private bool m_DisableCollisions = false;
  178. public bool DisableCollisions
  179. {
  180. get { return m_DisableCollisions; }
  181. set { m_DisableCollisions = value; }
  182. }
  183. private bool m_DisablePhysics = false;
  184. public bool DisablePhysics
  185. {
  186. get { return m_DisablePhysics; }
  187. set { m_DisablePhysics = value; }
  188. }
  189. private UUID m_TerrainTexture1 = UUID.Zero;
  190. public UUID TerrainTexture1
  191. {
  192. get { return m_TerrainTexture1; }
  193. set
  194. {
  195. if (value.IsZero())
  196. m_TerrainTexture1 = DEFAULT_TERRAIN_TEXTURE_1;
  197. else
  198. m_TerrainTexture1 = value;
  199. }
  200. }
  201. private UUID m_TerrainTexture2 = UUID.Zero;
  202. public UUID TerrainTexture2
  203. {
  204. get { return m_TerrainTexture2; }
  205. set
  206. {
  207. if (value.IsZero())
  208. m_TerrainTexture2 = DEFAULT_TERRAIN_TEXTURE_2;
  209. else
  210. m_TerrainTexture2 = value;
  211. }
  212. }
  213. private UUID m_TerrainTexture3 = UUID.Zero;
  214. public UUID TerrainTexture3
  215. {
  216. get { return m_TerrainTexture3; }
  217. set
  218. {
  219. if (value.IsZero())
  220. m_TerrainTexture3 = DEFAULT_TERRAIN_TEXTURE_3;
  221. else
  222. m_TerrainTexture3 = value;
  223. }
  224. }
  225. private UUID m_TerrainTexture4 = UUID.Zero;
  226. public UUID TerrainTexture4
  227. {
  228. get { return m_TerrainTexture4; }
  229. set
  230. {
  231. if (value.IsZero())
  232. m_TerrainTexture4 = DEFAULT_TERRAIN_TEXTURE_4;
  233. else
  234. m_TerrainTexture4 = value;
  235. }
  236. }
  237. private double m_Elevation1NW = 10;
  238. public double Elevation1NW
  239. {
  240. get { return m_Elevation1NW; }
  241. set { m_Elevation1NW = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap); ; }
  242. }
  243. private double m_Elevation2NW = 60;
  244. public double Elevation2NW
  245. {
  246. get { return m_Elevation2NW; }
  247. set { m_Elevation2NW = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap); ; }
  248. }
  249. private double m_Elevation1NE = 10;
  250. public double Elevation1NE
  251. {
  252. get { return m_Elevation1NE; }
  253. set { m_Elevation1NE = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap); ; }
  254. }
  255. private double m_Elevation2NE = 60;
  256. public double Elevation2NE
  257. {
  258. get { return m_Elevation2NE; }
  259. set { m_Elevation2NE = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap); ; }
  260. }
  261. private double m_Elevation1SE = 10;
  262. public double Elevation1SE
  263. {
  264. get { return m_Elevation1SE; }
  265. set { m_Elevation1SE = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap); ; }
  266. }
  267. private double m_Elevation2SE = 60;
  268. public double Elevation2SE
  269. {
  270. get { return m_Elevation2SE; }
  271. set { m_Elevation2SE = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap); ; }
  272. }
  273. private double m_Elevation1SW = 10;
  274. public double Elevation1SW
  275. {
  276. get { return m_Elevation1SW; }
  277. set { m_Elevation1SW = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap); ; }
  278. }
  279. private double m_Elevation2SW = 60;
  280. public double Elevation2SW
  281. {
  282. get { return m_Elevation2SW; }
  283. set { m_Elevation2SW = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap); ; }
  284. }
  285. private double m_WaterHeight = 20;
  286. public double WaterHeight
  287. {
  288. get { return m_WaterHeight; }
  289. set { m_WaterHeight = Utils.Clamp(value, Constants.MinWaterHeight, Constants.MaxWaterHeight); }
  290. }
  291. private double m_TerrainRaiseLimit = 100;
  292. public double TerrainRaiseLimit
  293. {
  294. get { return m_TerrainRaiseLimit; }
  295. set { m_TerrainRaiseLimit = Utils.Clamp(value, 0, 200f); }
  296. }
  297. private double m_TerrainLowerLimit = -100;
  298. public double TerrainLowerLimit
  299. {
  300. get { return m_TerrainLowerLimit; }
  301. set { m_TerrainLowerLimit = Utils.Clamp(value, -200f, 0);}
  302. }
  303. private bool m_UseEstateSun = true;
  304. public bool UseEstateSun
  305. {
  306. get { return m_UseEstateSun; }
  307. set { m_UseEstateSun = value; }
  308. }
  309. private bool m_Sandbox = false;
  310. public bool Sandbox
  311. {
  312. get { return m_Sandbox; }
  313. set { m_Sandbox = value; }
  314. }
  315. public Vector3 SunVector
  316. {
  317. get { return Vector3.Zero; }
  318. set { }
  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. public bool FixedSun
  333. {
  334. get { return false; }
  335. set { }
  336. }
  337. public double SunPosition
  338. {
  339. get { return 0; }
  340. set { }
  341. }
  342. private UUID m_Covenant = UUID.Zero;
  343. public UUID Covenant
  344. {
  345. get { return m_Covenant; }
  346. set { m_Covenant = value; }
  347. }
  348. private int m_CovenantChanged = 0;
  349. public int CovenantChangedDateTime
  350. {
  351. get { return m_CovenantChanged; }
  352. set { m_CovenantChanged = value; }
  353. }
  354. private int m_LoadedCreationDateTime;
  355. public int LoadedCreationDateTime
  356. {
  357. get { return m_LoadedCreationDateTime; }
  358. set { m_LoadedCreationDateTime = value; }
  359. }
  360. public String LoadedCreationDate
  361. {
  362. get
  363. {
  364. TimeSpan ts = new TimeSpan(0, 0, LoadedCreationDateTime);
  365. DateTime stamp = new DateTime(1970, 1, 1) + ts;
  366. return stamp.ToLongDateString();
  367. }
  368. }
  369. public String LoadedCreationTime
  370. {
  371. get
  372. {
  373. TimeSpan ts = new TimeSpan(0, 0, LoadedCreationDateTime);
  374. DateTime stamp = new DateTime(1970, 1, 1) + ts;
  375. return stamp.ToLongTimeString();
  376. }
  377. }
  378. private String m_LoadedCreationID;
  379. public String LoadedCreationID
  380. {
  381. get { return m_LoadedCreationID; }
  382. set { m_LoadedCreationID = value; }
  383. }
  384. private bool m_GodBlockSearch = false;
  385. public bool GodBlockSearch
  386. {
  387. get { return m_GodBlockSearch; }
  388. set { m_GodBlockSearch = value; }
  389. }
  390. private bool m_Casino = false;
  391. public bool Casino
  392. {
  393. get { return m_Casino; }
  394. set { m_Casino = value; }
  395. }
  396. // Telehub support
  397. private bool m_TelehubEnabled = false;
  398. public bool HasTelehub
  399. {
  400. get { return m_TelehubEnabled; }
  401. set { m_TelehubEnabled = value; }
  402. }
  403. /// <summary>
  404. /// Connected Telehub object
  405. /// </summary>
  406. public UUID TelehubObject { get; set; }
  407. /// <summary>
  408. /// Our connected Telehub's SpawnPoints
  409. /// </summary>
  410. public List<SpawnPoint> l_SpawnPoints = new List<SpawnPoint>();
  411. // Add a SpawnPoint
  412. // ** These are not region coordinates **
  413. // They are relative to the Telehub coordinates
  414. //
  415. public void AddSpawnPoint(SpawnPoint point)
  416. {
  417. l_SpawnPoints.Add(point);
  418. }
  419. // Remove a SpawnPoint
  420. public void RemoveSpawnPoint(int point_index)
  421. {
  422. l_SpawnPoints.RemoveAt(point_index);
  423. }
  424. // Return the List of SpawnPoints
  425. public List<SpawnPoint> SpawnPoints()
  426. {
  427. return l_SpawnPoints;
  428. }
  429. // Clear the SpawnPoints List of all entries
  430. public void ClearSpawnPoints()
  431. {
  432. l_SpawnPoints.Clear();
  433. }
  434. }
  435. }