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

Rumors: implement support for grail terrain rumor

This commit is contained in:
ArseniyShestakov 2015-12-01 04:57:52 +03:00
parent c5485ceede
commit ffcc5ccdd2
3 changed files with 23 additions and 17 deletions

View File

@ -567,7 +567,7 @@ EPlayerStatus::EStatus CGameInfoCallback::getPlayerStatus(PlayerColor player, bo
std::string CGameInfoCallback::getTavernRumor(const CGObjectInstance * townOrTavern) const std::string CGameInfoCallback::getTavernRumor(const CGObjectInstance * townOrTavern) const
{ {
std::string text = ""; std::string text = "", extraText = "";
if(gs->rumor.type == RumorState::RUMOR_NONE) // (version < 755 backward compatability if(gs->rumor.type == RumorState::RUMOR_NONE) // (version < 755 backward compatability
return text; return text;
@ -575,9 +575,14 @@ std::string CGameInfoCallback::getTavernRumor(const CGObjectInstance * townOrTav
switch(gs->rumor.type) switch(gs->rumor.type)
{ {
case RumorState::RUMOR_STATS: case RumorState::RUMOR_STATS:
text = boost::str(boost::format(VLC->generaltexth->allTexts[rumor.first]) % VLC->generaltexth->capColors[rumor.second]); if(rumor.first == 212)
break; extraText = VLC->generaltexth->arraytxt[158 + rumor.second];
else
extraText = VLC->generaltexth->capColors[rumor.second];
text = boost::str(boost::format(VLC->generaltexth->allTexts[rumor.first]) % extraText);
break;
case RumorState::RUMOR_MAP: case RumorState::RUMOR_MAP:
text = gs->map->rumors[rumor.first].text; text = gs->map->rumors[rumor.first].text;
break; break;

View File

@ -2136,10 +2136,9 @@ int3 CGameState::guardingCreaturePosition (int3 pos) const
void CGameState::updateRumor() void CGameState::updateRumor()
{ {
static std::vector<RumorState::ERumorType> rumorTypes = {RumorState::RUMOR_MAP, RumorState::RUMOR_STATS, RumorState::RUMOR_RAND, RumorState::RUMOR_RAND}; static std::vector<RumorState::ERumorType> rumorTypes = {RumorState::RUMOR_MAP, RumorState::RUMOR_STATS, RumorState::RUMOR_RAND, RumorState::RUMOR_RAND};
static std::vector<int> statsRumorTypes = {208, 209, 210};// 211, 212}; static std::vector<int> statsRumorTypes = {208, 209, 210, 212};// 211};
int rumorId = -1; int rumorId = -1, rumorExtra = -1;
int rumorPlayer = PlayerColor::CANNOT_DETERMINE.getNum();
auto & rand = gs->getRandomGenerator(); auto & rand = gs->getRandomGenerator();
rumor.type = *RandomGeneratorUtil::nextItem(rumorTypes, rand); rumor.type = *RandomGeneratorUtil::nextItem(rumorTypes, rand);
if(!gs->map->rumors.size() && rumor.type == RumorState::RUMOR_MAP) if(!gs->map->rumors.size() && rumor.type == RumorState::RUMOR_MAP)
@ -2153,8 +2152,14 @@ void CGameState::updateRumor()
{ {
SThievesGuildInfo tgi; SThievesGuildInfo tgi;
gs->obtainPlayersStats(tgi, 20); gs->obtainPlayersStats(tgi, 20);
std::vector<PlayerColor> players = {};
rumorId = *RandomGeneratorUtil::nextItem(statsRumorTypes, rand); rumorId = *RandomGeneratorUtil::nextItem(statsRumorTypes, rand);
if(rumorId == 212)
{
rumorExtra = getTile(map->grailPos)->terType;
break;
}
std::vector<PlayerColor> players = {};
switch(rumorId) switch(rumorId)
{ {
case 208: case 208:
@ -2173,12 +2178,8 @@ void CGameState::updateRumor()
/// TODO: not implemented in obtainPlayersStats /// TODO: not implemented in obtainPlayersStats
players = tgi.income[0]; players = tgi.income[0];
break; break;
case 212:
/// TODO: Check that ultimate artifact (grail) found
break;
} }
rumorPlayer = RandomGeneratorUtil::nextItem(players, rand)->getNum(); rumorExtra = RandomGeneratorUtil::nextItem(players, rand)->getNum();
break; break;
} }
@ -2197,7 +2198,7 @@ void CGameState::updateRumor()
break; break;
} }
} }
while(!rumor.update(rumorId, rumorPlayer)); while(!rumor.update(rumorId, rumorExtra));
} }
bool CGameState::isVisible(int3 pos, PlayerColor player) bool CGameState::isVisible(int3 pos, PlayerColor player)
@ -2867,20 +2868,20 @@ std::string PlayerState::nodeName() const
} }
bool RumorState::update(int id, int player) bool RumorState::update(int id, int extra)
{ {
if(vstd::contains(last, type)) if(vstd::contains(last, type))
{ {
if(last[type].first != id) if(last[type].first != id)
{ {
last[type].first = id; last[type].first = id;
last[type].second = player; last[type].second = extra;
} }
else else
return false; return false;
} }
else else
last[type] = std::make_pair(id, player); last[type] = std::make_pair(id, extra);
return true; return true;
} }

View File

@ -219,7 +219,7 @@ struct DLL_LINKAGE RumorState
std::map<ERumorType, std::pair<int, int>> last; std::map<ERumorType, std::pair<int, int>> last;
RumorState(){type = RUMOR_NONE; last = {};}; RumorState(){type = RUMOR_NONE; last = {};};
bool update(int id, int player); bool update(int id, int extra);
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {