Browse Source

CPathfinder: rename cObj and dObjt to ctObj and dtObj

This way it's more clear that it's pointer to object on tile and not path node.
It's important because air layer nodes don't have visitable objects while tile under them can have one.
ArseniyShestakov 10 years ago
parent
commit
3185b64fb0
2 changed files with 23 additions and 23 deletions
  1. 22 22
      lib/CPathfinder.cpp
  2. 1 1
      lib/CPathfinder.h

+ 22 - 22
lib/CPathfinder.cpp

@@ -102,7 +102,7 @@ void CPathfinder::calculatePaths()
 		pq.pop();
 		pq.pop();
 		cp->locked = true;
 		cp->locked = true;
 		ct = &gs->map->getTile(cp->coord);
 		ct = &gs->map->getTile(cp->coord);
-		cObj = ct->topVisitableObj(isSourceInitialPosition());
+		ctObj = ct->topVisitableObj(isSourceInitialPosition());
 
 
 		int movement = cp->moveRemains, turn = cp->turns;
 		int movement = cp->moveRemains, turn = cp->turns;
 		hlp->updateTurnInfo(turn);
 		hlp->updateTurnInfo(turn);
@@ -117,7 +117,7 @@ void CPathfinder::calculatePaths()
 		for(auto & neighbour : neighbours)
 		for(auto & neighbour : neighbours)
 		{
 		{
 			dt = &gs->map->getTile(neighbour);
 			dt = &gs->map->getTile(neighbour);
-			dObj = dt->topVisitableObj();
+			dtObj = dt->topVisitableObj();
 			for(ELayer i = ELayer::LAND; i <= ELayer::AIR; i.advance(1))
 			for(ELayer i = ELayer::LAND; i <= ELayer::AIR; i.advance(1))
 			{
 			{
 				dp = out.getNode(neighbour, i);
 				dp = out.getNode(neighbour, i);
@@ -201,7 +201,7 @@ void CPathfinder::addNeighbours(const int3 & coord)
 	{
 	{
 		for(int3 tile: tiles)
 		for(int3 tile: tiles)
 		{
 		{
-			if(canMoveBetween(tile, cObj->visitablePos()))
+			if(canMoveBetween(tile, ctObj->visitablePos()))
 				neighbours.push_back(tile);
 				neighbours.push_back(tile);
 		}
 		}
 	}
 	}
@@ -235,7 +235,7 @@ void CPathfinder::addTeleportExits(bool noTeleportExcludes)
 		return false;
 		return false;
 	};
 	};
 
 
-	const CGTeleport * sTileTeleport = dynamic_cast<const CGTeleport *>(cObj);
+	const CGTeleport * sTileTeleport = dynamic_cast<const CGTeleport *>(ctObj);
 	if(isAllowedTeleportEntrance(sTileTeleport))
 	if(isAllowedTeleportEntrance(sTileTeleport))
 	{
 	{
 		for(auto objId : gs->getTeleportChannelExits(sTileTeleport->channel, hero->tempOwner))
 		for(auto objId : gs->getTeleportChannelExits(sTileTeleport->channel, hero->tempOwner))
@@ -256,15 +256,15 @@ void CPathfinder::addTeleportExits(bool noTeleportExcludes)
 	}
 	}
 
 
 	if(options.useCastleGate
 	if(options.useCastleGate
-		&& (cObj->ID == Obj::TOWN && cObj->subID == ETownType::INFERNO
-		&& getPlayerRelations(hero->tempOwner, cObj->tempOwner) != PlayerRelations::ENEMIES))
+		&& (ctObj->ID == Obj::TOWN && ctObj->subID == ETownType::INFERNO
+		&& getPlayerRelations(hero->tempOwner, ctObj->tempOwner) != PlayerRelations::ENEMIES))
 	{
 	{
 		/// TODO: Find way to reuse CPlayerSpecificInfoCallback::getTownsInfo
 		/// TODO: Find way to reuse CPlayerSpecificInfoCallback::getTownsInfo
 		/// This may be handy if we allow to use teleportation to friendly towns
 		/// This may be handy if we allow to use teleportation to friendly towns
 		auto towns = gs->getPlayer(hero->tempOwner)->towns;
 		auto towns = gs->getPlayer(hero->tempOwner)->towns;
 		for(const auto & town : towns)
 		for(const auto & town : towns)
 		{
 		{
-			if(town->id != cObj->id && town->visitingHero == nullptr
+			if(town->id != ctObj->id && town->visitingHero == nullptr
 				&& town->hasBuilt(BuildingID::CASTLE_GATE, ETownType::INFERNO))
 				&& town->hasBuilt(BuildingID::CASTLE_GATE, ETownType::INFERNO))
 			{
 			{
 				neighbours.push_back(town->visitablePos());
 				neighbours.push_back(town->visitablePos());
@@ -374,13 +374,13 @@ bool CPathfinder::isMovementToDestPossible() const
 
 
 		if(cp->layer == ELayer::LAND)
 		if(cp->layer == ELayer::LAND)
 		{
 		{
-			if(!dObj)
+			if(!dtObj)
 				return false;
 				return false;
 
 
-			if(dObj->ID != Obj::BOAT && dObj->ID != Obj::HERO)
+			if(dtObj->ID != Obj::BOAT && dtObj->ID != Obj::HERO)
 				return false;
 				return false;
 		}
 		}
-		else if(dObj && dObj->ID == Obj::BOAT)
+		else if(dtObj && dtObj->ID == Obj::BOAT)
 		{
 		{
 			/// Hero in boat can't visit empty boats
 			/// Hero in boat can't visit empty boats
 			return false;
 			return false;
@@ -409,11 +409,11 @@ bool CPathfinder::isMovementAfterDestPossible() const
 	case CGPathNode::VISIT:
 	case CGPathNode::VISIT:
 		/// For now we only add visitable tile into queue when it's teleporter that allow transit
 		/// For now we only add visitable tile into queue when it's teleporter that allow transit
 		/// Movement from visitable tile when hero is standing on it is possible into any layer
 		/// Movement from visitable tile when hero is standing on it is possible into any layer
-		if(CGTeleport::isTeleport(dObj))
+		if(CGTeleport::isTeleport(dtObj))
 		{
 		{
 			/// For now we'll always allow transit over teleporters
 			/// For now we'll always allow transit over teleporters
 			/// Transit over whirlpools only allowed when hero protected
 			/// Transit over whirlpools only allowed when hero protected
-			auto whirlpool = dynamic_cast<const CGWhirlpool *>(dObj);
+			auto whirlpool = dynamic_cast<const CGWhirlpool *>(dtObj);
 			if(!whirlpool || options.useTeleportWhirlpool)
 			if(!whirlpool || options.useTeleportWhirlpool)
 				return true;
 				return true;
 		}
 		}
@@ -460,34 +460,34 @@ CGPathNode::ENodeAction CPathfinder::getDestAction() const
 		}
 		}
 
 
 	case ELayer::SAIL:
 	case ELayer::SAIL:
-		if(dObj)
+		if(dtObj)
 		{
 		{
-			auto objRel = getPlayerRelations(dObj->tempOwner, hero->tempOwner);
+			auto objRel = getPlayerRelations(dtObj->tempOwner, hero->tempOwner);
 
 
-			if(dObj->ID == Obj::BOAT)
+			if(dtObj->ID == Obj::BOAT)
 				action = CGPathNode::EMBARK;
 				action = CGPathNode::EMBARK;
-			else if(dObj->ID == Obj::HERO)
+			else if(dtObj->ID == Obj::HERO)
 			{
 			{
 				if(objRel == PlayerRelations::ENEMIES)
 				if(objRel == PlayerRelations::ENEMIES)
 					action = CGPathNode::BATTLE;
 					action = CGPathNode::BATTLE;
 				else
 				else
 					action = CGPathNode::BLOCKING_VISIT;
 					action = CGPathNode::BLOCKING_VISIT;
 			}
 			}
-			else if(dObj->ID == Obj::TOWN && objRel == PlayerRelations::ENEMIES)
+			else if(dtObj->ID == Obj::TOWN && objRel == PlayerRelations::ENEMIES)
 			{
 			{
-				const CGTownInstance * townObj = dynamic_cast<const CGTownInstance *>(dObj);
+				const CGTownInstance * townObj = dynamic_cast<const CGTownInstance *>(dtObj);
 				if(townObj->armedGarrison())
 				if(townObj->armedGarrison())
 					action = CGPathNode::BATTLE;
 					action = CGPathNode::BATTLE;
 			}
 			}
-			else if(dObj->ID == Obj::GARRISON || dObj->ID == Obj::GARRISON2)
+			else if(dtObj->ID == Obj::GARRISON || dtObj->ID == Obj::GARRISON2)
 			{
 			{
-				const CGGarrison * garrisonObj = dynamic_cast<const CGGarrison *>(dObj);
+				const CGGarrison * garrisonObj = dynamic_cast<const CGGarrison *>(dtObj);
 				if((garrisonObj->stacksCount() && objRel == PlayerRelations::ENEMIES) || isDestinationGuarded(true))
 				if((garrisonObj->stacksCount() && objRel == PlayerRelations::ENEMIES) || isDestinationGuarded(true))
 					action = CGPathNode::BATTLE;
 					action = CGPathNode::BATTLE;
 			}
 			}
 			else if(isDestinationGuardian())
 			else if(isDestinationGuardian())
 				action = CGPathNode::BATTLE;
 				action = CGPathNode::BATTLE;
-			else if(dObj->blockVisit && (!options.useCastleGate || dObj->ID != Obj::TOWN))
+			else if(dtObj->blockVisit && (!options.useCastleGate || dtObj->ID != Obj::TOWN))
 				action = CGPathNode::BLOCKING_VISIT;
 				action = CGPathNode::BLOCKING_VISIT;
 
 
 			if(action == CGPathNode::NORMAL)
 			if(action == CGPathNode::NORMAL)
@@ -515,7 +515,7 @@ bool CPathfinder::isSourceInitialPosition() const
 bool CPathfinder::isSourceVisitableObj() const
 bool CPathfinder::isSourceVisitableObj() const
 {
 {
 	/// Hero can't visit objects while walking on water or flying
 	/// Hero can't visit objects while walking on water or flying
-	return cObj != nullptr && (cp->layer == ELayer::LAND || cp->layer == ELayer::SAIL);
+	return ctObj != nullptr && (cp->layer == ELayer::LAND || cp->layer == ELayer::SAIL);
 }
 }
 
 
 bool CPathfinder::isSourceGuarded() const
 bool CPathfinder::isSourceGuarded() const

+ 1 - 1
lib/CPathfinder.h

@@ -160,7 +160,7 @@ private:
 	CGPathNode * cp; //current (source) path node -> we took it from the queue
 	CGPathNode * cp; //current (source) path node -> we took it from the queue
 	CGPathNode * dp; //destination node -> it's a neighbour of cp that we consider
 	CGPathNode * dp; //destination node -> it's a neighbour of cp that we consider
 	const TerrainTile * ct, * dt; //tile info for both nodes
 	const TerrainTile * ct, * dt; //tile info for both nodes
-	const CGObjectInstance * cObj, * dObj;
+	const CGObjectInstance * ctObj, * dtObj;
 	CGPathNode::ENodeAction destAction;
 	CGPathNode::ENodeAction destAction;
 
 
 	void addNeighbours(const int3 & coord);
 	void addNeighbours(const int3 & coord);