Przeglądaj źródła

Merge branch 'develop' into experimental/serializerrefactoring

DjWarmonger 10 lat temu
rodzic
commit
7735e193f0

+ 14 - 3
AI/VCAI/Goals.cpp

@@ -369,6 +369,9 @@ TSubgoal GetObj::whatToDoToAchieve()
 	const CGObjectInstance * obj = cb->getObj(ObjectInstanceID(objid));
 	if(!obj)
 		return sptr (Goals::Explore());
+	if (obj->tempOwner == ai->playerID) //we can't capture our own object -> move to Win codition
+		throw cannotFulfillGoalException("Cannot capture my own object " + obj->getObjectName());
+
 	int3 pos = obj->visitablePos();
 	if (hero)
 	{
@@ -377,8 +380,11 @@ TSubgoal GetObj::whatToDoToAchieve()
 	}
 	else
 	{
-		if (ai->isAccessible(obj->pos))
-			return sptr (Goals::VisitTile(pos).sethero(hero)); //we must visit object with same hero, if any
+		for (auto h : cb->getHeroesInfo())
+		{
+			if (ai->isAccessibleForHero(pos, h))
+				return sptr(Goals::VisitTile(pos).sethero(h)); //we must visit object with same hero, if any
+		}
 	}
 	return sptr (Goals::ClearWayTo(pos).sethero(hero));
 }
@@ -709,7 +715,12 @@ TGoalVec VisitTile::getAllPossibleSubgoals()
 	{
 		auto obj = frontOrNull(cb->getVisitableObjs(tile));
 		if (obj && obj->ID == Obj::HERO && obj->tempOwner == ai->playerID) //our own hero stands on that tile
-			ret.push_back (sptr(Goals::VisitTile(tile).sethero(dynamic_cast<const CGHeroInstance *>(obj)).setisElementar(true)));
+		{
+			if (hero.get(true) && hero->id == obj->id) //if it's assigned hero, visit tile. If it's different hero, we can't visit tile now
+				ret.push_back(sptr(Goals::VisitTile(tile).sethero(dynamic_cast<const CGHeroInstance *>(obj)).setisElementar(true)));
+			else
+				throw cannotFulfillGoalException("Tile is already occupied by another hero "); //FIXME: we should give up this tile earlier
+		}
 		else
 			ret.push_back (sptr(Goals::ClearWayTo(tile)));
 	}

+ 1 - 1
client/widgets/AdventureMapClasses.cpp

@@ -479,7 +479,7 @@ void CMinimapInstance::showAll(SDL_Surface *to)
 	blitAtLoc(minimap, 0, 0, to);
 
 	//draw heroes
-	std::vector <const CGHeroInstance *> heroes = LOCPLINT->cb->getHeroesInfo(false);
+	std::vector <const CGHeroInstance *> heroes = LOCPLINT->cb->getHeroesInfo(false); //TODO: do we really need separate function for drawing heroes? 
 	for(auto & hero : heroes)
 	{
 		int3 position = hero->getPosition(false);

+ 3 - 2
lib/CGameInfoCallback.cpp

@@ -108,7 +108,7 @@ const CGObjectInstance* CGameInfoCallback::getObj(ObjectInstanceID objid, bool v
 		return nullptr;
 	}
 
-	if(!isVisible(ret, player))
+	if(!isVisible(ret, player) && ret->tempOwner != player)
 	{
 		if(verbose)
             logGlobal->errorStream() << "Cannot get object with id " << oid << ". Object is not visible.";
@@ -525,7 +525,8 @@ std::vector < const CGHeroInstance *> CPlayerSpecificInfoCallback::getHeroesInfo
 	std::vector < const CGHeroInstance *> ret;
 	for(auto hero : gs->map->heroesOnMap)
 	{
-		if( !player || (hero->tempOwner == *player) ||
+		// !player || // - why would we even get access to hero not owned by any player?
+		if((hero->tempOwner == *player) ||
 			(isVisible(hero->getPosition(false), player) && !onlyOur)	)
 		{
 			ret.push_back(hero);

+ 4 - 0
lib/CGameState.cpp

@@ -2240,6 +2240,10 @@ bool CGameState::isVisible( const CGObjectInstance *obj, boost::optional<PlayerC
 	if(!player)
 		return true;
 
+	//we should always see our own heroes - but sometimes not visible heroes cause crash :?
+	if (player == obj->tempOwner)
+		return true;
+
 	if(*player == PlayerColor::NEUTRAL) //-> TODO ??? needed?
 		return false;
 	//object is visible when at least one blocked tile is visible

+ 1 - 1
server/CGameHandler.cpp

@@ -2887,7 +2887,7 @@ bool CGameHandler::buyArtifact( ObjectInstanceID hid, ArtifactID aid )
 			return false;
 
 		giveResource(hero->getOwner(),Res::GOLD,-GameConstants::SPELLBOOK_GOLD_COST);
-		giveHeroNewArtifact(hero, VLC->arth->artifacts[0], ArtifactPosition::SPELLBOOK);
+		giveHeroNewArtifact(hero, VLC->arth->artifacts[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK);
 		assert(hero->getArt(ArtifactPosition::SPELLBOOK));
 		giveSpells(town,hero);
 		return true;