From 0b6296d96f6f76949dfdee93e300a39fce711dac Mon Sep 17 00:00:00 2001
From: joris <joris.dauphin@gmail.com>
Date: Mon, 13 Feb 2012 15:44:20 +0100
Subject: [PATCH] NewResetPath is now a method in COrder instead of a Macro

---
 src/action/action_attack.cpp      | 12 ++++++------
 src/action/action_board.cpp       |  4 ++--
 src/action/action_build.cpp       |  2 +-
 src/action/action_follow.cpp      |  4 ++--
 src/action/action_move.cpp        |  4 ++--
 src/action/action_patrol.cpp      |  4 ++--
 src/action/action_repair.cpp      |  6 +++---
 src/action/action_resource.cpp    |  6 +++---
 src/action/action_returngoods.cpp |  2 +-
 src/action/action_spellcast.cpp   |  2 +-
 src/action/action_unload.cpp      |  2 +-
 src/include/actions.h             |  6 ++++++
 src/include/pathfinder.h          |  6 ------
 src/unit/unit.cpp                 |  2 +-
 14 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/src/action/action_attack.cpp b/src/action/action_attack.cpp
index a98f5297e..d3ecf310c 100644
--- a/src/action/action_attack.cpp
+++ b/src/action/action_attack.cpp
@@ -164,7 +164,7 @@ static int CheckForTargetInRange(CUnit &unit)
 			order->Range = unit.Stats->Variables[ATTACKRANGE_INDEX].Max;
 			order->goalPos.x = order->goalPos.y = -1;
 			unit.SubAction |= WEAK_TARGET; // weak target
-			NewResetPath(*order);
+			order->NewResetPath();
 		}
 	// Have a weak target, try a better target.
 	} else if (order->HasGoal() && (unit.SubAction & WEAK_TARGET)) {
@@ -180,7 +180,7 @@ static int CheckForTargetInRange(CUnit &unit)
 			}
 			order->SetGoal(temp);
 			order->goalPos.x = order->goalPos.y = -1;
-			NewResetPath(*order);
+			order->NewResetPath();
 		}
 	}
 
@@ -340,7 +340,7 @@ static void AttackTarget(CUnit &unit)
 		order->goalPos.x = order->goalPos.y = -1;
 		order->MinRange = unit.Type->MinAttackRange;
 		order->Range = unit.Stats->Variables[ATTACKRANGE_INDEX].Max;
-		NewResetPath(*order);
+		order->NewResetPath();
 		unit.SubAction |= WEAK_TARGET;
 
 	//
@@ -362,7 +362,7 @@ static void AttackTarget(CUnit &unit)
 				order->goalPos.x = order->goalPos.y = -1;
 				order->MinRange = unit.Type->MinAttackRange;
 				unit.SubAction = MOVE_TO_TARGET;
-				NewResetPath(*order);
+				order->NewResetPath();
 			}
 		}
 	}
@@ -378,7 +378,7 @@ static void AttackTarget(CUnit &unit)
 			delete savedOrder;
 			savedOrder = NULL;
 		}
-		NewResetPath(*order);
+		order->NewResetPath();
 		unit.Frame = 0;
 		unit.State = 0;
 		unit.SubAction &= WEAK_TARGET;
@@ -443,7 +443,7 @@ void HandleActionAttack(COrder& order, CUnit &unit)
 				}
 			}
 			unit.SubAction = MOVE_TO_TARGET;
-			NewResetPath(order);
+			order.NewResetPath();
 			// FIXME: should use a reachable place to reduce pathfinder time.
 			Assert(unit.State == 0);
 		}
diff --git a/src/action/action_board.cpp b/src/action/action_board.cpp
index fc615ef83..c6132301c 100644
--- a/src/action/action_board.cpp
+++ b/src/action/action_board.cpp
@@ -66,7 +66,7 @@ static int MoveToTransporter(CUnit &unit)
 	// We have to reset a lot, or else they will circle each other and stuff.
 	if (oldPos != unit.tilePos) {
 		unit.CurrentOrder()->Range = 1;
-		NewResetPath(*unit.CurrentOrder());
+		unit.CurrentOrder()->NewResetPath();
 	}
 	// New code has this as default.
 	Assert(unit.CurrentAction() == UnitActionBoard);
@@ -196,7 +196,7 @@ void HandleActionBoard(COrder& order, CUnit &unit)
 				unit.Wait--;
 				return;
 			}
-			NewResetPath(order);
+			order.NewResetPath();
 			unit.SubAction = 1;
 			// FALL THROUGH
 		default:
diff --git a/src/action/action_build.cpp b/src/action/action_build.cpp
index b218d9543..fae3a1e78 100644
--- a/src/action/action_build.cpp
+++ b/src/action/action_build.cpp
@@ -95,7 +95,7 @@ static void MoveToLocation(CUnit &unit)
 	// First entry
 	if (!unit.SubAction) {
 		unit.SubAction = 1;
-		NewResetPath(*unit.CurrentOrder());
+		unit.CurrentOrder()->NewResetPath();
 	}
 
 	if (unit.Wait) {
diff --git a/src/action/action_follow.cpp b/src/action/action_follow.cpp
index 3ac2cec38..34d072334 100644
--- a/src/action/action_follow.cpp
+++ b/src/action/action_follow.cpp
@@ -99,7 +99,7 @@ void HandleActionFollow(COrder& order, CUnit &unit)
 	}
 	if (!unit.SubAction) { // first entry
 		unit.SubAction = 1;
-		NewResetPath(order);
+		order.NewResetPath();
 		Assert(unit.State == 0);
 	}
 	switch (DoActionMove(unit)) { // reached end-point?
@@ -173,7 +173,7 @@ void HandleActionFollow(COrder& order, CUnit &unit)
 		order.goalPos = goal->tilePos + goal->Type->GetHalfTileSize();
 		order.ClearGoal();
 		goal = NoUnitP;
-		NewResetPath(order);
+		order.NewResetPath();
 	}
 
 	if (!unit.Anim.Unbreakable) {
diff --git a/src/action/action_move.cpp b/src/action/action_move.cpp
index 065201d76..d0287ae53 100644
--- a/src/action/action_move.cpp
+++ b/src/action/action_move.cpp
@@ -185,7 +185,7 @@ void HandleActionMove(COrder& order, CUnit &unit)
 
 	if (!unit.SubAction) { // first entry
 		unit.SubAction = 1;
-		NewResetPath(*unit.CurrentOrder());
+		unit.CurrentOrder()->NewResetPath();
 		order.Data.Move.Cycles = 0;
 		Assert(unit.State == 0);
 	}
@@ -220,7 +220,7 @@ void HandleActionMove(COrder& order, CUnit &unit)
 		DebugPrint("Goal dead\n");
 		order.goalPos = goal->tilePos + goal->Type->GetHalfTileSize();
 		order.ClearGoal();
-		NewResetPath(order);
+		order.NewResetPath();
 	}
 }
 
diff --git a/src/action/action_patrol.cpp b/src/action/action_patrol.cpp
index f1bbb4f78..2218d0ca0 100644
--- a/src/action/action_patrol.cpp
+++ b/src/action/action_patrol.cpp
@@ -61,7 +61,7 @@ static void SwapPatrolPoints(CUnit &unit)
 	std::swap(order->Arg1.Patrol.y, order->goalPos.y);
 
 	unit.CurrentOrder()->Data.Move.Cycles = 0; //moving counter
-	NewResetPath(*unit.CurrentOrder());
+	unit.CurrentOrder()->NewResetPath();
 }
 
 /**
@@ -84,7 +84,7 @@ void HandleActionPatrol(COrder& order, CUnit &unit)
 
 	if (!unit.SubAction) { // first entry.
 		order.Data.Move.Cycles = 0; //moving counter
-		NewResetPath(order);
+		order.NewResetPath();
 		unit.SubAction = 1;
 	}
 
diff --git a/src/action/action_repair.cpp b/src/action/action_repair.cpp
index c36bd7c6b..63ba2d25a 100644
--- a/src/action/action_repair.cpp
+++ b/src/action/action_repair.cpp
@@ -151,7 +151,7 @@ void HandleActionRepair(COrder& order, CUnit &unit)
 
 	switch (unit.SubAction) {
 		case 0:
-			NewResetPath(order);
+			order.NewResetPath();
 			unit.SubAction = 1;
 			// FALL THROUGH
 		case 1:// Move near to target.
@@ -172,7 +172,7 @@ void HandleActionRepair(COrder& order, CUnit &unit)
 						// FIXME: should I clear this here?
 						order.ClearGoal();
 						goal = NULL;
-						NewResetPath(order);
+						order.NewResetPath();
 					}
 				} else if (unit.Player->AiEnabled) {
 					// Ai players workers should stop if target is killed
@@ -218,7 +218,7 @@ void HandleActionRepair(COrder& order, CUnit &unit)
 						// FIXME: should I clear this here?
 						order.ClearGoal();
 						goal = NULL;
-						NewResetPath(order);
+						order.NewResetPath();
 					} else {
 						int dist = unit.MapDistanceTo(*goal);
 						if (dist <= unit.Type->RepairRange) {
diff --git a/src/action/action_resource.cpp b/src/action/action_resource.cpp
index 6d35b96ba..c212e88dd 100644
--- a/src/action/action_resource.cpp
+++ b/src/action/action_resource.cpp
@@ -83,7 +83,7 @@ static int MoveToResource_Terrain(CUnit &unit)
 			return -1;
 		} else {
 			unit.CurrentOrder()->goalPos = pos;
-			NewResetPath(*unit.CurrentOrder());
+			unit.CurrentOrder()->NewResetPath();
 		}
 	}
 	switch (DoActionMove(unit)) {
@@ -92,7 +92,7 @@ static int MoveToResource_Terrain(CUnit &unit)
 			if (FindTerrainType(unit.Type->MovementMask, MapFieldForest, 0, 9999,
 					unit.Player, unit.tilePos, &pos)) {
 				unit.CurrentOrder()->goalPos = pos;
-				NewResetPath(*unit.CurrentOrder());
+				unit.CurrentOrder()->NewResetPath();
 				DebugPrint("Found a better place to harvest %d,%d\n" _C_ pos.x _C_ pos.y);
 				// FIXME: can't this overflow? It really shouldn't, since
 				// x and y are really supossed to be reachable, checked thorugh a flood fill.
@@ -165,7 +165,7 @@ static void UnitGotoGoal(CUnit &unit, CUnit *const goal, int mode)
 	unit.State = 0;
 	if (mode == SUB_MOVE_TO_DEPOT || mode == SUB_MOVE_TO_RESOURCE) {
 		unit.CurrentOrder()->Data.Move.Cycles = 0; //moving counter
-		NewResetPath(*unit.CurrentOrder());
+		unit.CurrentOrder()->NewResetPath();
 	}
 }
 
diff --git a/src/action/action_returngoods.cpp b/src/action/action_returngoods.cpp
index 031422b02..981c58071 100644
--- a/src/action/action_returngoods.cpp
+++ b/src/action/action_returngoods.cpp
@@ -87,7 +87,7 @@ void HandleActionReturnGoods(COrder& order, CUnit &unit)
 	//FIXME!!!!!!!!!!!!!!!!!!!!
 	//unit.CurrentOrder()->Arg1.ResourcePos = -1;
 
-	NewResetPath(order);
+	order.NewResetPath();
 	unit.SubAction = /* SUB_MOVE_TO_DEPOT */ 70; // FIXME : Define value.
 }
 
diff --git a/src/action/action_spellcast.cpp b/src/action/action_spellcast.cpp
index 28468a363..b258d3f68 100644
--- a/src/action/action_spellcast.cpp
+++ b/src/action/action_spellcast.cpp
@@ -166,7 +166,7 @@ void HandleActionSpellCast(COrder& order, CUnit &unit)
 			}
 			// FIXME FIXME FIXME: Check if already in range and skip straight to 2(casting)
 			if (!spell->IsCasterOnly()) {
-				NewResetPath(*unit.CurrentOrder());
+				unit.CurrentOrder()->NewResetPath();
 			}
 			unit.ReCast = 0; // repeat spell on next pass? (defaults to `no')
 			unit.SubAction = 1;
diff --git a/src/action/action_unload.cpp b/src/action/action_unload.cpp
index f7452096f..c7d925414 100644
--- a/src/action/action_unload.cpp
+++ b/src/action/action_unload.cpp
@@ -343,7 +343,7 @@ void HandleActionUnload(COrder& order, CUnit &unit)
 				order.goalPos = pos;
 			}
 
-			NewResetPath(*unit.CurrentOrder());
+			unit.CurrentOrder()->NewResetPath();
 			unit.SubAction = 1;
 			// follow on next case
 		case 1: // Move unit to destination
diff --git a/src/include/actions.h b/src/include/actions.h
index fd831f3a5..82bf0459b 100644
--- a/src/include/actions.h
+++ b/src/include/actions.h
@@ -138,6 +138,12 @@ public:
 	void SetGoal(CUnit *const new_goal);
 	void ClearGoal();
 
+	/**
+	**  To remove pathfinder internals. Called if path destination changed.
+	*/
+	void NewResetPath() { Data.Move.Fast = 1; Data.Move.Length = 0; }
+
+
 private:
 	friend void CclParseOrder(lua_State *l, const CUnit &unit, COrder* order);
 
diff --git a/src/include/pathfinder.h b/src/include/pathfinder.h
index 712ccd719..0b4a60a5c 100644
--- a/src/include/pathfinder.h
+++ b/src/include/pathfinder.h
@@ -67,12 +67,6 @@ enum _move_return_ {
 	PF_MOVE = 1           /// On the way moving
 };
 
-/**
-**  To remove pathfinder internals. Called if path destination changed.
-*/
-#define NewResetPath(order) \
-	do { (order).Data.Move.Fast = 1; (order).Data.Move.Length = 0; } while (0)
-
 /*----------------------------------------------------------------------------
 --  Variables
 ----------------------------------------------------------------------------*/
diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp
index f43b7a99c..986982e90 100644
--- a/src/unit/unit.cpp
+++ b/src/unit/unit.cpp
@@ -384,7 +384,7 @@ bool CUnit::RestoreOrder()
 	this->Orders[0] = this->SavedOrder;
 	this->CurrentResource = this->SavedOrder->CurrentResource;
 
-	NewResetPath(*this->CurrentOrder());
+	this->CurrentOrder()->NewResetPath();
 
 	this->SavedOrder = NULL;
 	return true;