1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

cleanup unused code

This commit is contained in:
SoundSSGood 2024-08-17 20:19:48 +03:00
parent 39bb6d5f39
commit cd7ebea9e3
14 changed files with 41 additions and 69 deletions

View File

@ -1639,7 +1639,7 @@ void CPlayerInterface::showMarketWindow(const IMarket * market, const ObjectInst
cb->selectionMade(0, queryID); cb->selectionMade(0, queryID);
}; };
if (market->allowsTrade(EMarketMode::ARTIFACT_EXP) && dynamic_cast<const CGArtifactsAltar*>(market) == nullptr) if (market->allowsTrade(EMarketMode::ARTIFACT_EXP) && market->getArtifactsStorage() == nullptr)
{ {
// compatibility check, safe to remove for 1.6 // compatibility check, safe to remove for 1.6
// 1.4 saves loaded in 1.5 will not be able to visit Altar of Sacrifice due to Altar now requiring different map object class // 1.4 saves loaded in 1.5 will not be able to visit Altar of Sacrifice due to Altar now requiring different map object class
@ -1654,8 +1654,8 @@ void CPlayerInterface::showMarketWindow(const IMarket * market, const ObjectInst
GH.windows().createAndPushWindow<CMarketWindow>(market, visitor, marketId, onWindowClosed, EMarketMode::CREATURE_EXP); GH.windows().createAndPushWindow<CMarketWindow>(market, visitor, marketId, onWindowClosed, EMarketMode::CREATURE_EXP);
else if(market->allowsTrade(EMarketMode::CREATURE_UNDEAD)) else if(market->allowsTrade(EMarketMode::CREATURE_UNDEAD))
GH.windows().createAndPushWindow<CTransformerWindow>(market, visitor, onWindowClosed); GH.windows().createAndPushWindow<CTransformerWindow>(market, visitor, onWindowClosed);
else if(!market->availableModes().empty()) else if(vstd::contains(market->availableModes(), EMarketMode::RESOURCE_RESOURCE))
GH.windows().createAndPushWindow<CMarketWindow>(market, visitor, marketId, onWindowClosed, market->availableModes().front()); GH.windows().createAndPushWindow<CMarketWindow>(market, visitor, marketId, onWindowClosed, EMarketMode::RESOURCE_RESOURCE);
} }
void CPlayerInterface::showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor, QueryID queryID) void CPlayerInterface::showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor, QueryID queryID)

View File

@ -31,8 +31,8 @@ CAltarArtifacts::CAltarArtifacts(const IMarket * market, const CGHeroInstance *
{ {
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
assert(dynamic_cast<const CGArtifactsAltar*>(market)); assert(market->getArtifactsStorage());
altarArtifacts = dynamic_cast<const CGArtifactsAltar*>(market); altarArtifactsStorage = market->getArtifactsStorage();
deal = std::make_shared<CButton>(Point(269, 520), AnimationPath::builtin("ALTSACR.DEF"), deal = std::make_shared<CButton>(Point(269, 520), AnimationPath::builtin("ALTSACR.DEF"),
CGI->generaltexth->zelp[585], [this]() {CAltarArtifacts::makeDeal(); }, EShortcut::MARKET_DEAL); CGI->generaltexth->zelp[585], [this]() {CAltarArtifacts::makeDeal(); }, EShortcut::MARKET_DEAL);
@ -124,7 +124,7 @@ std::shared_ptr<CArtifactsOfHeroAltar> CAltarArtifacts::getAOHset() const
void CAltarArtifacts::updateAltarSlots() void CAltarArtifacts::updateAltarSlots()
{ {
assert(altarArtifacts->artifactsInBackpack.size() <= GameConstants::ALTAR_ARTIFACTS_SLOTS); assert(altarArtifactsStorage->artifactsInBackpack.size() <= GameConstants::ALTAR_ARTIFACTS_SLOTS);
assert(tradeSlotsMap.size() <= GameConstants::ALTAR_ARTIFACTS_SLOTS); assert(tradeSlotsMap.size() <= GameConstants::ALTAR_ARTIFACTS_SLOTS);
auto tradeSlotsMapNewArts = tradeSlotsMap; auto tradeSlotsMapNewArts = tradeSlotsMap;
@ -145,12 +145,12 @@ void CAltarArtifacts::updateAltarSlots()
for(auto & tradeSlot : tradeSlotsMapNewArts) for(auto & tradeSlot : tradeSlotsMapNewArts)
{ {
assert(tradeSlot.first->id == -1); assert(tradeSlot.first->id == -1);
assert(altarArtifacts->getArtPos(tradeSlot.second) != ArtifactPosition::PRE_FIRST); assert(altarArtifactsStorage->getArtPos(tradeSlot.second) != ArtifactPosition::PRE_FIRST);
tradeSlot.first->setID(tradeSlot.second->getTypeId().num); tradeSlot.first->setID(tradeSlot.second->getTypeId().num);
tradeSlot.first->subtitle->setText(std::to_string(calcExpCost(tradeSlot.second->getTypeId()))); tradeSlot.first->subtitle->setText(std::to_string(calcExpCost(tradeSlot.second->getTypeId())));
} }
auto newArtsFromBulkMove = altarArtifacts->artifactsInBackpack; auto newArtsFromBulkMove = altarArtifactsStorage->artifactsInBackpack;
for(const auto & [altarSlot, art] : tradeSlotsMap) for(const auto & [altarSlot, art] : tradeSlotsMap)
{ {
newArtsFromBulkMove.erase(std::remove_if(newArtsFromBulkMove.begin(), newArtsFromBulkMove.end(), [artForRemove = art](auto & slotInfo) newArtsFromBulkMove.erase(std::remove_if(newArtsFromBulkMove.begin(), newArtsFromBulkMove.end(), [artForRemove = art](auto & slotInfo)
@ -178,7 +178,7 @@ void CAltarArtifacts::putBackArtifacts()
{ {
// TODO: If the backpack capacity limit is enabled, artifacts may remain on the altar. // TODO: If the backpack capacity limit is enabled, artifacts may remain on the altar.
// Perhaps should be erased in CGameHandler::objectVisitEnded if id of visited object will be available // Perhaps should be erased in CGameHandler::objectVisitEnded if id of visited object will be available
if(!altarArtifacts->artifactsInBackpack.empty()) if(!altarArtifactsStorage->artifactsInBackpack.empty())
LOCPLINT->cb->bulkMoveArtifacts(heroArts->altarId, heroArts->getHero()->id, false, true, true); LOCPLINT->cb->bulkMoveArtifacts(heroArts->altarId, heroArts->getHero()->id, false, true, true);
} }
@ -199,7 +199,7 @@ void CAltarArtifacts::onSlotClickPressed(const std::shared_ptr<CTradeableItem> &
if(const auto pickedArtInst = heroArts->getPickedArtifact()) if(const auto pickedArtInst = heroArts->getPickedArtifact())
{ {
if(pickedArtInst->canBePutAt(altarArtifacts)) if(pickedArtInst->canBePutAt(altarArtifactsStorage.get()))
{ {
if(pickedArtInst->artType->isTradable()) if(pickedArtInst->artType->isTradable())
{ {
@ -220,7 +220,7 @@ void CAltarArtifacts::onSlotClickPressed(const std::shared_ptr<CTradeableItem> &
else if(altarSlot->id != -1) else if(altarSlot->id != -1)
{ {
assert(tradeSlotsMap.at(altarSlot)); assert(tradeSlotsMap.at(altarSlot));
const auto slot = altarArtifacts->getArtPos(tradeSlotsMap.at(altarSlot)); const auto slot = altarArtifactsStorage->getArtPos(tradeSlotsMap.at(altarSlot));
assert(slot != ArtifactPosition::PRE_FIRST); assert(slot != ArtifactPosition::PRE_FIRST);
LOCPLINT->cb->swapArtifacts(ArtifactLocation(heroArts->altarId, slot), LOCPLINT->cb->swapArtifacts(ArtifactLocation(heroArts->altarId, slot),
ArtifactLocation(hero->id, GH.isKeyboardCtrlDown() ? ArtifactPosition::FIRST_AVAILABLE : ArtifactPosition::TRANSITION_POS)); ArtifactLocation(hero->id, GH.isKeyboardCtrlDown() ? ArtifactPosition::FIRST_AVAILABLE : ArtifactPosition::TRANSITION_POS));

View File

@ -26,7 +26,7 @@ public:
void putBackArtifacts(); void putBackArtifacts();
private: private:
const CArtifactSet * altarArtifacts; std::shared_ptr<CArtifactSet> altarArtifactsStorage;
std::shared_ptr<CButton> sacrificeBackpackButton; std::shared_ptr<CButton> sacrificeBackpackButton;
std::shared_ptr<CArtifactsOfHeroAltar> heroArts; std::shared_ptr<CArtifactsOfHeroAltar> heroArts;
std::map<std::shared_ptr<CTradeableItem>, const CArtifactInstance*> tradeSlotsMap; std::map<std::shared_ptr<CTradeableItem>, const CArtifactInstance*> tradeSlotsMap;

View File

@ -239,10 +239,10 @@ void CMarketWindow::createAltarArtifacts(const IMarket * market, const CGHeroIns
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
background = createBg(ImagePath::builtin("ALTRART2.bmp"), PLAYER_COLORED); background = createBg(ImagePath::builtin("ALTRART2.bmp"), PLAYER_COLORED);
auto altarArtifacts = std::make_shared<CAltarArtifacts>(market, hero, marketId); auto altarArtifactsStorage = std::make_shared<CAltarArtifacts>(market, hero, marketId);
marketWidget = altarArtifacts; marketWidget = altarArtifactsStorage;
artSets.clear(); artSets.clear();
const auto heroArts = altarArtifacts->getAOHset(); const auto heroArts = altarArtifactsStorage->getAOHset();
heroArts->clickPressedCallback = [this, heroArts](const CArtPlace & artPlace, const Point & cursorPosition) heroArts->clickPressedCallback = [this, heroArts](const CArtPlace & artPlace, const Point & cursorPosition)
{ {
clickPressedOnArtPlace(heroArts->getHero(), artPlace.slot, true, true, false); clickPressedOnArtPlace(heroArts->getHero(), artPlace.slot, true, true, false);
@ -258,7 +258,7 @@ void CMarketWindow::createAltarArtifacts(const IMarket * market, const CGHeroIns
addSet(heroArts); addSet(heroArts);
initWidgetInternals(EMarketMode::ARTIFACT_EXP, CGI->generaltexth->zelp[568]); initWidgetInternals(EMarketMode::ARTIFACT_EXP, CGI->generaltexth->zelp[568]);
updateExperience(); updateExperience();
quitButton->addCallback([altarArtifacts](){altarArtifacts->putBackArtifacts();}); quitButton->addCallback([altarArtifactsStorage](){altarArtifactsStorage->putBackArtifacts();});
} }
void CMarketWindow::createAltarCreatures(const IMarket * market, const CGHeroInstance * hero) void CMarketWindow::createAltarCreatures(const IMarket * market, const CGHeroInstance * hero)

View File

@ -291,14 +291,12 @@ CArtifactSet * CNonConstInfoCallback::getArtSet(const ArtifactLocation & loc)
{ {
return army->getStackPtr(loc.creature.value()); return army->getStackPtr(loc.creature.value());
} }
else if(auto market = dynamic_cast<CGArtifactsAltar*>(getObjInstance(loc.artHolder))) else if(auto market = dynamic_cast<IMarket*>(getObjInstance(loc.artHolder)))
{ {
return market; if(auto artSet = market->getArtifactsStorage())
} return artSet.get();
else
{
return nullptr;
} }
return nullptr;
} }
bool IGameCallback::isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero) bool IGameCallback::isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero)

View File

@ -238,11 +238,6 @@ CGMarket * MarketInstanceConstructor::createObject(IGameCallback * cb) const
return new CGUniversity(cb); return new CGUniversity(cb);
} }
} }
else if(marketModes.size() == 2)
{
if(vstd::contains(marketModes, EMarketMode::ARTIFACT_EXP))
return new CGArtifactsAltar(cb);
}
return new CGMarket(cb); return new CGMarket(cb);
} }

View File

@ -108,9 +108,4 @@ void CGUniversity::onHeroVisit(const CGHeroInstance * h) const
cb->showObjectWindow(this, EOpenWindowMode::UNIVERSITY_WINDOW, h, true); cb->showObjectWindow(this, EOpenWindowMode::UNIVERSITY_WINDOW, h, true);
} }
ArtBearer::ArtBearer CGArtifactsAltar::bearerType() const
{
return ArtBearer::ALTAR;
}
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -76,18 +76,4 @@ public:
} }
}; };
class DLL_LINKAGE CGArtifactsAltar : public CGMarket, public CArtifactSet
{
public:
using CGMarket::CGMarket;
ArtBearer::ArtBearer bearerType() const override;
template <typename Handler> void serialize(Handler & h)
{
h & static_cast<CGMarket&>(*this);
h & static_cast<CArtifactSet&>(*this);
}
};
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -145,7 +145,7 @@ void IMarket::addMarketMode(const EMarketMode mode)
marketModes.insert(mode); marketModes.insert(mode);
if(mode == EMarketMode::ARTIFACT_EXP) if(mode == EMarketMode::ARTIFACT_EXP)
altarArtifacts = std::make_shared<CArtifactSetAltar>(); altarArtifactsStorage = std::make_shared<CArtifactSetAltar>();
} }
void IMarket::addMarketMode(const std::set<EMarketMode> & modes) void IMarket::addMarketMode(const std::set<EMarketMode> & modes)
@ -159,7 +159,12 @@ void IMarket::removeMarketMode(const EMarketMode mode)
marketModes.erase(mode); marketModes.erase(mode);
if(mode == EMarketMode::ARTIFACT_EXP) if(mode == EMarketMode::ARTIFACT_EXP)
altarArtifacts.reset(); altarArtifactsStorage.reset();
}
std::shared_ptr<CArtifactSet> IMarket::getArtifactsStorage() const
{
return altarArtifactsStorage;
} }
std::vector<TradeItemBuy> IMarket::availableItemsIds(const EMarketMode mode) const std::vector<TradeItemBuy> IMarket::availableItemsIds(const EMarketMode mode) const
@ -176,14 +181,9 @@ std::vector<TradeItemBuy> IMarket::availableItemsIds(const EMarketMode mode) con
return ret; return ret;
} }
std::vector<EMarketMode> IMarket::availableModes() const std::set<EMarketMode> IMarket::availableModes() const
{ {
std::vector<EMarketMode> ret; return marketModes;
for (EMarketMode i = static_cast<EMarketMode>(0); i < EMarketMode::MARKET_AFTER_LAST_PLACEHOLDER; i = vstd::next(i, 1))
if(allowsTrade(i))
ret.push_back(i);
return ret;
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -31,20 +31,20 @@ public:
void addMarketMode(const EMarketMode mode); void addMarketMode(const EMarketMode mode);
void addMarketMode(const std::set<EMarketMode> & modes); void addMarketMode(const std::set<EMarketMode> & modes);
void removeMarketMode(const EMarketMode mode); void removeMarketMode(const EMarketMode mode);
std::set<EMarketMode> availableModes() const;
std::shared_ptr<CArtifactSet> getArtifactsStorage() const;
bool getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode) const; //val1 - how many units of id1 player has to give to receive val2 units bool getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode) const; //val1 - how many units of id1 player has to give to receive val2 units
std::vector<EMarketMode> availableModes() const;
template <typename Handler> void serialize(Handler & h) template <typename Handler> void serialize(Handler & h)
{ {
h & marketModes; h & marketModes;
if(h.loadingGamestate && vstd::contains(marketModes, EMarketMode::ARTIFACT_EXP)) if(h.loadingGamestate && vstd::contains(marketModes, EMarketMode::ARTIFACT_EXP))
altarArtifacts = std::make_shared<CArtifactSetAltar>(); altarArtifactsStorage = std::make_shared<CArtifactSetAltar>();
} }
private: private:
std::shared_ptr<CArtifactSetAltar> altarArtifacts; std::shared_ptr<CArtifactSetAltar> altarArtifactsStorage;
std::set<EMarketMode> marketModes; std::set<EMarketMode> marketModes;
}; };

View File

@ -132,8 +132,6 @@ void registerTypesMapObjects(Serializer &s)
//s.template registerType<CObstacleInstance>(); //s.template registerType<CObstacleInstance>();
s.template registerType<CObstacleInstance, SpellCreatedObstacle>(); s.template registerType<CObstacleInstance, SpellCreatedObstacle>();
s.template registerType<CGMarket, CGArtifactsAltar>();
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -3909,15 +3909,15 @@ bool CGameHandler::sacrificeCreatures(const IMarket * market, const CGHeroInstan
return true; return true;
} }
bool CGameHandler::sacrificeArtifact(const IMarket * m, const CGHeroInstance * hero, const std::vector<ArtifactInstanceID> & arts) bool CGameHandler::sacrificeArtifact(const IMarket * market, const CGHeroInstance * hero, const ObjectInstanceID & marketId, const std::vector<ArtifactInstanceID> & arts)
{ {
if (!hero) if (!hero)
COMPLAIN_RET("You need hero to sacrifice artifact!"); COMPLAIN_RET("You need hero to sacrifice artifact!");
if(hero->getAlignment() == EAlignment::EVIL) if(hero->getAlignment() == EAlignment::EVIL)
COMPLAIN_RET("Evil hero can't sacrifice artifact!"); COMPLAIN_RET("Evil hero can't sacrifice artifact!");
assert(m); assert(market);
auto altarObj = dynamic_cast<const CGArtifactsAltar*>(m); const auto artSet = getArtSet(marketId);
int expSum = 0; int expSum = 0;
auto finish = [this, &hero, &expSum]() auto finish = [this, &hero, &expSum]()
@ -3927,15 +3927,15 @@ bool CGameHandler::sacrificeArtifact(const IMarket * m, const CGHeroInstance * h
for(const auto & artInstId : arts) for(const auto & artInstId : arts)
{ {
if(auto art = altarObj->getArtByInstanceId(artInstId)) if(auto art = artSet->getArtByInstanceId(artInstId))
{ {
if(art->artType->isTradable()) if(art->artType->isTradable())
{ {
int dmp; int dmp;
int expToGive; int expToGive;
m->getOffer(art->getTypeId(), 0, dmp, expToGive, EMarketMode::ARTIFACT_EXP); market->getOffer(art->getTypeId(), 0, dmp, expToGive, EMarketMode::ARTIFACT_EXP);
expSum += expToGive; expSum += expToGive;
removeArtifact(ArtifactLocation(altarObj->id, altarObj->getArtPos(art))); removeArtifact(ArtifactLocation(marketId, artSet->getArtPos(art)));
} }
else else
{ {

View File

@ -281,7 +281,7 @@ public:
void start(bool resume); void start(bool resume);
void tick(int millisecondsPassed); void tick(int millisecondsPassed);
bool sacrificeArtifact(const IMarket * m, const CGHeroInstance * hero, const std::vector<ArtifactInstanceID> & arts); bool sacrificeArtifact(const IMarket * market, const CGHeroInstance * hero, const ObjectInstanceID & marketId, const std::vector<ArtifactInstanceID> & arts);
void spawnWanderingMonsters(CreatureID creatureID); void spawnWanderingMonsters(CreatureID creatureID);
// Check for victory and loss conditions // Check for victory and loss conditions

View File

@ -347,7 +347,7 @@ void ApplyGhNetPackVisitor::visitTradeOnMarketplace(TradeOnMarketplace & pack)
for(auto const & artInstId : pack.r1) for(auto const & artInstId : pack.r1)
positions.push_back(artInstId.as<ArtifactInstanceID>()); positions.push_back(artInstId.as<ArtifactInstanceID>());
result = gh.sacrificeArtifact(market, hero, positions); result = gh.sacrificeArtifact(market, hero, pack.marketId, positions);
return; return;
} }
default: default: