1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

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

This commit is contained in:
DjWarmonger
2014-12-21 13:56:32 +01:00
parent af02655b30
commit c538370c5d
4 changed files with 9 additions and 4 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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

View File

@@ -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;