2008-09-10 15:19:48 +03:00
|
|
|
#include "CSpellWindow.h"
|
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"
|
|
|
|
#include "CBattleInterface.h"
|
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "SDL_Extensions.h"
|
|
|
|
#include "CMessage.h"
|
|
|
|
#include "CPlayerInterface.h"
|
2009-08-23 16:41:57 +03:00
|
|
|
#include "../CCallback.h"
|
2008-09-10 15:19:48 +03:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
#include <sstream>
|
2009-11-13 18:02:25 +02:00
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2010-08-17 17:58:13 +03:00
|
|
|
#include "CBitmapHandler.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-09-10 15:19:48 +03:00
|
|
|
extern SDL_Surface * screen;
|
2009-10-03 13:51:05 +03:00
|
|
|
extern SDL_Color tytulowy, zwykly, darkTitle;
|
2008-09-10 15:19:48 +03:00
|
|
|
|
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
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
used = 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-19 18:02:34 +02:00
|
|
|
CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells):
|
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]) )
|
* 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
|
|
|
mySpells.insert(v);
|
|
|
|
}
|
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
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
for(std::set<ui32>::const_iterator g = mySpells.begin(); g!=mySpells.end(); ++g)
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
2010-12-19 16:39:56 +02: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
|
|
|
|
|
2008-09-10 15:19:48 +03:00
|
|
|
pos = myRect;
|
|
|
|
background = BitmapHandler::loadBitmap("SpelBack.bmp");
|
|
|
|
graphics->blueToPlayersAdv(background, myHero->tempOwner);
|
|
|
|
|
2008-09-12 16:06:53 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
2009-01-07 21:40:19 +02:00
|
|
|
statusBar = new CStatusBar(7 + pos.x, 569 + pos.y, "Spelroll.bmp");
|
|
|
|
SDL_Rect temp_rect = genRect(45, 35, 479 + pos.x, 405 + pos.y);
|
2010-02-19 18:02:34 +02:00
|
|
|
exitBtn = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fexitb, this), CGI->generaltexth->zelp[460].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[460].first)), boost::bind(&CStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(45, 35, 221 + pos.x, 405 + pos.y);
|
2010-02-19 18:02:34 +02:00
|
|
|
battleSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fbattleSpellsb, this), CGI->generaltexth->zelp[453].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[453].first)), boost::bind(&CStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(45, 35, 355 + pos.x, 405 + pos.y);
|
2010-02-19 18:02:34 +02:00
|
|
|
adventureSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fadvSpellsb, this), CGI->generaltexth->zelp[452].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[452].first)), boost::bind(&CStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(45, 35, 418 + pos.x, 405 + pos.y);
|
2010-02-19 18:02:34 +02:00
|
|
|
manaPoints = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fmanaPtsb, this), CGI->generaltexth->zelp[459].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[459].first)), boost::bind(&CStatusBar::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);
|
2010-07-21 13:09:29 +03:00
|
|
|
selectSpellsA = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 0), CGI->generaltexth->zelp[454].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[454].first)), boost::bind(&CStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 151 + pos.y);
|
2010-07-21 13:09:29 +03:00
|
|
|
selectSpellsE = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 3), CGI->generaltexth->zelp[457].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[457].first)), boost::bind(&CStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 210 + pos.y);
|
2010-07-21 13:09:29 +03:00
|
|
|
selectSpellsF = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 1), CGI->generaltexth->zelp[455].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[455].first)), boost::bind(&CStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 270 + pos.y);
|
2010-07-21 13:09:29 +03:00
|
|
|
selectSpellsW = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 2), CGI->generaltexth->zelp[456].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[456].first)), boost::bind(&CStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 330 + pos.y);
|
2010-07-21 13:09:29 +03:00
|
|
|
selectSpellsAll = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::selectSchool, this, 4), CGI->generaltexth->zelp[458].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[458].first)), boost::bind(&CStatusBar::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);
|
2010-02-19 18:02:34 +02:00
|
|
|
lCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fLcornerb, this), CGI->generaltexth->zelp[450].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[450].first)), boost::bind(&CStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(rightCorner->h, rightCorner->w, 487 + pos.x, 72 + pos.y);
|
2010-02-19 18:02:34 +02:00
|
|
|
rCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fRcornerb, this), CGI->generaltexth->zelp[451].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[451].first)), boost::bind(&CStatusBar::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;
|
|
|
|
abetw(currentPage, 0, pagesWithinCurrentTab());
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CSpellWindow::~CSpellWindow()
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(background);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
void CSpellWindow::showAll(SDL_Surface *to)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
2010-08-23 18:16:40 +03:00
|
|
|
CSDL_Ext::blitSurface(background, NULL, to, &pos);
|
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;
|
|
|
|
CSDL_Ext::printAtMiddle(mana.str(), pos.x+435, pos.y +426, FONT_SMALL, tytulowy, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
std::vector<ui32> spellsCurSite;
|
|
|
|
for(std::set<ui32>::const_iterator it = mySpells.begin(); it != mySpells.end(); ++it)
|
|
|
|
{
|
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)
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
spellsCurSite = std::vector<ui32>(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
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
spellsCurSite = std::vector<ui32>(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
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
spellAreas[c]->setSpell(-1);
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
spellAreas[0]->setSpell(-1);
|
|
|
|
spellAreas[1]->setSpell(-1);
|
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
|
2010-07-21 13:09:29 +03:00
|
|
|
spellAreas[c+2]->setSpell(-1);
|
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()
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
activateKeys();
|
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()
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
deactivateKeys();
|
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;
|
|
|
|
static const int schoolsOrder[] = {0, 3, 1, 2, 4};
|
|
|
|
int index = -1;
|
|
|
|
while(schoolsOrder[++index] != selectedTab);
|
|
|
|
index += (down ? 1 : -1);
|
|
|
|
abetw(index, 0, ARRAY_COUNT(schoolsOrder) - 1);
|
|
|
|
if(selectedTab != schoolsOrder[index])
|
|
|
|
selectSchool(schoolsOrder[index]);
|
|
|
|
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;
|
|
|
|
if(isNumKey(hlpKey, false))
|
2010-07-21 22:50:15 +03:00
|
|
|
{
|
|
|
|
if(hlpKey == SDLK_KP_PLUS)
|
|
|
|
hlpKey = SDLK_EQUALS;
|
|
|
|
else
|
|
|
|
hlpKey = numToDigit(hlpKey);
|
|
|
|
}
|
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 )
|
|
|
|
{
|
|
|
|
const CGTownInstance * dest = LOCPLINT->cb->getTownInfo(town, 1);
|
2011-01-15 19:30:46 +02:00
|
|
|
LOCPLINT->cb->castSpell(hero, Spells::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;
|
2010-07-21 13:09:29 +03:00
|
|
|
used = LCLICK | RCLICK | HOVER;
|
|
|
|
|
|
|
|
spellCost = mySpell = whichSchool = schoolLevel = -1;
|
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
|
|
|
{
|
|
|
|
std::vector<SComponent*> hlp(1, new SComponent(SComponent::spell, mySpell, 0));
|
|
|
|
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
|
|
|
{
|
2010-01-28 19:23:01 +02:00
|
|
|
int spell = mySpell;
|
2009-10-03 13:51:05 +03:00
|
|
|
owner->fexitb();
|
2010-02-19 18:02:34 +02:00
|
|
|
owner->myInt->battleInt->castThisSpell(spell);
|
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
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
using namespace Spells;
|
|
|
|
int spell = mySpell;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
case 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;
|
|
|
|
case SCUTTLE_BOAT:
|
|
|
|
case DIMENSION_DOOR:
|
|
|
|
adventureInt->enterCastingMode(sp);
|
|
|
|
return;
|
|
|
|
case VISIONS:
|
|
|
|
case VIEW_EARTH:
|
|
|
|
case DISGUISE:
|
|
|
|
case VIEW_AIR:
|
|
|
|
case FLY:
|
|
|
|
case WATER_WALK:
|
2010-08-04 16:41:01 +03:00
|
|
|
break;
|
2010-07-21 13:09:29 +03:00
|
|
|
case 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-01-15 19:30:46 +02:00
|
|
|
const CGTownInstance * dest = LOCPLINT->cb->getTownInfo(Towns[g]->id, 1);
|
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
|
|
|
|
{
|
|
|
|
const CGTownInstance * town = LOCPLINT->cb->getTownInfo(Towns[nearest]->id, 1);
|
|
|
|
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
|
|
|
|
{
|
|
|
|
availableTowns.push_back(t->id);//add to the list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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));
|
2009-11-08 16:44:58 +02:00
|
|
|
if(causedDmg == 0)
|
|
|
|
dmgInfo = "";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dmgInfo = CGI->generaltexth->allTexts[343];
|
|
|
|
boost::algorithm::replace_first(dmgInfo, "%d", boost::lexical_cast<std::string>(causedDmg));
|
|
|
|
}
|
|
|
|
|
2009-08-23 21:23:21 +03:00
|
|
|
SDL_Surface *spellBox = CMessage::drawBoxTextBitmapSub(
|
2010-02-19 18:02:34 +02:00
|
|
|
owner->myInt->playerID,
|
2010-12-19 16:39:56 +02:00
|
|
|
CGI->spellh->spells[mySpell]->descriptions[schoolLevel] + dmgInfo, this->owner->spells->ourImages[mySpell].bitmap,
|
|
|
|
CGI->spellh->spells[mySpell]->name,30,30);
|
2009-08-23 21:23:21 +03:00
|
|
|
CInfoPopup *vinya = new CInfoPopup(spellBox, true);
|
2009-08-07 01:36:51 +03:00
|
|
|
GH.pushInt(vinya);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-21 13:09:29 +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;
|
|
|
|
|
2010-12-19 16:39:56 +02:00
|
|
|
const CSpell * spell = CGI->spellh->spells[mySpell];
|
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};
|
|
|
|
firstLineColor = zwykly;
|
|
|
|
secondLineColor = unavailableSpell;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstLineColor = tytulowy;
|
|
|
|
secondLineColor = zwykly;
|
|
|
|
}
|
|
|
|
//printing spell's name
|
|
|
|
CSDL_Ext::printAtMiddle(spell->name, pos.x + 39, pos.y + 70, FONT_TINY, firstLineColor, to);
|
|
|
|
//printing lvl
|
|
|
|
CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[171 + spell->level], pos.x + 39, pos.y + 82, FONT_TINY, secondLineColor, to);
|
|
|
|
//printing cost
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << CGI->generaltexth->allTexts[387] << ": " << spellCost;
|
|
|
|
CSDL_Ext::printAtMiddle(ss.str(), pos.x + 39, pos.y + 94, FONT_TINY, secondLineColor, to);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
void CSpellWindow::SpellArea::setSpell(int 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);
|
|
|
|
}
|