Index: binaries/data/mods/public/globalscripts/vector.js
===================================================================
--- binaries/data/mods/public/globalscripts/vector.js	(revision 0)
+++ binaries/data/mods/public/globalscripts/vector.js	(working copy)
@@ -0,0 +1,148 @@
+/////////////////////////////////////////////////////////////////////
+//	Vector2D
+//
+//	Class for representing and manipulating 2D vectors
+//
+/////////////////////////////////////////////////////////////////////
+
+// TODO: Type errors if v not instanceof Vector classes
+// TODO: Possibly implement in C++
+
+function Vector2D(x, y)
+{
+	if (arguments.length == 2)
+	{
+		this.set(x, y);
+	}
+	else
+	{
+		this.set(0, 0);
+	}
+}
+
+Vector2D.prototype.set = function(x, y)
+{
+	this.x = x;
+	this.y = y;
+};
+
+Vector2D.prototype.add = function(v)
+{
+	return new Vector2D(this.x + v.x, this.y + v.y);
+};
+
+Vector2D.prototype.sub = function(v)
+{
+	return new Vector2D(this.x - v.x, this.y - v.y);
+};
+
+Vector2D.prototype.mult = function(f)
+{
+	return new Vector2D(this.x * f, this.y * f);
+};
+
+Vector2D.prototype.div = function(f)
+{
+	return new Vector2D(this.x / f, this.y / f);
+};
+
+Vector2D.prototype.dot = function(v)
+{
+	return this.x * v.x + this.y * v.y;
+};
+
+Vector2D.prototype.lengthSquared = function()
+{
+	return this.dot(this);
+};
+
+Vector2D.prototype.length = function()
+{
+	return Math.sqrt(this.lengthSquared());
+};
+
+Vector2D.prototype.normalize = function()
+{
+	var mag = this.length();
+	if (!mag)
+		return;
+	
+	this.x /= mag;
+	this.y /= mag;
+};
+
+const Vector2Dprototype = Vector2D.prototype;
+
+/////////////////////////////////////////////////////////////////////
+//	Vector3D
+//
+//	Class for representing and manipulating 3D vectors
+//
+/////////////////////////////////////////////////////////////////////
+
+function Vector3D(x, y, z)
+{
+	if (arguments.length == 3)
+	{
+		this.set(x, y, y);
+	}
+	else
+	{
+		this.set(0, 0, 0);
+	}
+}
+
+Vector3D.prototype.set = function(x, y, z)
+{
+	this.x = x;
+	this.y = y;
+	this.z = z;
+};
+
+Vector3D.prototype.add = function(v)
+{
+	return new Vector3D(this.x + v.x, this.y + v.y, this.z + v.z);
+};
+
+Vector3D.prototype.sub = function(v)
+{
+	return new Vector3D(this.x - v.x, this.y - v.y, this.z - v.z);
+};
+
+Vector3D.prototype.mult = function(f)
+{
+	return new Vector3D(this.x * f, this.y * f, this.z * f);
+};
+
+Vector3D.prototype.div = function(f)
+{
+	return new Vector3D(this.x / f, this.y / f, this.z / f);
+};
+
+Vector3D.prototype.dot = function(v)
+{
+	return this.x * v.x + this.y * v.y + this.z * v.z;
+};
+
+Vector3D.prototype.lengthSquared = function()
+{
+	return this.dot(this);
+};
+
+Vector3D.prototype.length = function()
+{
+	return Math.sqrt(this.lengthSquared());
+};
+
+Vector3D.prototype.normalize = function()
+{
+	var mag = this.length();
+	if (!mag)
+		return;
+	
+	this.x /= mag;
+	this.y /= mag;
+	this.z /= mag;
+};
+
+const Vector3Dprototype = Vector3D.prototype;
Index: binaries/data/mods/public/maps/random/rmgen/vector.js
===================================================================
--- binaries/data/mods/public/maps/random/rmgen/vector.js	(revision 14624)
+++ binaries/data/mods/public/maps/random/rmgen/vector.js	(working copy)
@@ -1,141 +0,0 @@
-/////////////////////////////////////////////////////////////////////
-//	Vector2D
-//
-//	Class for representing and manipulating 2D vectors
-//
-/////////////////////////////////////////////////////////////////////
-
-// TODO: Type errors if v not instanceof Vector classes
-// TODO: Possibly implement in C++
-
-function Vector2D(x, y)
-{
-	if (arguments.length == 2)
-	{
-		this.set(x, y);
-	}
-	else
-	{
-		this.set(0, 0);
-	}
-}
-
-Vector2D.prototype.set = function(x, y)
-{
-	this.x = x;
-	this.y = y;
-};
-
-Vector2D.prototype.add = function(v)
-{
-	return new Vector2D(this.x + v.x, this.y + v.y);
-};
-
-Vector2D.prototype.sub = function(v)
-{
-	return new Vector2D(this.x - v.x, this.y - v.y);
-};
-
-Vector2D.prototype.mult = function(f)
-{
-	return new Vector2D(this.x * f, this.y * f);
-};
-
-Vector2D.prototype.div = function(f)
-{
-	return new Vector2D(this.x / f, this.y / f);
-};
-
-Vector2D.prototype.dot = function(v)
-{
-	return this.x * v.x + this.y * v.y;
-};
-
-Vector2D.prototype.lengthSquared = function()
-{
-	return this.dot(this);
-};
-
-Vector2D.prototype.length = function()
-{
-	return sqrt(this.lengthSquared());
-};
-
-Vector2D.prototype.normalize = function()
-{
-	var mag = this.length();
-	
-	this.x /= mag;
-	this.y /= mag;
-};
-
-/////////////////////////////////////////////////////////////////////
-//	Vector3D
-//
-//	Class for representing and manipulating 3D vectors
-//
-/////////////////////////////////////////////////////////////////////
-
-function Vector3D(x, y, z)
-{
-	if (arguments.length == 3)
-	{
-		this.set(x, y, y);
-	}
-	else
-	{
-		this.set(0, 0, 0);
-	}
-}
-
-Vector3D.prototype.set = function(x, y, z)
-{
-	this.x = x;
-	this.y = y;
-	this.z = z;
-};
-
-Vector3D.prototype.add = function(v)
-{
-	return new Vector3D(this.x + v.x, this.y + v.y, this.z + v.z);
-};
-
-Vector3D.prototype.sub = function(v)
-{
-	return new Vector3D(this.x - v.x, this.y - v.y, this.z - v.z);
-};
-
-Vector3D.prototype.mult = function(f)
-{
-	return new Vector3D(this.x * f, this.y * f, this.z * f);
-};
-
-Vector3D.prototype.div = function(f)
-{
-	return new Vector3D(this.x / f, this.y / f, this.z / f);
-};
-
-Vector3D.prototype.dot = function(v)
-{
-	return this.x * v.x + this.y * v.y + this.z * v.z;
-};
-
-Vector3D.prototype.lengthSquared = function()
-{
-	return this.dot(this);
-};
-
-Vector3D.prototype.length = function()
-{
-	return sqrt(this.lengthSquared());
-};
-
-Vector3D.prototype.normalize = function()
-{
-	var mag = this.length();
-	
-	this.x /= mag;
-	this.y /= mag;
-	this.z /= mag;
-};
-
Index: binaries/data/mods/public/simulation/components/Player.js
===================================================================
--- binaries/data/mods/public/simulation/components/Player.js	(revision 14624)
+++ binaries/data/mods/public/simulation/components/Player.js	(working copy)
@@ -664,4 +664,31 @@
 		cmpGUIInterface.PushNotification(notification);
 };
 
+Player.prototype.OnUpdate = function(msg)
+{
+	var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
+	var ents = cmpRangeManager.GetEntitiesByPlayer(this.GetPlayerID());
+	var positions = [];
+	for each (var ent in ents)
+		positions.push(Engine.QueryInterface(ent, IID_Position));
+
+	var pos2d;
+	var pos3d;
+	var sum2d = 0;
+	var sum3d = 0;
+	var oTime = +(new Date());
+	for (var i = 0; i < 40; i++)
+	{
+		for each (var cmpPosition in positions)
+		{
+			pos2d = cmpPosition.GetPosition2D();
+			sum2d += pos2d.x + pos2d.y;
+			pos3d = cmpPosition.GetPosition();
+			sum3d += pos3d.x + pos3d.y + pos3d.z;
+		}
+	}
+	var nTime = +(new Date());
+	warn("time:" + (nTime - oTime) + ", numbers: " + sum2d + " " + sum3d);
+};
+
 Engine.RegisterComponentType(IID_Player, "Player", Player);
Index: source/scriptinterface/ScriptInterface.cpp
===================================================================
--- source/scriptinterface/ScriptInterface.cpp	(revision 14624)
+++ source/scriptinterface/ScriptInterface.cpp	(working copy)
@@ -627,7 +627,11 @@
 			return false;
 		}
 	}
-
+	jsval proto;
+	if (JS_GetProperty(m->m_cx, JS_GetGlobalObject(m->m_cx), "Vector2Dprototype", &proto))
+		vector2Dprototype = CScriptValRooted(m->m_cx, proto);
+	if (JS_GetProperty(m->m_cx, JS_GetGlobalObject(m->m_cx), "Vector3Dprototype", &proto))
+		vector3Dprototype = CScriptValRooted(m->m_cx, proto);
 	return true;
 }
 
@@ -1033,7 +1037,6 @@
 	return ok ? true : false;
 }
 
-
 bool ScriptInterface::Eval(const char* code)
 {
 	jsval rval;
Index: source/scriptinterface/ScriptInterface.h
===================================================================
--- source/scriptinterface/ScriptInterface.h	(revision 14624)
+++ source/scriptinterface/ScriptInterface.h	(working copy)
@@ -91,6 +91,9 @@
 	 */
 	static shared_ptr<ScriptRuntime> CreateRuntime(int runtimeSize = DEFAULT_RUNTIME_SIZE);
 
+	CScriptValRooted vector2Dprototype;
+	CScriptValRooted vector3Dprototype;
+
 	/**
 	 * Constructor.
 	 * @param nativeScopeName Name of global object that functions (via RegisterFunction) will
Index: source/simulation2/scripting/EngineScriptConversions.cpp
===================================================================
--- source/simulation2/scripting/EngineScriptConversions.cpp	(revision 14624)
+++ source/simulation2/scripting/EngineScriptConversions.cpp	(working copy)
@@ -163,7 +163,10 @@
 
 template<> jsval ScriptInterface::ToJSVal<CFixedVector3D>(JSContext* cx, const CFixedVector3D& val)
 {
-	JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
+	// apply the Vector3D prototype to the return value;
+ 	ScriptInterface::CxPrivate* pCxPrivate = ScriptInterface::GetScriptInterfaceAndCBData(cx);
+	JSObject* obj = JS_NewObject(cx, NULL, JSVAL_TO_OBJECT(pCxPrivate->pScriptInterface->vector3Dprototype.get()), NULL);
+
 	if (!obj)
 		return JSVAL_VOID;
 
@@ -197,7 +200,10 @@
 
 template<> jsval ScriptInterface::ToJSVal<CFixedVector2D>(JSContext* cx, const CFixedVector2D& val)
 {
-	JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
+	// apply the Vector2D prototype to the return value
+ 	ScriptInterface::CxPrivate* pCxPrivate = ScriptInterface::GetScriptInterfaceAndCBData(cx);
+	JSObject* obj = JS_NewObject(cx, NULL, JSVAL_TO_OBJECT(pCxPrivate->pScriptInterface->vector2Dprototype.get()), NULL);
+
 	if (!obj)
 		return JSVAL_VOID;
 
