Index: binaries/data/mods/public/gui/page_summary.xml
===================================================================
--- binaries/data/mods/public/gui/page_summary.xml	(revision 0)
+++ binaries/data/mods/public/gui/page_summary.xml	(revision 0)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<page>
+	<include>common/setup.xml</include>
+    <include>common/styles.xml</include>
+    <include>common/sprite1.xml</include>
+    <include>common/init.xml</include>
+	<include>summary/summary.xml</include>
+	<include>common/global.xml</include>
+</page>
Index: binaries/data/mods/public/gui/session_new/session.js
===================================================================
--- binaries/data/mods/public/gui/session_new/session.js	(revision 8086)
+++ binaries/data/mods/public/gui/session_new/session.js	(working copy)
@@ -86,6 +86,8 @@
 
 function onTick()
 {
+	checkPlayerState();
+
 	while (true)
 	{
 		var message = Engine.PollNetworkClient();
@@ -119,6 +121,28 @@
 		getGUIObjectByName("resourcePop").textcolor = "0 0 0";
 }
 
+function gotoSummary(/*string*/ gameResult)
+{
+	stopMusic();
+	endGame();
+	Engine.SwitchGuiPage("page_summary.xml", { "gameResult" : gameResult });
+}
+
+function checkPlayerState()
+{
+	var simState = Engine.GuiInterfaceCall("GetSimulationState");
+	var playerState = simState.players[Engine.GetPlayerID()];
+	
+	if (playerState.state == simState.player_states.DEFEATED)
+	{
+		gotoSummary("You have been defeated...");
+	}
+	else if (playerState.state == simState.player_states.WON)
+	{
+		gotoSummary("You have won a battle!");
+	}
+}
+
 function onSimulationUpdate()
 {
 	g_Selection.dirty = false;
Index: binaries/data/mods/public/gui/summary/summary.js
===================================================================
--- binaries/data/mods/public/gui/summary/summary.js	(revision 0)
+++ binaries/data/mods/public/gui/summary/summary.js	(revision 0)
@@ -0,0 +1,5 @@
+function init(data)
+{
+	getGUIObjectByName ("summaryTitleBar").caption = "Summary";
+	getGUIObjectByName ("summaryText").caption = data.gameResult;
+}
Index: binaries/data/mods/public/gui/summary/summary.xml
===================================================================
--- binaries/data/mods/public/gui/summary/summary.xml	(revision 0)
+++ binaries/data/mods/public/gui/summary/summary.xml	(revision 0)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+==========================================
+- SUMMARY SCREEN -
+==========================================
+-->
+
+<objects>
+	<script file="gui/summary/summary.js"/>
+	<object name="summary" 
+			type="image"
+			sprite="bkFillBlack"
+		>
+		<!--
+		==========================================
+		- SUMMARY SCREEN - WINDOW
+		==========================================
+		-->
+
+		<object name="summaryWindow"
+			style="wheatWindowGranite"
+			type="image"
+			size="25 35 100%-25 100%-25"
+		>
+			<object	name="summaryTitleBar"
+				style="wheatWindowTitleBar"
+				type="button"
+			/>
+			
+			<object name="summaryText"
+				type="text"
+				size="50 50 100%-50 100%-200"
+				font="serif-16"
+				text_align="center"
+				text_valign="center"
+			/>
+			
+			<object type="button" style="wheatButton" size="100%-150 100%-40 100% 100%">
+				Main menu
+				<action on="Press"><![CDATA[
+					Engine.SwitchGuiPage("page_pregame.xml");
+				]]></action>
+			</object>
+		</object>
+	</object>
+</objects>
Index: binaries/data/mods/public/simulation/components/EndGameManager.js
===================================================================
--- binaries/data/mods/public/simulation/components/EndGameManager.js	(revision 0)
+++ binaries/data/mods/public/simulation/components/EndGameManager.js	(revision 0)
@@ -0,0 +1,88 @@
+// Interval, which defines how often game will check end game conditions
+var g_ProgressInterval = 1000;
+
+/* 
+	EndGameManager is the system component, which regularly (by timer) checks 
+	victory/defeat conditions and if it is satisfied ends the game
+*/
+function EndGameManager() {}
+
+EndGameManager.prototype.Schema =
+	"<a:component type='system'/><empty/>";
+
+// static member - gameTypes enum
+EndGameManager.GameTypes = { CONQUEST : 0 };
+	
+EndGameManager.prototype.Init = function()
+{
+	print("EndGameManager init");
+	// only CONQUEST mode for now
+	this.gameType = EndGameManager.GameTypes.CONQUEST;
+	
+	// start the timer
+	var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
+	this.timer = cmpTimer.SetTimeout(this.entity, IID_EndGameManager, "ProgressTimeout", g_ProgressInterval, {});	
+};
+
+EndGameManager.prototype.OnDestroy = function()
+{
+	if (this.timer)
+	{
+		var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
+		cmpTimer.CancelTimer(this.timer);
+	}
+};
+
+EndGameManager.prototype.ProgressTimeout = function(data)
+{
+	this.UpdatePlayerStates();
+	
+	// repeat the timer
+	var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
+	this.timer = cmpTimer.SetTimeout(this.entity, IID_EndGameManager, "ProgressTimeout", g_ProgressInterval, data);
+}
+
+EndGameManager.prototype.UpdatePlayerStates = function()
+{
+	var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
+	switch (this.gameType)
+	{
+		case EndGameManager.GameTypes.CONQUEST:
+			for (var i = 0; i < cmpPlayerManager.GetNumPlayers(); i++)
+			{
+				var playerEntityId = cmpPlayerManager.GetPlayerByID(i);
+				var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player);
+				if (cmpPlayer.state == cmpPlayer.GameStates.ACTIVE)
+				{
+					if (cmpPlayer.GetPopulationCount() == 0 && cmpPlayer.structuresCount == 0)
+					{
+						cmpPlayer.state = cmpPlayer.GameStates.DEFEATED;
+					}
+				}
+			}
+			// TODO: update this code for allies
+			var alivePlayersCount = 0;
+			var lastAlivePlayerId = -1;
+			for (var i = 0; i < cmpPlayerManager.GetNumPlayers(); i++)
+			{
+				var playerEntityId = cmpPlayerManager.GetPlayerByID(i);
+				var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player);
+				if (cmpPlayer.state == cmpPlayer.GameStates.ACTIVE)
+				{
+					alivePlayersCount++;
+					lastAlivePlayerId = i;
+				}
+			}
+			if (alivePlayersCount == 1)
+			{
+				var playerEntityId = cmpPlayerManager.GetPlayerByID(lastAlivePlayerId);
+				var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player);
+				cmpPlayer.state = cmpPlayer.GameStates.WON;
+			}
+			break;
+		default:
+			// strange game type ...
+	}
+}
+
+Engine.RegisterComponentType(IID_EndGameManager, "EndGameManager", EndGameManager);
Index: binaries/data/mods/public/simulation/components/GuiInterface.js
===================================================================
--- binaries/data/mods/public/simulation/components/GuiInterface.js	(revision 8086)
+++ binaries/data/mods/public/simulation/components/GuiInterface.js	(working copy)
@@ -20,7 +20,8 @@
 GuiInterface.prototype.GetSimulationState = function(player)
 {
 	var ret = {
-		"players": []
+		"players": [],
+		"player_states": undefined
 	};
 
 	var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
@@ -36,9 +37,11 @@
 			"popCount": cmpPlayer.GetPopulationCount(),
 			"popLimit": cmpPlayer.GetPopulationLimit(),
 			"resourceCounts": cmpPlayer.GetResourceCounts(),
-			"trainingQueueBlocked": cmpPlayer.IsTrainingQueueBlocked()
+			"trainingQueueBlocked": cmpPlayer.IsTrainingQueueBlocked(),
+			"state": cmpPlayer.GetState()
 		};
 		ret.players.push(playerData);
+		ret.player_states = cmpPlayer.GameStates;
 	}
 
 	return ret;
Index: binaries/data/mods/public/simulation/components/Identity.js
===================================================================
--- binaries/data/mods/public/simulation/components/Identity.js	(revision 8086)
+++ binaries/data/mods/public/simulation/components/Identity.js	(working copy)
@@ -62,6 +62,7 @@
 						"<value>Mechanical</value>" +
 						"<value>Super</value>" +
 						"<value>Hero</value>" +
+						"<value>Structure</value>" +
 						"<value>Civic</value>" +
 						"<value>Economic</value>" +
 						"<value>Defensive</value>" +
Index: binaries/data/mods/public/simulation/components/interfaces/EndGameManager.js
===================================================================
--- binaries/data/mods/public/simulation/components/interfaces/EndGameManager.js	(revision 0)
+++ binaries/data/mods/public/simulation/components/interfaces/EndGameManager.js	(revision 0)
@@ -0,0 +1 @@
+Engine.RegisterInterface("EndGameManager");
Index: binaries/data/mods/public/simulation/components/Player.js
===================================================================
--- binaries/data/mods/public/simulation/components/Player.js	(revision 8086)
+++ binaries/data/mods/public/simulation/components/Player.js	(working copy)
@@ -19,8 +19,15 @@
 		"metal": 500,	
 		"stone": 1000	
 	};
+	// player game state
+	this.state = this.GameStates.ACTIVE;
+	// buildings count
+	this.structuresCount = 0;
 };
 
+// static enum: player game state
+Player.prototype.GameStates = { ACTIVE : 0, DEFEATED : 1, WON : 2 };
+
 Player.prototype.SetPlayerID = function(id)
 {
 	this.playerID = id;
@@ -146,12 +153,25 @@
 	return true;
 };
 
+Player.prototype.GetState = function()
+{
+	return this.state;
+};
+
 // Keep track of population effects of all entities that
 // become owned or unowned by this player
 Player.prototype.OnGlobalOwnershipChanged = function(msg)
 {
+	var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity);
+	// Is this entity a structure?
+	var isStructure = (cmpIdentity && cmpIdentity.GetClassesList().indexOf("Structure") != -1);
+
 	if (msg.from == this.playerID)
 	{
+		if (isStructure) 
+		{
+			this.structuresCount--;
+		}
 		var cost = Engine.QueryInterface(msg.entity, IID_Cost);
 		if (cost)
 		{
@@ -162,6 +182,10 @@
 	
 	if (msg.to == this.playerID)
 	{
+		if (isStructure) 
+		{
+			this.structuresCount++;
+		}
 		var cost = Engine.QueryInterface(msg.entity, IID_Cost);
 		if (cost)
 		{
Index: binaries/data/mods/public/simulation/templates/template_structure.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_structure.xml	(revision 8086)
+++ binaries/data/mods/public/simulation/templates/template_structure.xml	(working copy)
@@ -2,6 +2,7 @@
 <Entity parent="template_entity_full">
   <Identity>
     <GenericName>Structure</GenericName>
+	<Classes datatype="tokens">Structure</Classes>
 	<IconSheet>snPortraitSheetBuildings</IconSheet>
   </Identity>
   <BuildRestrictions>
Index: source/simulation2/Simulation2.cpp
===================================================================
--- source/simulation2/Simulation2.cpp	(revision 8086)
+++ source/simulation2/Simulation2.cpp	(working copy)
@@ -112,6 +112,7 @@
 			LOAD_SCRIPTED_COMPONENT("GuiInterface");
 			LOAD_SCRIPTED_COMPONENT("PlayerManager");
 			LOAD_SCRIPTED_COMPONENT("Timer");
+			LOAD_SCRIPTED_COMPONENT("EndGameManager");
 
 #undef LOAD_SCRIPTED_COMPONENT
 		}
