diff --git a/CCallback.cpp b/CCallback.cpp index 4e609f432..1be655bc5 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -217,6 +217,16 @@ bool CCallback::buildBuilding(const CGTownInstance *town, BuildingID buildingID) return true; } +bool CCallback::triggerTownSpecialBuildingAction(const CGTownInstance *town, BuildingSubID::EBuildingSubID subBuildingID) +{ + if(town->tempOwner!=player) + return false; + + TriggerTownSpecialBuildingAction pack(town->id, subBuildingID); + sendRequest(&pack); + return true; +} + void CBattleCallback::battleMakeSpellAction(const BattleID & battleID, const BattleAction & action) { assert(action.actionType == EActionType::HERO_SPELL); diff --git a/CCallback.h b/CCallback.h index 8c579ae61..7da23128d 100644 --- a/CCallback.h +++ b/CCallback.h @@ -76,6 +76,7 @@ public: //town virtual void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero, const HeroTypeID & nextHero=HeroTypeID::NONE)=0; virtual bool buildBuilding(const CGTownInstance *town, BuildingID buildingID)=0; + virtual bool triggerTownSpecialBuildingAction(const CGTownInstance *town, BuildingSubID::EBuildingSubID subBuildingID)=0; virtual void recruitCreatures(const CGDwelling *obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level=-1)=0; virtual bool upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID=CreatureID::NONE)=0; //if newID==-1 then best possible upgrade will be made virtual void swapGarrisonHero(const CGTownInstance *town)=0; @@ -182,6 +183,7 @@ public: void manageHeroCostume(ObjectInstanceID hero, size_t costumeIdx, bool saveCostume) override; void eraseArtifactByClient(const ArtifactLocation & al) override; bool buildBuilding(const CGTownInstance *town, BuildingID buildingID) override; + bool triggerTownSpecialBuildingAction(const CGTownInstance *town, BuildingSubID::EBuildingSubID subBuildingID) override; void recruitCreatures(const CGDwelling * obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level=-1) override; bool dismissCreature(const CArmedInstance *obj, SlotID stackPos) override; bool upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID=CreatureID::NONE) override; diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 3edd38533..c85291da2 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -814,6 +814,10 @@ void CCastleBuildings::buildingClicked(BuildingID building, BuildingSubID::EBuil enterAnyThievesGuild(); break; + case BuildingSubID::BANK: + enterBank(); + break; + default: enterBuilding(building); break; @@ -1054,6 +1058,15 @@ void CCastleBuildings::enterAnyThievesGuild() LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithTavern")); } +void CCastleBuildings::enterBank() +{ + //town + LOCPLINT->cb->triggerTownSpecialBuildingAction(town, BuildingSubID::BANK); + + LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithTavern")); + //LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[214], onYes, onNo, components); +} + void CCastleBuildings::enterAnyMarket() { if(town->builtBuildings.count(BuildingID::MARKETPLACE)) diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 6accc8dde..6ee07cf04 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -170,6 +170,7 @@ public: void enterMagesGuild(); void enterAnyMarket(); void enterAnyThievesGuild(); + void enterBank(); void enterToTheQuickRecruitmentWindow(); void buildingClicked(BuildingID building, BuildingSubID::EBuildingSubID subID = BuildingSubID::NONE, BuildingID upgrades = BuildingID::NONE); diff --git a/lib/constants/Enumerations.h b/lib/constants/Enumerations.h index f1804a69f..199e409e6 100644 --- a/lib/constants/Enumerations.h +++ b/lib/constants/Enumerations.h @@ -51,6 +51,7 @@ namespace BuildingSubID LIGHTHOUSE, TREASURY, THIEVES_GUILD, + BANK, CUSTOM_VISITING_BONUS, CUSTOM_VISITING_REWARD }; diff --git a/lib/constants/StringConstants.h b/lib/constants/StringConstants.h index c017ef659..962bcb3bf 100644 --- a/lib/constants/StringConstants.h +++ b/lib/constants/StringConstants.h @@ -199,7 +199,8 @@ namespace MappedKeys { "experienceVisitingBonus", BuildingSubID::EXPERIENCE_VISITING_BONUS }, { "lighthouse", BuildingSubID::LIGHTHOUSE }, { "treasury", BuildingSubID::TREASURY }, - { "thievesGuild", BuildingSubID::THIEVES_GUILD } + { "thievesGuild", BuildingSubID::THIEVES_GUILD }, + { "bank", BuildingSubID::BANK } }; static const std::map MARKET_NAMES_TO_TYPES = diff --git a/lib/networkPacks/NetPackVisitor.h b/lib/networkPacks/NetPackVisitor.h index 2765f8e72..faeaecf1b 100644 --- a/lib/networkPacks/NetPackVisitor.h +++ b/lib/networkPacks/NetPackVisitor.h @@ -128,6 +128,7 @@ public: virtual void visitBulkSmartSplitStack(BulkSmartSplitStack & pack) {} virtual void visitDisbandCreature(DisbandCreature & pack) {} virtual void visitBuildStructure(BuildStructure & pack) {} + virtual void visitTriggerTownSpecialBuildingAction(TriggerTownSpecialBuildingAction & pack) {} virtual void visitRazeStructure(RazeStructure & pack) {} virtual void visitRecruitCreatures(RecruitCreatures & pack) {} virtual void visitUpgradeCreature(UpgradeCreature & pack) {} diff --git a/lib/networkPacks/NetPacksLib.cpp b/lib/networkPacks/NetPacksLib.cpp index 8c720922f..8fec89864 100644 --- a/lib/networkPacks/NetPacksLib.cpp +++ b/lib/networkPacks/NetPacksLib.cpp @@ -590,6 +590,11 @@ void BuildStructure::visitTyped(ICPackVisitor & visitor) visitor.visitBuildStructure(*this); } +void TriggerTownSpecialBuildingAction::visitTyped(ICPackVisitor & visitor) +{ + visitor.visitTriggerTownSpecialBuildingAction(*this); +} + void RazeStructure::visitTyped(ICPackVisitor & visitor) { visitor.visitRazeStructure(*this); diff --git a/lib/networkPacks/PacksForServer.h b/lib/networkPacks/PacksForServer.h index 9db178053..c0e40b4c0 100644 --- a/lib/networkPacks/PacksForServer.h +++ b/lib/networkPacks/PacksForServer.h @@ -280,6 +280,27 @@ struct DLL_LINKAGE BuildStructure : public CPackForServer } }; +struct DLL_LINKAGE TriggerTownSpecialBuildingAction : public CPackForServer +{ + TriggerTownSpecialBuildingAction() = default; + TriggerTownSpecialBuildingAction(const ObjectInstanceID & TID, const BuildingSubID::EBuildingSubID SID) + : tid(TID) + , sid(SID) + { + } + ObjectInstanceID tid; + BuildingSubID::EBuildingSubID sid; + + void visitTyped(ICPackVisitor & visitor) override; + + template void serialize(Handler & h) + { + h & static_cast(*this); + h & tid; + h & sid; + } +}; + struct DLL_LINKAGE RazeStructure : public BuildStructure { void visitTyped(ICPackVisitor & visitor) override; diff --git a/lib/registerTypes/RegisterTypesServerPacks.h b/lib/registerTypes/RegisterTypesServerPacks.h index de13eae8e..871b7a47d 100644 --- a/lib/registerTypes/RegisterTypesServerPacks.h +++ b/lib/registerTypes/RegisterTypesServerPacks.h @@ -27,6 +27,7 @@ void registerTypesServerPacks(Serializer &s) s.template registerType(); s.template registerType(); s.template registerType(); + s.template registerType(); s.template registerType(); s.template registerType(); s.template registerType(); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 225864d7f..f634cb2c2 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2469,6 +2469,29 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID, return true; } +bool CGameHandler::triggerTownSpecialBuildingAction(ObjectInstanceID tid, BuildingSubID::EBuildingSubID sid) +{ + const CGTownInstance * t = getTown(tid); + + bool hasBuilding = false; + for (auto building : t->town->buildings) + if(vstd::contains(t->builtBuildings, building.first) && building.second->subId == sid) + hasBuilding = true; + + if(!hasBuilding) + return false; + + + if(sid == BuildingSubID::EBuildingSubID::BANK) + { + TResources res; + res[EGameResID::GOLD] = 2500; + giveResources(t->getOwner(), res); + } + + return true; +} + bool CGameHandler::razeStructure (ObjectInstanceID tid, BuildingID bid) { ///incomplete, simply erases target building diff --git a/server/CGameHandler.h b/server/CGameHandler.h index ad90a0bbe..91e1b2d15 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -213,6 +213,7 @@ public: bool upgradeCreature( ObjectInstanceID objid, SlotID pos, CreatureID upgID ); bool recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dst, CreatureID crid, ui32 cram, si32 level, PlayerColor player); bool buildStructure(ObjectInstanceID tid, BuildingID bid, bool force=false);//force - for events: no cost, no checkings + bool triggerTownSpecialBuildingAction(ObjectInstanceID tid, BuildingSubID::EBuildingSubID sid); bool razeStructure(ObjectInstanceID tid, BuildingID bid); bool disbandCreature( ObjectInstanceID id, SlotID pos ); bool arrangeStacks( ObjectInstanceID id1, ObjectInstanceID id2, ui8 what, SlotID p1, SlotID p2, si32 val, PlayerColor player); diff --git a/server/NetPacksServer.cpp b/server/NetPacksServer.cpp index 576b3dffc..17217dac6 100644 --- a/server/NetPacksServer.cpp +++ b/server/NetPacksServer.cpp @@ -139,6 +139,14 @@ void ApplyGhNetPackVisitor::visitBuildStructure(BuildStructure & pack) result = gh.buildStructure(pack.tid, pack.bid); } +void ApplyGhNetPackVisitor::visitTriggerTownSpecialBuildingAction(TriggerTownSpecialBuildingAction & pack) +{ + gh.throwIfWrongOwner(&pack, pack.tid); + gh.throwIfPlayerNotActive(&pack); + + result = gh.triggerTownSpecialBuildingAction(pack.tid, pack.sid); +} + void ApplyGhNetPackVisitor::visitRecruitCreatures(RecruitCreatures & pack) { gh.throwIfWrongPlayer(&pack); diff --git a/server/ServerNetPackVisitors.h b/server/ServerNetPackVisitors.h index 568c8322a..68601e929 100644 --- a/server/ServerNetPackVisitors.h +++ b/server/ServerNetPackVisitors.h @@ -41,6 +41,7 @@ public: void visitBulkSmartSplitStack(BulkSmartSplitStack & pack) override; void visitDisbandCreature(DisbandCreature & pack) override; void visitBuildStructure(BuildStructure & pack) override; + void visitTriggerTownSpecialBuildingAction(TriggerTownSpecialBuildingAction & pack) override; void visitRecruitCreatures(RecruitCreatures & pack) override; void visitUpgradeCreature(UpgradeCreature & pack) override; void visitGarrisonHeroSwap(GarrisonHeroSwap & pack) override;