NewResetPath is now a method in COrder instead of a Macro

This commit is contained in:
joris 2012-02-13 15:44:20 +01:00
parent 6341a4cafd
commit 0b6296d96f
14 changed files with 31 additions and 31 deletions

View file

@ -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);
}

View file

@ -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:

View file

@ -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) {

View file

@ -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) {

View file

@ -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();
}
}

View file

@ -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;
}

View file

@ -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) {

View file

@ -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();
}
}

View file

@ -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.
}

View file

@ -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;

View file

@ -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

View file

@ -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);

View file

@ -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
----------------------------------------------------------------------------*/

View file

@ -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;