Index: binaries/data/mods/public/simulation/components/Health.js
===================================================================
--- binaries/data/mods/public/simulation/components/Health.js	(revision 13646)
+++ binaries/data/mods/public/simulation/components/Health.js	(working copy)
@@ -20,8 +20,8 @@
 			"<text/>" +
 		"</element>" +
 	"</optional>" +
-	"<element name='RegenRate' a:help='Hitpoint regeneration rate per second. Not yet implemented'>" +
-		"<ref name='nonNegativeDecimal'/>" +
+	"<element name='RegenRate' a:help='Hitpoint regeneration rate per second.'>" +
+		"<data type='decimal'/>" +
 	"</element>" +
 	"<element name='DeathType' a:help='Behaviour when the unit dies'>" +
 		"<choice>" +
@@ -44,6 +44,7 @@
 	// Default to <Initial>, but use <Max> if it's undefined or zero
 	// (Allowing 0 initial HP would break our death detection code)
 	this.hitpoints = +(this.template.Initial || this.GetMaxHitpoints());
+	this.regenRate = +this.template.RegenRate;
 };
 
 //// Interface functions ////
@@ -95,6 +96,48 @@
 		|| this.GetHitpoints() >= this.GetMaxHitpoints());
 };
 
+Health.prototype.GetRegenRate = function()
+{
+	return this.regenRate;
+};
+
+Health.prototype.ExecuteRegeneration = function()
+{
+	var regen = this.GetRegenRate();
+	if (regen > 0)
+		this.Increase(regen);
+	else 
+		this.Reduce(-regen);
+};
+
+/*
+ * Check if the regeneration timer needs to be started or stopped
+ */
+Health.prototype.CheckRegenTimer = function()
+{
+	// check if we need a timer
+	if (this.GetRegenRate() == 0 ||
+		this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() > 0 ||
+		this.GetHitpoints() == 0)
+	{
+		// we don't need a timer, disable if one exists
+		if (this.regenTimer)
+		{
+			var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
+			cmpTimer.CancelTimer(this.regenTimer);
+			this.regenTimer = undefined;
+		}
+		return;
+	}
+
+	// we need a timer, enable is one doesn't exist
+	if (this.regenTimer)
+		return;
+
+	var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
+	this.regenTimer = cmpTimer.SetInterval(this.entity, IID_Health, "ExecuteRegeneration", 1000, 1000, null);
+};
+
 Health.prototype.Kill = function()
 {
 	this.Reduce(this.hitpoints);
@@ -164,6 +207,11 @@
 
 Health.prototype.Increase = function(amount)
 {
+	if (this.hitpoints == this.GetMaxHitpoints())
+	{
+		return {"old": this.hitpoints, "new":this.hitpoints};
+	}
+
 	// If we're already dead, don't allow resurrection
 	if (this.hitpoints == 0)
 		return undefined;
@@ -284,19 +332,26 @@
 {
 	if (msg.component == "Health")
 	{
-		var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager);
-		if (cmpTechnologyManager)
+		var oldMaxHitpoints = this.GetMaxHitpoints();
+		var newMaxHitpoints = Math.round(ApplyTechModificationsToEntity("Health/Max", +this.template.Max, this.entity));
+		if (oldMaxHitpoints != newMaxHitpoints)
 		{
-			var oldMaxHitpoints = this.GetMaxHitpoints();
-			var newMaxHitpoints = Math.round(ApplyTechModificationsToEntity("Health/Max", +this.template.Max, this.entity));
-			if (oldMaxHitpoints != newMaxHitpoints)
-			{
-				var newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
-				this.maxHitpoints = newMaxHitpoints;
-				this.SetHitpoints(newHitpoints);
-			}
+			var newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
+			this.maxHitpoints = newMaxHitpoints;
+			this.SetHitpoints(newHitpoints);
 		}
+
+		var oldRegenRate = this.regenRate;
+		this.regenRate = ApplyTechModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity);
+		
+		if (this.regenRate != oldRegenRate)
+			this.CheckRegenTimer();
 	}
 };
 
+Health.prototype.OnHealthChanged = function()
+{
+	this.CheckRegenTimer();
+};
+
 Engine.RegisterComponentType(IID_Health, "Health", Health);
Index: binaries/data/mods/public/simulation/templates/gaia/fauna_elephant.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/fauna_elephant.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/gaia/fauna_elephant.xml	(working copy)
@@ -6,7 +6,6 @@
   </Footprint>
   <Health>
     <Max>200</Max>
-    <RegenRate>1</RegenRate>
   </Health>
   <Identity>
     <Civ>gaia</Civ>
Index: binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_african_bush.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_african_bush.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_african_bush.xml	(working copy)
@@ -39,7 +39,6 @@
   </Footprint>
   <Health>
     <Max>300</Max>
-    <RegenRate>1</RegenRate>
   </Health>
   <Identity>
     <Civ>gaia</Civ>
Index: binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_asian.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_asian.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_asian.xml	(working copy)
@@ -39,7 +39,6 @@
   </Footprint>
   <Health>
     <Max>250</Max>
-    <RegenRate>1</RegenRate>
   </Health>
   <Identity>
     <Civ>gaia</Civ>
Index: binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_north_african.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_north_african.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_north_african.xml	(working copy)
@@ -26,7 +26,6 @@
   </Footprint>
   <Health>
     <Max>200</Max>
-    <RegenRate>1</RegenRate>
   </Health>
   <Identity>
     <Civ>gaia</Civ>
Index: binaries/data/mods/public/simulation/templates/gaia/fauna_giraffe.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/fauna_giraffe.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/gaia/fauna_giraffe.xml	(working copy)
@@ -6,7 +6,6 @@
   </Footprint>
   <Health>
     <Max>150</Max>
-    <RegenRate>1</RegenRate>
   </Health>
   <Identity>
     <Civ>gaia</Civ>
Index: binaries/data/mods/public/simulation/templates/template_unit_cavalry.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_cavalry.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_cavalry.xml	(working copy)
@@ -26,7 +26,6 @@
   </Footprint>
   <Health>
     <Max>130</Max>
-    <RegenRate>0.2</RegenRate>
   </Health>
   <Identity>
     <Classes datatype="tokens">Cavalry CitizenSoldier Organic</Classes>
Index: binaries/data/mods/public/simulation/templates/template_unit_champion.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_champion.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_champion.xml	(working copy)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Entity parent="template_unit">
   <Health>
-    <RegenRate>0.4</RegenRate>
+    <RegenRate>0.1</RegenRate>
   </Health>
   <Identity>
     <GenericName>Champion Unit</GenericName>
Index: binaries/data/mods/public/simulation/templates/template_unit_fauna_hunt_whale.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_fauna_hunt_whale.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_fauna_hunt_whale.xml	(working copy)
@@ -3,7 +3,6 @@
   <Health>
     <Max>100</Max>
     <DeathType>remain</DeathType>
-    <RegenRate>1</RegenRate>
     <Unhealable>true</Unhealable>
     <Repairable>false</Repairable>
   </Health>
Index: binaries/data/mods/public/simulation/templates/template_unit_hero.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_hero.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_hero.xml	(working copy)
@@ -31,7 +31,7 @@
   </Cost>
   <Health>
     <Max>600</Max>
-    <RegenRate>0.5</RegenRate>
+    <RegenRate>0.2</RegenRate>
   </Health>
   <Identity>
     <GenericName>Hero</GenericName>
Index: binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry.xml	(working copy)
@@ -35,7 +35,6 @@
   </Footprint>
   <Health>
     <Max>800</Max>
-    <RegenRate>0.5</RegenRate>
   </Health>
   <Identity>
     <GenericName>Hero Cavalry</GenericName>
Index: binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_archer.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_archer.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_archer.xml	(working copy)
@@ -42,7 +42,6 @@
   </Footprint>
   <Health>
     <Max>800</Max>
-    <RegenRate>0.5</RegenRate>
   </Health>
   <Identity>
     <Classes datatype="tokens">Hero Bow -Javelin</Classes>
Index: binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_javelinist.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_javelinist.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_javelinist.xml	(working copy)
@@ -34,7 +34,6 @@
   </Footprint>
   <Health>
     <Max>800</Max>
-    <RegenRate>0.5</RegenRate>
   </Health>
   <Identity>
     <Classes datatype="tokens">Hero</Classes>
Index: binaries/data/mods/public/simulation/templates/template_unit_hero_infantry.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_hero_infantry.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_hero_infantry.xml	(working copy)
@@ -33,7 +33,6 @@
   </Footprint>
   <Health>
     <Max>600</Max>
-    <RegenRate>0.5</RegenRate>
   </Health>
   <Identity>
     <Classes datatype="tokens">Hero Infantry</Classes>
Index: binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_archer.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_archer.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_archer.xml	(working copy)
@@ -34,7 +34,6 @@
   </Footprint>
   <Health>
     <Max>600</Max>
-    <RegenRate>0.5</RegenRate>
   </Health>
   <Identity>
     <GenericName>Hero Archer</GenericName>
Index: binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_javelinist.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_javelinist.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_javelinist.xml	(working copy)
@@ -40,7 +40,6 @@
   </Footprint>
   <Health>
     <Max>600</Max>
-    <RegenRate>0.5</RegenRate>
   </Health>
   <Identity>
     <Classes datatype="tokens">Hero</Classes>
Index: binaries/data/mods/public/simulation/templates/template_unit_hero_ranged.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_hero_ranged.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_hero_ranged.xml	(working copy)
@@ -26,7 +26,6 @@
   </Cost>
   <Health>
     <Max>500</Max>
-    <RegenRate>0.2</RegenRate>
   </Health>
   <Identity>
     <GenericName>Hero</GenericName>
Index: binaries/data/mods/public/simulation/templates/template_unit_infantry.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_infantry.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_infantry.xml	(working copy)
@@ -44,7 +44,6 @@
   </Footprint>
   <Health>
     <Max>100</Max>
-    <RegenRate>0.2</RegenRate>
   </Health>
   <Identity>
     <GenericName>Infantry</GenericName>
Index: binaries/data/mods/public/simulation/templates/template_unit_infantry_melee.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_infantry_melee.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_infantry_melee.xml	(working copy)
@@ -25,7 +25,6 @@
   </Cost>
   <Health>
     <Max>100</Max>
-    <RegenRate>0.2</RegenRate>
   </Health>
   <Identity>
     <GenericName>Melee Infantry</GenericName>
Index: binaries/data/mods/public/simulation/templates/template_unit_infantry_ranged.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_infantry_ranged.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_infantry_ranged.xml	(working copy)
@@ -17,7 +17,6 @@
   </Attack>
   <Health>
     <Max>90</Max>
-    <RegenRate>0.2</RegenRate>
   </Health>
   <Identity>
     <GenericName>Ranged</GenericName>
Index: binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fire.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fire.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fire.xml	(working copy)
@@ -28,6 +28,7 @@
   </Footprint>
   <Health>
     <Max>500</Max>
+    <RegenRate>-3</RegenRate>
   </Health>
   <Identity>
     <GenericName>Fire Ship</GenericName>
@@ -42,9 +43,6 @@
     <BarHeight>0.5</BarHeight>
     <HeightOffset>6.0</HeightOffset>
   </StatusBars>
-  <TerritoryDecay>
-    <HealthDecayRate>3</HealthDecayRate>
-  </TerritoryDecay>
   <ResourceGatherer disable=""/>
   <UnitMotion>
     <WalkSpeed>16.0</WalkSpeed>
Index: binaries/data/mods/public/simulation/templates/template_unit_support.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_support.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_support.xml	(working copy)
@@ -8,9 +8,6 @@
   <Cost>
     <BuildTime>15</BuildTime>
   </Cost>
-  <Health>
-    <RegenRate>0.2</RegenRate>
-  </Health>
   <Identity>
     <GenericName>Support</GenericName>
     <Classes datatype="tokens">Support Organic</Classes>
Index: binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml	(working copy)
@@ -47,7 +47,6 @@
   </Cost>
   <Health>
     <Max>75</Max>
-    <RegenRate>0.3</RegenRate>
   </Health>
   <Identity>
     <GenericName>Female Citizen</GenericName>
Index: binaries/data/mods/public/simulation/templates/template_unit_support_healer.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_support_healer.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/template_unit_support_healer.xml	(working copy)
@@ -14,7 +14,7 @@
   </Cost>
   <Health>
     <Max>85</Max>
-    <RegenRate>0.3</RegenRate>
+    <RegenRate>0.1</RegenRate>
   </Health>
   <Identity>
     <Classes datatype="tokens">Healer</Classes>
Index: binaries/data/mods/public/simulation/templates/units/athen_infantry_archer_a.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/athen_infantry_archer_a.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/athen_infantry_archer_a.xml	(working copy)
@@ -13,7 +13,6 @@
   </Attack>
   <Health>
     <Max>95</Max>
-    <RegenRate>0.3</RegenRate>
   </Health>
   <Identity>
     <Rank>Advanced</Rank>
Index: binaries/data/mods/public/simulation/templates/units/athen_infantry_archer_e.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/athen_infantry_archer_e.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/athen_infantry_archer_e.xml	(working copy)
@@ -13,7 +13,6 @@
   </Attack>
   <Health>
     <Max>105</Max>
-    <RegenRate>0.4</RegenRate>
   </Health>
   <Identity>
     <Rank>Elite</Rank>
Index: binaries/data/mods/public/simulation/templates/units/brit_support_female_citizen.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/brit_support_female_citizen.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/brit_support_female_citizen.xml	(working copy)
@@ -7,7 +7,6 @@
   </Attack>
   <Health>
     <Max>75</Max>
-    <RegenRate>0.5</RegenRate>
   </Health>
   <Identity>
     <Civ>brit</Civ>
Index: binaries/data/mods/public/simulation/templates/units/cart_infantry_archer_a.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/cart_infantry_archer_a.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/cart_infantry_archer_a.xml	(working copy)
@@ -13,7 +13,6 @@
   </Attack>
   <Health>
     <Max>95</Max>
-    <RegenRate>0.3</RegenRate>
   </Health>
   <Identity>
     <Rank>Advanced</Rank>
Index: binaries/data/mods/public/simulation/templates/units/cart_infantry_archer_e.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/cart_infantry_archer_e.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/cart_infantry_archer_e.xml	(working copy)
@@ -13,7 +13,6 @@
   </Attack>
   <Health>
     <Max>105</Max>
-    <RegenRate>0.4</RegenRate>
   </Health>
   <Identity>
     <Rank>Elite</Rank>
Index: binaries/data/mods/public/simulation/templates/units/celt_support_female_citizen.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/celt_support_female_citizen.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/celt_support_female_citizen.xml	(working copy)
@@ -12,7 +12,6 @@
   </Builder>
   <Health>
     <Max>75</Max>
-    <RegenRate>0.5</RegenRate>
   </Health>
   <Identity>
     <Civ>celt</Civ>
Index: binaries/data/mods/public/simulation/templates/units/gaul_support_female_citizen.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/gaul_support_female_citizen.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/gaul_support_female_citizen.xml	(working copy)
@@ -12,7 +12,6 @@
   </Builder>
   <Health>
     <Max>75</Max>
-    <RegenRate>0.5</RegenRate>
   </Health>
   <Identity>
     <Civ>gaul</Civ>
Index: binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_a.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_a.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_a.xml	(working copy)
@@ -13,7 +13,6 @@
   </Attack>
   <Health>
     <Max>95</Max>
-    <RegenRate>0.3</RegenRate>
   </Health>
   <Identity>
     <Rank>Advanced</Rank>
Index: binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_e.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_e.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_e.xml	(working copy)
@@ -13,7 +13,6 @@
   </Attack>
   <Health>
     <Max>105</Max>
-    <RegenRate>0.4</RegenRate>
   </Health>
   <Identity>
     <Rank>Elite</Rank>
Index: binaries/data/mods/public/simulation/templates/units/mace_infantry_archer_a.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/mace_infantry_archer_a.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/mace_infantry_archer_a.xml	(working copy)
@@ -13,7 +13,6 @@
   </Attack>
   <Health>
     <Max>95</Max>
-    <RegenRate>0.3</RegenRate>
   </Health>
   <Identity>
     <Rank>Advanced</Rank>
Index: binaries/data/mods/public/simulation/templates/units/mace_infantry_archer_e.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/units/mace_infantry_archer_e.xml	(revision 13646)
+++ binaries/data/mods/public/simulation/templates/units/mace_infantry_archer_e.xml	(working copy)
@@ -13,7 +13,6 @@
   </Attack>
   <Health>
     <Max>105</Max>
-    <RegenRate>0.4</RegenRate>
   </Health>
   <Identity>
     <Rank>Elite</Rank>
