RegionSettings.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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 *= rot;
  49. Vector3 dir = Vector3.Normalize(offset);
  50. // Get the bearing (yaw)
  51. Yaw = MathF.Atan2(dir.Y, dir.X);
  52. // Get the elevation (pitch)
  53. Pitch = -MathF.Atan2(dir.Z, MathF.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()
  82. {
  83. Yaw = float.Parse(parts[0]),
  84. Pitch = float.Parse(parts[1]),
  85. Distance = float.Parse(parts[2])
  86. };
  87. return sp;
  88. }
  89. }
  90. public class RegionSettings
  91. {
  92. public delegate void SaveDelegate(RegionSettings rs);
  93. public event SaveDelegate OnSave;
  94. /// <value>
  95. /// These appear to be terrain textures that are shipped with the client.
  96. /// </value>
  97. public static readonly UUID DEFAULT_TERRAIN_TEXTURE_1 = new("b8d3965a-ad78-bf43-699b-bff8eca6c975");
  98. public static readonly UUID DEFAULT_TERRAIN_TEXTURE_2 = new("abb783e6-3e93-26c0-248a-247666855da3");
  99. public static readonly UUID DEFAULT_TERRAIN_TEXTURE_3 = new("179cdabd-398a-9b6b-1391-4dc333ba321f");
  100. public static readonly UUID DEFAULT_TERRAIN_TEXTURE_4 = new("beb169c7-11ea-fff2-efe5-0f24dc881df2");
  101. public static readonly UUID DEFAULT_TERRAIN_PBR_1 = new("b8d3965a-ad78-bf43-699b-bff8eca6c975");
  102. public static readonly UUID DEFAULT_TERRAIN_PBR_2 = new("abb783e6-3e93-26c0-248a-247666855da3");
  103. public static readonly UUID DEFAULT_TERRAIN_PBR_3 = new("179cdabd-398a-9b6b-1391-4dc333ba321f");
  104. public static readonly UUID DEFAULT_TERRAIN_PBR_4 = new("beb169c7-11ea-fff2-efe5-0f24dc881df2");
  105. public void Save()
  106. {
  107. OnSave?.Invoke(this);
  108. }
  109. private UUID m_RegionUUID = UUID.Zero;
  110. public UUID RegionUUID
  111. {
  112. get { return m_RegionUUID; }
  113. set { m_RegionUUID = value; }
  114. }
  115. public UUID CacheID { get; set; } = UUID.Random();
  116. private bool m_BlockTerraform = false;
  117. public bool BlockTerraform
  118. {
  119. get { return m_BlockTerraform; }
  120. set { m_BlockTerraform = value; }
  121. }
  122. private bool m_BlockFly = false;
  123. public bool BlockFly
  124. {
  125. get { return m_BlockFly; }
  126. set { m_BlockFly = value; }
  127. }
  128. private bool m_AllowDamage = false;
  129. public bool AllowDamage
  130. {
  131. get { return m_AllowDamage; }
  132. set { m_AllowDamage = value; }
  133. }
  134. private bool m_RestrictPushing = false;
  135. public bool RestrictPushing
  136. {
  137. get { return m_RestrictPushing; }
  138. set { m_RestrictPushing = value; }
  139. }
  140. private bool m_AllowLandResell = true;
  141. public bool AllowLandResell
  142. {
  143. get { return m_AllowLandResell; }
  144. set { m_AllowLandResell = value; }
  145. }
  146. private bool m_AllowLandJoinDivide = true;
  147. public bool AllowLandJoinDivide
  148. {
  149. get { return m_AllowLandJoinDivide; }
  150. set { m_AllowLandJoinDivide = value; }
  151. }
  152. private bool m_BlockShowInSearch = false;
  153. public bool BlockShowInSearch
  154. {
  155. get { return m_BlockShowInSearch; }
  156. set { m_BlockShowInSearch = value; }
  157. }
  158. private int m_AgentLimit = 40;
  159. public int AgentLimit
  160. {
  161. get { return m_AgentLimit; }
  162. set { m_AgentLimit = value; }
  163. }
  164. private double m_ObjectBonus = 1.0;
  165. public double ObjectBonus
  166. {
  167. get { return m_ObjectBonus; }
  168. set { m_ObjectBonus = value; }
  169. }
  170. private int m_Maturity = 0;
  171. public int Maturity
  172. {
  173. get { return m_Maturity; }
  174. set { m_Maturity = value; }
  175. }
  176. private bool m_DisableScripts = false;
  177. public bool DisableScripts
  178. {
  179. get { return m_DisableScripts; }
  180. set { m_DisableScripts = value; }
  181. }
  182. private bool m_DisableCollisions = false;
  183. public bool DisableCollisions
  184. {
  185. get { return m_DisableCollisions; }
  186. set { m_DisableCollisions = value; }
  187. }
  188. private bool m_DisablePhysics = false;
  189. public bool DisablePhysics
  190. {
  191. get { return m_DisablePhysics; }
  192. set { m_DisablePhysics = value; }
  193. }
  194. private UUID m_TerrainTexture1 = UUID.Zero;
  195. public UUID TerrainTexture1
  196. {
  197. get { return m_TerrainTexture1; }
  198. set { m_TerrainTexture1 = value.IsZero() ? DEFAULT_TERRAIN_TEXTURE_1 : value; }
  199. }
  200. private UUID m_TerrainTexture2 = UUID.Zero;
  201. public UUID TerrainTexture2
  202. {
  203. get { return m_TerrainTexture2; }
  204. set { m_TerrainTexture2 = value.IsZero() ? DEFAULT_TERRAIN_TEXTURE_2 : value; }
  205. }
  206. private UUID m_TerrainTexture3 = UUID.Zero;
  207. public UUID TerrainTexture3
  208. {
  209. get { return m_TerrainTexture3; }
  210. set { m_TerrainTexture3 = value.IsZero() ? DEFAULT_TERRAIN_TEXTURE_3 : value; }
  211. }
  212. private UUID m_TerrainTexture4 = UUID.Zero;
  213. public UUID TerrainTexture4
  214. {
  215. get { return m_TerrainTexture4; }
  216. set { m_TerrainTexture4 = value.IsZero() ? DEFAULT_TERRAIN_TEXTURE_4 : value; }
  217. }
  218. private UUID m_TerrainPBR1 = UUID.Zero;
  219. public UUID TerrainPBR1
  220. {
  221. get { return m_TerrainPBR1; }
  222. set { m_TerrainPBR1 = value;}
  223. }
  224. private UUID m_TerrainPBR2 = UUID.Zero;
  225. public UUID TerrainPBR2
  226. {
  227. get { return m_TerrainPBR2; }
  228. set { m_TerrainPBR2 = value; }
  229. }
  230. private UUID m_TerrainPBR3 = UUID.Zero;
  231. public UUID TerrainPBR3
  232. {
  233. get { return m_TerrainPBR3; }
  234. set { m_TerrainPBR3 = value; }
  235. }
  236. private UUID m_TerrainPBR4 = UUID.Zero;
  237. public UUID TerrainPBR4
  238. {
  239. get { return m_TerrainPBR4; }
  240. set { m_TerrainPBR4 = value; }
  241. }
  242. private double m_Elevation1NW = 10;
  243. public double Elevation1NW
  244. {
  245. get { return m_Elevation1NW; }
  246. set { m_Elevation1NW = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap); ; }
  247. }
  248. private double m_Elevation2NW = 60;
  249. public double Elevation2NW
  250. {
  251. get { return m_Elevation2NW; }
  252. set { m_Elevation2NW = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap);}
  253. }
  254. private double m_Elevation1NE = 10;
  255. public double Elevation1NE
  256. {
  257. get { return m_Elevation1NE; }
  258. set { m_Elevation1NE = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap);}
  259. }
  260. private double m_Elevation2NE = 60;
  261. public double Elevation2NE
  262. {
  263. get { return m_Elevation2NE; }
  264. set { m_Elevation2NE = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap);}
  265. }
  266. private double m_Elevation1SE = 10;
  267. public double Elevation1SE
  268. {
  269. get { return m_Elevation1SE; }
  270. set { m_Elevation1SE = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap);}
  271. }
  272. private double m_Elevation2SE = 60;
  273. public double Elevation2SE
  274. {
  275. get { return m_Elevation2SE; }
  276. set { m_Elevation2SE = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap);}
  277. }
  278. private double m_Elevation1SW = 10;
  279. public double Elevation1SW
  280. {
  281. get { return m_Elevation1SW; }
  282. set { m_Elevation1SW = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap);}
  283. }
  284. private double m_Elevation2SW = 60;
  285. public double Elevation2SW
  286. {
  287. get { return m_Elevation2SW; }
  288. set { m_Elevation2SW = Utils.Clamp(value, Constants.MinTerrainHeightmap, Constants.MaxTerrainHeightmap);}
  289. }
  290. private double m_WaterHeight = 20;
  291. public double WaterHeight
  292. {
  293. get { return m_WaterHeight; }
  294. set { m_WaterHeight = Utils.Clamp(value, Constants.MinWaterHeight, Constants.MaxWaterHeight);}
  295. }
  296. private double m_TerrainRaiseLimit = 100;
  297. public double TerrainRaiseLimit
  298. {
  299. get { return m_TerrainRaiseLimit; }
  300. set { m_TerrainRaiseLimit = Utils.Clamp(value, 0, 200f); }
  301. }
  302. private double m_TerrainLowerLimit = -100;
  303. public double TerrainLowerLimit
  304. {
  305. get { return m_TerrainLowerLimit; }
  306. set { m_TerrainLowerLimit = Utils.Clamp(value, -200f, 0);}
  307. }
  308. private bool m_UseEstateSun = true;
  309. public bool UseEstateSun
  310. {
  311. get { return m_UseEstateSun; }
  312. set { m_UseEstateSun = value; }
  313. }
  314. private bool m_Sandbox = false;
  315. public bool Sandbox
  316. {
  317. get { return m_Sandbox; }
  318. set { m_Sandbox = value; }
  319. }
  320. public Vector3 SunVector
  321. {
  322. get { return Vector3.Zero; }
  323. set { }
  324. }
  325. private UUID m_ParcelImageID;
  326. public UUID ParcelImageID
  327. {
  328. get { return m_ParcelImageID; }
  329. set { m_ParcelImageID = value; }
  330. }
  331. private UUID m_TerrainImageID;
  332. public UUID TerrainImageID
  333. {
  334. get { return m_TerrainImageID; }
  335. set { m_TerrainImageID = value; }
  336. }
  337. public bool FixedSun
  338. {
  339. get { return false; }
  340. set { }
  341. }
  342. public double SunPosition
  343. {
  344. get { return 0; }
  345. set { }
  346. }
  347. private UUID m_Covenant = UUID.Zero;
  348. public UUID Covenant
  349. {
  350. get { return m_Covenant; }
  351. set { m_Covenant = value; }
  352. }
  353. private int m_CovenantChanged = 0;
  354. public int CovenantChangedDateTime
  355. {
  356. get { return m_CovenantChanged; }
  357. set { m_CovenantChanged = value; }
  358. }
  359. private int m_LoadedCreationDateTime;
  360. public int LoadedCreationDateTime
  361. {
  362. get { return m_LoadedCreationDateTime; }
  363. set { m_LoadedCreationDateTime = value; }
  364. }
  365. public String LoadedCreationDate
  366. {
  367. get
  368. {
  369. TimeSpan ts = new(0, 0, LoadedCreationDateTime);
  370. DateTime stamp = new DateTime(1970, 1, 1) + ts;
  371. return stamp.ToLongDateString();
  372. }
  373. }
  374. public String LoadedCreationTime
  375. {
  376. get
  377. {
  378. TimeSpan ts = new(0, 0, LoadedCreationDateTime);
  379. DateTime stamp = new DateTime(1970, 1, 1) + ts;
  380. return stamp.ToLongTimeString();
  381. }
  382. }
  383. private String m_LoadedCreationID;
  384. public String LoadedCreationID
  385. {
  386. get { return m_LoadedCreationID; }
  387. set { m_LoadedCreationID = value; }
  388. }
  389. private bool m_GodBlockSearch = false;
  390. public bool GodBlockSearch
  391. {
  392. get { return m_GodBlockSearch; }
  393. set { m_GodBlockSearch = value; }
  394. }
  395. private bool m_Casino = false;
  396. public bool Casino
  397. {
  398. get { return m_Casino; }
  399. set { m_Casino = value; }
  400. }
  401. // Telehub support
  402. private bool m_TelehubEnabled = false;
  403. public bool HasTelehub
  404. {
  405. get { return m_TelehubEnabled; }
  406. set { m_TelehubEnabled = value; }
  407. }
  408. /// <summary>
  409. /// Connected Telehub object
  410. /// </summary>
  411. public UUID TelehubObject { get; set; }
  412. /// <summary>
  413. /// Our connected Telehub's SpawnPoints
  414. /// </summary>
  415. public List<SpawnPoint> l_SpawnPoints = new();
  416. // Add a SpawnPoint
  417. // ** These are not region coordinates **
  418. // They are relative to the Telehub coordinates
  419. //
  420. public void AddSpawnPoint(SpawnPoint point)
  421. {
  422. l_SpawnPoints.Add(point);
  423. }
  424. // Remove a SpawnPoint
  425. public void RemoveSpawnPoint(int point_index)
  426. {
  427. l_SpawnPoints.RemoveAt(point_index);
  428. }
  429. // Return the List of SpawnPoints
  430. public List<SpawnPoint> SpawnPoints()
  431. {
  432. return l_SpawnPoints;
  433. }
  434. // Clear the SpawnPoints List of all entries
  435. public void ClearSpawnPoints()
  436. {
  437. l_SpawnPoints.Clear();
  438. }
  439. }
  440. }