CODE

//

// LandownerBorderDetector

// Version 20070217-1

// Copyright (c) 2007 by Second Life resident Badpenguin Posthorn

//

// Plop this script in an object and touch the object to display border

// lines and boundary coordinates of contiguous land owned by the same

// landowner. Works by detecting changes in land ownership and is

// accurate up to 0.5 meters. Note that it will only detect boundaries

// on the direct X and Y coordinates from where the scripted object

// resides, so only expect useful results when the boundaries of the

// measured parcel(s) are straight lines. Works on group deeded land

// also.

//

//

// LICENSE:

// This program is free software; you can redistribute it and/or

// modify it under the terms of the GNU General Public License

// as published by the Free Software Foundation; either version 2

// of the License, or (at your option) any later version.

//

// This program is distributed in the hope that it will be useful,

// but WITHOUT ANY WARRANTY; without even the implied warranty of

// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

// GNU General Public License for more details.

//

// You should have received a copy of the GNU General Public License

// along with this program; if not, write to the:

// Free Software Foundation, Inc.

// 59 Temple Place Suite 330

// Boston, MA 02111-1307, USA.

// (Also available at http://www.gnu.org/copyleft/gpl.html)

//

//

// Global variables, feel free to customize

//

float gJumpAmount = 0.5;

// *************************************************

// Find a land border by searching out from a

// specific coordinate for a change in land ownership.

// *************************************************

vector findBorder(string axis, vector start_vec, float jump_amount) {

float x = 0;

float y = 0;

float z = 0;

float num = 0;

vector newVec = ZERO_VECTOR;

vector lastVec = ZERO_VECTOR;

key owner1 = NULL_KEY;

key owner2 = NULL_KEY;

//

// Validate axis

//

if ((axis != "x") && (axis != "y")) {

// llSay(0,"Invalid axis passed to findBorder()");

return ZERO_VECTOR;

}

//

// Validate jump_amount

//

if ((integer)jump_amount >= 255) {

// llSay(0,"Invalid jump amount");

return ZERO_VECTOR;

}

//

// Validate start_vec

//

x = getVectorAxis(0,start_vec);

y = getVectorAxis(1,start_vec);

z = getVectorAxis(2,start_vec);

if (x <= 0 || y <= 0 || z <= 0) {

// llSay(0,"Invalid vector passed to findBorder()");

return ZERO_VECTOR;

}

if (x >= 255 || y >= 255 || z >= 255) {

// llSay(0,"Invalid vector passed to findBorder()");

return ZERO_VECTOR;

}

//

// Are we too close to a sim border?

//

if (axis == "x") {

if ((x + jump_amount >= 255) ||(x + jump_amount <= 0)) {

return ZERO_VECTOR;

}

} else {

if ((y + jump_amount >= 255) ||(y + jump_amount <= 0)) {

return ZERO_VECTOR;

}

}

//

// Get owner of land at start vector

//

owner1 = llGetLandOwnerAt(start_vec);

if (owner1 == NULL_KEY) {

// llSay(0,"Could not determine land owner at the location");

return ZERO_VECTOR;

}

//

// Assign initial values

//

lastVec = start_vec;

if (axis == "x") {

num = x;

} else {

num = y;

}

//

// Loop through until we find a different landowner

//

while ((num >= 0) && (num <= 255)) {

if (axis == "x") {

newVec = <num, y, z> + <jump_amount, 0, 0>;

} else {

newVec = <x, num, z> + <0, jump_amount, 0>;

}

owner2 = llGetLandOwnerAt(newVec);

if ((owner2 == NULL_KEY) || (owner1 != owner2)) {

return lastVec;

}

num += jump_amount;

if ((num <= 0) || (num >= 255)) {

return lastVec;

}

lastVec = newVec;

}

return ZERO_VECTOR;

}

// *************************************************

// Return a particular axis from a vector

// *************************************************

float getVectorAxis(integer axis, vector vec) {

if ((axis < 0) || (axis > 2)) {

return -1;

}

list junk = llParseString2List((string)vec,[",","<",">"], []);

if (llGetListLength(junk) != 3) {

return -1;

}

return llList2Float(junk,axis);

}

//

// default state starts here

//

default {

state_entry() {

llSay(0,"Touch the object to determine borders");

}

touch_start(integer num_detected) {

// Uncomment to disallow anyone but the owner to use it

//if (llDetectedKey(0) != llGetOwner()) {

// return;

// }

vector BOUND_EAST = ZERO_VECTOR;

vector BOUND_NORTH = ZERO_VECTOR;

vector BOUND_SOUTH = ZERO_VECTOR;

vector BOUND_WEST = ZERO_VECTOR;

string msg;

vector HOME_POS = llGetPos();

//

// Determine the northern boundary

//

BOUND_NORTH = findBorder("y",HOME_POS,gJumpAmount);

if (BOUND_NORTH == ZERO_VECTOR) {

llSay(0,"Failed to locate northern boundary");

llResetScript();

}

//

// Determine the southern boundary

//

BOUND_SOUTH = findBorder("y",HOME_POS,-gJumpAmount);

if (BOUND_SOUTH == ZERO_VECTOR) {

llSay(0,"Failed to locate southern boundary");

llResetScript();

}

//

// Determine the eastern boundary

//

BOUND_EAST = findBorder("x",HOME_POS,gJumpAmount);

if (BOUND_EAST == ZERO_VECTOR) {

llSay(0,"Failed to locate eastern boundary");

llResetScript();

}

//

// Determine the western boundary

//

BOUND_WEST = findBorder("x",HOME_POS,-gJumpAmount);

if (BOUND_WEST == ZERO_VECTOR) {

llSay(0,"Failed to locate western boundary");

llResetScript();

}

//

// Format some results for displaying

//

float borderNorth = getVectorAxis(1,BOUND_NORTH);

float borderSouth = getVectorAxis(1,BOUND_SOUTH);

float borderEast = getVectorAxis(0,BOUND_EAST);

float borderWest = getVectorAxis(0,BOUND_WEST);

float zCoord = getVectorAxis(2,HOME_POS);

vector vectorNW = <borderNorth, borderWest, zCoord>;

vector vectorNE = <borderNorth, borderEast, zCoord>;

vector vectorSE = <borderSouth, borderEast, zCoord>;

vector vectorSW = <borderSouth, borderWest, zCoord>;

//

// Display the results

//

llSay(0,"");

llSay(0,"Northern Boundary Detected: " + (string)BOUND_NORTH);

llSay(0,"Southern Boundary Detected: " + (string)BOUND_SOUTH);

llSay(0,"Eastern Boudary Detected: " + (string)BOUND_EAST);

llSay(0,"Western Boundary Detected: " + (string)BOUND_WEST);

llSay(0,"");

llSay(0,"Northern Border Line: " + (string)borderNorth);

llSay(0,"Southern Border Line: " + (string)borderSouth);

llSay(0,"Eastern Border Line: " + (string)borderEast);

llSay(0,"Western Border Line: " + (string)borderWest);

llSay(0,"");

llSay(0,"Northwest Coords: " + (string)vectorNW);

llSay(0,"Northeast Coords: " + (string)vectorNE);

llSay(0,"Southeast Coords: " + (string)vectorSE);

llSay(0,"Southwest Coords: " + (string)vectorSW);

}

on_rez(integer num) {

llResetScript();

}

}