[*] Improved AI collision detection for bigger units
[*] AI tries to reach the goal pos when unloading units
This commit is contained in:
parent
7e83a31e76
commit
f80feaecf7
4 changed files with 33 additions and 4 deletions
|
@ -37,6 +37,7 @@
|
|||
|
||||
#include "action/action_unload.h"
|
||||
|
||||
#include "animation.h"
|
||||
#include "iolib.h"
|
||||
#include "map.h"
|
||||
#include "pathfinder.h"
|
||||
|
@ -68,6 +69,7 @@
|
|||
if (this->Finished) {
|
||||
file.printf(" \"finished\", ");
|
||||
}
|
||||
file.printf(" \"range\", %d,", this->Range);
|
||||
if (this->HasGoal()) {
|
||||
file.printf(" \"goal\", \"%s\",", UnitReference(this->GetGoal()).c_str());
|
||||
}
|
||||
|
@ -81,6 +83,9 @@
|
|||
if (!strcmp("state", value)) {
|
||||
++j;
|
||||
this->State = LuaToNumber(l, -1, j + 1);
|
||||
} else if (!strcmp(value, "range")) {
|
||||
++j;
|
||||
this->Range = LuaToNumber(l, -1, j + 1);
|
||||
} else if (!strcmp(value, "tile")) {
|
||||
++j;
|
||||
lua_rawgeti(l, -1, j + 1);
|
||||
|
@ -326,7 +331,7 @@ static int MoveToDropZone(CUnit &unit)
|
|||
{
|
||||
switch (DoActionMove(unit)) { // reached end-point?
|
||||
case PF_UNREACHABLE:
|
||||
return -1;
|
||||
return PF_UNREACHABLE;
|
||||
case PF_REACHED:
|
||||
break;
|
||||
default:
|
||||
|
@ -396,6 +401,25 @@ bool COrder_Unload::LeaveTransporter(CUnit &transporter)
|
|||
if (!unit.CanMove()) {
|
||||
this->State = 2;
|
||||
}
|
||||
|
||||
if (unit.Wait) {
|
||||
if (!unit.Waiting) {
|
||||
unit.Waiting = 1;
|
||||
unit.WaitBackup = unit.Anim;
|
||||
}
|
||||
UnitShowAnimation(unit, unit.Type->Animations->Still);
|
||||
unit.Wait--;
|
||||
return;
|
||||
}
|
||||
if (unit.Waiting) {
|
||||
unit.Anim = unit.WaitBackup;
|
||||
unit.Waiting = 0;
|
||||
}
|
||||
if (this->State == 1 && this->Range >= 5) {
|
||||
// failed to reach the goal
|
||||
this->State = 2;
|
||||
}
|
||||
|
||||
switch (this->State) {
|
||||
case 0: // Choose destination
|
||||
if (!this->HasGoal()) {
|
||||
|
@ -422,6 +446,10 @@ bool COrder_Unload::LeaveTransporter(CUnit &transporter)
|
|||
this->Finished = true;
|
||||
return ;
|
||||
}
|
||||
} else if (moveResult == PF_UNREACHABLE) {
|
||||
unit.Wait = 30;
|
||||
this->Range++;
|
||||
break;
|
||||
} else {
|
||||
this->State = 2;
|
||||
}
|
||||
|
|
|
@ -873,7 +873,7 @@ static void AiMoveUnitInTheWay(CUnit &unit)
|
|||
continue;
|
||||
}
|
||||
// Check for collision
|
||||
if (unit.MapDistanceTo(blocker) >= 2) {
|
||||
if (unit.MapDistanceTo(blocker) >= unit.Type->TileWidth + 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class COrder_Unload : public COrder
|
|||
{
|
||||
friend COrder *COrder::NewActionUnload(const Vec2i &pos, CUnit *what);
|
||||
public:
|
||||
COrder_Unload() : COrder(UnitActionUnload), State(0)
|
||||
COrder_Unload() : COrder(UnitActionUnload), State(0), Range(0)
|
||||
{
|
||||
goalPos.x = -1;
|
||||
goalPos.y = -1;
|
||||
|
@ -59,6 +59,7 @@ private:
|
|||
bool LeaveTransporter(CUnit &transporter);
|
||||
private:
|
||||
int State;
|
||||
int Range;
|
||||
Vec2i goalPos;
|
||||
};
|
||||
|
||||
|
|
|
@ -527,7 +527,7 @@ static int CostMoveToCallBack_Default(unsigned int index, const CUnit &unit)
|
|||
do {
|
||||
const int flag = mf->Flags & mask;
|
||||
if (flag && (AStarKnowUnseenTerrain || mf->playerInfo.IsExplored(*unit.Player))) {
|
||||
if (flag & ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit)) {
|
||||
if ((unit.Player->AiEnabled == false) && (flag & ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit))) {
|
||||
// we can't cross fixed units and other unpassable things
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue