1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00

Merge branch 'develop' into experimental/serializerrefactoring

This commit is contained in:
DjWarmonger
2014-12-22 19:17:40 +01:00
5 changed files with 23 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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

View File

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