aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs837
1 files changed, 0 insertions, 837 deletions
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs b/OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs
deleted file mode 100644
index 21b783f..0000000
--- a/OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs
+++ /dev/null
@@ -1,837 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.RegionServer.Simulator;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types;
36using OpenSim.RegionServer.Client;
37
38namespace OpenSim.RegionServer.Simulator
39{
40 public delegate void ParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id, bool snap_selection, ClientView remote_client);
41 public delegate void ParcelDivideRequest(int west, int south, int east, int north, ClientView remote_client);
42 public delegate void ParcelJoinRequest(int west, int south, int east, int north, ClientView remote_client);
43 public delegate void ParcelPropertiesUpdateRequest(ParcelPropertiesUpdatePacket packet, ClientView remote_client);
44
45 #region ParcelManager Class
46 /// <summary>
47 /// Handles Parcel objects and operations requiring information from other Parcel objects (divide, join, etc)
48 /// </summary>
49 public class ParcelManager : OpenSim.Framework.Interfaces.ILocalStorageParcelReceiver
50 {
51
52 #region Constants
53 //Parcel types set with flags in ParcelOverlay.
54 //Only one of these can be used.
55 public const byte PARCEL_TYPE_PUBLIC = (byte)0; //Equals 00000000
56 public const byte PARCEL_TYPE_OWNED_BY_OTHER = (byte)1; //Equals 00000001
57 public const byte PARCEL_TYPE_OWNED_BY_GROUP = (byte)2; //Equals 00000010
58 public const byte PARCEL_TYPE_OWNED_BY_REQUESTER = (byte)3; //Equals 00000011
59 public const byte PARCEL_TYPE_IS_FOR_SALE = (byte)4; //Equals 00000100
60 public const byte PARCEL_TYPE_IS_BEING_AUCTIONED = (byte)5; //Equals 00000101
61
62
63 //Flags that when set, a border on the given side will be placed
64 //NOTE: North and East is assumable by the west and south sides (if parcel to east has a west border, then I have an east border; etc)
65 //This took forever to figure out -- jeesh. /blame LL for even having to send these
66 public const byte PARCEL_FLAG_PROPERTY_BORDER_WEST = (byte)64; //Equals 01000000
67 public const byte PARCEL_FLAG_PROPERTY_BORDER_SOUTH = (byte)128; //Equals 10000000
68
69 //RequestResults (I think these are right, they seem to work):
70 public const int PARCEL_RESULT_ONE_PARCEL = 0; // The request they made contained only one parcel
71 public const int PARCEL_RESULT_MULTIPLE_PARCELS = 1; // The request they made contained more than one parcel
72
73 //These are other constants. Yay!
74 public const int START_PARCEL_LOCAL_ID = 1;
75 #endregion
76
77 #region Member Variables
78 public Dictionary<int, Parcel> parcelList = new Dictionary<int, Parcel>();
79 private int lastParcelLocalID = START_PARCEL_LOCAL_ID - 1;
80 private int[,] parcelIDList = new int[64, 64];
81
82 private static World m_world;
83 #endregion
84
85 #region Constructors
86 public ParcelManager(World world)
87 {
88
89 m_world = world;
90 parcelIDList.Initialize();
91
92 }
93 #endregion
94
95 #region Member Functions
96
97 #region Parcel From Storage Functions
98 public void ParcelFromStorage(ParcelData data)
99 {
100 Parcel new_parcel = new Parcel(data.ownerID, data.isGroupOwned, m_world);
101 new_parcel.parcelData = data.Copy();
102 new_parcel.setParcelBitmapFromByteArray();
103 addParcel(new_parcel);
104
105 }
106
107 public void NoParcelDataFromStorage()
108 {
109 resetSimParcels();
110 }
111 #endregion
112
113 #region Parcel Add/Remove/Get/Create
114 /// <summary>
115 /// Creates a basic Parcel object without an owner (a zeroed key)
116 /// </summary>
117 /// <returns></returns>
118 public Parcel createBaseParcel()
119 {
120 return new Parcel(new LLUUID(), false, m_world);
121 }
122
123 /// <summary>
124 /// Adds a parcel to the stored list and adds them to the parcelIDList to what they own
125 /// </summary>
126 /// <param name="new_parcel">The parcel being added</param>
127 public void addParcel(Parcel new_parcel)
128 {
129 lastParcelLocalID++;
130 new_parcel.parcelData.localID = lastParcelLocalID;
131 parcelList.Add(lastParcelLocalID, new_parcel.Copy());
132
133
134 bool[,] parcelBitmap = new_parcel.getParcelBitmap();
135 int x, y;
136 for (x = 0; x < 64; x++)
137 {
138 for (y = 0; y < 64; y++)
139 {
140 if (parcelBitmap[x, y])
141 {
142 parcelIDList[x, y] = lastParcelLocalID;
143 }
144 }
145 }
146 parcelList[lastParcelLocalID].forceUpdateParcelInfo();
147
148
149 }
150 /// <summary>
151 /// Removes a parcel from the list. Will not remove if local_id is still owning an area in parcelIDList
152 /// </summary>
153 /// <param name="local_id">Parcel.localID of the parcel to remove.</param>
154 public void removeParcel(int local_id)
155 {
156 int x, y;
157 for (x = 0; x < 64; x++)
158 {
159 for (y = 0; y < 64; y++)
160 {
161 if (parcelIDList[x, y] == local_id)
162 {
163 throw new Exception("Could not remove parcel. Still being used at " + x + ", " + y);
164 }
165 }
166 }
167 m_world.localStorage.RemoveParcel(parcelList[local_id].parcelData);
168 parcelList.Remove(local_id);
169 }
170
171 public void performFinalParcelJoin(Parcel master, Parcel slave)
172 {
173 int x, y;
174 bool[,] parcelBitmapSlave = slave.getParcelBitmap();
175 for (x = 0; x < 64; x++)
176 {
177 for (y = 0; y < 64; y++)
178 {
179 if (parcelBitmapSlave[x, y])
180 {
181 parcelIDList[x, y] = master.parcelData.localID;
182 }
183 }
184 }
185 removeParcel(slave.parcelData.localID);
186 }
187 /// <summary>
188 /// Get the parcel at the specified point
189 /// </summary>
190 /// <param name="x">Value between 0 - 256 on the x axis of the point</param>
191 /// <param name="y">Value between 0 - 256 on the y axis of the point</param>
192 /// <returns>Parcel at the point supplied</returns>
193 public Parcel getParcel(int x, int y)
194 {
195 if (x > 256 || y > 256 || x < 0 || y < 0)
196 {
197 throw new Exception("Error: Parcel not found at point " + x + ", " + y);
198 }
199 else
200 {
201 return parcelList[parcelIDList[x / 4, y / 4]];
202 }
203
204 }
205 #endregion
206
207 #region Parcel Modification
208 /// <summary>
209 /// Subdivides a parcel
210 /// </summary>
211 /// <param name="start_x">West Point</param>
212 /// <param name="start_y">South Point</param>
213 /// <param name="end_x">East Point</param>
214 /// <param name="end_y">North Point</param>
215 /// <param name="attempting_user_id">LLUUID of user who is trying to subdivide</param>
216 /// <returns>Returns true if successful</returns>
217 public bool subdivide(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
218 {
219 //First, lets loop through the points and make sure they are all in the same parcel
220 //Get the parcel at start
221 Parcel startParcel = getParcel(start_x, start_y);
222 if (startParcel == null) return false; //No such parcel at the beginning
223
224 //Loop through the points
225 try
226 {
227 int totalX = end_x - start_x;
228 int totalY = end_y - start_y;
229 int x, y;
230 for (y = 0; y < totalY; y++)
231 {
232 for (x = 0; x < totalX; x++)
233 {
234 Parcel tempParcel = getParcel(start_x + x, start_y + y);
235 if (tempParcel == null) return false; //No such parcel at that point
236 if (tempParcel != startParcel) return false; //Subdividing over 2 parcels; no-no
237 }
238 }
239 }
240 catch
241 {
242 return false; //Exception. For now, lets skip subdivision
243 }
244
245 //If we are still here, then they are subdividing within one parcel
246 //Check owner
247 if (startParcel.parcelData.ownerID != attempting_user_id)
248 {
249 return false; //They cant do this!
250 }
251
252 //Lets create a new parcel with bitmap activated at that point (keeping the old parcels info)
253 Parcel newParcel = startParcel.Copy();
254 newParcel.parcelData.parcelName = "Subdivision of " + newParcel.parcelData.parcelName;
255 newParcel.parcelData.globalID = LLUUID.Random();
256
257 newParcel.setParcelBitmap(Parcel.getSquareParcelBitmap(start_x, start_y, end_x, end_y));
258
259 //Now, lets set the subdivision area of the original to false
260 int startParcelIndex = startParcel.parcelData.localID;
261 parcelList[startParcelIndex].setParcelBitmap(Parcel.modifyParcelBitmapSquare(startParcel.getParcelBitmap(), start_x, start_y, end_x, end_y, false));
262 parcelList[startParcelIndex].forceUpdateParcelInfo();
263
264
265 //Now add the new parcel
266 addParcel(newParcel);
267
268
269
270
271
272 return true;
273 }
274 /// <summary>
275 /// Join 2 parcels together
276 /// </summary>
277 /// <param name="start_x">x value in first parcel</param>
278 /// <param name="start_y">y value in first parcel</param>
279 /// <param name="end_x">x value in second parcel</param>
280 /// <param name="end_y">y value in second parcel</param>
281 /// <param name="attempting_user_id">LLUUID of the avatar trying to join the parcels</param>
282 /// <returns>Returns true if successful</returns>
283 public bool join(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
284 {
285 end_x -= 4;
286 end_y -= 4;
287
288 //NOTE: The following only connects the parcels in each corner and not all the parcels that are within the selection box!
289 //This should be fixed later -- somewhat "incomplete code" --Ming
290 Parcel startParcel, endParcel;
291
292 try
293 {
294 startParcel = getParcel(start_x, start_y);
295 endParcel = getParcel(end_x, end_y);
296 }
297 catch
298 {
299 return false; //Error occured when trying to get the start and end parcels
300 }
301 if (startParcel == endParcel)
302 {
303 return false; //Subdivision of the same parcel is not allowed
304 }
305
306 //Check the parcel owners:
307 if (startParcel.parcelData.ownerID != endParcel.parcelData.ownerID)
308 {
309 return false;
310 }
311 if (startParcel.parcelData.ownerID != attempting_user_id)
312 {
313 //TODO: Group editing stuff. Avatar owner support for now
314 return false;
315 }
316
317 //Same owners! Lets join them
318 //Merge them to startParcel
319 parcelList[startParcel.parcelData.localID].setParcelBitmap(Parcel.mergeParcelBitmaps(startParcel.getParcelBitmap(), endParcel.getParcelBitmap()));
320 performFinalParcelJoin(startParcel, endParcel);
321
322 return true;
323
324
325
326 }
327 #endregion
328
329 #region Parcel Updating
330 /// <summary>
331 /// Where we send the ParcelOverlay packet to the client
332 /// </summary>
333 /// <param name="remote_client">The object representing the client</param>
334 public void sendParcelOverlay(ClientView remote_client)
335 {
336 const int PARCEL_BLOCKS_PER_PACKET = 1024;
337 int x, y = 0;
338 byte[] byteArray = new byte[PARCEL_BLOCKS_PER_PACKET];
339 int byteArrayCount = 0;
340 int sequenceID = 0;
341 ParcelOverlayPacket packet;
342
343 for (y = 0; y < 64; y++)
344 {
345 for (x = 0; x < 64; x++)
346 {
347 byte tempByte = (byte)0; //This represents the byte for the current 4x4
348 Parcel currentParcelBlock = getParcel(x * 4, y * 4);
349
350 if (currentParcelBlock.parcelData.ownerID == remote_client.AgentID)
351 {
352 //Owner Flag
353 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_OWNED_BY_REQUESTER);
354 }
355 else if (currentParcelBlock.parcelData.salePrice > 0 && (currentParcelBlock.parcelData.authBuyerID == LLUUID.Zero || currentParcelBlock.parcelData.authBuyerID == remote_client.AgentID))
356 {
357 //Sale Flag
358 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_IS_FOR_SALE);
359 }
360 else if (currentParcelBlock.parcelData.ownerID == LLUUID.Zero)
361 {
362 //Public Flag
363 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_PUBLIC);
364 }
365 else
366 {
367 //Other Flag
368 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_OWNED_BY_OTHER);
369 }
370
371
372 //Now for border control
373 if (x == 0)
374 {
375 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_WEST);
376 }
377 else if (getParcel((x - 1) * 4, y * 4) != currentParcelBlock)
378 {
379 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_WEST);
380 }
381
382 if (y == 0)
383 {
384 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_SOUTH);
385 }
386 else if (getParcel(x * 4, (y - 1) * 4) != currentParcelBlock)
387 {
388 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_SOUTH);
389 }
390
391 byteArray[byteArrayCount] = tempByte;
392 byteArrayCount++;
393 if (byteArrayCount >= PARCEL_BLOCKS_PER_PACKET)
394 {
395 byteArrayCount = 0;
396 packet = new ParcelOverlayPacket();
397 packet.ParcelData.Data = byteArray;
398 packet.ParcelData.SequenceID = sequenceID;
399 //remote_client.OutPacket((Packet)packet);
400 sequenceID++;
401 byteArray = new byte[PARCEL_BLOCKS_PER_PACKET];
402 }
403 }
404 }
405
406 packet = new ParcelOverlayPacket();
407 packet.ParcelData.Data = byteArray;
408 packet.ParcelData.SequenceID = sequenceID; //Eh?
409 //remote_client.OutPacket((Packet)packet);
410 }
411 #endregion
412
413 /// <summary>
414 /// Resets the sim to the default parcel (full sim parcel owned by the default user)
415 /// </summary>
416 public void resetSimParcels()
417 {
418 //Remove all the parcels in the sim and add a blank, full sim parcel set to public
419 parcelList.Clear();
420 lastParcelLocalID = START_PARCEL_LOCAL_ID - 1;
421 parcelIDList.Initialize();
422
423 Parcel fullSimParcel = new Parcel(LLUUID.Zero, false, m_world);
424
425 fullSimParcel.setParcelBitmap(Parcel.getSquareParcelBitmap(0, 0, 256, 256));
426 fullSimParcel.parcelData.parcelName = "Your Sim Parcel";
427 fullSimParcel.parcelData.parcelDesc = "";
428
429 fullSimParcel.parcelData.ownerID = m_world.m_regInfo.MasterAvatarAssignedUUID;
430 fullSimParcel.parcelData.salePrice = 1;
431 fullSimParcel.parcelData.parcelFlags = libsecondlife.Parcel.ParcelFlags.ForSale;
432 fullSimParcel.parcelData.parcelStatus = libsecondlife.Parcel.ParcelStatus.Leased;
433
434 addParcel(fullSimParcel);
435
436 }
437 #endregion
438 }
439 #endregion
440
441
442 #region Parcel Class
443 /// <summary>
444 /// Keeps track of a specific parcel's information
445 /// </summary>
446 public class Parcel
447 {
448 #region Member Variables
449 public ParcelData parcelData = new ParcelData();
450 public World m_world;
451
452 private bool[,] parcelBitmap = new bool[64, 64];
453
454 #endregion
455
456
457 #region Constructors
458 public Parcel(LLUUID owner_id, bool is_group_owned, World world)
459 {
460 m_world = world;
461 parcelData.ownerID = owner_id;
462 parcelData.isGroupOwned = is_group_owned;
463
464 }
465 #endregion
466
467
468 #region Member Functions
469
470 #region General Functions
471 /// <summary>
472 /// Checks to see if this parcel contains a point
473 /// </summary>
474 /// <param name="x"></param>
475 /// <param name="y"></param>
476 /// <returns>Returns true if the parcel contains the specified point</returns>
477 public bool containsPoint(int x, int y)
478 {
479 if (x >= 0 && y >= 0 && x <= 256 && x <= 256)
480 {
481 return (parcelBitmap[x / 4, y / 4] == true);
482 }
483 else
484 {
485 return false;
486 }
487 }
488
489 public Parcel Copy()
490 {
491 Parcel newParcel = new Parcel(this.parcelData.ownerID, this.parcelData.isGroupOwned, m_world);
492
493 //Place all new variables here!
494 newParcel.parcelBitmap = (bool[,])(this.parcelBitmap.Clone());
495 newParcel.parcelData = parcelData.Copy();
496
497 return newParcel;
498 }
499
500 #endregion
501
502
503 #region Packet Request Handling
504 /// <summary>
505 /// Sends parcel properties as requested
506 /// </summary>
507 /// <param name="sequence_id">ID sent by client for them to keep track of</param>
508 /// <param name="snap_selection">Bool sent by client for them to use</param>
509 /// <param name="remote_client">Object representing the client</param>
510 public void sendParcelProperties(int sequence_id, bool snap_selection, int request_result, ClientView remote_client)
511 {
512
513 /*ParcelPropertiesPacket updatePacket = new ParcelPropertiesPacket();
514 updatePacket.ParcelData.AABBMax = parcelData.AABBMax;
515 updatePacket.ParcelData.AABBMin = parcelData.AABBMin;
516 updatePacket.ParcelData.Area = parcelData.area;
517 updatePacket.ParcelData.AuctionID = parcelData.auctionID;
518 updatePacket.ParcelData.AuthBuyerID =parcelData.authBuyerID; //unemplemented
519
520 updatePacket.ParcelData.Bitmap = parcelData.parcelBitmapByteArray;
521
522 updatePacket.ParcelData.Desc = libsecondlife.Helpers.StringToField(parcelData.parcelDesc);
523 updatePacket.ParcelData.Category = (byte)parcelData.category;
524 updatePacket.ParcelData.ClaimDate = parcelData.claimDate;
525 updatePacket.ParcelData.ClaimPrice = parcelData.claimPrice;
526 updatePacket.ParcelData.GroupID = parcelData.groupID;
527 updatePacket.ParcelData.GroupPrims = parcelData.groupPrims;
528 updatePacket.ParcelData.IsGroupOwned = parcelData.isGroupOwned;
529 updatePacket.ParcelData.LandingType = (byte)parcelData.landingType;
530 updatePacket.ParcelData.LocalID = parcelData.localID;
531 updatePacket.ParcelData.MaxPrims = 1000; //unemplemented
532 updatePacket.ParcelData.MediaAutoScale = parcelData.mediaAutoScale;
533 updatePacket.ParcelData.MediaID = parcelData.mediaID;
534 updatePacket.ParcelData.MediaURL = Helpers.StringToField(parcelData.mediaURL);
535 updatePacket.ParcelData.MusicURL = Helpers.StringToField(parcelData.musicURL);
536 updatePacket.ParcelData.Name = Helpers.StringToField(parcelData.parcelName);
537 updatePacket.ParcelData.OtherCleanTime = 0; //unemplemented
538 updatePacket.ParcelData.OtherCount = 0; //unemplemented
539 updatePacket.ParcelData.OtherPrims = 0; //unemplented
540 updatePacket.ParcelData.OwnerID = parcelData.ownerID;
541 updatePacket.ParcelData.OwnerPrims = 0; //unemplemented
542 updatePacket.ParcelData.ParcelFlags = (uint)parcelData.parcelFlags; //unemplemented
543 updatePacket.ParcelData.ParcelPrimBonus = (float)1.0; //unemplemented
544 updatePacket.ParcelData.PassHours = parcelData.passHours;
545 updatePacket.ParcelData.PassPrice = parcelData.passPrice;
546 updatePacket.ParcelData.PublicCount = 0; //unemplemented
547 updatePacket.ParcelData.RegionDenyAnonymous = false; //unemplemented
548 updatePacket.ParcelData.RegionDenyIdentified = false; //unemplemented
549 updatePacket.ParcelData.RegionDenyTransacted = false; //unemplemented
550 updatePacket.ParcelData.RegionPushOverride = true; //unemplemented
551 updatePacket.ParcelData.RentPrice = 0; //??
552 updatePacket.ParcelData.RequestResult = request_result;
553 updatePacket.ParcelData.SalePrice = parcelData.salePrice; //unemplemented
554 updatePacket.ParcelData.SelectedPrims = 0; //unemeplemented
555 updatePacket.ParcelData.SelfCount = 0;//unemplemented
556 updatePacket.ParcelData.SequenceID = sequence_id;
557 updatePacket.ParcelData.SimWideMaxPrims = 15000; //unemplemented
558 updatePacket.ParcelData.SimWideTotalPrims = 0; //unemplemented
559 updatePacket.ParcelData.SnapSelection = snap_selection;
560 updatePacket.ParcelData.SnapshotID = parcelData.snapshotID;
561 updatePacket.ParcelData.Status = (byte)parcelData.parcelStatus;
562 updatePacket.ParcelData.TotalPrims = 0; //unemplemented
563 updatePacket.ParcelData.UserLocation = parcelData.userLocation;
564 updatePacket.ParcelData.UserLookAt = parcelData.userLookAt;
565 remote_client.OutPacket((Packet)updatePacket); */
566 }
567
568 public void updateParcelProperties(ParcelPropertiesUpdatePacket packet, ClientView remote_client)
569 {
570 if (remote_client.AgentID == parcelData.ownerID)
571 {
572 //Needs later group support
573 parcelData.authBuyerID = packet.ParcelData.AuthBuyerID;
574 parcelData.category = (libsecondlife.Parcel.ParcelCategory)packet.ParcelData.Category;
575 parcelData.parcelDesc = Helpers.FieldToUTF8String(packet.ParcelData.Desc);
576 parcelData.groupID = packet.ParcelData.GroupID;
577 parcelData.landingType = packet.ParcelData.LandingType;
578 parcelData.mediaAutoScale = packet.ParcelData.MediaAutoScale;
579 parcelData.mediaID = packet.ParcelData.MediaID;
580 parcelData.mediaURL = Helpers.FieldToUTF8String(packet.ParcelData.MediaURL);
581 parcelData.musicURL = Helpers.FieldToUTF8String(packet.ParcelData.MusicURL);
582 parcelData.parcelName = libsecondlife.Helpers.FieldToUTF8String(packet.ParcelData.Name);
583 parcelData.parcelFlags = (libsecondlife.Parcel.ParcelFlags)packet.ParcelData.ParcelFlags;
584 parcelData.passHours = packet.ParcelData.PassHours;
585 parcelData.passPrice = packet.ParcelData.PassPrice;
586 parcelData.salePrice = packet.ParcelData.SalePrice;
587 parcelData.snapshotID = packet.ParcelData.SnapshotID;
588 parcelData.userLocation = packet.ParcelData.UserLocation;
589 parcelData.userLookAt = packet.ParcelData.UserLookAt;
590
591 foreach (Avatar av in m_world.Avatars.Values)
592 {
593 Parcel over = m_world.parcelManager.getParcel((int)Math.Round(av.Pos.X), (int)Math.Round(av.Pos.Y));
594 if (over == this)
595 {
596 sendParcelProperties(0, false, 0, av.ControllingClient);
597 }
598 }
599 }
600 }
601 #endregion
602
603
604 #region Update Functions
605 /// <summary>
606 /// Updates the AABBMin and AABBMax values after area/shape modification of parcel
607 /// </summary>
608 private void updateAABBAndAreaValues()
609 {
610 int min_x = 64;
611 int min_y = 64;
612 int max_x = 0;
613 int max_y = 0;
614 int tempArea = 0;
615 int x, y;
616 for (x = 0; x < 64; x++)
617 {
618 for (y = 0; y < 64; y++)
619 {
620 if (parcelBitmap[x, y] == true)
621 {
622 if (min_x > x) min_x = x;
623 if (min_y > y) min_y = y;
624 if (max_x < x) max_x = x;
625 if (max_y < y) max_y = y;
626 tempArea += 16; //16sqm parcel
627 }
628 }
629 }
630 parcelData.AABBMin = new LLVector3((float)(min_x * 4), (float)(min_y * 4), m_world.Terrain[(min_x * 4), (min_y * 4)]);
631 parcelData.AABBMax = new LLVector3((float)(max_x * 4), (float)(max_y * 4), m_world.Terrain[(max_x * 4), (max_y * 4)]);
632 parcelData.area = tempArea;
633 }
634
635 public void updateParcelBitmapByteArray()
636 {
637 parcelData.parcelBitmapByteArray = convertParcelBitmapToBytes();
638 }
639
640 /// <summary>
641 /// Update all settings in parcel such as area, bitmap byte array, etc
642 /// </summary>
643 public void forceUpdateParcelInfo()
644 {
645 this.updateAABBAndAreaValues();
646 this.updateParcelBitmapByteArray();
647 }
648
649 public void setParcelBitmapFromByteArray()
650 {
651 parcelBitmap = convertBytesToParcelBitmap();
652 }
653 #endregion
654
655
656 #region Parcel Bitmap Functions
657 /// <summary>
658 /// Sets the parcel's bitmap manually
659 /// </summary>
660 /// <param name="bitmap">64x64 block representing where this parcel is on a map</param>
661 public void setParcelBitmap(bool[,] bitmap)
662 {
663 if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2)
664 {
665 //Throw an exception - The bitmap is not 64x64
666 throw new Exception("Error: Invalid Parcel Bitmap");
667 }
668 else
669 {
670 //Valid: Lets set it
671 parcelBitmap = bitmap;
672 forceUpdateParcelInfo();
673
674 }
675 }
676 /// <summary>
677 /// Gets the parcels bitmap manually
678 /// </summary>
679 /// <returns></returns>
680 public bool[,] getParcelBitmap()
681 {
682 return parcelBitmap;
683 }
684 /// <summary>
685 /// Converts the parcel bitmap to a packet friendly byte array
686 /// </summary>
687 /// <returns></returns>
688 private byte[] convertParcelBitmapToBytes()
689 {
690 byte[] tempConvertArr = new byte[512];
691 byte tempByte = 0;
692 int x, y, i, byteNum = 0;
693 i = 0;
694 for (y = 0; y < 64; y++)
695 {
696 for (x = 0; x < 64; x++)
697 {
698 tempByte = Convert.ToByte(tempByte | Convert.ToByte(parcelBitmap[x, y]) << (i++ % 8));
699 if (i % 8 == 0)
700 {
701 tempConvertArr[byteNum] = tempByte;
702 tempByte = (byte)0;
703 i = 0;
704 byteNum++;
705 }
706 }
707 }
708 return tempConvertArr;
709 }
710
711 private bool[,] convertBytesToParcelBitmap()
712 {
713 bool[,] tempConvertMap = new bool[64, 64];
714 tempConvertMap.Initialize();
715 byte tempByte = 0;
716 int x = 0, y = 0, i = 0, bitNum = 0;
717 for(i = 0; i < 512; i++)
718 {
719 tempByte = parcelData.parcelBitmapByteArray[i];
720 for(bitNum = 0; bitNum < 8; bitNum++)
721 {
722 bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte)1);
723 tempConvertMap[x, y] = bit;
724 x++;
725 if(x > 63)
726 {
727 x = 0;
728 y++;
729 }
730
731 }
732
733 }
734 return tempConvertMap;
735 }
736 /// <summary>
737 /// Full sim parcel creation
738 /// </summary>
739 /// <returns></returns>
740 public static bool[,] basicFullRegionParcelBitmap()
741 {
742 return getSquareParcelBitmap(0, 0, 256, 256);
743 }
744
745 /// <summary>
746 /// Used to modify the bitmap between the x and y points. Points use 64 scale
747 /// </summary>
748 /// <param name="start_x"></param>
749 /// <param name="start_y"></param>
750 /// <param name="end_x"></param>
751 /// <param name="end_y"></param>
752 /// <returns></returns>
753 public static bool[,] getSquareParcelBitmap(int start_x, int start_y, int end_x, int end_y)
754 {
755
756 bool[,] tempBitmap = new bool[64, 64];
757 tempBitmap.Initialize();
758
759 tempBitmap = modifyParcelBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
760 return tempBitmap;
761 }
762
763 /// <summary>
764 /// Change a parcel's bitmap at within a square and set those points to a specific value
765 /// </summary>
766 /// <param name="parcel_bitmap"></param>
767 /// <param name="start_x"></param>
768 /// <param name="start_y"></param>
769 /// <param name="end_x"></param>
770 /// <param name="end_y"></param>
771 /// <param name="set_value"></param>
772 /// <returns></returns>
773 public static bool[,] modifyParcelBitmapSquare(bool[,] parcel_bitmap, int start_x, int start_y, int end_x, int end_y, bool set_value)
774 {
775 if (parcel_bitmap.GetLength(0) != 64 || parcel_bitmap.GetLength(1) != 64 || parcel_bitmap.Rank != 2)
776 {
777 //Throw an exception - The bitmap is not 64x64
778 throw new Exception("Error: Invalid Parcel Bitmap in modifyParcelBitmapSquare()");
779 }
780
781 int x, y;
782 for (y = 0; y < 64; y++)
783 {
784 for (x = 0; x < 64; x++)
785 {
786 if (x >= start_x / 4 && x < end_x / 4
787 && y >= start_y / 4 && y < end_y / 4)
788 {
789 parcel_bitmap[x, y] = set_value;
790 }
791 }
792 }
793 return parcel_bitmap;
794 }
795 /// <summary>
796 /// Join the true values of 2 bitmaps together
797 /// </summary>
798 /// <param name="bitmap_base"></param>
799 /// <param name="bitmap_add"></param>
800 /// <returns></returns>
801 public static bool[,] mergeParcelBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
802 {
803 if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2)
804 {
805 //Throw an exception - The bitmap is not 64x64
806 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeParcelBitmaps");
807 }
808 if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
809 {
810 //Throw an exception - The bitmap is not 64x64
811 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeParcelBitmaps");
812
813 }
814
815 int x, y;
816 for (y = 0; y < 64; y++)
817 {
818 for (x = 0; x < 64; x++)
819 {
820 if (bitmap_add[x, y])
821 {
822 bitmap_base[x, y] = true;
823 }
824 }
825 }
826 return bitmap_base;
827 }
828 #endregion
829
830 #endregion
831
832
833 }
834 #endregion
835
836
837}