Browse Source

Players will be always able to see their owned heroes and other objects. Fixes #1959.

DjWarmonger 10 years ago
parent
commit
c538370c5d

+ 1 - 1
client/widgets/AdventureMapClasses.cpp

@@ -479,7 +479,7 @@ void CMinimapInstance::showAll(SDL_Surface *to)
 	blitAtLoc(minimap, 0, 0, to);
 	blitAtLoc(minimap, 0, 0, to);
 
 
 	//draw heroes
 	//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)
 	for(auto & hero : heroes)
 	{
 	{
 		int3 position = hero->getPosition(false);
 		int3 position = hero->getPosition(false);

+ 3 - 2
lib/CGameInfoCallback.cpp

@@ -108,7 +108,7 @@ const CGObjectInstance* CGameInfoCallback::getObj(ObjectInstanceID objid, bool v
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
-	if(!isVisible(ret, player))
+	if(!isVisible(ret, player) && ret->tempOwner != player)
 	{
 	{
 		if(verbose)
 		if(verbose)
             logGlobal->errorStream() << "Cannot get object with id " << oid << ". Object is not visible.";
             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;
 	std::vector < const CGHeroInstance *> ret;
 	for(auto hero : gs->map->heroesOnMap)
 	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)	)
 			(isVisible(hero->getPosition(false), player) && !onlyOur)	)
 		{
 		{
 			ret.push_back(hero);
 			ret.push_back(hero);

+ 4 - 0
lib/CGameState.cpp

@@ -2240,6 +2240,10 @@ bool CGameState::isVisible( const CGObjectInstance *obj, boost::optional<PlayerC
 	if(!player)
 	if(!player)
 		return true;
 		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?
 	if(*player == PlayerColor::NEUTRAL) //-> TODO ??? needed?
 		return false;
 		return false;
 	//object is visible when at least one blocked tile is visible
 	//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;
 			return false;
 
 
 		giveResource(hero->getOwner(),Res::GOLD,-GameConstants::SPELLBOOK_GOLD_COST);
 		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));
 		assert(hero->getArt(ArtifactPosition::SPELLBOOK));
 		giveSpells(town,hero);
 		giveSpells(town,hero);
 		return true;
 		return true;