From 5806976a9a13f25671479a7ff4c5abddcda63d51 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sat, 18 Dec 2010 22:11:28 +0000 Subject: [PATCH] * towards ConstTranssitivePointers in CGI --- CCallback.cpp | 4 ++-- client/CGameInfo.cpp | 2 +- client/CGameInfo.h | 14 +++++++------- client/CMT.cpp | 4 ++-- client/Client.cpp | 16 ++++++++-------- global.h | 2 +- hch/CArtHandler.cpp | 4 ++-- hch/CArtHandler.h | 6 +++--- lib/CGameState.cpp | 14 +++++++------- lib/Connection.h | 2 +- lib/ConstTransitivePtr.h | 6 +++--- lib/IGameCallback.cpp | 2 +- lib/NetPacksLib.cpp | 4 ++-- server/CGameHandler.cpp | 16 ++++++++-------- 14 files changed, 48 insertions(+), 48 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index 295d5d8fb..f58a241f4 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -232,7 +232,7 @@ const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) const //mode = } else //object id { - return static_cast(+gs->map->objects[val]); + return static_cast(gs->map->objects[val].get()); } return NULL; } @@ -599,7 +599,7 @@ const CGTownInstance *CCallback::battleGetDefendedTown() if(!gs->curB || gs->curB->tid == -1) return NULL; - return static_cast(+gs->map->objects[gs->curB->tid]); + return static_cast(gs->map->objects[gs->curB->tid].get()); } ui8 CCallback::battleGetWallState(int partOfWall) diff --git a/client/CGameInfo.cpp b/client/CGameInfo.cpp index 7779a9039..adab95cb6 100644 --- a/client/CGameInfo.cpp +++ b/client/CGameInfo.cpp @@ -12,7 +12,7 @@ * */ -CGameInfo * CGI; //game info for general use +const CGameInfo * CGI; //game info for general use CGameInfo::CGameInfo() { diff --git a/client/CGameInfo.h b/client/CGameInfo.h index aeb31c7a2..f6c877234 100644 --- a/client/CGameInfo.h +++ b/client/CGameInfo.h @@ -41,7 +41,7 @@ class CGameInfo { CGameState * state; //don't touch it in client's code public: - CArtHandler * arth; + ConstTransitivePtr arth; CHeroHandler * heroh; CCreatureHandler * creh; CSpellHandler * spellh; @@ -50,13 +50,13 @@ public: CGeneralTextHandler * generaltexth; CMapHandler * mh; CBuildingHandler * buildh; - CSoundHandler * soundh; - CMusicHandler * musich; + mutable CSoundHandler * soundh; + mutable CMusicHandler * musich; CTownHandler * townh; //CTownHandler * townh; - CConsoleHandler * consoleh; - CCursorHandler * curh; - CVideoPlayer * videoh; + mutable CConsoleHandler * consoleh; + mutable CCursorHandler * curh; + mutable CVideoPlayer * videoh; void setFromLib(); @@ -68,7 +68,7 @@ public: // ConstTransitivePtr state; //don't touch it in client's code // public: -// ConstTransitivePtr arth; +// // ConstTransitivePtr heroh; // ConstTransitivePtr creh; // ConstTransitivePtr spellh; diff --git a/client/CMT.cpp b/client/CMT.cpp index 9ca7ee782..0fd588e31 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -138,7 +138,7 @@ void init() tlog0<<"Initializing screen and sound handling: "<setFromLib(); + const_cast(CGI)->setFromLib(); CGI->soundh->initCreaturesSounds(CGI->creh->creatures); CGI->soundh->initSpellsSounds(CGI->spellh->spells); tlog0<<"Initializing VCMI_Lib: "<dobjinfo; - CGI->dobjinfo = new CDefObjInfoHandler; + const_cast(CGI)->dobjinfo = new CDefObjInfoHandler; CGI->dobjinfo->load(); GH.curInt = CGP; diff --git a/client/Client.cpp b/client/Client.cpp index a4e9f8dc8..7e0af5d78 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -207,10 +207,10 @@ void CClient::endGame( bool closeConnection /*= true*/ ) tlog0 << "Removed GUI." << std::endl; delete CGI->mh; - CGI->mh = NULL; + const_cast(CGI)->mh = NULL; delete CGI->state; - CGI->state = NULL; + const_cast(CGI)->state = NULL; tlog0 << "Deleted mapHandler and gameState." << std::endl; LOCPLINT = NULL; @@ -244,7 +244,7 @@ void CClient::loadGame( const std::string & fname ) { char sig[8]; CMapHeader dum; - CGI->mh = new CMapHandler(); + const_cast(CGI)->mh = new CMapHandler(); StartInfo *si; CLoadFile lf(fname + ".vlgm1"); @@ -252,14 +252,14 @@ void CClient::loadGame( const std::string & fname ) tlog0 <<"Reading save signature: "<> *VLC; - CGI->setFromLib(); + const_cast(CGI)->setFromLib(); tlog0 <<"Reading handlers: "<> gs; tlog0 <<"Reading gamestate: "<state = gs; - CGI->mh->map = gs->map; + const_cast(CGI)->state = gs; + const_cast(CGI)->mh->map = gs->map; pathInfo = new CPathsInfo(int3(gs->map->width, gs->map->height, gs->map->twoLevel+1)); CGI->mh->init(); initVillagesCapitols(gs->map); @@ -339,7 +339,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) timeHandler tmh; - CGI->state = new CGameState(); + const_cast(CGI)->state = new CGameState(); tlog0 <<"\tGamestate: "<scenarioOps = si; gs->init(si, sum, seed); - CGI->mh = new CMapHandler(); + const_cast(CGI)->mh = new CMapHandler(); tlog0 <<"Initializing GameState (together): "<mh->map = gs->map; tlog0 <<"Creating mapHandler: "< &artifWorn, ui16 slotID, const CArtifact* art ) +void CArtHandler::equipArtifact( std::map &artifWorn, ui16 slotID, const CArtifact* art ) const { unequipArtifact(artifWorn, slotID); @@ -803,7 +803,7 @@ void CArtHandler::equipArtifact( std::map &artifWorn, ui * @param artifWorn A hero's set of worn artifacts. * @param bonuses Optional list of bonuses to update. */ -void CArtHandler::unequipArtifact(std::map &artifWorn, ui16 slotID) +void CArtHandler::unequipArtifact(std::map &artifWorn, ui16 slotID) const { if (!vstd::contains(artifWorn, slotID)) return; diff --git a/hch/CArtHandler.h b/hch/CArtHandler.h index 087545ab6..5e41b83b9 100644 --- a/hch/CArtHandler.h +++ b/hch/CArtHandler.h @@ -156,9 +156,9 @@ public: void getAllowedArts(std::vector > &out, std::vector *arts, int flag); void getAllowed(std::vector > &out, int flags); void erasePickedArt (si32 id); - bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();} - void equipArtifact (std::map &artifWorn, ui16 slotID, const CArtifact* art); - void unequipArtifact (std::map &artifWorn, ui16 slotID); + bool isBigArtifact (ui32 artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();} + void equipArtifact (std::map &artifWorn, ui16 slotID, const CArtifact* art) const; + void unequipArtifact (std::map &artifWorn, ui16 slotID) const; void initAllowedArtifactsList(const std::vector &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed static int convertMachineID(int id, bool creToArt); CArtHandler(); diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 306f80a52..60aaf18a8 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1157,7 +1157,7 @@ CGHeroInstance *CGameState::getHero(int objid) { if(objid<0 || objid>=map->objects.size() || map->objects[objid]->ID!=HEROI_TYPE) return NULL; - return static_cast(+map->objects[objid]); + return static_cast(map->objects[objid].get()); } const CGHeroInstance * CGameState::getHero( int objid ) const @@ -1247,13 +1247,13 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) { for(unsigned int i=0;iobjects.size();i++) { - if(map->objects[i]->ID==77 && dynamic_cast(+map->objects[i])->identifier == info->identifier) + if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i].get())->identifier == info->identifier) { randomizeObject(map->objects[i]); //we have to randomize the castle first faction = map->objects[i]->subID; break; } - else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(+map->objects[i])->identifier == info->identifier) + else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(map->objects[i].get())->identifier == info->identifier) { faction = map->objects[i]->subID; break; @@ -1288,13 +1288,13 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) { for(unsigned int i=0;iobjects.size();i++) { - if(map->objects[i]->ID==77 && dynamic_cast(+map->objects[i])->identifier == info->identifier) + if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i].get())->identifier == info->identifier) { randomizeObject(map->objects[i]); //we have to randomize the castle first faction = map->objects[i]->subID; break; } - else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(+map->objects[i])->identifier == info->identifier) + else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(map->objects[i].get())->identifier == info->identifier) { faction = map->objects[i]->subID; break; @@ -2180,7 +2180,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) { map->objects[i]->initObj(); if(map->objects[i]->ID == 62) //prison also needs to initialize hero - static_cast(+map->objects[i])->initHero(); + static_cast(map->objects[i].get())->initHero(); } CGTeleport::postInit(); //pairing subterranean gates } @@ -3789,7 +3789,7 @@ int CGameState::victoryCheck( ui8 player ) const const CArmedInstance *ai = NULL; if(map->objects[i] && map->objects[i]->tempOwner == player //object controlled by player - && (ai = dynamic_cast(+map->objects[i]))) //contains army + && (ai = dynamic_cast(map->objects[i].get()))) //contains army { for(TSlots::const_iterator i=ai->Slots().begin(); i!=ai->Slots().end(); ++i) //iterate through army if(i->second->type->idNumber == map->victoryCondition.ID) //it's searched creature diff --git a/lib/Connection.h b/lib/Connection.h index 2d20d14ea..29bed198f 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -297,7 +297,7 @@ public: assert(oInfo.vector); assert(oInfo.vector->size() > id); - return const_cast(+(*oInfo.vector)[id]); + return const_cast((*oInfo.vector)[id].get()); } template diff --git a/lib/ConstTransitivePtr.h b/lib/ConstTransitivePtr.h index d4ba296bc..7656caa8e 100644 --- a/lib/ConstTransitivePtr.h +++ b/lib/ConstTransitivePtr.h @@ -21,11 +21,11 @@ public: { return ptr; } - T* operator+() + T* get() { return ptr; } - const T* operator+() const + const T* get() const { return ptr; } @@ -46,4 +46,4 @@ public: { h & ptr; } -}; \ No newline at end of file +}; diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index e1b4b08a9..231ca0ad3 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -54,7 +54,7 @@ const CGTownInstance* IGameCallback::getTown(int objid) { const CGObjectInstance *obj = getObj(objid, false); if(obj) - return dynamic_cast(+gs->map->objects[objid]); + return dynamic_cast(gs->map->objects[objid].get()); else return NULL; } diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 5520f288a..5592fec7d 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -413,7 +413,7 @@ DLL_EXPORT void RazeStructures::applyGs( CGameState *gs ) } DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs ) { - CGDwelling *dw = dynamic_cast(+gs->map->objects[tid]); + CGDwelling *dw = dynamic_cast(gs->map->objects[tid].get()); assert(dw); dw->creatures = creatures; } @@ -687,7 +687,7 @@ DLL_EXPORT void SetAvailableArtifacts::applyGs( CGameState *gs ) { if(id >= 0) { - if(CGBlackMarket *bm = dynamic_cast(+gs->map->objects[id])) + if(CGBlackMarket *bm = dynamic_cast(gs->map->objects[id].get())) { bm->artifacts = arts; } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 5ddff8c00..d7142ebaf 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -199,7 +199,7 @@ void CGameHandler::levelUpHero(int ID, int skill) void CGameHandler::levelUpHero(int ID) { - CGHeroInstance *hero = static_cast(+gs->map->objects[ID]); + CGHeroInstance *hero = static_cast(gs->map->objects[ID].get()); if (hero->exp < VLC->heroh->reqExp(hero->level+1)) // no more level-ups return; @@ -2585,8 +2585,8 @@ void CGameHandler::close() bool CGameHandler::arrangeStacks( si32 id1, si32 id2, ui8 what, ui8 p1, ui8 p2, si32 val, ui8 player ) { - CArmedInstance *s1 = static_cast(+gs->map->objects[id1]), - *s2 = static_cast(+gs->map->objects[id2]); + CArmedInstance *s1 = static_cast(gs->map->objects[id1].get()), + *s2 = static_cast(gs->map->objects[id2].get()); CCreatureSet &S1 = *s1, &S2 = *s2; StackLocation sl1(s1, p1), sl2(s2, p2); @@ -2688,7 +2688,7 @@ int CGameHandler::getPlayerAt( CConnection *c ) const bool CGameHandler::disbandCreature( si32 id, ui8 pos ) { - CArmedInstance *s1 = static_cast(+gs->map->objects[id]); + CArmedInstance *s1 = static_cast(gs->map->objects[id].get()); if(!vstd::contains(s1->slots,pos)) { complain("Illegal call to disbandCreature - no such stack in army!"); @@ -2701,7 +2701,7 @@ bool CGameHandler::disbandCreature( si32 id, ui8 pos ) bool CGameHandler::buildStructure( si32 tid, si32 bid, bool force /*=false*/ ) { - CGTownInstance * t = static_cast(+gs->map->objects[tid]); + CGTownInstance * t = static_cast(gs->map->objects[tid].get()); CBuilding * b = VLC->buildh->buildings[t->subID][bid]; if( !force && gs->canBuildStructure(t,bid) != 7) @@ -2811,7 +2811,7 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid, bool force /*=false*/ ) bool CGameHandler::razeStructure (si32 tid, si32 bid) { ///incomplete, simply erases target building - CGTownInstance * t = static_cast(+gs->map->objects[tid]); + CGTownInstance * t = static_cast(gs->map->objects[tid].get()); if (t->builtBuildings.find(bid) == t->builtBuildings.end()) return false; RazeStructures rs; @@ -2840,7 +2840,7 @@ void CGameHandler::sendMessageToAll( const std::string &message ) bool CGameHandler::recruitCreatures( si32 objid, ui32 crid, ui32 cram, si32 fromLvl ) { - const CGDwelling *dw = static_cast(+gs->map->objects[objid]); + const CGDwelling *dw = static_cast(gs->map->objects[objid].get()); const CArmedInstance *dst = NULL; const CCreature *c = VLC->creh->creatures[crid]; bool warMachine = c->hasBonusOfType(Bonus::SIEGE_WEAPON); @@ -2929,7 +2929,7 @@ bool CGameHandler::recruitCreatures( si32 objid, ui32 crid, ui32 cram, si32 from bool CGameHandler::upgradeCreature( ui32 objid, ui8 pos, ui32 upgID ) { - CArmedInstance *obj = static_cast(+gs->map->objects[objid]); + CArmedInstance *obj = static_cast(gs->map->objects[objid].get()); assert(obj->hasStackAtSlot(pos)); UpgradeInfo ui = gs->getUpgradeInfo(obj->getStack(pos)); int player = obj->tempOwner;