| 476 | } |
| 477 | |
| 478 | void AgentMission::setPathTo(GameState &state [[maybe_unused]], Agent &a, StateRef<Building> b) |
| 479 | { |
| 480 | this->currentPlannedPath.clear(); |
| 481 | auto &map = *a.city->map; |
| 482 | |
| 483 | std::list<Vec3<int>> path; |
| 484 | auto key = Vec3<int>{(Vec3<int>)a.position * map.size + b->crewQuarters}; |
| 485 | if (map.agentPathCache.find(key) != map.agentPathCache.end()) |
| 486 | { |
| 487 | LogWarning("Found cached path from %s to %s, using it", a.position, b->crewQuarters); |
| 488 | path = map.agentPathCache[key]; |
| 489 | } |
| 490 | else |
| 491 | { |
| 492 | path = map.findShortestPath(a.position, b->crewQuarters, 2000, AgentTileHelper{map}); |
| 493 | map.agentPathCache[key] = path; |
| 494 | } |
| 495 | if (path.empty() || path.back() != b->crewQuarters) |
| 496 | { |
| 497 | cancelled = true; |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | // Always start with the current position |
| 502 | this->currentPlannedPath.push_back(a.position); |
| 503 | for (auto &p : path) |
| 504 | { |
| 505 | this->currentPlannedPath.push_back(p); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | bool AgentMission::advanceAlongPath(GameState &state, Agent &a, Vec3<float> &destPos) |
| 510 | { |
no test coverage detected