- bugfixes to AI where workers harvesting think they have arrived but really did not.
This commit is contained in:
parent
d96bf7f978
commit
182f2cd20d
|
@ -125,7 +125,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos) {
|
|||
}
|
||||
|
||||
//route cache miss
|
||||
TravelState ts= aStar(unit, finalPos);
|
||||
TravelState ts= aStar(unit, finalPos, false);
|
||||
|
||||
//post actions
|
||||
switch(ts) {
|
||||
|
@ -142,7 +142,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos) {
|
|||
for(int bailoutY = -20; bailoutY <= 20 && ts == tsBlocked; ++bailoutY) {
|
||||
const Vec2i newFinalPos = finalPos + Vec2i(bailoutX,bailoutY);
|
||||
if(map->canMove(unit, unit->getPos(), newFinalPos)) {
|
||||
ts= aStar(unit, newFinalPos);
|
||||
ts= aStar(unit, newFinalPos, true);
|
||||
if(ts == tsMoving) {
|
||||
unit->setInBailOutAttempt(false);
|
||||
|
||||
|
@ -173,10 +173,10 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos) {
|
|||
throw runtime_error("unsupported or missing path finder detected!");
|
||||
}
|
||||
}
|
||||
else if(ts == tsArrived) {
|
||||
ts = aStar(unit, finalPos);
|
||||
break;
|
||||
}
|
||||
//else if(ts == tsArrived) {
|
||||
// ts = aStar(unit, finalPos, true);
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos) {
|
|||
// ==================== PRIVATE ====================
|
||||
|
||||
//route a unit using A* algorithm
|
||||
TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
|
||||
TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout) {
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
|
@ -237,6 +237,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
|
|||
const Vec2i finalPos= computeNearestFreePos(unit, targetPos);
|
||||
|
||||
//if arrived
|
||||
/*
|
||||
if(finalPos == unit->getPos()) {
|
||||
Command *command= unit->getCurrCommand();
|
||||
if(command == NULL || command->getPos() != unit->getPos()) {
|
||||
|
@ -247,12 +248,13 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
|
|||
commandDesc = command->getCommandType()->toString();
|
||||
}
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"State: arrived#2 at pos: %s, command [%s]",targetPos.getString().c_str(),commandDesc.c_str());
|
||||
sprintf(szBuf,"State: arrived#2 at pos: %s, command [%s] inBailout = %d",targetPos.getString().c_str(),commandDesc.c_str(),inBailout);
|
||||
unit->setCurrentUnitTitle(szBuf);
|
||||
}
|
||||
return tsArrived;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//path find algorithm
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ public:
|
|||
TravelState findPath(Unit *unit, const Vec2i &finalPos);
|
||||
|
||||
private:
|
||||
TravelState aStar(Unit *unit, const Vec2i &finalPos);
|
||||
TravelState aStar(Unit *unit, const Vec2i &finalPos, bool inBailout);
|
||||
Node *newNode();
|
||||
Vec2i computeNearestFreePos(const Unit *unit, const Vec2i &targetPos);
|
||||
float heuristic(const Vec2i &pos, const Vec2i &finalPos);
|
||||
|
|
|
@ -3788,8 +3788,12 @@ void Renderer::renderUnitTitles(Font2D *font, Vec3f color) {
|
|||
for(int idx = 0; idx < renderUnitTitleList.size(); idx++) {
|
||||
std::pair<Unit *,Vec3f> &unitInfo = renderUnitTitleList[idx];
|
||||
Unit *unit = unitInfo.first;
|
||||
if(unit != NULL && unitRenderedList.find(unit->getId()) == unitRenderedList.end()) {
|
||||
string str = unit->getFullName() + " - " + intToStr(unit->getId());
|
||||
|
||||
const World *world= game->getWorld();
|
||||
Unit *validUnit = world->findUnitById(unit->getId());
|
||||
|
||||
if(validUnit != NULL && unitRenderedList.find(validUnit->getId()) == unitRenderedList.end()) {
|
||||
string str = validUnit->getFullName() + " - " + intToStr(validUnit->getId());
|
||||
//get the screen coordinates
|
||||
Vec3f &screenPos = unitInfo.second;
|
||||
renderText(str, font, color, fabs(screenPos.x) + 5, fabs(screenPos.y) + 5, false);
|
||||
|
|
|
@ -458,22 +458,13 @@ void World::tick() {
|
|||
}
|
||||
}
|
||||
|
||||
Unit* World::findUnitById(int id){
|
||||
Unit* World::findUnitById(int id) const {
|
||||
for(int i= 0; i<getFactionCount(); ++i){
|
||||
Faction* faction= getFaction(i);
|
||||
const Faction* faction= getFaction(i);
|
||||
Unit* unit = faction->findUnit(id);
|
||||
if(unit != NULL) {
|
||||
return unit;
|
||||
}
|
||||
/*
|
||||
for(int j= 0; j<faction->getUnitCount(); ++j){
|
||||
Unit* unit= faction->getUnit(j);
|
||||
|
||||
if(unit->getId()==id){
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ public:
|
|||
|
||||
//misc
|
||||
void update();
|
||||
Unit* findUnitById(int id);
|
||||
Unit* findUnitById(int id) const;
|
||||
const UnitType* findUnitTypeById(const FactionType* factionType, int id);
|
||||
bool placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spaciated= false);
|
||||
void moveUnitCells(Unit *unit);
|
||||
|
|
Loading…
Reference in New Issue