From e9c991a1809ff098c0cfa23bb8b5e1b1d5013821 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Wed, 23 Sep 2009 12:05:33 +0000 Subject: [PATCH] * compilation fixes (I didn't test everything, I hope it works) --- client/Client.h | 2 +- hch/CObjectHandler.cpp | 132 +++++++++++++--------------------------- hch/CObjectHandler.h | 17 +----- int3.h | 4 -- lib/IGameCallback.h | 2 +- lib/RegisterTypes.cpp | 2 +- lib/map.cpp | 2 +- server/CGameHandler.cpp | 18 +++--- server/CGameHandler.h | 2 +- 9 files changed, 57 insertions(+), 124 deletions(-) diff --git a/client/Client.h b/client/Client.h index b59e91bf8..55eaa913f 100644 --- a/client/Client.h +++ b/client/Client.h @@ -99,7 +99,7 @@ public: ui32 showBlockingDialog(BlockingDialog *iw){return 0;}; //synchronous version of above void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function &cb){}; void giveResource(int player, int which, int val){}; - void giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const {}; + void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) {}; void showCompInfo(ShowInInfobox * comp){}; void heroVisitCastle(int obj, int heroID){}; void stopHeroVisitCastle(int obj, int heroID){}; diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 9f9c8b4d1..35f86abc7 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -1244,7 +1244,7 @@ void CGDwelling::initObj() void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const { - if(h->tempOwner != tempOwner && army) //object is guarded + if(h->tempOwner != tempOwner && army.slots.size() > 0) //object is guarded { BlockingDialog bd; bd.player = h->tempOwner; @@ -1508,10 +1508,7 @@ CGTownInstance::CGTownInstance() } CGTownInstance::~CGTownInstance() -{ - for (std::vector::const_iterator i = bonusingBuildings.begin(); i != bonusingBuildings.end(); i++) - delete *i; -} +{} int CGTownInstance::spellsAtLevel(int level, bool checkGuild) const { @@ -1535,7 +1532,7 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const if(getOwner() != h->getOwner()) { //TODO ally check - if(army || visitingHero) + if(army.slots.size() > 0 || visitingHero) { const CGHeroInstance *defendingHero = NULL; if(visitingHero) @@ -1552,7 +1549,6 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const } else { - removeCapitols (h->getOwner(), true); cb->setOwner(id, h->tempOwner); } } @@ -1587,7 +1583,6 @@ void CGTownInstance::initObj() bonusingBuildings.push_back (new CTownBonus(17, this)); break; } - removeCapitols (getOwner(), false); // destroy other capitols } int3 CGTownInstance::getSightCenter() const @@ -1604,35 +1599,10 @@ void CGTownInstance::fightOver( const CGHeroInstance *h, BattleResult *result ) { if(result->winner == 0) { - removeCapitols (h->getOwner(), true); - cb->setOwner (id, h->tempOwner); //give control after checkout is done + cb->setOwner(id, h->tempOwner); } } -void CGTownInstance::removeCapitols (ui8 owner, bool me) const -{ - if (hasCapitol()) // search for older capitol - { - PlayerState* state = cb->gameState()->getPlayer (owner); - for (std::vector::const_iterator i = state->towns.begin(); i < state->towns.end(); ++i) - { - if (*i != this && (*i)->hasCapitol()) - { - if (me) - { - RazeStructures rs; - rs.tid = id; - rs.bid.insert(13); - si16 builded = destroyed; - cb->sendAndApply(&rs); - //cb->gameState()->getTown(id)->builtBuildings.erase(13); //destroy local capitol - return; - } - else - (*i)->builtBuildings.erase(13); //destroy all other capitols at the beginning of game - } - } - } -} + void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h ) const { if(visitors.find(h->id)==visitors.end()) @@ -2449,7 +2419,7 @@ void CGVisitableOPW::newTurn() const void CGVisitableOPW::onHeroVisit( const CGHeroInstance * h ) const { - int mid, sound = 0; //message id, sound + int mid, sound = 0; switch (ID) { case 55: //mystical garden @@ -3129,38 +3099,6 @@ void CGBonusingObject::initObj() } } -void CGMagicSpring::onHeroVisit(const CGHeroInstance * h) const -{ - int messageID; - InfoWindow iw; - iw.player = h->tempOwner; - iw.soundID = soundBase::GENIE; - if (!visited) - { - if (h->mana > h->manaLimit()) - messageID = 76; - else - { - messageID = 74; - cb->setManaPoints (h->id, 2 * h->manaLimit()); - cb->setObjProperty (id, 5, true); - } - } - else - messageID = 75; - iw.text << std::pair(11,messageID); - cb->showInfoDialog(&iw); -} -const std::string & CGMagicSpring::getHoverText() const -{ - hoverName = VLC->generaltexth->names[ID]; - if(!visited) - hoverName += " " + VLC->generaltexth->allTexts[353]; //not visited - else - hoverName += " " + VLC->generaltexth->allTexts[352]; //visited - return hoverName; -} - void CGMagicWell::onHeroVisit( const CGHeroInstance * h ) const { int message; @@ -3209,7 +3147,7 @@ void CGPandoraBox::open( const CGHeroInstance * h, ui32 accept ) const { if (accept) { - if (army) //if pandora's box is protected by army + if (army.slots.size() > 0) //if pandora's box is protected by army { InfoWindow iw; iw.player = h->tempOwner; @@ -3220,7 +3158,7 @@ void CGPandoraBox::open( const CGHeroInstance * h, ui32 accept ) const else if (message.size() == 0 && resources.size() == 0 && primskills.size() == 0 && abilities.size() == 0 && abilityLevels.size() == 0 && artifacts.size() == 0 - && spells.size() == 0 && creatures == 0 + && spells.size() == 0 && creatures.slots.size() > 0 && gainedExp == 0 && manaDiff == 0 && moraleDiff == 0 && luckDiff == 0) //if it gives nothing without battle { InfoWindow iw; @@ -3421,7 +3359,34 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con } cb->showInfoDialog(&iw); } - cb->giveCreatures (id, h, &creatures); + + //check if creatures can be moved to hero army + CCreatureSet heroArmy = h->army; + CCreatureSet ourArmy = creatures; + while(ourArmy.slots.size() > 0) + { + int slot = heroArmy.getSlotFor(ourArmy.slots.begin()->second.first); + if(slot < 0) + break; + + heroArmy.slots[slot].first = ourArmy.slots.begin()->second.first; + heroArmy.slots[slot].second += ourArmy.slots.begin()->second.second; + ourArmy.slots.erase(ourArmy.slots.begin()); + } + + if(ourArmy.slots.size() > 0) //all creatures can be moved to hero army - do that + { + SetGarrisons sg; + sg.garrs[h->id] = heroArmy; + cb->sendAndApply(&sg); + } + else //show garrison window and let player pick creatures + { + SetGarrisons sg; + sg.garrs[id] = creatures; + cb->sendAndApply(&sg); + cb->showGarrisonDialog(id,h->id,true,boost::bind(&IGameCallback::removeObject,cb,id)); + } if(!afterBattle && message.size()) { @@ -3476,7 +3441,7 @@ void CGEvent::onHeroVisit( const CGHeroInstance * h ) const void CGEvent::activated( const CGHeroInstance * h ) const { - if(army) + if(army.slots.size() > 0) { InfoWindow iw; iw.player = h->tempOwner; @@ -3691,7 +3656,7 @@ void CGScholar::initObj() void CGGarrison::onHeroVisit (const CGHeroInstance *h) const { - if (h->tempOwner != tempOwner && army) { + if (h->tempOwner != tempOwner && army.slots.size() > 0) { //TODO: Find a way to apply magic garrison effects in battle. cb->startBattleI(h, this, boost::bind(&CGGarrison::fightOver, this, h, _1)); return; @@ -4211,7 +4176,7 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons iw.text.addReplacement (loot.buildList()); iw.text.addReplacement (h->name); cb->showInfoDialog(&iw); - cb->giveCreatures (id, h, &ourArmy); + cb->giveCreatures (id, h, ourArmy); } cb->setObjProperty (id, 15, 0); //bc = NULL } @@ -4592,22 +4557,6 @@ void CCartographer::buyMap (const CGHeroInstance *h, ui32 accept) const } } -void CShop::newTurn() const -{ - switch (ID) - { - case 7: //ArtMerchant aka. Black Market - if (cb->getDate(0)%28 == 1) - cb->setObjProperty (id, 13, 0); - cb->setObjProperty (id, 14, rand()); - break; - case 78: //Refugee Camp - case 95: //Tavern - if (cb->getDate(0)%7 == 1) - cb->setObjProperty (id, 14, rand()); - break; - } -} void CShop::setPropertyDer (ui8 what, ui32 val) { switch (what) @@ -4650,8 +4599,9 @@ void CGArtMerchant::reset(ui32 val) } for (ui8 n = 0; n < count; n++) { + index = arts.begin() + val % arts.size(); - avaliable[avaliable.size()] = new Component (Component::ARTIFACT, (*index)->id, 0, 0); + avaliable [avaliable.size()] = new Component (Component::ARTIFACT, (*index)->id, 0, 0); arts.erase(index); val *= (id + n * i); //randomize } diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 0886f3377..a9baba575 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -441,7 +441,6 @@ public: bool hasCapitol() const; int dailyIncome() const; //calculates daily income of this town int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5) - void removeCapitols (ui8 owner, bool me) const; CGTownInstance(); virtual ~CGTownInstance(); @@ -752,18 +751,6 @@ public: } }; -class DLL_EXPORT CGMagicSpring : public CGVisitableOPW -{///unfortunatelly, this one is quite different than others -public: - void onHeroVisit(const CGHeroInstance * h) const; - const std::string & getHoverText() const; - - template void serialize(Handler &h, const int version) - { - h & static_cast(*this); - h & visited; - } -}; class DLL_EXPORT CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement { public: @@ -961,8 +948,8 @@ public: void initObj() {}; void setPropertyDer (ui8 what, ui32 val); - void newTurn() const; - virtual void reset (ui32 val) {}; //get new items for Black Market, Tavern, Refugee Camp + void newTurn() const {}; + virtual void reset (ui32 val) {}; void onHeroVisit (const CGHeroInstance * h) const {}; virtual void trade (const CGHeroInstance * h) const {}; diff --git a/int3.h b/int3.h index c2a24f8a3..80f56b896 100644 --- a/int3.h +++ b/int3.h @@ -87,10 +87,6 @@ public: { h & slots & formation; } - operator bool() const - { - return slots.size() > 0; - } void sweep() { for(TSlots::iterator i=slots.begin(); i!=slots.end(); ++i) diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index f32de7d23..4b656f282 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -76,7 +76,7 @@ public: virtual ui32 showBlockingDialog(BlockingDialog *iw) =0; //synchronous version of above //TODO: virtual void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function &cb) =0; //cb will be called when player closes garrison window virtual void giveResource(int player, int which, int val)=0; - virtual void giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const=0; + virtual void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) =0; virtual void showCompInfo(ShowInInfobox * comp)=0; virtual void heroVisitCastle(int obj, int heroID)=0; virtual void stopHeroVisitCastle(int obj, int heroID)=0; diff --git a/lib/RegisterTypes.cpp b/lib/RegisterTypes.cpp index f78879dbd..cb43625e1 100644 --- a/lib/RegisterTypes.cpp +++ b/lib/RegisterTypes.cpp @@ -42,7 +42,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(); s.template registerType(); diff --git a/lib/map.cpp b/lib/map.cpp index 20e4ccb2d..26402ed2d 100644 --- a/lib/map.cpp +++ b/lib/map.cpp @@ -1950,7 +1950,7 @@ void Mapa::readObjects( unsigned char * bufor, int &i) } case 48: //Magic Spring { - nobj = new CGMagicSpring(); + //nobj = new CGMagicSpring(); break; } default: diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index f477c4242..b0620e7e3 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1570,22 +1570,22 @@ void CGameHandler::giveResource(int player, int which, int val) sr.val = gs->players.find(player)->second.resources[which]+val; sendAndApply(&sr); } -void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const +void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) { - if (creatures->slots.size() <= 0) + if (creatures.slots.size() <= 0) return; CCreatureSet heroArmy = h->army; - while (*creatures) + while (creatures.slots.size() > 0) { - int slot = heroArmy.getSlotFor (creatures->slots.begin()->second.first); + int slot = heroArmy.getSlotFor (creatures.slots.begin()->second.first); if (slot < 0) break; - heroArmy.slots[slot].first = creatures->slots.begin()->second.first; - heroArmy.slots[slot].second += creatures->slots.begin()->second.second; - creatures->slots.erase (creatures->slots.begin()); + heroArmy.slots[slot].first = creatures.slots.begin()->second.first; + heroArmy.slots[slot].second += creatures.slots.begin()->second.second; + creatures.slots.erase (creatures.slots.begin()); } - if (!*creatures) //all creatures can be moved to hero army - do that + if (creatures.slots.size() == 0) //all creatures can be moved to hero army - do that { SetGarrisons sg; sg.garrs[h->id] = heroArmy; @@ -1594,7 +1594,7 @@ void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, const CCr else //show garrison window and let player pick creatures { SetGarrisons sg; - sg.garrs[objid] = *creatures; + sg.garrs[objid] = creatures; sendAndApply (&sg); showGarrisonDialog (objid, h->id, true, 0); return; diff --git a/server/CGameHandler.h b/server/CGameHandler.h index e10814133..8b465c505 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -115,7 +115,7 @@ public: ui32 showBlockingDialog(BlockingDialog *iw); //synchronous version of above void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function &cb); void giveResource(int player, int which, int val); - void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet *creatures); + void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures); void showCompInfo(ShowInInfobox * comp); void heroVisitCastle(int obj, int heroID); void stopHeroVisitCastle(int obj, int heroID);