From c59a035066285912dcfeb3488447b94aa26638f0 Mon Sep 17 00:00:00 2001
From: cybermind <iddqd_mail@mail.ru>
Date: Thu, 3 May 2012 19:46:26 +0600
Subject: [PATCH] [+] Reverted back the gray dot showing for UnitActionStill.
 [+] Added support for AlwaysFire flag in spawn-missile anim. [*] More
 complete changelog. [-] Fixed unit freeze for UnitActionStandGround. [-] Fix
 MaxResources manage. [-] Fixed clamp assert if left and right ranges are
 equal.

---
 doc/changelog.html                       | 13 +++++++++----
 src/action/action_still.cpp              |  5 ++++-
 src/action/action_upgradeto.cpp          |  2 +-
 src/action/actions.cpp                   |  3 ++-
 src/animation/animation_ifvar.cpp        |  2 +-
 src/animation/animation_spawnmissile.cpp |  8 +++++---
 src/include/util.h                       |  2 +-
 src/stratagus/script_player.cpp          |  4 +++-
 src/ui/mainscr.cpp                       |  4 ++--
 src/unit/unit.cpp                        |  2 +-
 src/unit/unittype.cpp                    | 14 ++++++++++++--
 11 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/doc/changelog.html b/doc/changelog.html
index a6c393614..21dd69a93 100644
--- a/doc/changelog.html
+++ b/doc/changelog.html
@@ -2,7 +2,7 @@
 <html>
 <head>
 <!--
-----	(c) Copyright 1998-2011 by Lutz Sammer and Pali Rohár
+----	(c) Copyright 1998-2012 by Lutz Sammer and Pali Rohár
 
 ----    This program is free software; you can redistribute it and/or modify
 ----    it under the terms of the GNU General Public License as published by
@@ -46,8 +46,13 @@
 <p/>
 	<li>trunk</li>
 	<ul>
+	<li>Added OnHit Lua callback parameter for UnitType to create some effects if unit is hit (from Cybermind)</li>
+	<li>Reworked the button's popup system to achieve more flexibility (from Cybermind)</li>
+	<li>Added Preference.ShowNameDelay and Preference.ShowNameTime to show a popup for unit under cursor (from Cybermind)</li>
 	<li>Code compile now with Lua 5.2 (from Joris Dauphin).</li>
-	<li>Fix bug #909454: compile errorson OpenBSD. (from Pali Rohár)</li>
+	<li>Fix bug #901393: Always "network out of sync" in multiplayer mode (from Cybermind)</li>
+	<li>Fix bug #710187: OpenGL is slower than without OpenGL (from Cybermind)</li>
+	<li>Fix bug #909454: compile errors on OpenBSD. (from Pali Rohár)</li>
 	<li>Fix compilation for maemo. (from Pali Rohár)</li>
 	<li>Fix bug #910078: worker unable to do anything after building structure. (patch from Neil Tan)</li>
 	<li>Fix bug #912904: Fix pathfinfing problem with unit near of goal. (patch from Neil Tan)</li>
@@ -55,7 +60,7 @@
 	<li>Fix bug #841133: Fix Action resource and DeassignWorkerFromMine. (from Joris Dauphin)</li>
 	<li>Fix some regression in pathFinding. (from Joris Dauphin)</li>
 	<li>Rearchitecturing of COrder and CAnimation. (from Joris Dauphin)</li>
-	<li>Add DefineDefaultResourceMaxAmounts() to define max value per resource. Add "Storing" in UnitType to increase MaxResourceAmount (from Cybermind)</li>
+	<li>Add DefineDefaultResourceMaxAmounts() to define max value per resource (like tiberium from C&C). Add "Storing" in UnitType to increase MaxResourceAmount (from Cybermind)</li>
 	<li>New unitType flag:"Wall" which create "connection" with its neighboors. (from Cybermind)</li>
 	<li>New unitType flag:"NonSolid" for unit which don't forbid other unit to be in the same place. (from Cybermind)</li>
 	<li>New missile class "missile-class-treacer" which seek towards its target. (from Cybermind)</li>
@@ -1430,7 +1435,7 @@ g the callback. (from Francois Beerten)
 </ul>
 
 <hr>
-(C) Copyright 1998-2011 by The <a href="https://launchpad.net/stratagus">Stratagus</a> Project
+(C) Copyright 1998-2012 by The <a href="https://launchpad.net/stratagus">Stratagus</a> Project
 under the <a href="gpl.html">GNU General Public License</a>.<br>
 All trademarks and copyrights on this page are owned by their respective owners.<br>
 </body>
diff --git a/src/action/action_still.cpp b/src/action/action_still.cpp
index 368aee6f6..4312b98ef 100644
--- a/src/action/action_still.cpp
+++ b/src/action/action_still.cpp
@@ -108,6 +108,8 @@ enum {
 {
 	if (this->Action == UnitActionStandGround) {
 		Video.FillCircleClip(ColorBlack, lastScreenPos, 2);
+	} else {
+		Video.FillCircleClip(ColorGray, lastScreenPos, 2);
 	}
 	return lastScreenPos;
 }
@@ -257,7 +259,7 @@ static CUnit *UnitToRepairInRange(const CUnit &unit, int range)
 */
 bool AutoRepair(CUnit &unit)
 {
-	const int repairRange = unit.Variable[AUTOREPAIRRANGE_INDEX].Value;
+	const int repairRange = unit.Type->DefaultStat.Variables[AUTOREPAIRRANGE_INDEX].Value;
 
 	if (unit.AutoRepair == false || repairRange == 0) {
 		return false;
@@ -291,6 +293,7 @@ bool COrder_Still::AutoAttackStand(CUnit &unit)
 		return false;
 	}
 	this->State = SUB_STILL_ATTACK; // Mark attacking.
+	this->SetGoal(this->AutoTarget);
 	UnitHeadingFromDeltaXY(unit, this->AutoTarget->tilePos + this->AutoTarget->Type->GetHalfTileSize() - unit.tilePos);
 	return true;
 }
diff --git a/src/action/action_upgradeto.cpp b/src/action/action_upgradeto.cpp
index 946dd1b05..70f6c1cd8 100644
--- a/src/action/action_upgradeto.cpp
+++ b/src/action/action_upgradeto.cpp
@@ -116,7 +116,7 @@ static int TransformUnitIntoType(CUnit &unit, const CUnitType &newtype)
 	for (int i = 0; i < MaxCosts; ++i) {
 		if (player.MaxResources[i] != -1) {
 			player.MaxResources[i] += newtype._Storing[i] - oldtype._Storing[i];
-			player.SetResource(i, player.Resources[i], true);
+			player.SetResource(i, player.StoredResources[i], true);
 		}
 	}
 
diff --git a/src/action/actions.cpp b/src/action/actions.cpp
index 338f33222..404398009 100644
--- a/src/action/actions.cpp
+++ b/src/action/actions.cpp
@@ -335,7 +335,8 @@ static void HandleUnitAction(CUnit &unit)
 
 		// o Look if we have a new order and old finished.
 		// o Or the order queue should be flushed.
-		if (unit.Orders[0]->Finished && unit.Orders.size() > 1) {
+		if ((unit.Orders[0]->Action == UnitActionStandGround || unit.Orders[0]->Finished)
+			&& unit.Orders.size() > 1) {
 			if (unit.Removed) { // FIXME: johns I see this as an error
 				DebugPrint("Flushing removed unit\n");
 				// This happens, if building with ALT+SHIFT.
diff --git a/src/animation/animation_ifvar.cpp b/src/animation/animation_ifvar.cpp
index 613da17dc..92aff265f 100644
--- a/src/animation/animation_ifvar.cpp
+++ b/src/animation/animation_ifvar.cpp
@@ -71,7 +71,7 @@ bool returnFalse(int , int) { return false; }
 }
 
 /*
-** s = "leftOp rigthOp Op gotoLabel"
+** s = "leftOp Op rigthOp gotoLabel"
 */
 /* virtual */ void CAnimation_IfVar::Init(const char *s)
 {
diff --git a/src/animation/animation_spawnmissile.cpp b/src/animation/animation_spawnmissile.cpp
index 52fd3ca8b..91b900b5b 100644
--- a/src/animation/animation_spawnmissile.cpp
+++ b/src/animation/animation_spawnmissile.cpp
@@ -114,10 +114,12 @@ static int ParseAnimFlags(CUnit &unit, const char *parseflag)
 		start.y = (goal->tilePos.y + starty) * PixelTileSize.y + PixelTileSize.y / 2;
 	}
 	if ((flags & ANIM_SM_TOTARGET)) {
-		const CUnit *target = goal->CurrentOrder()->GetGoal();
-		Assert(goal->CurrentAction() == UnitActionAttack);
+		CUnit *target = goal->CurrentOrder()->GetGoal();
 		if (!target  || target->Destroyed || target->Removed) {
-			return;
+			Assert(!unit.Type->Missile.Missile->AlwaysFire || unit.Type->Missile.Missile->Range);
+			if (!target || !unit.Type->Missile.Missile->AlwaysFire) {
+				return;
+			}
 		}
 		if (flags & ANIM_SM_PIXEL) {
 			dest.x = target->tilePos.x * PixelTileSize.x + target->IX + destx;
diff --git a/src/include/util.h b/src/include/util.h
index 09009bb71..23ac5da0e 100644
--- a/src/include/util.h
+++ b/src/include/util.h
@@ -180,7 +180,7 @@ extern long isqrt(long num);
 template <typename T>
 void clamp(T *value, T minValue, T maxValue)
 {
-	Assert(minValue < maxValue);
+	Assert(minValue <= maxValue);
 
 	if (*value < minValue) {
 		*value = minValue;
diff --git a/src/stratagus/script_player.cpp b/src/stratagus/script_player.cpp
index f55c25643..632f0fb45 100644
--- a/src/stratagus/script_player.cpp
+++ b/src/stratagus/script_player.cpp
@@ -338,7 +338,9 @@ void CPlayer::Load(lua_State *l)
 	}
 	// Manage max
 	for (int i = 0; i < MaxCosts; ++i) {
-		this->SetResource(i, this->Resources[i]);
+		if (this->MaxResources[i] != -1) {
+			this->SetResource(i, this->StoredResources[i]);
+		}
 	}
 }
 
diff --git a/src/ui/mainscr.cpp b/src/ui/mainscr.cpp
index 1cde7aa2c..b7a55e7d2 100644
--- a/src/ui/mainscr.cpp
+++ b/src/ui/mainscr.cpp
@@ -821,9 +821,9 @@ void DrawResources()
 			const int resourceAmount = ThisPlayer->Resources[i];
 
 			if (ThisPlayer->MaxResources[i] != -1) {
-				const int storedAmount = ThisPlayer->StoredResources[i];
+				const int resAmount = ThisPlayer->StoredResources[i] + ThisPlayer->Resources[i];
 				char tmp[128];
-				snprintf(tmp, sizeof(tmp), "%d/%d (%d)", storedAmount, ThisPlayer->MaxResources[i], resourceAmount);
+				snprintf(tmp, sizeof(tmp), "%d (%d)", resAmount, ThisPlayer->MaxResources[i] - ThisPlayer->StoredResources[i]);
 				label.SetFont(GetSmallFont());
 
 				label.Draw(UI.Resources[i].TextX, UI.Resources[i].TextY + 3, tmp);
diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp
index db4fed6c9..85279b81d 100644
--- a/src/unit/unit.cpp
+++ b/src/unit/unit.cpp
@@ -970,7 +970,7 @@ void UnitLost(CUnit &unit)
 				const int newMaxValue = player.MaxResources[i] - type._Storing[i];
 
 				player.MaxResources[i] = std::max(0, newMaxValue);
-				player.SetResource(i, player.Resources[i]);
+				player.SetResource(i, player.StoredResources[i], true);
 			}
 		}
 		//  Handle income improvements, look if a player loses a building
diff --git a/src/unit/unittype.cpp b/src/unit/unittype.cpp
index b21dbaf38..a473cf184 100644
--- a/src/unit/unittype.cpp
+++ b/src/unit/unittype.cpp
@@ -254,8 +254,18 @@ void UpdateStats(int reset)
 
 		// Non-solid units can always be entered and they don't block anything
 		if (type.NonSolid) {
-			type.MovementMask = 0;
-			type.FieldFlags = 0;
+			if (type.Building) {
+				type.MovementMask = MapFieldLandUnit |
+					MapFieldSeaUnit |
+					MapFieldBuilding |
+					MapFieldCoastAllowed |
+					MapFieldWaterAllowed |
+					MapFieldUnpassable;
+				type.FieldFlags = MapFieldNoBuilding;
+			} else {
+				type.MovementMask = 0;
+				type.FieldFlags = 0;
+			}
 			continue;
 		}