2022-07-26 15:07:42 +02:00
|
|
|
/*
|
2014-06-05 20:26:50 +03:00
|
|
|
* CBank.cpp, part of VCMI engine
|
2014-06-05 19:52:14 +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 20:26:50 +03:00
|
|
|
#include "CBank.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
#include <vcmi/spells/Spell.h>
|
|
|
|
#include <vcmi/spells/Service.h>
|
|
|
|
|
2014-06-05 20:26:50 +03:00
|
|
|
#include "../NetPacks.h"
|
|
|
|
#include "../CGeneralTextHandler.h"
|
2014-06-05 23:51:24 +03:00
|
|
|
#include "../CSoundBase.h"
|
2023-07-19 12:17:50 +02:00
|
|
|
#include "../GameSettings.h"
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
2023-06-06 17:32:53 +02:00
|
|
|
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
|
2014-06-25 17:11:07 +03:00
|
|
|
#include "../IGameCallback.h"
|
2023-06-23 17:02:48 +02:00
|
|
|
#include "../gameState/CGameState.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
///helpers
|
2023-01-01 20:54:05 +02:00
|
|
|
static std::string visitedTxt(const bool visited)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
int id = visited ? 352 : 353;
|
|
|
|
return VLC->generaltexth->allTexts[id];
|
|
|
|
}
|
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
//must be instantiated in .cpp file for access to complete types of all member fields
|
|
|
|
CBank::CBank() = default;
|
|
|
|
//must be instantiated in .cpp file for access to complete types of all member fields
|
|
|
|
CBank::~CBank() = default;
|
2014-06-22 13:39:40 +03:00
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CBank::initObj(CRandomGenerator & rand)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
daycounter = 0;
|
2014-06-22 13:39:40 +03:00
|
|
|
resetDuration = 0;
|
2016-09-09 19:30:36 +02:00
|
|
|
VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, rand);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2014-06-22 13:39:40 +03:00
|
|
|
|
2023-06-21 15:49:44 +02:00
|
|
|
bool CBank::isCoastVisitable() const
|
|
|
|
{
|
|
|
|
return coastVisitable;
|
|
|
|
}
|
|
|
|
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string CBank::getHoverText(PlayerColor player) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-24 20:39:36 +03:00
|
|
|
// TODO: record visited players
|
2014-06-30 00:16:45 +03:00
|
|
|
return getObjectName() + " " + visitedTxt(bc == nullptr);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2014-06-22 13:39:40 +03:00
|
|
|
void CBank::setConfig(const BankConfig & config)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
bc = std::make_unique<BankConfig>(config);
|
2023-08-07 18:13:02 +02:00
|
|
|
clearSlots(); // remove all stacks, if any
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
for(const auto & stack : config.guards)
|
2023-01-02 18:00:51 +02:00
|
|
|
setCreature (SlotID(stacksCount()), stack.type->getId(), stack.count);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2014-06-22 13:39:40 +03:00
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
void CBank::setPropertyDer (ui8 what, ui32 val)
|
|
|
|
{
|
|
|
|
switch (what)
|
|
|
|
{
|
|
|
|
case ObjProperty::BANK_DAYCOUNTER: //daycounter
|
2014-06-22 13:39:40 +03:00
|
|
|
daycounter+=val;
|
2014-06-05 19:52:14 +03:00
|
|
|
break;
|
|
|
|
case ObjProperty::BANK_RESET:
|
2016-09-09 19:30:36 +02:00
|
|
|
// FIXME: Object reset must be done by separate netpack from server
|
|
|
|
initObj(cb->gameState()->getRandomGenerator());
|
2014-06-22 13:39:40 +03:00
|
|
|
daycounter = 1; //yes, 1 since "today" daycounter won't be incremented
|
2014-06-05 19:52:14 +03:00
|
|
|
break;
|
2014-06-22 13:39:40 +03:00
|
|
|
case ObjProperty::BANK_CLEAR:
|
|
|
|
bc.reset();
|
2014-06-05 19:52:14 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CBank::newTurn(CRandomGenerator & rand) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
if (bc == nullptr)
|
|
|
|
{
|
2014-06-22 13:39:40 +03:00
|
|
|
if (resetDuration != 0)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-22 13:39:40 +03:00
|
|
|
if (daycounter >= resetDuration)
|
|
|
|
cb->setObjProperty (id, ObjProperty::BANK_RESET, 0); //daycounter 0
|
|
|
|
else
|
|
|
|
cb->setObjProperty (id, ObjProperty::BANK_DAYCOUNTER, 1); //daycounter++
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-22 13:39:40 +03:00
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
bool CBank::wasVisited (PlayerColor player) const
|
|
|
|
{
|
2014-06-22 13:39:40 +03:00
|
|
|
return !bc; //FIXME: player A should not know about visit done by player B
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2017-11-15 22:16:44 +02:00
|
|
|
void CBank::onHeroVisit(const CGHeroInstance * h) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2017-11-15 22:16:44 +02:00
|
|
|
int banktext = 0;
|
|
|
|
switch (ID)
|
|
|
|
{
|
|
|
|
case Obj::DERELICT_SHIP:
|
|
|
|
banktext = 41;
|
|
|
|
break;
|
|
|
|
case Obj::DRAGON_UTOPIA:
|
|
|
|
banktext = 47;
|
|
|
|
break;
|
|
|
|
case Obj::CRYPT:
|
|
|
|
banktext = 119;
|
|
|
|
break;
|
|
|
|
case Obj::SHIPWRECK:
|
|
|
|
banktext = 122;
|
|
|
|
break;
|
|
|
|
case Obj::PYRAMID:
|
|
|
|
banktext = 105;
|
|
|
|
break;
|
|
|
|
case Obj::CREATURE_BANK:
|
|
|
|
default:
|
|
|
|
banktext = 32;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BlockingDialog bd(true, false);
|
|
|
|
bd.player = h->getOwner();
|
2019-05-03 00:46:18 +02:00
|
|
|
bd.soundID = soundBase::invalid; // Sound is handled in json files, else two sounds are played
|
2023-06-18 11:18:25 +02:00
|
|
|
bd.text.appendLocalString(EMetaText::ADVOB_TXT, banktext);
|
2017-11-15 22:16:44 +02:00
|
|
|
if (banktext == 32)
|
2023-06-18 11:18:25 +02:00
|
|
|
bd.text.replaceRawString(getObjectName());
|
2023-07-19 12:17:50 +02:00
|
|
|
|
|
|
|
if (VLC->settings()->getBoolean(EGameSettings::BANKS_SHOW_GUARDS_COMPOSITION))
|
|
|
|
{
|
|
|
|
std::map<CreatureID, int> guardsAmounts;
|
|
|
|
|
2023-07-19 13:21:33 +02:00
|
|
|
for (auto const & slot : Slots())
|
|
|
|
if (slot.second)
|
|
|
|
guardsAmounts[slot.second->getCreatureID()] += slot.second->getCount();
|
2023-07-19 12:17:50 +02:00
|
|
|
|
|
|
|
for (auto const & guard : guardsAmounts)
|
|
|
|
{
|
|
|
|
Component comp;
|
|
|
|
comp.id = Component::EComponentType::CREATURE;
|
|
|
|
comp.subtype = guard.first.getNum();
|
|
|
|
comp.val = guard.second;
|
|
|
|
|
|
|
|
bd.components.push_back(comp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 22:16:44 +02:00
|
|
|
cb->showBlockingDialog(&bd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBank::doVisit(const CGHeroInstance * hero) const
|
|
|
|
{
|
|
|
|
int textID = -1;
|
|
|
|
InfoWindow iw;
|
2023-03-07 03:09:19 +02:00
|
|
|
iw.type = EInfoWindowMode::AUTO;
|
2017-11-15 22:16:44 +02:00
|
|
|
iw.player = hero->getOwner();
|
|
|
|
MetaString loot;
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
if (bc)
|
|
|
|
{
|
|
|
|
switch (ID)
|
|
|
|
{
|
|
|
|
case Obj::DERELICT_SHIP:
|
2017-11-15 22:16:44 +02:00
|
|
|
textID = 43;
|
2014-06-05 19:52:14 +03:00
|
|
|
break;
|
|
|
|
case Obj::CRYPT:
|
2017-11-15 22:16:44 +02:00
|
|
|
textID = 121;
|
2014-06-05 19:52:14 +03:00
|
|
|
break;
|
|
|
|
case Obj::SHIPWRECK:
|
2017-11-15 22:16:44 +02:00
|
|
|
textID = 124;
|
2014-06-05 19:52:14 +03:00
|
|
|
break;
|
2014-06-22 13:39:40 +03:00
|
|
|
case Obj::PYRAMID:
|
2017-11-15 22:16:44 +02:00
|
|
|
textID = 106;
|
|
|
|
break;
|
|
|
|
case Obj::CREATURE_BANK:
|
|
|
|
case Obj::DRAGON_UTOPIA:
|
|
|
|
default:
|
|
|
|
textID = 34;
|
2014-06-22 13:39:40 +03:00
|
|
|
break;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-15 22:16:44 +02:00
|
|
|
switch (ID)
|
2014-06-22 13:39:40 +03:00
|
|
|
{
|
2017-11-15 22:16:44 +02:00
|
|
|
case Obj::SHIPWRECK:
|
|
|
|
case Obj::DERELICT_SHIP:
|
|
|
|
case Obj::CRYPT:
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
GiveBonus gbonus;
|
2014-06-22 13:39:40 +03:00
|
|
|
gbonus.id = hero->id.getNum();
|
2023-05-01 00:20:01 +02:00
|
|
|
gbonus.bonus.duration = BonusDuration::ONE_BATTLE;
|
|
|
|
gbonus.bonus.source = BonusSource::OBJECT;
|
2014-06-05 19:52:14 +03:00
|
|
|
gbonus.bonus.sid = ID;
|
2023-05-01 00:20:01 +02:00
|
|
|
gbonus.bonus.type = BonusType::MORALE;
|
2014-06-05 19:52:14 +03:00
|
|
|
gbonus.bonus.val = -1;
|
2017-11-15 22:16:44 +02:00
|
|
|
switch (ID)
|
|
|
|
{
|
|
|
|
case Obj::SHIPWRECK:
|
|
|
|
textID = 123;
|
2023-06-18 11:18:25 +02:00
|
|
|
gbonus.bdescr.appendRawString(VLC->generaltexth->arraytxt[99]);
|
2017-11-15 22:16:44 +02:00
|
|
|
break;
|
|
|
|
case Obj::DERELICT_SHIP:
|
|
|
|
textID = 42;
|
2023-06-18 11:18:25 +02:00
|
|
|
gbonus.bdescr.appendRawString(VLC->generaltexth->arraytxt[101]);
|
2017-11-15 22:16:44 +02:00
|
|
|
break;
|
|
|
|
case Obj::CRYPT:
|
|
|
|
textID = 120;
|
2023-06-18 11:18:25 +02:00
|
|
|
gbonus.bdescr.appendRawString(VLC->generaltexth->arraytxt[98]);
|
2017-11-15 22:16:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->giveHeroBonus(&gbonus);
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::MORALE, 0, -1, 0);
|
2017-11-15 22:16:44 +02:00
|
|
|
iw.soundID = soundBase::GRAVEYARD;
|
|
|
|
break;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2017-11-15 22:16:44 +02:00
|
|
|
case Obj::PYRAMID:
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2017-11-15 22:16:44 +02:00
|
|
|
GiveBonus gb;
|
2023-05-01 00:20:01 +02:00
|
|
|
gb.bonus = Bonus(BonusDuration::ONE_BATTLE, BonusType::LUCK, BonusSource::OBJECT, -2, id.getNum(), VLC->generaltexth->arraytxt[70]);
|
2017-11-15 22:16:44 +02:00
|
|
|
gb.id = hero->id.getNum();
|
|
|
|
cb->giveHeroBonus(&gb);
|
|
|
|
textID = 107;
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::LUCK, 0, -2, 0);
|
2017-11-15 22:16:44 +02:00
|
|
|
break;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2017-11-15 22:16:44 +02:00
|
|
|
case Obj::CREATURE_BANK:
|
|
|
|
case Obj::DRAGON_UTOPIA:
|
|
|
|
default:
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendRawString(VLC->generaltexth->advobtxt[33]);// This was X, now is completely empty
|
|
|
|
iw.text.replaceRawString(getObjectName());
|
2017-11-15 22:16:44 +02:00
|
|
|
}
|
|
|
|
if(textID != -1)
|
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, textID);
|
2017-11-15 22:16:44 +02:00
|
|
|
}
|
|
|
|
cb->showInfoDialog(&iw);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2014-06-22 13:39:40 +03:00
|
|
|
//grant resources
|
|
|
|
if (bc)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-22 13:39:40 +03:00
|
|
|
for (int it = 0; it < bc->resources.size(); it++)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-22 13:39:40 +03:00
|
|
|
if (bc->resources[it] != 0)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::RESOURCE, it, bc->resources[it], 0);
|
2023-06-18 11:18:25 +02:00
|
|
|
loot.appendRawString("%d %s");
|
|
|
|
loot.replaceNumber(iw.components.back().val);
|
|
|
|
loot.replaceLocalString(EMetaText::RES_NAMES, iw.components.back().subtype);
|
2023-04-05 02:26:29 +02:00
|
|
|
cb->giveResource(hero->getOwner(), static_cast<EGameResID>(it), bc->resources[it]);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//grant artifacts
|
2014-06-22 13:39:40 +03:00
|
|
|
for (auto & elem : bc->artifacts)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::ARTIFACT, elem, 0, 0);
|
2023-06-18 11:18:25 +02:00
|
|
|
loot.appendRawString("%s");
|
|
|
|
loot.replaceLocalString(EMetaText::ART_NAMES, elem);
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
cb->giveHeroNewArtifact(hero, VLC->arth->objects[elem], ArtifactPosition::FIRST_AVAILABLE);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
//display loot
|
|
|
|
if (!iw.components.empty())
|
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, textID);
|
2014-06-05 19:52:14 +03:00
|
|
|
if (textID == 34)
|
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
const auto * strongest = boost::range::max_element(bc->guards, [](const CStackBasicDescriptor & a, const CStackBasicDescriptor & b)
|
2014-06-22 13:39:40 +03:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
return a.type->getFightValue() < b.type->getFightValue();
|
2014-06-22 13:39:40 +03:00
|
|
|
})->type;
|
|
|
|
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.replaceLocalString(EMetaText::CRE_PL_NAMES, strongest->getId());
|
|
|
|
iw.text.replaceRawString(loot.buildList());
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
2014-06-22 13:39:40 +03:00
|
|
|
|
2016-10-09 12:41:35 +02:00
|
|
|
loot.clear();
|
|
|
|
iw.components.clear();
|
|
|
|
iw.text.clear();
|
|
|
|
|
2014-06-22 13:39:40 +03:00
|
|
|
if (!bc->spells.empty())
|
|
|
|
{
|
|
|
|
std::set<SpellID> spells;
|
|
|
|
|
|
|
|
bool noWisdom = false;
|
2017-11-15 22:16:44 +02:00
|
|
|
if(textID == 106)
|
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, textID); //pyramid
|
2017-11-15 22:16:44 +02:00
|
|
|
}
|
2016-10-09 12:41:35 +02:00
|
|
|
for(const SpellID & spellId : bc->spells)
|
2014-06-22 13:39:40 +03:00
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
const auto * spell = spellId.toSpell(VLC->spells());
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::SPELL_NAME, spellId);
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(spell->getLevel() <= hero->maxSpellLevel())
|
2014-06-22 13:39:40 +03:00
|
|
|
{
|
2016-10-09 12:41:35 +02:00
|
|
|
if(hero->canLearnSpell(spell))
|
|
|
|
{
|
|
|
|
spells.insert(spellId);
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::SPELL, spellId, 0, 0);
|
2016-10-09 12:41:35 +02:00
|
|
|
}
|
2014-06-22 13:39:40 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
noWisdom = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hero->getArt(ArtifactPosition::SPELLBOOK))
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 109); //no spellbook
|
2017-11-15 22:16:44 +02:00
|
|
|
else if(noWisdom)
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 108); //no expert Wisdom
|
2016-10-09 12:41:35 +02:00
|
|
|
|
|
|
|
if(!iw.components.empty() || !iw.text.toString().empty())
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
|
|
|
|
if(!spells.empty())
|
2017-11-15 22:16:44 +02:00
|
|
|
cb->changeSpells(hero, true, spells);
|
2014-06-22 13:39:40 +03:00
|
|
|
}
|
2016-10-09 12:41:35 +02:00
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
iw.components.clear();
|
|
|
|
iw.text.clear();
|
|
|
|
|
|
|
|
//grant creatures
|
|
|
|
CCreatureSet ourArmy;
|
2023-02-12 22:39:17 +02:00
|
|
|
for(const auto & slot : bc->creatures)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
ourArmy.addToSlot(ourArmy.getSlotFor(slot.type->getId()), slot.type->getId(), slot.count);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2014-06-22 13:39:40 +03:00
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
for(const auto & elem : ourArmy.Slots())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
iw.components.emplace_back(*elem.second);
|
2023-06-18 11:18:25 +02:00
|
|
|
loot.appendRawString("%s");
|
|
|
|
loot.replaceCreatureName(*elem.second);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2015-12-24 20:30:57 +02:00
|
|
|
if(ourArmy.stacksCount())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2015-12-24 20:30:57 +02:00
|
|
|
if(ourArmy.stacksCount() == 1 && ourArmy.Slots().begin()->second->count == 1)
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 185);
|
2014-06-05 19:52:14 +03:00
|
|
|
else
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 186);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.replaceRawString(loot.buildList());
|
|
|
|
iw.text.replaceRawString(hero->getNameTranslated());
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
cb->giveCreatures(this, hero, ourArmy, false);
|
|
|
|
}
|
2017-11-15 22:16:44 +02:00
|
|
|
cb->setObjProperty(id, ObjProperty::BANK_CLEAR, 0); //bc = nullptr
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 13:39:40 +03:00
|
|
|
void CBank::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-22 13:39:40 +03:00
|
|
|
if (result.winner == 0)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-22 13:39:40 +03:00
|
|
|
doVisit(hero);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 13:39:40 +03:00
|
|
|
void CBank::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-22 13:39:40 +03:00
|
|
|
if (answer)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-22 13:39:40 +03:00
|
|
|
if (bc) // not looted bank
|
|
|
|
cb->startBattleI(hero, this, true);
|
2014-06-05 19:52:14 +03:00
|
|
|
else
|
2014-06-22 13:39:40 +03:00
|
|
|
doVisit(hero);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|