| 414 | } |
| 415 | |
| 416 | bool BaseAI::digWayToTile(Tile* tileStart, Tile* tileEnd) |
| 417 | { |
| 418 | // We find a way to tileEnd. We search in reverse order to stop when we reach the first |
| 419 | // accessible tile |
| 420 | |
| 421 | // Set a diggable path up to the first gold spot for the given team color, by the first available worker |
| 422 | Seat* seat = mPlayer.getSeat(); |
| 423 | Creature* worker = mGameMap.getWorkerForPathFinding(seat); |
| 424 | if (worker == nullptr) |
| 425 | return false; |
| 426 | |
| 427 | std::list<Tile*> pathToDig = mGameMap.path(tileEnd, tileStart, worker, seat, true); |
| 428 | if (pathToDig.empty()) |
| 429 | return false; |
| 430 | |
| 431 | // We search for the first reachable tile in the list |
| 432 | bool isPathFound = false; |
| 433 | for(std::list<Tile*>::iterator it = pathToDig.begin(); it != pathToDig.end();) |
| 434 | { |
| 435 | Tile* tile = *it; |
| 436 | if(!isPathFound && |
| 437 | (tile->getFullness() == 0.0) && |
| 438 | (mGameMap.pathExists(worker, tileStart, tile))) |
| 439 | { |
| 440 | isPathFound = true; |
| 441 | } |
| 442 | |
| 443 | if(isPathFound) |
| 444 | { |
| 445 | it = pathToDig.erase(it); |
| 446 | continue; |
| 447 | } |
| 448 | |
| 449 | // If the tile should be dug, we check if one of its neighboors can be reached. |
| 450 | // If yes, we will stop after digging it to avoid digging through a wall as much as |
| 451 | // possible |
| 452 | for(Tile* t : tile->getAllNeighbors()) |
| 453 | { |
| 454 | if(!isPathFound && |
| 455 | (t->getFullness() == 0.0) && |
| 456 | (mGameMap.pathExists(worker, tileStart, t))) |
| 457 | { |
| 458 | // we let the iterator increment because we want to dig the currently |
| 459 | // tested tile |
| 460 | isPathFound = true; |
| 461 | break; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | ++it; |
| 466 | } |
| 467 | |
| 468 | for(Tile* tile : pathToDig) |
| 469 | { |
| 470 | if (tile && tile->isDiggable(seat)) |
| 471 | tile->setMarkedForDigging(true, &mPlayer); |
| 472 | } |
| 473 |
nothing calls this directly
no test coverage detected