1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Core functionality for new objects in now in place, not yet tested

- added selection of rewards
- moved "on grant" message to reward struct
- multiple minor fixes
This commit is contained in:
Ivan Savenko 2014-04-11 20:38:27 +03:00
parent dab9fd7148
commit d14a16249d
2 changed files with 140 additions and 87 deletions

View File

@ -81,44 +81,58 @@ std::vector<ui32> CObjectWithReward::getAvailableRewards(const CGHeroInstance *
void CObjectWithReward::onHeroVisit(const CGHeroInstance *h) const void CObjectWithReward::onHeroVisit(const CGHeroInstance *h) const
{ {
auto grantRewardWithMessage = [&](int index) -> void
{
grantReward(index, h);
InfoWindow iw;
iw.player = h->tempOwner;
iw.soundID = soundID;
iw.text = info[index].message;
info[index].reward.loadComponents(iw.components);
cb->showInfoDialog(&iw);
};
if (!wasVisited(h)) if (!wasVisited(h))
{ {
auto rewards = getAvailableRewards(h); auto rewards = getAvailableRewards(h);
switch (rewards.size()) switch (rewards.size())
{ {
case 0: // no rewards, e.g. empty flotsam case 0: // no available rewards, e.g. empty flotsam
{ {
InfoWindow iw; InfoWindow iw;
iw.player = h->tempOwner; iw.player = h->tempOwner;
iw.soundID = soundID; iw.soundID = soundID;
iw.text = onEmpty; iw.text = onEmpty;
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
onRewardGiven(h); onRewardGiven(h); // FIXME: dummy call to properly act on empty objects (e.g. Floatsam that must be removed after visit)
break; break;
} }
case 1: // one reward. Just give it with message case 1: // one reward. Just give it with message
{ {
//FIXME: merge into grantReward call? grantRewardWithMessage(rewards[0]);
cb->setObjProperty(id, ObjProperty::REWARD_SELECT, rewards[0]);
grantReward(info[rewards[0]], h);
InfoWindow iw;
iw.player = h->tempOwner;
iw.soundID = soundID;
iw.text = onGrant;
info[rewards[0]].reward.loadComponents(iw.components);
cb->showInfoDialog(&iw);
onRewardGiven(h);
break; break;
} }
default: // multiple rewards. Let player select default: // multiple rewards. Act according to select mode
{//TODO: implement various modes {
BlockingDialog sd(false,true); switch (selectMode) {
sd.player = h->tempOwner; case SELECT_PLAYER: // player must select
sd.soundID = soundID; {
sd.text = onGrant; BlockingDialog sd(canRefuse, true);
for (auto index : rewards) sd.player = h->tempOwner;
sd.components.push_back(info[index].reward.getDisplayedComponent()); sd.soundID = soundID;
cb->showBlockingDialog(&sd); sd.text = onSelect;
for (auto index : rewards)
sd.components.push_back(info[index].reward.getDisplayedComponent());
cb->showBlockingDialog(&sd);
break;
}
case SELECT_FIRST: // give first available
grantRewardWithMessage(rewards[0]);
break;
case SELECT_RANDOM: // select one randomly
grantRewardWithMessage(rewards[cb->gameState()->getRandomGenerator().nextInt(rewards.size()-1)]);
break;
}
return; return;
} }
} }
@ -140,11 +154,14 @@ void CObjectWithReward::heroLevelUpDone(const CGHeroInstance *hero) const
void CObjectWithReward::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const void CObjectWithReward::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
{ {
if (answer == 0)
return; // player refused
if (answer > 0 && answer-1 < info.size()) if (answer > 0 && answer-1 < info.size())
{ {
//NOTE: this relies on assumption that there won't be any changes in player/hero during blocking dialog
auto list = getAvailableRewards(hero); auto list = getAvailableRewards(hero);
cb->setObjProperty(id, ObjProperty::REWARD_SELECT, list[answer - 1]); grantReward(list[answer - 1], hero);
grantReward(info[list[answer - 1]], hero);
} }
else else
{ {
@ -157,7 +174,16 @@ void CObjectWithReward::onRewardGiven(const CGHeroInstance * hero) const
// no implementation, virtual function for overrides // no implementation, virtual function for overrides
} }
void CObjectWithReward::grantReward(const CVisitInfo & info, const CGHeroInstance * hero) const void CObjectWithReward::grantReward(ui32 rewardID, const CGHeroInstance * hero) const
{
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD, id, hero->id);
cb->sendAndApply(&cov);
cb->setObjProperty(id, ObjProperty::REWARD_SELECT, rewardID);
grantRewardBeforeLevelup(info[rewardID], hero);
}
void CObjectWithReward::grantRewardBeforeLevelup(const CVisitInfo & info, const CGHeroInstance * hero) const
{ {
assert(hero); assert(hero);
assert(hero->tempOwner.isValidPlayer()); assert(hero->tempOwner.isValidPlayer());
@ -165,10 +191,6 @@ void CObjectWithReward::grantReward(const CVisitInfo & info, const CGHeroInstanc
assert(info.reward.creatures.size() <= GameConstants::ARMY_SIZE); assert(info.reward.creatures.size() <= GameConstants::ARMY_SIZE);
assert(!cb->isVisitCoveredByAnotherQuery(this, hero)); assert(!cb->isVisitCoveredByAnotherQuery(this, hero));
//FIXME: move somewhere?
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD, id, hero->id);
cb->sendAndApply(&cov);
cb->giveResources(hero->tempOwner, info.reward.resources); cb->giveResources(hero->tempOwner, info.reward.resources);
for (auto & entry : info.reward.secondary) for (auto & entry : info.reward.secondary)
@ -185,7 +207,6 @@ void CObjectWithReward::grantReward(const CVisitInfo & info, const CGHeroInstanc
if(info.reward.primary[i] > 0) if(info.reward.primary[i] > 0)
cb->changePrimSkill(hero, static_cast<PrimarySkill::PrimarySkill>(i), info.reward.primary[i], false); cb->changePrimSkill(hero, static_cast<PrimarySkill::PrimarySkill>(i), info.reward.primary[i], false);
si64 expToGive = 0; si64 expToGive = 0;
expToGive += VLC->heroh->reqExp(hero->level+info.reward.gainedLevels) - VLC->heroh->reqExp(hero->level); expToGive += VLC->heroh->reqExp(hero->level+info.reward.gainedLevels) - VLC->heroh->reqExp(hero->level);
expToGive += hero->calculateXp(info.reward.gainedExp); expToGive += hero->calculateXp(info.reward.gainedExp);
@ -371,7 +392,8 @@ CObjectWithReward::CObjectWithReward():
soundID(soundBase::invalid), soundID(soundBase::invalid),
selectMode(0), selectMode(0),
selectedReward(0), selectedReward(0),
resetDuration(0) resetDuration(0),
canRefuse(false)
{} {}
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
@ -416,30 +438,28 @@ void CGPickable::initObj()
case Obj::CAMPFIRE: case Obj::CAMPFIRE:
{ {
soundID = soundBase::experience; soundID = soundBase::experience;
onGrant.addTxt(MetaString::ADVOB_TXT,23);
int givenRes = cb->gameState()->getRandomGenerator().nextInt(5); int givenRes = cb->gameState()->getRandomGenerator().nextInt(5);
int givenAmm = cb->gameState()->getRandomGenerator().nextInt(4, 6); int givenAmm = cb->gameState()->getRandomGenerator().nextInt(4, 6);
info.resize(1); info.resize(1);
info[0].reward.resources[givenRes] = givenAmm; info[0].reward.resources[givenRes] = givenAmm;
info[0].reward.resources[Res::GOLD]= givenAmm * 100; info[0].reward.resources[Res::GOLD]= givenAmm * 100;
info[0].message.addTxt(MetaString::ADVOB_TXT,23);
break; break;
} }
case Obj::FLOTSAM: case Obj::FLOTSAM:
{ {
int type = cb->gameState()->getRandomGenerator().nextInt(3); int type = cb->gameState()->getRandomGenerator().nextInt(3);
soundID = soundBase::GENIE; soundID = soundBase::GENIE;
if (type == 0)
onEmpty.addTxt(MetaString::ADVOB_TXT, 51+type);
else
onGrant.addTxt(MetaString::ADVOB_TXT, 51+type);
switch(type) switch(type)
{ {
//case 0: case 0:
onEmpty.addTxt(MetaString::ADVOB_TXT, 51);
case 1: case 1:
{ {
info.resize(1); info.resize(1);
info[0].reward.resources[Res::WOOD] = 5; info[0].reward.resources[Res::WOOD] = 5;
info[0].message.addTxt(MetaString::ADVOB_TXT, 52);
break; break;
} }
case 2: case 2:
@ -447,6 +467,7 @@ void CGPickable::initObj()
info.resize(1); info.resize(1);
info[0].reward.resources[Res::WOOD] = 5; info[0].reward.resources[Res::WOOD] = 5;
info[0].reward.resources[Res::GOLD] = 200; info[0].reward.resources[Res::GOLD] = 200;
info[0].message.addTxt(MetaString::ADVOB_TXT, 53);
break; break;
} }
case 3: case 3:
@ -454,6 +475,7 @@ void CGPickable::initObj()
info.resize(1); info.resize(1);
info[0].reward.resources[Res::WOOD] = 10; info[0].reward.resources[Res::WOOD] = 10;
info[0].reward.resources[Res::GOLD] = 500; info[0].reward.resources[Res::GOLD] = 500;
info[0].message.addTxt(MetaString::ADVOB_TXT, 54);
break; break;
} }
} }
@ -465,21 +487,21 @@ void CGPickable::initObj()
int hlp = cb->gameState()->getRandomGenerator().nextInt(99); int hlp = cb->gameState()->getRandomGenerator().nextInt(99);
if(hlp < 20) if(hlp < 20)
{ {
onGrant.addTxt(MetaString::ADVOB_TXT, 116); onEmpty.addTxt(MetaString::ADVOB_TXT, 116);
} }
else if(hlp < 90) else if(hlp < 90)
{ {
info.resize(1); info.resize(1);
info[0].reward.resources[Res::GOLD] = 1500; info[0].reward.resources[Res::GOLD] = 1500;
onGrant.addTxt(MetaString::ADVOB_TXT, 118); info[0].message.addTxt(MetaString::ADVOB_TXT, 118);
} }
else else
{ {
info.resize(1); info.resize(1);
loadRandomArtifact(info[0], 100, 0, 0, 0); loadRandomArtifact(info[0], 100, 0, 0, 0);
info[0].reward.resources[Res::GOLD] = 1000; info[0].reward.resources[Res::GOLD] = 1000;
onGrant.addTxt(MetaString::ADVOB_TXT, 117); info[0].message.addTxt(MetaString::ADVOB_TXT, 117);
onGrant.addReplacement(MetaString::ART_NAMES, info[0].reward.artifacts.back()); info[0].message.addReplacement(MetaString::ART_NAMES, info[0].reward.artifacts.back());
} }
} }
break; break;
@ -488,8 +510,8 @@ void CGPickable::initObj()
soundID = soundBase::experience; soundID = soundBase::experience;
info.resize(1); info.resize(1);
loadRandomArtifact(info[0], 55, 20, 20, 5); loadRandomArtifact(info[0], 55, 20, 20, 5);
onGrant.addTxt(MetaString::ADVOB_TXT, 125); info[0].message.addTxt(MetaString::ADVOB_TXT, 125);
onGrant.addReplacement(MetaString::ART_NAMES, info[0].reward.artifacts.back()); info[0].message.addReplacement(MetaString::ART_NAMES, info[0].reward.artifacts.back());
} }
break; break;
case Obj::TREASURE_CHEST: case Obj::TREASURE_CHEST:
@ -500,14 +522,14 @@ void CGPickable::initObj()
soundID = soundBase::treasure; soundID = soundBase::treasure;
info.resize(1); info.resize(1);
loadRandomArtifact(info[0], 100, 0, 0, 0); loadRandomArtifact(info[0], 100, 0, 0, 0);
onGrant.addTxt(MetaString::ADVOB_TXT,145); info[0].message.addTxt(MetaString::ADVOB_TXT,145);
onGrant.addReplacement(MetaString::ART_NAMES, info[0].reward.artifacts.back()); info[0].message.addReplacement(MetaString::ART_NAMES, info[0].reward.artifacts.back());
return; return;
} }
else if (hlp >= 65) else if (hlp >= 65)
{ {
soundID = soundBase::chest; soundID = soundBase::chest;
onGrant.addTxt(MetaString::ADVOB_TXT,146); onSelect.addTxt(MetaString::ADVOB_TXT,146);
info.resize(2); info.resize(2);
info[0].reward.resources[Res::GOLD] = 2000; info[0].reward.resources[Res::GOLD] = 2000;
info[1].reward.gainedExp = 1500; info[1].reward.gainedExp = 1500;
@ -515,7 +537,7 @@ void CGPickable::initObj()
else if(hlp >= 33) else if(hlp >= 33)
{ {
soundID = soundBase::chest; soundID = soundBase::chest;
onGrant.addTxt(MetaString::ADVOB_TXT,146); onSelect.addTxt(MetaString::ADVOB_TXT,146);
info.resize(2); info.resize(2);
info[0].reward.resources[Res::GOLD] = 1500; info[0].reward.resources[Res::GOLD] = 1500;
info[1].reward.gainedExp = 1000; info[1].reward.gainedExp = 1000;
@ -523,7 +545,7 @@ void CGPickable::initObj()
else else
{ {
soundID = soundBase::chest; soundID = soundBase::chest;
onGrant.addTxt(MetaString::ADVOB_TXT,146); onSelect.addTxt(MetaString::ADVOB_TXT,146);
info.resize(2); info.resize(2);
info[0].reward.resources[Res::GOLD] = 1000; info[0].reward.resources[Res::GOLD] = 1000;
info[1].reward.gainedExp = 500; info[1].reward.gainedExp = 500;
@ -559,9 +581,9 @@ void CGBonusingObject::initObj()
configureBonusDuration(visit, Bonus::ONE_BATTLE, type, value, descrID); configureBonusDuration(visit, Bonus::ONE_BATTLE, type, value, descrID);
}; };
auto configureMessage = [&](int onGrantID, int onVisitedID, soundBase::soundID sound) auto configureMessage = [&](CVisitInfo & visit, int onGrantID, int onVisitedID, soundBase::soundID sound)
{ {
onGrant.addTxt(MetaString::ADVOB_TXT, onGrantID); visit.message.addTxt(MetaString::ADVOB_TXT, onGrantID);
onVisited.addTxt(MetaString::ADVOB_TXT, onVisitedID); onVisited.addTxt(MetaString::ADVOB_TXT, onVisitedID);
soundID = sound; soundID = sound;
}; };
@ -575,28 +597,28 @@ void CGBonusingObject::initObj()
switch(ID) switch(ID)
{ {
case Obj::BUOY: case Obj::BUOY:
configureMessage(21, 22, soundBase::MORALE); configureMessage(visit, 21, 22, soundBase::MORALE);
configureBonus(visit, Bonus::MORALE, +1, 94); configureBonus(visit, Bonus::MORALE, +1, 94);
break; break;
case Obj::SWAN_POND: case Obj::SWAN_POND:
configureMessage(29, 30, soundBase::LUCK); configureMessage(visit, 29, 30, soundBase::LUCK);
configureBonus(visit, Bonus::LUCK, 2, 67); configureBonus(visit, Bonus::LUCK, 2, 67);
visit.reward.movePercentage = 0; visit.reward.movePercentage = 0;
break; break;
case Obj::FAERIE_RING: case Obj::FAERIE_RING:
configureMessage(49, 50, soundBase::LUCK); configureMessage(visit, 49, 50, soundBase::LUCK);
configureBonus(visit, Bonus::LUCK, 2, 71); configureBonus(visit, Bonus::LUCK, 2, 71);
break; break;
case Obj::FOUNTAIN_OF_FORTUNE: case Obj::FOUNTAIN_OF_FORTUNE:
selectMode = SELECT_RANDOM; selectMode = SELECT_RANDOM;
configureMessage(55, 56, soundBase::LUCK); configureMessage(visit, 55, 56, soundBase::LUCK);
info.resize(5); info.resize(5);
for (int i=0; i<5; i++) for (int i=0; i<5; i++)
configureBonus(info[i], Bonus::LUCK, i-1, 69); //NOTE: description have %d that should be replaced with value configureBonus(info[i], Bonus::LUCK, i-1, 69); //NOTE: description have %d that should be replaced with value
break; break;
case Obj::IDOL_OF_FORTUNE: case Obj::IDOL_OF_FORTUNE:
configureMessage(62, 63, soundBase::experience); configureMessage(visit, 62, 63, soundBase::experience);
info.resize(7); info.resize(7);
for (int i=0; i<6; i++) for (int i=0; i<6; i++)
{ {
@ -609,40 +631,41 @@ void CGBonusingObject::initObj()
break; break;
case Obj::MERMAID: case Obj::MERMAID:
configureMessage(83, 82, soundBase::LUCK); configureMessage(visit, 83, 82, soundBase::LUCK);
configureBonus(visit, Bonus::LUCK, 1, 72); configureBonus(visit, Bonus::LUCK, 1, 72);
break; break;
case Obj::RALLY_FLAG: case Obj::RALLY_FLAG:
configureMessage(111, 110, soundBase::MORALE); configureMessage(visit, 111, 110, soundBase::MORALE);
configureBonus(visit, Bonus::MORALE, 1, 102); configureBonus(visit, Bonus::MORALE, 1, 102);
configureBonus(visit, Bonus::LUCK, 1, 102); configureBonus(visit, Bonus::LUCK, 1, 102);
visit.reward.movePoints = 400; visit.reward.movePoints = 400;
break; break;
case Obj::OASIS: case Obj::OASIS:
configureMessage(95, 94, soundBase::MORALE); configureMessage(visit, 95, 94, soundBase::MORALE);
onGrant.addTxt(MetaString::ADVOB_TXT, 95);
configureBonus(visit, Bonus::MORALE, 1, 95); configureBonus(visit, Bonus::MORALE, 1, 95);
visit.reward.movePoints = 800; visit.reward.movePoints = 800;
break; break;
case Obj::TEMPLE: case Obj::TEMPLE:
configureMessage(140, 141, soundBase::temple);
info[0].limiter.dayOfWeek = 7; info[0].limiter.dayOfWeek = 7;
info.resize(2); info.resize(2);
configureBonus(info[0], Bonus::MORALE, 2, 96); configureBonus(info[0], Bonus::MORALE, 2, 96);
configureBonus(info[1], Bonus::MORALE, 1, 97); configureBonus(info[1], Bonus::MORALE, 1, 97);
configureMessage(visit, 140, 141, soundBase::temple);
configureMessage(info[1], 140, 141, soundBase::temple);
break; break;
case Obj::WATERING_HOLE: case Obj::WATERING_HOLE:
configureMessage(166, 167, soundBase::MORALE); configureMessage(visit, 166, 167, soundBase::MORALE);
configureBonus(visit, Bonus::MORALE, 1, 100); configureBonus(visit, Bonus::MORALE, 1, 100);
visit.reward.movePoints = 400; visit.reward.movePoints = 400;
break; break;
case Obj::FOUNTAIN_OF_YOUTH: case Obj::FOUNTAIN_OF_YOUTH:
configureMessage(57, 58, soundBase::MORALE); configureMessage(visit, 57, 58, soundBase::MORALE);
configureBonus(visit, Bonus::MORALE, 1, 103); configureBonus(visit, Bonus::MORALE, 1, 103);
visit.reward.movePoints = 400; visit.reward.movePoints = 400;
break; break;
case Obj::STABLES: case Obj::STABLES:
configureMessage(137, 136, soundBase::STORE); configureMessage(visit, 137, 136, soundBase::STORE);
configureBonusDuration(visit, Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, 600, 0); configureBonusDuration(visit, Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, 600, 0);
visit.reward.movePoints = 600; visit.reward.movePoints = 600;
@ -681,7 +704,6 @@ void CGOnceVisitable::initObj()
{ {
case Obj::CORPSE: case Obj::CORPSE:
{ {
onGrant.addTxt(MetaString::ADVOB_TXT, 37);
onEmpty.addTxt(MetaString::ADVOB_TXT, 38); onEmpty.addTxt(MetaString::ADVOB_TXT, 38);
soundID = soundBase::MYSTERY; soundID = soundBase::MYSTERY;
blockVisit = true; blockVisit = true;
@ -689,6 +711,7 @@ void CGOnceVisitable::initObj()
{ {
info.resize(1); info.resize(1);
loadRandomArtifact(info[0], 10, 10, 10, 0); loadRandomArtifact(info[0], 10, 10, 10, 0);
info[0].message.addTxt(MetaString::ADVOB_TXT, 37);
} }
} }
break; break;
@ -696,21 +719,19 @@ void CGOnceVisitable::initObj()
case Obj::LEAN_TO: case Obj::LEAN_TO:
{ {
soundID = soundBase::GENIE; soundID = soundBase::GENIE;
onGrant.addTxt(MetaString::ADVOB_TXT, 64);
onEmpty.addTxt(MetaString::ADVOB_TXT, 65); onEmpty.addTxt(MetaString::ADVOB_TXT, 65);
info.resize(1); info.resize(1);
int type = cb->gameState()->getRandomGenerator().nextInt(5); //any basic resource without gold int type = cb->gameState()->getRandomGenerator().nextInt(5); //any basic resource without gold
int value = cb->gameState()->getRandomGenerator().nextInt(1, 4); int value = cb->gameState()->getRandomGenerator().nextInt(1, 4);
info[0].reward.resources[type] = value; info[0].reward.resources[type] = value;
info[0].message.addTxt(MetaString::ADVOB_TXT, 64);
} }
break; break;
case Obj::WARRIORS_TOMB: case Obj::WARRIORS_TOMB:
{ {
// TODO: line 161 - ask if player wants to search the Tomb
soundID = soundBase::GRAVEYARD; soundID = soundBase::GRAVEYARD;
onGrant.addTxt(MetaString::ADVOB_TXT, 162); onSelect.addTxt(MetaString::ADVOB_TXT, 161);
onVisited.addTxt(MetaString::ADVOB_TXT, 163);
info.resize(2); info.resize(2);
loadRandomArtifact(info[0], 30, 50, 25, 5); loadRandomArtifact(info[0], 30, 50, 25, 5);
@ -718,6 +739,8 @@ void CGOnceVisitable::initObj()
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].message.addTxt(MetaString::ADVOB_TXT, 162);
info[1].message.addTxt(MetaString::ADVOB_TXT, 163);
} }
break; break;
case Obj::WAGON: case Obj::WAGON:
@ -729,17 +752,17 @@ void CGOnceVisitable::initObj()
if(hlp < 40) //minor or treasure art if(hlp < 40) //minor or treasure art
{ {
onGrant.addTxt(MetaString::ADVOB_TXT, 155);
info.resize(1); info.resize(1);
loadRandomArtifact(info[0], 10, 10, 0, 0); loadRandomArtifact(info[0], 10, 10, 0, 0);
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
{ {
onGrant.addTxt(MetaString::ADVOB_TXT, 154);
info.resize(1); info.resize(1);
int type = cb->gameState()->getRandomGenerator().nextInt(5); int type = cb->gameState()->getRandomGenerator().nextInt(5);
int value = cb->gameState()->getRandomGenerator().nextInt(2, 5); int value = cb->gameState()->getRandomGenerator().nextInt(2, 5);
info[0].reward.resources[type] = value; info[0].reward.resources[type] = value;
info[0].message.addTxt(MetaString::ADVOB_TXT, 154);
} }
// or nothing // or nothing
} }
@ -761,64 +784,76 @@ void CGVisitableOPH::initObj()
{ {
case Obj::ARENA: case Obj::ARENA:
soundID = soundBase::NOMAD; soundID = soundBase::NOMAD;
onGrant.addTxt(MetaString::ADVOB_TXT, 0);
info.resize(2); info.resize(2);
info[0].reward.primary[PrimarySkill::ATTACK] = 2; info[0].reward.primary[PrimarySkill::ATTACK] = 2;
info[1].reward.primary[PrimarySkill::DEFENSE] = 2; info[1].reward.primary[PrimarySkill::DEFENSE] = 2;
onSelect.addTxt(MetaString::ADVOB_TXT, 0);
onVisited.addTxt(MetaString::ADVOB_TXT, 1);
canRefuse = true;
break; break;
case Obj::MERCENARY_CAMP: case Obj::MERCENARY_CAMP:
info.resize(1); info.resize(1);
info[0].reward.primary[PrimarySkill::ATTACK] = 1; info[0].reward.primary[PrimarySkill::ATTACK] = 1;
soundID = soundBase::NOMAD; soundID = soundBase::NOMAD;
onGrant.addTxt(MetaString::ADVOB_TXT, 80); info[0].message.addTxt(MetaString::ADVOB_TXT, 80);
onVisited.addTxt(MetaString::ADVOB_TXT, 81);
break; break;
case Obj::MARLETTO_TOWER: case Obj::MARLETTO_TOWER:
info.resize(1); info.resize(1);
info[0].reward.primary[PrimarySkill::DEFENSE] = 1; info[0].reward.primary[PrimarySkill::DEFENSE] = 1;
soundID = soundBase::NOMAD; soundID = soundBase::NOMAD;
onGrant.addTxt(MetaString::ADVOB_TXT, 39); info[0].message.addTxt(MetaString::ADVOB_TXT, 39);
onVisited.addTxt(MetaString::ADVOB_TXT, 40);
break; break;
case Obj::STAR_AXIS: case Obj::STAR_AXIS:
info.resize(1); info.resize(1);
info[0].reward.primary[PrimarySkill::SPELL_POWER] = 1; info[0].reward.primary[PrimarySkill::SPELL_POWER] = 1;
soundID = soundBase::gazebo; soundID = soundBase::gazebo;
onGrant.addTxt(MetaString::ADVOB_TXT, 100); info[0].message.addTxt(MetaString::ADVOB_TXT, 100);
onVisited.addTxt(MetaString::ADVOB_TXT, 101);
break; break;
case Obj::GARDEN_OF_REVELATION: case Obj::GARDEN_OF_REVELATION:
info.resize(1); info.resize(1);
info[0].reward.primary[PrimarySkill::KNOWLEDGE] = 1; info[0].reward.primary[PrimarySkill::KNOWLEDGE] = 1;
soundID = soundBase::GETPROTECTION; soundID = soundBase::GETPROTECTION;
onGrant.addTxt(MetaString::ADVOB_TXT, 59); info[0].message.addTxt(MetaString::ADVOB_TXT, 59);
onVisited.addTxt(MetaString::ADVOB_TXT, 60);
break; break;
case Obj::LEARNING_STONE: case Obj::LEARNING_STONE:
info.resize(1); info.resize(1);
info[0].reward.gainedExp = 1000; info[0].reward.gainedExp = 1000;
soundID = soundBase::gazebo; soundID = soundBase::gazebo;
onGrant.addTxt(MetaString::ADVOB_TXT, 143); info[0].message.addTxt(MetaString::ADVOB_TXT, 143);
onVisited.addTxt(MetaString::ADVOB_TXT, 144);
break; break;
case Obj::TREE_OF_KNOWLEDGE: case Obj::TREE_OF_KNOWLEDGE:
soundID = soundBase::gazebo; soundID = soundBase::gazebo;
info.resize(1); info.resize(1);
canRefuse = true;
info[0].reward.gainedLevels = 1; info[0].reward.gainedLevels = 1;
onVisited.addTxt(MetaString::ADVOB_TXT, 147);
info.resize(1); info.resize(1);
switch (cb->gameState()->getRandomGenerator().nextInt(2)) switch (cb->gameState()->getRandomGenerator().nextInt(2))
{ {
case 0: // free case 0: // free
onSelect.addTxt(MetaString::ADVOB_TXT, 148);
break; break;
case 1: case 1:
info[0].limiter.resources[Res::GOLD] = 2000; info[0].limiter.resources[Res::GOLD] = 2000;
info[0].reward.resources[Res::GOLD] = -2000; info[0].reward.resources[Res::GOLD] = -2000;
onSelect.addTxt(MetaString::ADVOB_TXT, 149);
onEmpty.addTxt(MetaString::ADVOB_TXT, 150);
break; break;
case 2: case 2:
info[0].limiter.resources[Res::GEMS] = 10; info[0].limiter.resources[Res::GEMS] = 10;
info[0].reward.resources[Res::GEMS] = -10; info[0].reward.resources[Res::GEMS] = -10;
onSelect.addTxt(MetaString::ADVOB_TXT, 151);
onEmpty.addTxt(MetaString::ADVOB_TXT, 152);
break; break;
} }
break; break;
case Obj::LIBRARY_OF_ENLIGHTENMENT: case Obj::LIBRARY_OF_ENLIGHTENMENT:
{ {
onGrant.addTxt(MetaString::ADVOB_TXT, 66);
onVisited.addTxt(MetaString::ADVOB_TXT, 67); onVisited.addTxt(MetaString::ADVOB_TXT, 67);
onEmpty.addTxt(MetaString::ADVOB_TXT, 68); onEmpty.addTxt(MetaString::ADVOB_TXT, 68);
@ -834,6 +869,7 @@ void CGVisitableOPH::initObj()
{ {
visit.limiter.minLevel = 10 - i * 2; visit.limiter.minLevel = 10 - i * 2;
visit.limiter.secondary[SecondarySkill::DIPLOMACY] = i; visit.limiter.secondary[SecondarySkill::DIPLOMACY] = i;
visit.message.addTxt(MetaString::ADVOB_TXT, 66);
info.push_back(visit); info.push_back(visit);
} }
soundID = soundBase::gazebo; soundID = soundBase::gazebo;
@ -843,15 +879,21 @@ void CGVisitableOPH::initObj()
info.resize(2); info.resize(2);
info[0].reward.primary[PrimarySkill::SPELL_POWER] = 1; info[0].reward.primary[PrimarySkill::SPELL_POWER] = 1;
info[1].reward.primary[PrimarySkill::KNOWLEDGE] = 1; info[1].reward.primary[PrimarySkill::KNOWLEDGE] = 1;
onSelect.addTxt(MetaString::ADVOB_TXT, 71);
onVisited.addTxt(MetaString::ADVOB_TXT, 72);
onEmpty.addTxt(MetaString::ADVOB_TXT, 73);
soundID = soundBase::faerie; soundID = soundBase::faerie;
onGrant.addTxt(MetaString::ADVOB_TXT, 71); canRefuse = true;
break; break;
case Obj::SCHOOL_OF_WAR: case Obj::SCHOOL_OF_WAR:
info.resize(2); info.resize(2);
info[0].reward.primary[PrimarySkill::ATTACK] = 1; info[0].reward.primary[PrimarySkill::ATTACK] = 1;
info[1].reward.primary[PrimarySkill::DEFENSE] = 1; info[1].reward.primary[PrimarySkill::DEFENSE] = 1;
onSelect.addTxt(MetaString::ADVOB_TXT, 158);
onVisited.addTxt(MetaString::ADVOB_TXT, 159);
onEmpty.addTxt(MetaString::ADVOB_TXT, 160);
soundID = soundBase::MILITARY; soundID = soundBase::MILITARY;
onGrant.addTxt(MetaString::ADVOB_TXT, 158); canRefuse = true;
break; break;
} }
} }
@ -922,15 +964,15 @@ void CGVisitableOPW::initObj()
{ {
case Obj::MYSTICAL_GARDEN: case Obj::MYSTICAL_GARDEN:
soundID = soundBase::experience; soundID = soundBase::experience;
onGrant.addTxt(MetaString::ADVOB_TXT, 92);
onEmpty.addTxt(MetaString::ADVOB_TXT, 93); onEmpty.addTxt(MetaString::ADVOB_TXT, 93);
info.resize(2); info.resize(2);
info[0].reward.resources[Res::GEMS] = 5; info[0].reward.resources[Res::GEMS] = 5;
info[1].reward.resources[Res::GOLD] = 500; info[1].reward.resources[Res::GOLD] = 500;
info[0].message.addTxt(MetaString::ADVOB_TXT, 92);
info[1].message.addTxt(MetaString::ADVOB_TXT, 92);
break; break;
case Obj::WINDMILL: case Obj::WINDMILL:
soundID = soundBase::GENIE; soundID = soundBase::GENIE;
onGrant.addTxt(MetaString::ADVOB_TXT, 170);
onEmpty.addTxt(MetaString::ADVOB_TXT, 169); onEmpty.addTxt(MetaString::ADVOB_TXT, 169);
// 3-6 of any resource but wood and gold // 3-6 of any resource but wood and gold
// this is UGLY. TODO: find better way to describe this // this is UGLY. TODO: find better way to describe this
@ -940,25 +982,31 @@ void CGVisitableOPW::initObj()
{ {
CVisitInfo visit; CVisitInfo visit;
visit.reward.resources[resID] = val; visit.reward.resources[resID] = val;
visit.message.addTxt(MetaString::ADVOB_TXT, 92);
info.push_back(visit); info.push_back(visit);
} }
} }
break; break;
case Obj::WATER_WHEEL: case Obj::WATER_WHEEL:
soundID = soundBase::GENIE; soundID = soundBase::GENIE;
onGrant.addTxt(MetaString::ADVOB_TXT, 164);
onEmpty.addTxt(MetaString::ADVOB_TXT, 165); onEmpty.addTxt(MetaString::ADVOB_TXT, 165);
info.resize(2); info.resize(2);
info[0].limiter.dayOfWeek = 7; // double amount on sunday info[0].limiter.dayOfWeek = 7; // double amount on sunday
info[0].reward.resources[Res::GOLD] = 1000; info[0].reward.resources[Res::GOLD] = 1000;
info[1].reward.resources[Res::GOLD] = 500; info[1].reward.resources[Res::GOLD] = 500;
info[0].message.addTxt(MetaString::ADVOB_TXT, 164);
info[1].message.addTxt(MetaString::ADVOB_TXT, 164);
break; break;
} }
} }
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
void CGMagicSpring::initObj()
{
}
std::vector<int3> CGMagicSpring::getVisitableOffsets() const std::vector<int3> CGMagicSpring::getVisitableOffsets() const
{ {

View File

@ -145,6 +145,8 @@ class DLL_LINKAGE CObjectWithReward : public CArmedInstance
/// function that must be called if hero got level-up during grantReward call /// function that must be called if hero got level-up during grantReward call
void grantRewardAfterLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const; void grantRewardAfterLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const;
/// grants reward to hero
void grantRewardBeforeLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const;
protected: protected:
/// controls selection of reward granted to player /// controls selection of reward granted to player
enum ESelectMode enum ESelectMode
@ -165,14 +167,13 @@ protected:
/// filters list of visit info and returns rewards that can be granted to current hero /// filters list of visit info and returns rewards that can be granted to current hero
virtual std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const; virtual std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const;
/// grants reward to hero void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
void grantReward(const CVisitInfo & reward, const CGHeroInstance * hero) const;
/// Rewars that can be granted by an object /// Rewars that can be granted by an object
std::vector<CVisitInfo> info; std::vector<CVisitInfo> info;
/// MetaString's that contain text for messages for specific situations /// MetaString's that contain text for messages for specific situations
MetaString onGrant; MetaString onSelect;
MetaString onVisited; MetaString onVisited;
MetaString onEmpty; MetaString onEmpty;
@ -188,6 +189,9 @@ protected:
/// object visitability info will be reset each resetDuration days /// object visitability info will be reset each resetDuration days
ui16 resetDuration; ui16 resetDuration;
/// if true - player can refuse visiting an object (e.g. Tomb)
bool canRefuse;
public: public:
void setPropertyDer(ui8 what, ui32 val) override; void setPropertyDer(ui8 what, ui32 val) override;
const std::string & getHoverText() const override; const std::string & getHoverText() const override;
@ -216,8 +220,8 @@ public:
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & static_cast<CArmedInstance&>(*this); h & static_cast<CArmedInstance&>(*this);
h & info; h & info & canRefuse;
h & onGrant & onVisited & onEmpty; h & onSelect & onVisited & onEmpty;
h & soundID & selectMode & selectedReward; h & soundID & selectMode & selectedReward;
} }
}; };
@ -295,6 +299,7 @@ protected:
std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const override; std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const override;
public: public:
void initObj() override;
std::vector<int3> getVisitableOffsets() const; std::vector<int3> getVisitableOffsets() const;
int3 getVisitableOffset() const override; int3 getVisitableOffset() const override;