From 0cc04664b63495baee5ff2a5007ea5107e0e4dae Mon Sep 17 00:00:00 2001
From: joris <joris.dauphin@gmail.com>
Date: Sun, 19 Feb 2012 09:59:01 +0100
Subject: [PATCH] Fix mixed EOL (\n, \r\n) fix small bugs

---
 src/action/action_attack.cpp |  2 +-
 src/action/action_build.cpp  |  4 +---
 src/include/unit.h           |  2 +-
 src/unit/unit.cpp            | 23 ++++++++++++++---------
 4 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/action/action_attack.cpp b/src/action/action_attack.cpp
index f78fd6ea4..a829b457a 100644
--- a/src/action/action_attack.cpp
+++ b/src/action/action_attack.cpp
@@ -209,7 +209,7 @@ static void MoveToTarget(CUnit &unit)
 	COrderPtr order = unit.CurrentOrder();
 	if (err == 0 && !order->HasGoal()) {
 		// Check if we're in range when attacking a location and we are waiting
-		if (unit.MapDistanceTo(order->goalPos.x, order->goalPos.y) <
+		if (unit.MapDistanceTo(order->goalPos.x, order->goalPos.y) <=
 				unit.Stats->Variables[ATTACKRANGE_INDEX].Max) {
 			err = PF_REACHED;
 		}
diff --git a/src/action/action_build.cpp b/src/action/action_build.cpp
index 31d2eab00..72aa22856 100644
--- a/src/action/action_build.cpp
+++ b/src/action/action_build.cpp
@@ -555,9 +555,7 @@ void HandleActionBuilt(COrder& order, CUnit &unit)
 			// Set to Zero as it's part of a union
 			memset(&unit.CurrentOrder()->Data, 0, sizeof(unit.CurrentOrder()->Data));
 			// Has StartingResources, Use those
-			if (type->StartingResources) {
-				unit.ResourcesHeld = type->StartingResources;
-			}
+			unit.ResourcesHeld = type->StartingResources;
 		}
 
 		unit.Player->Notify(NotifyGreen, unit.tilePos.x, unit.tilePos.y,
diff --git a/src/include/unit.h b/src/include/unit.h
index e6b73f9b2..0f5fe5020 100644
--- a/src/include/unit.h
+++ b/src/include/unit.h
@@ -1073,7 +1073,7 @@ extern CUnit *CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i
 extern bool CanBuildOn(const Vec2i &pos, int mask);
 	/// FIXME: more docu
 extern CUnit *CanBuildUnitType(const CUnit *unit, const CUnitType &type, const Vec2i &pos, int real);
-	/// Get the suitable animation frame depends of unit's damaged type.
+	/// Get the suitable animation frame depends of unit's damaged type.
 extern int ExtraDeathIndex(const char *death);
 
 	/// Find resource
diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp
index 54641d00d..0310c3812 100644
--- a/src/unit/unit.cpp
+++ b/src/unit/unit.cpp
@@ -342,6 +342,9 @@ void CUnit::Init(CUnitType &type)
 	Active = 1;
 	Removed = 1;
 
+	// Has StartingResources, Use those
+	this->ResourcesHeld = type.StartingResources;
+
 	Rs = MyRand() % 100; // used for fancy buildings and others
 
 	Assert(Orders.empty());
@@ -962,14 +965,16 @@ void UnitLost(CUnit &unit)
 	//
 	//  Call back to AI, for killed or lost units.
 	//
-	if (player && player->AiEnabled) {
-		AiUnitKilled(unit);
-	} else {
-		//
-		//  Remove unit from its groups
-		//
-		if (unit.GroupId) {
-			RemoveUnitFromGroups(unit);
+	if (Editor.Running == EditorNotRunning){
+		if (player && player->AiEnabled) {
+			AiUnitKilled(unit);
+		} else {
+			//
+			//  Remove unit from its groups
+			//
+			if (unit.GroupId) {
+				RemoveUnitFromGroups(unit);
+			}
 		}
 	}
 
@@ -2496,7 +2501,7 @@ CUnit *UnitFindResource(const CUnit &unit, const Vec2i &startPos, int range, int
 				// Look if there is a mine
 				//
 				if ((mine = res_finder.Find(Map.Field(pos))) &&
-						mine->Type->CanHarvest &&
+					mine->Type->CanHarvest && mine->ResourcesHeld &&
 						(resinfo.HarvestFromOutside ||
 							mine->Player->Index == PlayerMax - 1 ||
 							mine->Player == unit.Player ||