Browse Source

* refactoring

mateuszb 16 years ago
parent
commit
bb8e505ccd
6 changed files with 12 additions and 12 deletions
  1. 2 2
      CAdvmapInterface.cpp
  2. 4 4
      CGameState.cpp
  3. 2 2
      CMessage.cpp
  4. 1 1
      client/NetPacksClient.cpp
  5. 2 2
      server/CGameHandler.cpp
  6. 1 1
      server/CVCMIServer.cpp

+ 2 - 2
CAdvmapInterface.cpp

@@ -872,7 +872,7 @@ void CTerrainRect::showPath(const SDL_Rect * extRect)
 			}
 			}
 
 
 		}
 		}
-		if (  ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection))->movement)
+		if (  ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > (static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection))->movement)
 			pn+=25;
 			pn+=25;
 		if (pn>=0)
 		if (pn>=0)
 		{
 		{
@@ -1324,7 +1324,7 @@ void CAdvMapInt::fshowSpellbok()
 		return;
 		return;
 
 
 
 
-	CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), ((const CGHeroInstance*)LOCPLINT->adventureInt->selection));
+	CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), (static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection)));
 	LOCPLINT->pushInt(spellWindow);
 	LOCPLINT->pushInt(spellWindow);
 }
 }
 void CAdvMapInt::fadventureOPtions()
 void CAdvMapInt::fadventureOPtions()

+ 4 - 4
CGameState.cpp

@@ -716,7 +716,7 @@ std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj)
 		return std::pair<int,int>(79,ran()%7); //now it's OH3 style, use %8 for mithril 
 		return std::pair<int,int>(79,ran()%7); //now it's OH3 style, use %8 for mithril 
 	case 77: //random town
 	case 77: //random town
 		{
 		{
-			int align = ((CGTownInstance*)obj)->alignment,
+			int align = (static_cast<CGTownInstance*>(obj))->alignment,
 				f;
 				f;
 			if(align>PLAYER_LIMIT-1)//same as owner / random
 			if(align>PLAYER_LIMIT-1)//same as owner / random
 			{
 			{
@@ -741,7 +741,7 @@ std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj)
 	case 216: //random dwelling
 	case 216: //random dwelling
 		{
 		{
 			int faction = ran()%F_NUMBER;
 			int faction = ran()%F_NUMBER;
-			CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info;
+			CCreGen2ObjInfo* info = static_cast<CCreGen2ObjInfo*>(obj->info);
 			if (info->asCastle)
 			if (info->asCastle)
 			{
 			{
 				for(int i=0;i<map->objects.size();i++)
 				for(int i=0;i<map->objects.size();i++)
@@ -779,7 +779,7 @@ std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj)
 	case 217:
 	case 217:
 		{
 		{
 			int faction = ran()%F_NUMBER;
 			int faction = ran()%F_NUMBER;
-			CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info;
+			CCreGenObjInfo* info = static_cast<CCreGenObjInfo*>(obj->info);
 			if (info->asCastle)
 			if (info->asCastle)
 			{
 			{
 				for(int i=0;i<map->objects.size();i++)
 				for(int i=0;i<map->objects.size();i++)
@@ -815,7 +815,7 @@ std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj)
 		}
 		}
 	case 218:
 	case 218:
 		{
 		{
-			CCreGen3ObjInfo* info =(CCreGen3ObjInfo*)obj->info;
+			CCreGen3ObjInfo* info = static_cast<CCreGen3ObjInfo*>(obj->info);
 			int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
 			int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
 			int cid = VLC->townh->towns[obj->subID].basicCreatures[level];
 			int cid = VLC->townh->towns[obj->subID].basicCreatures[level];
 			for(int i=0;i<VLC->objh->cregens.size();i++)
 			for(int i=0;i<VLC->objh->cregens.size();i++)

+ 2 - 2
CMessage.cpp

@@ -455,11 +455,11 @@ SDL_Surface * CMessage::genMessage
 		//ok
 		//ok
 		SDL_Rect trescRect = genRect((*addPics)[0]->ourImages[0].bitmap->h,hwo,((ret->w/2)-hwo-10),by);
 		SDL_Rect trescRect = genRect((*addPics)[0]->ourImages[0].bitmap->h,hwo,((ret->w/2)-hwo-10),by);
 		SDL_BlitSurface((*addPics)[0]->ourImages[0].bitmap,NULL,ret,&trescRect);
 		SDL_BlitSurface((*addPics)[0]->ourImages[0].bitmap,NULL,ret,&trescRect);
-		((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
+		reinterpret_cast<std::vector<SDL_Rect>*>(cb)->push_back(trescRect);
 		//cancel
 		//cancel
 		trescRect = genRect((*addPics)[1]->ourImages[0].bitmap->h,hwc,((ret->w/2)+10),by);
 		trescRect = genRect((*addPics)[1]->ourImages[0].bitmap->h,hwc,((ret->w/2)+10),by);
 		SDL_BlitSurface((*addPics)[1]->ourImages[0].bitmap,NULL,ret,&trescRect);
 		SDL_BlitSurface((*addPics)[1]->ourImages[0].bitmap,NULL,ret,&trescRect);
-		((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
+		reinterpret_cast<std::vector<SDL_Rect>*>(cb)->push_back(trescRect);
 	}
 	}
 	delete tekst;
 	delete tekst;
 	return ret;
 	return ret;

+ 1 - 1
client/NetPacksClient.cpp

@@ -277,7 +277,7 @@ void HeroLevelUp::applyCl( CClient *cl )
 	if(vstd::contains(cl->playerint,h->tempOwner))
 	if(vstd::contains(cl->playerint,h->tempOwner))
 	{
 	{
 		boost::function<void(ui32)> callback = boost::function<void(ui32)>(boost::bind(&CCallback::selectionMade,LOCPLINT->cb,_1,id));
 		boost::function<void(ui32)> callback = boost::function<void(ui32)>(boost::bind(&CCallback::selectionMade,LOCPLINT->cb,_1,id));
-		cl->playerint[h->tempOwner]->heroGotLevel((const CGHeroInstance *)h,(int)primskill,skills, callback);
+		cl->playerint[h->tempOwner]->heroGotLevel(const_cast<const CGHeroInstance*>(h),static_cast<int>(primskill),skills, callback);
 	}
 	}
 }
 }
 
 

+ 2 - 2
server/CGameHandler.cpp

@@ -466,7 +466,7 @@ void CGameHandler::prepareAttack(BattleAttack &bat, CStack *att, CStack *def)
 	bat.bsa.clear();
 	bat.bsa.clear();
 	bat.stackAttacking = att->ID;
 	bat.stackAttacking = att->ID;
 	std::set<BattleStackAttacked>::iterator i = bat.bsa.insert(BattleStackAttacked()).first;
 	std::set<BattleStackAttacked>::iterator i = bat.bsa.insert(BattleStackAttacked()).first;
-	BattleStackAttacked *bsa = (BattleStackAttacked *) &*i;
+	BattleStackAttacked *bsa = &*i;
 
 
 	bsa->stackAttacked = def->ID;
 	bsa->stackAttacked = def->ID;
 	bsa->damageAmount = BattleInfo::calculateDmg(att, def, gs->getHero(att->attackerOwned ? gs->curB->hero1 : gs->curB->hero2), gs->getHero(def->attackerOwned ? gs->curB->hero1 : gs->curB->hero2), bat.shot());//counting dealt damage
 	bsa->damageAmount = BattleInfo::calculateDmg(att, def, gs->getHero(att->attackerOwned ? gs->curB->hero1 : gs->curB->hero2), gs->getHero(def->attackerOwned ? gs->curB->hero1 : gs->curB->hero2), bat.shot());//counting dealt damage
@@ -1339,7 +1339,7 @@ void CGameHandler::giveHeroArtifact(int artid, int hid, int position) //pos==-1
 
 
 void CGameHandler::startBattleI(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb) //use hero=NULL for no hero
 void CGameHandler::startBattleI(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb) //use hero=NULL for no hero
 {
 {
-	boost::thread(boost::bind(&CGameHandler::startBattle,this,*(CCreatureSet *)army1,*(CCreatureSet *)army2,tile,(CGHeroInstance *)hero1,(CGHeroInstance *)hero2,cb));
+	boost::thread(boost::bind(&CGameHandler::startBattle,this,*const_cast<CCreatureSet *>(army1),*const_cast<CCreatureSet *>(army2),tile,const_cast<CGHeroInstance *>(hero1), const_cast<CGHeroInstance *>(hero2),cb));
 }
 }
 void CGameHandler::startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb) //for hero<=>neutral army
 void CGameHandler::startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb) //for hero<=>neutral army
 {
 {

+ 1 - 1
server/CVCMIServer.cpp

@@ -121,7 +121,7 @@ void CVCMIServer::start()
 		intpr::shared_memory_object smo(intpr::open_only,"vcmi_memory",intpr::read_write);
 		intpr::shared_memory_object smo(intpr::open_only,"vcmi_memory",intpr::read_write);
 		smo.truncate(sizeof(ServerReady));
 		smo.truncate(sizeof(ServerReady));
 		mr = new intpr::mapped_region(smo,intpr::read_write);
 		mr = new intpr::mapped_region(smo,intpr::read_write);
-		sr = (ServerReady*)mr->get_address();
+		sr = reinterpret_cast<ServerReady*>(mr->get_address());
 	}
 	}
 	catch(...)
 	catch(...)
 	{
 	{