1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Merge pull request #214 from Chocimier/iss1975

Properly check if corpse was visited
This commit is contained in:
ArseniyShestakov 2016-09-23 06:26:10 +03:00 committed by GitHub
commit 50b271393c
3 changed files with 27 additions and 10 deletions

View File

@ -1068,9 +1068,10 @@ struct ChangeObjectVisitors : public CPackForClient // 1003
{
enum VisitMode
{
VISITOR_ADD, // mark hero as one that have visited this object
VISITOR_REMOVE, // unmark visitor, reversed to ADD
VISITOR_CLEAR // clear all visitors from this object (object reset)
VISITOR_ADD, // mark hero as one that have visited this object
VISITOR_ADD_TEAM, // mark team as one that have visited this object
VISITOR_REMOVE, // unmark visitor, reversed to ADD
VISITOR_CLEAR // clear all visitors from this object (object reset)
};
ui32 mode; // uses VisitMode enum
ObjectInstanceID object;

View File

@ -312,6 +312,15 @@ DLL_LINKAGE void ChangeObjectVisitors::applyGs( CGameState *gs )
gs->getHero(hero)->visitedObjects.insert(object);
gs->getPlayer(gs->getHero(hero)->tempOwner)->visitedObjects.insert(object);
break;
case VISITOR_ADD_TEAM:
{
TeamState *ts = gs->getPlayerTeam(gs->getHero(hero)->tempOwner);
for (auto & color : ts->players)
{
gs->getPlayer(color)->visitedObjects.insert(object);
}
}
break;
case VISITOR_CLEAR:
for (CGHeroInstance * hero : gs->map->allHeroes)
hero->visitedObjects.erase(object); // remove visit info from all heroes, including those that are not present on map

View File

@ -161,9 +161,15 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
grantRewardWithMessage(rewards[CRandomGenerator::getDefault().nextInt(rewards.size()-1)]);
break;
}
return;
break;
}
}
if (getAvailableRewards(h).size() == 0)
{
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id);
cb->sendAndApply(&cov);
}
}
else
{
@ -317,12 +323,8 @@ bool CRewardableObject::wasVisited(PlayerColor player) const
case VISIT_UNLIMITED:
case VISIT_BONUS:
return false;
case VISIT_ONCE: // FIXME: hide this info deeper and return same as player?
for (auto & visit : info)
{
if (visit.numOfGrants != 0)
return true;
}
case VISIT_ONCE:
return vstd::contains(cb->getPlayer(player)->visitedObjects, ObjectInstanceID(id));
case VISIT_HERO:
return false;
case VISIT_PLAYER:
@ -831,6 +833,7 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
info.resize(1);
loadRandomArtifact(rand, info[0], 10, 10, 10, 0);
info[0].message.addTxt(MetaString::ADVOB_TXT, 37);
info[0].limiter.numOfGrants = 1;
}
}
break;
@ -843,6 +846,7 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
int value = rand.nextInt(1, 4);
info[0].reward.resources[type] = value;
info[0].message.addTxt(MetaString::ADVOB_TXT, 64);
info[0].limiter.numOfGrants = 1;
}
break;
case Obj::WARRIORS_TOMB:
@ -856,6 +860,7 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
Bonus bonus(Bonus::ONE_BATTLE, Bonus::MORALE, Bonus::OBJECT, -3, ID);
info[0].reward.bonuses.push_back(bonus);
info[1].reward.bonuses.push_back(bonus);
info[0].limiter.numOfGrants = 1;
info[0].message.addTxt(MetaString::ADVOB_TXT, 162);
info[0].message.addReplacement(VLC->arth->artifacts[info[0].reward.artifacts.back()]->Name());
info[1].message.addTxt(MetaString::ADVOB_TXT, 163);
@ -872,6 +877,7 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
{
info.resize(1);
loadRandomArtifact(rand, info[0], 10, 10, 0, 0);
info[0].limiter.numOfGrants = 1;
info[0].message.addTxt(MetaString::ADVOB_TXT, 155);
}
else if(hlp < 90) //2 - 5 of non-gold resource
@ -880,6 +886,7 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
int type = rand.nextInt(5);
int value = rand.nextInt(2, 5);
info[0].reward.resources[type] = value;
info[0].limiter.numOfGrants = 1;
info[0].message.addTxt(MetaString::ADVOB_TXT, 154);
}
// or nothing