diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 35bffe24a..4d466d056 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -64,11 +64,11 @@ #define THREAD_CREATED_BY_CLIENT #define RETURN_IF_QUICK_COMBAT \ - if(isAutoFightOn && !battleInt) \ + if (isAutoFightOn && !battleInt) \ return; #define BATTLE_EVENT_POSSIBLE_RETURN\ - if(LOCPLINT != this) \ + if (LOCPLINT != this) \ return; \ RETURN_IF_QUICK_COMBAT @@ -130,20 +130,20 @@ CPlayerInterface::~CPlayerInterface() //vstd::clear_pointer(pim); delete showingDialog; delete cingconsole; - if(LOCPLINT == this) + if (LOCPLINT == this) LOCPLINT = nullptr; } void CPlayerInterface::init(std::shared_ptr CB) { cb = CB; - if(observerInDuelMode) + if (observerInDuelMode) return; - if(!towns.size() && !wanderingHeroes.size()) + if (!towns.size() && !wanderingHeroes.size()) initializeHeroTownList(); // always recreate advmap interface to avoid possible memory-corruption bugs - if(adventureInt) + if (adventureInt) delete adventureInt; adventureInt = new CAdvMapInt(); } @@ -158,19 +158,19 @@ void CPlayerInterface::yourTurn() adventureInt->selection = nullptr; std::string prefix = ""; - if(settings["testing"]["enabled"].Bool()) + if (settings["testing"]["enabled"].Bool()) { prefix = settings["testing"]["prefix"].String(); } - if(firstCall) + if (firstCall) { - if(howManyPeople == 1) + if (howManyPeople == 1) adventureInt->setPlayer(playerID); autosaveCount = getLastIndex(prefix + "Autosave_"); - if(firstCall > 0) //new game, not loaded + if (firstCall > 0) //new game, not loaded { int index = getLastIndex(prefix + "Newgame_"); index %= SAVES_COUNT; @@ -178,16 +178,16 @@ void CPlayerInterface::yourTurn() } firstCall = 0; } - else if(settings["testing"].isNull() || cb->getDate() % static_cast(settings["testing"]["savefrequency"].Float()) == 0) + else if (settings["testing"].isNull() || cb->getDate() % static_cast(settings["testing"]["savefrequency"].Float()) == 0) { LOCPLINT->cb->save("Saves/" + prefix + "Autosave_" + boost::lexical_cast(autosaveCount++ + 1)); autosaveCount %= 5; } - if(adventureInt->player != playerID) + if (adventureInt->player != playerID) adventureInt->setPlayer(playerID); - if(howManyPeople > 1) //hot seat message + if (howManyPeople > 1) //hot seat message { adventureInt->startHotSeatWait(playerID); @@ -211,8 +211,8 @@ void CPlayerInterface::yourTurn() STRONG_INLINE void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const ObjectInstanceID & hid) { TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z]; - for(auto & elem : hlp.objects) - if(elem.obj && elem.obj->id == hid) + for (auto & elem : hlp.objects) + if (elem.obj && elem.obj->id == hid) { elem.rect = r; return; @@ -222,8 +222,8 @@ STRONG_INLINE void subRect(const int & x, const int & y, const int & z, const SD STRONG_INLINE void delObjRect(const int & x, const int & y, const int & z, const ObjectInstanceID & hid) { TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z]; - for(int h=0; hid == hid) + for (int h=0; hid == hid) { hlp.objects.erase(hlp.objects.begin()+h); return; @@ -233,23 +233,23 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details) { EVENT_HANDLER_CALLED_BY_CLIENT; waitWhileDialog(); - if(LOCPLINT != this) + if (LOCPLINT != this) return; const CGHeroInstance * hero = cb->getHero(details.id); //object representing this hero int3 hp = details.start; - if(!hero) + if (!hero) { //AI hero left the visible area (we can't obtain info) //TODO very evil workaround -> retrieve pointer to hero so we could animate it // TODO -> we should not need full CGHeroInstance structure to display animation or it should not be handled by playerint (but by the client itself) const TerrainTile2 &tile = CGI->mh->ttiles[hp.x-1][hp.y][hp.z]; - for(auto & elem : tile.objects) - if(elem.obj && elem.obj->id == details.id) + for (auto & elem : tile.objects) + if (elem.obj && elem.obj->id == details.id) hero = dynamic_cast(elem.obj); - if(!hero) //still nothing... + if (!hero) //still nothing... return; } @@ -258,19 +258,19 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details) && adventureInt->terrain.currentPath //in case if movement has been canceled in the meantime and path was already erased && adventureInt->terrain.currentPath->nodes.size() == 3;//FIXME should be 2 but works nevertheless... - if(makingTurn && hero->tempOwner == playerID) //we are moving our hero - we may need to update assigned path + if (makingTurn && hero->tempOwner == playerID) //we are moving our hero - we may need to update assigned path { //We may need to change music - select new track, music handler will change it if needed CCS->musich->playMusicFromSet("terrain", LOCPLINT->cb->getTile(hero->visitablePos())->terType, true); - if(details.result == TryMoveHero::TELEPORTATION) + if (details.result == TryMoveHero::TELEPORTATION) { - if(adventureInt->terrain.currentPath) + if (adventureInt->terrain.currentPath) { assert(adventureInt->terrain.currentPath->nodes.size() >= 2); std::vector::const_iterator nodesIt = adventureInt->terrain.currentPath->nodes.end() - 1; - if((nodesIt)->coord == CGHeroInstance::convertPosition(details.start, false) + if ((nodesIt)->coord == CGHeroInstance::convertPosition(details.start, false) && (nodesIt-1)->coord == CGHeroInstance::convertPosition(details.end, false)) { //path was between entrance and exit of teleport -> OK, erase node as usual @@ -295,9 +295,9 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details) { eraseCurrentPathOf(hero, false); } - else if(adventureInt->terrain.currentPath && hero->pos == details.end) //&& hero is moving + else if (adventureInt->terrain.currentPath && hero->pos == details.end) //&& hero is moving { - if(details.start != details.end) //so we don't touch path when revisiting with spacebar + if (details.start != details.end) //so we don't touch path when revisiting with spacebar removeLastNodeFromPath(hero); } } @@ -336,7 +336,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details) GH.mainFPSmng->framerateDelay(); // after first move //main moving - for(int i=1; i<32; i+=2*speed) + for (int i=1; i<32; i+=2*speed) { movementPxStep(details, i, hp, hero); adventureInt->updateScreen = true; @@ -351,7 +351,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details) } //CSDL_Ext::update(screen); - } //for(int i=1; i<32; i+=4) + } //for (int i=1; i<32; i+=4) //main moving done //finishing move @@ -375,14 +375,14 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details) stillMoveHero.setn(STOP_MOVE); break; case SDL_KEYDOWN: - if(ev.key.keysym.sym < SDLK_F1 || ev.key.keysym.sym > SDLK_F15) + if (ev.key.keysym.sym < SDLK_F1 || ev.key.keysym.sym > SDLK_F15) stillMoveHero.setn(STOP_MOVE); break; } } } - if(stillMoveHero.get() == WAITING_MOVE) + if (stillMoveHero.get() == WAITING_MOVE) stillMoveHero.setn(DURING_MOVE); // Hero attacked creature directly, set direction to face it. @@ -422,13 +422,13 @@ void CPlayerInterface::heroKilled(const CGHeroInstance* hero) } wanderingHeroes -= hero; - if(vstd::contains(paths, hero)) + if (vstd::contains(paths, hero)) paths.erase(hero); adventureInt->heroList.update(hero); if (makingTurn && newSelection) adventureInt->select(newSelection, true); - else if(adventureInt->selection == hero) + else if (adventureInt->selection == hero) adventureInt->selection = nullptr; } @@ -448,25 +448,25 @@ void CPlayerInterface::openTownWindow(const CGTownInstance * town) int3 CPlayerInterface::repairScreenPos(int3 pos) { - if(pos.x<-CGI->mh->frameW) + if (pos.x<-CGI->mh->frameW) pos.x = -CGI->mh->frameW; - if(pos.y<-CGI->mh->frameH) + if (pos.y<-CGI->mh->frameH) pos.y = -CGI->mh->frameH; - if(pos.x>CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW) + if (pos.x>CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW) pos.x = CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW; - if(pos.y>CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH) + if (pos.y>CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH) pos.y = CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH; return pos; } void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(which == 4) + if (which == 4) { - if(CAltarWindow *ctw = dynamic_cast(GH.topInt())) + if (CAltarWindow *ctw = dynamic_cast(GH.topInt())) ctw->setExpToLevel(); } - else if(which < GameConstants::PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4) + else if (which < GameConstants::PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4) updateInfo(hero); } @@ -474,7 +474,7 @@ void CPlayerInterface::heroSecondarySkillChanged(const CGHeroInstance * hero, in { EVENT_HANDLER_CALLED_BY_CLIENT; CUniversityWindow* cuw = dynamic_cast(GH.topInt()); - if(cuw) //university window is open + if (cuw) //university window is open { GH.totalRedraw(); } @@ -484,19 +484,19 @@ void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero) { EVENT_HANDLER_CALLED_BY_CLIENT; updateInfo(hero); - if(makingTurn && hero->tempOwner == playerID) + if (makingTurn && hero->tempOwner == playerID) adventureInt->heroList.update(hero); } void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(makingTurn && hero->tempOwner == playerID) + if (makingTurn && hero->tempOwner == playerID) adventureInt->heroList.update(hero); } void CPlayerInterface::receivedResource(int type, int val) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(CMarketplaceWindow *mw = dynamic_cast(GH.topInt())) + if (CMarketplaceWindow *mw = dynamic_cast(GH.topInt())) mw->resourceChanged(type, val); GH.totalRedraw(); @@ -529,23 +529,23 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town) EVENT_HANDLER_CALLED_BY_CLIENT; updateInfo(town); - if(town->garrisonHero) //wandering hero moved to the garrison + if (town->garrisonHero) //wandering hero moved to the garrison { CGI->mh->hideObject(town->garrisonHero); - if(town->garrisonHero->tempOwner == playerID && vstd::contains(wanderingHeroes,town->garrisonHero)) // our hero + if (town->garrisonHero->tempOwner == playerID && vstd::contains(wanderingHeroes,town->garrisonHero)) // our hero wanderingHeroes -= town->garrisonHero; } - if(town->visitingHero) //hero leaves garrison + if (town->visitingHero) //hero leaves garrison { CGI->mh->printObject(town->visitingHero); - if(town->visitingHero->tempOwner == playerID && !vstd::contains(wanderingHeroes,town->visitingHero)) // our hero + if (town->visitingHero->tempOwner == playerID && !vstd::contains(wanderingHeroes,town->visitingHero)) // our hero wanderingHeroes.push_back(town->visitingHero); } adventureInt->heroList.update(); adventureInt->updateNextHero(nullptr); - if(CCastleInterface *c = castleInt) + if (CCastleInterface *c = castleInt) { c->garr->selectSlot(nullptr); c->garr->setArmy(town->getUpperArmy(), 0); @@ -553,7 +553,7 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town) c->garr->recreateSlots(); c->heroes->update(); } - for(IShowActivatable *isa : GH.listInt) + for (IShowActivatable *isa : GH.listInt) { CKingdomInterface *ki = dynamic_cast(isa); if (ki) @@ -567,7 +567,7 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town) void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(hero->tempOwner != playerID ) + if (hero->tempOwner != playerID ) return; waitWhileDialog(); @@ -576,18 +576,18 @@ void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownIn void CPlayerInterface::garrisonsChanged(std::vector objs) { boost::unique_lock un(*pim); - for(auto object : objs) + for (auto object : objs) updateInfo(object); - for(auto & elem : GH.listInt) + for (auto & elem : GH.listInt) { CGarrisonHolder *cgh = dynamic_cast(elem); if (cgh) cgh->updateGarrisons(); - if(CTradeWindow *cmw = dynamic_cast(elem)) + if (CTradeWindow *cmw = dynamic_cast(elem)) { - if(vstd::contains(objs, cmw->hero)) + if (vstd::contains(objs, cmw->hero)) cmw->garrisonChanged(); } } @@ -612,11 +612,11 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, BuildingID build break; } - if(castleInt) + if (castleInt) { castleInt->townlist->update(town); - if(castleInt->town == town) + if (castleInt->town == town) { switch(what) { @@ -636,14 +636,14 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, BuildingID build void CPlayerInterface::battleStartBefore(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2) { //Don't wait for dialogs when we are non-active hot-seat player - if(LOCPLINT == this) + if (LOCPLINT == this) waitForAllDialogs(); } void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(settings["adventure"]["quickCombat"].Bool()) + if (settings["adventure"]["quickCombat"].Bool()) { autofightingAI = CDynLibHandler::getNewBattleAI(settings["server"]["neutralAI"].String()); autofightingAI->init(cb); @@ -655,7 +655,7 @@ void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet } //Don't wait for dialogs when we are non-active hot-seat player - if(LOCPLINT == this) + if (LOCPLINT == this) waitForAllDialogs(); BATTLE_EVENT_POSSIBLE_RETURN; @@ -667,10 +667,10 @@ void CPlayerInterface::battleStacksHealedRes(const std::vectorbattleGetStackByID(healedStack.first); - if(battleInt->creAnims[healed->ID]->isDead()) + if (battleInt->creAnims[healed->ID]->isDead()) { //stack has been resurrected battleInt->creAnims[healed->ID]->setType(CCreatureAnim::HOLDING); @@ -737,7 +737,7 @@ void CPlayerInterface::battleStacksRemoved(const BattleStacksRemoved & bsr) EVENT_HANDLER_CALLED_BY_CLIENT; BATTLE_EVENT_POSSIBLE_RETURN; - for(auto & elem : bsr.stackIDs) //for each removed stack + for (auto & elem : bsr.stackIDs) //for each removed stack { battleInt->stackRemoved(elem); } @@ -776,12 +776,12 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i logGlobal->traceStream() << "Awaiting command for " << stack->nodeName(); auto stackId = stack->ID; auto stackName = stack->nodeName(); - if(autofightingAI) + if (autofightingAI) { - if(isAutoFightOn) + if (isAutoFightOn) { auto ret = autofightingAI->activeStack(stack); - if(isAutoFightOn) + if (isAutoFightOn) { return ret; } @@ -809,7 +809,7 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i while(!b->givenCommand->data) { b->givenCommand->cond.wait(lock); - if(!battleInt) //battle ended while we were waiting for movement (eg. because of spell) + if (!battleInt) //battle ended while we were waiting for movement (eg. because of spell) throw boost::thread_interrupted(); //will shut the thread peacefully } @@ -817,9 +817,9 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i BattleAction ret = *(b->givenCommand->data); vstd::clear_pointer(b->givenCommand->data); - if(ret.actionType == Battle::CANCEL) + if (ret.actionType == Battle::CANCEL) { - if(stackId != ret.stackNumber) + if (stackId != ret.stackNumber) logGlobal->error("Not current active stack action canceled"); logGlobal->traceStream() << "Canceled command for " << stackName; } @@ -832,14 +832,14 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i void CPlayerInterface::battleEnd(const BattleResult *br) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(isAutoFightOn) + if (isAutoFightOn) { isAutoFightOn = false; cb->unregisterBattleInterface(autofightingAI); autofightingAI.reset(); adventureInt->quickCombatUnlock(); - if(!battleInt) + if (!battleInt) { SDL_Rect temp_rect = genRect(561, 470, (screen->w - 800)/2 + 165, (screen->h - 600)/2 + 19); auto resWindow = new CBattleResultWindow(*br, temp_rect, *this); @@ -891,16 +891,16 @@ void CPlayerInterface::battleStacksAttacked(const std::vector arg; - for(auto & elem : bsa) + for (auto & elem : bsa) { const CStack *defender = cb->battleGetStackByID(elem.stackAttacked, false); const CStack *attacker = cb->battleGetStackByID(elem.attackerID, false); - if(elem.isEffect()) + if (elem.isEffect()) { if (defender && !elem.isSecondary()) battleInt->displayEffect(elem.effect, defender->position); } - if(elem.isSpell()) + if (elem.isSpell()) { if (defender) battleInt->displaySpellEffect(elem.spellID, defender->position); @@ -923,7 +923,7 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba) BATTLE_EVENT_POSSIBLE_RETURN; assert(curAction); - if(ba->lucky()) //lucky hit + if (ba->lucky()) //lucky hit { const CStack *stack = cb->battleGetStackByID(ba->stackAttacking); std::string hlp = CGI->generaltexth->allTexts[45]; @@ -932,7 +932,7 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba) battleInt->displayEffect(18, stack->position); CCS->soundh->playSound(soundBase::GOODLUCK); } - if(ba->unlucky()) //unlucky hit + if (ba->unlucky()) //unlucky hit { const CStack *stack = cb->battleGetStackByID(ba->stackAttacking); std::string hlp = CGI->generaltexth->allTexts[44]; @@ -959,9 +959,9 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba) const CStack * attacker = cb->battleGetStackByID(ba->stackAttacking); - if(ba->shot()) + if (ba->shot()) { - for(auto & elem : ba->bsa) + for (auto & elem : ba->bsa) { if (!elem.isSecondary()) //display projectile only for primary target { @@ -973,12 +973,12 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba) else { int shift = 0; - if(ba->counter() && BattleHex::mutualPosition(curAction->destinationTile, attacker->position) < 0) + if (ba->counter() && BattleHex::mutualPosition(curAction->destinationTile, attacker->position) < 0) { int distp = BattleHex::getDistance(curAction->destinationTile + 1, attacker->position); int distm = BattleHex::getDistance(curAction->destinationTile - 1, attacker->position); - if( distp < distm ) + if ( distp < distm ) shift = 1; else shift = -1; @@ -989,7 +989,7 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba) //battleInt->waitForAnims(); //FIXME: freeze - if(ba->spellLike()) + if (ba->spellLike()) { //display hit animation SpellID spellID = ba->spellID; @@ -1036,7 +1036,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector return; } std::vector intComps; - for(auto & component : components) + for (auto & component : components) intComps.push_back(new CComponent(*component)); showInfoDialog(text,intComps,soundID); @@ -1061,7 +1061,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector } CInfoWindow *temp = CInfoWindow::create(text, playerID, &components); temp->setDelComps(delComps); - if(makingTurn && GH.listInt.size() && LOCPLINT == this) + if (makingTurn && GH.listInt.size() && LOCPLINT == this) { CCS->soundh->playSound(static_cast(soundID)); showingDialog->set(true); @@ -1078,7 +1078,7 @@ void CPlayerInterface::showInfoDialogAndWait(std::vector & components { EVENT_HANDLER_CALLED_BY_CLIENT; std::vector comps; - for(auto & elem : components) + for (auto & elem : components) { comps.push_back(&elem); } @@ -1103,7 +1103,7 @@ void CPlayerInterface::showOkDialog(std::vector & components, const M boost::unique_lock un(*pim); std::vector comps; - for(auto & elem : components) + for (auto & elem : components) { comps.push_back(&elem); } @@ -1114,7 +1114,7 @@ void CPlayerInterface::showOkDialog(std::vector & components, const M showingDialog->setn(true); std::vector intComps; - for(auto & component : comps) + for (auto & component : comps) intComps.push_back(new CComponent(*component)); CInfoWindow::showOkDialog(str, &intComps, onOk, true, playerID); } @@ -1127,23 +1127,23 @@ void CPlayerInterface::showBlockingDialog( const std::string &text, const std::v stopMovement(); CCS->soundh->playSound(static_cast(soundID)); - if(!selection && cancel) //simple yes/no dialog + if (!selection && cancel) //simple yes/no dialog { std::vector intComps; - for(auto & component : components) + for (auto & component : components) intComps.push_back(new CComponent(component)); //will be deleted by close in window showYesNoDialog(text, [=]{ cb->selectionMade(1, askID); }, [=]{ cb->selectionMade(0, askID); }, true, intComps); } - else if(selection) + else if (selection) { std::vector intComps; - for(auto & component : components) + for (auto & component : components) intComps.push_back(new CSelectableComponent(component)); //will be deleted by CSelWindow::close std::vector > > pom; pom.push_back(std::pair >("IOKAY.DEF",0)); - if(cancel) + if (cancel) { pom.push_back(std::pair >("ICANCEL.DEF",0)); } @@ -1163,7 +1163,7 @@ void CPlayerInterface::showTeleportDialog(TeleportChannelID channel, TTeleportEx EVENT_HANDLER_CALLED_BY_CLIENT; int choosenExit = -1; auto neededExit = std::make_pair(destinationTeleport, destinationTeleportPos); - if(destinationTeleport != ObjectInstanceID() && vstd::contains(exits, neededExit)) + if (destinationTeleport != ObjectInstanceID() && vstd::contains(exits, neededExit)) choosenExit = vstd::find_pos(exits, neededExit); cb->selectionMade(choosenExit, askID); @@ -1173,18 +1173,18 @@ void CPlayerInterface::tileRevealed(const std::unordered_set &p { EVENT_HANDLER_CALLED_BY_CLIENT; //FIXME: wait for dialog? Magi hut/eye would benefit from this but may break other areas - for(auto & po : pos) + for (auto & po : pos) adventureInt->minimap.showTile(po); - if(!pos.empty()) + if (!pos.empty()) GH.totalRedraw(); } void CPlayerInterface::tileHidden(const std::unordered_set &pos) { EVENT_HANDLER_CALLED_BY_CLIENT; - for(auto & po : pos) + for (auto & po : pos) adventureInt->minimap.hideTile(po); - if(!pos.empty()) + if (!pos.empty()) GH.totalRedraw(); } @@ -1197,18 +1197,18 @@ void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero) void CPlayerInterface::heroArtifactSetChanged(const CGHeroInstance*hero) { boost::unique_lock un(*pim); - if(adventureInt->heroWindow->curHero && adventureInt->heroWindow->curHero->id == hero->id) //hero window is opened + if (adventureInt->heroWindow->curHero && adventureInt->heroWindow->curHero->id == hero->id) //hero window is opened { adventureInt->heroWindow->deactivate(); adventureInt->heroWindow->setHero(hero); adventureInt->heroWindow->activate(); } - else if(CExchangeWindow* cew = dynamic_cast(GH.topInt())) //exchange window is open + else if (CExchangeWindow* cew = dynamic_cast(GH.topInt())) //exchange window is open { cew->deactivate(); - for(int g=0; gheroInst); ++g) + for (int g=0; gheroInst); ++g) { - if(cew->heroInst[g]->id == hero->id) + if (cew->heroInst[g]->id == hero->id) { cew->heroInst[g] = hero; cew->artifs[g]->updateState = true; @@ -1219,9 +1219,9 @@ void CPlayerInterface::heroArtifactSetChanged(const CGHeroInstance*hero) cew->prepareBackground(); cew->activate(); } - else if(CTradeWindow *caw = dynamic_cast(GH.topInt())) + else if (CTradeWindow *caw = dynamic_cast(GH.topInt())) { - if(caw->arts) + if (caw->arts) { caw->deactivate(); caw->arts->updateState = true; @@ -1237,24 +1237,24 @@ void CPlayerInterface::heroArtifactSetChanged(const CGHeroInstance*hero) void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town ) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(const CGTownInstance * townObj = dynamic_cast(town)) + if (const CGTownInstance * townObj = dynamic_cast(town)) { CFortScreen *fs = dynamic_cast(GH.topInt()); - if(fs) + if (fs) fs->creaturesChanged(); - for(IShowActivatable *isa : GH.listInt) + for (IShowActivatable *isa : GH.listInt) { CKingdomInterface *ki = dynamic_cast(isa); if (ki && townObj) ki->townChanged(townObj); } } - else if(GH.listInt.size() && (town->ID == Obj::CREATURE_GENERATOR1 + else if (GH.listInt.size() && (town->ID == Obj::CREATURE_GENERATOR1 || town->ID == Obj::CREATURE_GENERATOR4 || town->ID == Obj::WAR_MACHINE_FACTORY)) { CRecruitmentWindow *crw = dynamic_cast(GH.topInt()); - if(crw && crw->dwelling == town) + if (crw && crw->dwelling == town) crw->availableCreaturesChanged(); } } @@ -1262,7 +1262,7 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town ) void CPlayerInterface::heroBonusChanged( const CGHeroInstance *hero, const Bonus &bonus, bool gain ) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(bonus.type == Bonus::NONE) + if (bonus.type == Bonus::NONE) return; updateInfo(hero); @@ -1281,11 +1281,11 @@ template void CPlayerInterface::serializeTempl( Handler &h, c h & wanderingHeroes & towns & sleepingHeroes; std::map pathsMap; //hero -> dest - if(h.saving) + if (h.saving) { - for(auto &p : paths) + for (auto &p : paths) { - if(p.second.nodes.size()) + if (p.second.nodes.size()) pathsMap[p.first] = p.second.endPos(); else logGlobal->errorStream() << p.first->name << " has assigned an empty path! Ignoring it..."; @@ -1296,8 +1296,8 @@ template void CPlayerInterface::serializeTempl( Handler &h, c { h & pathsMap; - if(cb) - for(auto &p : pathsMap) + if (cb) + for (auto &p : pathsMap) { CGPath path; cb->getPathsInfo(p.first)->getPath(path, p.second); @@ -1326,13 +1326,13 @@ void CPlayerInterface::loadGame( CISer & h, const int version ) void CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path ) { logGlobal->traceStream() << __FUNCTION__; - if(!LOCPLINT->makingTurn) + if (!LOCPLINT->makingTurn) return; if (!h) return; //can't find hero //It shouldn't be possible to move hero with open dialog (or dialog waiting in bg) - if(showingDialog->get() || !dialogs.empty()) + if (showingDialog->get() || !dialogs.empty()) return; setMovementStatus(true); @@ -1364,7 +1364,7 @@ void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHer EVENT_HANDLER_CALLED_BY_CLIENT; auto onEnd = [=]{ cb->selectionMade(0, queryID); }; - if(stillMoveHero.get() == DURING_MOVE && adventureInt->terrain.currentPath && adventureInt->terrain.currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons + if (stillMoveHero.get() == DURING_MOVE && adventureInt->terrain.currentPath && adventureInt->terrain.currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons { onEnd(); return; @@ -1415,11 +1415,11 @@ void CPlayerInterface::showArtifactAssemblyDialog (ui32 artifactID, ui32 assembl void CPlayerInterface::requestRealized( PackageApplied *pa ) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(pa->packType == typeList.getTypeID() && stillMoveHero.get() == DURING_MOVE + if (pa->packType == typeList.getTypeID() && stillMoveHero.get() == DURING_MOVE && destinationTeleport == ObjectInstanceID()) stillMoveHero.setn(CONTINUE_MOVE); - if(destinationTeleport != ObjectInstanceID() + if (destinationTeleport != ObjectInstanceID() && pa->packType == typeList.getTypeID() && stillMoveHero.get() == DURING_MOVE) { // After teleportation via CGTeleport object is finished @@ -1439,19 +1439,19 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop) { EVENT_HANDLER_CALLED_BY_CLIENT; //redraw minimap if owner changed - if(sop->what == ObjProperty::OWNER) + if (sop->what == ObjProperty::OWNER) { const CGObjectInstance * obj = cb->getObj(sop->id); std::set pos = obj->getBlockedPos(); - for(auto & po : pos) + for (auto & po : pos) { - if(cb->isVisible(po)) + if (cb->isVisible(po)) adventureInt->minimap.showTile(po); } - if(obj->ID == Obj::TOWN) + if (obj->ID == Obj::TOWN) { - if(obj->tempOwner == playerID) + if (obj->tempOwner == playerID) towns.push_back(static_cast(obj)); else towns -= obj; @@ -1500,7 +1500,7 @@ void CPlayerInterface::initializeHeroTownList() towns.clear(); towns = newTowns; newTowns.clear();*/ - for(auto & allTown : allTowns) + for (auto & allTown : allTowns) towns.push_back(allTown); if (adventureInt) @@ -1518,7 +1518,7 @@ void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const C void CPlayerInterface::waitWhileDialog(bool unlockPim /*= true*/) { - if(GH.amIGuiThread()) + if (GH.amIGuiThread()) { logGlobal->warnStream() << "Cannot wait for dialogs in gui thread (deadlock risk)!"; return; @@ -1544,7 +1544,7 @@ void CPlayerInterface::newObject( const CGObjectInstance * obj ) { EVENT_HANDLER_CALLED_BY_CLIENT; //we might have built a boat in shipyard in opened town screen - if(obj->ID == Obj::BOAT + if (obj->ID == Obj::BOAT && LOCPLINT->castleInt && obj->pos-obj->getVisitableOffset() == LOCPLINT->castleInt->town->bestLocation()) { @@ -1559,7 +1559,7 @@ void CPlayerInterface::centerView (int3 pos, int focusTime) waitWhileDialog(); CCS->curh->hide(); adventureInt->centerOn (pos); - if(focusTime) + if (focusTime) { GH.totalRedraw(); { @@ -1584,7 +1584,7 @@ void CPlayerInterface::objectRemoved( const CGObjectInstance *obj ) CCS->soundh->playSound(soundBase::KillFade); } } - if(obj->ID == Obj::HERO && obj->tempOwner == playerID) + if (obj->ID == Obj::HERO && obj->tempOwner == playerID) { const CGHeroInstance *h = static_cast(obj); heroKilled(h); @@ -1612,11 +1612,11 @@ void CPlayerInterface::update() boost::shared_lock gsLock(cb->getGsMutex()); // While mutexes were locked away we may be have stopped being the active interface - if(LOCPLINT != this) + if (LOCPLINT != this) return; //if there are any waiting dialogs, show them - if((howManyPeople <= 1 || makingTurn) && !dialogs.empty() && !showingDialog->get()) + if ((howManyPeople <= 1 || makingTurn) && !dialogs.empty() && !showingDialog->get()) { showingDialog->set(true); GH.pushInt(dialogs.front()); @@ -1624,7 +1624,7 @@ void CPlayerInterface::update() } //in some conditions we may receive calls before selection is initialized - we must ignore them - if(adventureInt && !adventureInt->selection && GH.topInt() == adventureInt) + if (adventureInt && !adventureInt->selection && GH.topInt() == adventureInt) { return; } @@ -1633,7 +1633,7 @@ void CPlayerInterface::update() GH.updateTime(); GH.handleEvents(); - if(adventureInt && !adventureInt->isActive() && adventureInt->scrollingDir) //player forces map scrolling though interface is disabled + if (adventureInt && !adventureInt->isActive() && adventureInt->scrollingDir) //player forces map scrolling though interface is disabled GH.totalRedraw(); else GH.simpleRedraw(); @@ -1648,31 +1648,31 @@ int CPlayerInterface::getLastIndex( std::string namePrefix) std::map dates; //save number => datestamp const directory_iterator enddir; - if(!exists(gamesDir)) + if (!exists(gamesDir)) create_directory(gamesDir); else for (directory_iterator dir(gamesDir); dir != enddir; ++dir) { - if(is_regular(dir->status())) + if (is_regular(dir->status())) { std::string name = dir->path().filename().string(); - if(starts_with(name, namePrefix) && ends_with(name, ".vcgm1")) + if (starts_with(name, namePrefix) && ends_with(name, ".vcgm1")) { char nr = name[namePrefix.size()]; - if(std::isdigit(nr)) + if (std::isdigit(nr)) dates[last_write_time(dir->path())] = boost::lexical_cast(nr); } } } - if(!dates.empty()) + if (!dates.empty()) return (--dates.end())->second; //return latest file number return 0; } void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroInstance * ho, const int3 &hp ) { - if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl + if (details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl { //ho->moveDir = 1; ho->isStanding = false; @@ -1700,7 +1700,7 @@ void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroIns std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), objectBlitOrderSorter); } - else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t + else if (details.end.x == details.start.x && details.end.y+1 == details.start.y) //t { //ho->moveDir = 2; ho->isStanding = false; @@ -1720,7 +1720,7 @@ void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroIns std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), objectBlitOrderSorter); std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), objectBlitOrderSorter); } - else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr + else if (details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr { //ho->moveDir = 3; ho->isStanding = false; @@ -1748,7 +1748,7 @@ void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroIns std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), objectBlitOrderSorter); } - else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r + else if (details.end.x-1 == details.start.x && details.end.y == details.start.y) //r { //ho->moveDir = 4; ho->isStanding = false; @@ -1766,7 +1766,7 @@ void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroIns std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), objectBlitOrderSorter); } - else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br + else if (details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br { //ho->moveDir = 5; ho->isStanding = false; @@ -1794,7 +1794,7 @@ void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroIns std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), objectBlitOrderSorter); std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.end(), objectBlitOrderSorter); } - else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b + else if (details.end.x == details.start.x && details.end.y-1 == details.start.y) //b { //ho->moveDir = 6; ho->isStanding = false; @@ -1814,7 +1814,7 @@ void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroIns std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), objectBlitOrderSorter); std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), objectBlitOrderSorter); } - else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl + else if (details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl { //ho->moveDir = 7; ho->isStanding = false; @@ -1842,7 +1842,7 @@ void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroIns std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), objectBlitOrderSorter); std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), objectBlitOrderSorter); } - else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l + else if (details.end.x+1 == details.start.x && details.end.y == details.start.y) //l { //ho->moveDir = 8; ho->isStanding = false; @@ -1864,7 +1864,7 @@ void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroIns void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const int3 &hp, const CGHeroInstance * ho ) { - if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl + if (details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl { //setting advmap shift adventureInt->terrain.moveX = i-32; @@ -1885,7 +1885,7 @@ void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id); subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id); } - else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t + else if (details.end.x == details.start.x && details.end.y+1 == details.start.y) //t { //setting advmap shift adventureInt->terrain.moveY = i-32; @@ -1902,7 +1902,7 @@ void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id); subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id); } - else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr + else if (details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr { //setting advmap shift adventureInt->terrain.moveX = -i+32; @@ -1923,7 +1923,7 @@ void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id); subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id); } - else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r + else if (details.end.x-1 == details.start.x && details.end.y == details.start.y) //r { //setting advmap shift adventureInt->terrain.moveX = -i+32; @@ -1938,7 +1938,7 @@ void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id); subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id); } - else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br + else if (details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br { //setting advmap shift @@ -1960,7 +1960,7 @@ void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id); subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id); } - else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b + else if (details.end.x == details.start.x && details.end.y-1 == details.start.y) //b { //setting advmap shift adventureInt->terrain.moveY = -i+32; @@ -1977,7 +1977,7 @@ void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id); subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id); } - else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl + else if (details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl { //setting advmap shift adventureInt->terrain.moveX = i-32; @@ -1998,7 +1998,7 @@ void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id); subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id); } - else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l + else if (details.end.x+1 == details.start.x && details.end.y == details.start.y) //l { //setting advmap shift adventureInt->terrain.moveX = i-32; @@ -2019,7 +2019,7 @@ void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &h { adventureInt->terrain.moveX = adventureInt->terrain.moveY = 0; - if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl + if (details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl { delObjRect(hp.x, hp.y-2, hp.z, ho->id); delObjRect(hp.x, hp.y-1, hp.z, ho->id); @@ -2028,13 +2028,13 @@ void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &h delObjRect(hp.x-2, hp.y, hp.z, ho->id); delObjRect(hp.x-3, hp.y, hp.z, ho->id); } - else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t + else if (details.end.x == details.start.x && details.end.y+1 == details.start.y) //t { delObjRect(hp.x, hp.y, hp.z, ho->id); delObjRect(hp.x-1, hp.y, hp.z, ho->id); delObjRect(hp.x-2, hp.y, hp.z, ho->id); } - else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr + else if (details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr { delObjRect(hp.x-2, hp.y-2, hp.z, ho->id); delObjRect(hp.x-2, hp.y-1, hp.z, ho->id); @@ -2043,12 +2043,12 @@ void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &h delObjRect(hp.x-1, hp.y, hp.z, ho->id); delObjRect(hp.x-2, hp.y, hp.z, ho->id); } - else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r + else if (details.end.x-1 == details.start.x && details.end.y == details.start.y) //r { delObjRect(hp.x-2, hp.y-1, hp.z, ho->id); delObjRect(hp.x-2, hp.y, hp.z, ho->id); } - else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br + else if (details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br { delObjRect(hp.x-2, hp.y+1, hp.z, ho->id); delObjRect(hp.x-2, hp.y, hp.z, ho->id); @@ -2057,13 +2057,13 @@ void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &h delObjRect(hp.x-1, hp.y-1, hp.z, ho->id); delObjRect(hp.x-2, hp.y-1, hp.z, ho->id); } - else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b + else if (details.end.x == details.start.x && details.end.y-1 == details.start.y) //b { delObjRect(hp.x, hp.y-1, hp.z, ho->id); delObjRect(hp.x-1, hp.y-1, hp.z, ho->id); delObjRect(hp.x-2, hp.y-1, hp.z, ho->id); } - else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl + else if (details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl { delObjRect(hp.x, hp.y-1, hp.z, ho->id); delObjRect(hp.x-1, hp.y-1, hp.z, ho->id); @@ -2072,7 +2072,7 @@ void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &h delObjRect(hp.x, hp.y, hp.z, ho->id); delObjRect(hp.x, hp.y+1, hp.z, ho->id); } - else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l + else if (details.end.x+1 == details.start.x && details.end.y == details.start.y) //l { delObjRect(hp.x, hp.y-1, hp.z, ho->id); delObjRect(hp.x, hp.y, hp.z, ho->id); @@ -2101,12 +2101,12 @@ void CPlayerInterface::gameOver(PlayerColor player, const EVictoryLossCheckResul { EVENT_HANDLER_CALLED_BY_CLIENT; - if(player == playerID) + if (player == playerID) { - if(victoryLossCheckResult.loss()) + if (victoryLossCheckResult.loss()) showInfoDialog(CGI->generaltexth->allTexts[95]); - if(LOCPLINT == this) + if (LOCPLINT == this) { GH.curInt = this; //waiting for dialogs requires this to get events waitForAllDialogs(); //wait till all dialogs are displayed and closed @@ -2114,42 +2114,42 @@ void CPlayerInterface::gameOver(PlayerColor player, const EVictoryLossCheckResul --howManyPeople; - if(howManyPeople == 0) //all human players eliminated + if (howManyPeople == 0) //all human players eliminated { - if(adventureInt) + if (adventureInt) { GH.terminate_cond.setn(true); adventureInt->deactivate(); - if(GH.topInt() == adventureInt) + if (GH.topInt() == adventureInt) GH.popInt(adventureInt); delete adventureInt; adventureInt = nullptr; } } - if(cb->getStartInfo()->mode == StartInfo::CAMPAIGN) + if (cb->getStartInfo()->mode == StartInfo::CAMPAIGN) { // if you lose the campaign go back to the main menu // campaign wins are handled in proposeNextMission - if(victoryLossCheckResult.loss()) requestReturningToMainMenu(); + if (victoryLossCheckResult.loss()) requestReturningToMainMenu(); } else { - if(howManyPeople == 0) //all human players eliminated + if (howManyPeople == 0) //all human players eliminated { requestReturningToMainMenu(); } - else if(victoryLossCheckResult.victory() && LOCPLINT == this) // end game if current human player has won + else if (victoryLossCheckResult.victory() && LOCPLINT == this) // end game if current human player has won { requestReturningToMainMenu(); } } - if(GH.curInt == this) GH.curInt = nullptr; + if (GH.curInt == this) GH.curInt = nullptr; } else { - if(victoryLossCheckResult.loss() && cb->getPlayerStatus(playerID) == EPlayerStatus::INGAME) //enemy has lost + if (victoryLossCheckResult.loss() && cb->getPlayerStatus(playerID) == EPlayerStatus::INGAME) //enemy has lost { std::string str = victoryLossCheckResult.messageToSelf; boost::algorithm::replace_first(str, "%s", CGI->generaltexth->capColors[player.getNum()]); @@ -2189,7 +2189,7 @@ void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellI } const CSpell * spell = CGI->spellh->objects[spellID]; - if(spellID == SpellID::VIEW_EARTH) + if (spellID == SpellID::VIEW_EARTH) { //TODO: implement on server side int level = caster->getSpellSchoolLevel(spell); @@ -2203,7 +2203,7 @@ void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellI void CPlayerInterface::eraseCurrentPathOf( const CGHeroInstance * ho, bool checkForExistanceOfPath /*= true */ ) { - if(checkForExistanceOfPath) + if (checkForExistanceOfPath) { assert(vstd::contains(paths, ho)); } @@ -2221,16 +2221,16 @@ void CPlayerInterface::eraseCurrentPathOf( const CGHeroInstance * ho, bool check void CPlayerInterface::removeLastNodeFromPath(const CGHeroInstance *ho) { adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1); - if(adventureInt->terrain.currentPath->nodes.size() < 2) //if it was the last one, remove entire path and path with only one tile is not a real path + if (adventureInt->terrain.currentPath->nodes.size() < 2) //if it was the last one, remove entire path and path with only one tile is not a real path eraseCurrentPathOf(ho); } CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h) { - if(vstd::contains(paths,h)) //hero has assigned path + if (vstd::contains(paths,h)) //hero has assigned path { CGPath &path = paths[h]; - if(!path.nodes.size()) + if (!path.nodes.size()) { logGlobal->warnStream() << "Warning: empty path found..."; paths.erase(h); @@ -2239,7 +2239,7 @@ CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h) { assert(h->getPosition(false) == path.startPos()); //update the hero path in case of something has changed on map - if(LOCPLINT->cb->getPathsInfo(h)->getPath(path, path.endPos())) + if (LOCPLINT->cb->getPathsInfo(h)->getPath(path, path.endPos())) return &path; else paths.erase(h); @@ -2252,7 +2252,7 @@ CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h) void CPlayerInterface::acceptTurn() { bool centerView = true; - if(settings["session"]["autoSkip"].Bool()) + if (settings["session"]["autoSkip"].Bool()) { centerView = false; while(CInfoWindow *iw = dynamic_cast(GH.topInt())) @@ -2260,7 +2260,7 @@ void CPlayerInterface::acceptTurn() } waitWhileDialog(); - if(howManyPeople > 1) + if (howManyPeople > 1) adventureInt->startTurn(); adventureInt->heroList.update(); @@ -2279,11 +2279,11 @@ void CPlayerInterface::acceptTurn() } //select first hero if available. - if(heroToSelect != nullptr) + if (heroToSelect != nullptr) { adventureInt->select(heroToSelect, centerView); } - else if(towns.size()) + else if (towns.size()) adventureInt->select(towns.front(), centerView); else adventureInt->select(wanderingHeroes.front()); @@ -2294,16 +2294,16 @@ void CPlayerInterface::acceptTurn() adventureInt->updateNextHero(nullptr); adventureInt->showAll(screen); - if(settings["session"]["autoSkip"].Bool() && !LOCPLINT->shiftPressed()) + if (settings["session"]["autoSkip"].Bool() && !LOCPLINT->shiftPressed()) { - if(CInfoWindow *iw = dynamic_cast(GH.topInt())) + if (CInfoWindow *iw = dynamic_cast(GH.topInt())) iw->close(); adventureInt->fendTurn(); } // warn player if he has no town - if(cb->howManyTowns() == 0) + if (cb->howManyTowns() == 0) { auto playerColor = *cb->getPlayerID(); @@ -2318,7 +2318,7 @@ void CPlayerInterface::acceptTurn() text.addReplacement(MetaString::COLOR, playerColor.getNum()); text.addReplacement(7 - daysWithoutCastle); } - else if(daysWithoutCastle == 6) + else if (daysWithoutCastle == 6) { text.addTxt(MetaString::ARRAY_TXT,129); //%s, this is your last day to capture a town or you will be banished from this land. text.addReplacement(MetaString::COLOR, playerColor.getNum()); @@ -2333,7 +2333,7 @@ void CPlayerInterface::tryDiggging(const CGHeroInstance *h) std::string hlp; CGI->mh->getTerrainDescr(h->getPosition(false), hlp, false); auto isDiggingPossible = h->diggingStatus(); - if(hlp.length()) + if (hlp.length()) isDiggingPossible = EDiggingStatus::TILE_OCCUPIED; //TODO integrate with canDig int msgToShow = -1; @@ -2354,7 +2354,7 @@ void CPlayerInterface::tryDiggging(const CGHeroInstance *h) assert(0); } - if(msgToShow < 0) + if (msgToShow < 0) cb->dig(h); else showInfoDialog(CGI->generaltexth->allTexts[msgToShow]); @@ -2375,19 +2375,19 @@ void CPlayerInterface::battleNewRoundFirst( int round ) void CPlayerInterface::stopMovement() { - if(stillMoveHero.get() == DURING_MOVE)//if we are in the middle of hero movement + if (stillMoveHero.get() == DURING_MOVE)//if we are in the middle of hero movement stillMoveHero.setn(STOP_MOVE); //after showing dialog movement will be stopped } void CPlayerInterface::showMarketWindow(const IMarket *market, const CGHeroInstance *visitor) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(market->o->ID == Obj::ALTAR_OF_SACRIFICE) + if (market->o->ID == Obj::ALTAR_OF_SACRIFICE) { //EEMarketMode mode = market->availableModes().front(); - if(market->allowsTrade(EMarketMode::ARTIFACT_EXP) && visitor->getAlignment() != EAlignment::EVIL) + if (market->allowsTrade(EMarketMode::ARTIFACT_EXP) && visitor->getAlignment() != EAlignment::EVIL) GH.pushInt(new CAltarWindow(market, visitor, EMarketMode::ARTIFACT_EXP)); - else if(market->allowsTrade(EMarketMode::CREATURE_EXP) && visitor->getAlignment() != EAlignment::GOOD) + else if (market->allowsTrade(EMarketMode::CREATURE_EXP) && visitor->getAlignment() != EAlignment::GOOD) GH.pushInt(new CAltarWindow(market, visitor, EMarketMode::CREATURE_EXP)); } else @@ -2411,7 +2411,7 @@ void CPlayerInterface::showHillFortWindow(const CGObjectInstance *object, const void CPlayerInterface::availableArtifactsChanged(const CGBlackMarket *bm /*= nullptr*/) { EVENT_HANDLER_CALLED_BY_CLIENT; - if(CMarketplaceWindow *cmw = dynamic_cast(GH.topInt())) + if (CMarketplaceWindow *cmw = dynamic_cast(GH.topInt())) cmw->artifactsChanged(false); } @@ -2438,7 +2438,7 @@ void CPlayerInterface::showQuestLog() void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj) { - if(obj->shipyardStatus() != IBoatGenerator::GOOD) + if (obj->shipyardStatus() != IBoatGenerator::GOOD) { MetaString txt; obj->getProblemText(txt); @@ -2483,7 +2483,7 @@ void CPlayerInterface::stacksSwapped(const StackLocation &loc1, const StackLocat std::vector objects; objects.push_back(loc1.army); - if(loc2.army != loc1.army) + if (loc2.army != loc1.army) objects.push_back(loc2.army); garrisonsChanged(objects); @@ -2501,7 +2501,7 @@ void CPlayerInterface::stacksRebalanced(const StackLocation &src, const StackLoc std::vector objects; objects.push_back(src.army); - if(src.army != dst.army) + if (src.army != dst.army) objects.push_back(dst.army); garrisonsChanged(objects); @@ -2510,9 +2510,16 @@ void CPlayerInterface::stacksRebalanced(const StackLocation &src, const StackLoc void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al) { auto hero = dynamic_cast(al.relatedObj()); - if(hero) + if (hero) { - CArtPlace::askToAssemble(hero->getArt(al.slot), al.slot, hero); + auto art = hero->getArt(al.slot); + if (art == nullptr) + { + logGlobal->error("artifact location %d points to nothing", + al.slot.num); + return; + } + CArtPlace::askToAssemble(art, al.slot, hero); } } @@ -2527,10 +2534,10 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al) { EVENT_HANDLER_CALLED_BY_CLIENT; adventureInt->infoBar.showSelection(); - for(IShowActivatable *isa : GH.listInt) + for (IShowActivatable *isa : GH.listInt) { auto artWin = dynamic_cast(isa); - if(artWin) + if (artWin) artWin->artifactRemoved(al); } } @@ -2539,10 +2546,10 @@ void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const Artifact { EVENT_HANDLER_CALLED_BY_CLIENT; adventureInt->infoBar.showSelection(); - for(IShowActivatable *isa : GH.listInt) + for (IShowActivatable *isa : GH.listInt) { auto artWin = dynamic_cast(isa); - if(artWin) + if (artWin) artWin->artifactMoved(src, dst); } askToAssembleArtifact(dst); @@ -2552,10 +2559,10 @@ void CPlayerInterface::artifactAssembled(const ArtifactLocation &al) { EVENT_HANDLER_CALLED_BY_CLIENT; adventureInt->infoBar.showSelection(); - for(IShowActivatable *isa : GH.listInt) + for (IShowActivatable *isa : GH.listInt) { auto artWin = dynamic_cast(isa); - if(artWin) + if (artWin) artWin->artifactAssembled(al); } } @@ -2564,10 +2571,10 @@ void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al) { EVENT_HANDLER_CALLED_BY_CLIENT; adventureInt->infoBar.showSelection(); - for(IShowActivatable *isa : GH.listInt) + for (IShowActivatable *isa : GH.listInt) { auto artWin = dynamic_cast(isa); - if(artWin) + if (artWin) artWin->artifactDisassembled(al); } } @@ -2587,12 +2594,12 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player) GH.popInts(1); } - if(howManyPeople == 1) + if (howManyPeople == 1) { GH.curInt = this; adventureInt->startTurn(); } - if(player != playerID && this == LOCPLINT) + if (player != playerID && this == LOCPLINT) { waitWhileDialog(); adventureInt->aiTurnStarted(); @@ -2622,13 +2629,13 @@ CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting() bool CPlayerInterface::capturedAllEvents() { - if(duringMovement) + if (duringMovement) { //just inform that we are capturing events. they will be processed by heroMoved() in client thread. return true; } - if(ignoreEvents) + if (ignoreEvents) { boost::unique_lock un(eventsM); while(!events.empty()) @@ -2644,7 +2651,7 @@ bool CPlayerInterface::capturedAllEvents() void CPlayerInterface::setMovementStatus(bool value) { duringMovement = value; - if(value) + if (value) { CCS->curh->hide(); } @@ -2664,7 +2671,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path) auto isTeleportAction = [&](CGPathNode::ENodeAction action) -> bool { - if(action != CGPathNode::TELEPORT_NORMAL && + if (action != CGPathNode::TELEPORT_NORMAL && action != CGPathNode::TELEPORT_BLOCKING_VISIT && action != CGPathNode::TELEPORT_BATTLE) { @@ -2676,9 +2683,9 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path) auto getDestTeleportObj = [&](const CGObjectInstance * currentObject, const CGObjectInstance * nextObjectTop, const CGObjectInstance * nextObject) -> const CGObjectInstance * { - if(CGTeleport::isConnected(currentObject, nextObjectTop)) + if (CGTeleport::isConnected(currentObject, nextObjectTop)) return nextObjectTop; - if(nextObjectTop && nextObjectTop->ID == Obj::HERO && + if (nextObjectTop && nextObjectTop->ID == Obj::HERO && CGTeleport::isConnected(currentObject, nextObject)) { return nextObject; @@ -2705,16 +2712,16 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path) auto canStop = [&](CGPathNode * node) -> bool { - if(node->layer == EPathfindingLayer::LAND || node->layer == EPathfindingLayer::SAIL) + if (node->layer == EPathfindingLayer::LAND || node->layer == EPathfindingLayer::SAIL) return true; - if(node->accessible == CGPathNode::ACCESSIBLE) + if (node->accessible == CGPathNode::ACCESSIBLE) return true; return false; }; - for(i=path.nodes.size()-1; i>0 && (stillMoveHero.data == CONTINUE_MOVE || !canStop(&path.nodes[i])); i--) + for (i=path.nodes.size()-1; i>0 && (stillMoveHero.data == CONTINUE_MOVE || !canStop(&path.nodes[i])); i--) { int3 currentCoord = path.nodes[i].coord; int3 nextCoord = path.nodes[i-1].coord; @@ -2723,13 +2730,13 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path) auto nextObjectTop = getObj(nextCoord, false); auto nextObject = getObj(nextCoord, true); auto destTeleportObj = getDestTeleportObj(currentObject, nextObjectTop, nextObject); - if(isTeleportAction(path.nodes[i-1].action) && destTeleportObj != nullptr) + if (isTeleportAction(path.nodes[i-1].action) && destTeleportObj != nullptr) { CCS->soundh->stopSound(sh); destinationTeleport = destTeleportObj->id; destinationTeleportPos = nextCoord; doMovement(h->pos, false); - if(path.nodes[i-1].action == CGPathNode::TELEPORT_BLOCKING_VISIT) + if (path.nodes[i-1].action == CGPathNode::TELEPORT_BLOCKING_VISIT) { destinationTeleport = ObjectInstanceID(); destinationTeleportPos = int3(-1); @@ -2738,7 +2745,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path) continue; } - if(path.nodes[i-1].turns) + if (path.nodes[i-1].turns) { //stop sending move requests if the next node can't be reached at the current turn (hero exhausted his move points) stillMoveHero.data = STOP_MOVE; break; @@ -2747,12 +2754,12 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path) // Start a new sound for the hero movement or let the existing one carry on. #if 0 // TODO - if(hero is flying && sh == -1) + if (hero is flying && sh == -1) sh = CCS->soundh->playSound(soundBase::horseFlying, -1); #endif { newTerrain = cb->getTile(CGHeroInstance::convertPosition(currentCoord, false))->terType; - if(newTerrain != currentTerrain) + if (newTerrain != currentTerrain) { CCS->soundh->stopSound(sh); sh = CCS->soundh->playSound(CCS->soundh->horseSounds[newTerrain], -1); @@ -2765,20 +2772,20 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path) logGlobal->traceStream() << "Requesting hero movement to " << endpos; bool useTransit = false; - if((i-2 >= 0) // Check there is node after next one; otherwise transit is pointless + if ((i-2 >= 0) // Check there is node after next one; otherwise transit is pointless && (CGTeleport::isConnected(nextObjectTop, getObj(path.nodes[i-2].coord, false)) || CGTeleport::isTeleport(nextObjectTop))) { // Hero should be able to go through object if it's allow transit useTransit = true; } - else if(path.nodes[i-1].layer == EPathfindingLayer::AIR) + else if (path.nodes[i-1].layer == EPathfindingLayer::AIR) useTransit = true; doMovement(endpos, useTransit); logGlobal->traceStream() << "Resuming " << __FUNCTION__; bool guarded = cb->isInTheMap(cb->getGuardingCreaturePosition(endpos - int3(1, 0, 0))); - if((!useTransit && guarded) || showingDialog->get() == true) // Abort movement if a guard was fought or there is a dialog to display (Mantis #1136) + if ((!useTransit && guarded) || showingDialog->get() == true) // Abort movement if a guard was fought or there is a dialog to display (Mantis #1136) break; } @@ -2786,12 +2793,12 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path) } //Update cursor so icon can change if needed when it reappears; doesn;'t apply if a dialog box pops up at the end of the movement - if(!showingDialog->get()) + if (!showingDialog->get()) GH.fakeMouseMove(); //todo: this should be in main thread - if(adventureInt) + if (adventureInt) { // (i == 0) means hero went through all the path adventureInt->updateMoveHero(h, (i != 0)); diff --git a/client/widgets/CArtifactHolder.cpp b/client/widgets/CArtifactHolder.cpp index 8284b6b67..f9bebc3fd 100644 --- a/client/widgets/CArtifactHolder.cpp +++ b/client/widgets/CArtifactHolder.cpp @@ -214,6 +214,8 @@ void CArtPlace::clickLeft(tribool down, bool previousState) bool CArtPlace::askToAssemble(const CArtifactInstance *art, ArtifactPosition slot, const CGHeroInstance *hero) { + assert(art != nullptr); + assert(hero != nullptr); std::vector assemblyPossibilities = art->assemblyPossibilities(hero); // If the artifact can be assembled, display dialog.