1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-16 10:19:47 +02:00
vcmi/client/windows/CSpellWindow.cpp

625 lines
18 KiB
C++
Raw Normal View History

/*
* CSpellWindow.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"
2008-09-10 15:19:48 +03:00
#include "CSpellWindow.h"
2015-04-11 08:24:51 +02:00
#include "../../lib/ScopeGuard.h"
#include "GUIClasses.h"
#include "InfoWindows.h"
#include "CCastleInterface.h"
2008-09-10 15:19:48 +03:00
#include "../CGameInfo.h"
#include "../CPlayerInterface.h"
#include "../PlayerLocalState.h"
#include "../CVideoHandler.h"
#include "../battle/BattleInterface.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../widgets/MiscWidgets.h"
#include "../widgets/CComponent.h"
2016-10-17 03:05:33 +02:00
#include "../widgets/TextControls.h"
#include "../adventureMap/AdventureMapInterface.h"
#include "../render/CAnimation.h"
#include "../../CCallback.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CGeneralTextHandler.h"
#include "../../lib/spells/CSpellHandler.h"
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
#include "../../lib/spells/Problem.h"
#include "../../lib/GameConstants.h"
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
#include "../../lib/mapObjects/CGHeroInstance.h"
2008-09-10 15:19:48 +03:00
CSpellWindow::InteractiveArea::InteractiveArea(const Rect & myRect, std::function<void()> funcL, int helpTextId, CSpellWindow * _owner)
2008-09-10 15:19:48 +03:00
{
2023-06-13 18:33:35 +02:00
addUsedEvents(LCLICK | SHOW_POPUP | HOVER);
2008-09-10 15:19:48 +03:00
pos = myRect;
2008-09-11 15:29:22 +03:00
onLeft = funcL;
hoverText = CGI->generaltexth->zelp[helpTextId].first;
helpText = CGI->generaltexth->zelp[helpTextId].second;
owner = _owner;
2008-09-10 15:19:48 +03:00
}
void CSpellWindow::InteractiveArea::clickPressed(const Point & cursorPosition)
2008-09-10 15:19:48 +03:00
{
onLeft();
2008-09-10 15:19:48 +03:00
}
void CSpellWindow::InteractiveArea::showPopupWindow(const Point & cursorPosition)
2008-09-11 15:29:22 +03:00
{
CRClickPopup::createAndPush(helpText);
2008-09-11 15:29:22 +03:00
}
void CSpellWindow::InteractiveArea::hover(bool on)
2008-09-11 15:29:22 +03:00
{
if(on)
owner->statusBar->write(hoverText);
2008-09-11 15:29:22 +03:00
else
owner->statusBar->clear();
2008-09-11 15:29:22 +03:00
}
2016-10-16 09:32:12 +02:00
class SpellbookSpellSorter
{
public:
bool operator()(const CSpell * A, const CSpell * B)
{
if(A->getLevel() < B->getLevel())
2016-10-16 09:32:12 +02:00
return true;
if(A->getLevel() > B->getLevel())
2016-10-16 09:32:12 +02:00
return false;
for(auto schoolId = 0; schoolId < GameConstants::DEFAULT_SCHOOLS; schoolId++)
2016-10-16 09:32:12 +02:00
{
if(A->school.at(SpellSchool(schoolId)) && !B->school.at(SpellSchool(schoolId)))
2016-10-16 09:32:12 +02:00
return true;
if(!A->school.at(SpellSchool(schoolId)) && B->school.at(SpellSchool(schoolId)))
2016-10-16 09:32:12 +02:00
return false;
}
return A->getNameTranslated() < B->getNameTranslated();
2016-10-16 09:32:12 +02:00
}
} spellsorter;
2016-10-16 08:27:22 +02:00
CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells):
CWindowObject(PLAYER_COLORED, "SpelBack"),
battleSpellsOnly(openOnBattleSpells),
selectedTab(4),
currentPage(0),
myHero(_myHero),
myInt(_myInt)
2008-09-10 15:19:48 +03:00
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
//initializing castable spells
2016-10-16 09:32:12 +02:00
mySpells.reserve(CGI->spellh->objects.size());
for(const CSpell * spell : CGI->spellh->objects)
{
2016-10-16 09:32:12 +02:00
if(!spell->isCreatureAbility() && myHero->canCastThisSpell(spell))
mySpells.push_back(spell);
}
2016-10-16 09:32:12 +02:00
std::sort(mySpells.begin(), mySpells.end(), spellsorter);
//initializing sizes of spellbook's parts
for(auto & elem : sitesPerTabAdv)
elem = 0;
for(auto & elem : sitesPerTabBattle)
elem = 0;
2016-10-16 09:32:12 +02:00
for(const auto spell : mySpells)
{
int * sitesPerOurTab = spell->isCombat() ? sitesPerTabBattle : sitesPerTabAdv;
++sitesPerOurTab[4];
spell->forEachSchool([&sitesPerOurTab](const SpellSchool & school, bool & stop)
{
++sitesPerOurTab[school];
});
}
if(sitesPerTabAdv[4] % 12 == 0)
sitesPerTabAdv[4]/=12;
else
sitesPerTabAdv[4] = sitesPerTabAdv[4]/12 + 1;
for(int v=0; v<4; ++v)
{
if(sitesPerTabAdv[v] <= 10)
sitesPerTabAdv[v] = 1;
else
{
if((sitesPerTabAdv[v] - 10) % 12 == 0)
sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 1;
else
sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 2;
}
}
if(sitesPerTabBattle[4] % 12 == 0)
sitesPerTabBattle[4]/=12;
else
sitesPerTabBattle[4] = sitesPerTabBattle[4]/12 + 1;
for(int v=0; v<4; ++v)
{
if(sitesPerTabBattle[v] <= 10)
sitesPerTabBattle[v] = 1;
else
{
if((sitesPerTabBattle[v] - 10) % 12 == 0)
sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 1;
else
sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 2;
}
}
//numbers of spell pages computed
leftCorner = std::make_shared<CPicture>("SpelTrnL.bmp", 97, 77);
rightCorner = std::make_shared<CPicture>("SpelTrnR.bmp", 487, 72);
spellIcons = std::make_shared<CAnimation>("Spells");
schoolTab = std::make_shared<CAnimImage>("SpelTab", selectedTab, 0, 524, 88);
schoolPicture = std::make_shared<CAnimImage>("Schools", 0, 0, 117, 74);
2016-10-16 14:27:35 +02:00
schoolBorders[0] = std::make_shared<CAnimation>("SplevA.def");
schoolBorders[1] = std::make_shared<CAnimation>("SplevF.def");
schoolBorders[2] = std::make_shared<CAnimation>("SplevW.def");
schoolBorders[3] = std::make_shared<CAnimation>("SplevE.def");
for(auto item : schoolBorders)
item->preload();
2023-03-09 15:36:46 +02:00
mana = std::make_shared<CLabel>(435, 426, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, std::to_string(myHero->mana));
statusBar = CGStatusBar::create(7, 569, "Spelroll.bmp");
2008-09-11 15:29:22 +03:00
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 479 + pos.x, 405 + pos.y, 36, 56), std::bind(&CSpellWindow::fexitb, this), 460, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 221 + pos.x, 405 + pos.y, 36, 56), std::bind(&CSpellWindow::fbattleSpellsb, this), 453, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 355 + pos.x, 405 + pos.y, 36, 56), std::bind(&CSpellWindow::fadvSpellsb, this), 452, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 418 + pos.x, 405 + pos.y, 36, 56), std::bind(&CSpellWindow::fmanaPtsb, this), 459, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 94 + pos.y, 36, 56), std::bind(&CSpellWindow::selectSchool, this, 0), 454, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 151 + pos.y, 45, 35), std::bind(&CSpellWindow::selectSchool, this, 3), 457, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 210 + pos.y, 45, 35), std::bind(&CSpellWindow::selectSchool, this, 1), 455, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 270 + pos.y, 45, 35), std::bind(&CSpellWindow::selectSchool, this, 2), 456, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 330 + pos.y, 45, 35), std::bind(&CSpellWindow::selectSchool, this, 4), 458, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 97 + pos.x, 77 + pos.y, leftCorner->pos.h, leftCorner->pos.w ), std::bind(&CSpellWindow::fLcornerb, this), 450, this));
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 487 + pos.x, 72 + pos.y, rightCorner->pos.h, rightCorner->pos.w ), std::bind(&CSpellWindow::fRcornerb, this), 451, this));
//areas for spells
int xpos = 117 + pos.x, ypos = 90 + pos.y;
for(int v=0; v<12; ++v)
{
spellAreas[v] = std::make_shared<SpellArea>( Rect(xpos, ypos, 65, 78), this);
if(v == 5) //to right page
{
xpos = 336 + pos.x; ypos = 90 + pos.y;
}
else
{
if(v%2 == 0)
{
xpos+=85;
}
else
{
xpos -= 85; ypos+=97;
}
}
}
selectedTab = battleSpellsOnly ? myInt->localState->spellbookSettings.spellbookLastTabBattle : myInt->localState->spellbookSettings.spellbookLastTabAdvmap;
schoolTab->setFrame(selectedTab, 0);
int cp = battleSpellsOnly ? myInt->localState->spellbookSettings.spellbookLastPageBattle : myInt->localState->spellbookSettings.spellbokLastPageAdvmap;
// spellbook last page battle index is not reset after battle, so this needs to stay here
2016-10-16 14:27:35 +02:00
vstd::abetween(cp, 0, std::max(0, pagesWithinCurrentTab() - 1));
setCurrentPage(cp);
computeSpellsPerArea();
addUsedEvents(KEYBOARD);
2008-09-10 15:19:48 +03:00
}
CSpellWindow::~CSpellWindow()
{
}
void CSpellWindow::fexitb()
{
(myInt->battleInt ? myInt->localState->spellbookSettings.spellbookLastTabBattle : myInt->localState->spellbookSettings.spellbookLastTabAdvmap) = selectedTab;
(myInt->battleInt ? myInt->localState->spellbookSettings.spellbookLastPageBattle : myInt->localState->spellbookSettings.spellbokLastPageAdvmap) = currentPage;
close();
2008-09-10 15:19:48 +03:00
}
2008-09-11 15:29:22 +03:00
void CSpellWindow::fadvSpellsb()
{
if(battleSpellsOnly == true)
{
2009-06-20 04:42:19 +03:00
turnPageRight();
2009-06-20 05:14:25 +03:00
battleSpellsOnly = false;
2016-10-16 14:27:35 +02:00
setCurrentPage(0);
2009-06-20 05:14:25 +03:00
}
computeSpellsPerArea();
2008-09-11 15:29:22 +03:00
}
void CSpellWindow::fbattleSpellsb()
{
if(battleSpellsOnly == false)
{
2009-06-20 04:42:19 +03:00
turnPageLeft();
2009-06-20 05:14:25 +03:00
battleSpellsOnly = true;
2016-10-16 14:27:35 +02:00
setCurrentPage(0);
2009-06-20 05:14:25 +03:00
}
computeSpellsPerArea();
2008-09-11 15:29:22 +03:00
}
void CSpellWindow::fmanaPtsb()
{
}
void CSpellWindow::selectSchool(int school)
2008-09-11 15:29:22 +03:00
{
if(selectedTab != school)
{
if(selectedTab < school)
turnPageLeft();
else
turnPageRight();
selectedTab = school;
schoolTab->setFrame(selectedTab, 0);
2016-10-16 14:27:35 +02:00
setCurrentPage(0);
2009-06-20 05:14:25 +03:00
}
computeSpellsPerArea();
}
void CSpellWindow::fLcornerb()
{
if(currentPage>0)
{
2009-06-20 04:42:19 +03:00
turnPageLeft();
2016-10-16 14:27:35 +02:00
setCurrentPage(currentPage - 1);
2009-06-20 04:42:19 +03:00
}
computeSpellsPerArea();
}
void CSpellWindow::fRcornerb()
{
if((currentPage + 1) < (pagesWithinCurrentTab()))
{
2009-06-20 04:42:19 +03:00
turnPageRight();
2016-10-16 14:27:35 +02:00
setCurrentPage(currentPage + 1);
2009-06-20 04:42:19 +03:00
}
computeSpellsPerArea();
2008-09-11 15:29:22 +03:00
}
void CSpellWindow::show(Canvas & to)
{
statusBar->show(to);
}
void CSpellWindow::computeSpellsPerArea()
{
2016-10-16 09:32:12 +02:00
std::vector<const CSpell *> spellsCurSite;
spellsCurSite.reserve(mySpells.size());
for(const CSpell * spell : mySpells)
{
if(spell->isCombat() ^ !battleSpellsOnly
&& ((selectedTab == 4) || spell->school.at(SpellSchool(selectedTab)))
)
{
2016-10-16 09:32:12 +02:00
spellsCurSite.push_back(spell);
}
}
2016-10-16 09:32:12 +02:00
if(selectedTab == 4)
{
if(spellsCurSite.size() > 12)
{
2016-10-16 09:32:12 +02:00
spellsCurSite = std::vector<const CSpell *>(spellsCurSite.begin() + currentPage*12, spellsCurSite.end());
if(spellsCurSite.size() > 12)
{
spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
}
}
}
else //selectedTab == 0, 1, 2 or 3
{
if(spellsCurSite.size() > 10)
{
if(currentPage == 0)
{
spellsCurSite.erase(spellsCurSite.begin()+10, spellsCurSite.end());
}
else
{
2016-10-16 09:32:12 +02:00
spellsCurSite = std::vector<const CSpell *>(spellsCurSite.begin() + (currentPage-1)*12 + 10, spellsCurSite.end());
if(spellsCurSite.size() > 12)
{
spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
}
}
}
}
//applying
if(selectedTab == 4 || currentPage != 0)
{
for(size_t c=0; c<12; ++c)
{
2016-10-16 09:32:12 +02:00
if(c < spellsCurSite.size())
{
spellAreas[c]->setSpell(spellsCurSite[c]);
}
else
{
2016-10-16 09:32:12 +02:00
spellAreas[c]->setSpell(nullptr);
}
}
}
else
{
2016-10-16 09:32:12 +02:00
spellAreas[0]->setSpell(nullptr);
spellAreas[1]->setSpell(nullptr);
for(size_t c=0; c<10; ++c)
{
2016-10-16 09:32:12 +02:00
if(c < spellsCurSite.size())
spellAreas[c+2]->setSpell(spellsCurSite[c]);
else
2016-10-16 09:32:12 +02:00
spellAreas[c+2]->setSpell(nullptr);
}
}
redraw();
2008-09-10 15:19:48 +03:00
}
2016-10-16 14:27:35 +02:00
void CSpellWindow::setCurrentPage(int value)
{
currentPage = value;
schoolPicture->visible = selectedTab!=4 && currentPage == 0;
2016-10-16 14:27:35 +02:00
if(selectedTab != 4)
schoolPicture->setFrame(selectedTab, 0);
2016-10-16 14:27:35 +02:00
leftCorner->visible = currentPage != 0;
rightCorner->visible = (currentPage+1) < pagesWithinCurrentTab();
2016-10-17 03:05:33 +02:00
2023-03-09 15:36:46 +02:00
mana->setText(std::to_string(myHero->mana));//just in case, it will be possible to cast spell without closing book
2016-10-16 14:27:35 +02:00
}
2009-06-20 04:42:19 +03:00
void CSpellWindow::turnPageLeft()
{
if(settings["video"]["spellbookAnimation"].Bool())
CCS->videoh->openAndPlayVideo("PGTRNLFT.SMK", pos.x+13, pos.y+15);
2009-06-20 04:42:19 +03:00
}
void CSpellWindow::turnPageRight()
{
if(settings["video"]["spellbookAnimation"].Bool())
CCS->videoh->openAndPlayVideo("PGTRNRGH.SMK", pos.x+13, pos.y+15);
2009-06-20 04:42:19 +03:00
}
void CSpellWindow::keyPressed(EShortcut key)
{
switch(key)
2015-04-11 08:24:51 +02:00
{
case EShortcut::GLOBAL_RETURN:
fexitb();
break;
2023-04-28 13:22:03 +02:00
case EShortcut::MOVE_LEFT:
fLcornerb();
break;
2023-04-28 13:22:03 +02:00
case EShortcut::MOVE_RIGHT:
fRcornerb();
break;
2023-04-28 13:22:03 +02:00
case EShortcut::MOVE_UP:
case EShortcut::MOVE_DOWN:
{
2023-04-28 13:22:03 +02:00
bool down = key == EShortcut::MOVE_DOWN;
static const int schoolsOrder[] = { 0, 3, 1, 2, 4 };
int index = -1;
while(schoolsOrder[++index] != selectedTab);
index += (down ? 1 : -1);
vstd::abetween<int>(index, 0, std::size(schoolsOrder) - 1);
if(selectedTab != schoolsOrder[index])
selectSchool(schoolsOrder[index]);
break;
}
case EShortcut::SPELLBOOK_TAB_COMBAT:
2012-09-30 15:19:14 +03:00
fbattleSpellsb();
break;
case EShortcut::SPELLBOOK_TAB_ADVENTURE:
2012-09-30 15:19:14 +03:00
fadvSpellsb();
break;
}
}
int CSpellWindow::pagesWithinCurrentTab()
{
return battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab];
}
CSpellWindow::SpellArea::SpellArea(Rect pos, CSpellWindow * owner)
{
this->pos = pos;
this->owner = owner;
2023-06-13 18:33:35 +02:00
addUsedEvents(LCLICK | SHOW_POPUP | HOVER);
schoolLevel = -1;
2016-10-16 09:32:12 +02:00
mySpell = nullptr;
2016-10-16 12:22:07 +02:00
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
2016-10-17 04:05:48 +02:00
image = std::make_shared<CAnimImage>(owner->spellIcons, 0, 0);
2016-10-16 12:22:07 +02:00
image->visible = false;
2016-10-17 04:05:48 +02:00
name = std::make_shared<CLabel>(39, 70, FONT_TINY, ETextAlignment::CENTER);
level = std::make_shared<CLabel>(39, 82, FONT_TINY, ETextAlignment::CENTER);
cost = std::make_shared<CLabel>(39, 94, FONT_TINY, ETextAlignment::CENTER);
2016-10-18 01:15:43 +02:00
for(auto l : {name, level, cost})
l->setAutoRedraw(false);
}
CSpellWindow::SpellArea::~SpellArea() = default;
void CSpellWindow::SpellArea::clickPressed(const Point & cursorPosition)
{
if(mySpell)
{
auto spellCost = owner->myInt->cb->getSpellCost(mySpell, owner->myHero);
if(spellCost > owner->myHero->mana) //insufficient mana
{
LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[206]) % spellCost % owner->myHero->mana));
2010-07-26 23:56:39 +03:00
return;
}
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
//anything that is not combat spell is adventure spell
//this not an error in general to cast even creature ability with hero
const bool combatSpell = mySpell->isCombat();
if(combatSpell == mySpell->isAdventure())
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
{
logGlobal->error("Spell have invalid flags");
return;
}
const bool inCombat = owner->myInt->battleInt != nullptr;
const bool inCastle = owner->myInt->castleInt != nullptr;
//battle spell on adv map or adventure map spell during combat => display infowindow, not cast
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
if((combatSpell ^ inCombat) || inCastle)
{
std::vector<std::shared_ptr<CComponent>> hlp(1, std::make_shared<CComponent>(CComponent::spell, mySpell->id, 0));
LOCPLINT->showInfoDialog(mySpell->getDescriptionTranslated(schoolLevel), hlp);
}
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
else if(combatSpell)
2008-10-17 20:43:25 +03:00
{
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
spells::detail::ProblemImpl problem;
if(mySpell->canBeCast(problem, owner->myInt->cb.get(), spells::Mode::HERO, owner->myHero))
{
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
owner->myInt->battleInt->castThisSpell(mySpell->id);
owner->fexitb();
}
else
{
std::vector<std::string> texts;
problem.getAll(texts);
if(!texts.empty())
LOCPLINT->showInfoDialog(texts.front());
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
else
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.spellUnknownProblem"));
}
2008-10-17 20:43:25 +03:00
}
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
else //adventure spell
2010-01-29 18:19:12 +02:00
{
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
const CGHeroInstance * h = owner->myHero;
GH.windows().popWindows(1);
auto guard = vstd::makeScopeGuard([this]()
2015-04-11 08:24:51 +02:00
{
owner->myInt->localState->spellbookSettings.spellbookLastTabAdvmap = owner->selectedTab;
owner->myInt->localState->spellbookSettings.spellbokLastPageAdvmap = owner->currentPage;
});
2010-03-11 01:16:30 +02:00
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
if(mySpell->getTargetType() == spells::AimType::LOCATION)
2016-10-16 09:32:12 +02:00
adventureInt->enterCastingMode(mySpell);
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
else if(mySpell->getTargetType() == spells::AimType::NO_TARGET)
2016-10-17 04:42:29 +02:00
owner->myInt->cb->castSpell(h, mySpell->id);
else
logGlobal->error("Invalid spell target type");
2010-01-29 18:19:12 +02:00
}
}
}
void CSpellWindow::SpellArea::showPopupWindow(const Point & cursorPosition)
{
if(mySpell)
{
2009-11-08 16:44:58 +02:00
std::string dmgInfo;
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
auto causedDmg = owner->myInt->cb->estimateSpellDamage(mySpell, owner->myHero);
2016-10-16 09:32:12 +02:00
if(causedDmg == 0 || mySpell->id == SpellID::TITANS_LIGHTNING_BOLT) //Titan's Lightning Bolt already has damage info included
dmgInfo.clear();
2009-11-08 16:44:58 +02:00
else
{
dmgInfo = CGI->generaltexth->allTexts[343];
2023-03-09 15:36:46 +02:00
boost::algorithm::replace_first(dmgInfo, "%d", std::to_string(causedDmg));
2009-11-08 16:44:58 +02:00
}
CRClickPopup::createAndPush(mySpell->getDescriptionTranslated(schoolLevel) + dmgInfo, std::make_shared<CComponent>(CComponent::spell, mySpell->id));
}
}
void CSpellWindow::SpellArea::hover(bool on)
{
2016-10-16 09:32:12 +02:00
if(mySpell)
{
if(on)
owner->statusBar->write(boost::str(boost::format("%s (%s)") % mySpell->getNameTranslated() % CGI->generaltexth->allTexts[171+mySpell->getLevel()]));
else
owner->statusBar->clear();
}
}
2016-10-16 09:32:12 +02:00
void CSpellWindow::SpellArea::setSpell(const CSpell * spell)
{
schoolBorder.reset();
2016-10-16 12:22:07 +02:00
image->visible = false;
2016-10-17 04:05:48 +02:00
name->setText("");
level->setText("");
cost->setText("");
2016-10-16 09:32:12 +02:00
mySpell = spell;
if(mySpell)
{
int32_t whichSchool = 0; //0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic,
2016-10-16 09:32:12 +02:00
schoolLevel = owner->myHero->getSpellSchoolLevel(mySpell, &whichSchool);
auto spellCost = owner->myInt->cb->getSpellCost(mySpell, owner->myHero);
2016-10-16 09:43:49 +02:00
2016-10-16 12:22:07 +02:00
image->setFrame(mySpell->id);
image->visible = true;
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
schoolBorder = std::make_shared<CAnimImage>(owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab], schoolLevel);
}
2016-10-17 04:05:48 +02:00
ColorRGBA firstLineColor, secondLineColor;
2016-10-17 04:05:48 +02:00
if(spellCost > owner->myHero->mana) //hero cannot cast this spell
{
firstLineColor = Colors::WHITE;
2023-01-30 00:12:43 +02:00
secondLineColor = Colors::ORANGE;
2016-10-17 04:05:48 +02:00
}
else
{
firstLineColor = Colors::YELLOW;
secondLineColor = Colors::WHITE;
}
name->color = firstLineColor;
name->setText(mySpell->getNameTranslated());
2016-10-17 04:05:48 +02:00
level->color = secondLineColor;
if(schoolLevel > 0)
{
boost::format fmt("%s/%s");
fmt % CGI->generaltexth->allTexts[171 + mySpell->getLevel()];
fmt % CGI->generaltexth->levels[3+(schoolLevel-1)];//lines 4-6
2016-10-17 04:05:48 +02:00
level->setText(fmt.str());
}
else
level->setText(CGI->generaltexth->allTexts[171 + mySpell->getLevel()]);
2016-10-17 04:05:48 +02:00
cost->color = secondLineColor;
boost::format costfmt("%s: %d");
costfmt % CGI->generaltexth->allTexts[387] % spellCost;
cost->setText(costfmt.str());
2016-10-16 09:32:12 +02:00
}
}