Merge pull request #269 from mxdamien/master
Potentially use goal position of previous command as starting point f…
This commit is contained in:
commit
8627ad20ad
20 changed files with 158 additions and 3 deletions
|
@ -296,5 +296,18 @@ static void EnterTransporter(CUnit &unit, COrder_Board &order)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
** Get goal position
|
||||
*/
|
||||
/* virtual */ const Vec2i COrder_Board::GetGoalPos() const
|
||||
{
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
if (goalPos != invalidPos) {
|
||||
return goalPos;
|
||||
}
|
||||
if (this->HasGoal()) {
|
||||
return this->GetGoal()->tilePos;
|
||||
}
|
||||
return invalidPos;
|
||||
}
|
||||
//@}
|
||||
|
|
|
@ -469,4 +469,19 @@ bool COrder_Build::BuildFromOutside(CUnit &unit) const
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Get goal position
|
||||
*/
|
||||
/* virtual */ const Vec2i COrder_Build::GetGoalPos() const
|
||||
{
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
if (goalPos != invalidPos) {
|
||||
return goalPos;
|
||||
}
|
||||
if (this->HasGoal()) {
|
||||
return this->GetGoal()->tilePos;
|
||||
}
|
||||
return invalidPos;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -213,3 +213,18 @@ enum {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Get goal position
|
||||
*/
|
||||
/* virtual */ const Vec2i COrder_Defend::GetGoalPos() const
|
||||
{
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
if (goalPos != invalidPos) {
|
||||
return goalPos;
|
||||
}
|
||||
if (this->HasGoal()) {
|
||||
return this->GetGoal()->tilePos;
|
||||
}
|
||||
return invalidPos;
|
||||
}
|
||||
|
|
|
@ -201,4 +201,19 @@ static void GetExplorationTarget(const CUnit &unit, Vec2i &dest)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Get goal position
|
||||
*/
|
||||
/* virtual */ const Vec2i COrder_Explore::GetGoalPos() const
|
||||
{
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
if (goalPos != invalidPos) {
|
||||
return goalPos;
|
||||
}
|
||||
if (this->HasGoal()) {
|
||||
return this->GetGoal()->tilePos;
|
||||
}
|
||||
return invalidPos;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -317,4 +317,19 @@ enum {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Get goal position
|
||||
*/
|
||||
/* virtual */ const Vec2i COrder_Follow::GetGoalPos() const
|
||||
{
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
if (goalPos != invalidPos) {
|
||||
return goalPos;
|
||||
}
|
||||
if (this->HasGoal()) {
|
||||
return this->GetGoal()->tilePos;
|
||||
}
|
||||
return invalidPos;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -261,4 +261,19 @@ int DoActionMove(CUnit &unit)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Get goal position
|
||||
*/
|
||||
/* virtual */ const Vec2i COrder_Move::GetGoalPos() const
|
||||
{
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
if (goalPos != invalidPos) {
|
||||
return goalPos;
|
||||
}
|
||||
if (this->HasGoal()) {
|
||||
return this->GetGoal()->tilePos;
|
||||
}
|
||||
return invalidPos;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -186,4 +186,19 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Get goal position
|
||||
*/
|
||||
/* virtual */ const Vec2i COrder_Patrol::GetGoalPos() const
|
||||
{
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
if (goalPos != invalidPos) {
|
||||
return goalPos;
|
||||
}
|
||||
if (this->HasGoal()) {
|
||||
return this->GetGoal()->tilePos;
|
||||
}
|
||||
return invalidPos;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -319,5 +319,20 @@ static void AnimateActionRepair(CUnit &unit)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Get goal position
|
||||
*/
|
||||
/* virtual */ const Vec2i COrder_Repair::GetGoalPos() const
|
||||
{
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
if (goalPos != invalidPos) {
|
||||
return goalPos;
|
||||
}
|
||||
if (this->HasGoal()) {
|
||||
return this->GetGoal()->tilePos;
|
||||
}
|
||||
return invalidPos;
|
||||
}
|
||||
|
||||
|
||||
//@}
|
||||
|
|
|
@ -1369,4 +1369,19 @@ void COrder_Resource::Execute(CUnit &unit)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Get goal position
|
||||
*/
|
||||
/* virtual */ const Vec2i COrder_Resource::GetGoalPos() const
|
||||
{
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
if (goalPos != invalidPos) {
|
||||
return goalPos;
|
||||
}
|
||||
if (this->HasGoal()) {
|
||||
return this->GetGoal()->tilePos;
|
||||
}
|
||||
return invalidPos;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -403,6 +403,19 @@ void CommandPatrolUnit(CUnit &unit, const Vec2i &pos, int flush)
|
|||
if (IsUnitValidForNetwork(unit) == false) {
|
||||
return ;
|
||||
}
|
||||
|
||||
const Vec2i invalidPos(-1, -1);
|
||||
|
||||
Vec2i startPos = unit.tilePos;
|
||||
COrderPtr *prevOrder = &unit.Orders.back();
|
||||
|
||||
if(*prevOrder != NULL) {
|
||||
Vec2i prevGoalPos = (*prevOrder)->GetGoalPos();
|
||||
if(prevGoalPos != invalidPos) {
|
||||
startPos = prevGoalPos;
|
||||
}
|
||||
}
|
||||
|
||||
COrderPtr *order;
|
||||
|
||||
if (!unit.CanMove()) {
|
||||
|
@ -414,7 +427,7 @@ void CommandPatrolUnit(CUnit &unit, const Vec2i &pos, int flush)
|
|||
return;
|
||||
}
|
||||
}
|
||||
*order = COrder::NewActionPatrol(unit.tilePos, pos);
|
||||
*order = COrder::NewActionPatrol(startPos, pos);
|
||||
|
||||
ClearSavedAction(unit);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
virtual void Execute(CUnit &unit);
|
||||
virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const;
|
||||
virtual void UpdatePathFinderData(PathFinderInput &input);
|
||||
virtual const Vec2i GetGoalPos() const;
|
||||
private:
|
||||
bool WaitForTransporter(CUnit &unit);
|
||||
int MoveToTransporter(CUnit &unit);
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
virtual void AiUnitKilled(CUnit &unit);
|
||||
|
||||
const CUnitType &GetUnitType() const { return *Type; }
|
||||
virtual const Vec2i GetGoalPos() const { return goalPos; }
|
||||
virtual const Vec2i GetGoalPos() const;
|
||||
|
||||
private:
|
||||
bool MoveToLocation(CUnit &unit);
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
virtual void Execute(CUnit &unit);
|
||||
virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const;
|
||||
virtual void UpdatePathFinderData(PathFinderInput &input);
|
||||
virtual const Vec2i GetGoalPos() const;
|
||||
private:
|
||||
unsigned int State;
|
||||
int Range;
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
virtual void Execute(CUnit &unit);
|
||||
virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const;
|
||||
virtual void UpdatePathFinderData(PathFinderInput &input);
|
||||
virtual const Vec2i GetGoalPos() const;
|
||||
private:
|
||||
unsigned int WaitingCycle; /// number of cycle pathfinder wait.
|
||||
int Range;
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
virtual void Execute(CUnit &unit);
|
||||
virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const;
|
||||
virtual void UpdatePathFinderData(PathFinderInput &input);
|
||||
virtual const Vec2i GetGoalPos() const;
|
||||
private:
|
||||
unsigned int State;
|
||||
int Range;
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
virtual void Execute(CUnit &unit);
|
||||
virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const;
|
||||
virtual void UpdatePathFinderData(PathFinderInput &input);
|
||||
virtual const Vec2i GetGoalPos() const;
|
||||
|
||||
private:
|
||||
int Range;
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
virtual void UpdatePathFinderData(PathFinderInput &input);
|
||||
|
||||
const Vec2i &GetWayPoint() const { return WayPoint; }
|
||||
virtual const Vec2i GetGoalPos() const;
|
||||
private:
|
||||
Vec2i WayPoint; /// position for patroling.
|
||||
unsigned int WaitingCycle; /// number of cycle pathfinder wait.
|
||||
|
|
|
@ -57,6 +57,7 @@ public:
|
|||
virtual void UpdatePathFinderData(PathFinderInput &input);
|
||||
|
||||
const CUnitPtr &GetReparableTarget() const { return ReparableTarget; }
|
||||
virtual const Vec2i GetGoalPos() const;
|
||||
private:
|
||||
bool RepairUnit(const CUnit &unit, CUnit &goal);
|
||||
private:
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
bool IsGatheringStarted() const;
|
||||
bool IsGatheringFinished() const;
|
||||
bool IsGatheringWaiting() const;
|
||||
virtual const Vec2i GetGoalPos() const;
|
||||
private:
|
||||
int MoveToResource_Terrain(CUnit &unit);
|
||||
int MoveToResource_Unit(CUnit &unit);
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
virtual void Execute(CUnit &unit);
|
||||
virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const;
|
||||
virtual void UpdatePathFinderData(PathFinderInput &input);
|
||||
virtual const Vec2i GetGoalPos() const { return goalPos; }
|
||||
|
||||
private:
|
||||
bool LeaveTransporter(CUnit &transporter);
|
||||
|
|
Loading…
Add table
Reference in a new issue