MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / setPathTo

Method setPathTo

game/state/city/agentmission.cpp:478–507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476}
477
478void 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
509bool AgentMission::advanceAlongPath(GameState &state, Agent &a, Vec3<float> &destPos)
510{

Callers 1

startMethod · 0.95

Calls 4

endMethod · 0.80
emptyMethod · 0.80
clearMethod · 0.45
findShortestPathMethod · 0.45

Tested by

no test coverage detected