aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Land/LandObject.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandObject.cs324
1 files changed, 198 insertions, 126 deletions
diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
index 5969d45..a0c1b9d 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
@@ -45,14 +45,12 @@ namespace OpenSim.Region.CoreModules.World.Land
45 #region Member Variables 45 #region Member Variables
46 46
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 #pragma warning disable 0429 48 private static readonly string LogHeader = "[LAND OBJECT]";
49 private const int landArrayMax = ((int)((int)Constants.RegionSize / 4) >= 64) ? (int)((int)Constants.RegionSize / 4) : 64;
50 #pragma warning restore 0429
51 private bool[,] m_landBitmap = new bool[landArrayMax,landArrayMax];
52 49
53 private int m_lastSeqId = 0; 50 private readonly int landUnit = 4;
54 51
55 protected LandData m_landData = new LandData(); 52 private int m_lastSeqId = 0;
53
56 protected Scene m_scene; 54 protected Scene m_scene;
57 protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>(); 55 protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>();
58 protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>(); 56 protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>();
@@ -60,76 +58,83 @@ namespace OpenSim.Region.CoreModules.World.Land
60 protected ExpiringCache<UUID, bool> m_groupMemberCache = new ExpiringCache<UUID, bool>(); 58 protected ExpiringCache<UUID, bool> m_groupMemberCache = new ExpiringCache<UUID, bool>();
61 protected TimeSpan m_groupMemberCacheTimeout = TimeSpan.FromSeconds(30); // cache invalidation after 30 seconds 59 protected TimeSpan m_groupMemberCacheTimeout = TimeSpan.FromSeconds(30); // cache invalidation after 30 seconds
62 60
63 public bool[,] LandBitmap 61 public bool[,] LandBitmap { get; set; }
64 {
65 get { return m_landBitmap; }
66 set { m_landBitmap = value; }
67 }
68 62
69 #endregion 63 #endregion
70 64
71 public int GetPrimsFree() 65 public int GetPrimsFree()
72 { 66 {
73 m_scene.EventManager.TriggerParcelPrimCountUpdate(); 67 m_scene.EventManager.TriggerParcelPrimCountUpdate();
74 int free = GetSimulatorMaxPrimCount() - m_landData.SimwidePrims; 68 int free = GetSimulatorMaxPrimCount() - LandData.SimwidePrims;
75 return free; 69 return free;
76 } 70 }
77 71
78 public LandData LandData 72 public LandData LandData { get; set; }
79 {
80 get { return m_landData; }
81 73
82 set { m_landData = value; }
83 }
84
85 public IPrimCounts PrimCounts { get; set; } 74 public IPrimCounts PrimCounts { get; set; }
86 75
87 public UUID RegionUUID 76 public UUID RegionUUID
88 { 77 {
89 get { return m_scene.RegionInfo.RegionID; } 78 get { return m_scene.RegionInfo.RegionID; }
90 } 79 }
91 80
92 public Vector3 StartPoint 81 public Vector3 StartPoint
93 { 82 {
94 get 83 get
95 { 84 {
96 for (int y = 0; y < landArrayMax; y++) 85 for (int y = 0; y < LandBitmap.GetLength(1); y++)
97 { 86 {
98 for (int x = 0; x < landArrayMax; x++) 87 for (int x = 0; x < LandBitmap.GetLength(0); x++)
99 { 88 {
100 if (LandBitmap[x, y]) 89 if (LandBitmap[x, y])
101 return new Vector3(x * 4, y * 4, 0); 90 return new Vector3(x * landUnit, y * landUnit, 0);
102 } 91 }
103 } 92 }
104 93
94 m_log.ErrorFormat("{0} StartPoint. No start point found. bitmapSize=<{1},{2}>",
95 LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
105 return new Vector3(-1, -1, -1); 96 return new Vector3(-1, -1, -1);
106 } 97 }
107 } 98 }
108 99
109 public Vector3 EndPoint 100 public Vector3 EndPoint
110 { 101 {
111 get 102 get
112 { 103 {
113 for (int y = landArrayMax - 1; y >= 0; y--) 104 for (int y = LandBitmap.GetLength(1) - 1; y >= 0; y--)
114 { 105 {
115 for (int x = landArrayMax - 1; x >= 0; x--) 106 for (int x = LandBitmap.GetLength(0) - 1; x >= 0; x--)
116 { 107 {
117 if (LandBitmap[x, y]) 108 if (LandBitmap[x, y])
118 { 109 {
119 return new Vector3(x * 4, y * 4, 0); 110 return new Vector3(x * landUnit + landUnit, y * landUnit + landUnit, 0);
120 } 111 }
121 } 112 }
122 } 113 }
123 114
115 m_log.ErrorFormat("{0} EndPoint. No end point found. bitmapSize=<{1},{2}>",
116 LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
124 return new Vector3(-1, -1, -1); 117 return new Vector3(-1, -1, -1);
125 } 118 }
126 } 119 }
127 120
128 #region Constructors 121 #region Constructors
129 122
123 public LandObject(LandData landData, Scene scene)
124 {
125 LandData = landData.Copy();
126 m_scene = scene;
127 }
128
130 public LandObject(UUID owner_id, bool is_group_owned, Scene scene) 129 public LandObject(UUID owner_id, bool is_group_owned, Scene scene)
131 { 130 {
132 m_scene = scene; 131 m_scene = scene;
132 if (m_scene == null)
133 LandBitmap = new bool[Constants.RegionSize / landUnit, Constants.RegionSize / landUnit];
134 else
135 LandBitmap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
136
137 LandData = new LandData();
133 LandData.OwnerID = owner_id; 138 LandData.OwnerID = owner_id;
134 if (is_group_owned) 139 if (is_group_owned)
135 LandData.GroupID = owner_id; 140 LandData.GroupID = owner_id;
@@ -152,9 +157,9 @@ namespace OpenSim.Region.CoreModules.World.Land
152 /// <returns>Returns true if the piece of land contains the specified point</returns> 157 /// <returns>Returns true if the piece of land contains the specified point</returns>
153 public bool ContainsPoint(int x, int y) 158 public bool ContainsPoint(int x, int y)
154 { 159 {
155 if (x >= 0 && y >= 0 && x < Constants.RegionSize && y < Constants.RegionSize) 160 if (x >= 0 && y >= 0 && x < m_scene.RegionInfo.RegionSizeX && y < m_scene.RegionInfo.RegionSizeY)
156 { 161 {
157 return (LandBitmap[x / 4, y / 4] == true); 162 return LandBitmap[x / landUnit, y / landUnit];
158 } 163 }
159 else 164 else
160 { 165 {
@@ -164,12 +169,8 @@ namespace OpenSim.Region.CoreModules.World.Land
164 169
165 public ILandObject Copy() 170 public ILandObject Copy()
166 { 171 {
167 ILandObject newLand = new LandObject(LandData.OwnerID, LandData.IsGroupOwned, m_scene); 172 ILandObject newLand = new LandObject(LandData, m_scene);
168
169 //Place all new variables here!
170 newLand.LandBitmap = (bool[,]) (LandBitmap.Clone()); 173 newLand.LandBitmap = (bool[,]) (LandBitmap.Clone());
171 newLand.LandData = LandData.Copy();
172
173 return newLand; 174 return newLand;
174 } 175 }
175 176
@@ -194,7 +195,7 @@ namespace OpenSim.Region.CoreModules.World.Land
194 else 195 else
195 { 196 {
196 // Normal Calculations 197 // Normal Calculations
197 int parcelMax = (int)(((float)LandData.Area / 65536.0f) 198 int parcelMax = (int)(((float)LandData.Area / (m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY))
198 * (float)m_scene.RegionInfo.ObjectCapacity 199 * (float)m_scene.RegionInfo.ObjectCapacity
199 * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus); 200 * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus);
200 // TODO: The calculation of ObjectBonus should be refactored. It does still not work in the same manner as SL! 201 // TODO: The calculation of ObjectBonus should be refactored. It does still not work in the same manner as SL!
@@ -211,7 +212,7 @@ namespace OpenSim.Region.CoreModules.World.Land
211 else 212 else
212 { 213 {
213 //Normal Calculations 214 //Normal Calculations
214 int simMax = (int)(((float)LandData.SimwideArea / 65536.0f) 215 int simMax = (int)(((float)LandData.SimwideArea / (m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY))
215 * (float)m_scene.RegionInfo.ObjectCapacity); 216 * (float)m_scene.RegionInfo.ObjectCapacity);
216 return simMax; 217 return simMax;
217 } 218 }
@@ -224,17 +225,15 @@ namespace OpenSim.Region.CoreModules.World.Land
224 public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client) 225 public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client)
225 { 226 {
226 IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>(); 227 IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
227 uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome)); 228 // uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome));
229 uint regionFlags = (uint)(RegionFlags.PublicAllowed
230 | RegionFlags.AllowDirectTeleport
231 | RegionFlags.AllowParcelChanges
232 | RegionFlags.AllowVoice );
233
228 if (estateModule != null) 234 if (estateModule != null)
229 regionFlags = estateModule.GetRegionFlags(); 235 regionFlags = estateModule.GetRegionFlags();
230 236
231 // In a perfect world, this would have worked.
232 //
233// if ((landData.Flags & (uint)ParcelFlags.AllowLandmark) != 0)
234// regionFlags |= (uint)RegionFlags.AllowLandmark;
235// if (landData.OwnerID == remote_client.AgentId)
236// regionFlags |= (uint)RegionFlags.AllowSetHome;
237
238 int seq_id; 237 int seq_id;
239 if (snap_selection && (sequence_id == 0)) 238 if (snap_selection && (sequence_id == 0))
240 { 239 {
@@ -368,12 +367,14 @@ namespace OpenSim.Region.CoreModules.World.Land
368 ParcelFlags.DenyAgeUnverified); 367 ParcelFlags.DenyAgeUnverified);
369 } 368 }
370 369
371 uint preserve = LandData.Flags & ~allowedDelta; 370 if (allowedDelta != (uint)ParcelFlags.None)
372 newData.Flags = preserve | (args.ParcelFlags & allowedDelta); 371 {
373 372 uint preserve = LandData.Flags & ~allowedDelta;
374 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData); 373 newData.Flags = preserve | (args.ParcelFlags & allowedDelta);
375 374
376 SendLandUpdateToAvatarsOverMe(snap_selection); 375 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
376 SendLandUpdateToAvatarsOverMe(snap_selection);
377 }
377 } 378 }
378 379
379 public void UpdateLandSold(UUID avatarID, UUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area) 380 public void UpdateLandSold(UUID avatarID, UUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area)
@@ -388,9 +389,16 @@ namespace OpenSim.Region.CoreModules.World.Land
388 newData.SalePrice = 0; 389 newData.SalePrice = 0;
389 newData.AuthBuyerID = UUID.Zero; 390 newData.AuthBuyerID = UUID.Zero;
390 newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); 391 newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
392
393 bool sellObjects = (LandData.Flags & (uint)(ParcelFlags.SellParcelObjects)) != 0
394 && !LandData.IsGroupOwned && !groupOwned;
395 UUID previousOwner = LandData.OwnerID;
396
391 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData); 397 m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
392 m_scene.EventManager.TriggerParcelPrimCountUpdate(); 398 m_scene.EventManager.TriggerParcelPrimCountUpdate();
393 SendLandUpdateToAvatarsOverMe(true); 399 SendLandUpdateToAvatarsOverMe(true);
400
401 if (sellObjects) SellLandObjects(previousOwner);
394 } 402 }
395 403
396 public void DeedToGroup(UUID groupID) 404 public void DeedToGroup(UUID groupID)
@@ -421,6 +429,19 @@ namespace OpenSim.Region.CoreModules.World.Land
421 return false; 429 return false;
422 } 430 }
423 431
432 public bool CanBeOnThisLand(UUID avatar, float posHeight)
433 {
434 if (posHeight < LandChannel.BAN_LINE_SAFETY_HIEGHT && IsBannedFromLand(avatar))
435 {
436 return false;
437 }
438 else if (IsRestrictedFromLand(avatar))
439 {
440 return false;
441 }
442 return true;
443 }
444
424 public bool HasGroupAccess(UUID avatar) 445 public bool HasGroupAccess(UUID avatar)
425 { 446 {
426 if (LandData.GroupID != UUID.Zero && (LandData.Flags & (uint)ParcelFlags.UseAccessGroup) == (uint)ParcelFlags.UseAccessGroup) 447 if (LandData.GroupID != UUID.Zero && (LandData.Flags & (uint)ParcelFlags.UseAccessGroup) == (uint)ParcelFlags.UseAccessGroup)
@@ -553,8 +574,8 @@ namespace OpenSim.Region.CoreModules.World.Land
553 try 574 try
554 { 575 {
555 over = 576 over =
556 m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)Constants.RegionSize - 1)), 577 m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)m_scene.RegionInfo.RegionSizeX - 1)),
557 Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)Constants.RegionSize - 1))); 578 Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)m_scene.RegionInfo.RegionSizeY - 1)));
558 } 579 }
559 catch (Exception) 580 catch (Exception)
560 { 581 {
@@ -701,15 +722,15 @@ namespace OpenSim.Region.CoreModules.World.Land
701 /// </summary> 722 /// </summary>
702 private void UpdateAABBAndAreaValues() 723 private void UpdateAABBAndAreaValues()
703 { 724 {
704 int min_x = 64; 725 int min_x = 10000;
705 int min_y = 64; 726 int min_y = 10000;
706 int max_x = 0; 727 int max_x = 0;
707 int max_y = 0; 728 int max_y = 0;
708 int tempArea = 0; 729 int tempArea = 0;
709 int x, y; 730 int x, y;
710 for (x = 0; x < 64; x++) 731 for (x = 0; x < LandBitmap.GetLength(0); x++)
711 { 732 {
712 for (y = 0; y < 64; y++) 733 for (y = 0; y < LandBitmap.GetLength(1); y++)
713 { 734 {
714 if (LandBitmap[x, y] == true) 735 if (LandBitmap[x, y] == true)
715 { 736 {
@@ -717,31 +738,31 @@ namespace OpenSim.Region.CoreModules.World.Land
717 if (min_y > y) min_y = y; 738 if (min_y > y) min_y = y;
718 if (max_x < x) max_x = x; 739 if (max_x < x) max_x = x;
719 if (max_y < y) max_y = y; 740 if (max_y < y) max_y = y;
720 tempArea += 16; //16sqm peice of land 741 tempArea += landUnit * landUnit; //16sqm peice of land
721 } 742 }
722 } 743 }
723 } 744 }
724 int tx = min_x * 4; 745 int tx = min_x * landUnit;
725 if (tx > ((int)Constants.RegionSize - 1)) 746 if (tx > ((int)m_scene.RegionInfo.RegionSizeX - 1))
726 tx = ((int)Constants.RegionSize - 1); 747 tx = ((int)m_scene.RegionInfo.RegionSizeX - 1);
727 int ty = min_y * 4; 748 int ty = min_y * landUnit;
728 if (ty > ((int)Constants.RegionSize - 1)) 749 if (ty > ((int)m_scene.RegionInfo.RegionSizeY - 1))
729 ty = ((int)Constants.RegionSize - 1); 750 ty = ((int)m_scene.RegionInfo.RegionSizeY - 1);
730 751
731 LandData.AABBMin = 752 LandData.AABBMin =
732 new Vector3( 753 new Vector3(
733 (float)(min_x * 4), (float)(min_y * 4), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0); 754 (float)(min_x * landUnit), (float)(min_y * landUnit), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0);
734 755
735 tx = max_x * 4; 756 tx = max_x * landUnit;
736 if (tx > ((int)Constants.RegionSize - 1)) 757 if (tx > ((int)m_scene.RegionInfo.RegionSizeX - 1))
737 tx = ((int)Constants.RegionSize - 1); 758 tx = ((int)m_scene.RegionInfo.RegionSizeX - 1);
738 ty = max_y * 4; 759 ty = max_y * landUnit;
739 if (ty > ((int)Constants.RegionSize - 1)) 760 if (ty > ((int)m_scene.RegionInfo.RegionSizeY - 1))
740 ty = ((int)Constants.RegionSize - 1); 761 ty = ((int)m_scene.RegionInfo.RegionSizeY - 1);
741 762
742 LandData.AABBMax 763 LandData.AABBMax
743 = new Vector3( 764 = new Vector3(
744 (float)(max_x * 4), (float)(max_y * 4), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0); 765 (float)(max_x * landUnit), (float)(max_y * landUnit), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0);
745 766
746 LandData.Area = tempArea; 767 LandData.Area = tempArea;
747 } 768 }
@@ -753,20 +774,12 @@ namespace OpenSim.Region.CoreModules.World.Land
753 /// <summary> 774 /// <summary>
754 /// Sets the land's bitmap manually 775 /// Sets the land's bitmap manually
755 /// </summary> 776 /// </summary>
756 /// <param name="bitmap">64x64 block representing where this land is on a map</param> 777 /// <param name="bitmap">block representing where this land is on a map mapped in a 4x4 meter grid</param>
757 public void SetLandBitmap(bool[,] bitmap) 778 public void SetLandBitmap(bool[,] bitmap)
758 { 779 {
759 if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2) 780 LandBitmap = bitmap;
760 { 781 // m_log.DebugFormat("{0} SetLandBitmap. BitmapSize=<{1},{2}>", LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
761 //Throw an exception - The bitmap is not 64x64 782 ForceUpdateLandInfo();
762 //throw new Exception("Error: Invalid Parcel Bitmap");
763 }
764 else
765 {
766 //Valid: Lets set it
767 LandBitmap = bitmap;
768 ForceUpdateLandInfo();
769 }
770 } 783 }
771 784
772 /// <summary> 785 /// <summary>
@@ -780,15 +793,19 @@ namespace OpenSim.Region.CoreModules.World.Land
780 793
781 public bool[,] BasicFullRegionLandBitmap() 794 public bool[,] BasicFullRegionLandBitmap()
782 { 795 {
783 return GetSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize); 796 return GetSquareLandBitmap(0, 0, (int)m_scene.RegionInfo.RegionSizeX, (int) m_scene.RegionInfo.RegionSizeY);
784 } 797 }
785 798
786 public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y) 799 public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y)
787 { 800 {
788 bool[,] tempBitmap = new bool[64,64]; 801 // Empty bitmap for the whole region
802 bool[,] tempBitmap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
789 tempBitmap.Initialize(); 803 tempBitmap.Initialize();
790 804
805 // Fill the bitmap square area specified by state and end
791 tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true); 806 tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
807 // m_log.DebugFormat("{0} GetSquareLandBitmap. tempBitmapSize=<{1},{2}>",
808 // LogHeader, tempBitmap.GetLength(0), tempBitmap.GetLength(1));
792 return tempBitmap; 809 return tempBitmap;
793 } 810 }
794 811
@@ -805,24 +822,20 @@ namespace OpenSim.Region.CoreModules.World.Land
805 public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y, 822 public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
806 bool set_value) 823 bool set_value)
807 { 824 {
808 if (land_bitmap.GetLength(0) != 64 || land_bitmap.GetLength(1) != 64 || land_bitmap.Rank != 2)
809 {
810 //Throw an exception - The bitmap is not 64x64
811 //throw new Exception("Error: Invalid Parcel Bitmap in modifyLandBitmapSquare()");
812 }
813
814 int x, y; 825 int x, y;
815 for (y = 0; y < 64; y++) 826 for (y = 0; y < land_bitmap.GetLength(1); y++)
816 { 827 {
817 for (x = 0; x < 64; x++) 828 for (x = 0; x < land_bitmap.GetLength(0); x++)
818 { 829 {
819 if (x >= start_x / 4 && x < end_x / 4 830 if (x >= start_x / landUnit && x < end_x / landUnit
820 && y >= start_y / 4 && y < end_y / 4) 831 && y >= start_y / landUnit && y < end_y / landUnit)
821 { 832 {
822 land_bitmap[x, y] = set_value; 833 land_bitmap[x, y] = set_value;
823 } 834 }
824 } 835 }
825 } 836 }
837 // m_log.DebugFormat("{0} ModifyLandBitmapSquare. startXY=<{1},{2}>, endXY=<{3},{4}>, val={5}, landBitmapSize=<{6},{7}>",
838 // LogHeader, start_x, start_y, end_x, end_y, set_value, land_bitmap.GetLength(0), land_bitmap.GetLength(1));
826 return land_bitmap; 839 return land_bitmap;
827 } 840 }
828 841
@@ -834,21 +847,21 @@ namespace OpenSim.Region.CoreModules.World.Land
834 /// <returns></returns> 847 /// <returns></returns>
835 public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add) 848 public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
836 { 849 {
837 if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2) 850 if (bitmap_base.GetLength(0) != bitmap_add.GetLength(0)
851 || bitmap_base.GetLength(1) != bitmap_add.GetLength(1)
852 || bitmap_add.Rank != 2
853 || bitmap_base.Rank != 2)
838 { 854 {
839 //Throw an exception - The bitmap is not 64x64 855 throw new Exception(
840 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeLandBitmaps"); 856 String.Format("{0} MergeLandBitmaps. merging maps not same size. baseSizeXY=<{1},{2}>, addSizeXY=<{3},{4}>",
841 } 857 LogHeader, bitmap_base.GetLength(0), bitmap_base.GetLength(1), bitmap_add.GetLength(0), bitmap_add.GetLength(1))
842 if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2) 858 );
843 {
844 //Throw an exception - The bitmap is not 64x64
845 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeLandBitmaps");
846 } 859 }
847 860
848 int x, y; 861 int x, y;
849 for (y = 0; y < 64; y++) 862 for (y = 0; y < bitmap_base.GetLength(1); y++)
850 { 863 {
851 for (x = 0; x < 64; x++) 864 for (x = 0; x < bitmap_add.GetLength(0); x++)
852 { 865 {
853 if (bitmap_add[x, y]) 866 if (bitmap_add[x, y])
854 { 867 {
@@ -865,13 +878,13 @@ namespace OpenSim.Region.CoreModules.World.Land
865 /// <returns></returns> 878 /// <returns></returns>
866 private byte[] ConvertLandBitmapToBytes() 879 private byte[] ConvertLandBitmapToBytes()
867 { 880 {
868 byte[] tempConvertArr = new byte[512]; 881 byte[] tempConvertArr = new byte[LandBitmap.GetLength(0) * LandBitmap.GetLength(1) / 8];
869 byte tempByte = 0; 882 byte tempByte = 0;
870 int x, y, i, byteNum = 0; 883 int byteNum = 0;
871 i = 0; 884 int i = 0;
872 for (y = 0; y < 64; y++) 885 for (int y = 0; y < LandBitmap.GetLength(1); y++)
873 { 886 {
874 for (x = 0; x < 64; x++) 887 for (int x = 0; x < LandBitmap.GetLength(0); x++)
875 { 888 {
876 tempByte = Convert.ToByte(tempByte | Convert.ToByte(LandBitmap[x, y]) << (i++ % 8)); 889 tempByte = Convert.ToByte(tempByte | Convert.ToByte(LandBitmap[x, y]) << (i++ % 8));
877 if (i % 8 == 0) 890 if (i % 8 == 0)
@@ -883,30 +896,52 @@ namespace OpenSim.Region.CoreModules.World.Land
883 } 896 }
884 } 897 }
885 } 898 }
899 // m_log.DebugFormat("{0} ConvertLandBitmapToBytes. BitmapSize=<{1},{2}>",
900 // LogHeader, LandBitmap.GetLength(0), LandBitmap.GetLength(1));
886 return tempConvertArr; 901 return tempConvertArr;
887 } 902 }
888 903
889 private bool[,] ConvertBytesToLandBitmap() 904 private bool[,] ConvertBytesToLandBitmap()
890 { 905 {
891 bool[,] tempConvertMap = new bool[landArrayMax, landArrayMax]; 906 bool[,] tempConvertMap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
892 tempConvertMap.Initialize(); 907 tempConvertMap.Initialize();
893 byte tempByte = 0; 908 byte tempByte = 0;
894 int x = 0, y = 0, i = 0, bitNum = 0; 909 // Math.Min overcomes an old bug that might have made it into the database. Only use the bytes that fit into convertMap.
895 for (i = 0; i < 512; i++) 910 int bitmapLen = Math.Min(LandData.Bitmap.Length, tempConvertMap.GetLength(0) * tempConvertMap.GetLength(1) / 8);
911 int xLen = (int)(m_scene.RegionInfo.RegionSizeX / landUnit);
912
913 if (bitmapLen == 512)
914 {
915 // Legacy bitmap being passed in. Use the legacy region size
916 // and only set the lower area of the larger region.
917 xLen = (int)(Constants.RegionSize / landUnit);
918 }
919 // m_log.DebugFormat("{0} ConvertBytesToLandBitmap: bitmapLen={1}, xLen={2}", LogHeader, bitmapLen, xLen);
920
921 int x = 0, y = 0;
922 for (int i = 0; i < bitmapLen; i++)
896 { 923 {
897 tempByte = LandData.Bitmap[i]; 924 tempByte = LandData.Bitmap[i];
898 for (bitNum = 0; bitNum < 8; bitNum++) 925 for (int bitNum = 0; bitNum < 8; bitNum++)
899 { 926 {
900 bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1); 927 bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
901 tempConvertMap[x, y] = bit; 928 try
929 {
930 tempConvertMap[x, y] = bit;
931 }
932 catch (Exception)
933 {
934 m_log.DebugFormat("{0} ConvertBytestoLandBitmap: i={1}, x={2}, y={3}", LogHeader, i, x, y);
935 }
902 x++; 936 x++;
903 if (x > 63) 937 if (x >= xLen)
904 { 938 {
905 x = 0; 939 x = 0;
906 y++; 940 y++;
907 } 941 }
908 } 942 }
909 } 943 }
944
910 return tempConvertMap; 945 return tempConvertMap;
911 } 946 }
912 947
@@ -1043,6 +1078,43 @@ namespace OpenSim.Region.CoreModules.World.Land
1043 1078
1044 #endregion 1079 #endregion
1045 1080
1081 #region Object Sales
1082
1083 public void SellLandObjects(UUID previousOwner)
1084 {
1085 // m_log.DebugFormat(
1086 // "[LAND OBJECT]: Request to sell objects in {0} from {1}", LandData.Name, previousOwner);
1087
1088 if (LandData.IsGroupOwned)
1089 return;
1090
1091 IBuySellModule m_BuySellModule = m_scene.RequestModuleInterface<IBuySellModule>();
1092 if (m_BuySellModule == null)
1093 {
1094 m_log.Error("[LAND OBJECT]: BuySellModule not found");
1095 return;
1096 }
1097
1098 ScenePresence sp;
1099 if (!m_scene.TryGetScenePresence(LandData.OwnerID, out sp))
1100 {
1101 m_log.Error("[LAND OBJECT]: New owner is not present in scene");
1102 return;
1103 }
1104
1105 lock (primsOverMe)
1106 {
1107 foreach (SceneObjectGroup obj in primsOverMe)
1108 {
1109 if (obj.OwnerID == previousOwner && obj.GroupID == UUID.Zero &&
1110 (obj.GetEffectivePermissions() & (uint)(OpenSim.Framework.PermissionMask.Transfer)) != 0)
1111 m_BuySellModule.BuyObject(sp.ControllingClient, UUID.Zero, obj.LocalId, 1, 0);
1112 }
1113 }
1114 }
1115
1116 #endregion
1117
1046 #region Object Returning 1118 #region Object Returning
1047 1119
1048 public void ReturnObject(SceneObjectGroup obj) 1120 public void ReturnObject(SceneObjectGroup obj)
@@ -1065,7 +1137,7 @@ namespace OpenSim.Region.CoreModules.World.Land
1065 { 1137 {
1066 foreach (SceneObjectGroup obj in primsOverMe) 1138 foreach (SceneObjectGroup obj in primsOverMe)
1067 { 1139 {
1068 if (obj.OwnerID == m_landData.OwnerID) 1140 if (obj.OwnerID == LandData.OwnerID)
1069 { 1141 {
1070 if (!returns.ContainsKey(obj.OwnerID)) 1142 if (!returns.ContainsKey(obj.OwnerID))
1071 returns[obj.OwnerID] = 1143 returns[obj.OwnerID] =
@@ -1074,11 +1146,11 @@ namespace OpenSim.Region.CoreModules.World.Land
1074 } 1146 }
1075 } 1147 }
1076 } 1148 }
1077 else if (type == (uint)ObjectReturnType.Group && m_landData.GroupID != UUID.Zero) 1149 else if (type == (uint)ObjectReturnType.Group && LandData.GroupID != UUID.Zero)
1078 { 1150 {
1079 foreach (SceneObjectGroup obj in primsOverMe) 1151 foreach (SceneObjectGroup obj in primsOverMe)
1080 { 1152 {
1081 if (obj.GroupID == m_landData.GroupID) 1153 if (obj.GroupID == LandData.GroupID)
1082 { 1154 {
1083 if (!returns.ContainsKey(obj.OwnerID)) 1155 if (!returns.ContainsKey(obj.OwnerID))
1084 returns[obj.OwnerID] = 1156 returns[obj.OwnerID] =
@@ -1091,9 +1163,9 @@ namespace OpenSim.Region.CoreModules.World.Land
1091 { 1163 {
1092 foreach (SceneObjectGroup obj in primsOverMe) 1164 foreach (SceneObjectGroup obj in primsOverMe)
1093 { 1165 {
1094 if (obj.OwnerID != m_landData.OwnerID && 1166 if (obj.OwnerID != LandData.OwnerID &&
1095 (obj.GroupID != m_landData.GroupID || 1167 (obj.GroupID != LandData.GroupID ||
1096 m_landData.GroupID == UUID.Zero)) 1168 LandData.GroupID == UUID.Zero))
1097 { 1169 {
1098 if (!returns.ContainsKey(obj.OwnerID)) 1170 if (!returns.ContainsKey(obj.OwnerID))
1099 returns[obj.OwnerID] = 1171 returns[obj.OwnerID] =