From dbe38a7062ae41ff872c438337a83abba6658194 Mon Sep 17 00:00:00 2001 From: Frank Zago Date: Sat, 30 Oct 2010 21:53:41 +0000 Subject: [PATCH] A few bug fixes and arious warning fixes: unused code/variables, out of order initializations, ... --- client/CAdvmapInterface.cpp | 4 ++-- client/CBattleInterface.cpp | 19 +++++++++---------- client/CCreatureAnimation.cpp | 2 +- client/CGameInfo.h | 2 +- client/CMessage.cpp | 4 ++-- client/CPlayerInterface.cpp | 10 +++++----- client/CPreGame.cpp | 10 ++++++---- client/CPreGame.h | 6 +++--- client/Client.cpp | 3 +-- client/GUIBase.h | 2 +- client/GUIClasses.cpp | 2 +- client/GUIClasses.h | 2 +- client/mapHandler.cpp | 17 +++++++++-------- hch/CDefHandler.cpp | 3 +++ hch/CObjectHandler.cpp | 6 +++--- hch/CObjectHandler.h | 2 +- lib/CGameState.cpp | 14 +++++++------- lib/CMapInfo.h | 4 ++-- lib/Connection.h | 2 +- lib/HeroBonus.cpp | 5 +++-- server/CGameHandler.cpp | 7 ++----- server/CVCMIServer.cpp | 5 ++--- server/CVCMIServer.h | 2 +- 23 files changed, 67 insertions(+), 66 deletions(-) diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index ccf78fd2d..0edbbfbe3 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -429,7 +429,7 @@ void CMinimap::show( SDL_Surface * to ) } CTerrainRect::CTerrainRect() - :currentPath(NULL), curHoveredTile(-1,-1,-1) + :curHoveredTile(-1,-1,-1), currentPath(NULL) { tilesw=(ADVOPT.advmapW+31)/32; tilesh=(ADVOPT.advmapH+31)/32; @@ -2116,4 +2116,4 @@ CAdventureOptions::~CAdventureOptions() void CAdventureOptions::showScenarioInfo() { GH.pushInt(new CScenarioInfo(LOCPLINT->cb->getMapHeader(), LOCPLINT->cb->getStartInfo())); -} \ No newline at end of file +} diff --git a/client/CBattleInterface.cpp b/client/CBattleInterface.cpp index 1146812f6..59859914f 100644 --- a/client/CBattleInterface.cpp +++ b/client/CBattleInterface.cpp @@ -136,7 +136,7 @@ void CDummyAnim::endAnim() delete this; } -CDummyAnim::CDummyAnim(CBattleInterface * _owner, int howManyFrames) : CBattleAnimation(_owner), howMany(howManyFrames), counter(0) +CDummyAnim::CDummyAnim(CBattleInterface * _owner, int howManyFrames) : CBattleAnimation(_owner), counter(0), howMany(howManyFrames) { } @@ -441,7 +441,7 @@ void CReverseAnim::endAnim() } CReverseAnim::CReverseAnim(CBattleInterface * _owner, int stack, int dest, bool _priority) -: CBattleStackAnimation(_owner, stack), partOfAnim(1), hex(dest), secondPartSetup(false), priority(_priority) +: CBattleStackAnimation(_owner, stack), partOfAnim(1), secondPartSetup(false), hex(dest), priority(_priority) { } @@ -514,8 +514,6 @@ bool CDefenceAnim::init() } //initializing - int maxLen = 0; - if(killed) { CGI->soundh->playSound(battle_sound(attacked->type, killed)); @@ -1095,10 +1093,11 @@ void CBattleInterface::addNewAnim(CBattleAnimation * anim) } CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect, CPlayerInterface * att, CPlayerInterface * defen) - : attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), stackToActivate(-1), - mouseHoveredStack(-1), previouslyHoveredHex(-1), currentlyHoveredHex(-1), spellDestSelectMode(false), - spellToCast(NULL), givenCommand(NULL), myTurn(false), resWindow(NULL), animIDhelper(0), - moveStarted(false), moveSh(-1), siegeH(NULL), bresult(NULL), queue(NULL), attackerInt(att), defenderInt(defen), curInt(att) + : queue(NULL), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), + activeStack(-1), stackToActivate(-1), mouseHoveredStack(-1), previouslyHoveredHex(-1), + currentlyHoveredHex(-1), spellDestSelectMode(false), spellToCast(NULL), siegeH(NULL), + attackerInt(att), defenderInt(defen), curInt(att), animIDhelper(0), givenCommand(NULL), + myTurn(false), resWindow(NULL), moveStarted(false), moveSh(-1), bresult(NULL) { ObjectConstruction h__l__p(this); @@ -4009,7 +4008,7 @@ void CBattleOptionsWindow::bExitf() std::string CBattleInterface::SiegeHelper::townTypeInfixes[F_NUMBER] = {"CS", "RM", "TW", "IN", "NC", "DN", "ST", "FR", "EL"}; CBattleInterface::SiegeHelper::SiegeHelper(const CGTownInstance *siegeTown, const CBattleInterface * _owner) -: town(siegeTown), owner(_owner) + : owner(_owner), town(siegeTown) { for(int g=0; g(i,FDef); i+=4; diff --git a/client/CGameInfo.h b/client/CGameInfo.h index a0636e025..d475d78b3 100644 --- a/client/CGameInfo.h +++ b/client/CGameInfo.h @@ -30,7 +30,7 @@ class CCursorHandler; class CGameState; class CVideoPlayer; -class Mapa; +struct Mapa; /* CGameInfo class diff --git a/client/CMessage.cpp b/client/CMessage.cpp index 63631c2ca..e6221bcb9 100644 --- a/client/CMessage.cpp +++ b/client/CMessage.cpp @@ -396,8 +396,8 @@ SDL_Surface * CMessage::drawBoxTextBitmapSub( int player, std::string text, SDL_ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player) { SDL_Surface * _or = NULL; - const Font &f = *graphics->fonts[FONT_MEDIUM]; - int fontHeight = f.height; + //const Font &f = *graphics->fonts[FONT_MEDIUM]; + //int fontHeight = f.height; if(dynamic_cast(ret)) //it's selection window, so we'll blit "or" between components _or = FNT_RenderText(FONT_MEDIUM,CGI->generaltexth->allTexts[4],zwykly); diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 968989c37..fe9cc5386 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -329,10 +329,10 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details) if (directlyAttackingCreature) { // Get direction to attacker. int3 posOffset = details.attackedFrom - details.end + int3(2, 1, 0); - const ui8 dirLookup[3][3] = { - 1, 2, 3, - 8, 0, 4, - 7, 6, 5 + static const ui8 dirLookup[3][3] = { + { 1, 2, 3 }, + { 8, 0, 4 }, + { 7, 6, 5 } }; // FIXME: Avoid const_cast, make moveDir mutable in some other way? const_cast(ho)->moveDir = dirLookup[posOffset.y][posOffset.x]; @@ -2110,4 +2110,4 @@ CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting() { spellbookLastPageBattle = spellbokLastPageAdvmap = 0; spellbookLastTabBattle = spellbookLastTabAdvmap = 4; -} \ No newline at end of file +} diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 431877040..5ca5a9635 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -349,7 +349,8 @@ void CGPreGame::update() } CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer /*= CMenuScreen::SINGLE_PLAYER*/, const std::map *Names /*= NULL*/) - : ISelectionScreenInfo(Names), serv(NULL), ongoingClosing(false), serverHandlingThread(NULL), myNameID(255), mx(new boost::recursive_mutex) + : ISelectionScreenInfo(Names), serverHandlingThread(NULL), mx(new boost::recursive_mutex), + serv(NULL), ongoingClosing(false), myNameID(255) { screenType = Type; multiPlayer = MultiPlayer; @@ -1397,7 +1398,8 @@ void CChatBox::addNewMessage(const std::string &text) } InfoCard::InfoCard( bool Network ) -: difficulty(NULL), sizes(NULL), sFlags(NULL), bg(NULL), chatOn(false), chat(NULL), network(Network), playerListBg(NULL) + : bg(NULL), network(Network), chatOn(false), chat(NULL), playerListBg(NULL), + difficulty(NULL), sizes(NULL), sFlags(NULL) { OBJ_CONSTRUCTION; pos.x += 393; @@ -2018,7 +2020,7 @@ void OptionsTab::flagPressed( int color ) } OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSettings &S) -:s(S), pi(SEL->current->mapHeader->players[S.color]) + : pi(SEL->current->mapHeader->players[S.color]), s(S) { OBJ_CONSTRUCTION; defActions |= SHARE_POS; @@ -3346,4 +3348,4 @@ void StartWithCurrentSettings::apply(CSelectionScreen *selScreen) GH.popInt(GH.topInt()); //only deactivate main menu screen ::startGame(startingInfo.sInfo, startingInfo.serv); throw 666; //EVIL, EVIL, EVIL workaround to kill thread (does "goto catch" outside listening loop) -} \ No newline at end of file +} diff --git a/client/CPreGame.h b/client/CPreGame.h index 8ae714203..ad3c9129c 100644 --- a/client/CPreGame.h +++ b/client/CPreGame.h @@ -18,7 +18,7 @@ * */ -struct CMusicHandler; +class CMusicHandler; class CMapHeader; class CCampaignHeader; class CTextInput; @@ -27,8 +27,8 @@ class CGStatusBar; class CTextBox; class CCampaignState; class CConnection; -class CPackForSelectionScreen; -class PlayerInfo; +struct CPackForSelectionScreen; +struct PlayerInfo; namespace boost{ class thread; class recursive_mutex;} diff --git a/client/Client.cpp b/client/Client.cpp index 87ada3082..5c8335b99 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -241,7 +241,6 @@ void CClient::loadGame( const std::string & fname ) timeHandler tmh; { - ui32 ver; char sig[8]; CMapHeader dum; CGI->mh = new CMapHandler(); @@ -600,4 +599,4 @@ CConnection * CServerHandler::justConnectToServer(const std::string &host, const } } return ret; -} \ No newline at end of file +} diff --git a/client/GUIBase.h b/client/GUIBase.h index 4453dee0f..510b3c98a 100644 --- a/client/GUIBase.h +++ b/client/GUIBase.h @@ -50,7 +50,7 @@ template struct CondSh; class CInGameConsole; class CGarrisonInt; class CInGameConsole; -class Component; +struct Component; class CArmedInstance; class CGTownInstance; class StackState; diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 5bac255a7..62fb05081 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -2866,7 +2866,7 @@ std::vector *CTradeWindow::getItemsIds(bool Left) { case PLAYER: ids = new std::vector; - for(int i = 0, found = 0; i < PLAYER_LIMIT; i++) + for(int i = 0; i < PLAYER_LIMIT; i++) if(i != LOCPLINT->playerID && LOCPLINT->cb->getPlayerStatus(i) == PlayerState::INGAME) ids->push_back(i); break; diff --git a/client/GUIClasses.h b/client/GUIClasses.h index 506c01ef2..14f8b6023 100644 --- a/client/GUIClasses.h +++ b/client/GUIClasses.h @@ -53,7 +53,7 @@ template struct CondSh; class CInGameConsole; class CGarrisonInt; class CInGameConsole; -class Component; +struct Component; class CArmedInstance; class CGTownInstance; class StackState; diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index 41e877feb..49fe6a104 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -825,11 +825,12 @@ bool CMapHandler::printObject(const CGObjectInstance *obj) processDef(obj->defInfo); const SDL_Surface *bitmap = obj->defInfo->handler->ourImages[0].bitmap; - int tilesW = bitmap->w/32, - tilesH = bitmap->h/32; - for(int fx=0; fxw/32; ++fx) + const int tilesW = bitmap->w/32; + const int tilesH = bitmap->h/32; + + for(int fx=0; fxh/32; ++fy) + for(int fy=0; fy toAdd = std::make_pair(obj, cr); - if((obj->pos.x + fx - bitmap->w/32+1)>=0 && (obj->pos.x + fx - bitmap->w/32+1)pos.y + fy - bitmap->h/32+1)>=0 && (obj->pos.y + fy - bitmap->h/32+1)pos.x + fx - tilesW+1)>=0 && (obj->pos.x + fx - tilesW+1)pos.y + fy - tilesH+1)>=0 && (obj->pos.y + fy - tilesH+1)pos.x + fx - bitmap->w/32+1][obj->pos.y + fy - bitmap->h/32+1][obj->pos.z]; + TerrainTile2 & curt = ttiles[obj->pos.x + fx - tilesW+1][obj->pos.y + fy - tilesH+1][obj->pos.z]; std::vector< std::pair >::iterator i = curt.objects.begin(); for(; i != curt.objects.end(); i++) @@ -857,8 +858,8 @@ bool CMapHandler::printObject(const CGObjectInstance *obj) curt.objects.insert(i, toAdd); } - } // for(int fy=0; fyh/32; ++fy) - } //for(int fx=0; fxw/32; ++fx) + } // for(int fy=0; fygetDate(3)<<1); {//no lower tiers or above current month - if (n = getSlotFor(town->basicCreatures[i], ARMY_SIZE)); + if ((n = getSlotFor(town->basicCreatures[i], ARMY_SIZE))) { SetGarrisons sg; sg.garrs[id] = getArmy(); @@ -6183,10 +6183,10 @@ int3 IBoatGenerator::bestLocation() const std::vector offsets; getOutOffsets(offsets); - TerrainTile *tile; for (int i = 0; i < offsets.size(); ++i) { - if (tile = IObjectInterface::cb->getTile(o->pos + offsets[i])) //tile is in the map + TerrainTile *tile = IObjectInterface::cb->getTile(o->pos + offsets[i]); + if (tile) //tile is in the map { if (tile->tertype == TerrainTile::water && (!tile->blocked || tile->blockingObjects.front()->ID == 8)) //and is water and is not blocked or is blocked by boat return o->pos + offsets[i]; diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index da3c6964c..2cb9a2762 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -24,7 +24,7 @@ */ struct MetaString; -class BattleInfo; +struct BattleInfo; class IGameCallback; struct BattleResult; class CCPPObjectScript; diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 3515adffd..5f38761af 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1061,8 +1061,8 @@ int CGameState::pickHero(int owner) const PlayerSettings &ps = scenarioOps->getIthPlayersSettings(owner); if(!map->getHero(h = ps.hero,0) && h>=0) //we haven't used selected hero return h; - int f = ps.castle; int i=0; + do //try to find free hero of our faction { i++; @@ -1666,7 +1666,6 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) continue; } CGHeroPlaceholder * hp = static_cast(obj); - CGHeroInstance * substitution = NULL; if(hp->subID != 0xFF) //select by type { @@ -1699,7 +1698,6 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) continue; } CGHeroPlaceholder * hp = static_cast(obj); - CGHeroInstance * substitution = NULL; if (hp->subID == 0xFF) //select by power { @@ -2023,7 +2021,9 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) } while(vti->possibleSpells.size()) { - ui32 total=0, sel=-1; + ui32 total=0; + int sel = -1; + for(unsigned int ps=0;pspossibleSpells.size();ps++) total += VLC->spellh->spells[vti->possibleSpells[ps]].probabilities[vti->subID]; int r = (total)? ran()%total : -1; @@ -4277,7 +4277,7 @@ si8 BattleInfo::hasWallPenalty( int stackID, int destHex ) return false; } const CStack * stack = getStack(stackID); - if (stack->hasBonusOfType(Bonus::NO_WALL_PENALTY)); + if (stack->hasBonusOfType(Bonus::NO_WALL_PENALTY)) { return false; } @@ -4486,8 +4486,8 @@ CMP_stack::CMP_stack( int Phase /*= 1*/, int Turn ) } PlayerState::PlayerState() - : color(-1), currentSelection(0xffffffff), status(INGAME), daysWithoutCastle(0), - enteredLosingCheatCode(0), enteredWinningCheatCode(0) + : color(-1), currentSelection(0xffffffff), enteredWinningCheatCode(0), + enteredLosingCheatCode(0), status(INGAME), daysWithoutCastle(0) { } diff --git a/lib/CMapInfo.h b/lib/CMapInfo.h index ec4693a44..091fc381d 100644 --- a/lib/CMapInfo.h +++ b/lib/CMapInfo.h @@ -4,7 +4,7 @@ class CMapHeader; class CCampaignHeader; -class StartInfo; +struct StartInfo; class DLL_EXPORT CMapInfo @@ -32,4 +32,4 @@ public: h & mapHeader & campaignHeader & scenarioOpts & filename & lodCmpgn & date & playerAmnt & humenPlayers; h & actualHumanPlayers; } -}; \ No newline at end of file +}; diff --git a/lib/Connection.h b/lib/Connection.h index 92d74d6f2..ef02ec5d9 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -30,7 +30,7 @@ class CGameState; class CCreature; class LibClasses; class CHero; -class CPack; +struct CPack; extern DLL_EXPORT LibClasses * VLC; namespace mpl = boost::mpl; diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index 3b1ac8772..b7a83c6c4 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -105,7 +105,7 @@ namespace HHLP { public: Bonus::BonusSource src; - SourceComp(Bonus::BonusSource _src) : src(src) + SourceComp(Bonus::BonusSource _src) : src(_src) { } bool operator()(const Bonus & bon) @@ -186,7 +186,8 @@ Bonus * CBonusSystemNode::getBonus(const CSelector &selector) getParents (parents, this); BOOST_FOREACH (CBonusSystemNode *pname, parents) { - if(ret = pname->getBonus(selector)) + ret = pname->getBonus(selector); + if (ret) return ret; } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index a3905e983..c32c0accd 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1198,7 +1198,6 @@ void CGameHandler::newTurn() for (int i = 0; i < amount; ++i) { tile = tiles.begin(); - TerrainTile *tinfo = &gs->map->terrain[tile->x][tile->y][tile->z]; NewObject no; no.ID = 54; //creature no.subID= n.creatureid; @@ -1214,7 +1213,6 @@ void CGameHandler::newTurn() for(std::vector::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns { - ui8 player = (*j)->tempOwner; SetAvailableCreatures sac; sac.tid = (**j).id; sac.creatures = (**j).creatures; @@ -4640,7 +4638,6 @@ void CGameHandler::objectVisited( const CGObjectInstance * obj, const CGHeroInst bool CGameHandler::buildBoat( ui32 objid ) { const IShipyard *obj = IShipyard::castFrom(getObj(objid)); - int boatType = 1; if(obj->state()) { @@ -4788,7 +4785,7 @@ void CGameHandler::checkLossVictory( ui8 player ) void CGameHandler::getLossVicMessage( ui8 player, ui8 standard, bool victory, InfoWindow &out ) const { - const PlayerState *p = gs->getPlayer(player); +// const PlayerState *p = gs->getPlayer(player); // if(!p->human) // return; //AI doesn't need text info of loss @@ -4971,7 +4968,7 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat ) int spellID = sf.subtype; int spellLevel = sf.val; int chance = sf.additionalInfo % 1000; - int meleeRanged = sf.additionalInfo / 1000; + //int meleeRanged = sf.additionalInfo / 1000; int destination = oneOfAttacked->position; //check if spell should be casted (probability handling) if( rand()%100 >= chance ) diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 4eb8dfae1..0750e0002 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -60,8 +60,8 @@ static void vaccept(tcp::acceptor *ac, tcp::socket *s, boost::system::error_code CPregameServer::CPregameServer(CConnection *Host, TAcceptor *Acceptor /*= NULL*/) - : host(Host), state(RUNNING), acceptor(Acceptor), upcomingConnection(NULL), curmap(NULL), listeningThreads(0), - curStartInfo(NULL) + : host(Host), listeningThreads(0), acceptor(Acceptor), upcomingConnection(NULL), + curmap(NULL), curStartInfo(NULL), state(RUNNING) { initConnection(host); } @@ -458,7 +458,6 @@ void CVCMIServer::loadGame() c >> clients >> fname; //how many clients should be connected - TODO: support more than one { - ui32 ver; char sig[8]; CMapHeader dum; StartInfo *si; diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h index 73e22d2c2..642b00a91 100644 --- a/server/CVCMIServer.h +++ b/server/CVCMIServer.h @@ -17,7 +17,7 @@ class CMapInfo; class CConnection; -class CPackForSelectionScreen; +struct CPackForSelectionScreen; class CGameHandler; namespace boost