mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
Reworked resource piles loading to fix wog maps with mithril
This commit is contained in:
@ -256,115 +256,6 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
}
|
||||
}
|
||||
|
||||
GameResID CGResource::resourceID() const
|
||||
{
|
||||
return getObjTypeIndex().getNum();
|
||||
}
|
||||
|
||||
std::string CGResource::getHoverText(PlayerColor player) const
|
||||
{
|
||||
return VLC->generaltexth->restypes[resourceID().getNum()];
|
||||
}
|
||||
|
||||
void CGResource::pickRandomObject(vstd::RNG & rand)
|
||||
{
|
||||
assert(ID == Obj::RESOURCE || ID == Obj::RANDOM_RESOURCE);
|
||||
|
||||
if (ID == Obj::RANDOM_RESOURCE)
|
||||
{
|
||||
ID = Obj::RESOURCE;
|
||||
subID = rand.nextInt(EGameResID::WOOD, EGameResID::GOLD);
|
||||
setType(ID, subID);
|
||||
|
||||
if (subID == EGameResID::GOLD && amount != CGResource::RANDOM_AMOUNT)
|
||||
amount *= CGResource::GOLD_AMOUNT_MULTIPLIER;
|
||||
}
|
||||
}
|
||||
|
||||
void CGResource::initObj(vstd::RNG & rand)
|
||||
{
|
||||
blockVisit = true;
|
||||
|
||||
if(amount == CGResource::RANDOM_AMOUNT)
|
||||
{
|
||||
switch(resourceID().toEnum())
|
||||
{
|
||||
case EGameResID::GOLD:
|
||||
amount = rand.nextInt(5, 10) * CGResource::GOLD_AMOUNT_MULTIPLIER;
|
||||
break;
|
||||
case EGameResID::WOOD: case EGameResID::ORE:
|
||||
amount = rand.nextInt(6, 10);
|
||||
break;
|
||||
default:
|
||||
amount = rand.nextInt(3, 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGResource::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
if(stacksCount())
|
||||
{
|
||||
if(!message.empty())
|
||||
{
|
||||
BlockingDialog ynd(true,false);
|
||||
ynd.player = h->getOwner();
|
||||
ynd.text = message;
|
||||
cb->showBlockingDialog(this, &ynd);
|
||||
}
|
||||
else
|
||||
{
|
||||
blockingDialogAnswered(h, true); //behave as if player accepted battle
|
||||
}
|
||||
}
|
||||
else
|
||||
collectRes(h->getOwner());
|
||||
}
|
||||
|
||||
void CGResource::collectRes(const PlayerColor & player) const
|
||||
{
|
||||
cb->giveResource(player, resourceID(), amount);
|
||||
InfoWindow sii;
|
||||
sii.player = player;
|
||||
if(!message.empty())
|
||||
{
|
||||
sii.type = EInfoWindowMode::AUTO;
|
||||
sii.text = message;
|
||||
}
|
||||
else
|
||||
{
|
||||
sii.type = EInfoWindowMode::INFO;
|
||||
sii.text.appendLocalString(EMetaText::ADVOB_TXT,113);
|
||||
sii.text.replaceName(resourceID());
|
||||
}
|
||||
sii.components.emplace_back(ComponentType::RESOURCE, resourceID(), amount);
|
||||
sii.soundID = soundBase::pickup01 + cb->gameState()->getRandomGenerator().nextInt(6);
|
||||
cb->showInfoDialog(&sii);
|
||||
cb->removeObject(this, player);
|
||||
}
|
||||
|
||||
void CGResource::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
|
||||
{
|
||||
if(result.winner == BattleSide::ATTACKER) //attacker won
|
||||
collectRes(hero->getOwner());
|
||||
}
|
||||
|
||||
void CGResource::blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const
|
||||
{
|
||||
if(answer)
|
||||
cb->startBattle(hero, this);
|
||||
}
|
||||
|
||||
void CGResource::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
{
|
||||
CArmedInstance::serializeJsonOptions(handler);
|
||||
if(!handler.saving && !handler.getCurrent()["guards"].Vector().empty())
|
||||
CCreatureSet::serializeJson(handler, "guards", 7);
|
||||
handler.serializeInt("amount", amount, 0);
|
||||
handler.serializeStruct("guardMessage", message);
|
||||
}
|
||||
|
||||
bool CGTeleport::isEntrance() const
|
||||
{
|
||||
return type == BOTH || type == ENTRANCE;
|
||||
|
Reference in New Issue
Block a user