diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index d67186d..ae4f31a 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -1458,7 +1458,6 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h) lostHero(h); //we need to throw, otherwise hero will be assigned to sth again throw std::runtime_error("Hero was lost!"); - break; } } @@ -2305,7 +2304,7 @@ void AIStatus::madeTurn() void AIStatus::waitTillFree() { boost::unique_lock lock(mx); - while(battle != NO_BATTLE || remainingQueries.size() || objectsBeingVisited.size() || ongoingHeroMovement) + while(battle != NO_BATTLE || !remainingQueries.empty() || !objectsBeingVisited.empty() || ongoingHeroMovement) cv.timed_wait(lock, boost::posix_time::milliseconds(100)); } @@ -2423,7 +2422,7 @@ void SectorMap::exploreNewSector(crint3 pos, int num) std::queue toVisit; toVisit.push(pos); - while(toVisit.size()) + while(!toVisit.empty()) { int3 curPos = toVisit.front(); toVisit.pop(); @@ -2513,7 +2512,6 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj) } } return true; //we don't have this quest yet - break; } case Obj::SEER_HUT: case Obj::QUEST_GUARD: @@ -2529,7 +2527,6 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj) } } return true; //we don't have this quest yet - break; } case Obj::CREATURE_GENERATOR1: { @@ -2546,7 +2543,6 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj) } } return canRecruitCreatures; - break; } case Obj::HILL_FORT: { @@ -2556,7 +2552,6 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj) return true; //TODO: check price? } return false; - break; } case Obj::MONOLITH1: case Obj::MONOLITH2: @@ -2564,7 +2559,6 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj) case Obj::WHIRLPOOL: //TODO: mechanism for handling monoliths return false; - break; case Obj::SCHOOL_OF_MAGIC: case Obj::SCHOOL_OF_WAR: { @@ -2778,7 +2772,7 @@ void SectorMap::makeParentBFS(crint3 source) int mySector = retreiveTile(source); std::queue toVisit; toVisit.push(source); - while(toVisit.size()) + while(!toVisit.empty()) { int3 curPos = toVisit.front(); toVisit.pop(); diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 7baa01d..11c9b12 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -338,7 +338,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details) //check if user cancelled movement { boost::unique_lock un(eventsM); - while(events.size()) + while(!events.empty()) { SDL_Event ev = events.front(); events.pop(); @@ -1075,7 +1075,7 @@ void CPlayerInterface::tileRevealed(const std::unordered_set &p EVENT_HANDLER_CALLED_BY_CLIENT; for(auto & po : pos) adventureInt->minimap.showTile(po); - if(pos.size()) + if(!pos.empty()) GH.totalRedraw(); } @@ -1084,7 +1084,7 @@ void CPlayerInterface::tileHidden(const std::unordered_set &pos EVENT_HANDLER_CALLED_BY_CLIENT; for(auto & po : pos) adventureInt->minimap.hideTile(po); - if(pos.size()) + if(!pos.empty()) GH.totalRedraw(); } @@ -1233,7 +1233,7 @@ bool CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path ) return false; //can't find hero //It shouldn't be possible to move hero with open dialog (or dialog waiting in bg) - if(showingDialog->get() || dialogs.size()) + if(showingDialog->get() || !dialogs.empty()) return false; @@ -1578,7 +1578,7 @@ void CPlayerInterface::update() boost::shared_lock gsLock(cb->getGsMutex()); //if there are any waiting dialogs, show them - if((howManyPeople <= 1 || makingTurn) && dialogs.size() && !showingDialog->get()) + if((howManyPeople <= 1 || makingTurn) && !dialogs.empty() && !showingDialog->get()) { showingDialog->set(true); GH.pushInt(dialogs.front()); @@ -1637,7 +1637,7 @@ int CPlayerInterface::getLastIndex( std::string namePrefix) } } - if(dates.size()) + if(!dates.empty()) return (--dates.end())->second; //return latest file number return 0; } @@ -2506,7 +2506,7 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player) void CPlayerInterface::waitForAllDialogs(bool unlockPim /*= true*/) { - while(dialogs.size()) + while(!dialogs.empty()) { auto unlock = vstd::makeUnlockGuardIf(*pim, unlockPim); SDL_Delay(5); diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index f5b5549..2da72c1 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -986,7 +986,7 @@ void CSelectionScreen::setSInfo(const StartInfo &si) void CSelectionScreen::processPacks() { boost::unique_lock lll(*mx); - while(upcomingPacks.size()) + while(!upcomingPacks.empty()) { CPackForSelectionScreen *pack = upcomingPacks.front(); upcomingPacks.pop_front(); @@ -3759,7 +3759,7 @@ ISelectionScreenInfo::ISelectionScreenInfo(const std::map *Nam SEL = this; current = nullptr; - if(Names && Names->size()) //if have custom set of player names - use it + if(Names && !Names->empty()) //if have custom set of player names - use it playerNames = *Names; else playerNames[1] = settings["general"]["playerName"].String(); //by default we have only one player and his name is "Player" (or whatever the last used name was) diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index a20b44c..15acca4 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -758,12 +758,12 @@ void CBattleInterface::setBattleCursor(const int myNumber) attackingHex = myNumber - GameConstants::BFIELD_WIDTH + zigzagCorrection; //top right break; case 3: - break; attackingHex = myNumber + 1; //right + break; case 4: - break; attackingHex = myNumber + GameConstants::BFIELD_WIDTH + zigzagCorrection; //bottom right - case 5: + break; + case 5: attackingHex = myNumber + GameConstants::BFIELD_WIDTH - 1 + zigzagCorrection; //bottom left break; } @@ -3033,7 +3033,7 @@ void CBattleInterface::show(SDL_Surface * to) showInterface(to); //activation of next stack - if(pendingAnims.size() == 0 && stackToActivate != nullptr) + if(pendingAnims.empty() && stackToActivate != nullptr) { activateStack(); @@ -3542,7 +3542,7 @@ void CBattleInterface::updateBattleAnimations() } } - if(preSize > 0 && pendingAnims.size() == 0) + if(preSize > 0 && pendingAnims.empty()) { //anims ended blockUI(activeStack == nullptr); @@ -3672,4 +3672,4 @@ void CBattleInterface::showPiecesOfWall(SDL_Surface * to, std::vector piece } } } -} \ No newline at end of file +} diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index 2acf78b..0602cea 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -86,7 +86,7 @@ void CGuiHandler::popInt( IShowActivatable *top ) top->deactivate(); listInt.pop_front(); objsToBlit -= top; - if(listInt.size()) + if(!listInt.empty()) listInt.front()->activate(); totalRedraw(); } @@ -107,7 +107,7 @@ void CGuiHandler::pushInt( IShowActivatable *newInt ) //a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway) screenBuf = screen2; - if(listInt.size()) + if(!listInt.empty()) listInt.front()->deactivate(); listInt.push_front(newInt); newInt->activate(); @@ -128,7 +128,7 @@ void CGuiHandler::popInts( int howMany ) listInt.pop_front(); } - if(listInt.size()) + if(!listInt.empty()) { listInt.front()->activate(); totalRedraw(); @@ -138,7 +138,7 @@ void CGuiHandler::popInts( int howMany ) IShowActivatable * CGuiHandler::topInt() { - if(!listInt.size()) + if(listInt.empty()) return nullptr; else return listInt.front(); diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index b4b6991..a1eeb99 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -58,7 +58,7 @@ int BattleInfo::getAvaliableHex(CreatureID creID, bool attackerOwned, int initia if(accessibility.accessible(i, twoHex, attackerOwned)) occupyable.insert(i); - if (!occupyable.size()) + if (occupyable.empty()) { return BattleHex::INVALID; //all tiles are covered } diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index 94f598a..3176427 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -2023,7 +2023,7 @@ std::set CBattleInfoCallback::getAffectedCreatures(const CSpell * { possibleHexes.erase (hex); //can't hit same place twice } - if (!possibleHexes.size()) //not enough targets + if (possibleHexes.empty()) //not enough targets break; lightningHex = BattleHex::getClosestTile (stack->attackerOwned, destinationTile, possibleHexes); } diff --git a/lib/CCreatureSet.h b/lib/CCreatureSet.h index 41787c9..522b0b6 100644 --- a/lib/CCreatureSet.h +++ b/lib/CCreatureSet.h @@ -208,7 +208,7 @@ public: } operator bool() const { - return stacks.size() > 0; + return !stacks.empty(); } void sweep(); }; diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index b880ea2..b771bbe 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1542,7 +1542,7 @@ void CGameState::initDuel() for(int i = 0; i < ss.heroPrimSkills.size(); i++) h->pushPrimSkill(static_cast(i), ss.heroPrimSkills[i]); - if(ss.spells.size()) + if(!ss.spells.empty()) { h->putArtifact(ArtifactPosition::SPELLBOOK, CArtifactInstance::createNewArtifactInstance(0)); boost::copy(ss.spells, std::inserter(h->spells, h->spells.begin())); diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index 2b89348..1546ef0 100644 --- a/lib/CObjectHandler.cpp +++ b/lib/CObjectHandler.cpp @@ -1715,7 +1715,7 @@ std::vector CGHeroInstance::levelUpProposedSkills() const { skills.push_back (obligatorySkills[0]); } - else if(basicAndAdv.size()) + else if(!basicAndAdv.empty()) { SecondarySkill s = type->heroClass->chooseSecSkill(basicAndAdv);//upgrade existing skills.push_back(s); @@ -1736,7 +1736,7 @@ std::vector CGHeroInstance::levelUpProposedSkills() const { skills.push_back(type->heroClass->chooseSecSkill(none)); //new skill } - else if(basicAndAdv.size()) + else if(!basicAndAdv.empty()) { skills.push_back(type->heroClass->chooseSecSkill(basicAndAdv)); //upgrade existing } @@ -5573,7 +5573,7 @@ void CGPandoraBox::giveContentsAfterExp(const CGHeroInstance *h) const spellsToGive.insert(*i); } } - if(spellsToGive.size()) + if(!spellsToGive.empty()) { cb->changeSpells(h,true,spellsToGive); cb->showInfoDialog(&iw); @@ -7264,7 +7264,7 @@ void CArmedInstance::updateMoraleBonusFromArmy() b->val = +1; b->description = VLC->generaltexth->arraytxt[115]; //All troops of one alignment +1 } - else if (factions.size()) // no bonus from empty garrison + else if (!factions.empty()) // no bonus from empty garrison { b->val = 2 - factionsInArmy; b->description = boost::str(boost::format(VLC->generaltexth->arraytxt[114]) % factionsInArmy % b->val); //Troops of %d alignments %d diff --git a/lib/Connection.h b/lib/Connection.h index 8dcd61a..e7962da 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -1255,10 +1255,7 @@ public: class DLL_LINKAGE CSaveFile : public COSer { - void dummyMagicFunction() - { - *this << std::string("This function makes stuff working."); - } + public: std::string fName; unique_ptr sfile; @@ -1277,11 +1274,7 @@ public: class DLL_LINKAGE CLoadFile : public CISer { - void dummyMagicFunction() - { - std::string dummy = "This function makes stuff working."; - *this >> dummy; - } + public: std::string fName; unique_ptr sfile; diff --git a/scripting/erm/ERMParser.cpp b/scripting/erm/ERMParser.cpp index b0837a8..018339d 100644 --- a/scripting/erm/ERMParser.cpp +++ b/scripting/erm/ERMParser.cpp @@ -488,34 +488,6 @@ ERM::TLine ERMParser::parseLine(const std::string & line) return AST; } -ERMParser::ELineType ERMParser::classifyLine( const std::string & line, bool inString ) const -{ - ERMParser::ELineType ret; - if(line[0] == '!') - { - if(countHatsBeforeSemicolon(line) % 2 == 1) - ret = ERMParser::UNFINISHED; - else - ret = ERMParser::COMMAND_FULL; - } - else - { - if(inString) - { - if(countHatsBeforeSemicolon(line) % 2 == 1) - ret = ERMParser::END_OF; - else - ret = ERMParser::UNFINISHED; - } - else - { - ret = ERMParser::COMMENT; - } - } - - return ret; -} - int ERMParser::countHatsBeforeSemicolon( const std::string & line ) const { //CHECK: omit macros? or anything else? @@ -543,4 +515,4 @@ void ERMParser::repairEncoding( char * str, int len ) const for(int g=0; gwinnerHero->id; @@ -1586,7 +1586,7 @@ void CGameHandler::giveSpells( const CGTownInstance *t, const CGHeroInstance *h } } } - if(cs.spells.size()) + if(!cs.spells.empty()) sendAndApply(&cs); } @@ -2079,7 +2079,7 @@ void CGameHandler::useScholarSkill(ObjectInstanceID fromHero, ObjectInstanceID t if ( h1Lvl >= it.toSpell()->level && !vstd::contains(h1->spells, it)) cs2.spells.insert(it); - if (cs1.spells.size() || cs2.spells.size())//create a message + if (!cs1.spells.empty() || !cs2.spells.empty())//create a message { InfoWindow iw; iw.player = h1->tempOwner; @@ -2088,7 +2088,7 @@ void CGameHandler::useScholarSkill(ObjectInstanceID fromHero, ObjectInstanceID t iw.text.addTxt(MetaString::GENERAL_TXT, 139);//"%s, who has studied magic extensively, iw.text.addReplacement(h1->name); - if (cs2.spells.size())//if found new spell - apply + if (!cs2.spells.empty())//if found new spell - apply { iw.text.addTxt(MetaString::GENERAL_TXT, 140);//learns int size = cs2.spells.size(); @@ -2108,12 +2108,12 @@ void CGameHandler::useScholarSkill(ObjectInstanceID fromHero, ObjectInstanceID t sendAndApply(&cs2); } - if (cs1.spells.size() && cs2.spells.size() ) + if (!cs1.spells.empty() && !cs2.spells.empty() ) { iw.text.addTxt(MetaString::GENERAL_TXT, 141);//and } - if (cs1.spells.size()) + if (!cs1.spells.empty()) { iw.text.addTxt(MetaString::GENERAL_TXT, 147);//teaches int size = cs1.spells.size(); @@ -2482,7 +2482,7 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID, std::queue buildingsToAdd; buildingsToAdd.push(requestedBuilding); - while(buildingsToAdd.size()) + while(!buildingsToAdd.empty()) { auto b = buildingsToAdd.front(); buildingsToAdd.pop(); @@ -4263,7 +4263,7 @@ void CGameHandler::handleSpellCasting( SpellID spellID, int spellLvl, BattleHex for(int i = 0; i < GameConstants::BFIELD_SIZE; i += 1) { BattleHex hex = i; - if(hex.getX() > 2 && hex.getX() < 14 && !battleGetStackByPos(hex, false) & !battleGetObstacleOnPos(hex, false)) + if(hex.getX() > 2 && hex.getX() < 14 && !battleGetStackByPos(hex, false) && !battleGetObstacleOnPos(hex, false)) availableTiles.push_back(hex); } boost::range::random_shuffle(availableTiles); diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index e1748ea..6b47b5c 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -119,7 +119,7 @@ void CPregameServer::handleConnection(CConnection *cpc) announceTxt(cpc->name + " left the game"); toAnnounce.push_back(pl); - if(!connections.size()) + if(connections.empty()) { logNetwork->errorStream() << "Last connection lost, server will close itself..."; boost::this_thread::sleep(boost::posix_time::seconds(2)); //we should never be hasty when networking @@ -141,7 +141,7 @@ void CPregameServer::run() { { boost::unique_lock myLock(mx); - while(toAnnounce.size()) + while(!toAnnounce.empty()) { processPack(toAnnounce.front()); toAnnounce.pop_front();