From d468b7f2d33ac2562048f60de599e2e07cac270d Mon Sep 17 00:00:00 2001
From: Dahlia Trimble
Date: Sun, 29 Mar 2009 23:59:14 +0000
Subject: Thank you Flyte Xevious for Mantis #3361 - Implementation of
 llEdgeOfWorld

---
 .../Shared/Api/Implementation/LSL_Api.cs           | 62 +++++++++++++++++++++-
 1 file changed, 60 insertions(+), 2 deletions(-)

(limited to 'OpenSim/Region')

diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 9819ce0..3c1b87f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -4991,8 +4991,66 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
         public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
         {
             m_host.AddScriptLPS(1);
-            NotImplemented("llEdgeOfWorld");
-            return 0;
+
+            // edge will be used to pass the Region Coordinates offset
+            // we want to check for a neighboring sim
+            LSL_Vector edge = new LSL_Vector(0, 0, 0);
+            
+            if (dir.x == 0)
+            {
+            	if (dir.y == 0)
+            	{
+            		// Direction vector is 0,0 so return
+            		// false since we're staying in the sim
+            	    return 0;
+            	}
+            	else
+            	{
+            		// Y is the only valid direction
+            		edge.y = dir.y / Math.Abs(dir.y);
+            	}
+            }
+            else
+            {
+                LSL_Float mag;
+            	if (dir.x > 0)
+            	{
+                    mag = (Constants.RegionSize - pos.x) / dir.x;  
+            	}
+            	else
+            	{
+                    mag = (pos.x/dir.x);
+            	}
+
+                mag = Math.Abs(mag);
+
+                edge.y = pos.y + (dir.y * mag);
+
+                if (edge.y > Constants.RegionSize || edge.y < 0)
+                {
+                	// Y goes out of bounds first
+                    edge.y = dir.y / Math.Abs(dir.y);
+                }
+                else
+                {
+                    // X goes out of bounds first or its a corner exit
+                    edge.y = 0;
+                    edge.x = dir.x / Math.Abs(dir.x);
+                }
+            }
+            
+        	List<SimpleRegionInfo> neighbors = World.CommsManager.GridService.RequestNeighbours(World.RegionInfo.RegionLocX, World.RegionInfo.RegionLocY);
+            
+        	uint neighborX = World.RegionInfo.RegionLocX + (uint)dir.x;
+        	uint neighborY = World.RegionInfo.RegionLocY + (uint)dir.y;
+        	
+        	foreach (SimpleRegionInfo sri in neighbors)
+        	{
+        		if (sri.RegionLocX == neighborX && sri.RegionLocY == neighborY)
+        			return 0;
+          	}
+            
+        	return 1;
         }
 
         /// <summary>
-- 
cgit v1.1