Michał W. Urbańczyk 12 лет назад
Родитель
Сommit
d4c30667b8
2 измененных файлов с 9 добавлено и 8 удалено
  1. 5 5
      AI/VCAI/VCAI.cpp
  2. 4 3
      server/CGameHandler.cpp

+ 5 - 5
AI/VCAI/VCAI.cpp

@@ -3355,7 +3355,7 @@ TSubgoal CGoal::whatToDoToAchieve()
 					auto heroDummy = hero;
 					erase_if(otherHeroes, [heroDummy](const CGHeroInstance * h)
 					{
-						return (h == heroDummy.h || !ai->isAccessibleForHero(heroDummy->pos, h, true) || !ai->canGetArmy(heroDummy.h, h));
+						return (h == heroDummy.h || !ai->isAccessibleForHero(heroDummy->visitablePos(), h, true) || !ai->canGetArmy(heroDummy.h, h));
 					});
 					if (otherHeroes.size())
 					{
@@ -3363,9 +3363,9 @@ TSubgoal CGoal::whatToDoToAchieve()
 						int primaryPath, secondaryPath;
 						auto h = otherHeroes.back();
 						cb->setSelection(hero.h);
-						primaryPath = cb->getPathInfo(h->pos)->turns; //FIXME: investigate crash at this line
+						primaryPath = cb->getPathInfo(h->visitablePos())->turns;
 						cb->setSelection(h);
-						secondaryPath = cb->getPathInfo(hero->pos)->turns;
+						secondaryPath = cb->getPathInfo(hero->visitablePos())->turns;
 
 						if (primaryPath < secondaryPath)
 							return CGoal(VISIT_HERO).setisAbstract(true).setobjid(h->id).sethero(hero); //go to the other hero if we are faster
@@ -3533,7 +3533,7 @@ void SectorMap::exploreNewSector(crint3 pos, int num)
 						}
 					});
 					if(t->visitable && vstd::contains(ai->knownSubterraneanGates, t->visitableObjects.front()))
-						toVisit.push(ai->knownSubterraneanGates[t->visitableObjects.front()]->pos);
+						toVisit.push(ai->knownSubterraneanGates[t->visitableObjects.front()]->visitablePos());
 				}
 			}
 		}
@@ -3805,7 +3805,7 @@ int3 SectorMap::firstTileToGet(HeroPtr h, crint3 dst)
 					else
 					{
 						//TODO pick best shipyard to take over
-						return shipyards.front()->o->pos;
+						return shipyards.front()->o->visitablePos();
 					}
 				}
 			}

+ 4 - 3
server/CGameHandler.cpp

@@ -1918,19 +1918,20 @@ void CGameHandler::takeCreatures(int objid, const std::vector<CStackBasicDescrip
 		TQuantity collected = 0;
 		while(collected < sbd.count)
 		{
-			TSlots::const_iterator i = obj->Slots().begin();
-			for(; i != obj->Slots().end(); i++)
+			bool foundSth = false;
+			for(auto i = obj->Slots().begin(); i != obj->Slots().end(); i++)
 			{
 				if(i->second->type == sbd.type)
 				{
 					TQuantity take = std::min(sbd.count - collected, i->second->count); //collect as much cres as we can
 					changeStackCount(StackLocation(obj, i->first), -take, false);
 					collected += take;
+					foundSth = true;
 					break;
 				}
 			}
 
-			if(i ==  obj->Slots().end()) //we went through the whole loop and haven't found appropriate cres
+			if(!foundSth) //we went through the whole loop and haven't found appropriate cres
 			{
 				complain("Unexpected failure during taking creatures!");
 				return;