1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* towards ConstTranssitivePointers in CGI

This commit is contained in:
mateuszb 2010-12-18 22:11:28 +00:00
parent 23c501b79e
commit 5806976a9a
14 changed files with 48 additions and 48 deletions

View File

@ -232,7 +232,7 @@ const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) const //mode =
}
else //object id
{
return static_cast<const CGHeroInstance*>(+gs->map->objects[val]);
return static_cast<const CGHeroInstance*>(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<const CGTownInstance *>(+gs->map->objects[gs->curB->tid]);
return static_cast<const CGTownInstance *>(gs->map->objects[gs->curB->tid].get());
}
ui8 CCallback::battleGetWallState(int partOfWall)

View File

@ -12,7 +12,7 @@
*
*/
CGameInfo * CGI; //game info for general use
const CGameInfo * CGI; //game info for general use
CGameInfo::CGameInfo()
{

View File

@ -41,7 +41,7 @@ class CGameInfo
{
CGameState * state; //don't touch it in client's code
public:
CArtHandler * arth;
ConstTransitivePtr<CArtHandler> 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<CGameState> state; //don't touch it in client's code
// public:
// ConstTransitivePtr<CArtHandler> arth;
//
// ConstTransitivePtr<CHeroHandler> heroh;
// ConstTransitivePtr<CCreatureHandler> creh;
// ConstTransitivePtr<CSpellHandler> spellh;

View File

@ -138,7 +138,7 @@ void init()
tlog0<<"Initializing screen and sound handling: "<<tmh.getDif()<<std::endl;
initDLL(::console,logfile);
CGI->setFromLib();
const_cast<CGameInfo*>(CGI)->setFromLib();
CGI->soundh->initCreaturesSounds(CGI->creh->creatures);
CGI->soundh->initSpellsSounds(CGI->spellh->spells);
tlog0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
@ -610,7 +610,7 @@ static void listenForEvents()
client = NULL;
delete CGI->dobjinfo;
CGI->dobjinfo = new CDefObjInfoHandler;
const_cast<CGameInfo*>(CGI)->dobjinfo = new CDefObjInfoHandler;
CGI->dobjinfo->load();
GH.curInt = CGP;

View File

@ -207,10 +207,10 @@ void CClient::endGame( bool closeConnection /*= true*/ )
tlog0 << "Removed GUI." << std::endl;
delete CGI->mh;
CGI->mh = NULL;
const_cast<CGameInfo*>(CGI)->mh = NULL;
delete CGI->state;
CGI->state = NULL;
const_cast<CGameInfo*>(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<CGameInfo*>(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: "<<tmh.getDif()<<std::endl;
lf >> *VLC;
CGI->setFromLib();
const_cast<CGameInfo*>(CGI)->setFromLib();
tlog0 <<"Reading handlers: "<<tmh.getDif()<<std::endl;
lf >> gs;
tlog0 <<"Reading gamestate: "<<tmh.getDif()<<std::endl;
CGI->state = gs;
CGI->mh->map = gs->map;
const_cast<CGameInfo*>(CGI)->state = gs;
const_cast<CGameInfo*>(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<CGameInfo*>(CGI)->state = new CGameState();
tlog0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
CConnection &c(*serv);
////////////////////////////////////////////////////
@ -368,7 +368,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
gs->scenarioOps = si;
gs->init(si, sum, seed);
CGI->mh = new CMapHandler();
const_cast<CGameInfo*>(CGI)->mh = new CMapHandler();
tlog0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
CGI->mh->map = gs->map;
tlog0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl;

View File

@ -78,7 +78,7 @@ enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
enum ECombatInfo{ALIVE = 180, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING};
class CGameInfo;
extern CGameInfo* CGI; //game info for general use
extern const CGameInfo* CGI; //game info for general use
//a few typedefs for CCreatureSet
typedef si32 TSlot;

View File

@ -757,7 +757,7 @@ void CArtHandler::clear()
* @param artifWorn A hero's set of worn artifacts.
* @param bonuses Optional list of bonuses to update.
*/
void CArtHandler::equipArtifact( std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art )
void CArtHandler::equipArtifact( std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art ) const
{
unequipArtifact(artifWorn, slotID);
@ -803,7 +803,7 @@ void CArtHandler::equipArtifact( std::map<ui16, const CArtifact*> &artifWorn, ui
* @param artifWorn A hero's set of worn artifacts.
* @param bonuses Optional list of bonuses to update.
*/
void CArtHandler::unequipArtifact(std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID)
void CArtHandler::unequipArtifact(std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const
{
if (!vstd::contains(artifWorn, slotID))
return;

View File

@ -156,9 +156,9 @@ public:
void getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, int flag);
void getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags);
void erasePickedArt (si32 id);
bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();}
void equipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art);
void unequipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID);
bool isBigArtifact (ui32 artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();}
void equipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art) const;
void unequipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const;
void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
static int convertMachineID(int id, bool creToArt);
CArtHandler();

View File

@ -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<CGHeroInstance *>(+map->objects[objid]);
return static_cast<CGHeroInstance *>(map->objects[objid].get());
}
const CGHeroInstance * CGameState::getHero( int objid ) const
@ -1247,13 +1247,13 @@ std::pair<int,int> CGameState::pickObject (CGObjectInstance *obj)
{
for(unsigned int i=0;i<map->objects.size();i++)
{
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(+map->objects[i])->identifier == info->identifier)
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(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<CGTownInstance*>(+map->objects[i])->identifier == info->identifier)
else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast<CGTownInstance*>(map->objects[i].get())->identifier == info->identifier)
{
faction = map->objects[i]->subID;
break;
@ -1288,13 +1288,13 @@ std::pair<int,int> CGameState::pickObject (CGObjectInstance *obj)
{
for(unsigned int i=0;i<map->objects.size();i++)
{
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(+map->objects[i])->identifier == info->identifier)
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(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<CGTownInstance*>(+map->objects[i])->identifier == info->identifier)
else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast<CGTownInstance*>(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<CGHeroInstance*>(+map->objects[i])->initHero();
static_cast<CGHeroInstance*>(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<const CArmedInstance*>(+map->objects[i]))) //contains army
&& (ai = dynamic_cast<const CArmedInstance*>(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

View File

@ -297,7 +297,7 @@ public:
assert(oInfo.vector);
assert(oInfo.vector->size() > id);
return const_cast<T*>(+(*oInfo.vector)[id]);
return const_cast<T*>((*oInfo.vector)[id].get());
}
template <typename T>

View File

@ -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;
}
};
};

View File

@ -54,7 +54,7 @@ const CGTownInstance* IGameCallback::getTown(int objid)
{
const CGObjectInstance *obj = getObj(objid, false);
if(obj)
return dynamic_cast<const CGTownInstance*>(+gs->map->objects[objid]);
return dynamic_cast<const CGTownInstance*>(gs->map->objects[objid].get());
else
return NULL;
}

View File

@ -413,7 +413,7 @@ DLL_EXPORT void RazeStructures::applyGs( CGameState *gs )
}
DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs )
{
CGDwelling *dw = dynamic_cast<CGDwelling*>(+gs->map->objects[tid]);
CGDwelling *dw = dynamic_cast<CGDwelling*>(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<CGBlackMarket*>(+gs->map->objects[id]))
if(CGBlackMarket *bm = dynamic_cast<CGBlackMarket*>(gs->map->objects[id].get()))
{
bm->artifacts = arts;
}

View File

@ -199,7 +199,7 @@ void CGameHandler::levelUpHero(int ID, int skill)
void CGameHandler::levelUpHero(int ID)
{
CGHeroInstance *hero = static_cast<CGHeroInstance *>(+gs->map->objects[ID]);
CGHeroInstance *hero = static_cast<CGHeroInstance *>(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<CArmedInstance*>(+gs->map->objects[id1]),
*s2 = static_cast<CArmedInstance*>(+gs->map->objects[id2]);
CArmedInstance *s1 = static_cast<CArmedInstance*>(gs->map->objects[id1].get()),
*s2 = static_cast<CArmedInstance*>(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<CArmedInstance*>(+gs->map->objects[id]);
CArmedInstance *s1 = static_cast<CArmedInstance*>(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<CGTownInstance*>(+gs->map->objects[tid]);
CGTownInstance * t = static_cast<CGTownInstance*>(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<CGTownInstance*>(+gs->map->objects[tid]);
CGTownInstance * t = static_cast<CGTownInstance*>(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<CGDwelling*>(+gs->map->objects[objid]);
const CGDwelling *dw = static_cast<CGDwelling*>(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<CArmedInstance*>(+gs->map->objects[objid]);
CArmedInstance *obj = static_cast<CArmedInstance*>(gs->map->objects[objid].get());
assert(obj->hasStackAtSlot(pos));
UpgradeInfo ui = gs->getUpgradeInfo(obj->getStack(pos));
int player = obj->tempOwner;