mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
Remove logic for banks in 1.5 format
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
|
||||
#include "../../../lib/mapObjectConstructors/AObjectTypeHandler.h"
|
||||
#include "../../../lib/mapObjectConstructors/CObjectClassesHandler.h"
|
||||
#include "../../../lib/mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
|
||||
namespace NKAI
|
||||
{
|
||||
|
@@ -13,7 +13,6 @@
|
||||
#include "Nullkiller.h"
|
||||
#include "../../../lib/mapObjectConstructors/AObjectTypeHandler.h"
|
||||
#include "../../../lib/mapObjectConstructors/CObjectClassesHandler.h"
|
||||
#include "../../../lib/mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
#include "../../../lib/mapObjects/CGResource.h"
|
||||
#include "../../../lib/mapping/CMapDefines.h"
|
||||
#include "../../../lib/RoadHandler.h"
|
||||
@@ -145,46 +144,6 @@ int32_t getResourcesGoldReward(const TResources & res)
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t getCreatureBankArmyReward(const CGObjectInstance * target, const CGHeroInstance * hero)
|
||||
{
|
||||
auto objectInfo = target->getObjectHandler()->getObjectInfo(target->appearance);
|
||||
CBankInfo * bankInfo = dynamic_cast<CBankInfo *>(objectInfo.get());
|
||||
auto creatures = bankInfo->getPossibleCreaturesReward(target->cb);
|
||||
uint64_t result = 0;
|
||||
|
||||
const auto& slots = hero->Slots();
|
||||
ui64 weakestStackPower = 0;
|
||||
int duplicatingSlots = getDuplicatingSlots(hero);
|
||||
|
||||
if (slots.size() >= GameConstants::ARMY_SIZE)
|
||||
{
|
||||
//No free slot, we might discard our weakest stack
|
||||
weakestStackPower = std::numeric_limits<ui64>().max();
|
||||
for (const auto & stack : slots)
|
||||
{
|
||||
vstd::amin(weakestStackPower, stack.second->getPower());
|
||||
}
|
||||
}
|
||||
|
||||
for (auto c : creatures)
|
||||
{
|
||||
//Only if hero has slot for this creature in the army
|
||||
auto ccre = dynamic_cast<const CCreature*>(c.data.getType());
|
||||
if (hero->getSlotFor(ccre).validSlot() || duplicatingSlots > 0)
|
||||
{
|
||||
result += (c.data.getType()->getAIValue() * c.data.count) * c.chance;
|
||||
}
|
||||
/*else
|
||||
{
|
||||
//we will need to discard the weakest stack
|
||||
result += (c.data.type->getAIValue() * c.data.count - weakestStackPower) * c.chance;
|
||||
}*/
|
||||
}
|
||||
result /= 100; //divide by total chance
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t getDwellingArmyValue(CCallback * cb, const CGObjectInstance * target, bool checkGold)
|
||||
{
|
||||
auto dwelling = dynamic_cast<const CGDwelling *>(target);
|
||||
|
@@ -15,7 +15,6 @@
|
||||
#include "../../../lib/constants/StringConstants.h"
|
||||
#include "../../../lib/mapObjectConstructors/AObjectTypeHandler.h"
|
||||
#include "../../../lib/mapObjectConstructors/CObjectClassesHandler.h"
|
||||
#include "../../../lib/mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
#include "../../../lib/mapObjects/MapObjects.h"
|
||||
#include "../../../lib/modding/CModHandler.h"
|
||||
#include "../../../lib/GameLibrary.h"
|
||||
|
@@ -15,7 +15,6 @@
|
||||
|
||||
#include "../../lib/mapObjectConstructors/AObjectTypeHandler.h"
|
||||
#include "../../lib/mapObjectConstructors/CObjectClassesHandler.h"
|
||||
#include "../../lib/mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
#include "../../lib/mapObjects/CGCreature.h"
|
||||
#include "../../lib/mapObjects/CGDwelling.h"
|
||||
#include "../../lib/gameState/InfoAboutArmy.h"
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include "../lib/battle/BattleInfo.h"
|
||||
#include "../lib/serializer/Connection.h"
|
||||
#include "../lib/mapping/CMapService.h"
|
||||
#include "../lib/mapObjects/CArmedInstance.h"
|
||||
#include "../lib/pathfinder/CGPathNode.h"
|
||||
#include "../lib/filesystem/Filesystem.h"
|
||||
|
||||
|
@@ -223,7 +223,6 @@ public:
|
||||
|
||||
void setObjPropertyValue(ObjectInstanceID objid, ObjProperty prop, int32_t value) override {};
|
||||
void setObjPropertyID(ObjectInstanceID objid, ObjProperty prop, ObjPropertyID identifier) override {};
|
||||
void setBankObjectConfiguration(ObjectInstanceID objid, const BankConfig & configuration) override {};
|
||||
void setRewardableObjectConfiguration(ObjectInstanceID objid, const Rewardable::Configuration & configuration) override {};
|
||||
void setRewardableObjectConfiguration(ObjectInstanceID townInstanceID, BuildingID buildingID, const Rewardable::Configuration & configuration) override{};
|
||||
|
||||
|
@@ -113,7 +113,6 @@ set(lib_MAIN_SRCS
|
||||
gameState/UpgradeInfo.cpp
|
||||
|
||||
mapObjectConstructors/AObjectTypeHandler.cpp
|
||||
mapObjectConstructors/CBankInstanceConstructor.cpp
|
||||
mapObjectConstructors/CObjectClassesHandler.cpp
|
||||
mapObjectConstructors/CommonConstructors.cpp
|
||||
mapObjectConstructors/CRewardableConstructor.cpp
|
||||
@@ -123,7 +122,6 @@ set(lib_MAIN_SRCS
|
||||
mapObjectConstructors/ShipyardInstanceConstructor.cpp
|
||||
|
||||
mapObjects/CArmedInstance.cpp
|
||||
mapObjects/CBank.cpp
|
||||
mapObjects/CGCreature.cpp
|
||||
mapObjects/CGDwelling.cpp
|
||||
mapObjects/CGHeroInstance.cpp
|
||||
@@ -498,7 +496,6 @@ set(lib_MAIN_HEADERS
|
||||
gameState/QuestInfo.h
|
||||
|
||||
mapObjectConstructors/AObjectTypeHandler.h
|
||||
mapObjectConstructors/CBankInstanceConstructor.h
|
||||
mapObjectConstructors/CDefaultObjectTypeHandler.h
|
||||
mapObjectConstructors/CObjectClassesHandler.h
|
||||
mapObjectConstructors/CommonConstructors.h
|
||||
@@ -512,7 +509,6 @@ set(lib_MAIN_HEADERS
|
||||
mapObjectConstructors/SObjectSounds.h
|
||||
|
||||
mapObjects/CArmedInstance.h
|
||||
mapObjects/CBank.h
|
||||
mapObjects/CGCreature.h
|
||||
mapObjects/CGDwelling.h
|
||||
mapObjects/CGHeroInstance.h
|
||||
|
@@ -86,7 +86,6 @@ class DLL_LINKAGE IGameEventCallback
|
||||
{
|
||||
public:
|
||||
virtual void setObjPropertyValue(ObjectInstanceID objid, ObjProperty prop, int32_t value = 0) = 0;
|
||||
virtual void setBankObjectConfiguration(ObjectInstanceID objid, const BankConfig & configuration) = 0;
|
||||
virtual void setRewardableObjectConfiguration(ObjectInstanceID mapObjectID, const Rewardable::Configuration & configuration) = 0;
|
||||
virtual void setRewardableObjectConfiguration(ObjectInstanceID townInstanceID, BuildingID buildingID, const Rewardable::Configuration & configuration) = 0;
|
||||
virtual void setObjPropertyID(ObjectInstanceID objid, ObjProperty prop, ObjPropertyID identifier) = 0;
|
||||
|
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* CBankInstanceConstructor.cpp, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
#include "StdInc.h"
|
||||
#include "CBankInstanceConstructor.h"
|
||||
|
||||
#include "../json/JsonRandom.h"
|
||||
#include "../texts/CGeneralTextHandler.h"
|
||||
#include "../IGameCallback.h"
|
||||
|
||||
#include <vstd/RNG.h>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
bool CBankInstanceConstructor::hasNameTextID() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CBankInstanceConstructor::initTypeData(const JsonNode & input)
|
||||
{
|
||||
if (input.Struct().count("name") == 0)
|
||||
logMod->warn("Bank %s missing name!", getJsonKey());
|
||||
|
||||
LIBRARY->generaltexth->registerString(input.getModScope(), getNameTextID(), input["name"]);
|
||||
|
||||
levels = input["levels"].Vector();
|
||||
bankResetDuration = static_cast<si32>(input["resetDuration"].Float());
|
||||
blockVisit = input["blockedVisitable"].Bool();
|
||||
coastVisitable = input["coastVisitable"].Bool();
|
||||
regularUnitPlacement = input["regularUnitPlacement"].Bool();
|
||||
}
|
||||
|
||||
BankConfig CBankInstanceConstructor::generateLevelConfiguration(IGameCallback * cb, const JsonNode & level, vstd::RNG & rng) const
|
||||
{
|
||||
BankConfig bc;
|
||||
JsonRandom randomizer(cb);
|
||||
JsonRandom::Variables emptyVariables;
|
||||
|
||||
bc.chance = static_cast<ui32>(level["chance"].Float());
|
||||
bc.guards = randomizer.loadCreatures(level["guards"], rng, emptyVariables);
|
||||
|
||||
bc.resources = ResourceSet(level["reward"]["resources"]);
|
||||
bc.creatures = randomizer.loadCreatures(level["reward"]["creatures"], rng, emptyVariables);
|
||||
bc.artifacts = randomizer.loadArtifacts(level["reward"]["artifacts"], rng, emptyVariables);
|
||||
bc.spells = randomizer.loadSpells(level["reward"]["spells"], rng, emptyVariables);
|
||||
|
||||
return bc;
|
||||
}
|
||||
|
||||
void CBankInstanceConstructor::randomizeObject(CBank * bank, vstd::RNG & rng) const
|
||||
{
|
||||
bank->resetDuration = bankResetDuration;
|
||||
bank->blockVisit = blockVisit;
|
||||
bank->coastVisitable = coastVisitable;
|
||||
bank->regularUnitPlacement = regularUnitPlacement;
|
||||
bank->setConfig(generateConfiguration(bank->cb, rng, bank->ID));
|
||||
}
|
||||
|
||||
BankConfig CBankInstanceConstructor::generateConfiguration(IGameCallback * cb, vstd::RNG & rng, MapObjectID objectID) const
|
||||
{
|
||||
si32 totalChance = 0;
|
||||
for(const auto & node : levels)
|
||||
totalChance += static_cast<si32>(node["chance"].Float());
|
||||
|
||||
assert(totalChance != 0);
|
||||
|
||||
si32 selectedChance = rng.nextInt(totalChance - 1);
|
||||
|
||||
int cumulativeChance = 0;
|
||||
for(const auto & node : levels)
|
||||
{
|
||||
cumulativeChance += static_cast<int>(node["chance"].Float());
|
||||
if(selectedChance < cumulativeChance)
|
||||
return generateLevelConfiguration(cb, node, rng);
|
||||
}
|
||||
|
||||
throw std::runtime_error("Failed to select bank configuration");
|
||||
}
|
||||
|
||||
CBankInfo::CBankInfo(const JsonVector & Config) :
|
||||
config(Config)
|
||||
{
|
||||
assert(!Config.empty());
|
||||
}
|
||||
|
||||
TPossibleGuards CBankInfo::getPossibleGuards(IGameCallback * cb) const
|
||||
{
|
||||
JsonRandom::Variables emptyVariables;
|
||||
JsonRandom randomizer(cb);
|
||||
TPossibleGuards out;
|
||||
|
||||
for(const JsonNode & configEntry : config)
|
||||
{
|
||||
const JsonNode & guardsInfo = configEntry["guards"];
|
||||
auto stacks = randomizer.evaluateCreatures(guardsInfo, emptyVariables);
|
||||
IObjectInfo::CArmyStructure army;
|
||||
|
||||
|
||||
for(auto stack : stacks)
|
||||
{
|
||||
army.totalStrength += stack.allowedCreatures.front()->getAIValue() * (stack.minAmount + stack.maxAmount) / 2;
|
||||
//TODO: add fields for flyers, walkers etc...
|
||||
}
|
||||
|
||||
ui8 chance = static_cast<ui8>(configEntry["chance"].Float());
|
||||
out.push_back(std::make_pair(chance, army));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<PossibleReward<TResources>> CBankInfo::getPossibleResourcesReward() const
|
||||
{
|
||||
std::vector<PossibleReward<TResources>> result;
|
||||
|
||||
for(const JsonNode & configEntry : config)
|
||||
{
|
||||
const JsonNode & resourcesInfo = configEntry["reward"]["resources"];
|
||||
|
||||
if(!resourcesInfo.isNull())
|
||||
{
|
||||
result.emplace_back(configEntry["chance"].Integer(), TResources(resourcesInfo));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<PossibleReward<CStackBasicDescriptor>> CBankInfo::getPossibleCreaturesReward(IGameCallback * cb) const
|
||||
{
|
||||
JsonRandom::Variables emptyVariables;
|
||||
JsonRandom randomizer(cb);
|
||||
std::vector<PossibleReward<CStackBasicDescriptor>> approximateReward;
|
||||
|
||||
for(const JsonNode & configEntry : config)
|
||||
{
|
||||
const JsonNode & guardsInfo = configEntry["reward"]["creatures"];
|
||||
auto stacks = randomizer.evaluateCreatures(guardsInfo, emptyVariables);
|
||||
|
||||
for(auto stack : stacks)
|
||||
{
|
||||
const auto * creature = stack.allowedCreatures.front();
|
||||
|
||||
approximateReward.emplace_back(configEntry["chance"].Integer(), CStackBasicDescriptor(creature, (stack.minAmount + stack.maxAmount) / 2));
|
||||
}
|
||||
}
|
||||
|
||||
return approximateReward;
|
||||
}
|
||||
|
||||
bool CBankInfo::givesResources() const
|
||||
{
|
||||
for(const JsonNode & node : config)
|
||||
if(!node["reward"]["resources"].isNull())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CBankInfo::givesArtifacts() const
|
||||
{
|
||||
for(const JsonNode & node : config)
|
||||
if(!node["reward"]["artifacts"].isNull())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CBankInfo::givesCreatures() const
|
||||
{
|
||||
for(const JsonNode & node : config)
|
||||
if(!node["reward"]["creatures"].isNull())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CBankInfo::givesSpells() const
|
||||
{
|
||||
for(const JsonNode & node : config)
|
||||
if(!node["reward"]["spells"].isNull())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<IObjectInfo> CBankInstanceConstructor::getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const
|
||||
{
|
||||
return std::unique_ptr<IObjectInfo>(new CBankInfo(levels));
|
||||
}
|
||||
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* CBankInstanceConstructor.h, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "CDefaultObjectTypeHandler.h"
|
||||
#include "IObjectInfo.h"
|
||||
|
||||
#include "../CCreatureSet.h"
|
||||
#include "../ResourceSet.h"
|
||||
#include "../json/JsonNode.h"
|
||||
#include "../mapObjects/CBank.h"
|
||||
#include "../serializer/Serializeable.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
struct BankConfig : public Serializeable
|
||||
{
|
||||
ui32 chance = 0; //chance for this level being chosen
|
||||
std::vector<CStackBasicDescriptor> guards; //creature ID, amount
|
||||
ResourceSet resources; //resources given in case of victory
|
||||
std::vector<CStackBasicDescriptor> creatures; //creatures granted in case of victory (creature ID, amount)
|
||||
std::vector<ArtifactID> artifacts; //artifacts given in case of victory
|
||||
std::vector<SpellID> spells; // granted spell(s), for Pyramid
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
{
|
||||
h & chance;
|
||||
h & guards;
|
||||
h & resources;
|
||||
h & creatures;
|
||||
h & artifacts;
|
||||
h & spells;
|
||||
}
|
||||
};
|
||||
|
||||
using TPossibleGuards = std::vector<std::pair<ui8, IObjectInfo::CArmyStructure>>;
|
||||
|
||||
template <typename T>
|
||||
struct DLL_LINKAGE PossibleReward
|
||||
{
|
||||
int chance;
|
||||
T data;
|
||||
|
||||
PossibleReward(int chance, const T & data) : chance(chance), data(data) {}
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CBankInfo : public IObjectInfo
|
||||
{
|
||||
const JsonVector & config;
|
||||
public:
|
||||
CBankInfo(const JsonVector & Config);
|
||||
|
||||
TPossibleGuards getPossibleGuards(IGameCallback * cb) const;
|
||||
std::vector<PossibleReward<TResources>> getPossibleResourcesReward() const;
|
||||
std::vector<PossibleReward<CStackBasicDescriptor>> getPossibleCreaturesReward(IGameCallback * cb) const;
|
||||
|
||||
bool givesResources() const override;
|
||||
bool givesArtifacts() const override;
|
||||
bool givesCreatures() const override;
|
||||
bool givesSpells() const override;
|
||||
};
|
||||
|
||||
class CBankInstanceConstructor : public CDefaultObjectTypeHandler<CBank>
|
||||
{
|
||||
BankConfig generateLevelConfiguration(IGameCallback * cb, const JsonNode & conf, vstd::RNG & rng) const;
|
||||
|
||||
JsonVector levels;
|
||||
|
||||
// all banks of this type will be reset N days after clearing,
|
||||
si32 bankResetDuration = 0;
|
||||
|
||||
// bank is only visitable from adjacent tile
|
||||
bool blockVisit;
|
||||
// bank is visitable from land even when bank is on water tile
|
||||
bool coastVisitable;
|
||||
//If true, player units will be placed on the left and enemy on the right
|
||||
bool regularUnitPlacement;
|
||||
protected:
|
||||
void initTypeData(const JsonNode & input) override;
|
||||
|
||||
public:
|
||||
|
||||
void randomizeObject(CBank * object, vstd::RNG & rng) const override;
|
||||
|
||||
bool hasNameTextID() const override;
|
||||
|
||||
std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override;
|
||||
|
||||
BankConfig generateConfiguration(IGameCallback * cb, vstd::RNG & rand, MapObjectID objectID) const;
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@@ -19,7 +19,6 @@
|
||||
#include "../IGameSettings.h"
|
||||
#include "../CSoundBase.h"
|
||||
|
||||
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
#include "../mapObjectConstructors/CRewardableConstructor.h"
|
||||
#include "../mapObjectConstructors/CommonConstructors.h"
|
||||
#include "../mapObjectConstructors/DwellingInstanceConstructor.h"
|
||||
@@ -59,7 +58,6 @@ CObjectClassesHandler::CObjectClassesHandler()
|
||||
SET_HANDLER_CLASS("dwelling", DwellingInstanceConstructor);
|
||||
SET_HANDLER_CLASS("hero", CHeroInstanceConstructor);
|
||||
SET_HANDLER_CLASS("town", CTownInstanceConstructor);
|
||||
SET_HANDLER_CLASS("bank", CBankInstanceConstructor);
|
||||
SET_HANDLER_CLASS("boat", BoatInstanceConstructor);
|
||||
SET_HANDLER_CLASS("flaggable", FlaggableInstanceConstructor);
|
||||
SET_HANDLER_CLASS("market", MarketInstanceConstructor);
|
||||
|
@@ -1,292 +0,0 @@
|
||||
/*
|
||||
* CBank.cpp, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "CBank.h"
|
||||
|
||||
#include <vcmi/spells/Spell.h>
|
||||
#include <vcmi/spells/Service.h>
|
||||
|
||||
#include "../texts/CGeneralTextHandler.h"
|
||||
#include "../IGameSettings.h"
|
||||
#include "../CPlayerState.h"
|
||||
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
||||
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
#include "../mapObjects/CGHeroInstance.h"
|
||||
#include "../networkPacks/Component.h"
|
||||
#include "../networkPacks/PacksForClient.h"
|
||||
#include "../networkPacks/PacksForClientBattle.h"
|
||||
#include "../IGameCallback.h"
|
||||
#include "../gameState/CGameState.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
///helpers
|
||||
static std::string visitedTxt(const bool visited)
|
||||
{
|
||||
int id = visited ? 352 : 353;
|
||||
return LIBRARY->generaltexth->allTexts[id];
|
||||
}
|
||||
|
||||
CBank::CBank(IGameCallback *cb)
|
||||
: CArmedInstance(cb)
|
||||
{}
|
||||
|
||||
//must be instantiated in .cpp file for access to complete types of all member fields
|
||||
CBank::~CBank() = default;
|
||||
|
||||
void CBank::initObj(vstd::RNG & rand)
|
||||
{
|
||||
daycounter = 0;
|
||||
resetDuration = 0;
|
||||
getObjectHandler()->configureObject(this, rand);
|
||||
}
|
||||
|
||||
bool CBank::isCoastVisitable() const
|
||||
{
|
||||
return coastVisitable;
|
||||
}
|
||||
|
||||
std::string CBank::getHoverText(PlayerColor player) const
|
||||
{
|
||||
if (!wasVisited(player))
|
||||
return getObjectName();
|
||||
|
||||
return getObjectName() + "\n" + visitedTxt(bankConfig == nullptr);
|
||||
}
|
||||
|
||||
std::vector<Component> CBank::getPopupComponents(PlayerColor player) const
|
||||
{
|
||||
if (!wasVisited(player))
|
||||
return {};
|
||||
|
||||
if (!cb->getSettings().getBoolean(EGameSettings::BANKS_SHOW_GUARDS_COMPOSITION))
|
||||
return {};
|
||||
|
||||
if (bankConfig == nullptr)
|
||||
return {};
|
||||
|
||||
std::map<CreatureID, int> guardsAmounts;
|
||||
std::vector<Component> result;
|
||||
|
||||
for (auto const & slot : Slots())
|
||||
if (slot.second)
|
||||
guardsAmounts[slot.second->getCreatureID()] += slot.second->getCount();
|
||||
|
||||
for (auto const & guard : guardsAmounts)
|
||||
{
|
||||
Component comp(ComponentType::CREATURE, guard.first, guard.second);
|
||||
result.push_back(comp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void CBank::setConfig(const BankConfig & config)
|
||||
{
|
||||
bankConfig = std::make_unique<BankConfig>(config);
|
||||
clearSlots(); // remove all stacks, if any
|
||||
|
||||
for(const auto & stack : config.guards)
|
||||
setCreature (SlotID(stacksCount()), stack.getId(), stack.count);
|
||||
|
||||
daycounter = 1; //yes, 1 since "today" daycounter won't be incremented
|
||||
}
|
||||
|
||||
void CBank::setPropertyDer (ObjProperty what, ObjPropertyID identifier)
|
||||
{
|
||||
switch (what)
|
||||
{
|
||||
case ObjProperty::BANK_DAYCOUNTER: //daycounter
|
||||
daycounter+= identifier.getNum();
|
||||
break;
|
||||
case ObjProperty::BANK_CLEAR:
|
||||
bankConfig.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CBank::newTurn(vstd::RNG & rand) const
|
||||
{
|
||||
if (bankConfig == nullptr)
|
||||
{
|
||||
if (resetDuration != 0)
|
||||
{
|
||||
if (daycounter >= resetDuration)
|
||||
{
|
||||
auto handler = std::dynamic_pointer_cast<CBankInstanceConstructor>(getObjectHandler());
|
||||
auto config = handler->generateConfiguration(cb, rand, ID);
|
||||
cb->setBankObjectConfiguration(id, config);
|
||||
}
|
||||
else
|
||||
cb->setObjPropertyValue(id, ObjProperty::BANK_DAYCOUNTER, 1); //daycounter++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CBank::wasVisited (PlayerColor player) const
|
||||
{
|
||||
return vstd::contains(cb->getPlayerState(player)->visitedObjects, ObjectInstanceID(id));
|
||||
}
|
||||
|
||||
void CBank::onHeroVisit(const CGHeroInstance * h) const
|
||||
{
|
||||
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_PLAYER, id, h->id);
|
||||
cb->sendAndApply(cov);
|
||||
|
||||
BlockingDialog bd(true, false);
|
||||
bd.player = h->getOwner();
|
||||
bd.text.appendLocalString(EMetaText::ADVOB_TXT, 32);
|
||||
bd.components = getPopupComponents(h->getOwner());
|
||||
bd.text.replaceTextID(getObjectHandler()->getNameTextID());
|
||||
cb->showBlockingDialog(this, &bd);
|
||||
}
|
||||
|
||||
void CBank::doVisit(const CGHeroInstance * hero) const
|
||||
{
|
||||
InfoWindow iw;
|
||||
iw.type = EInfoWindowMode::AUTO;
|
||||
iw.player = hero->getOwner();
|
||||
MetaString loot;
|
||||
|
||||
if (!bankConfig)
|
||||
{
|
||||
iw.text.appendRawString(LIBRARY->generaltexth->advobtxt[33]);// This was X, now is completely empty
|
||||
iw.text.replaceTextID(getObjectHandler()->getNameTextID());
|
||||
cb->showInfoDialog(&iw);
|
||||
}
|
||||
|
||||
//grant resources
|
||||
if (bankConfig)
|
||||
{
|
||||
for (GameResID it : GameResID::ALL_RESOURCES())
|
||||
{
|
||||
if (bankConfig->resources[it] != 0)
|
||||
{
|
||||
iw.components.emplace_back(ComponentType::RESOURCE, it, bankConfig->resources[it]);
|
||||
loot.appendRawString("%d %s");
|
||||
loot.replaceNumber(bankConfig->resources[it]);
|
||||
loot.replaceName(it);
|
||||
cb->giveResource(hero->getOwner(), it, bankConfig->resources[it]);
|
||||
}
|
||||
}
|
||||
//grant artifacts
|
||||
for (auto & elem : bankConfig->artifacts)
|
||||
{
|
||||
iw.components.emplace_back(ComponentType::ARTIFACT, elem);
|
||||
loot.appendRawString("%s");
|
||||
loot.replaceName(elem);
|
||||
cb->giveHeroNewArtifact(hero, elem, ArtifactPosition::FIRST_AVAILABLE);
|
||||
}
|
||||
//display loot
|
||||
if (!iw.components.empty())
|
||||
{
|
||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 34);
|
||||
const auto * strongest = boost::range::max_element(bankConfig->guards, [](const CStackBasicDescriptor & a, const CStackBasicDescriptor & b)
|
||||
{
|
||||
return a.getType()->getFightValue() < b.getType()->getFightValue();
|
||||
})->getType();
|
||||
|
||||
iw.text.replaceNamePlural(strongest->getId());
|
||||
iw.text.replaceRawString(loot.buildList());
|
||||
|
||||
cb->showInfoDialog(&iw);
|
||||
}
|
||||
|
||||
loot.clear();
|
||||
iw.components.clear();
|
||||
iw.text.clear();
|
||||
|
||||
if (!bankConfig->spells.empty())
|
||||
{
|
||||
std::set<SpellID> spells;
|
||||
|
||||
bool noWisdom = false;
|
||||
|
||||
for(const SpellID & spellId : bankConfig->spells)
|
||||
{
|
||||
const auto * spell = spellId.toEntity(LIBRARY);
|
||||
iw.text.appendName(spellId);
|
||||
if(spell->getLevel() <= hero->maxSpellLevel())
|
||||
{
|
||||
if(hero->canLearnSpell(spell))
|
||||
{
|
||||
spells.insert(spellId);
|
||||
iw.components.emplace_back(ComponentType::SPELL, spellId);
|
||||
}
|
||||
}
|
||||
else
|
||||
noWisdom = true;
|
||||
}
|
||||
|
||||
if (!hero->getArt(ArtifactPosition::SPELLBOOK))
|
||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 109); //no spellbook
|
||||
else if(noWisdom)
|
||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 108); //no expert Wisdom
|
||||
|
||||
if(!iw.components.empty() || !iw.text.toString().empty())
|
||||
cb->showInfoDialog(&iw);
|
||||
|
||||
if(!spells.empty())
|
||||
cb->changeSpells(hero, true, spells);
|
||||
}
|
||||
|
||||
iw.components.clear();
|
||||
iw.text.clear();
|
||||
|
||||
//grant creatures
|
||||
CCreatureSet ourArmy;
|
||||
for(const auto & slot : bankConfig->creatures)
|
||||
{
|
||||
ourArmy.addToSlot(ourArmy.getSlotFor(slot.getId()), slot.getId(), slot.count);
|
||||
}
|
||||
|
||||
for(const auto & elem : ourArmy.Slots())
|
||||
{
|
||||
iw.components.emplace_back(ComponentType::CREATURE, elem.second->getId(), elem.second->getCount());
|
||||
loot.appendRawString("%s");
|
||||
loot.replaceName(*elem.second);
|
||||
}
|
||||
|
||||
if(ourArmy.stacksCount())
|
||||
{
|
||||
if(ourArmy.stacksCount() == 1 && ourArmy.Slots().begin()->second->count == 1)
|
||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 185);
|
||||
else
|
||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 186);
|
||||
|
||||
iw.text.replaceRawString(loot.buildList());
|
||||
iw.text.replaceRawString(hero->getNameTranslated());
|
||||
cb->showInfoDialog(&iw);
|
||||
cb->giveCreatures(this, hero, ourArmy, false);
|
||||
}
|
||||
cb->setObjPropertyValue(id, ObjProperty::BANK_CLEAR); //bc = nullptr
|
||||
}
|
||||
}
|
||||
|
||||
void CBank::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
|
||||
{
|
||||
if (result.winner == BattleSide::ATTACKER)
|
||||
{
|
||||
doVisit(hero);
|
||||
}
|
||||
}
|
||||
|
||||
void CBank::blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const
|
||||
{
|
||||
if (answer)
|
||||
{
|
||||
if (bankConfig) // not looted bank
|
||||
cb->startBattle(hero, this);
|
||||
else
|
||||
doVisit(hero);
|
||||
}
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* CBank.h, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "CArmedInstance.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
struct BankConfig;
|
||||
class CBankInstanceConstructor;
|
||||
|
||||
class DLL_LINKAGE CBank : public CArmedInstance
|
||||
{
|
||||
std::unique_ptr<BankConfig> bankConfig;
|
||||
ui32 daycounter;
|
||||
ui32 resetDuration;
|
||||
bool coastVisitable;
|
||||
bool regularUnitPlacement;
|
||||
|
||||
void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
|
||||
void doVisit(const CGHeroInstance * hero) const;
|
||||
|
||||
public:
|
||||
CBank(IGameCallback *cb);
|
||||
~CBank() override;
|
||||
|
||||
void setConfig(const BankConfig & bc);
|
||||
|
||||
void initObj(vstd::RNG & rand) override;
|
||||
std::string getHoverText(PlayerColor player) const override;
|
||||
void newTurn(vstd::RNG & rand) const override;
|
||||
bool wasVisited (PlayerColor player) const override;
|
||||
bool isCoastVisitable() const override;
|
||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
|
||||
void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
|
||||
|
||||
std::vector<Component> getPopupComponents(PlayerColor player) const override;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
{
|
||||
h & static_cast<CArmedInstance&>(*this);
|
||||
h & daycounter;
|
||||
h & bankConfig;
|
||||
h & resetDuration;
|
||||
h & coastVisitable;
|
||||
h & regularUnitPlacement;
|
||||
}
|
||||
|
||||
friend class CBankInstanceConstructor;
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@@ -37,7 +37,6 @@ public:
|
||||
virtual void visitGamePause(GamePause & pack) {}
|
||||
virtual void visitEntitiesChanged(EntitiesChanged & pack) {}
|
||||
virtual void visitSetRewardableConfiguration(SetRewardableConfiguration & pack) {}
|
||||
virtual void visitSetBankConfiguration(SetBankConfiguration & pack) {}
|
||||
virtual void visitSetResources(SetResources & pack) {}
|
||||
virtual void visitSetPrimSkill(SetPrimSkill & pack) {}
|
||||
virtual void visitSetSecSkill(SetSecSkill & pack) {}
|
||||
|
@@ -34,7 +34,6 @@
|
||||
#include "TerrainHandler.h"
|
||||
#include "entities/building/CBuilding.h"
|
||||
#include "entities/building/TownFortifications.h"
|
||||
#include "mapObjects/CBank.h"
|
||||
#include "mapObjects/CGCreature.h"
|
||||
#include "mapObjects/CGMarket.h"
|
||||
#include "mapObjects/TownBuildingInstance.h"
|
||||
@@ -139,11 +138,6 @@ void SetRewardableConfiguration::visitTyped(ICPackVisitor & visitor)
|
||||
visitor.visitSetRewardableConfiguration(*this);
|
||||
}
|
||||
|
||||
void SetBankConfiguration::visitTyped(ICPackVisitor & visitor)
|
||||
{
|
||||
visitor.visitSetBankConfiguration(*this);
|
||||
}
|
||||
|
||||
void SetResources::visitTyped(ICPackVisitor & visitor)
|
||||
{
|
||||
visitor.visitSetResources(*this);
|
||||
@@ -2486,16 +2480,6 @@ void SetRewardableConfiguration::applyGs(CGameState *gs)
|
||||
}
|
||||
}
|
||||
|
||||
void SetBankConfiguration::applyGs(CGameState *gs)
|
||||
{
|
||||
auto * objectPtr = gs->getObjInstance(objectID);
|
||||
auto * bankPtr = dynamic_cast<CBank *>(objectPtr);
|
||||
|
||||
assert(bankPtr);
|
||||
|
||||
bankPtr->setConfig(configuration);
|
||||
}
|
||||
|
||||
const CArtifactInstance * ArtSlotInfo::getArt() const
|
||||
{
|
||||
if(locked)
|
||||
|
@@ -12,7 +12,6 @@
|
||||
#include "NetPacksBase.h"
|
||||
|
||||
#include "../rewardable/Configuration.h"
|
||||
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@@ -33,19 +32,4 @@ struct DLL_LINKAGE SetRewardableConfiguration : public CPackForClient
|
||||
}
|
||||
};
|
||||
|
||||
struct DLL_LINKAGE SetBankConfiguration : public CPackForClient
|
||||
{
|
||||
void applyGs(CGameState * gs) override;
|
||||
void visitTyped(ICPackVisitor & visitor) override;
|
||||
|
||||
ObjectInstanceID objectID;
|
||||
BankConfig configuration;
|
||||
|
||||
template <typename Handler> void serialize(Handler & h)
|
||||
{
|
||||
h & objectID;
|
||||
h & configuration;
|
||||
}
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@@ -97,7 +97,6 @@ void registerTypes(Serializer &s)
|
||||
s.template registerType<CGArtifact>(36);
|
||||
s.template registerType<CGResource>(37);
|
||||
s.template registerType<CGMine>(38);
|
||||
s.template registerType<CBank>(39);
|
||||
s.template registerType<CGSeerHut>(40);
|
||||
s.template registerType<CGQuestGuard>(41);
|
||||
s.template registerType<IUpdater>(42);
|
||||
@@ -229,7 +228,6 @@ void registerTypes(Serializer &s)
|
||||
s.template registerType<BulkRebalanceStacks>(175);
|
||||
s.template registerType<BulkSmartRebalanceStacks>(176);
|
||||
s.template registerType<SetRewardableConfiguration>(177);
|
||||
s.template registerType<SetBankConfiguration>(178);
|
||||
s.template registerType<CPackForServer>(179);
|
||||
s.template registerType<EndTurn>(180);
|
||||
s.template registerType<DismissHero>(181);
|
||||
|
@@ -4209,14 +4209,6 @@ void CGameHandler::setObjPropertyID(ObjectInstanceID objid, ObjProperty prop, Ob
|
||||
sendAndApply(sob);
|
||||
}
|
||||
|
||||
void CGameHandler::setBankObjectConfiguration(ObjectInstanceID objid, const BankConfig & configuration)
|
||||
{
|
||||
SetBankConfiguration srb;
|
||||
srb.objectID = objid;
|
||||
srb.configuration = configuration;
|
||||
sendAndApply(srb);
|
||||
}
|
||||
|
||||
void CGameHandler::setRewardableObjectConfiguration(ObjectInstanceID objid, const Rewardable::Configuration & configuration)
|
||||
{
|
||||
SetRewardableConfiguration srb;
|
||||
|
@@ -172,7 +172,6 @@ public:
|
||||
bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero) override;
|
||||
void setObjPropertyValue(ObjectInstanceID objid, ObjProperty prop, int32_t value) override;
|
||||
void setObjPropertyID(ObjectInstanceID objid, ObjProperty prop, ObjPropertyID identifier) override;
|
||||
void setBankObjectConfiguration(ObjectInstanceID objid, const BankConfig & configuration) override;
|
||||
void setRewardableObjectConfiguration(ObjectInstanceID objid, const Rewardable::Configuration & configuration) override;
|
||||
void setRewardableObjectConfiguration(ObjectInstanceID townInstanceID, BuildingID buildingID, const Rewardable::Configuration & configuration) override;
|
||||
void showInfoDialog(InfoWindow * iw) override;
|
||||
|
@@ -37,7 +37,6 @@ public:
|
||||
|
||||
void setObjPropertyValue(ObjectInstanceID objid, ObjProperty prop, int32_t value = 0) override {}
|
||||
void setObjPropertyID(ObjectInstanceID objid, ObjProperty prop, ObjPropertyID identifier) override {}
|
||||
void setBankObjectConfiguration(ObjectInstanceID objid, const BankConfig & configuration) override {}
|
||||
void setRewardableObjectConfiguration(ObjectInstanceID mapObjectID, const Rewardable::Configuration & configuration) override {}
|
||||
void setRewardableObjectConfiguration(ObjectInstanceID townInstanceID, BuildingID buildingID, const Rewardable::Configuration & configuration) override {}
|
||||
|
||||
|
Reference in New Issue
Block a user