diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index ab6d49219..8669716af 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -563,24 +563,24 @@ void CBattleInterface::deactivate() void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key) { - if (key.keysym.sym == SDLK_q && key.state == SDL_PRESSED) + if(key.keysym.sym == SDLK_q && key.state == SDL_PRESSED) { - if (settings["battle"]["showQueue"].Bool()) //hide queue + if(settings["battle"]["showQueue"].Bool()) //hide queue hideQueue(); else showQueue(); } - else if (key.keysym.sym == SDLK_f && key.state == SDL_PRESSED) + else if(key.keysym.sym == SDLK_f && key.state == SDL_PRESSED) { enterCreatureCastingMode(); } - else if (key.keysym.sym == SDLK_ESCAPE) + else if(key.keysym.sym == SDLK_ESCAPE) { if(!battleActionsStarted) CCS->soundh->stopSound(battleIntroSoundChannel); else - endCastingSpell(); + endCastingSpell(); } } void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) @@ -788,14 +788,14 @@ void CBattleInterface::bOptionsf() void CBattleInterface::bSurrenderf() { - if (spellDestSelectMode) //we are casting a spell + if(spellDestSelectMode) //we are casting a spell return; int cost = curInt->cb->battleGetSurrenderCost(); - if (cost >= 0) + if(cost >= 0) { std::string enemyHeroName = curInt->cb->battleGetEnemyHero().name; - if (enemyHeroName.empty()) + if(enemyHeroName.empty()) { logGlobal->warn("Surrender performed without enemy hero, should not happen!"); enemyHeroName = "#ENEMY#"; @@ -1462,14 +1462,9 @@ void CBattleInterface::displayEffect(ui32 effect, BattleHex destTile) addNewAnim(new CEffectAnimation(this, customAnim, destTile)); } -void CBattleInterface::displaySpellCast(SpellID spellID, BattleHex destinationTile) +void CBattleInterface::displaySpellAnimationQueue(const CSpell::TAnimationQueue & q, BattleHex destinationTile) { - const CSpell * spell = spellID.toSpell(); - - if(spell == nullptr) - return; - - for(const CSpell::TAnimation & animation : spell->animationInfo.cast) + for(const CSpell::TAnimation & animation : q) { if(animation.pause > 0) addNewAnim(new CDummyAnimation(this, animation.pause)); @@ -1478,37 +1473,28 @@ void CBattleInterface::displaySpellCast(SpellID spellID, BattleHex destinationTi } } +void CBattleInterface::displaySpellCast(SpellID spellID, BattleHex destinationTile) +{ + const CSpell * spell = spellID.toSpell(); + + if(spell) + displaySpellAnimationQueue(spell->animationInfo.cast, destinationTile); +} + void CBattleInterface::displaySpellEffect(SpellID spellID, BattleHex destinationTile) { const CSpell *spell = spellID.toSpell(); - if(spell == nullptr) - return; - - for(const CSpell::TAnimation & animation : spell->animationInfo.affect) - { - if(animation.pause > 0) - addNewAnim(new CDummyAnimation(this, animation.pause)); - else - addNewAnim(new CEffectAnimation(this, animation.resourceName, destinationTile, false, animation.verticalPosition == VerticalPosition::BOTTOM)); - - } + if(spell) + displaySpellAnimationQueue(spell->animationInfo.affect, destinationTile); } void CBattleInterface::displaySpellHit(SpellID spellID, BattleHex destinationTile) { const CSpell * spell = spellID.toSpell(); - if(spell == nullptr) - return; - - for(const CSpell::TAnimation & animation : spell->animationInfo.hit) - { - if(animation.pause > 0) - addNewAnim(new CDummyAnimation(this, animation.pause)); - else - addNewAnim(new CEffectAnimation(this, animation.resourceName, destinationTile, false, animation.verticalPosition == VerticalPosition::BOTTOM)); - } + if(spell) + displaySpellAnimationQueue(spell->animationInfo.hit, destinationTile); } void CBattleInterface::battleTriggerEffect(const BattleTriggerEffect & bte) @@ -1704,13 +1690,12 @@ void CBattleInterface::enterCreatureCastingMode() spells::Target target; target.emplace_back(); - spells::BattleCast cast(curInt->cb.get(), caster, spells::Mode::CREATURE_ACTIVE, spell); auto m = spell->battleMechanics(&cast); spells::detail::ProblemImpl ignored; - const bool isCastingPossible = m->canBeCastAt(ignored, target); + const bool isCastingPossible = m->canBeCastAt(target, ignored); if (isCastingPossible) { @@ -1762,7 +1747,7 @@ void CBattleInterface::reorderPossibleActionsPriority(const CStack * stack, Mous case PossiblePlayerBattleAction::OBSTACLE: if(!stack->hasBonusOfType(Bonus::NO_SPELLCAST_BY_DEFAULT) && context == MouseHoveredHexContext::OCCUPIED_HEX) return 1; - else + else return 100;//bottom priority break; case PossiblePlayerBattleAction::RANDOM_GENIE_SPELL: @@ -2543,7 +2528,7 @@ bool CBattleInterface::isCastingPossibleHere(const CStack *sactive, const CStack auto m = sp->battleMechanics(&cast); spells::detail::ProblemImpl problem; //todo: display problem in status bar - isCastingPossible = m->canBeCastAt(problem, target); + isCastingPossible = m->canBeCastAt(target, problem); } } else @@ -3022,7 +3007,7 @@ void CBattleInterface::show(SDL_Surface *to) showProjectiles(to); if(battleActionsStarted) - updateBattleAnimations(); + updateBattleAnimations(); SDL_SetClipRect(to, &buf); //restoring previous clip_rect diff --git a/client/battle/CBattleInterface.h b/client/battle/CBattleInterface.h index 79ace75df..a6b933c2b 100644 --- a/client/battle/CBattleInterface.h +++ b/client/battle/CBattleInterface.h @@ -358,6 +358,7 @@ public: void displayEffect(ui32 effect, BattleHex destTile); //displays custom effect on the battlefield + void displaySpellAnimationQueue(const CSpell::TAnimationQueue & q, BattleHex destinationTile); void displaySpellCast(SpellID spellID, BattleHex destinationTile); //displays spell`s cast animation void displaySpellEffect(SpellID spellID, BattleHex destinationTile); //displays spell`s affected animation void displaySpellHit(SpellID spellID, BattleHex destinationTile); //displays spell`s affected animation diff --git a/client/widgets/CGarrisonInt.cpp b/client/widgets/CGarrisonInt.cpp index 7831d527c..ba3a08e14 100644 --- a/client/widgets/CGarrisonInt.cpp +++ b/client/widgets/CGarrisonInt.cpp @@ -368,11 +368,11 @@ void CGarrisonSlot::update() } CGarrisonSlot::CGarrisonSlot(CGarrisonInt * Owner, int x, int y, SlotID IID, CGarrisonSlot::EGarrisonType Upg, const CStackInstance * creature_) - : ID(IID), - owner(Owner), - myStack(creature_), - creature(creature_ ? creature_->type : nullptr), - upg(Upg) + : ID(IID), + owner(Owner), + myStack(creature_), + creature(creature_ ? creature_->type : nullptr), + upg(Upg) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -381,8 +381,8 @@ CGarrisonSlot::CGarrisonSlot(CGarrisonInt * Owner, int x, int y, SlotID IID, CGa std::string imgName = owner->smallIcons ? "cprsmall" : "TWCRPORT"; - creatureImage = std::make_shared(imgName, 0); - creatureImage->disable(); + creatureImage = std::make_shared(imgName, 0); + creatureImage->disable(); selectionImage = std::make_shared(imgName, 1); selectionImage->disable(); diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 88843f536..c37c8e2af 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -111,12 +111,14 @@ void CBuildingRect::hover(bool on) void CBuildingRect::clickLeft(tribool down, bool previousState) { - if( previousState && getBuilding() && area && !down && (parent->selectedBuilding==this)) - if (!CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image + if(previousState && getBuilding() && area && !down && (parent->selectedBuilding==this)) + { + if(!CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y)) //inside building image { auto building = getBuilding(); parent->buildingClicked(building->bid, building->subId, building->upgrade); -} + } + } } void CBuildingRect::clickRight(tribool down, bool previousState) @@ -606,8 +608,7 @@ void CCastleBuildings::recreate() const CStructure * toAdd = *boost::max_element(entry.second, [=](const CStructure * a, const CStructure * b) { - return build->getDistance(a->building->bid) - < build->getDistance(b->building->bid); + return build->getDistance(a->building->bid) < build->getDistance(b->building->bid); }); buildings.push_back(std::make_shared(this, town, toAdd)); @@ -866,8 +867,8 @@ void CCastleBuildings::enterFountain(const BuildingID & building, BuildingSubID: boost::algorithm::replace_first(hasProduced, "%s", buildingName); } - bool isMysticPondOrItsUpgrade = subID == BuildingSubID::MYSTIC_POND - || (upgrades != BuildingID::NONE + bool isMysticPondOrItsUpgrade = subID == BuildingSubID::MYSTIC_POND + || (upgrades != BuildingID::NONE && town->town->buildings.find(BuildingID(upgrades))->second->subId == BuildingSubID::MYSTIC_POND); if(upgrades != BuildingID::NONE) @@ -880,9 +881,9 @@ void CCastleBuildings::enterFountain(const BuildingID & building, BuildingSubID: else //Mystic Pond produced something; { descr += "\n\n" + hasProduced; - boost::algorithm::replace_first(descr,"%s",CGI->generaltexth->restypes[town->bonusValue.first]); - boost::algorithm::replace_first(descr,"%d",boost::lexical_cast(town->bonusValue.second)); - } + boost::algorithm::replace_first(descr,"%s",CGI->generaltexth->restypes[town->bonusValue.first]); + boost::algorithm::replace_first(descr,"%d",boost::lexical_cast(town->bonusValue.second)); + } } LOCPLINT->showInfoDialog(descr, comps); } diff --git a/include/vcmi/events/SubscriptionRegistry.h b/include/vcmi/events/SubscriptionRegistry.h index f508207a5..01af2876f 100644 --- a/include/vcmi/events/SubscriptionRegistry.h +++ b/include/vcmi/events/SubscriptionRegistry.h @@ -32,20 +32,20 @@ public: using PostHandler = std::function; using BusTag = const void *; - std::unique_ptr subscribeBefore(BusTag tag, PreHandler && cb) + std::unique_ptr subscribeBefore(BusTag tag, PreHandler && handler) { boost::unique_lock lock(mutex); - auto storage = std::make_shared(std::move(cb)); + auto storage = std::make_shared(std::move(handler)); preHandlers[tag].push_back(storage); return make_unique(tag, storage); } - std::unique_ptr subscribeAfter(BusTag tag, PostHandler && cb) + std::unique_ptr subscribeAfter(BusTag tag, PostHandler && handler) { boost::unique_lock lock(mutex); - auto storage = std::make_shared(std::move(cb)); + auto storage = std::make_shared(std::move(handler)); postHandlers[tag].push_back(storage); return make_unique(tag, storage); } @@ -84,18 +84,18 @@ private: class HandlerStorage { public: - explicit HandlerStorage(T && cb_) - : cb(cb_) + explicit HandlerStorage(T && handler_) + : handler(handler_) { } STRONG_INLINE void operator()(E & event) { - cb(event); + handler(event); } private: - T cb; + T handler; }; using PreHandlerStorage = HandlerStorage; @@ -104,8 +104,8 @@ private: class PreSubscription : public EventSubscription { public: - PreSubscription(BusTag tag_, std::shared_ptr cb_) - : cb(cb_), + PreSubscription(BusTag tag_, std::shared_ptr handler_) + : handler(handler_), tag(tag_) { } @@ -113,18 +113,18 @@ private: virtual ~PreSubscription() { auto registry = E::getRegistry(); - registry->unsubscribe(tag, cb, registry->preHandlers); + registry->unsubscribe(tag, handler, registry->preHandlers); } private: BusTag tag; - std::shared_ptr cb; + std::shared_ptr handler; }; class PostSubscription : public EventSubscription { public: - PostSubscription(BusTag tag_, std::shared_ptr cb_) - : cb(cb_), + PostSubscription(BusTag tag_, std::shared_ptr handler_) + : handler(handler_), tag(tag_) { } @@ -132,11 +132,11 @@ private: virtual ~PostSubscription() { auto registry = E::getRegistry(); - registry->unsubscribe(tag, cb, registry->postHandlers); + registry->unsubscribe(tag, handler, registry->postHandlers); } private: BusTag tag; - std::shared_ptr cb; + std::shared_ptr handler; }; boost::shared_mutex mutex; diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 7320dfc7d..7045245ed 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -697,7 +697,7 @@ bool CModHandler::checkDependencies(const std::vector & input) const for(const TModID & dep : mod.dependencies) { - if (!vstd::contains(input, dep)) + if(!vstd::contains(input, dep)) { logMod->error("Error: Mod %s requires missing %s!", mod.name, dep); return false; @@ -706,14 +706,14 @@ bool CModHandler::checkDependencies(const std::vector & input) const for(const TModID & conflicting : mod.conflicts) { - if (vstd::contains(input, conflicting)) + if(vstd::contains(input, conflicting)) { logMod->error("Error: Mod %s conflicts with %s!", mod.name, allMods.at(conflicting).name); return false; } } - if (hasCircularDependency(id)) + if(hasCircularDependency(id)) return false; } return true; @@ -732,7 +732,7 @@ std::vector CModHandler::resolveDependencies(std::vector modsT { logMod->error("Mod '%s' will not work: it depends on mod '%s', which is not installed.", mod.name, dependency); res = false; //continue iterations, since we should show all errors for the current mod. - } + } } return res; }; @@ -745,19 +745,19 @@ std::vector CModHandler::resolveDependencies(std::vector modsT brokenMods.push_back(mod); } if(!brokenMods.empty()) - { + { vstd::erase_if(modsToResolve, [&](TModID mid) { return brokenMods.end() != std::find(brokenMods.begin(), brokenMods.end(), mid); }); brokenMods.clear(); continue; - } - break; } + break; + } boost::range::sort(modsToResolve); return modsToResolve; - } +} std::vector CModHandler::getModList(std::string path) { diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 902a84c28..574bd4dbd 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -560,29 +560,31 @@ R CTownHandler::getMappedValue(const K key, const R defval, const std::map template R CTownHandler::getMappedValue(const JsonNode & node, const R defval, const std::map & map, bool required) - { +{ if(!node.isNull() && node.getType() == JsonNode::JsonType::DATA_STRING) return getMappedValue(node.String(), defval, map, required); return defval; } void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building) - { +{ std::shared_ptr b; static TPropagatorPtr playerPropagator = std::make_shared(CBonusSystemNode::ENodeTypes::PLAYER); if(building->subId == BuildingSubID::NONE) - { + { if(building->bid == BuildingID::TAVERN) - b = createBonus(building, Bonus::MORALE, +1); - else if(building->bid == BuildingID::GRAIL - && building->town->faction != nullptr - && boost::algorithm::ends_with(building->town->faction->identifier, ":cove")) { - static TPropagatorPtr allCreaturesPropagator(new CPropagatorNodeType(CBonusSystemNode::ENodeTypes::ALL_CREATURES)); - static auto factionLimiter = std::make_shared(building->town->faction->index); - b = createBonus(building, Bonus::NO_TERRAIN_PENALTY, 0, allCreaturesPropagator); - b->addLimiter(factionLimiter); + b = createBonus(building, Bonus::MORALE, +1); + } + else if(building->bid == BuildingID::GRAIL + && building->town->faction != nullptr + && boost::algorithm::ends_with(building->town->faction->identifier, ":cove")) + { + static TPropagatorPtr allCreaturesPropagator(new CPropagatorNodeType(CBonusSystemNode::ENodeTypes::ALL_CREATURES)); + static auto factionLimiter = std::make_shared(building->town->faction->index); + b = createBonus(building, Bonus::NO_TERRAIN_PENALTY, 0, allCreaturesPropagator); + b->addLimiter(factionLimiter); } } else diff --git a/lib/ScriptHandler.cpp b/lib/ScriptHandler.cpp index fe6da0f31..6536d2d7f 100644 --- a/lib/ScriptHandler.cpp +++ b/lib/ScriptHandler.cpp @@ -121,7 +121,7 @@ void ScriptImpl::resolveHost() else if(sourcePathId.getType() == EResType::LUA) host = owner->lua; else - throw std::runtime_error("Unknown script language in:"+sourcePath); + throw std::runtime_error("Unknown script language in:" + sourcePath); } PoolImpl::PoolImpl(const Environment * ENV) @@ -217,7 +217,8 @@ std::vector ScriptHandler::loadLegacyData(size_t dataSize) return std::vector(); } -ScriptPtr ScriptHandler::loadFromJson(vstd::CLoggerBase * logger, const std::string & scope, const JsonNode & json, const std::string & identifier) const +ScriptPtr ScriptHandler::loadFromJson(vstd::CLoggerBase * logger, const std::string & scope, + const JsonNode & json, const std::string & identifier) const { ScriptPtr ret = std::make_shared(this); diff --git a/lib/battle/CBattleInfoCallback.cpp b/lib/battle/CBattleInfoCallback.cpp index 168950a1d..14789fbb1 100644 --- a/lib/battle/CBattleInfoCallback.cpp +++ b/lib/battle/CBattleInfoCallback.cpp @@ -785,7 +785,7 @@ TDmgRange CBattleInfoCallback::calculateDmgRange(const BattleAttackInfo & info) } if(isAffected) - { + { attackDefenceDifference += SpellID(SpellID::SLAYER).toSpell()->getLevelPower(spLevel); if(info.attacker->hasBonusOfType(Bonus::SPECIAL_PECULIAR_ENCHANT, SpellID::SLAYER)) { @@ -1407,9 +1407,7 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes (const battl { auto st = battleGetUnitByPos(tile, true); if(st && battleMatchOwner(st, attacker)) //only hostile stacks - does it work well with Berserk? - { at.hostileCreaturePositions.insert(tile); - } } } } @@ -1429,44 +1427,42 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes (const battl //friendly stacks can also be damaged by Dragon Breath auto st = battleGetUnitByPos(tile, true); if(st && st != attacker) - { - at.friendlyCreaturePositions.insert(tile); - } + at.friendlyCreaturePositions.insert(tile); } } else if(attacker->hasBonusOfType(Bonus::TWO_HEX_ATTACK_BREATH)) { int pos = BattleHex::mutualPosition(destinationTile, hex); - if (pos > -1) //only adjacent hexes are subject of dragon breath calculation + if(pos > -1) //only adjacent hexes are subject of dragon breath calculation { - std::vector hexes; //only one, in fact - int pseudoVector = destinationTile.hex - hex; - switch(pseudoVector) - { - case 1: - case -1: - BattleHex::checkAndPush(destinationTile.hex + pseudoVector, hexes); - break; - case WN: //17 //left-down or right-down - case -WN: //-17 //left-up or right-up - case WN + 1: //18 //right-down - case -WN + 1: //-16 //right-up - BattleHex::checkAndPush(destinationTile.hex + pseudoVector + (((hex / WN) % 2) ? 1 : -1), hexes); - break; - case WN - 1: //16 //left-down - case -WN - 1: //-18 //left-up - BattleHex::checkAndPush(destinationTile.hex + pseudoVector + (((hex / WN) % 2) ? 1 : 0), hexes); - break; - } - for(BattleHex tile : hexes) - { - //friendly stacks can also be damaged by Dragon Breath + std::vector hexes; //only one, in fact + int pseudoVector = destinationTile.hex - hex; + switch(pseudoVector) + { + case 1: + case -1: + BattleHex::checkAndPush(destinationTile.hex + pseudoVector, hexes); + break; + case WN: //17 //left-down or right-down + case -WN: //-17 //left-up or right-up + case WN + 1: //18 //right-down + case -WN + 1: //-16 //right-up + BattleHex::checkAndPush(destinationTile.hex + pseudoVector + (((hex / WN) % 2) ? 1 : -1), hexes); + break; + case WN - 1: //16 //left-down + case -WN - 1: //-18 //left-up + BattleHex::checkAndPush(destinationTile.hex + pseudoVector + (((hex / WN) % 2) ? 1 : 0), hexes); + break; + } + for(BattleHex tile : hexes) + { + //friendly stacks can also be damaged by Dragon Breath auto st = battleGetUnitByPos(tile, true); - if (st != nullptr) - at.friendlyCreaturePositions.insert(tile); + if(st != nullptr) + at.friendlyCreaturePositions.insert(tile); + } } } - } return at; } diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index 1d5891668..92f0be651 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -850,18 +850,18 @@ void CGTownInstance::updateBonusingBuildings() //update to version 792 //firstly, update subtype for the Bonusing objects, which are already stored in the bonusing list for(auto building : bonusingBuildings) //no garrison bonuses here, only week and visiting bonuses { - switch (this->town->faction->index) + switch(this->town->faction->index) { - case ETownType::CASTLE: - building->setBuildingSubtype(BuildingSubID::STABLES); + case ETownType::CASTLE: + building->setBuildingSubtype(BuildingSubID::STABLES); break; - case ETownType::DUNGEON: + case ETownType::DUNGEON: if(building->getBuildingType() == BuildingID::SPECIAL_2) building->setBuildingSubtype(BuildingSubID::MANA_VORTEX); else if(building->getBuildingType() == BuildingID::SPECIAL_4) building->setBuildingSubtype(BuildingSubID::EXPERIENCE_VISITING_BONUS); - break; + break; case ETownType::TOWER: building->setBuildingSubtype(BuildingSubID::KNOWLEDGE_VISITING_BONUS); @@ -875,10 +875,10 @@ void CGTownInstance::updateBonusingBuildings() //update to version 792 building->setBuildingSubtype(BuildingSubID::SPELL_POWER_VISITING_BONUS); break; - case ETownType::FORTRESS: + case ETownType::FORTRESS: building->setBuildingSubtype(BuildingSubID::DEFENSE_VISITING_BONUS); - break; - } + break; + } } } //secondly, supplement bonusing buildings list and active bonuses; subtypes for these objects are already set in update792 @@ -1264,14 +1264,14 @@ void CGTownInstance::recreateBuildingsBonuses() continue; for(auto bonus : building->buildingBonuses) -{ + { if(bonus->propagator != nullptr && bonus->propagator->getPropagatorType() == ALL_CREATURES) VLC->creh->addBonusForAllCreatures(bonus); else addNewBonus(bonus); + } } } -} void CGTownInstance::setVisitingHero(CGHeroInstance *h) { @@ -1353,11 +1353,11 @@ int CGTownInstance::getTownLevel() const // count all buildings that are not upgrades int level = 0; - for (const auto & bid : builtBuildings) + for(const auto & bid : builtBuildings) { if(town->buildings.at(bid)->upgrade == BuildingID::NONE) level++; -} + } return level; } @@ -1685,7 +1685,7 @@ void COPWBonus::setProperty(ui8 what, ui32 val) void COPWBonus::onHeroVisit (const CGHeroInstance * h) const { ObjectInstanceID heroID = h->id; - if (town->hasBuilt(bID)) + if(town->hasBuilt(bID)) { InfoWindow iw; iw.player = h->tempOwner; @@ -1693,37 +1693,37 @@ void COPWBonus::onHeroVisit (const CGHeroInstance * h) const switch (this->bType) { case BuildingSubID::STABLES: - if (!h->hasBonusFrom(Bonus::OBJECT, Obj::STABLES)) //does not stack with advMap Stables - { - GiveBonus gb; - gb.bonus = Bonus(Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, Bonus::OBJECT, 600, 94, VLC->generaltexth->arraytxt[100]); - gb.id = heroID.getNum(); - cb->giveHeroBonus(&gb); + if(!h->hasBonusFrom(Bonus::OBJECT, Obj::STABLES)) //does not stack with advMap Stables + { + GiveBonus gb; + gb.bonus = Bonus(Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, Bonus::OBJECT, 600, 94, VLC->generaltexth->arraytxt[100]); + gb.id = heroID.getNum(); + cb->giveHeroBonus(&gb); - SetMovePoints mp; - mp.val = 600; - mp.absolute = false; - mp.hid = heroID; - cb->setMovePoints(&mp); + SetMovePoints mp; + mp.val = 600; + mp.absolute = false; + mp.hid = heroID; + cb->setMovePoints(&mp); - iw.text << VLC->generaltexth->allTexts[580]; - cb->showInfoDialog(&iw); - } - break; + iw.text << VLC->generaltexth->allTexts[580]; + cb->showInfoDialog(&iw); + } + break; case BuildingSubID::MANA_VORTEX: - if (visitors.empty()) - { - if (h->mana < h->manaLimit() * 2) + if(visitors.empty()) + { + if(h->mana < h->manaLimit() * 2) cb->setManaPoints (heroID, 2 * h->manaLimit()); - //TODO: investigate line below - //cb->setObjProperty (town->id, ObjProperty::VISITED, true); - iw.text << getVisitingBonusGreeting(); - cb->showInfoDialog(&iw); - //extra visit penalty if hero alredy had double mana points (or even more?!) - town->addHeroToStructureVisitors(h, indexOnTV); - } - break; + //TODO: investigate line below + //cb->setObjProperty (town->id, ObjProperty::VISITED, true); + iw.text << getVisitingBonusGreeting(); + cb->showInfoDialog(&iw); + //extra visit penalty if hero alredy had double mana points (or even more?!) + town->addHeroToStructureVisitors(h, indexOnTV); + } + break; } } } @@ -1750,37 +1750,37 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const InfoWindow iw; PrimarySkill::PrimarySkill what = PrimarySkill::NONE; - switch (bType) + switch(bType) { case BuildingSubID::KNOWLEDGE_VISITING_BONUS: //wall of knowledge - what = PrimarySkill::KNOWLEDGE; - val = 1; - iw.components.push_back (Component(Component::PRIM_SKILL, 3, 1, 0)); - break; + what = PrimarySkill::KNOWLEDGE; + val = 1; + iw.components.push_back(Component(Component::PRIM_SKILL, 3, 1, 0)); + break; case BuildingSubID::SPELL_POWER_VISITING_BONUS: //order of fire - what = PrimarySkill::SPELL_POWER; - val = 1; - iw.components.push_back (Component(Component::PRIM_SKILL, 2, 1, 0)); - break; + what = PrimarySkill::SPELL_POWER; + val = 1; + iw.components.push_back(Component(Component::PRIM_SKILL, 2, 1, 0)); + break; case BuildingSubID::ATTACK_VISITING_BONUS: //hall of Valhalla - what = PrimarySkill::ATTACK; - val = 1; - iw.components.push_back (Component(Component::PRIM_SKILL, 0, 1, 0)); - break; + what = PrimarySkill::ATTACK; + val = 1; + iw.components.push_back(Component(Component::PRIM_SKILL, 0, 1, 0)); + break; case BuildingSubID::EXPERIENCE_VISITING_BONUS: //academy of battle scholars - what = PrimarySkill::EXPERIENCE; + what = PrimarySkill::EXPERIENCE; val = static_cast(h->calculateXp(1000)); - iw.components.push_back (Component(Component::EXPERIENCE, 0, val, 0)); - break; + iw.components.push_back(Component(Component::EXPERIENCE, 0, val, 0)); + break; case BuildingSubID::DEFENSE_VISITING_BONUS: //cage of warlords - what = PrimarySkill::DEFENSE; - val = 1; - iw.components.push_back (Component(Component::PRIM_SKILL, 1, 1, 0)); - break; + what = PrimarySkill::DEFENSE; + val = 1; + iw.components.push_back(Component(Component::PRIM_SKILL, 1, 1, 0)); + break; case BuildingSubID::CUSTOM_VISITING_BONUS: const auto building = town->town->buildings.at(bID); @@ -1788,19 +1788,20 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const { const auto & bonuses = building->onVisitBonuses; applyBonuses(const_cast(h), bonuses); - } - break; + } + break; } + if(what != PrimarySkill::NONE) { - iw.player = cb->getOwner(heroID); - iw.text << getVisitingBonusGreeting(); - cb->showInfoDialog(&iw); - cb->changePrimSkill (cb->getHero(heroID), what, val); - town->addHeroToStructureVisitors(h, indexOnTV); + iw.player = cb->getOwner(heroID); + iw.text << getVisitingBonusGreeting(); + cb->showInfoDialog(&iw); + cb->changePrimSkill (cb->getHero(heroID), what, val); + town->addHeroToStructureVisitors(h, indexOnTV); + } } } -} void CTownBonus::applyBonuses(CGHeroInstance * h, const BonusList & bonuses) const { diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index 2bb8f3336..ab714b35b 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjects/CObjectClassesHandler.cpp @@ -207,11 +207,11 @@ void CObjectClassesHandler::loadObjectEntry(const std::string & identifier, cons return str.compare(obj->subObjects[id]->subTypeName) == 0; }); - if (overrideForce) // DO NOT override mod handlers by default + if(overrideForce) // DO NOT override mod handlers by default { - obj->subObjects[id] = handler; - obj->subIds[convertedId] = id; -} + obj->subObjects[id] = handler; + obj->subIds[convertedId] = id; + } else { logGlobal->warn("Don't override handler %s in object %s(%d)::%s(%d) subTypeName : %s" diff --git a/lib/spells/BattleSpellMechanics.cpp b/lib/spells/BattleSpellMechanics.cpp index ce0e79e56..3ab3fd991 100644 --- a/lib/spells/BattleSpellMechanics.cpp +++ b/lib/spells/BattleSpellMechanics.cpp @@ -203,7 +203,7 @@ bool BattleSpellMechanics::canBeCast(Problem & problem) const return effects->applicable(problem, this); } -bool BattleSpellMechanics::canBeCastAt(Problem & problem, const Target & target) const +bool BattleSpellMechanics::canBeCastAt(const Target & target, Problem & problem) const { if(!canBeCast(problem)) return false; @@ -618,7 +618,7 @@ std::vector BattleSpellMechanics::getPossibleDestinations(size_t in detail::ProblemImpl ingored; - if(canBeCastAt(ingored, tmp)) + if(canBeCastAt(tmp, ingored)) ret.emplace_back(dest); } } diff --git a/lib/spells/BattleSpellMechanics.h b/lib/spells/BattleSpellMechanics.h index 8bd7544fb..d4a792412 100644 --- a/lib/spells/BattleSpellMechanics.h +++ b/lib/spells/BattleSpellMechanics.h @@ -28,7 +28,7 @@ public: void applyEffects(ServerCallback * server, const Target & targets, bool indirect, bool ignoreImmunity) const override; bool canBeCast(Problem & problem) const override; - bool canBeCastAt(Problem & problem, const Target & target) const override; + bool canBeCastAt(const Target & target, Problem & problem) const override; void cast(ServerCallback * server, const Target & target) override final; void castEval(ServerCallback * server, const Target & target) override final; diff --git a/lib/spells/ISpellMechanics.h b/lib/spells/ISpellMechanics.h index d90fe5e12..de9546757 100644 --- a/lib/spells/ISpellMechanics.h +++ b/lib/spells/ISpellMechanics.h @@ -183,7 +183,7 @@ public: virtual std::vector getAffectedStacks(const Target & target) const = 0; virtual bool canBeCast(Problem & problem) const = 0; - virtual bool canBeCastAt(Problem & problem, const Target & target) const = 0; + virtual bool canBeCastAt(const Target & target, Problem & problem) const = 0; virtual void applyEffects(ServerCallback * server, const Target & targets, bool indirect, bool ignoreImmunity) const = 0; diff --git a/scripting/lua/api/Services.cpp b/scripting/lua/api/Services.cpp index b63959841..78bfcbde6 100644 --- a/scripting/lua/api/Services.cpp +++ b/scripting/lua/api/Services.cpp @@ -39,9 +39,9 @@ const std::vector ServicesProxy::REGISTER_CUSTOM = {"creatures", LuaMethodWrapper::invoke, false}, {"factions", LuaMethodWrapper::invoke, false}, {"heroClasses", LuaMethodWrapper::invoke, false}, - {"heroTypes", LuaMethodWrapper::invoke, false}, + {"heroTypes", LuaMethodWrapper::invoke, false}, {"spells", LuaMethodWrapper::invoke, false}, - {"skills", LuaMethodWrapper::invoke, false}, + {"skills", LuaMethodWrapper::invoke, false}, }; VCMI_REGISTER_CORE_SCRIPT_API(ArtifactServiceProxy, "Artifacts"); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index d0460426b..ebad84199 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -5631,9 +5631,9 @@ void CGameHandler::attackCasting(bool ranged, Bonus::BonusType attackMode, const auto m = spell->battleMechanics(¶meters); - spells::detail::ProblemImpl ingored; + spells::detail::ProblemImpl ignored; - if(!m->canBeCastAt(ingored, target)) + if(!m->canBeCastAt(target, ignored)) continue; //check if spell should be cast (probability handling) diff --git a/test/game/CGameStateTest.cpp b/test/game/CGameStateTest.cpp index 15cf0e913..9b15f9971 100644 --- a/test/game/CGameStateTest.cpp +++ b/test/game/CGameStateTest.cpp @@ -297,7 +297,7 @@ TEST_F(CGameStateTest, issue2765) auto m = age->battleMechanics(&cast); - EXPECT_FALSE(m->canBeCastAt(problemMock, target)); + EXPECT_FALSE(m->canBeCastAt(target, problemMock)); EXPECT_TRUE(cast.castIfPossible(this, target));//should be possible, but with no effect (change to aimed cast check?) @@ -397,7 +397,7 @@ TEST_F(CGameStateTest, battleResurrection) EXPECT_TRUE(m->canBeCast(problemMock)); - EXPECT_TRUE(m->canBeCastAt(problemMock, target)); + EXPECT_TRUE(m->canBeCastAt(target, problemMock)); cast.cast(this, target); // diff --git a/test/mock/mock_spells_Mechanics.h b/test/mock/mock_spells_Mechanics.h index 26944b150..e868f82f4 100644 --- a/test/mock/mock_spells_Mechanics.h +++ b/test/mock/mock_spells_Mechanics.h @@ -25,7 +25,7 @@ public: MOCK_CONST_METHOD1(getAffectedStacks, std::vector(const Target &)); MOCK_CONST_METHOD1(canBeCast, bool(Problem &)); - MOCK_CONST_METHOD2(canBeCastAt, bool(Problem &, const Target &)); + MOCK_CONST_METHOD2(canBeCastAt, bool(const Target &, Problem &)); MOCK_CONST_METHOD4(applyEffects, void(ServerCallback *, const Target &, bool, bool));