1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

spell replacement works

This commit is contained in:
Laserlicht 2024-09-27 23:52:33 +02:00
parent a9327b3fa3
commit 857b2e9a35
6 changed files with 37 additions and 19 deletions

View File

@ -37,6 +37,7 @@ public:
void visitHeroVisitCastle(HeroVisitCastle & pack) override;
void visitSetMana(SetMana & pack) override;
void visitSetMovePoints(SetMovePoints & pack) override;
void visitSetTownSpells(SetTownSpells & pack) override;
void visitFoWChange(FoWChange & pack) override;
void visitChangeStackCount(ChangeStackCount & pack) override;
void visitSetStackType(SetStackType & pack) override;

View File

@ -14,6 +14,7 @@
#include "CPlayerInterface.h"
#include "CGameInfo.h"
#include "windows/GUIClasses.h"
#include "windows/CCastleInterface.h"
#include "mapView/mapHandler.h"
#include "adventureMap/AdventureMapInterface.h"
#include "adventureMap/CInGameConsole.h"
@ -172,6 +173,12 @@ void ApplyClientNetPackVisitor::visitSetMovePoints(SetMovePoints & pack)
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroMovePointsChanged, h);
}
void ApplyClientNetPackVisitor::visitSetTownSpells(SetTownSpells & pack)
{
for(const auto & win : GH.windows().findWindows<CMageGuildScreen>())
win->update();
}
void ApplyClientNetPackVisitor::visitFoWChange(FoWChange & pack)
{
for(auto &i : cl.playerint)

View File

@ -1966,7 +1966,7 @@ void CFortScreen::RecruitArea::showPopupWindow(const Point & cursorPosition)
}
CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner, const ImagePath & imagename)
: CWindowObject(BORDERED, imagename), town(owner->town)
: CWindowObject(BORDERED, imagename), townId(owner->town->id)
{
OBJECT_CONSTRUCTION;
@ -1982,6 +1982,12 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner, const ImagePath & i
exit = std::make_shared<CButton>(Point(748, 556), AnimationPath::builtin("TPMAGE1.DEF"), CButton::tooltip(CGI->generaltexth->allTexts[593]), [&](){ close(); }, EShortcut::GLOBAL_RETURN);
update();
}
void CMageGuildScreen::update()
{
OBJECT_CONSTRUCTION;
static const std::vector<std::vector<Point> > positions =
{
{Point(222,445), Point(312,445), Point(402,445), Point(520,445), Point(610,445), Point(700,445)},
@ -1991,21 +1997,28 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner, const ImagePath & i
{Point(491,325), Point(591,325)}
};
for(size_t i=0; i<owner->town->town->mageLevel; i++)
spells.clear();
emptyScrolls.clear();
const CGTownInstance * town = LOCPLINT->cb->getTown(townId);
for(size_t i=0; i<town->town->mageLevel; i++)
{
size_t spellCount = owner->town->spellsAtLevel((int)i+1,false); //spell at level with -1 hmmm?
size_t spellCount = town->spellsAtLevel((int)i+1,false); //spell at level with -1 hmmm?
for(size_t j=0; j<spellCount; j++)
{
if(i<owner->town->mageGuildLevel() && owner->town->spells[i].size()>j)
spells.push_back(std::make_shared<Scroll>(positions[i][j], owner->town->spells[i][j].toSpell(), town));
if(i<town->mageGuildLevel() && town->spells[i].size()>j)
spells.push_back(std::make_shared<Scroll>(positions[i][j], town->spells[i][j].toSpell(), townId));
else
emptyScrolls.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("TPMAGES.DEF"), 1, 0, positions[i][j].x, positions[i][j].y));
}
}
redraw();
}
CMageGuildScreen::Scroll::Scroll(Point position, const CSpell *Spell, const CGTownInstance *town)
: spell(Spell), town(town)
CMageGuildScreen::Scroll::Scroll(Point position, const CSpell *Spell, ObjectInstanceID townId)
: spell(Spell), townId(townId)
{
OBJECT_CONSTRUCTION;
@ -2017,6 +2030,7 @@ CMageGuildScreen::Scroll::Scroll(Point position, const CSpell *Spell, const CGTo
void CMageGuildScreen::Scroll::clickPressed(const Point & cursorPosition)
{
const CGTownInstance * town = LOCPLINT->cb->getTown(townId);
if(LOCPLINT->cb->getSettings().getBoolean(EGameSettings::TOWNS_SPELL_RESEARCH))
LOCPLINT->cb->spellResearch(town);
else

View File

@ -379,10 +379,10 @@ class CMageGuildScreen : public CStatusbarWindow
{
const CSpell * spell;
std::shared_ptr<CAnimImage> image;
const CGTownInstance *town;
ObjectInstanceID townId;
public:
Scroll(Point position, const CSpell *Spell, const CGTownInstance *town);
Scroll(Point position, const CSpell *Spell, ObjectInstanceID townId);
void clickPressed(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
void hover(bool on) override;
@ -394,10 +394,11 @@ class CMageGuildScreen : public CStatusbarWindow
std::shared_ptr<CMinorResDataBar> resdatabar;
const CGTownInstance *town;
ObjectInstanceID townId;
public:
CMageGuildScreen(CCastleInterface * owner, const ImagePath & image);
void update();
};
/// The blacksmith window where you can buy available in town war machine

View File

@ -2248,21 +2248,17 @@ bool CGameHandler::spellResearch(ObjectInstanceID tid)
return false;
CGTownInstance *t = gs->getTown(tid);
auto spells = t->spells.at(1);
auto spells = t->spells.at(0);
auto spell = SpellID(SpellID::FLY);
spells.at(0) = spell;
setTownSpells(t, 1, spells);
spellResearchFinished(tid);
return true;
}
setTownSpells(t, 0, spells);
void CGameHandler::spellResearchFinished(ObjectInstanceID tid)
{
const CGTownInstance * t = getTown(tid);
if(t->visitingHero)
giveSpells(t, t->visitingHero);
if(t->garrisonHero)
giveSpells(t, t->garrisonHero);
return true;
}
bool CGameHandler::recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dstid, CreatureID crid, ui32 cram, si32 fromLvl, PlayerColor player)

View File

@ -220,7 +220,6 @@ public:
bool visitTownBuilding(ObjectInstanceID tid, BuildingID bid);
bool razeStructure(ObjectInstanceID tid, BuildingID bid);
bool spellResearch(ObjectInstanceID tid);
void spellResearchFinished(ObjectInstanceID tid);
bool disbandCreature( ObjectInstanceID id, SlotID pos );
bool arrangeStacks( ObjectInstanceID id1, ObjectInstanceID id2, ui8 what, SlotID p1, SlotID p2, si32 val, PlayerColor player);
bool bulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot);