1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Marking visited for team

Also no longer gives reward every player
This commit is contained in:
Piotr Wójcik 2016-09-20 22:05:44 +02:00
parent 28d859419c
commit 97d358b70f
3 changed files with 27 additions and 15 deletions

View File

@ -1069,6 +1069,7 @@ struct ChangeObjectVisitors : public CPackForClient // 1003
enum VisitMode enum VisitMode
{ {
VISITOR_ADD, // mark hero as one that have visited this object 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_REMOVE, // unmark visitor, reversed to ADD
VISITOR_CLEAR // clear all visitors from this object (object reset) VISITOR_CLEAR // clear all visitors from this object (object reset)
}; };

View File

@ -312,6 +312,15 @@ DLL_LINKAGE void ChangeObjectVisitors::applyGs( CGameState *gs )
gs->getHero(hero)->visitedObjects.insert(object); gs->getHero(hero)->visitedObjects.insert(object);
gs->getPlayer(gs->getHero(hero)->tempOwner)->visitedObjects.insert(object); gs->getPlayer(gs->getHero(hero)->tempOwner)->visitedObjects.insert(object);
break; 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: case VISITOR_CLEAR:
for (CGHeroInstance * hero : gs->map->allHeroes) for (CGHeroInstance * hero : gs->map->allHeroes)
hero->visitedObjects.erase(object); // remove visit info from all heroes, including those that are not present on map 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)]); grantRewardWithMessage(rewards[CRandomGenerator::getDefault().nextInt(rewards.size()-1)]);
break; break;
} }
return; break;
} }
} }
if (getAvailableRewards(h).size() == 0)
{
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id);
cb->sendAndApply(&cov);
}
} }
else else
{ {
@ -317,12 +323,7 @@ bool CRewardableObject::wasVisited(PlayerColor player) const
case VISIT_UNLIMITED: case VISIT_UNLIMITED:
case VISIT_BONUS: case VISIT_BONUS:
return false; return false;
case VISIT_ONCE: // FIXME: hide this info deeper and return same as player? case VISIT_ONCE:
// for (auto & visit : info)
// {
// if (visit.numOfGrants != 0)
// return true;
// }
return vstd::contains(cb->getPlayer(player)->visitedObjects, ObjectInstanceID(id)); return vstd::contains(cb->getPlayer(player)->visitedObjects, ObjectInstanceID(id));
case VISIT_HERO: case VISIT_HERO:
return false; return false;
@ -827,15 +828,12 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
onEmpty.addTxt(MetaString::ADVOB_TXT, 38); onEmpty.addTxt(MetaString::ADVOB_TXT, 38);
soundID = soundBase::MYSTERY; soundID = soundBase::MYSTERY;
blockVisit = true; blockVisit = true;
info.resize(1);
if(rand.nextInt(99) < 20) if(rand.nextInt(99) < 20)
{ {
info.resize(1);
loadRandomArtifact(rand, info[0], 10, 10, 10, 0); loadRandomArtifact(rand, info[0], 10, 10, 10, 0);
info[0].message.addTxt(MetaString::ADVOB_TXT, 37); info[0].message.addTxt(MetaString::ADVOB_TXT, 37);
} info[0].limiter.numOfGrants = 1;
else
{
info[0].message.addTxt(MetaString::ADVOB_TXT, 38);
} }
} }
break; break;
@ -848,6 +846,7 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
int value = rand.nextInt(1, 4); int value = rand.nextInt(1, 4);
info[0].reward.resources[type] = value; info[0].reward.resources[type] = value;
info[0].message.addTxt(MetaString::ADVOB_TXT, 64); info[0].message.addTxt(MetaString::ADVOB_TXT, 64);
info[0].limiter.numOfGrants = 1;
} }
break; break;
case Obj::WARRIORS_TOMB: case Obj::WARRIORS_TOMB:
@ -861,6 +860,7 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
Bonus bonus(Bonus::ONE_BATTLE, Bonus::MORALE, Bonus::OBJECT, -3, ID); Bonus bonus(Bonus::ONE_BATTLE, Bonus::MORALE, Bonus::OBJECT, -3, ID);
info[0].reward.bonuses.push_back(bonus); info[0].reward.bonuses.push_back(bonus);
info[1].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.addTxt(MetaString::ADVOB_TXT, 162);
info[0].message.addReplacement(VLC->arth->artifacts[info[0].reward.artifacts.back()]->Name()); info[0].message.addReplacement(VLC->arth->artifacts[info[0].reward.artifacts.back()]->Name());
info[1].message.addTxt(MetaString::ADVOB_TXT, 163); info[1].message.addTxt(MetaString::ADVOB_TXT, 163);
@ -877,6 +877,7 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
{ {
info.resize(1); info.resize(1);
loadRandomArtifact(rand, info[0], 10, 10, 0, 0); loadRandomArtifact(rand, info[0], 10, 10, 0, 0);
info[0].limiter.numOfGrants = 1;
info[0].message.addTxt(MetaString::ADVOB_TXT, 155); info[0].message.addTxt(MetaString::ADVOB_TXT, 155);
} }
else if(hlp < 90) //2 - 5 of non-gold resource else if(hlp < 90) //2 - 5 of non-gold resource
@ -885,6 +886,7 @@ void CGOnceVisitable::initObj(CRandomGenerator & rand)
int type = rand.nextInt(5); int type = rand.nextInt(5);
int value = rand.nextInt(2, 5); int value = rand.nextInt(2, 5);
info[0].reward.resources[type] = value; info[0].reward.resources[type] = value;
info[0].limiter.numOfGrants = 1;
info[0].message.addTxt(MetaString::ADVOB_TXT, 154); info[0].message.addTxt(MetaString::ADVOB_TXT, 154);
} }
// or nothing // or nothing