diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 57d5eda62..cac13cca2 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -43,7 +43,7 @@ extern CLodHandler * bitmaph; extern boost::rand48 ran; std::map > CGKeys::playerKeyMap; std::map > CGMagi::eyelist; - +BankConfig CGPyramid::pyramidConfig; void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const {}; @@ -1624,9 +1624,8 @@ void CGTownInstance::removeCapitols (ui8 owner, bool me) const RazeStructures rs; rs.tid = id; rs.bid.insert(13); - si16 builded = destroyed; + rs.destroyed = destroyed; cb->sendAndApply(&rs); - //cb->gameState()->getTown(id)->builtBuildings.erase(13); //destroy local capitol return; } else @@ -4249,6 +4248,72 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons cb->setObjProperty (id, 14, ran()); //reset } +void CGPyramid::initObj() +{ +//would be nice to do that only once + if (!pyramidConfig.guards.size()) + { + pyramidConfig.level = 1; + pyramidConfig.chance = 100; + pyramidConfig.upgradeChance = 0; + for (int i = 0; i < 2; ++i) + { + pyramidConfig.guards.push_back (std::pair (116, 20)); + pyramidConfig.guards.push_back (std::pair (117, 10)); + } + pyramidConfig.combatValue; //how hard are guards of this level + pyramidConfig.value; //overall value of given things + pyramidConfig.rewardDifficulty; //proportion of reward value to difficulty of guards; how profitable is this creature Bank config + pyramidConfig.easiest; //?!? + } + bc = &pyramidConfig; + std::vector avaliable; + cb->getAllowedSpells (avaliable, 5); + spell = (avaliable[rand()%avaliable.size()]); +} +void CGPyramid::onHeroVisit (const CGHeroInstance * h) const +{ + if (bc) + { + BlockingDialog bd (true, false); + bd.player = h->getOwner(); + bd.soundID = soundBase::DANGER; + bd.text << VLC->generaltexth->advobtxt[105]; + cb->showBlockingDialog (&bd, boost::bind (&CBank::fightGuards, this, h, _1)); + } + else + { + InfoWindow iw; + iw.text << VLC->generaltexth->advobtxt[107]; + iw.components.push_back (Component (Component::LUCK, 0 , -2, 0)); + GiveBonus gb; + gb.bonus = HeroBonus(HeroBonus::ONE_BATTLE,HeroBonus::LUCK,HeroBonus::OBJECT,-2,id,VLC->generaltexth->arraytxt[ID]); + cb->giveHeroBonus(&gb); + cb->showInfoDialog(&iw); + } +} + +void CGPyramid::endBattle (const CGHeroInstance *h, const BattleResult *result) const +{ + if (result->winner == 0) + { + InfoWindow iw; + iw.text.addTxt (MetaString::ADVOB_TXT, 106); + iw.text.addTxt (MetaString::SPELL_NAME, spell); + if (!h->getArt(17)) //no spellbook + iw.text.addTxt (MetaString::ADVOB_TXT, 109); + else if (h->getSecSkillLevel(7) < 3) //no expert Wisdom + iw.text.addTxt (MetaString::ADVOB_TXT, 108); + else + { + std::set spells; + spells.insert (spell); + cb->changeSpells (h->id, true, spells); + iw.components.push_back(Component (Component::SPELL, spell, 0, 0)); + } + cb->showInfoDialog(&iw); + } +} void CGKeys::setPropertyDer (ui8 what, ui32 val) //101-108 - enable key for player 1-8 { if (what >= 101 && what <= (100 + PLAYER_LIMIT)) @@ -4658,7 +4723,7 @@ void CShop::setPropertyDer (ui8 what, ui32 val) void CGArtMerchant::reset(ui32 val) { std::vector::iterator index; - for (ui8 i = 0; i <= 6; i++) + for (ui8 i = 0; i < 4; ++i) //each tier { int count = 0; std::vector arts; //to avoid addition of different tiers diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 336378134..024174502 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -912,6 +912,24 @@ class DLL_EXPORT CBank : public CArmedInstance h & index & multiplier & artifacts & daycounter; } }; +class DLL_EXPORT CGPyramid : public CBank +{ +public: + static BankConfig pyramidConfig; + ui16 spell; + + void initObj(); + void newTurn() const {}; //empty, no reset + void onHeroVisit (const CGHeroInstance * h) const; + void fightGuards (const CGHeroInstance *h, ui32 accept) const {}; + void endBattle (const CGHeroInstance *h, const BattleResult *result) const; + + template void serialize(Handler &h, const int version) + { + h & static_cast(*this); + h & spell; + } +}; class CGShipyard : public CGObjectInstance, public IShipyard { diff --git a/hch/CSpellHandler.cpp b/hch/CSpellHandler.cpp index 7e4e5c5a9..b9d3857ba 100644 --- a/hch/CSpellHandler.cpp +++ b/hch/CSpellHandler.cpp @@ -122,7 +122,10 @@ namespace SRSLPraserHelpers } } using namespace SRSLPraserHelpers; - +CSpellHandler::CSpellHandler() +{ + VLC->spellh = this; +} std::set CSpell::rangeInHexes(unsigned int centralHex, ui8 schoolLvl ) const { std::set ret; diff --git a/hch/CSpellHandler.h b/hch/CSpellHandler.h index bef51c3c7..d696d5f0e 100644 --- a/hch/CSpellHandler.h +++ b/hch/CSpellHandler.h @@ -6,6 +6,7 @@ #include #include "CSoundBase.h" +//#include "map.h" /* * CSpellHandler.h, part of VCMI engine @@ -53,6 +54,7 @@ public: class DLL_EXPORT CSpellHandler { public: + CSpellHandler::CSpellHandler(); std::vector spells; void loadSpells(); diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 4bcd8de31..873418dfd 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -5,6 +5,7 @@ #include "../hch/CObjectHandler.h" #include "../StartInfo.h" #include "../hch/CArtHandler.h" +#include "../hch/CSpellHandler.h" #include "../lib/VCMI_Lib.h" /* @@ -190,6 +191,17 @@ void IGameCallback::getAllowed(std::vector &out, int flags) getAllowedArts(out,&CArtHandler::relics); } +void IGameCallback::getAllowedSpells(std::vector &out, ui16 level) +{ + for (int i = 0; i < (VLC->spellh->spells).size(); i++) + { + if (isAllowed (1, i)) + { + out.push_back(i); + } + } +} + int3 IGameCallback::getMapSize() { return int3(gs->map->width, gs->map->height, gs->map->twoLevel + 1); diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index 4b656f282..e73b79591 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -59,6 +59,7 @@ public: virtual bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact virtual void getAllowedArts(std::vector &out, std::vector CArtHandler::*arts); virtual void getAllowed(std::vector &out, int flags); //flags: bitfield uses EartClass + virtual void getAllowedSpells(std::vector &out, ui16 level); virtual int3 getMapSize(); //returns size of the map virtual TerrainTile * getTile(int3 pos); diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 9666f81a9..fa11b932f 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -453,15 +453,19 @@ struct NewStructures : public CPackForClient //504 h & tid & bid & builded; } }; -struct RazeStructures : public NewStructures //505 +struct RazeStructures : public CPackForClient //505 { RazeStructures() {type = 505;}; void applyCl (CClient *cl); DLL_EXPORT void applyGs(CGameState *gs); + si32 tid; + std::set bid; + si16 destroyed; + template void serialize(Handler &h, const int version) { - h & tid & bid & builded; + h & tid & bid & destroyed; } }; struct SetAvailableCreatures : public CPackForClient //506 diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 2050b8fe0..f3484c261 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -359,7 +359,7 @@ DLL_EXPORT void RazeStructures::applyGs( CGameState *gs ) { t->builtBuildings.erase(id); } - t->destroyed = builded; //yeaha + t->destroyed = destroyed; //yeaha } DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs ) { diff --git a/lib/RegisterTypes.cpp b/lib/RegisterTypes.cpp index f78879dbd..d2fd77aec 100644 --- a/lib/RegisterTypes.cpp +++ b/lib/RegisterTypes.cpp @@ -53,6 +53,7 @@ void registerTypes1(Serializer &s) s.template registerType(); s.template registerType(); s.template registerType(); + s.template registerType(); s.template registerType(); s.template registerType(); s.template registerType(); diff --git a/lib/map.cpp b/lib/map.cpp index 20e4ccb2d..a5a607fbd 100644 --- a/lib/map.cpp +++ b/lib/map.cpp @@ -1943,6 +1943,11 @@ void Mapa::readObjects( unsigned char * bufor, int &i) nobj = new CBank(); break; } + case 63: //Pyramid + { + nobj = new CGPyramid(); + break; + } case 13: //Cartographer { nobj = new CCartographer(); diff --git a/lib/map.h b/lib/map.h index bf632f0d4..dffcd87d3 100644 --- a/lib/map.h +++ b/lib/map.h @@ -406,10 +406,12 @@ struct DLL_EXPORT Mapa : public CMapHeader objects.resize(hlp); } + //static structures h & CGTeleport::objs; h & CGTeleport::gates; h & CGKeys::playerKeyMap; h & CGMagi::eyelist; + h & CGPyramid::pyramidConfig; for(int i=0; idestroyed + 1; //define TRUE FALSE? + rs.destroyed = t->destroyed + 1; sendAndApply(&rs); return true; }