- some code cleanup related to supporting multiple path finders
This commit is contained in:
parent
74b6fc8139
commit
77ee50b681
|
@ -65,8 +65,8 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
|
||||||
return tsArrived;
|
return tsArrived;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if(path->isEmpty() == false) {
|
||||||
if(dynamic_cast<UnitPathBasic *>(path) != NULL) {
|
if(dynamic_cast<UnitPathBasic *>(path) != NULL) {
|
||||||
if(!path->isEmpty()) {
|
|
||||||
//route cache
|
//route cache
|
||||||
UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(path);
|
UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(path);
|
||||||
Vec2i pos= basicPath->pop();
|
Vec2i pos= basicPath->pop();
|
||||||
|
@ -75,23 +75,21 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){
|
||||||
return tsOnTheWay;
|
return tsOnTheWay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if(dynamic_cast<UnitPath *>(path) != NULL) {
|
else if(dynamic_cast<UnitPath *>(path) != NULL) {
|
||||||
UnitPath *advPath = dynamic_cast<UnitPath *>(path);
|
UnitPath *advPath = dynamic_cast<UnitPath *>(path);
|
||||||
if(advPath->isEmpty() == false) {
|
|
||||||
//route cache
|
//route cache
|
||||||
Vec2i pos= advPath->peek();
|
Vec2i pos= advPath->peek();
|
||||||
if(map->canMove(unit, unit->getPos(), pos)){
|
if(map->canMove(unit, unit->getPos(), pos)) {
|
||||||
advPath->pop();
|
advPath->pop();
|
||||||
unit->setTargetPos(pos);
|
unit->setTargetPos(pos);
|
||||||
return tsOnTheWay;
|
return tsOnTheWay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
throw runtime_error("unsupported or missing path finder detected!");
|
throw runtime_error("unsupported or missing path finder detected!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//route cache miss
|
//route cache miss
|
||||||
TravelState ts= aStar(unit, finalPos);
|
TravelState ts= aStar(unit, finalPos);
|
||||||
|
|
|
@ -51,6 +51,7 @@ void UnitUpdater::init(Game *game){
|
||||||
this->map= world->getMap();
|
this->map= world->getMap();
|
||||||
this->console= game->getConsole();
|
this->console= game->getConsole();
|
||||||
this->scriptManager= game->getScriptManager();
|
this->scriptManager= game->getScriptManager();
|
||||||
|
this->routePlanner = NULL;
|
||||||
|
|
||||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||||
case pfBasic:
|
case pfBasic:
|
||||||
|
@ -59,6 +60,8 @@ void UnitUpdater::init(Game *game){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
routePlanner = world->getRoutePlanner();
|
routePlanner = world->getRoutePlanner();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +208,8 @@ void UnitUpdater::updateMove(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
tsValue = routePlanner->findPath(unit, pos);
|
tsValue = routePlanner->findPath(unit, pos);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (tsValue) {
|
switch (tsValue) {
|
||||||
|
@ -264,6 +269,8 @@ void UnitUpdater::updateAttack(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
tsValue = routePlanner->findPath(unit, pos);
|
tsValue = routePlanner->findPath(unit, pos);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
//if unit arrives destPos order has ended
|
//if unit arrives destPos order has ended
|
||||||
|
@ -320,6 +327,8 @@ void UnitUpdater::updateBuild(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
tsValue = routePlanner->findPathToBuildSite(unit, ut, command->getPos(), command->getFacing());
|
tsValue = routePlanner->findPathToBuildSite(unit, ut, command->getPos(), command->getFacing());
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (tsValue) {
|
switch (tsValue) {
|
||||||
|
@ -340,6 +349,8 @@ void UnitUpdater::updateBuild(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
canOccupyCell = map->canOccupy(command->getPos(), ut->getField(), ut, command->getFacing());
|
canOccupyCell = map->canOccupy(command->getPos(), ut->getField(), ut, command->getFacing());
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canOccupyCell == true) {
|
if (canOccupyCell == true) {
|
||||||
|
@ -354,6 +365,8 @@ void UnitUpdater::updateBuild(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
newpath = new UnitPath();
|
newpath = new UnitPath();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit *builtUnit= new Unit(world->getNextUnitId(unit->getFaction()), newpath, command->getPos(), builtUnitType, unit->getFaction(), world->getMap(), facing);
|
Unit *builtUnit= new Unit(world->getNextUnitId(unit->getFaction()), newpath, command->getPos(), builtUnitType, unit->getFaction(), world->getMap(), facing);
|
||||||
|
@ -374,6 +387,8 @@ void UnitUpdater::updateBuild(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
world->getCartographer()->updateMapMetrics(builtUnit->getPos(), builtUnit->getType()->getSight());
|
world->getCartographer()->updateMapMetrics(builtUnit->getPos(), builtUnit->getType()->getSight());
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
command->setUnit(builtUnit);
|
command->setUnit(builtUnit);
|
||||||
|
@ -463,6 +478,8 @@ void UnitUpdater::updateHarvest(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
canHarvestDestPos = map->isResourceNear(unit->getPos(), unit->getType()->getSize(), r->getType(), targetPos);
|
canHarvestDestPos = map->isResourceNear(unit->getPos(), unit->getType()->getSize(), r->getType(), targetPos);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canHarvestDestPos == true) {
|
if (canHarvestDestPos == true) {
|
||||||
|
@ -479,6 +496,8 @@ void UnitUpdater::updateHarvest(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
unit->setLoadType(r->getType());
|
unit->setLoadType(r->getType());
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -498,6 +517,8 @@ void UnitUpdater::updateHarvest(Unit *unit){
|
||||||
unit->setCurrSkill(hct->getMoveSkillType());
|
unit->setCurrSkill(hct->getMoveSkillType());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -521,6 +542,8 @@ void UnitUpdater::updateHarvest(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
tsValue = routePlanner->findPathToStore(unit, store);
|
tsValue = routePlanner->findPathToStore(unit, store);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(tsValue) {
|
switch(tsValue) {
|
||||||
|
@ -588,6 +611,8 @@ void UnitUpdater::updateHarvest(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
world->getCartographer()->onResourceDepleted(Map::toSurfCoords(unit->getTargetPos()), rt);
|
world->getCartographer()->onResourceDepleted(Map::toSurfCoords(unit->getTargetPos()), rt);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
unit->setCurrSkill(hct->getStopLoadedSkillType());
|
unit->setCurrSkill(hct->getStopLoadedSkillType());
|
||||||
|
@ -642,6 +667,8 @@ void UnitUpdater::updateRepair(Unit *unit){
|
||||||
ts = routePlanner->findPath(unit, command->getPos());
|
ts = routePlanner->findPath(unit, command->getPos());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ts) {
|
switch(ts) {
|
||||||
|
@ -706,6 +733,8 @@ void UnitUpdater::updateProduce(Unit *unit){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
newpath = new UnitPath();
|
newpath = new UnitPath();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
produced= new Unit(world->getNextUnitId(unit->getFaction()), newpath, Vec2i(0), pct->getProducedUnit(), unit->getFaction(), world->getMap(), CardinalDir::NORTH);
|
produced= new Unit(world->getNextUnitId(unit->getFaction()), newpath, Vec2i(0), pct->getProducedUnit(), unit->getFaction(), world->getMap(), CardinalDir::NORTH);
|
||||||
|
@ -788,6 +817,8 @@ void UnitUpdater::updateMorph(Unit *unit){
|
||||||
oldSize = unit->getType()->getSize();
|
oldSize = unit->getType()->getSize();
|
||||||
needMapUpdate = unit->getType()->isMobile() != mct->getMorphUnit()->isMobile();
|
needMapUpdate = unit->getType()->isMobile() != mct->getMorphUnit()->isMobile();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
//finish the command
|
//finish the command
|
||||||
|
@ -805,6 +836,8 @@ void UnitUpdater::updateMorph(Unit *unit){
|
||||||
world->getCartographer()->updateMapMetrics(unit->getPos(), size);
|
world->getCartographer()->updateMapMetrics(unit->getPos(), size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
scriptManager->onUnitCreated(unit);
|
scriptManager->onUnitCreated(unit);
|
||||||
|
@ -884,6 +917,8 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
|
||||||
world->getCartographer()->updateMapMetrics(attacked->getPos(), attacked->getType()->getSize());
|
world->getCartographer()->updateMapMetrics(attacked->getPos(), attacked->getType()->getSize());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
scriptManager->onUnitDied(attacked);
|
scriptManager->onUnitDied(attacked);
|
||||||
}
|
}
|
||||||
|
|
|
@ -450,6 +450,8 @@ void World::createUnit(const string &unitName, int factionIndex, const Vec2i &po
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
newpath = new UnitPath();
|
newpath = new UnitPath();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit* unit= new Unit(getNextUnitId(faction), newpath, pos, ut, faction, &map, CardinalDir::NORTH);
|
Unit* unit= new Unit(getNextUnitId(faction), newpath, pos, ut, faction, &map, CardinalDir::NORTH);
|
||||||
|
@ -740,6 +742,8 @@ void World::initUnits(){
|
||||||
case pfRoutePlanner:
|
case pfRoutePlanner:
|
||||||
newpath = new UnitPath();
|
newpath = new UnitPath();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw runtime_error("detected unsupported pathfinder type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit *unit= new Unit(getNextUnitId(f), newpath, Vec2i(0), ut, f, &map, CardinalDir::NORTH);
|
Unit *unit= new Unit(getNextUnitId(f), newpath, Vec2i(0), ut, f, &map, CardinalDir::NORTH);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user