2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2008-09-10 15:19:48 +03:00
|
|
|
#include "CSpellWindow.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2008-09-12 11:51:46 +03:00
|
|
|
#include "Graphics.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CDefHandler.h"
|
|
|
|
#include "../lib/CObjectHandler.h"
|
|
|
|
#include "../lib/CSpellHandler.h"
|
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
|
|
|
#include "CVideoHandler.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "CAdvmapInterface.h"
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "battle/CBattleInterface.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "CGameInfo.h"
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/SDL_Extensions.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "CMessage.h"
|
|
|
|
#include "CPlayerInterface.h"
|
2009-08-23 16:41:57 +03:00
|
|
|
#include "../CCallback.h"
|
2010-08-17 17:58:13 +03:00
|
|
|
#include "CBitmapHandler.h"
|
2011-02-10 16:44:21 +02:00
|
|
|
#include "../lib/CHeroHandler.h"
|
2011-02-15 21:54:55 +02:00
|
|
|
#include "../lib/BattleState.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "../lib/GameConstants.h"
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/CGuiHandler.h"
|
2013-04-04 17:58:54 +03:00
|
|
|
#include "CMT.h"
|
2008-09-10 15:19:48 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-02-19 18:02:34 +02:00
|
|
|
SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function<void()> funcL,
|
|
|
|
const std::string & textR, boost::function<void()> funcHon, boost::function<void()> funcHoff, CPlayerInterface * _myInt)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(LCLICK | RCLICK | HOVER);
|
2008-09-10 15:19:48 +03:00
|
|
|
pos = myRect;
|
2008-09-11 15:29:22 +03:00
|
|
|
onLeft = funcL;
|
|
|
|
textOnRclick = textR;
|
|
|
|
onHoverOn = funcHon;
|
|
|
|
onHoverOff = funcHoff;
|
2010-02-19 18:02:34 +02:00
|
|
|
myInt = _myInt;
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void SpellbookInteractiveArea::clickLeft(tribool down, bool previousState)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
|
|
|
if(!down)
|
|
|
|
{
|
2008-09-11 15:29:22 +03:00
|
|
|
onLeft();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void SpellbookInteractiveArea::clickRight(tribool down, bool previousState)
|
2008-09-11 15:29:22 +03:00
|
|
|
{
|
2010-03-21 00:17:19 +02:00
|
|
|
adventureInt->handleRightClick(textOnRclick, down);
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpellbookInteractiveArea::hover(bool on)
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
//Hoverable::hover(on);
|
2008-09-11 15:29:22 +03:00
|
|
|
if(on)
|
|
|
|
{
|
|
|
|
onHoverOn();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onHoverOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CSpellWindow::CSpellWindow(const SDL_Rect &, const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells):
|
|
|
|
CWindowObject(PLAYER_COLORED, "SpelBack"),
|
2009-07-03 22:57:14 +03:00
|
|
|
battleSpellsOnly(openOnBattleSpells),
|
2008-12-23 15:59:03 +02:00
|
|
|
selectedTab(4),
|
2010-07-21 13:09:29 +03:00
|
|
|
currentPage(0),
|
2010-02-19 18:02:34 +02:00
|
|
|
myHero(_myHero),
|
|
|
|
myInt(_myInt)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
* support for new hero bonuses (BLOCK_MORALE, SECONDARY_SKILL_PREMY (archery), AIR_SPELL_DMG_PREMY, EARTH_SPELL_DMG_PREMY, FIRE_SPELL_DMG_PREMY, WATER_SPELL_DMG_PREMY, BLOCK_SPELLS_ABOVE_LEVEL, SPELL_IMMUNITY, BLOCK_MORALE, FIRE_SPELLS, AIR_SPELLS, WATER_SPELLS, EARTH_SPELLS, SPELL, SPELLS_OF_LEVEL). It means that following artifacts are now supported:
- Orb of the Firmament
- Orb of Silt
- Orb of Tempestuous Fire
- Orb of Driving Rain
- Bow of Elven Cherrywood
- Bowstring of the Unicorn's Mane
- Angel Feather Arrows
- Tome of Fire Magic
- Tome of Air Magic
- Tome of Water Magic
- Tome of Earth Magic
- Recanter's Cloak
- Orb of Inhibition
- Pendant of Dispassion
- Pendant of Second Sight
- Pendant of Holiness
- Pendant of Life
- Pendant of Death
- Pendant of Free Will
- Pendant of Negativity
- Pendant of Total Recall
- Spellbinder's Hat
- Spirit of Oppression
- Sphere of Permanence
I hope I listed them all here :). Please try them and report if something's wrong.
2009-05-03 19:14:16 +03:00
|
|
|
//initializing castable spells
|
|
|
|
for(ui32 v=0; v<CGI->spellh->spells.size(); ++v)
|
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
if( !CGI->spellh->spells[v]->creatureAbility && myHero->canCastThisSpell(CGI->spellh->spells[v]) )
|
2013-02-11 02:24:57 +03:00
|
|
|
mySpells.insert(SpellID(v));
|
* support for new hero bonuses (BLOCK_MORALE, SECONDARY_SKILL_PREMY (archery), AIR_SPELL_DMG_PREMY, EARTH_SPELL_DMG_PREMY, FIRE_SPELL_DMG_PREMY, WATER_SPELL_DMG_PREMY, BLOCK_SPELLS_ABOVE_LEVEL, SPELL_IMMUNITY, BLOCK_MORALE, FIRE_SPELLS, AIR_SPELLS, WATER_SPELLS, EARTH_SPELLS, SPELL, SPELLS_OF_LEVEL). It means that following artifacts are now supported:
- Orb of the Firmament
- Orb of Silt
- Orb of Tempestuous Fire
- Orb of Driving Rain
- Bow of Elven Cherrywood
- Bowstring of the Unicorn's Mane
- Angel Feather Arrows
- Tome of Fire Magic
- Tome of Air Magic
- Tome of Water Magic
- Tome of Earth Magic
- Recanter's Cloak
- Orb of Inhibition
- Pendant of Dispassion
- Pendant of Second Sight
- Pendant of Holiness
- Pendant of Life
- Pendant of Death
- Pendant of Free Will
- Pendant of Negativity
- Pendant of Total Recall
- Spellbinder's Hat
- Spirit of Oppression
- Sphere of Permanence
I hope I listed them all here :). Please try them and report if something's wrong.
2009-05-03 19:14:16 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
|
2008-09-12 16:06:53 +03:00
|
|
|
//initializing sizes of spellbook's parts
|
|
|
|
for(int b=0; b<5; ++b)
|
|
|
|
sitesPerTabAdv[b] = 0;
|
|
|
|
for(int b=0; b<5; ++b)
|
|
|
|
sitesPerTabBattle[b] = 0;
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
BOOST_FOREACH(auto g, mySpells)
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
const CSpell &s = *CGI->spellh->spells[g];
|
2010-07-21 13:09:29 +03:00
|
|
|
Uint8 *sitesPerOurTab = s.combatSpell ? sitesPerTabBattle : sitesPerTabAdv;
|
2008-09-15 19:46:54 +03:00
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
++sitesPerOurTab[4];
|
|
|
|
|
|
|
|
if(s.air)
|
|
|
|
++sitesPerOurTab[0];
|
|
|
|
if(s.fire)
|
|
|
|
++sitesPerOurTab[1];
|
|
|
|
if(s.water)
|
|
|
|
++sitesPerOurTab[2];
|
|
|
|
if(s.earth)
|
|
|
|
++sitesPerOurTab[3];
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
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 = BitmapHandler::loadBitmap("SpelTrnL.bmp", true);
|
|
|
|
rightCorner = BitmapHandler::loadBitmap("SpelTrnR.bmp", true);
|
2008-09-10 15:19:48 +03:00
|
|
|
spells = CDefHandler::giveDef("Spells.def");
|
|
|
|
spellTab = CDefHandler::giveDef("SpelTab.def");
|
|
|
|
schools = CDefHandler::giveDef("Schools.def");
|
2008-09-15 19:46:54 +03:00
|
|
|
schoolBorders[0] = CDefHandler::giveDef("SplevA.def");
|
|
|
|
schoolBorders[1] = CDefHandler::giveDef("SplevF.def");
|
|
|
|
schoolBorders[2] = CDefHandler::giveDef("SplevW.def");
|
|
|
|
schoolBorders[3] = CDefHandler::giveDef("SplevE.def");
|
2008-09-10 15:19:48 +03:00
|
|
|
|
2008-09-11 15:29:22 +03:00
|
|
|
|
|
|
|
|
2012-12-22 23:05:08 +03:00
|
|
|
statusBar = new CGStatusBar(7 + pos.x, 569 + pos.y, "Spelroll.bmp");
|
2009-01-07 21:40:19 +02:00
|
|
|
SDL_Rect temp_rect = genRect(45, 35, 479 + pos.x, 405 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
exitBtn = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fexitb, this), CGI->generaltexth->zelp[460].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[460].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(45, 35, 221 + pos.x, 405 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
battleSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fbattleSpellsb, this), CGI->generaltexth->zelp[453].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[453].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(45, 35, 355 + pos.x, 405 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
adventureSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fadvSpellsb, this), CGI->generaltexth->zelp[452].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[452].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(45, 35, 418 + pos.x, 405 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
manaPoints = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fmanaPtsb, this), CGI->generaltexth->zelp[459].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[459].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2008-09-11 15:29:22 +03:00
|
|
|
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 94 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
selectSpellsA = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 0), CGI->generaltexth->zelp[454].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[454].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 151 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
selectSpellsE = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 3), CGI->generaltexth->zelp[457].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[457].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 210 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
selectSpellsF = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 1), CGI->generaltexth->zelp[455].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[455].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 270 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
selectSpellsW = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 2), CGI->generaltexth->zelp[456].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[456].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 330 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
selectSpellsAll = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 4), CGI->generaltexth->zelp[458].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[458].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2008-09-12 16:06:53 +03:00
|
|
|
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(leftCorner->h, leftCorner->w, 97 + pos.x, 77 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
lCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fLcornerb, this), CGI->generaltexth->zelp[450].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[450].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(rightCorner->h, rightCorner->w, 487 + pos.x, 72 + pos.y);
|
2012-12-22 23:05:08 +03:00
|
|
|
rCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fRcornerb, this), CGI->generaltexth->zelp[451].second, boost::bind(&CGStatusBar::print, statusBar, (CGI->generaltexth->zelp[451].first)), boost::bind(&CGStatusBar::clear, statusBar), myInt);
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
//areas for spells
|
2009-01-07 21:40:19 +02:00
|
|
|
int xpos = 117 + pos.x, ypos = 90 + pos.y;
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
for(int v=0; v<12; ++v)
|
|
|
|
{
|
|
|
|
temp_rect = genRect(65, 78, xpos, ypos);
|
|
|
|
spellAreas[v] = new SpellArea(temp_rect, this);
|
|
|
|
|
|
|
|
if(v == 5) //to right page
|
|
|
|
{
|
2009-01-07 21:40:19 +02:00
|
|
|
xpos = 336 + pos.x; ypos = 90 + pos.y;
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(v%2 == 0)
|
|
|
|
{
|
|
|
|
xpos+=85;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xpos -= 85; ypos+=97;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
selectedTab = battleSpellsOnly ? LOCPLINT->spellbookSettings.spellbookLastTabBattle : LOCPLINT->spellbookSettings.spellbookLastTabAdvmap;
|
|
|
|
currentPage = battleSpellsOnly ? LOCPLINT->spellbookSettings.spellbookLastPageBattle : LOCPLINT->spellbookSettings.spellbokLastPageAdvmap;
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::abetween(currentPage, 0, pagesWithinCurrentTab());
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(KEYBOARD);
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CSpellWindow::~CSpellWindow()
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(leftCorner);
|
|
|
|
SDL_FreeSurface(rightCorner);
|
|
|
|
delete spells;
|
|
|
|
delete spellTab;
|
|
|
|
delete schools;
|
2008-09-15 19:46:54 +03:00
|
|
|
for(int b=0; b<4; ++b)
|
|
|
|
delete schoolBorders[b];
|
2008-09-10 15:19:48 +03:00
|
|
|
|
|
|
|
delete exitBtn;
|
2008-09-11 15:29:22 +03:00
|
|
|
delete battleSpells;
|
|
|
|
delete adventureSpells;
|
|
|
|
delete manaPoints;
|
2008-09-10 15:19:48 +03:00
|
|
|
delete statusBar;
|
2008-09-11 15:29:22 +03:00
|
|
|
|
|
|
|
delete selectSpellsA;
|
|
|
|
delete selectSpellsE;
|
|
|
|
delete selectSpellsF;
|
|
|
|
delete selectSpellsW;
|
|
|
|
delete selectSpellsAll;
|
2008-09-12 16:06:53 +03:00
|
|
|
|
|
|
|
delete lCorner;
|
|
|
|
delete rCorner;
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
for(int g=0; g<12; ++g)
|
|
|
|
{
|
|
|
|
delete spellAreas[g];
|
|
|
|
}
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fexitb()
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
(LOCPLINT->battleInt ? LOCPLINT->spellbookSettings.spellbookLastTabBattle : LOCPLINT->spellbookSettings.spellbookLastTabAdvmap) = selectedTab;
|
|
|
|
(LOCPLINT->battleInt ? LOCPLINT->spellbookSettings.spellbookLastPageBattle : LOCPLINT->spellbookSettings.spellbokLastPageAdvmap) = currentPage;
|
|
|
|
|
2009-08-07 01:36:51 +03:00
|
|
|
GH.popIntTotally(this);
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2008-09-11 15:29:22 +03:00
|
|
|
void CSpellWindow::fadvSpellsb()
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if (battleSpellsOnly == true)
|
|
|
|
{
|
2009-06-20 04:42:19 +03:00
|
|
|
turnPageRight();
|
2009-06-20 05:14:25 +03:00
|
|
|
battleSpellsOnly = false;
|
2010-07-21 13:09:29 +03:00
|
|
|
currentPage = 0;
|
2009-06-20 05:14:25 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fbattleSpellsb()
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if (battleSpellsOnly == false)
|
|
|
|
{
|
2009-06-20 04:42:19 +03:00
|
|
|
turnPageLeft();
|
2009-06-20 05:14:25 +03:00
|
|
|
battleSpellsOnly = true;
|
2010-07-21 13:09:29 +03:00
|
|
|
currentPage = 0;
|
2009-06-20 05:14:25 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fmanaPtsb()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
void CSpellWindow::selectSchool(int school)
|
2008-09-11 15:29:22 +03:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if (selectedTab != school)
|
|
|
|
{
|
2009-06-20 04:42:19 +03:00
|
|
|
turnPageRight();
|
2010-07-21 13:09:29 +03:00
|
|
|
selectedTab = school;
|
|
|
|
currentPage = 0;
|
2009-06-20 05:14:25 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fLcornerb()
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if(currentPage>0)
|
|
|
|
{
|
2009-06-20 04:42:19 +03:00
|
|
|
turnPageLeft();
|
2010-07-21 13:09:29 +03:00
|
|
|
--currentPage;
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2010-07-21 13:09:29 +03:00
|
|
|
GH.breakEventHandling();
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fRcornerb()
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if((currentPage + 1) < (pagesWithinCurrentTab()))
|
|
|
|
{
|
2009-06-20 04:42:19 +03:00
|
|
|
turnPageRight();
|
2010-07-21 13:09:29 +03:00
|
|
|
++currentPage;
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2010-07-21 13:09:29 +03:00
|
|
|
GH.breakEventHandling();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void CSpellWindow::showAll(SDL_Surface * to)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
2012-06-15 20:08:19 +03:00
|
|
|
CWindowObject::showAll(to);
|
2009-06-20 05:14:25 +03:00
|
|
|
blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 88 + pos.y, to);
|
2010-02-02 18:24:53 +02:00
|
|
|
|
|
|
|
std::ostringstream mana;
|
|
|
|
mana<<myHero->mana;
|
2012-12-19 20:24:53 +03:00
|
|
|
printAtMiddleLoc(mana.str(), 435, 426, FONT_SMALL, Colors::YELLOW, to);
|
2008-09-10 15:19:48 +03:00
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
statusBar->showAll(to);
|
2008-09-12 16:06:53 +03:00
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
//printing school images
|
2010-07-21 13:09:29 +03:00
|
|
|
if(selectedTab!=4 && currentPage == 0)
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
2009-01-07 21:40:19 +02:00
|
|
|
blitAt(schools->ourImages[selectedTab].bitmap, 117 + pos.x, 74 + pos.y, to);
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
//printing corners
|
2010-07-21 13:09:29 +03:00
|
|
|
if(currentPage!=0)
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
|
|
|
blitAt(leftCorner, lCorner->pos.x, lCorner->pos.y, to);
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
if((currentPage+1) < (pagesWithinCurrentTab()) )
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
|
|
|
blitAt(rightCorner, rCorner->pos.x, rCorner->pos.y, to);
|
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
//printing spell info
|
|
|
|
for(int b=0; b<12; ++b)
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
spellAreas[b]->showAll(to);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-30 13:35:17 +03:00
|
|
|
void CSpellWindow::show(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
statusBar->show(to);
|
|
|
|
}
|
|
|
|
|
2008-09-16 18:23:44 +03:00
|
|
|
class SpellbookSpellSorter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool operator()(const int & a, const int & b)
|
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
const CSpell & A = *CGI->spellh->spells[a];
|
|
|
|
const CSpell & B = *CGI->spellh->spells[b];
|
2008-09-16 18:23:44 +03:00
|
|
|
if(A.level<B.level)
|
|
|
|
return true;
|
|
|
|
if(A.level>B.level)
|
|
|
|
return false;
|
|
|
|
if(A.air && !B.air)
|
|
|
|
return true;
|
|
|
|
if(!A.air && B.air)
|
|
|
|
return false;
|
|
|
|
if(A.fire && !B.fire)
|
|
|
|
return true;
|
|
|
|
if(!A.fire && B.fire)
|
|
|
|
return false;
|
|
|
|
if(A.water && !B.water)
|
|
|
|
return true;
|
|
|
|
if(!A.water && B.water)
|
|
|
|
return false;
|
|
|
|
if(A.earth && !B.earth)
|
|
|
|
return true;
|
|
|
|
if(!A.earth && B.earth)
|
|
|
|
return false;
|
|
|
|
return A.name < B.name;
|
|
|
|
}
|
|
|
|
} spellsorter;
|
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
void CSpellWindow::computeSpellsPerArea()
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
std::vector<SpellID> spellsCurSite;
|
|
|
|
for(auto it = mySpells.cbegin(); it != mySpells.cend(); ++it)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
if(CGI->spellh->spells[*it]->combatSpell ^ !battleSpellsOnly
|
|
|
|
&& ((CGI->spellh->spells[*it]->air && selectedTab == 0) ||
|
|
|
|
(CGI->spellh->spells[*it]->fire && selectedTab == 1) ||
|
|
|
|
(CGI->spellh->spells[*it]->water && selectedTab == 2) ||
|
|
|
|
(CGI->spellh->spells[*it]->earth && selectedTab == 3) ||
|
2008-09-15 19:46:54 +03:00
|
|
|
selectedTab == 4 )
|
|
|
|
)
|
|
|
|
{
|
|
|
|
spellsCurSite.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
2008-09-16 18:23:44 +03:00
|
|
|
std::sort(spellsCurSite.begin(), spellsCurSite.end(), spellsorter);
|
2008-09-15 19:46:54 +03:00
|
|
|
if(selectedTab == 4)
|
|
|
|
{
|
|
|
|
if(spellsCurSite.size() > 12)
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
spellsCurSite = std::vector<SpellID>(spellsCurSite.begin() + currentPage*12, spellsCurSite.end());
|
2008-09-15 19:46:54 +03:00
|
|
|
if(spellsCurSite.size() > 12)
|
|
|
|
{
|
|
|
|
spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //selectedTab == 0, 1, 2 or 3
|
|
|
|
{
|
|
|
|
if(spellsCurSite.size() > 10)
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if(currentPage == 0)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
|
|
|
spellsCurSite.erase(spellsCurSite.begin()+10, spellsCurSite.end());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
spellsCurSite = std::vector<SpellID>(spellsCurSite.begin() + (currentPage-1)*12 + 10, spellsCurSite.end());
|
2008-09-15 19:46:54 +03:00
|
|
|
if(spellsCurSite.size() > 12)
|
|
|
|
{
|
|
|
|
spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//applying
|
2010-07-21 13:09:29 +03:00
|
|
|
if(selectedTab == 4 || currentPage != 0)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t c=0; c<12; ++c)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2008-12-23 15:59:03 +02:00
|
|
|
if(c<spellsCurSite.size())
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
spellAreas[c]->setSpell(spellsCurSite[c]);
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
spellAreas[c]->setSpell(SpellID::NONE);
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
spellAreas[0]->setSpell(SpellID::NONE);
|
|
|
|
spellAreas[1]->setSpell(SpellID::NONE);
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t c=0; c<10; ++c)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
|
|
|
if(c<spellsCurSite.size())
|
2010-07-21 13:09:29 +03:00
|
|
|
spellAreas[c+2]->setSpell(spellsCurSite[c]);
|
2008-09-15 19:46:54 +03:00
|
|
|
else
|
2013-02-11 02:24:57 +03:00
|
|
|
spellAreas[c+2]->setSpell(SpellID::NONE);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
redraw();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::activate()
|
|
|
|
{
|
2012-06-02 18:16:54 +03:00
|
|
|
CIntObject::activate();
|
2008-09-10 15:19:48 +03:00
|
|
|
exitBtn->activate();
|
2008-09-11 15:29:22 +03:00
|
|
|
battleSpells->activate();
|
|
|
|
adventureSpells->activate();
|
|
|
|
manaPoints->activate();
|
|
|
|
|
|
|
|
selectSpellsA->activate();
|
|
|
|
selectSpellsE->activate();
|
|
|
|
selectSpellsF->activate();
|
|
|
|
selectSpellsW->activate();
|
|
|
|
selectSpellsAll->activate();
|
2008-09-12 16:06:53 +03:00
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
for(int g=0; g<12; ++g)
|
|
|
|
{
|
|
|
|
spellAreas[g]->activate();
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
lCorner->activate();
|
|
|
|
rCorner->activate();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::deactivate()
|
|
|
|
{
|
2012-06-02 18:16:54 +03:00
|
|
|
CIntObject::deactivate();
|
2008-09-10 15:19:48 +03:00
|
|
|
exitBtn->deactivate();
|
2008-09-11 15:29:22 +03:00
|
|
|
battleSpells->deactivate();
|
|
|
|
adventureSpells->deactivate();
|
|
|
|
manaPoints->deactivate();
|
|
|
|
|
|
|
|
selectSpellsA->deactivate();
|
|
|
|
selectSpellsE->deactivate();
|
|
|
|
selectSpellsF->deactivate();
|
|
|
|
selectSpellsW->deactivate();
|
|
|
|
selectSpellsAll->deactivate();
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
for(int g=0; g<12; ++g)
|
|
|
|
{
|
|
|
|
spellAreas[g]->deactivate();
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
lCorner->deactivate();
|
|
|
|
rCorner->deactivate();
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
2009-06-20 04:42:19 +03:00
|
|
|
void CSpellWindow::turnPageLeft()
|
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->videoh->openAndPlayVideo("PGTRNLFT.SMK", pos.x+13, pos.y+15, screen);
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::turnPageRight()
|
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->videoh->openAndPlayVideo("PGTRNRGH.SMK", pos.x+13, pos.y+15, screen);
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
|
|
|
|
2009-07-03 22:57:14 +03:00
|
|
|
void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
|
|
|
|
{
|
|
|
|
if(key.keysym.sym == SDLK_ESCAPE || key.keysym.sym == SDLK_RETURN)
|
|
|
|
fexitb();
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
if(key.state == SDL_PRESSED)
|
|
|
|
{
|
|
|
|
switch(key.keysym.sym)
|
|
|
|
{
|
|
|
|
case SDLK_LEFT:
|
|
|
|
fLcornerb();
|
|
|
|
break;
|
|
|
|
case SDLK_RIGHT:
|
|
|
|
fRcornerb();
|
|
|
|
break;
|
|
|
|
case SDLK_UP:
|
|
|
|
case SDLK_DOWN:
|
2010-08-27 19:20:35 +03:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
bool down = key.keysym.sym == SDLK_DOWN;
|
2011-12-14 00:23:17 +03:00
|
|
|
static const int schoolsOrder[] = { 0, 3, 1, 2, 4 };
|
2010-07-21 13:09:29 +03:00
|
|
|
int index = -1;
|
|
|
|
while(schoolsOrder[++index] != selectedTab);
|
|
|
|
index += (down ? 1 : -1);
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::abetween(index, 0, ARRAY_COUNT(schoolsOrder) - 1);
|
2010-07-21 13:09:29 +03:00
|
|
|
if(selectedTab != schoolsOrder[index])
|
|
|
|
selectSchool(schoolsOrder[index]);
|
|
|
|
break;
|
|
|
|
}
|
2012-09-30 15:19:14 +03:00
|
|
|
case SDLK_c:
|
|
|
|
fbattleSpellsb();
|
|
|
|
break;
|
|
|
|
case SDLK_a:
|
|
|
|
fadvSpellsb();
|
|
|
|
break;
|
2010-08-27 19:20:35 +03:00
|
|
|
default://to get rid of warnings
|
|
|
|
break;
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
//alt + 1234567890-= casts spell from 1 - 12 slot
|
|
|
|
if(LOCPLINT->altPressed())
|
|
|
|
{
|
|
|
|
SDLKey hlpKey = key.keysym.sym;
|
2011-12-17 21:59:59 +03:00
|
|
|
if(CGuiHandler::isNumKey(hlpKey, false))
|
2010-07-21 22:50:15 +03:00
|
|
|
{
|
|
|
|
if(hlpKey == SDLK_KP_PLUS)
|
|
|
|
hlpKey = SDLK_EQUALS;
|
|
|
|
else
|
2011-12-17 21:59:59 +03:00
|
|
|
hlpKey = CGuiHandler::numToDigit(hlpKey);
|
2010-07-21 22:50:15 +03:00
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
static const SDLKey spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS};
|
|
|
|
|
|
|
|
int index = -1;
|
|
|
|
while(++index < ARRAY_COUNT(spellSelectors) && spellSelectors[index] != hlpKey);
|
|
|
|
if(index >= ARRAY_COUNT(spellSelectors))
|
|
|
|
return;
|
|
|
|
|
|
|
|
//try casting spell
|
|
|
|
spellAreas[index]->clickLeft(false, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Uint8 CSpellWindow::pagesWithinCurrentTab()
|
|
|
|
{
|
|
|
|
return battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab];
|
2009-07-03 22:57:14 +03:00
|
|
|
}
|
|
|
|
|
2010-08-04 16:41:01 +03:00
|
|
|
void CSpellWindow::teleportTo( int town, const CGHeroInstance * hero )
|
|
|
|
{
|
2013-02-14 02:55:42 +03:00
|
|
|
const CGTownInstance * dest = LOCPLINT->cb->getTown(ObjectInstanceID(town));
|
2013-02-11 02:24:57 +03:00
|
|
|
LOCPLINT->cb->castSpell(hero, SpellID::TOWN_PORTAL, dest->visitablePos());
|
2010-08-04 16:41:01 +03:00
|
|
|
}
|
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
|
|
|
|
{
|
|
|
|
this->pos = pos;
|
|
|
|
this->owner = owner;
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(LCLICK | RCLICK | HOVER);
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
spellCost = whichSchool = schoolLevel = -1;
|
|
|
|
mySpell = SpellID::NONE;
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2008-10-17 20:43:25 +03:00
|
|
|
if(!down && mySpell!=-1)
|
2008-10-17 19:30:56 +03:00
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
const CSpell *sp = CGI->spellh->spells[mySpell];
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2010-03-11 01:16:30 +02:00
|
|
|
int spellCost = owner->myInt->cb->getSpellCost(sp, owner->myHero);
|
2010-07-21 13:09:29 +03:00
|
|
|
if(spellCost > owner->myHero->mana) //insufficient mana
|
|
|
|
{
|
|
|
|
char msgBuf[500];
|
|
|
|
sprintf(msgBuf, CGI->generaltexth->allTexts[206].c_str(), spellCost, owner->myHero->mana);
|
|
|
|
owner->myInt->showInfoDialog(std::string(msgBuf));
|
2010-07-26 23:56:39 +03:00
|
|
|
return;
|
2010-07-21 13:09:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//battle spell on adv map or adventure map spell during combat => display infowindow, not cast
|
2010-08-27 19:20:35 +03:00
|
|
|
if((sp->combatSpell && !owner->myInt->battleInt)
|
|
|
|
|| (!sp->combatSpell && owner->myInt->battleInt))
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2011-12-22 16:05:19 +03:00
|
|
|
std::vector<CComponent*> hlp(1, new CComponent(CComponent::spell, mySpell, 0));
|
2010-07-21 13:09:29 +03:00
|
|
|
LOCPLINT->showInfoDialog(sp->descriptions[schoolLevel], hlp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-17 20:43:25 +03:00
|
|
|
//we will cast a spell
|
2010-07-21 13:09:29 +03:00
|
|
|
if(sp->combatSpell && owner->myInt->battleInt && owner->myInt->cb->battleCanCastSpell()) //if battle window is open
|
2008-10-17 20:43:25 +03:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
ESpellCastProblem::ESpellCastProblem problem = owner->myInt->cb->battleCanCastThisSpell(sp);
|
2011-02-10 16:44:21 +02:00
|
|
|
switch (problem)
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
case ESpellCastProblem::OK:
|
2011-02-10 16:44:21 +02:00
|
|
|
{
|
|
|
|
int spell = mySpell;
|
|
|
|
owner->fexitb();
|
|
|
|
owner->myInt->battleInt->castThisSpell(spell);
|
|
|
|
}
|
2011-02-21 15:27:31 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case ESpellCastProblem::ANOTHER_ELEMENTAL_SUMMONED:
|
2011-02-10 16:44:21 +02:00
|
|
|
{
|
|
|
|
std::string text = CGI->generaltexth->allTexts[538], summoner, elemental, caster;
|
|
|
|
std::vector<const CStack *> stacks = owner->myInt->cb->battleGetStacks();
|
2011-02-15 21:54:55 +02:00
|
|
|
BOOST_FOREACH(const CStack * s, stacks)
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
if(vstd::contains(s->state, EBattleStackState::SUMMONED))
|
2011-02-15 21:54:55 +02:00
|
|
|
{
|
|
|
|
elemental = s->getCreature()->namePl;
|
2013-01-20 23:29:35 +03:00
|
|
|
summoner = owner->myInt->cb->battleGetHeroInfo(!s->attackerOwned).name;
|
2011-02-15 21:54:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-02-10 16:44:21 +02:00
|
|
|
if (owner->myHero->type->sex)
|
|
|
|
{ //female
|
|
|
|
caster = CGI->generaltexth->allTexts[540];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //male
|
|
|
|
caster = CGI->generaltexth->allTexts[539];
|
|
|
|
}
|
2011-02-15 21:54:55 +02:00
|
|
|
text = boost::str(boost::format(text) % summoner % elemental % caster);
|
|
|
|
|
2011-02-10 16:44:21 +02:00
|
|
|
|
|
|
|
owner->myInt->showInfoDialog(text);
|
|
|
|
}
|
2011-02-21 15:27:31 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED:
|
2011-02-21 15:27:31 +02:00
|
|
|
{
|
2012-08-26 12:07:48 +03:00
|
|
|
//Recanter's Cloak or similar effect. Try to retrieve bonus
|
2012-09-20 19:55:21 +03:00
|
|
|
const Bonus *b = owner->myHero->getBonusLocalFirst(Selector::type(Bonus::BLOCK_MAGIC_ABOVE));
|
2012-08-26 12:07:48 +03:00
|
|
|
//TODO what about other values and non-artifact sources?
|
|
|
|
if(b && b->val == 2 && b->source == Bonus::ARTIFACT)
|
|
|
|
{
|
|
|
|
std::string artName = CGI->arth->artifacts[b->sid]->Name();
|
|
|
|
//The %s prevents %s from casting 3rd level or higher spells.
|
|
|
|
owner->myInt->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[536])
|
|
|
|
% artName % owner->myHero->name));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// General message:
|
|
|
|
// %s recites the incantations but they seem to have no effect.
|
|
|
|
std::string text = CGI->generaltexth->allTexts[541], caster = owner->myHero->name;
|
|
|
|
text = boost::str(boost::format(text) % caster);
|
|
|
|
owner->myInt->showInfoDialog(text);
|
|
|
|
}
|
2011-02-21 15:27:31 +02:00
|
|
|
}
|
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case ESpellCastProblem::NO_APPROPRIATE_TARGET:
|
2011-02-21 18:53:23 +02:00
|
|
|
{
|
|
|
|
owner->myInt->showInfoDialog(CGI->generaltexth->allTexts[185]);
|
|
|
|
}
|
|
|
|
break;
|
2011-02-10 16:44:21 +02:00
|
|
|
}
|
2008-10-17 20:43:25 +03:00
|
|
|
}
|
2010-07-23 15:02:15 +03:00
|
|
|
else if(!sp->combatSpell && !owner->myInt->battleInt) //adventure spell
|
2010-01-29 18:19:12 +02:00
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
SpellID spell = mySpell;
|
2010-07-21 13:09:29 +03:00
|
|
|
const CGHeroInstance *h = owner->myHero;
|
|
|
|
owner->fexitb();
|
2010-03-11 01:16:30 +02:00
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
switch(spell)
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
case SpellID::SUMMON_BOAT:
|
2010-03-11 01:16:30 +02:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
int3 pos = h->bestLocation();
|
|
|
|
if(pos.x < 0)
|
2010-03-11 01:16:30 +02:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[334]); //There is no place to put the boat.
|
|
|
|
return;
|
2010-03-11 01:16:30 +02:00
|
|
|
}
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
break;
|
2013-02-11 02:24:57 +03:00
|
|
|
case SpellID::SCUTTLE_BOAT:
|
|
|
|
case SpellID::DIMENSION_DOOR:
|
2010-07-21 13:09:29 +03:00
|
|
|
adventureInt->enterCastingMode(sp);
|
|
|
|
return;
|
2013-02-11 02:24:57 +03:00
|
|
|
case SpellID::VISIONS:
|
|
|
|
case SpellID::VIEW_EARTH:
|
|
|
|
case SpellID::DISGUISE:
|
|
|
|
case SpellID::VIEW_AIR:
|
|
|
|
case SpellID::FLY:
|
|
|
|
case SpellID::WATER_WALK:
|
2010-08-04 16:41:01 +03:00
|
|
|
break;
|
2013-02-11 02:24:57 +03:00
|
|
|
case SpellID::TOWN_PORTAL:
|
2010-08-04 16:41:01 +03:00
|
|
|
{
|
|
|
|
std::vector <int> availableTowns;
|
2011-01-15 19:30:46 +02:00
|
|
|
std::vector <const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(true);
|
|
|
|
if (Towns.empty())
|
2010-08-04 16:41:01 +03:00
|
|
|
{
|
2011-01-15 19:30:46 +02:00
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[124]);
|
|
|
|
return;
|
2010-08-04 16:41:01 +03:00
|
|
|
}
|
|
|
|
|
2011-01-15 22:07:16 +02:00
|
|
|
if (h->getSpellSchoolLevel(CGI->spellh->spells[spell]) < 2) //not advanced or expert - teleport to nearest available city
|
2010-08-04 16:41:01 +03:00
|
|
|
{
|
|
|
|
int nearest = -1; //nearest town's ID
|
|
|
|
double dist = -1;
|
2011-01-15 19:30:46 +02:00
|
|
|
for (int g=0; g<Towns.size(); ++g)
|
2010-08-04 16:41:01 +03:00
|
|
|
{
|
2011-05-03 06:14:18 +03:00
|
|
|
const CGTownInstance * dest = LOCPLINT->cb->getTown(Towns[g]->id);
|
2010-08-04 16:41:01 +03:00
|
|
|
double curDist = dest->pos.dist2d(h->pos);
|
|
|
|
if (nearest == -1 || curDist < dist)
|
|
|
|
{
|
|
|
|
nearest = g;
|
|
|
|
dist = curDist;
|
|
|
|
}
|
|
|
|
}
|
2011-01-15 19:30:46 +02:00
|
|
|
if ( Towns[nearest]->visitingHero )
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[123]);
|
|
|
|
else
|
|
|
|
{
|
2011-05-03 06:14:18 +03:00
|
|
|
const CGTownInstance * town = LOCPLINT->cb->getTown(Towns[nearest]->id);
|
2011-01-15 19:30:46 +02:00
|
|
|
LOCPLINT->cb->castSpell(h, spell, town->visitablePos());// - town->getVisitableOffset());
|
|
|
|
}
|
2010-08-04 16:41:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //let the player choose
|
2011-01-15 19:30:46 +02:00
|
|
|
for(size_t i=0;i<Towns.size();i++)
|
|
|
|
{
|
|
|
|
const CGTownInstance *t = Towns[i];
|
|
|
|
if (t->visitingHero == NULL) //empty town and this is
|
|
|
|
{
|
2013-02-14 02:55:42 +03:00
|
|
|
availableTowns.push_back(t->id.getNum());//add to the list
|
2011-01-15 19:30:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (availableTowns.empty())
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[124]);
|
|
|
|
else
|
|
|
|
GH.pushInt (new CObjectListWindow(availableTowns,
|
|
|
|
new CPicture(graphics->spellscr->ourImages[spell].bitmap, 0, 0, false),
|
|
|
|
CGI->generaltexth->jktexts[40], CGI->generaltexth->jktexts[41],
|
|
|
|
boost::bind (&CSpellWindow::teleportTo, owner, _1, h)));
|
2010-08-04 16:41:01 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
2010-01-29 18:19:12 +02:00
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2010-08-04 16:41:01 +03:00
|
|
|
//can return earlier in some cases
|
2010-07-21 13:09:29 +03:00
|
|
|
LOCPLINT->cb->castSpell(h, spell);
|
2010-01-29 18:19:12 +02:00
|
|
|
}
|
2008-10-17 19:30:56 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void CSpellWindow::SpellArea::clickRight(tribool down, bool previousState)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2008-09-16 18:23:44 +03:00
|
|
|
if(down && mySpell != -1)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2009-11-08 16:44:58 +02:00
|
|
|
std::string dmgInfo;
|
2010-11-15 09:15:10 +02:00
|
|
|
const CGHeroInstance * hero = owner->myHero;
|
2010-12-19 16:39:56 +02:00
|
|
|
int causedDmg = owner->myInt->cb->estimateSpellDamage( CGI->spellh->spells[mySpell], (hero ? hero : NULL));
|
2011-06-25 09:55:35 +03:00
|
|
|
if(causedDmg == 0 || mySpell == 57) //Titan's Lightning Bolt already has damage info included
|
2009-11-08 16:44:58 +02:00
|
|
|
dmgInfo = "";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dmgInfo = CGI->generaltexth->allTexts[343];
|
|
|
|
boost::algorithm::replace_first(dmgInfo, "%d", boost::lexical_cast<std::string>(causedDmg));
|
|
|
|
}
|
|
|
|
|
2012-12-19 20:24:53 +03:00
|
|
|
CRClickPopup::createAndPush(CGI->spellh->spells[mySpell]->descriptions[schoolLevel] + dmgInfo,
|
|
|
|
new CComponent(CComponent::spell, mySpell));
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::SpellArea::hover(bool on)
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
//Hoverable::hover(on);
|
2008-09-16 18:23:44 +03:00
|
|
|
if(mySpell != -1)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2008-09-16 18:23:44 +03:00
|
|
|
if(on)
|
|
|
|
{
|
2009-06-17 19:46:16 +03:00
|
|
|
std::ostringstream ss;
|
2010-12-19 16:39:56 +02:00
|
|
|
ss<<CGI->spellh->spells[mySpell]->name<<" ("<<CGI->generaltexth->allTexts[171+CGI->spellh->spells[mySpell]->level]<<")";
|
2008-09-16 18:23:44 +03:00
|
|
|
owner->statusBar->print(ss.str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
owner->statusBar->clear();
|
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void CSpellWindow::SpellArea::showAll(SDL_Surface * to)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if(mySpell < 0)
|
|
|
|
return;
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
const CSpell * spell = mySpell.toSpell();
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
blitAt(owner->spells->ourImages[mySpell].bitmap, pos.x, pos.y, to);
|
|
|
|
blitAt(owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab]->ourImages[schoolLevel].bitmap, pos.x, pos.y, to); //printing border (indicates level of magic school)
|
|
|
|
|
|
|
|
SDL_Color firstLineColor, secondLineColor;
|
|
|
|
if(spellCost > owner->myHero->mana) //hero cannot cast this spell
|
|
|
|
{
|
|
|
|
static const SDL_Color unavailableSpell = {239, 189, 33, 0};
|
2012-11-11 15:23:31 +03:00
|
|
|
firstLineColor = Colors::WHITE;
|
2010-07-21 13:09:29 +03:00
|
|
|
secondLineColor = unavailableSpell;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
firstLineColor = Colors::YELLOW;
|
|
|
|
secondLineColor = Colors::WHITE;
|
2010-07-21 13:09:29 +03:00
|
|
|
}
|
|
|
|
//printing spell's name
|
2012-12-19 20:24:53 +03:00
|
|
|
printAtMiddleLoc(spell->name, 39, 70, FONT_TINY, firstLineColor, to);
|
2010-07-21 13:09:29 +03:00
|
|
|
//printing lvl
|
2012-12-19 20:24:53 +03:00
|
|
|
printAtMiddleLoc(CGI->generaltexth->allTexts[171 + spell->level], 39, 82, FONT_TINY, secondLineColor, to);
|
2010-07-21 13:09:29 +03:00
|
|
|
//printing cost
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << CGI->generaltexth->allTexts[387] << ": " << spellCost;
|
2012-12-19 20:24:53 +03:00
|
|
|
printAtMiddleLoc(ss.str(), 39, 94, FONT_TINY, secondLineColor, to);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
void CSpellWindow::SpellArea::setSpell(SpellID spellID)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
mySpell = spellID;
|
|
|
|
if(mySpell < 0)
|
|
|
|
return;
|
|
|
|
|
2010-12-19 16:39:56 +02:00
|
|
|
const CSpell * spell = CGI->spellh->spells[mySpell];
|
2010-07-21 13:09:29 +03:00
|
|
|
schoolLevel = owner->myHero->getSpellSchoolLevel(spell, &whichSchool);
|
|
|
|
spellCost = owner->myInt->cb->getSpellCost(spell, owner->myHero);
|
|
|
|
}
|