Index: binaries/data/mods/public/simulation/components/Foundation.js
===================================================================
--- binaries/data/mods/public/simulation/components/Foundation.js	(revision 18569)
+++ binaries/data/mods/public/simulation/components/Foundation.js	(working copy)
@@ -251,11 +251,11 @@
 			}
 
 			var cmpFoundationPosition = Engine.QueryInterface(this.entity, IID_Position);
-			var pos = cmpFoundationPosition.GetPosition();
+			var pos = cmpFoundationPosition.GetPosition2D();
 			var rot = cmpFoundationPosition.GetRotation();
 			cmpPreviewPosition.SetYRotation(rot.y);
 			cmpPreviewPosition.SetXZRotation(rot.x, rot.z);
-			cmpPreviewPosition.JumpTo(pos.x, pos.z);
+			cmpPreviewPosition.JumpTo(pos.x, pos.y);
 		}
 
 		this.committed = true;
@@ -333,7 +333,7 @@
 		if (cmpTerritoryDecay && cmpTerritoryDecay.HasTerritoryOwnership())
 		{
 			let cmpTerritoryManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager);
-			owner = cmpTerritoryManager.GetOwner(pos.x, pos.z);
+			owner = cmpTerritoryManager.GetOwner(pos.x, pos.y);
 		}
 		else
 		{
Index: binaries/data/mods/public/simulation/components/tests/test_Foundation.js
===================================================================
--- binaries/data/mods/public/simulation/components/tests/test_Foundation.js	(revision 18569)
+++ binaries/data/mods/public/simulation/components/tests/test_Foundation.js	(working copy)
@@ -8,132 +8,179 @@
 Engine.LoadComponentScript("interfaces/Trigger.js");
 Engine.LoadComponentScript("Foundation.js");
 
-AddMock(SYSTEM_ENTITY, IID_Trigger, {
-	"CallEvent": () => {},
-});
-
 let player = 1;
 let playerEnt = 3;
+let foundationEnt = 20;
+let previewEnt = 21;
+let newEnt = 22;
 
-AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
-	"GetPlayerByID": () => playerEnt,
-});
+function testFoundation(...mocks)
+{
+	ResetState();
 
-AddMock(playerEnt, IID_StatisticsTracker, {
-	"IncreaseConstructedBuildingsCounter": ent => {
-		TS_ASSERT_EQUALS(ent, newEnt);
-	},
-});
+	AddMock(SYSTEM_ENTITY, IID_Trigger, {
+		"CallEvent": () => {},
+	});
 
-let foundationEnt = 20;
-let newEnt = 21;
-let finalTemplate = "structures/athen_civil_centre.xml";
-let foundationHP = 1;
-let maxHP = 100;
+	AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
+		"GetPlayerByID": () => playerEnt,
+	});
 
-AddMock(foundationEnt, IID_Cost, {
-	"GetBuildTime": () => 50,
-	"GetResourceCosts": () => ({ "wood": 100 }),
-});
+	AddMock(SYSTEM_ENTITY, IID_TerritoryManager, {
+		"GetOwner": (x, y) => {
+			TS_ASSERT_EQUALS(x, pos.x);
+			TS_ASSERT_EQUALS(y, pos.y);
+			return player;
+		},
+	});
 
-AddMock(foundationEnt, IID_Health, {
-	"GetHitpoints": () => foundationHP,
-	"GetMaxHitpoints": () => maxHP,
-	"Increase": hp => {
-		foundationHP = Math.min(foundationHP + hp, maxHP);
-		cmpFoundation.OnHealthChanged();
-	},
-});
+	Engine.RegisterGlobal("PlaySound", (name, source) => {
+		TS_ASSERT_EQUALS(name, "constructed");
+		TS_ASSERT_EQUALS(source, newEnt);
+	});
+	Engine.RegisterGlobal("MT_EntityRenamed", "entityRenamed");
 
-AddMock(foundationEnt, IID_Obstruction, {
-	"GetBlockMovementFlag": () => true,
-	"GetUnitCollisions": () => [],
-	"SetDisableBlockMovementPathfinding": () => {},
-});
+	let finalTemplate = "structures/athen_civil_centre.xml";
+	let foundationHP = 1;
+	let maxHP = 100;
+	let rot = new Vector3D(1, 2, 3);
+	let pos = new Vector2D(4, 5);
 
-AddMock(foundationEnt, IID_Ownership, {
-	"GetOwner": () => player,
-});
+	AddMock(foundationEnt, IID_Cost, {
+		"GetBuildTime": () => 50,
+		"GetResourceCosts": () => ({ "wood": 100 }),
+	});
 
-AddMock(foundationEnt, IID_Position, {
-	"GetPosition2D": () => new Vector2D(1, 2),
-	"GetRotation": () => new Vector3D(1, 2, 3),
-	"IsInWorld": () => true,
-});
+	AddMock(foundationEnt, IID_Health, {
+		"GetHitpoints": () => foundationHP,
+		"GetMaxHitpoints": () => maxHP,
+		"Increase": hp => {
+			foundationHP = Math.min(foundationHP + hp, maxHP);
+			cmpFoundation.OnHealthChanged();
+		},
+	});
 
-Engine.AddEntity = function(template)
-{
-	AddMock(newEnt, IID_Position, {
-		"JumpTo": (x, y) => { TS_ASSERT_EQUALS(x, 1); TS_ASSERT_EQUALS(y, 2); },
-		"SetYRotation": r => { TS_ASSERT_EQUALS(r, 2); },
+	AddMock(foundationEnt, IID_Obstruction, {
+		"GetBlockMovementFlag": () => true,
+		"GetUnitCollisions": () => [],
+		"SetDisableBlockMovementPathfinding": () => {},
+	});
+
+	AddMock(foundationEnt, IID_Ownership, {
+		"GetOwner": () => player,
+	});
+
+	AddMock(foundationEnt, IID_Position, {
+		"GetPosition2D": () => pos,
+		"GetRotation": () => rot,
+		"SetConstructionProgress": () => {},
+		"IsInWorld": () => true,
+	});
+
+	AddMock(previewEnt, IID_Ownership, {
+		"SetOwner": owner => { TS_ASSERT_EQUALS(owner, player); },
+	});
+
+	AddMock(previewEnt, IID_Position, {
+		"JumpTo": (x, y) => {
+			TS_ASSERT_EQUALS(x, pos.x);
+			TS_ASSERT_EQUALS(y, pos.y);
+		},
+		"SetConstructionProgress": p => {},
+		"SetYRotation": r => { TS_ASSERT_EQUALS(r, rot.y); },
 		"SetXZRotation": (rx, rz) => {
-			TS_ASSERT_EQUALS(rx, 1);
-			TS_ASSERT_EQUALS(rz, 3);
+			TS_ASSERT_EQUALS(rx, rot.x);
+			TS_ASSERT_EQUALS(rz, rot.z);
 		},
 	});
+
 	AddMock(newEnt, IID_Ownership, {
 		"SetOwner": owner => { TS_ASSERT_EQUALS(owner, player); },
 	});
-	return newEnt;
-};
 
-function PlaySound(name, source)
-{
-	TS_ASSERT_EQUALS(name, "constructed");
-	TS_ASSERT_EQUALS(source, newEnt);
-};
-Engine.RegisterGlobal("PlaySound", PlaySound);
-Engine.RegisterGlobal("MT_EntityRenamed", "entityRenamed");
+	AddMock(newEnt, IID_Position, {
+		"JumpTo": (x, y) => {
+			TS_ASSERT_EQUALS(x, pos.x);
+			TS_ASSERT_EQUALS(y, pos.y);
+		},
+		"SetYRotation": r => { TS_ASSERT_EQUALS(r, rot.y); },
+		"SetXZRotation": (rx, rz) => {
+			TS_ASSERT_EQUALS(rx, rot.x);
+			TS_ASSERT_EQUALS(rz, rot.z);
+		},
+	});
 
-let cmpFoundation = ConstructComponent(foundationEnt, "Foundation", {});
+	for (let mock of mocks)
+		AddMock(...mock);
 
-// INITIALISE
-cmpFoundation.InitialiseConstruction(player, finalTemplate);
+	// INITIALISE
+	Engine.AddEntity = function(template) {
+		TS_ASSERT_EQUALS(template, "construction|" + finalTemplate);
+		return previewEnt;
+	};
+	let cmpFoundation = ConstructComponent(foundationEnt, "Foundation", {});
+	cmpFoundation.InitialiseConstruction(player, finalTemplate);
 
-TS_ASSERT_EQUALS(cmpFoundation.owner, player);
-TS_ASSERT_EQUALS(cmpFoundation.finalTemplateName, finalTemplate);
-TS_ASSERT_EQUALS(cmpFoundation.maxProgress, 0);
-TS_ASSERT_EQUALS(cmpFoundation.initialised, true);
+	TS_ASSERT_EQUALS(cmpFoundation.owner, player);
+	TS_ASSERT_EQUALS(cmpFoundation.finalTemplateName, finalTemplate);
+	TS_ASSERT_EQUALS(cmpFoundation.maxProgress, 0);
+	TS_ASSERT_EQUALS(cmpFoundation.initialised, true);
 
-// BUILDER COUNT
-let twoBuilderMultiplier = Math.pow(2, cmpFoundation.buildTimePenalty) / 2;
-TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 0);
-cmpFoundation.AddBuilder(10);
-TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 1);
-TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, 1);
-cmpFoundation.AddBuilder(11);
-TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 2);
-TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, twoBuilderMultiplier);
-cmpFoundation.AddBuilder(11);
-TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 2);
-TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, twoBuilderMultiplier);
-cmpFoundation.RemoveBuilder(11);
-TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 1);
-TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, 1);
-cmpFoundation.RemoveBuilder(11);
-TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 1);
-TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, 1);
-// with cmpVisual
-AddMock(foundationEnt, IID_Visual, {
+	// BUILDER COUNT
+	let twoBuilderMultiplier = Math.pow(2, cmpFoundation.buildTimePenalty) / 2;
+	TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 0);
+	cmpFoundation.AddBuilder(10);
+	TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 1);
+	TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, 1);
+	cmpFoundation.AddBuilder(11);
+	TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 2);
+	TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, twoBuilderMultiplier);
+	cmpFoundation.AddBuilder(11);
+	TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 2);
+	TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, twoBuilderMultiplier);
+	cmpFoundation.RemoveBuilder(11);
+	TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 1);
+	TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, 1);
+	cmpFoundation.RemoveBuilder(11);
+	TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 1);
+	TS_ASSERT_EQUALS(cmpFoundation.buildMultiplier, 1);
+
+	// COMMIT FOUNDATION
+	TS_ASSERT_EQUALS(cmpFoundation.committed, false);
+	let work = 5;
+	cmpFoundation.Build(10, work);
+	TS_ASSERT_EQUALS(cmpFoundation.committed, true);
+	TS_ASSERT_EQUALS(foundationHP, 1 + work * cmpFoundation.GetBuildRate() * cmpFoundation.buildMultiplier);
+	TS_ASSERT_EQUALS(cmpFoundation.maxProgress, foundationHP / maxHP);
+
+	// FINISH CONSTRUCTION
+	Engine.AddEntity = function(template) {
+		TS_ASSERT_EQUALS(template, finalTemplate);
+		return newEnt;
+	};
+	cmpFoundation.Build(10, 1000);
+	TS_ASSERT_EQUALS(cmpFoundation.maxProgress, 1);
+	TS_ASSERT_EQUALS(foundationHP, maxHP);
+}
+
+testFoundation();
+
+testFoundation([foundationEnt, IID_Visual, {
 	"SetVariable": (key, num) => {
 		TS_ASSERT_EQUALS(key, "numbuilders");
-		TS_ASSERT_EQUALS(num, 2);
+		TS_ASSERT(num == 1 || num == 2);
 	},
-});
-cmpFoundation.AddBuilder(11);
-DeleteMock(foundationEnt, IID_Visual);
-cmpFoundation.RemoveBuilder(11);
+	"SelectAnimation": () => {},
+	"HasConstructionPreview": () => true,
+}]);
 
-// COMMIT FOUNDATION
-TS_ASSERT_EQUALS(cmpFoundation.committed, false);
-let work = 5;
-cmpFoundation.Build(10, work);
-TS_ASSERT_EQUALS(cmpFoundation.committed, true);
-TS_ASSERT_EQUALS(foundationHP, 1 + work * cmpFoundation.GetBuildRate() * cmpFoundation.buildMultiplier);
-TS_ASSERT_EQUALS(cmpFoundation.maxProgress, foundationHP / maxHP);
+testFoundation([newEnt, IID_TerritoryDecay, {
+	"HasTerritoryOwnership": () => true,
+}]);
 
-// FINISH CONSTRUCTION
-cmpFoundation.Build(10, 1000);
-TS_ASSERT_EQUALS(cmpFoundation.maxProgress, 1);
-TS_ASSERT_EQUALS(foundationHP, maxHP);
+testFoundation([playerEnt, IID_StatisticsTracker, {
+	"IncreaseConstructedBuildingsCounter": ent => {
+		TS_ASSERT_EQUALS(ent, newEnt);
+	},
+}]);
 

Property changes on: binaries/data/mods/public/simulation/components/tests/test_Foundation.js
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
