2014-04-06 23:14:26 +03:00
|
|
|
/*
|
2014-06-05 14:19:47 +03:00
|
|
|
* CRewardableObject.cpp, part of VCMI engine
|
2014-04-06 23:14:26 +03:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
2014-06-05 14:19:47 +03:00
|
|
|
#include "CRewardableObject.h"
|
2014-06-05 20:26:50 +03:00
|
|
|
#include "../CHeroHandler.h"
|
|
|
|
#include "../CGeneralTextHandler.h"
|
2014-06-05 23:51:24 +03:00
|
|
|
#include "../CSoundBase.h"
|
2014-06-05 20:26:50 +03:00
|
|
|
#include "../NetPacks.h"
|
2014-06-25 17:11:07 +03:00
|
|
|
#include "../IGameCallback.h"
|
|
|
|
#include "../CGameState.h"
|
2015-12-02 21:39:53 +02:00
|
|
|
#include "../CPlayerState.h"
|
2014-04-06 23:14:26 +03:00
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
#include "CObjectClassesHandler.h"
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
bool CRewardLimiter::heroAllowed(const CGHeroInstance * hero) const
|
|
|
|
{
|
2016-02-01 08:41:15 +02:00
|
|
|
if(dayOfWeek != 0)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
if (IObjectInterface::cb->getDate(Date::DAY_OF_WEEK) != dayOfWeek)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
for(auto & reqStack : creatures)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
size_t count = 0;
|
|
|
|
for (auto slot : hero->Slots())
|
|
|
|
{
|
|
|
|
const CStackInstance * heroStack = slot.second;
|
|
|
|
if (heroStack->type == reqStack.type)
|
|
|
|
count += heroStack->count;
|
|
|
|
}
|
|
|
|
if (count < reqStack.count) //not enough creatures of this kind
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
if(!IObjectInterface::cb->getPlayer(hero->tempOwner)->resources.canAfford(resources))
|
2014-04-06 23:14:26 +03:00
|
|
|
return false;
|
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
if(minLevel > (si32)hero->level)
|
2014-04-06 23:14:26 +03:00
|
|
|
return false;
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
for(size_t i=0; i<primary.size(); i++)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2014-04-07 20:32:15 +03:00
|
|
|
if (primary[i] > hero->getPrimSkillLevel(PrimarySkill::PrimarySkill(i)))
|
2014-04-06 23:14:26 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
for(auto & skill : secondary)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2014-04-07 20:32:15 +03:00
|
|
|
if (skill.second > hero->getSecSkillLevel(skill.first))
|
2014-04-06 23:14:26 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
for(auto & art : artifacts)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
if (!hero->hasArt(art))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
std::vector<ui32> CRewardableObject::getAvailableRewards(const CGHeroInstance * hero) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
std::vector<ui32> ret;
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
for(size_t i=0; i<info.size(); i++)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
const CVisitInfo & visit = info[i];
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
if((visit.limiter.numOfGrants == 0 || visit.numOfGrants < visit.limiter.numOfGrants) // reward has unlimited uses or some are still available
|
2014-06-29 20:13:25 +03:00
|
|
|
&& visit.limiter.heroAllowed(hero))
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->trace("Reward %d is allowed", i);
|
2020-10-01 10:38:06 +02:00
|
|
|
ret.push_back(static_cast<ui32>(i));
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-30 22:51:21 +02:00
|
|
|
CVisitInfo CRewardableObject::getVisitInfo(int index, const CGHeroInstance *) const
|
|
|
|
{
|
|
|
|
return info[index];
|
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2014-04-11 20:38:27 +03:00
|
|
|
auto grantRewardWithMessage = [&](int index) -> void
|
|
|
|
{
|
2016-01-30 22:51:21 +02:00
|
|
|
auto vi = getVisitInfo(index, h);
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->debug("Granting reward %d. Message says: %s", index, vi.message.toString());
|
2014-04-11 22:49:25 +03:00
|
|
|
// show message only if it is not empty
|
2016-01-30 22:51:21 +02:00
|
|
|
if (!vi.message.toString().empty())
|
2014-04-11 22:49:25 +03:00
|
|
|
{
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = h->tempOwner;
|
2016-01-30 22:51:21 +02:00
|
|
|
iw.text = vi.message;
|
|
|
|
vi.reward.loadComponents(iw.components, h);
|
2014-04-11 22:49:25 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
2014-06-28 17:19:53 +03:00
|
|
|
// grant reward afterwards. Note that it may remove object
|
|
|
|
grantReward(index, h);
|
2014-04-11 20:38:27 +03:00
|
|
|
};
|
2014-04-12 14:47:20 +03:00
|
|
|
auto selectRewardsMessage = [&](std::vector<ui32> rewards) -> void
|
|
|
|
{
|
|
|
|
BlockingDialog sd(canRefuse, rewards.size() > 1);
|
|
|
|
sd.player = h->tempOwner;
|
|
|
|
sd.text = onSelect;
|
|
|
|
for (auto index : rewards)
|
2016-01-30 22:51:21 +02:00
|
|
|
sd.components.push_back(getVisitInfo(index, h).reward.getDisplayedComponent(h));
|
2014-04-12 14:47:20 +03:00
|
|
|
cb->showBlockingDialog(&sd);
|
|
|
|
};
|
2014-04-11 20:38:27 +03:00
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
if(!wasVisited(h))
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
auto rewards = getAvailableRewards(h);
|
2016-09-23 10:47:07 +02:00
|
|
|
bool objectRemovalPossible = false;
|
|
|
|
for(auto index : rewards)
|
|
|
|
{
|
|
|
|
if(getVisitInfo(index, h).reward.removeObject)
|
|
|
|
objectRemovalPossible = true;
|
|
|
|
}
|
|
|
|
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->debug("Visiting object with %d possible rewards", rewards.size());
|
2014-04-06 23:14:26 +03:00
|
|
|
switch (rewards.size())
|
|
|
|
{
|
2014-04-11 20:38:27 +03:00
|
|
|
case 0: // no available rewards, e.g. empty flotsam
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = h->tempOwner;
|
2014-04-11 22:49:25 +03:00
|
|
|
if (!onEmpty.toString().empty())
|
|
|
|
iw.text = onEmpty;
|
|
|
|
else
|
|
|
|
iw.text = onVisited;
|
2014-04-06 23:14:26 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1: // one reward. Just give it with message
|
|
|
|
{
|
2014-04-12 14:47:20 +03:00
|
|
|
if (canRefuse)
|
|
|
|
selectRewardsMessage(rewards);
|
|
|
|
else
|
|
|
|
grantRewardWithMessage(rewards[0]);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
}
|
2014-04-11 20:38:27 +03:00
|
|
|
default: // multiple rewards. Act according to select mode
|
|
|
|
{
|
|
|
|
switch (selectMode) {
|
|
|
|
case SELECT_PLAYER: // player must select
|
2014-04-12 14:47:20 +03:00
|
|
|
selectRewardsMessage(rewards);
|
2014-04-11 20:38:27 +03:00
|
|
|
break;
|
|
|
|
case SELECT_FIRST: // give first available
|
|
|
|
grantRewardWithMessage(rewards[0]);
|
|
|
|
break;
|
2014-05-24 01:56:51 +03:00
|
|
|
case SELECT_RANDOM: // select one randomly //TODO: use weights
|
2020-10-01 10:38:06 +02:00
|
|
|
grantRewardWithMessage(rewards[CRandomGenerator::getDefault().nextInt((int)rewards.size()-1)]);
|
2014-04-11 20:38:27 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-09-20 22:05:44 +02:00
|
|
|
break;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-20 22:05:44 +02:00
|
|
|
|
2016-09-23 10:47:07 +02:00
|
|
|
if(!objectRemovalPossible && getAvailableRewards(h).size() == 0)
|
2016-09-20 22:05:44 +02:00
|
|
|
{
|
|
|
|
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id);
|
|
|
|
cb->sendAndApply(&cov);
|
|
|
|
}
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->debug("Revisiting already visited object");
|
2014-04-06 23:14:26 +03:00
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = h->tempOwner;
|
2014-04-11 22:49:25 +03:00
|
|
|
if (!onVisited.toString().empty())
|
|
|
|
iw.text = onVisited;
|
|
|
|
else
|
|
|
|
iw.text = onEmpty;
|
2014-04-06 23:14:26 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
void CRewardableObject::heroLevelUpDone(const CGHeroInstance *hero) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-01-30 22:51:21 +02:00
|
|
|
grantRewardAfterLevelup(getVisitInfo(selectedReward, hero), hero);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
void CRewardableObject::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-02-01 08:41:15 +02:00
|
|
|
if(answer == 0)
|
2014-04-11 20:38:27 +03:00
|
|
|
return; // player refused
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
if(answer > 0 && answer-1 < info.size())
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
auto list = getAvailableRewards(hero);
|
2014-04-11 20:38:27 +03:00
|
|
|
grantReward(list[answer - 1], hero);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Unhandled choice");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
void CRewardableObject::onRewardGiven(const CGHeroInstance * hero) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
// no implementation, virtual function for overrides
|
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
void CRewardableObject::grantReward(ui32 rewardID, const CGHeroInstance * hero) const
|
2014-04-11 20:38:27 +03:00
|
|
|
{
|
|
|
|
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD, id, hero->id);
|
|
|
|
cb->sendAndApply(&cov);
|
|
|
|
cb->setObjProperty(id, ObjProperty::REWARD_SELECT, rewardID);
|
|
|
|
|
2016-01-30 22:51:21 +02:00
|
|
|
grantRewardBeforeLevelup(getVisitInfo(rewardID, hero), hero);
|
2014-04-11 20:38:27 +03:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
void CRewardableObject::grantRewardBeforeLevelup(const CVisitInfo & info, const CGHeroInstance * hero) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
assert(hero);
|
|
|
|
assert(hero->tempOwner.isValidPlayer());
|
|
|
|
assert(stacks.empty());
|
|
|
|
assert(info.reward.creatures.size() <= GameConstants::ARMY_SIZE);
|
|
|
|
assert(!cb->isVisitCoveredByAnotherQuery(this, hero));
|
|
|
|
|
|
|
|
cb->giveResources(hero->tempOwner, info.reward.resources);
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
for(auto & entry : info.reward.secondary)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
int current = hero->getSecSkillLevel(entry.first);
|
|
|
|
if( (current != 0 && current < entry.second) ||
|
|
|
|
(hero->canLearnSkill() ))
|
|
|
|
{
|
|
|
|
cb->changeSecSkill(hero, entry.first, entry.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0; i< info.reward.primary.size(); i++)
|
|
|
|
if(info.reward.primary[i] > 0)
|
|
|
|
cb->changePrimSkill(hero, static_cast<PrimarySkill::PrimarySkill>(i), info.reward.primary[i], false);
|
|
|
|
|
|
|
|
si64 expToGive = 0;
|
|
|
|
expToGive += VLC->heroh->reqExp(hero->level+info.reward.gainedLevels) - VLC->heroh->reqExp(hero->level);
|
|
|
|
expToGive += hero->calculateXp(info.reward.gainedExp);
|
2016-02-01 08:41:15 +02:00
|
|
|
if(expToGive)
|
2014-04-06 23:14:26 +03:00
|
|
|
cb->changePrimSkill(hero, PrimarySkill::EXPERIENCE, expToGive);
|
2014-04-12 16:47:48 +03:00
|
|
|
|
|
|
|
// hero is not blocked by levelup dialog - grant remainer immediately
|
2016-02-01 08:41:15 +02:00
|
|
|
if(!cb->isVisitCoveredByAnotherQuery(this, hero))
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
grantRewardAfterLevelup(info, hero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
void CRewardableObject::grantRewardAfterLevelup(const CVisitInfo & info, const CGHeroInstance * hero) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-02-01 08:41:15 +02:00
|
|
|
if(info.reward.manaDiff || info.reward.manaPercentage >= 0)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
si32 mana = hero->mana;
|
|
|
|
if (info.reward.manaPercentage >= 0)
|
|
|
|
mana = hero->manaLimit() * info.reward.manaPercentage / 100;
|
|
|
|
|
|
|
|
cb->setManaPoints(hero->id, mana + info.reward.manaDiff);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(info.reward.movePoints || info.reward.movePercentage >= 0)
|
|
|
|
{
|
|
|
|
SetMovePoints smp;
|
|
|
|
smp.hid = hero->id;
|
|
|
|
smp.val = hero->movement;
|
|
|
|
|
|
|
|
if (info.reward.movePercentage >= 0) // percent from max
|
|
|
|
smp.val = hero->maxMovePoints(hero->boat != nullptr) * info.reward.movePercentage / 100;
|
|
|
|
smp.val = std::max<si32>(0, smp.val + info.reward.movePoints);
|
|
|
|
|
|
|
|
cb->setMovePoints(&smp);
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
for(const Bonus & bonus : info.reward.bonuses)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2014-06-29 20:13:25 +03:00
|
|
|
assert(bonus.source == Bonus::OBJECT);
|
|
|
|
assert(bonus.sid == ID);
|
2014-04-06 23:14:26 +03:00
|
|
|
GiveBonus gb;
|
2014-06-29 20:13:25 +03:00
|
|
|
gb.who = GiveBonus::HERO;
|
2014-04-06 23:14:26 +03:00
|
|
|
gb.bonus = bonus;
|
|
|
|
gb.id = hero->id.getNum();
|
|
|
|
cb->giveHeroBonus(&gb);
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
for(ArtifactID art : info.reward.artifacts)
|
2014-04-06 23:14:26 +03:00
|
|
|
cb->giveHeroNewArtifact(hero, VLC->arth->artifacts[art],ArtifactPosition::FIRST_AVAILABLE);
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
if(!info.reward.spells.empty())
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
std::set<SpellID> spellsToGive(info.reward.spells.begin(), info.reward.spells.end());
|
|
|
|
cb->changeSpells(hero, true, spellsToGive);
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
if(!info.reward.creatures.empty())
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
CCreatureSet creatures;
|
|
|
|
for (auto & crea : info.reward.creatures)
|
|
|
|
creatures.addToSlot(creatures.getFreeSlot(), new CStackInstance(crea.type, crea.count));
|
|
|
|
|
|
|
|
cb->giveCreatures(this, hero, creatures, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
onRewardGiven(hero);
|
2014-04-12 16:47:48 +03:00
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
if(info.reward.removeObject)
|
2014-04-12 16:47:48 +03:00
|
|
|
cb->removeObject(this);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
bool CRewardableObject::wasVisited(PlayerColor player) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
switch (visitMode)
|
|
|
|
{
|
|
|
|
case VISIT_UNLIMITED:
|
2014-07-01 17:19:08 +03:00
|
|
|
case VISIT_BONUS:
|
2014-04-06 23:14:26 +03:00
|
|
|
return false;
|
2016-09-20 22:05:44 +02:00
|
|
|
case VISIT_ONCE:
|
2014-06-29 20:13:25 +03:00
|
|
|
return vstd::contains(cb->getPlayer(player)->visitedObjects, ObjectInstanceID(id));
|
2016-09-16 20:59:07 +02:00
|
|
|
case VISIT_HERO:
|
|
|
|
return false;
|
2016-09-16 22:01:21 +02:00
|
|
|
case VISIT_PLAYER:
|
|
|
|
return vstd::contains(cb->getPlayer(player)->visitedObjects, ObjectInstanceID(id));
|
2014-04-06 23:14:26 +03:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
bool CRewardableObject::wasVisited(const CGHeroInstance * h) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
switch (visitMode)
|
|
|
|
{
|
2014-06-29 20:13:25 +03:00
|
|
|
case VISIT_UNLIMITED:
|
2014-07-01 17:19:08 +03:00
|
|
|
return false;
|
|
|
|
case VISIT_BONUS:
|
2014-06-29 20:13:25 +03:00
|
|
|
return h->hasBonusFrom(Bonus::OBJECT, ID);
|
2014-04-06 23:14:26 +03:00
|
|
|
case VISIT_HERO:
|
2014-06-29 20:13:25 +03:00
|
|
|
return h->visitedObjects.count(ObjectInstanceID(id));
|
2014-04-06 23:14:26 +03:00
|
|
|
default:
|
|
|
|
return wasVisited(h->tempOwner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-31 09:12:01 +02:00
|
|
|
void CRewardInfo::loadComponents(std::vector<Component> & comps,
|
|
|
|
const CGHeroInstance * h) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2014-04-12 16:16:23 +03:00
|
|
|
for (auto comp : extraComponents)
|
|
|
|
comps.push_back(comp);
|
|
|
|
|
2016-01-31 09:12:01 +02:00
|
|
|
if (gainedExp)
|
|
|
|
{
|
|
|
|
comps.push_back(Component(
|
2020-10-01 10:38:06 +02:00
|
|
|
Component::EXPERIENCE, 0, (si32)h->calculateXp(gainedExp), 0));
|
2016-01-31 09:12:01 +02:00
|
|
|
}
|
2014-04-06 23:14:26 +03:00
|
|
|
if (gainedLevels) comps.push_back(Component(Component::EXPERIENCE, 0, gainedLevels, 0));
|
|
|
|
|
2016-01-31 09:12:01 +02:00
|
|
|
if (manaDiff) comps.push_back(Component(Component::PRIM_SKILL, 5, manaDiff, 0));
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
for (size_t i=0; i<primary.size(); i++)
|
|
|
|
{
|
2016-01-31 09:12:01 +02:00
|
|
|
if (primary[i] != 0)
|
2020-10-01 10:38:06 +02:00
|
|
|
comps.push_back(Component(Component::PRIM_SKILL, (ui16)i, primary[i], 0));
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto & entry : secondary)
|
|
|
|
comps.push_back(Component(Component::SEC_SKILL, entry.first, entry.second, 0));
|
|
|
|
|
|
|
|
for (auto & entry : artifacts)
|
|
|
|
comps.push_back(Component(Component::ARTIFACT, entry, 1, 0));
|
|
|
|
|
|
|
|
for (auto & entry : spells)
|
|
|
|
comps.push_back(Component(Component::SPELL, entry, 1, 0));
|
|
|
|
|
|
|
|
for (auto & entry : creatures)
|
|
|
|
comps.push_back(Component(Component::CREATURE, entry.type->idNumber, entry.count, 0));
|
2014-06-29 20:13:25 +03:00
|
|
|
|
|
|
|
for (size_t i=0; i<resources.size(); i++)
|
|
|
|
{
|
|
|
|
if (resources[i] !=0)
|
2020-10-01 10:38:06 +02:00
|
|
|
comps.push_back(Component(Component::RESOURCE, (ui16)i, resources[i], 0));
|
2014-06-29 20:13:25 +03:00
|
|
|
}
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
|
2016-01-31 09:12:01 +02:00
|
|
|
Component CRewardInfo::getDisplayedComponent(const CGHeroInstance * h) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
std::vector<Component> comps;
|
2016-01-31 09:12:01 +02:00
|
|
|
loadComponents(comps, h);
|
2014-04-06 23:14:26 +03:00
|
|
|
assert(!comps.empty());
|
|
|
|
return comps.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: copy-pasted from CObjectHandler
|
|
|
|
static std::string & visitedTxt(const bool visited)
|
|
|
|
{
|
|
|
|
int id = visited ? 352 : 353;
|
|
|
|
return VLC->generaltexth->allTexts[id];
|
|
|
|
}
|
|
|
|
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string CRewardableObject::getHoverText(PlayerColor player) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2014-07-01 17:19:08 +03:00
|
|
|
if(visitMode == VISIT_PLAYER || visitMode == VISIT_ONCE)
|
2014-06-24 20:39:36 +03:00
|
|
|
return getObjectName() + " " + visitedTxt(wasVisited(player));
|
|
|
|
return getObjectName();
|
|
|
|
}
|
2014-04-07 14:56:59 +03:00
|
|
|
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string CRewardableObject::getHoverText(const CGHeroInstance * hero) const
|
|
|
|
{
|
|
|
|
if(visitMode != VISIT_UNLIMITED)
|
|
|
|
return getObjectName() + " " + visitedTxt(wasVisited(hero));
|
|
|
|
return getObjectName();
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
void CRewardableObject::setPropertyDer(ui8 what, ui32 val)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
switch (what)
|
|
|
|
{
|
|
|
|
case ObjProperty::REWARD_RESET:
|
2014-04-07 14:56:59 +03:00
|
|
|
for (auto & visit : info)
|
|
|
|
visit.numOfGrants = 0;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case ObjProperty::REWARD_SELECT:
|
|
|
|
selectedReward = val;
|
2014-04-07 20:32:15 +03:00
|
|
|
info[val].numOfGrants++;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-09 18:38:13 +02:00
|
|
|
void CRewardableObject::triggerRewardReset() const
|
|
|
|
{
|
|
|
|
cb->setObjProperty(id, ObjProperty::REWARD_RESET, 0);
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CRewardableObject::newTurn(CRandomGenerator & rand) const
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-01-30 18:11:22 +02:00
|
|
|
if (resetDuration != 0 && cb->getDate(Date::DAY) > 1 && (cb->getDate(Date::DAY) % resetDuration) == 1)
|
2016-10-09 18:38:13 +02:00
|
|
|
triggerRewardReset();
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
CRewardableObject::CRewardableObject():
|
2014-04-06 23:14:26 +03:00
|
|
|
selectMode(0),
|
2016-11-27 21:07:01 +02:00
|
|
|
visitMode(0),
|
2014-04-06 23:14:26 +03:00
|
|
|
selectedReward(0),
|
2014-04-11 20:38:27 +03:00
|
|
|
resetDuration(0),
|
|
|
|
canRefuse(false)
|
2014-04-06 23:14:26 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-06-05 14:19:47 +03:00
|
|
|
/// END OF CODE FOR CREWARDABLEOBJECT AND RELATED CLASSES ///
|
2014-04-06 23:14:26 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/// Helper, selects random art class based on weights
|
2016-09-09 19:30:36 +02:00
|
|
|
static int selectRandomArtClass(CRandomGenerator & rand, int treasure, int minor, int major, int relic)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
int total = treasure + minor + major + relic;
|
|
|
|
assert(total != 0);
|
2016-09-09 19:30:36 +02:00
|
|
|
int hlp = rand.nextInt(total - 1);
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
if(hlp < treasure)
|
|
|
|
return CArtifact::ART_TREASURE;
|
|
|
|
if(hlp < treasure + minor)
|
|
|
|
return CArtifact::ART_MINOR;
|
|
|
|
if(hlp < treasure + minor + major)
|
|
|
|
return CArtifact::ART_MAJOR;
|
|
|
|
return CArtifact::ART_RELIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Helper, adds random artifact to reward selecting class based on weights
|
2016-09-09 19:30:36 +02:00
|
|
|
static void loadRandomArtifact(CRandomGenerator & rand, CVisitInfo & info, int treasure, int minor, int major, int relic)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-09-09 19:30:36 +02:00
|
|
|
int artClass = selectRandomArtClass(rand, treasure, minor, major, relic);
|
|
|
|
ArtifactID artID = VLC->arth->pickRandomArtifact(rand, artClass);
|
2014-04-06 23:14:26 +03:00
|
|
|
info.reward.artifacts.push_back(artID);
|
|
|
|
}
|
|
|
|
|
|
|
|
CGPickable::CGPickable()
|
|
|
|
{
|
2014-04-25 17:59:05 +03:00
|
|
|
visitMode = VISIT_UNLIMITED;
|
2014-04-06 23:14:26 +03:00
|
|
|
selectMode = SELECT_PLAYER;
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGPickable::initObj(CRandomGenerator & rand)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
blockVisit = true;
|
|
|
|
switch(ID)
|
|
|
|
{
|
2014-06-30 00:16:45 +03:00
|
|
|
case Obj::CAMPFIRE:
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-09-09 19:30:36 +02:00
|
|
|
int givenRes = rand.nextInt(5);
|
|
|
|
int givenAmm = rand.nextInt(4, 6);
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.resources[givenRes] = givenAmm;
|
|
|
|
info[0].reward.resources[Res::GOLD]= givenAmm * 100;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT,23);
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Obj::FLOTSAM:
|
|
|
|
{
|
2016-09-09 19:30:36 +02:00
|
|
|
int type = rand.nextInt(3);
|
2014-04-06 23:14:26 +03:00
|
|
|
switch(type)
|
|
|
|
{
|
2014-04-11 20:38:27 +03:00
|
|
|
case 0:
|
2014-04-12 16:47:48 +03:00
|
|
|
info.resize(1);
|
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 51);
|
|
|
|
info[0].reward.removeObject = true;
|
2016-01-16 08:45:30 +02:00
|
|
|
break;
|
2014-04-06 23:14:26 +03:00
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.resources[Res::WOOD] = 5;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 52);
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.resources[Res::WOOD] = 5;
|
|
|
|
info[0].reward.resources[Res::GOLD] = 200;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 53);
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.resources[Res::WOOD] = 10;
|
|
|
|
info[0].reward.resources[Res::GOLD] = 500;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 54);
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Obj::SEA_CHEST:
|
|
|
|
{
|
2016-09-09 19:30:36 +02:00
|
|
|
int hlp = rand.nextInt(99);
|
2014-04-06 23:14:26 +03:00
|
|
|
if(hlp < 20)
|
|
|
|
{
|
2014-04-12 16:47:48 +03:00
|
|
|
info.resize(1);
|
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 116);
|
|
|
|
info[0].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
else if(hlp < 90)
|
|
|
|
{
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.resources[Res::GOLD] = 1500;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 118);
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info.resize(1);
|
2016-09-09 19:30:36 +02:00
|
|
|
loadRandomArtifact(rand, info[0], 100, 0, 0, 0);
|
2014-04-06 23:14:26 +03:00
|
|
|
info[0].reward.resources[Res::GOLD] = 1000;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 117);
|
|
|
|
info[0].message.addReplacement(MetaString::ART_NAMES, info[0].reward.artifacts.back());
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Obj::SHIPWRECK_SURVIVOR:
|
|
|
|
{
|
|
|
|
info.resize(1);
|
2016-09-09 19:30:36 +02:00
|
|
|
loadRandomArtifact(rand, info[0], 55, 20, 20, 5);
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 125);
|
|
|
|
info[0].message.addReplacement(MetaString::ART_NAMES, info[0].reward.artifacts.back());
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Obj::TREASURE_CHEST:
|
|
|
|
{
|
2016-09-09 19:30:36 +02:00
|
|
|
int hlp = rand.nextInt(99);
|
2014-04-06 23:14:26 +03:00
|
|
|
if(hlp >= 95)
|
|
|
|
{
|
|
|
|
info.resize(1);
|
2016-09-09 19:30:36 +02:00
|
|
|
loadRandomArtifact(rand, info[0], 100, 0, 0, 0);
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT,145);
|
|
|
|
info[0].message.addReplacement(MetaString::ART_NAMES, info[0].reward.artifacts.back());
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (hlp >= 65)
|
|
|
|
{
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT,146);
|
2014-04-06 23:14:26 +03:00
|
|
|
info.resize(2);
|
|
|
|
info[0].reward.resources[Res::GOLD] = 2000;
|
|
|
|
info[1].reward.gainedExp = 1500;
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
|
|
|
info[1].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
else if(hlp >= 33)
|
|
|
|
{
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT,146);
|
2014-04-06 23:14:26 +03:00
|
|
|
info.resize(2);
|
|
|
|
info[0].reward.resources[Res::GOLD] = 1500;
|
|
|
|
info[1].reward.gainedExp = 1000;
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
|
|
|
info[1].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT,146);
|
2014-04-06 23:14:26 +03:00
|
|
|
info.resize(2);
|
|
|
|
info[0].reward.resources[Res::GOLD] = 1000;
|
|
|
|
info[1].reward.gainedExp = 500;
|
2014-04-12 16:47:48 +03:00
|
|
|
info[0].reward.removeObject = true;
|
|
|
|
info[1].reward.removeObject = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CGBonusingObject::CGBonusingObject()
|
|
|
|
{
|
2014-07-01 17:19:08 +03:00
|
|
|
visitMode = VISIT_BONUS;
|
2014-04-06 23:14:26 +03:00
|
|
|
selectMode = SELECT_FIRST;
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGBonusingObject::initObj(CRandomGenerator & rand)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
auto configureBonusDuration = [&](CVisitInfo & visit, Bonus::BonusDuration duration, Bonus::BonusType type, si32 value, si32 descrID)
|
|
|
|
{
|
|
|
|
Bonus b(duration, type, Bonus::OBJECT, value, ID, descrID != 0 ? VLC->generaltexth->advobtxt[descrID] : "");
|
|
|
|
visit.reward.bonuses.push_back(b);
|
2014-04-12 16:16:23 +03:00
|
|
|
if (type == Bonus::MORALE)
|
|
|
|
visit.reward.extraComponents.push_back(Component(Component::MORALE, 0, value, 0));
|
|
|
|
if (type == Bonus::LUCK)
|
|
|
|
visit.reward.extraComponents.push_back(Component(Component::LUCK, 0, value, 0));
|
2014-04-06 23:14:26 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
auto configureBonus = [&](CVisitInfo & visit, Bonus::BonusType type, si32 value, si32 descrID)
|
|
|
|
{
|
|
|
|
configureBonusDuration(visit, Bonus::ONE_BATTLE, type, value, descrID);
|
|
|
|
};
|
|
|
|
|
2017-09-13 02:35:58 +02:00
|
|
|
auto configureMessage = [&](CVisitInfo & visit, int onGrantID, int onVisitedID)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2014-04-11 20:38:27 +03:00
|
|
|
visit.message.addTxt(MetaString::ADVOB_TXT, onGrantID);
|
2014-04-06 23:14:26 +03:00
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, onVisitedID);
|
|
|
|
};
|
|
|
|
|
|
|
|
info.resize(1);
|
|
|
|
|
|
|
|
switch(ID)
|
|
|
|
{
|
|
|
|
case Obj::BUOY:
|
2014-04-12 14:35:48 +03:00
|
|
|
blockVisit = true;
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info[0], 21, 22);
|
2014-06-15 23:25:10 +03:00
|
|
|
configureBonus(info[0], Bonus::MORALE, +1, 94);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::SWAN_POND:
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info[0], 29, 30);
|
2014-06-15 23:25:10 +03:00
|
|
|
configureBonus(info[0], Bonus::LUCK, 2, 67);
|
|
|
|
info[0].reward.movePercentage = 0;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::FAERIE_RING:
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info[0], 49, 50);
|
2014-07-01 18:19:51 +03:00
|
|
|
configureBonus(info[0], Bonus::LUCK, 1, 71);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::FOUNTAIN_OF_FORTUNE:
|
|
|
|
selectMode = SELECT_RANDOM;
|
|
|
|
info.resize(5);
|
|
|
|
for (int i=0; i<5; i++)
|
2014-04-12 14:35:48 +03:00
|
|
|
{
|
2014-04-06 23:14:26 +03:00
|
|
|
configureBonus(info[i], Bonus::LUCK, i-1, 69); //NOTE: description have %d that should be replaced with value
|
2014-06-29 20:13:25 +03:00
|
|
|
info[i].message.addTxt(MetaString::ADVOB_TXT, 55);
|
2014-04-12 14:35:48 +03:00
|
|
|
}
|
2014-06-29 20:13:25 +03:00
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 56);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::IDOL_OF_FORTUNE:
|
|
|
|
|
|
|
|
info.resize(7);
|
|
|
|
for (int i=0; i<6; i++)
|
|
|
|
{
|
|
|
|
info[i].limiter.dayOfWeek = i+1;
|
2014-11-16 19:48:29 +02:00
|
|
|
configureBonus(info[i], (i%2) ? Bonus::MORALE : Bonus::LUCK, 1, 68);
|
2014-06-29 20:13:25 +03:00
|
|
|
info[i].message.addTxt(MetaString::ADVOB_TXT, 62);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
info.back().limiter.dayOfWeek = 7;
|
|
|
|
configureBonus(info.back(), Bonus::MORALE, 1, 68); // on last day of week
|
|
|
|
configureBonus(info.back(), Bonus::LUCK, 1, 68);
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info.back(), 62, 63);
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
break;
|
|
|
|
case Obj::MERMAID:
|
2014-04-12 14:35:48 +03:00
|
|
|
blockVisit = true;
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info[0], 83, 82);
|
2014-06-15 23:25:10 +03:00
|
|
|
configureBonus(info[0], Bonus::LUCK, 1, 72);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::RALLY_FLAG:
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info[0], 111, 110);
|
2014-06-15 23:25:10 +03:00
|
|
|
configureBonus(info[0], Bonus::MORALE, 1, 102);
|
|
|
|
configureBonus(info[0], Bonus::LUCK, 1, 102);
|
|
|
|
info[0].reward.movePoints = 400;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::OASIS:
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info[0], 95, 94);
|
2014-06-15 23:25:10 +03:00
|
|
|
configureBonus(info[0], Bonus::MORALE, 1, 95);
|
|
|
|
info[0].reward.movePoints = 800;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::TEMPLE:
|
|
|
|
info[0].limiter.dayOfWeek = 7;
|
|
|
|
info.resize(2);
|
|
|
|
configureBonus(info[0], Bonus::MORALE, 2, 96);
|
|
|
|
configureBonus(info[1], Bonus::MORALE, 1, 97);
|
2014-04-11 20:38:27 +03:00
|
|
|
|
2014-06-29 20:13:25 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 140);
|
|
|
|
info[1].message.addTxt(MetaString::ADVOB_TXT, 140);
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 141);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::WATERING_HOLE:
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info[0], 166, 167);
|
2014-06-15 23:25:10 +03:00
|
|
|
configureBonus(info[0], Bonus::MORALE, 1, 100);
|
|
|
|
info[0].reward.movePoints = 400;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::FOUNTAIN_OF_YOUTH:
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info[0], 57, 58);
|
2014-06-15 23:25:10 +03:00
|
|
|
configureBonus(info[0], Bonus::MORALE, 1, 103);
|
|
|
|
info[0].reward.movePoints = 400;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::STABLES:
|
2017-09-13 02:35:58 +02:00
|
|
|
configureMessage(info[0], 137, 136);
|
2015-02-15 06:55:59 +02:00
|
|
|
configureBonusDuration(info[0], Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, 400, 0);
|
|
|
|
info[0].reward.movePoints = 400;
|
2016-01-30 22:51:21 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-04-06 23:14:26 +03:00
|
|
|
|
2016-01-30 22:51:21 +02:00
|
|
|
CVisitInfo CGBonusingObject::getVisitInfo(int index, const CGHeroInstance *h) const
|
|
|
|
{
|
|
|
|
if(ID == Obj::STABLES)
|
|
|
|
{
|
|
|
|
assert(index == 0);
|
|
|
|
for(auto& slot : h->Slots())
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-01-30 22:51:21 +02:00
|
|
|
if(slot.second->type->idNumber == CreatureID::CAVALIER)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-01-30 22:51:21 +02:00
|
|
|
CVisitInfo vi(info[0]);
|
|
|
|
vi.message.clear();
|
|
|
|
vi.message.addTxt(MetaString::ADVOB_TXT, 138);
|
|
|
|
vi.reward.extraComponents.push_back(Component(
|
|
|
|
Component::CREATURE, CreatureID::CHAMPION, 0, 1));
|
2019-01-19 12:52:02 +02:00
|
|
|
return vi;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-30 22:51:21 +02:00
|
|
|
}
|
|
|
|
return info[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGBonusingObject::onHeroVisit(const CGHeroInstance *h) const
|
|
|
|
{
|
|
|
|
CRewardableObject::onHeroVisit(h);
|
|
|
|
if(ID == Obj::STABLES)
|
|
|
|
{
|
|
|
|
//regardless of whether this hero visited stables or not, cavaliers must be upgraded
|
|
|
|
for(auto& slot : h->Slots())
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-01-30 22:51:21 +02:00
|
|
|
if(slot.second->type->idNumber == CreatureID::CAVALIER)
|
|
|
|
{
|
|
|
|
cb->changeStackType(StackLocation(h, slot.first),
|
|
|
|
VLC->creh->creatures[CreatureID::CHAMPION]);
|
|
|
|
}
|
|
|
|
}
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
bool CGBonusingObject::wasVisited(const CGHeroInstance * h) const
|
|
|
|
{
|
|
|
|
if(ID == Obj::STABLES)
|
|
|
|
{
|
|
|
|
for(auto& slot : h->Slots())
|
|
|
|
{
|
|
|
|
if(slot.second->type->idNumber == CreatureID::CAVALIER)
|
|
|
|
{
|
|
|
|
// always display the reward message if the hero got cavaliers
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CRewardableObject::wasVisited(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGBonusingObject::grantReward(ui32 rewardID, const CGHeroInstance * hero) const
|
|
|
|
{
|
|
|
|
if(ID == Obj::STABLES && CRewardableObject::wasVisited(hero))
|
|
|
|
{
|
|
|
|
// reward message has been displayed - do not give the actual bonus
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CRewardableObject::grantReward(rewardID, hero);
|
|
|
|
}
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CGOnceVisitable::CGOnceVisitable()
|
|
|
|
{
|
|
|
|
visitMode = VISIT_ONCE;
|
|
|
|
selectMode = SELECT_FIRST;
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGOnceVisitable::initObj(CRandomGenerator & rand)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
switch(ID)
|
|
|
|
{
|
|
|
|
case Obj::CORPSE:
|
|
|
|
{
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 38);
|
|
|
|
blockVisit = true;
|
2016-09-09 19:30:36 +02:00
|
|
|
if(rand.nextInt(99) < 20)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-09-20 22:05:44 +02:00
|
|
|
info.resize(1);
|
2016-09-09 19:30:36 +02:00
|
|
|
loadRandomArtifact(rand, info[0], 10, 10, 10, 0);
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 37);
|
2016-09-20 22:05:44 +02:00
|
|
|
info[0].limiter.numOfGrants = 1;
|
2016-09-16 20:59:07 +02:00
|
|
|
}
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Obj::LEAN_TO:
|
|
|
|
{
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 65);
|
|
|
|
info.resize(1);
|
2016-09-09 19:30:36 +02:00
|
|
|
int type = rand.nextInt(5); //any basic resource without gold
|
|
|
|
int value = rand.nextInt(1, 4);
|
2014-04-06 23:14:26 +03:00
|
|
|
info[0].reward.resources[type] = value;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 64);
|
2016-09-20 22:05:44 +02:00
|
|
|
info[0].limiter.numOfGrants = 1;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Obj::WARRIORS_TOMB:
|
|
|
|
{
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT, 161);
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
info.resize(2);
|
2016-09-09 19:30:36 +02:00
|
|
|
loadRandomArtifact(rand, info[0], 30, 50, 25, 5);
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
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);
|
2016-09-20 22:05:44 +02:00
|
|
|
info[0].limiter.numOfGrants = 1;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 162);
|
2016-08-30 20:50:03 +02:00
|
|
|
info[0].message.addReplacement(VLC->arth->artifacts[info[0].reward.artifacts.back()]->Name());
|
2014-04-11 20:38:27 +03:00
|
|
|
info[1].message.addTxt(MetaString::ADVOB_TXT, 163);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Obj::WAGON:
|
|
|
|
{
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 156);
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
int hlp = rand.nextInt(99);
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
if(hlp < 40) //minor or treasure art
|
|
|
|
{
|
|
|
|
info.resize(1);
|
2016-09-09 19:30:36 +02:00
|
|
|
loadRandomArtifact(rand, info[0], 10, 10, 0, 0);
|
2016-09-20 22:05:44 +02:00
|
|
|
info[0].limiter.numOfGrants = 1;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 155);
|
2017-10-05 14:52:51 +02:00
|
|
|
info[0].message.addReplacement(VLC->arth->artifacts[info[0].reward.artifacts.back()]->Name());
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
else if(hlp < 90) //2 - 5 of non-gold resource
|
|
|
|
{
|
|
|
|
info.resize(1);
|
2016-09-09 19:30:36 +02:00
|
|
|
int type = rand.nextInt(5);
|
|
|
|
int value = rand.nextInt(2, 5);
|
2014-04-06 23:14:26 +03:00
|
|
|
info[0].reward.resources[type] = value;
|
2016-09-20 22:05:44 +02:00
|
|
|
info[0].limiter.numOfGrants = 1;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 154);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
// or nothing
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CGVisitableOPH::CGVisitableOPH()
|
|
|
|
{
|
|
|
|
visitMode = VISIT_HERO;
|
|
|
|
selectMode = SELECT_PLAYER;
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGVisitableOPH::initObj(CRandomGenerator & rand)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
switch(ID)
|
|
|
|
{
|
|
|
|
case Obj::ARENA:
|
|
|
|
info.resize(2);
|
|
|
|
info[0].reward.primary[PrimarySkill::ATTACK] = 2;
|
|
|
|
info[1].reward.primary[PrimarySkill::DEFENSE] = 2;
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT, 0);
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 1);
|
|
|
|
canRefuse = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::MERCENARY_CAMP:
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.primary[PrimarySkill::ATTACK] = 1;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 80);
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 81);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::MARLETTO_TOWER:
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.primary[PrimarySkill::DEFENSE] = 1;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 39);
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 40);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::STAR_AXIS:
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.primary[PrimarySkill::SPELL_POWER] = 1;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 100);
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 101);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::GARDEN_OF_REVELATION:
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.primary[PrimarySkill::KNOWLEDGE] = 1;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 59);
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 60);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::LEARNING_STONE:
|
|
|
|
info.resize(1);
|
|
|
|
info[0].reward.gainedExp = 1000;
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 143);
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 144);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::TREE_OF_KNOWLEDGE:
|
|
|
|
info.resize(1);
|
2014-04-11 20:38:27 +03:00
|
|
|
canRefuse = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
info[0].reward.gainedLevels = 1;
|
2014-04-11 20:38:27 +03:00
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 147);
|
2014-04-06 23:14:26 +03:00
|
|
|
info.resize(1);
|
2016-09-09 19:30:36 +02:00
|
|
|
switch (rand.nextInt(2))
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
case 0: // free
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT, 148);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
info[0].limiter.resources[Res::GOLD] = 2000;
|
|
|
|
info[0].reward.resources[Res::GOLD] = -2000;
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT, 149);
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 150);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
info[0].limiter.resources[Res::GEMS] = 10;
|
|
|
|
info[0].reward.resources[Res::GEMS] = -10;
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT, 151);
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 152);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Obj::LIBRARY_OF_ENLIGHTENMENT:
|
|
|
|
{
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 67);
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 68);
|
|
|
|
|
|
|
|
// Don't like this one but don't see any easier approach
|
|
|
|
CVisitInfo visit;
|
|
|
|
visit.reward.primary[PrimarySkill::ATTACK] = 2;
|
|
|
|
visit.reward.primary[PrimarySkill::DEFENSE] = 2;
|
|
|
|
visit.reward.primary[PrimarySkill::KNOWLEDGE] = 2;
|
|
|
|
visit.reward.primary[PrimarySkill::SPELL_POWER] = 2;
|
|
|
|
|
|
|
|
static_assert(SecSkillLevel::LEVELS_SIZE == 4, "Behavior of Library of Enlignment may not be correct");
|
|
|
|
for (int i=0; i<SecSkillLevel::LEVELS_SIZE; i++)
|
|
|
|
{
|
|
|
|
visit.limiter.minLevel = 10 - i * 2;
|
|
|
|
visit.limiter.secondary[SecondarySkill::DIPLOMACY] = i;
|
2014-04-11 20:38:27 +03:00
|
|
|
visit.message.addTxt(MetaString::ADVOB_TXT, 66);
|
2014-04-06 23:14:26 +03:00
|
|
|
info.push_back(visit);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Obj::SCHOOL_OF_MAGIC:
|
|
|
|
info.resize(2);
|
|
|
|
info[0].reward.primary[PrimarySkill::SPELL_POWER] = 1;
|
|
|
|
info[1].reward.primary[PrimarySkill::KNOWLEDGE] = 1;
|
2019-03-11 19:56:05 +02:00
|
|
|
info[0].limiter.resources[Res::GOLD] = 1000;
|
2014-06-29 20:13:25 +03:00
|
|
|
info[0].reward.resources[Res::GOLD] = -1000;
|
2019-03-11 19:56:05 +02:00
|
|
|
info[1].limiter.resources[Res::GOLD] = 1000;
|
2014-06-29 20:13:25 +03:00
|
|
|
info[1].reward.resources[Res::GOLD] = -1000;
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT, 71);
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 72);
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 73);
|
|
|
|
canRefuse = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::SCHOOL_OF_WAR:
|
|
|
|
info.resize(2);
|
|
|
|
info[0].reward.primary[PrimarySkill::ATTACK] = 1;
|
|
|
|
info[1].reward.primary[PrimarySkill::DEFENSE] = 1;
|
2014-06-29 20:13:25 +03:00
|
|
|
info[0].reward.resources[Res::GOLD] = -1000;
|
|
|
|
info[1].reward.resources[Res::GOLD] = -1000;
|
2014-04-11 20:38:27 +03:00
|
|
|
onSelect.addTxt(MetaString::ADVOB_TXT, 158);
|
|
|
|
onVisited.addTxt(MetaString::ADVOB_TXT, 159);
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 160);
|
|
|
|
canRefuse = true;
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-04-25 17:59:05 +03:00
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CGVisitableOPW::CGVisitableOPW()
|
|
|
|
{
|
|
|
|
visitMode = VISIT_ONCE;
|
|
|
|
resetDuration = 7;
|
|
|
|
}
|
|
|
|
|
2016-10-09 18:38:13 +02:00
|
|
|
void CGVisitableOPW::triggerRewardReset() const
|
|
|
|
{
|
|
|
|
CRewardableObject::triggerRewardReset();
|
|
|
|
|
|
|
|
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_CLEAR, id);
|
|
|
|
cb->sendAndApply(&cov);
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGVisitableOPW::initObj(CRandomGenerator & rand)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-09-28 19:07:48 +02:00
|
|
|
setRandomReward(rand);
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
switch (ID)
|
|
|
|
{
|
|
|
|
case Obj::MYSTICAL_GARDEN:
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 93);
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 92);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::WINDMILL:
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 169);
|
2016-10-11 17:19:42 +02:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 170);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
case Obj::WATER_WHEEL:
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 165);
|
2014-04-11 20:38:27 +03:00
|
|
|
info[0].message.addTxt(MetaString::ADVOB_TXT, 164);
|
2014-04-06 23:14:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-30 18:11:22 +02:00
|
|
|
void CGVisitableOPW::setPropertyDer(ui8 what, ui32 val)
|
|
|
|
{
|
2016-09-28 19:07:48 +02:00
|
|
|
if(what == ObjProperty::REWARD_RESET)
|
2016-01-30 18:11:22 +02:00
|
|
|
{
|
2016-09-28 19:07:48 +02:00
|
|
|
setRandomReward(cb->gameState()->getRandomGenerator());
|
|
|
|
|
|
|
|
if (ID == Obj::WATER_WHEEL)
|
2016-01-30 18:11:22 +02:00
|
|
|
{
|
2016-09-28 19:07:48 +02:00
|
|
|
auto& reward = info[0].reward.resources[Res::GOLD];
|
2017-07-18 14:00:30 +02:00
|
|
|
if(cb->getDate() > 7)
|
2016-09-28 19:07:48 +02:00
|
|
|
{
|
|
|
|
reward = 1000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reward = 500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CRewardableObject::setPropertyDer(what, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGVisitableOPW::setRandomReward(CRandomGenerator &rand)
|
|
|
|
{
|
|
|
|
switch (ID)
|
|
|
|
{
|
|
|
|
case Obj::MYSTICAL_GARDEN:
|
|
|
|
info.resize(1);
|
2016-10-11 17:00:54 +02:00
|
|
|
info[0].limiter.numOfGrants = 1;
|
|
|
|
info[0].reward.resources.amin(0);
|
2016-09-28 19:07:48 +02:00
|
|
|
if (rand.nextInt(1) == 0)
|
|
|
|
{
|
|
|
|
info[0].reward.resources[Res::GEMS] = 5;
|
2016-01-30 18:11:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-28 19:07:48 +02:00
|
|
|
info[0].reward.resources[Res::GOLD] = 500;
|
2016-01-30 18:11:22 +02:00
|
|
|
}
|
2016-09-28 19:07:48 +02:00
|
|
|
break;
|
|
|
|
case Obj::WINDMILL:
|
|
|
|
info.resize(1);
|
2016-10-11 17:00:54 +02:00
|
|
|
info[0].reward.resources.amin(0);
|
2016-09-28 19:07:48 +02:00
|
|
|
// 3-6 of any resource but wood and gold
|
|
|
|
info[0].reward.resources[rand.nextInt(Res::MERCURY, Res::GEMS)] = rand.nextInt(3, 6);
|
|
|
|
info[0].limiter.numOfGrants = 1;
|
|
|
|
break;
|
|
|
|
case Obj::WATER_WHEEL:
|
|
|
|
info.resize(1);
|
2016-10-11 17:00:54 +02:00
|
|
|
info[0].reward.resources.amin(0);
|
2016-09-28 19:07:48 +02:00
|
|
|
info[0].reward.resources[Res::GOLD] = 500;
|
|
|
|
info[0].limiter.numOfGrants = 1;
|
|
|
|
break;
|
2016-01-30 18:11:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGMagicSpring::initObj(CRandomGenerator & rand)
|
2014-04-11 20:38:27 +03:00
|
|
|
{
|
2014-05-24 01:56:51 +03:00
|
|
|
CVisitInfo visit; // TODO: "player above max mana" limiter. Use logical expressions for limiters?
|
2014-04-12 14:35:48 +03:00
|
|
|
visit.reward.manaPercentage = 200;
|
|
|
|
visit.message.addTxt(MetaString::ADVOB_TXT, 74);
|
|
|
|
info.push_back(visit); // two rewards, one for each entrance
|
|
|
|
info.push_back(visit);
|
|
|
|
onEmpty.addTxt(MetaString::ADVOB_TXT, 75);
|
2014-04-11 20:38:27 +03:00
|
|
|
}
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
std::vector<int3> CGMagicSpring::getVisitableOffsets() const
|
|
|
|
{
|
|
|
|
std::vector <int3> visitableTiles;
|
|
|
|
|
|
|
|
for(int y = 0; y < 6; y++)
|
|
|
|
for (int x = 0; x < 8; x++) //starting from left
|
|
|
|
if (appearance.isVisitableAt(x, y))
|
|
|
|
visitableTiles.push_back (int3(x, y , 0));
|
|
|
|
|
|
|
|
return visitableTiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
int3 CGMagicSpring::getVisitableOffset() const
|
|
|
|
{
|
|
|
|
auto visitableTiles = getVisitableOffsets();
|
|
|
|
|
|
|
|
if (visitableTiles.size() != info.size())
|
|
|
|
{
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->warn("Unexpected number of visitable tiles of Magic Spring at %s", pos.toString());
|
2014-04-06 23:14:26 +03:00
|
|
|
return int3(-1,-1,-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i=0; i<visitableTiles.size(); i++)
|
|
|
|
{
|
2014-04-07 14:56:59 +03:00
|
|
|
if (info[i].numOfGrants == 0)
|
2014-04-06 23:14:26 +03:00
|
|
|
return visitableTiles[i];
|
|
|
|
}
|
|
|
|
return visitableTiles[0]; // return *something*. This is valid visitable tile but already used
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ui32> CGMagicSpring::getAvailableRewards(const CGHeroInstance * hero) const
|
|
|
|
{
|
|
|
|
auto tiles = getVisitableOffsets();
|
|
|
|
for (size_t i=0; i<tiles.size(); i++)
|
|
|
|
{
|
2014-04-07 14:56:59 +03:00
|
|
|
if (pos - tiles[i] == hero->getPosition() && info[i].numOfGrants == 0)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
return std::vector<ui32>(1, (ui32)i);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// hero is either not on visitable tile (should not happen) or tile is already used
|
|
|
|
return std::vector<ui32>();
|
|
|
|
}
|