2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
#include "CCreatureWindow.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2011-03-03 20:25:48 +02:00
|
|
|
#include "../lib/CCreatureSet.h"
|
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../lib/BattleState.h"
|
|
|
|
#include "../CCallback.h"
|
|
|
|
|
|
|
|
#include <SDL.h>
|
2011-12-22 16:05:19 +03:00
|
|
|
#include "UIFramework/SDL_Extensions.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
#include "CBitmapHandler.h"
|
|
|
|
#include "CDefHandler.h"
|
|
|
|
#include "Graphics.h"
|
|
|
|
#include "CPlayerInterface.h"
|
2011-03-06 14:12:22 +02:00
|
|
|
#include "CConfigHandler.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
#include "CAnimation.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2011-05-10 01:20:47 +03:00
|
|
|
#include "../lib/CGameState.h"
|
2011-08-06 10:05:04 +03:00
|
|
|
#include "../lib/BattleState.h"
|
2011-05-21 10:07:07 +03:00
|
|
|
#include "../lib/CSpellHandler.h"
|
2012-02-10 13:32:21 +03:00
|
|
|
#include "../lib/CArtHandler.h"
|
2012-04-17 17:50:23 +03:00
|
|
|
#include "../lib/NetPacks.h" //ArtifactLocation
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2011-12-17 21:59:59 +03:00
|
|
|
#include "UIFramework/CGuiHandler.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
#include "UIFramework/CIntObjectClasses.h"
|
2011-12-17 21:59:59 +03:00
|
|
|
|
2011-03-03 20:25:48 +02:00
|
|
|
using namespace CSDL_Ext;
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
class CBonusItem;
|
2012-02-10 13:32:21 +03:00
|
|
|
class CCreatureArtifactInstance;
|
2012-07-03 11:07:34 +03:00
|
|
|
class CSelectableSkill;
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2011-03-03 20:25:48 +02:00
|
|
|
/*
|
|
|
|
* CCreatureWindow.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreatureWindow::CCreatureWindow (const CStack &stack, int Type):
|
|
|
|
CWindowObject(PLAYER_COLORED | (Type < 3 ? RCLICK_POPUP : 0 ) ),
|
|
|
|
type(Type)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
2011-05-13 17:33:48 +03:00
|
|
|
if (stack.base)
|
|
|
|
init(stack.base, &stack, dynamic_cast<const CGHeroInstance*>(stack.base->armyObj));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CStackInstance * s = new CStackInstance(stack.type, 1); //TODO: war machines and summons should be regular stacks
|
2011-10-22 10:05:57 +03:00
|
|
|
init(s, &stack, NULL);
|
2011-05-13 17:33:48 +03:00
|
|
|
delete s;
|
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreatureWindow::CCreatureWindow (const CStackInstance &stack, int Type):
|
|
|
|
CWindowObject(PLAYER_COLORED | (Type < 3 ? RCLICK_POPUP : 0 ) ),
|
|
|
|
type(Type)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
|
|
|
|
init(&stack, &stack, dynamic_cast<const CGHeroInstance*>(stack.armyObj));
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreatureWindow::CCreatureWindow(int Cid, int Type, int creatureCount):
|
|
|
|
CWindowObject(PLAYER_COLORED | (Type < 3 ? RCLICK_POPUP : 0 ) ),
|
|
|
|
type(Type)
|
2011-03-06 14:12:22 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
|
2011-03-21 10:14:23 +02:00
|
|
|
CStackInstance * stack = new CStackInstance(Cid, creatureCount); //TODO: simplify?
|
2011-03-06 14:12:22 +02:00
|
|
|
init(stack, CGI->creh->creatures[Cid], NULL);
|
|
|
|
delete stack;
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreatureWindow::CCreatureWindow(const CStackInstance &st, int Type, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui):
|
|
|
|
CWindowObject(PLAYER_COLORED | (Type < 3 ? RCLICK_POPUP : 0 ) ),
|
|
|
|
type(Type),
|
|
|
|
dismiss(0),
|
|
|
|
upgrade(0),
|
|
|
|
ok(0),
|
|
|
|
dsm(Dsm)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2011-04-09 22:34:48 +03:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
init(&st, &st,dynamic_cast<const CGHeroInstance*>(st.armyObj));
|
|
|
|
|
|
|
|
//print abilities text - if r-click popup
|
|
|
|
if(type)
|
|
|
|
{
|
|
|
|
if(Upg && ui)
|
|
|
|
{
|
2011-07-05 09:14:07 +03:00
|
|
|
TResources upgradeCost = ui->cost[0] * st.count;
|
|
|
|
for(TResources::nziterator i(upgradeCost); i.valid(); i++)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
|
|
|
BLOCK_CAPTURING;
|
2012-02-16 20:10:58 +03:00
|
|
|
upgResCost.push_back(new CComponent(CComponent::resource, i->resType, i->resVal));
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2011-07-05 09:14:07 +03:00
|
|
|
if(LOCPLINT->cb->getResourceAmount().canAfford(upgradeCost))
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
|
|
|
CFunctionList<void()> fs;
|
|
|
|
fs += Upg;
|
|
|
|
fs += boost::bind(&CCreatureWindow::close,this);
|
|
|
|
CFunctionList<void()> cfl;
|
2012-04-09 05:53:50 +03:00
|
|
|
cfl = boost::bind(&CPlayerInterface::showYesNoDialog, LOCPLINT, CGI->generaltexth->allTexts[207], fs, 0, false, boost::ref(upgResCost));
|
2011-12-22 16:05:19 +03:00
|
|
|
upgrade = new CAdventureMapButton("",CGI->generaltexth->zelp[446].second,cfl,385, 148,"IVIEWCR.DEF",SDLK_u);
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-22 16:05:19 +03:00
|
|
|
upgrade = new CAdventureMapButton("",CGI->generaltexth->zelp[446].second,boost::function<void()>(),385, 148,"IVIEWCR.DEF");
|
2011-04-09 22:34:48 +03:00
|
|
|
upgrade->callback.funcs.clear();
|
|
|
|
upgrade->setOffset(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(Dsm)
|
|
|
|
{
|
|
|
|
CFunctionList<void()> fs[2];
|
|
|
|
//on dismiss confirmed
|
|
|
|
fs[0] += Dsm; //dismiss
|
|
|
|
fs[0] += boost::bind(&CCreatureWindow::close,this);//close this window
|
|
|
|
CFunctionList<void()> cfl;
|
2012-04-09 05:53:50 +03:00
|
|
|
cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],fs[0],fs[1],false,std::vector<CComponent*>());
|
2011-12-22 16:05:19 +03:00
|
|
|
dismiss = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second,cfl,333, 148,"IVIEWCR2.DEF",SDLK_d);
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreatureWindow::CCreatureWindow (const CCommanderInstance * Commander):
|
|
|
|
CWindowObject(PLAYER_COLORED),
|
|
|
|
type(COMMANDER),
|
|
|
|
commander (Commander)
|
2012-05-16 20:29:05 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
init(commander, commander, dynamic_cast<const CGHeroInstance*>(commander->armyObj));
|
|
|
|
|
|
|
|
boost::function<void()> Dsm;
|
|
|
|
CFunctionList<void()> fs[2];
|
|
|
|
//on dismiss confirmed
|
|
|
|
fs[0] += Dsm; //dismiss
|
|
|
|
fs[0] += boost::bind(&CCreatureWindow::close,this);//close this window
|
|
|
|
CFunctionList<void()> cfl;
|
|
|
|
cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],fs[0],fs[1],false,std::vector<CComponent*>());
|
|
|
|
dismiss = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, cfl, 333, 148,"IVIEWCR2.DEF", SDLK_d);
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
CCreatureWindow::CCreatureWindow (std::vector<ui32> &skills, const CCommanderInstance * Commander, boost::function<void(ui32)> &callback):
|
|
|
|
CWindowObject(PLAYER_COLORED),
|
|
|
|
type(COMMANDER_LEVEL_UP),
|
|
|
|
commander (Commander),
|
2012-07-06 23:19:54 +03:00
|
|
|
selectedOption (0), //choose something before drawing
|
|
|
|
upgradeOptions(skills), //copy skills to choose from
|
|
|
|
levelUp (callback)
|
2012-07-03 11:07:34 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
|
|
|
|
init(commander, commander, dynamic_cast<const CGHeroInstance*>(commander->armyObj));
|
|
|
|
|
|
|
|
boost::function<void()> Dsm;
|
|
|
|
CFunctionList<void()> fs[2];
|
|
|
|
//on dismiss confirmed
|
|
|
|
fs[0] += Dsm; //dismiss
|
|
|
|
fs[0] += boost::bind(&CCreatureWindow::close,this);//close this window
|
|
|
|
CFunctionList<void()> cfl;
|
|
|
|
cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],fs[0],fs[1],false,std::vector<CComponent*>());
|
|
|
|
dismiss = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, cfl, 333, 148,"IVIEWCR2.DEF", SDLK_d);
|
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *StackNode, const CGHeroInstance *HeroOwner)
|
|
|
|
{
|
2012-04-14 05:20:22 +03:00
|
|
|
creatureArtifact = NULL; //may be set later
|
2012-05-13 18:04:21 +03:00
|
|
|
artifactImage = NULL;
|
2011-04-09 22:34:48 +03:00
|
|
|
stack = Stack;
|
2011-03-03 20:25:48 +02:00
|
|
|
c = stack->type;
|
2011-04-09 22:34:48 +03:00
|
|
|
if(!StackNode)
|
|
|
|
stackNode = c;
|
|
|
|
else
|
|
|
|
stackNode = StackNode;
|
2011-10-20 14:03:04 +03:00
|
|
|
const CStack *battleStack = dynamic_cast<const CStack*>(stackNode); //only during battle
|
2011-04-09 22:34:48 +03:00
|
|
|
heroOwner = HeroOwner;
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2012-02-20 11:19:03 +03:00
|
|
|
if (battleStack)
|
|
|
|
count = boost::lexical_cast<std::string>(battleStack->count);
|
|
|
|
else if (Stack->count)
|
2011-08-05 10:59:15 +03:00
|
|
|
count = boost::lexical_cast<std::string>(Stack->count);
|
|
|
|
|
2012-05-16 20:29:05 +03:00
|
|
|
if (type < COMMANDER)
|
|
|
|
commander = NULL;
|
|
|
|
|
2012-05-22 20:16:37 +03:00
|
|
|
bool creArt = false;
|
|
|
|
displayedArtifact = ArtifactPosition::CREATURE_SLOT; // 0
|
|
|
|
|
2011-03-06 14:12:22 +02:00
|
|
|
//Basic graphics - need to calculate size
|
|
|
|
|
2012-05-18 22:44:15 +03:00
|
|
|
int commanderOffset = 0;
|
|
|
|
if (type >= COMMANDER)
|
|
|
|
commanderOffset = 74;
|
|
|
|
|
2012-07-04 17:41:53 +03:00
|
|
|
if (commander) //secondary skills
|
|
|
|
{
|
|
|
|
creArt = true;
|
|
|
|
for (int i = ECommander::ATTACK; i <= ECommander::SPELL_POWER; ++i)
|
|
|
|
{
|
|
|
|
if (commander->secondarySkills[i] || vstd::contains(upgradeOptions, i))
|
|
|
|
{
|
|
|
|
std::string file = skillToFile(i);
|
|
|
|
|
|
|
|
skillPictures.push_back(new CPicture(file, 0,0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == COMMANDER_LEVEL_UP)
|
|
|
|
{
|
|
|
|
BOOST_FOREACH (auto option, upgradeOptions)
|
|
|
|
{
|
|
|
|
ui32 index = selectableSkills.size();
|
|
|
|
CSelectableSkill * selectableSkill = new CSelectableSkill();
|
|
|
|
selectableSkill->callback = boost::bind(&CCreatureWindow::selectSkill, this, index);
|
|
|
|
|
|
|
|
if (option < 100)
|
|
|
|
{
|
|
|
|
selectableSkill->pos = skillPictures[index]->pos; //resize
|
|
|
|
selectableSkills.push_back (selectableSkill);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selectableSkill->pos = Rect (95, 256, 55, 55); //TODO: scroll
|
|
|
|
Bonus b = CGI->creh->skillRequirements[option-100].first;
|
|
|
|
bonusItems.push_back (new CBonusItem (genRect(0, 0, 251, 57), stack->bonusToString(&b, false), stack->bonusToString(&b, true), stack->bonusToGraphics(&b)));
|
|
|
|
selectableBonuses.push_back (selectableSkill); //insert these before other bonuses
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 21:39:02 +03:00
|
|
|
BonusList bl, blTemp;
|
|
|
|
blTemp = (*(stackNode->getBonuses(Selector::durationType(Bonus::PERMANENT))));
|
2012-02-16 20:10:58 +03:00
|
|
|
|
2011-07-13 21:39:02 +03:00
|
|
|
while (blTemp.size())
|
2011-03-06 14:12:22 +02:00
|
|
|
{
|
2011-07-13 21:39:02 +03:00
|
|
|
Bonus * b = blTemp.front();
|
2011-03-06 14:12:22 +02:00
|
|
|
|
|
|
|
bl.push_back (new Bonus(*b));
|
2011-07-13 21:39:02 +03:00
|
|
|
bl.back()->val = blTemp.valOfBonuses(Selector::typeSubtype(b->type, b->subtype)); //merge multiple bonuses into one
|
|
|
|
blTemp.remove_if (Selector::typeSubtype(b->type, b->subtype)); //remove used bonuses
|
2011-03-06 14:12:22 +02:00
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
std::string text;
|
2011-03-06 14:12:22 +02:00
|
|
|
BOOST_FOREACH(Bonus* b, bl)
|
|
|
|
{
|
|
|
|
text = stack->bonusToString(b, false);
|
2011-04-09 22:34:48 +03:00
|
|
|
if (text.size()) //if it's possible to give any description for this kind of bonus
|
2011-03-06 14:12:22 +02:00
|
|
|
{
|
2011-04-09 22:34:48 +03:00
|
|
|
bonusItems.push_back (new CBonusItem(genRect(0, 0, 251, 57), text, stack->bonusToString(b, true), stack->bonusToGraphics(b)));
|
2011-03-06 14:12:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-20 14:03:04 +03:00
|
|
|
int magicResistance = 0; //handle it separately :/
|
|
|
|
if (battleStack)
|
|
|
|
{
|
|
|
|
magicResistance = battleStack->magicResistance(); //include Aura of Resistance
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
magicResistance = stack->magicResistance(); //include Resiatance hero skill
|
|
|
|
}
|
|
|
|
if (magicResistance)
|
|
|
|
{
|
|
|
|
std::map<TBonusType, std::pair<std::string, std::string> >::const_iterator it = CGI->creh->stackBonuses.find(Bonus::MAGIC_RESISTANCE);
|
|
|
|
std::string description;
|
|
|
|
text = it->second.first;
|
|
|
|
description = it->second.second;
|
|
|
|
boost::algorithm::replace_first(description, "%d", boost::lexical_cast<std::string>(magicResistance));
|
|
|
|
Bonus b;
|
|
|
|
b.type = Bonus::MAGIC_RESISTANCE;
|
|
|
|
bonusItems.push_back (new CBonusItem(genRect(0, 0, 251, 57), text, description, stack->bonusToGraphics(&b)));
|
|
|
|
}
|
|
|
|
|
2012-01-12 18:23:00 +03:00
|
|
|
bonusRows = std::min ((int)((bonusItems.size() + 1) / 2), (screen->h - 230) / 60);
|
2012-05-16 20:29:05 +03:00
|
|
|
if (type >= COMMANDER)
|
|
|
|
vstd::amin(bonusRows, 3);
|
|
|
|
else
|
|
|
|
vstd::amin(bonusRows, 4);
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::amax(bonusRows, 1);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2012-05-16 20:29:05 +03:00
|
|
|
if (type >= COMMANDER)
|
2012-07-04 17:41:53 +03:00
|
|
|
{
|
2012-06-15 20:08:19 +03:00
|
|
|
setBackground("CommWin" + boost::lexical_cast<std::string>(bonusRows) + ".pcx");
|
2012-07-04 17:41:53 +03:00
|
|
|
for (int i = 0; i < skillPictures.size(); ++i)
|
|
|
|
{
|
|
|
|
skillPictures[i]->moveTo (Point (pos.x + 37 + i * 84, pos.y + 224));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < selectableSkills.size(); ++i)
|
|
|
|
{
|
|
|
|
if (upgradeOptions[i] < skillPictures.size()) // it's secondary skill
|
|
|
|
{
|
|
|
|
selectableSkills[i]->pos = skillPictures[upgradeOptions[i]]->pos; //dirty workaround
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//print commander level
|
|
|
|
new CLabel(488, 62, FONT_MEDIUM, CENTER, Colors::Jasmine,
|
|
|
|
boost::lexical_cast<std::string>((ui16)(commander->level)));
|
|
|
|
|
|
|
|
new CLabel(488, 82, FONT_SMALL, CENTER, Colors::Cornsilk,
|
|
|
|
boost::lexical_cast<std::string>(stack->experience));
|
|
|
|
}
|
2012-05-16 20:29:05 +03:00
|
|
|
else
|
2012-06-15 20:08:19 +03:00
|
|
|
setBackground("CreWin" + boost::lexical_cast<std::string>(bonusRows) + ".pcx"); //1 to 4 rows for now
|
2011-03-03 20:25:48 +02:00
|
|
|
|
|
|
|
//Buttons
|
2011-12-22 16:05:19 +03:00
|
|
|
ok = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CCreatureWindow::close,this), 489, 148, "hsbtns.def", SDLK_RETURN);
|
2012-05-16 20:29:05 +03:00
|
|
|
ok->assignedKeys.insert(SDLK_ESCAPE);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
|
|
|
if (type <= BATTLE) //in battle or info window
|
|
|
|
{
|
|
|
|
upgrade = NULL;
|
|
|
|
dismiss = NULL;
|
|
|
|
}
|
2011-03-06 14:12:22 +02:00
|
|
|
anim = new CCreaturePic(22, 48, c);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
|
|
|
//Stats
|
2011-03-06 14:12:22 +02:00
|
|
|
morale = new MoraleLuckBox(true, genRect(42, 42, 335, 100));
|
2011-03-03 20:25:48 +02:00
|
|
|
morale->set(stack);
|
2011-03-06 14:12:22 +02:00
|
|
|
luck = new MoraleLuckBox(false, genRect(42, 42, 387, 100));
|
2011-03-03 20:25:48 +02:00
|
|
|
luck->set(stack);
|
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
new CAnimImage("PSKIL42", 4, 0, 387, 51); //exp icon - Print it always?
|
2011-03-21 10:14:23 +02:00
|
|
|
if (type) //not in fort window
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2012-05-18 22:44:15 +03:00
|
|
|
if (GameConstants::STACK_EXP && type < COMMANDER)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2011-03-21 10:14:23 +02:00
|
|
|
int rank = std::min(stack->getExpRank(), 10); //hopefully nobody adds more
|
2012-06-15 20:08:19 +03:00
|
|
|
new CLabel(488, 82, FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast<std::string>(stack->experience));
|
|
|
|
new CLabel(488, 62, FONT_MEDIUM, CENTER, Colors::Jasmine,
|
|
|
|
CGI->generaltexth->zcrexp[rank] + " [" + boost::lexical_cast<std::string>(rank) + "]");
|
2012-05-18 22:44:15 +03:00
|
|
|
|
2011-03-21 10:14:23 +02:00
|
|
|
if (type > BATTLE) //we need it only on adv. map
|
|
|
|
{
|
|
|
|
int tier = stack->type->level;
|
2011-12-14 00:23:17 +03:00
|
|
|
if (!vstd::iswithin(tier, 1, 7))
|
2011-03-21 10:14:23 +02:00
|
|
|
tier = 0;
|
|
|
|
int number;
|
|
|
|
std::string expText = CGI->generaltexth->zcrexp[324];
|
|
|
|
boost::replace_first (expText, "%s", c->namePl);
|
|
|
|
boost::replace_first (expText, "%s", CGI->generaltexth->zcrexp[rank]);
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(rank));
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(stack->experience));
|
|
|
|
number = CGI->creh->expRanks[tier][rank] - stack->experience;
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number));
|
|
|
|
|
|
|
|
number = CGI->creh->maxExpPerBattle[tier]; //percent
|
|
|
|
boost::replace_first (expText, "%i%", boost::lexical_cast<std::string>(number));
|
|
|
|
number *= CGI->creh->expRanks[tier].back() / 100; //actual amount
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number));
|
|
|
|
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(stack->count)); //Number of Creatures in stack
|
|
|
|
|
|
|
|
int expmin = std::max(CGI->creh->expRanks[tier][std::max(rank-1, 0)], (ui32)1);
|
|
|
|
number = (stack->count * (stack->experience - expmin)) / expmin; //Maximum New Recruits without losing current Rank
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number)); //TODO
|
|
|
|
|
|
|
|
boost::replace_first (expText, "%.2f", boost::lexical_cast<std::string>(1)); //TODO Experience Multiplier
|
|
|
|
number = CGI->creh->expAfterUpgrade;
|
|
|
|
boost::replace_first (expText, "%.2f", boost::lexical_cast<std::string>(number) + "%"); //Upgrade Multiplier
|
|
|
|
|
|
|
|
expmin = CGI->creh->expRanks[tier][9];
|
|
|
|
int expmax = CGI->creh->expRanks[tier][10];
|
|
|
|
number = expmax - expmin;
|
2012-02-16 20:10:58 +03:00
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number)); //Experience after Rank 10
|
|
|
|
number = (stack->count * (expmax - expmin)) / expmin;
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number)); //Maximum New Recruits to remain at Rank 10 if at Maximum Experience
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
expArea = new LRClickableAreaWTextComp(Rect(334, 49, 160, 44),CComponent::experience);
|
2011-05-21 10:07:07 +03:00
|
|
|
expArea->text = expText;
|
|
|
|
expArea->bonusValue = 0; //TDO: some specific value or no number at all
|
2011-03-21 10:14:23 +02:00
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2012-02-04 19:34:29 +03:00
|
|
|
if (GameConstants::STACK_ARTIFACT)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2012-05-22 20:16:37 +03:00
|
|
|
creArt = true;
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-22 20:16:37 +03:00
|
|
|
if (creArt) //stack or commander artifacts
|
|
|
|
{
|
|
|
|
setArt (stack->getArt(ArtifactPosition::CREATURE_SLOT));
|
|
|
|
if (type > BATTLE) //artifact buttons inactive in battle
|
|
|
|
{
|
|
|
|
//TODO: disable buttons if no artifact is equipped
|
|
|
|
leftArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, -1), 437, 98, "hsbtns3.def", SDLK_LEFT);
|
|
|
|
rightArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, +1), 516, 98, "hsbtns5.def", SDLK_RIGHT);
|
|
|
|
if (heroOwner)
|
|
|
|
passArtToHero = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::passArtifactToHero, this), 437, 148, "OVBUTN1.DEF", SDLK_HOME);
|
|
|
|
}
|
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2011-10-20 14:03:04 +03:00
|
|
|
if (battleStack) //only during battle
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
|
|
|
//spell effects
|
|
|
|
int printed=0; //how many effect pics have been printed
|
|
|
|
std::vector<si32> spells = battleStack->activeSpells();
|
|
|
|
BOOST_FOREACH(si32 effect, spells)
|
|
|
|
{
|
2011-05-21 10:07:07 +03:00
|
|
|
std::string spellText;
|
2011-05-13 12:02:16 +03:00
|
|
|
if (effect < graphics->spellEffectsPics->ourImages.size()) //not all effects have graphics (for eg. Acid Breath)
|
|
|
|
{
|
2012-02-16 20:10:58 +03:00
|
|
|
spellText = CGI->generaltexth->allTexts[610]; //"%s, duration: %d rounds."
|
2011-05-21 10:07:07 +03:00
|
|
|
boost::replace_first (spellText, "%s", CGI->spellh->spells[effect]->name);
|
|
|
|
int duration = battleStack->getBonus(Selector::source(Bonus::SPELL_EFFECT,effect))->turnsRemain;
|
2012-02-16 20:10:58 +03:00
|
|
|
boost::replace_first (spellText, "%d", boost::lexical_cast<std::string>(duration));
|
2012-06-15 20:08:19 +03:00
|
|
|
|
|
|
|
new CAnimImage("SpellInt", effect + 1, 0, 20 + 52 * printed, 184);
|
2011-12-22 16:05:19 +03:00
|
|
|
spellEffects.push_back(new LRClickableAreaWText(Rect(20 + 52 * printed, 184, 50, 38), spellText, spellText));
|
2011-05-13 12:02:16 +03:00
|
|
|
if (++printed >= 10) //we can fit only 10 effects
|
|
|
|
break;
|
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
//print current health
|
|
|
|
printLine (5, CGI->generaltexth->allTexts[200], battleStack->firstHPleft);
|
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
if (bonusItems.size() > (bonusRows << 1)) //only after graphics are created
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2012-05-18 22:44:15 +03:00
|
|
|
slider = new CSlider(528, 231 + commanderOffset, bonusRows*60, boost::bind (&CCreatureWindow::sliderMoved, this, _1),
|
2011-04-09 22:34:48 +03:00
|
|
|
bonusRows, (bonusItems.size() + 1) >> 1, 0, false, 0);
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
else //slider automatically places bonus Items
|
|
|
|
recreateSkillList (0);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2011-04-10 08:41:24 +03:00
|
|
|
showAll(screen2);
|
|
|
|
|
2011-03-03 20:25:48 +02:00
|
|
|
//AUIDAT.DEF
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureWindow::printLine(int nr, const std::string &text, int baseVal, int val/*=-1*/, bool range/*=false*/)
|
|
|
|
{
|
2012-06-15 20:08:19 +03:00
|
|
|
new CLabel(162, 48 + nr*19, FONT_SMALL, TOPLEFT, Colors::Cornsilk, text);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
|
|
|
std::string hlp;
|
|
|
|
if(range && baseVal != val)
|
|
|
|
hlp = boost::str(boost::format("%d - %d") % baseVal % val);
|
|
|
|
else if(baseVal != val && val>=0)
|
|
|
|
hlp = boost::str(boost::format("%d (%d)") % baseVal % val);
|
|
|
|
else
|
|
|
|
hlp = boost::lexical_cast<std::string>(baseVal);
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
new CLabel(325, 64 + nr*19, FONT_SMALL, BOTTOMRIGHT, Colors::Cornsilk, hlp);
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
void CCreatureWindow::recreateSkillList(int Pos)
|
|
|
|
{
|
2012-05-16 20:29:05 +03:00
|
|
|
int commanderOffset = 0;
|
|
|
|
if (type >= COMMANDER)
|
|
|
|
commanderOffset = 74;
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
int n = 0, i = 0, j = 0;
|
|
|
|
int numSkills = std::min ((bonusRows + Pos) << 1, (int)bonusItems.size());
|
|
|
|
std::string gfxName;
|
|
|
|
for (n = 0; n < Pos << 1; ++n)
|
|
|
|
{
|
|
|
|
bonusItems[n]->visible = false;
|
2012-07-04 17:41:53 +03:00
|
|
|
if (n < selectableBonuses.size())
|
|
|
|
selectableBonuses[n]->deactivate(); //we assume that bonuses are at front of the list
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
for (n = Pos << 1; n < numSkills; ++n)
|
|
|
|
{
|
2011-04-10 13:31:42 +03:00
|
|
|
int offsetx = 257*j - (bonusRows == 4 ? 1 : 0);
|
2012-05-16 20:29:05 +03:00
|
|
|
int offsety = 60*i + (bonusRows > 1 ? 1 : 0) + commanderOffset; //lack of precision :/
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
bonusItems[n]->moveTo (Point(pos.x + offsetx + 10, pos.y + offsety + 230), true);
|
2011-04-09 22:34:48 +03:00
|
|
|
bonusItems[n]->visible = true;
|
2012-07-04 17:41:53 +03:00
|
|
|
if (n < selectableBonuses.size())
|
|
|
|
{
|
|
|
|
selectableBonuses[n]->moveTo (Point(bonusItems[n]->pos.x + 12, bonusItems[n]->pos.y + 2)); //for some reason bonusItems have dimensions 0?
|
|
|
|
//selectableBonuses[n]->pos = bonusItems[n]->bonusGraphics->pos;
|
|
|
|
selectableBonuses[n]->activate();
|
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
|
|
|
|
if (++j > 1) //next line
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (n = numSkills; n < bonusItems.size(); ++n)
|
|
|
|
{
|
|
|
|
bonusItems[n]->visible = false;
|
2012-07-04 17:41:53 +03:00
|
|
|
selectableBonuses[n]->deactivate();
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureWindow::showAll(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
CIntObject::showAll(to);
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
printAtMiddleLoc((type >= COMMANDER ? c->nameSing : c->namePl), 180, 30, FONT_SMALL, Colors::Jasmine, to); //creature name
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2011-05-13 12:02:16 +03:00
|
|
|
printLine(0, CGI->generaltexth->primarySkillNames[0], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->Attack());
|
|
|
|
printLine(1, CGI->generaltexth->primarySkillNames[1], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->Defense());
|
2011-06-18 18:43:28 +03:00
|
|
|
|
2012-05-07 15:54:22 +03:00
|
|
|
if (stackNode->valOfBonuses(Bonus::SHOTS) && stackNode->hasBonusOfType(Bonus::SHOOTER))
|
2011-08-06 10:05:04 +03:00
|
|
|
{//only for shooting units - important with wog exp shooters
|
|
|
|
if (type == BATTLE)
|
2011-08-06 10:15:21 +03:00
|
|
|
printLine(2, CGI->generaltexth->allTexts[198], dynamic_cast<const CStack*>(stackNode)->shots);
|
2011-08-06 10:05:04 +03:00
|
|
|
else
|
|
|
|
printLine(2, CGI->generaltexth->allTexts[198], stackNode->valOfBonuses(Bonus::SHOTS));
|
|
|
|
}
|
2012-05-07 15:54:22 +03:00
|
|
|
if (stackNode->valOfBonuses(Bonus::CASTS))
|
|
|
|
{
|
2012-06-15 20:08:19 +03:00
|
|
|
printAtMiddleLoc(CGI->generaltexth->allTexts[399], 356, 62, FONT_SMALL, Colors::Cornsilk, to);
|
2012-05-07 15:54:22 +03:00
|
|
|
std::string casts;
|
|
|
|
if (type == BATTLE)
|
|
|
|
casts = boost::lexical_cast<std::string>((ui16)dynamic_cast<const CStack*>(stackNode)->casts); //ui8 is converted to char :(
|
|
|
|
else
|
|
|
|
casts = boost::lexical_cast<std::string>(stackNode->valOfBonuses(Bonus::CASTS));
|
2012-06-15 20:08:19 +03:00
|
|
|
printAtMiddleLoc(casts, 356, 82, FONT_SMALL, Colors::Cornsilk, to);
|
2012-05-07 15:54:22 +03:00
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
|
|
|
|
//TODO
|
|
|
|
int dmgMultiply = 1;
|
|
|
|
if(heroOwner && stackNode->hasBonusOfType(Bonus::SIEGE_WEAPON))
|
2012-02-16 20:10:58 +03:00
|
|
|
dmgMultiply += heroOwner->Attack();
|
2011-04-09 22:34:48 +03:00
|
|
|
|
|
|
|
printLine(3, CGI->generaltexth->allTexts[199], stackNode->getMinDamage() * dmgMultiply, stackNode->getMaxDamage() * dmgMultiply, true);
|
|
|
|
printLine(4, CGI->generaltexth->allTexts[388], c->valOfBonuses(Bonus::STACK_HEALTH), stackNode->valOfBonuses(Bonus::STACK_HEALTH));
|
|
|
|
printLine(6, CGI->generaltexth->zelp[441].first, c->valOfBonuses(Bonus::STACKS_SPEED), stackNode->valOfBonuses(Bonus::STACKS_SPEED));
|
|
|
|
|
|
|
|
BOOST_FOREACH(CBonusItem* b, bonusItems)
|
|
|
|
b->showAll (to);
|
2012-07-03 11:07:34 +03:00
|
|
|
|
|
|
|
BOOST_FOREACH(auto s, selectableSkills)
|
|
|
|
s->showAll (to);
|
|
|
|
|
|
|
|
for (int i = 0; i < skillPictures.size(); i++)
|
|
|
|
{
|
|
|
|
skillPictures[i]->bg = BitmapHandler::loadBitmap (skillToFile(i));
|
|
|
|
skillPictures[i]->showAll (to);
|
|
|
|
}
|
2012-07-04 17:41:53 +03:00
|
|
|
|
|
|
|
if (upgradeOptions[selectedOption] >= 100) //add frame to selected skill
|
|
|
|
{
|
|
|
|
int index = selectedOption - selectableSkills.size(); //this is screwed
|
|
|
|
CSDL_Ext::drawBorder(to, Rect::around(selectableBonuses[index]->pos), int3(Colors::MetallicGold.r, Colors::MetallicGold.g, Colors::MetallicGold.b));
|
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2011-08-05 10:59:15 +03:00
|
|
|
void CCreatureWindow::show(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
if (count.size()) //army stack
|
2011-12-22 16:05:19 +03:00
|
|
|
printTo(count, pos.x + 114, pos.y + 174,FONT_TIMES, Colors::Cornsilk, to);
|
2011-08-05 10:59:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
void CCreatureWindow::close()
|
|
|
|
{
|
|
|
|
if (upgradeOptions.size()) //a skill for commander was chosen
|
2012-07-04 17:41:53 +03:00
|
|
|
levelUp (selectedOption); //callback value is vector index
|
2012-07-03 11:07:34 +03:00
|
|
|
|
|
|
|
GH.popIntTotally(this);
|
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
void CCreatureWindow::sliderMoved(int newpos)
|
|
|
|
{
|
|
|
|
recreateSkillList(newpos); //move components
|
|
|
|
redraw();
|
|
|
|
}
|
2011-03-06 14:12:22 +02:00
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
std::string CCreatureWindow::skillToFile (int skill)
|
|
|
|
{
|
|
|
|
std::string file = "zvs/Lib1.res/_";
|
|
|
|
switch (skill)
|
|
|
|
{
|
|
|
|
case ECommander::ATTACK:
|
|
|
|
file += "AT";
|
|
|
|
break;
|
|
|
|
case ECommander::DEFENSE:
|
|
|
|
file += "DF";
|
|
|
|
break;
|
|
|
|
case ECommander::HEALTH:
|
|
|
|
file += "HP";
|
|
|
|
break;
|
|
|
|
case ECommander::DAMAGE:
|
|
|
|
file += "DM";
|
|
|
|
break;
|
|
|
|
case ECommander::SPEED:
|
|
|
|
file += "SP";
|
|
|
|
break;
|
|
|
|
case ECommander::SPELL_POWER:
|
|
|
|
file += "MP";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
std::string sufix = boost::lexical_cast<std::string>((int)(commander->secondarySkills[skill])); //casting ui8 causes ascii char conversion
|
|
|
|
if (type == COMMANDER_LEVEL_UP)
|
|
|
|
{
|
|
|
|
if (upgradeOptions.size() && upgradeOptions[selectedOption] == skill)//that one specific skill is selected
|
|
|
|
sufix += "="; //level-up highlight
|
|
|
|
else if (!vstd::contains(upgradeOptions, skill))
|
|
|
|
sufix = "no"; //not avaliable - no number
|
|
|
|
}
|
|
|
|
file += sufix += ".bmp";
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2012-05-22 20:16:37 +03:00
|
|
|
void CCreatureWindow::setArt(const CArtifactInstance *art)
|
2012-05-13 18:04:21 +03:00
|
|
|
{
|
2012-05-22 20:16:37 +03:00
|
|
|
creatureArtifact = art;
|
2012-05-13 18:04:21 +03:00
|
|
|
if (creatureArtifact)
|
|
|
|
{
|
|
|
|
if (artifactImage == NULL)
|
2012-05-22 20:16:37 +03:00
|
|
|
artifactImage = new CAnimImage("ARTIFACT", creatureArtifact->artType->id, 0, 466, 100);
|
2012-05-13 18:04:21 +03:00
|
|
|
else
|
|
|
|
artifactImage->setFrame(creatureArtifact->artType->id);
|
|
|
|
}
|
|
|
|
else
|
2012-05-22 20:16:37 +03:00
|
|
|
artifactImage = NULL;
|
|
|
|
|
|
|
|
redraw();
|
2012-05-13 18:04:21 +03:00
|
|
|
}
|
|
|
|
|
2011-03-03 20:25:48 +02:00
|
|
|
void CCreatureWindow::scrollArt(int dir)
|
|
|
|
{
|
2012-02-10 13:32:21 +03:00
|
|
|
//TODO: get next artifact
|
2012-05-22 20:16:37 +03:00
|
|
|
int size = stack->artifactsWorn.size();
|
|
|
|
displayedArtifact = size ? (displayedArtifact + dir) % size : ArtifactPosition::CREATURE_SLOT;
|
|
|
|
setArt (stack->getArt(displayedArtifact));
|
2012-02-10 13:32:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureWindow::passArtifactToHero()
|
|
|
|
{
|
2012-04-17 17:50:23 +03:00
|
|
|
const CGHeroInstance * h = dynamic_cast<const CGHeroInstance *>(stack->armyObj);
|
|
|
|
if (h && creatureArtifact)
|
|
|
|
{
|
2012-05-22 20:16:37 +03:00
|
|
|
LOCPLINT->cb->swapArtifacts (ArtifactLocation (stack, displayedArtifact), ArtifactLocation(h, creatureArtifact->firstBackpackSlot(h)));
|
2012-04-17 17:50:23 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
tlog2 << "Pass artifact to hero should be disabled, no hero or no artifact!\n";
|
|
|
|
|
|
|
|
//redraw is handled via CArtifactHolder interface
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureWindow::artifactRemoved (const ArtifactLocation &artLoc)
|
|
|
|
{
|
2012-05-25 18:10:38 +03:00
|
|
|
//align artifacts to remove holes
|
|
|
|
BOOST_FOREACH (auto al, stack->artifactsWorn)
|
|
|
|
{
|
|
|
|
int freeSlot = al.second.artifact->firstAvailableSlot(stack);
|
|
|
|
if (freeSlot < al.first)
|
|
|
|
LOCPLINT->cb->swapArtifacts (ArtifactLocation(stack, al.first), ArtifactLocation(stack, freeSlot));
|
|
|
|
}
|
2012-05-22 20:16:37 +03:00
|
|
|
int size = stack->artifactsWorn.size();
|
|
|
|
displayedArtifact = size ? (displayedArtifact % size) : ArtifactPosition::CREATURE_SLOT; //0
|
|
|
|
setArt (stack->getArt(displayedArtifact));
|
2012-04-17 17:50:23 +03:00
|
|
|
}
|
|
|
|
void CCreatureWindow::artifactMoved (const ArtifactLocation &artLoc, const ArtifactLocation &destLoc)
|
|
|
|
{
|
2012-05-22 20:16:37 +03:00
|
|
|
artifactRemoved (artLoc); //same code
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
void CCreatureWindow::selectSkill (ui32 which)
|
|
|
|
{
|
|
|
|
selectedOption = which;
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2011-03-06 14:12:22 +02:00
|
|
|
CCreatureWindow::~CCreatureWindow()
|
|
|
|
{
|
2011-03-20 10:45:05 +02:00
|
|
|
for (int i=0; i<upgResCost.size(); ++i)
|
2011-03-06 14:12:22 +02:00
|
|
|
delete upgResCost[i];
|
2011-04-09 22:34:48 +03:00
|
|
|
bonusItems.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CBonusItem::CBonusItem()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
CBonusItem::CBonusItem(const Rect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION;
|
|
|
|
visible = false;
|
|
|
|
|
|
|
|
name = Name;
|
|
|
|
description = Description;
|
|
|
|
if (graphicsName.size())
|
|
|
|
bonusGraphics = new CPicture(graphicsName, 26, 232);
|
|
|
|
else
|
|
|
|
bonusGraphics = NULL;
|
|
|
|
|
2012-06-02 18:16:54 +03:00
|
|
|
removeUsedEvents(ALL); //no actions atm
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusItem::showAll (SDL_Surface * to)
|
|
|
|
{
|
|
|
|
if (visible)
|
|
|
|
{
|
2011-12-22 16:05:19 +03:00
|
|
|
printAt(name, pos.x + 72, pos.y + 6, FONT_SMALL, Colors::Jasmine, to);
|
|
|
|
printAt(description, pos.x + 72, pos.y + 30, FONT_SMALL, Colors::Cornsilk, to);
|
2011-04-09 22:34:48 +03:00
|
|
|
if (bonusGraphics && bonusGraphics->bg)
|
|
|
|
blitAtLoc(bonusGraphics->bg, 12, 2, to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CBonusItem::~CBonusItem()
|
|
|
|
{
|
|
|
|
//delete bonusGraphics; //automatic destruction
|
2011-03-13 18:06:20 +02:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
void CSelectableSkill::clickLeft(tribool down, bool previousState)
|
|
|
|
{
|
|
|
|
if (down)
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void CCreInfoWindow::show(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
CIntObject::show(to);
|
|
|
|
creatureCount->showAll(to);
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreInfoWindow::CCreInfoWindow(const CStackInstance &stack, bool LClicked, boost::function<void()> upgradeFunc, boost::function<void()> dismissFunc, UpgradeInfo *upgradeInfo):
|
|
|
|
CWindowObject(PLAYER_COLORED | (LClicked ? 0 : RCLICK_POPUP), "CRSTKPU")
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
init(stack.type, &stack, dynamic_cast<const CGHeroInstance*>(stack.armyObj), stack.count, LClicked);
|
|
|
|
|
|
|
|
//additional buttons if opened with left click
|
|
|
|
if(LClicked)
|
|
|
|
{
|
|
|
|
boost::function<void()> closeFunc = boost::bind(&CCreInfoWindow::close,this);
|
|
|
|
|
|
|
|
if(upgradeFunc && upgradeInfo)
|
|
|
|
{
|
|
|
|
TResources upgradeCost = upgradeInfo->cost[0] * stack.count;
|
|
|
|
for(TResources::nziterator i(upgradeCost); i.valid(); i++)
|
|
|
|
{
|
|
|
|
BLOCK_CAPTURING;
|
2012-02-16 20:10:58 +03:00
|
|
|
upgResCost.push_back(new CComponent(CComponent::resource, i->resType, i->resVal));
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CFunctionList<void()> onUpgrade;
|
|
|
|
onUpgrade += upgradeFunc;
|
|
|
|
onUpgrade += closeFunc;
|
|
|
|
|
|
|
|
boost::function<void()> dialog = boost::bind(&CPlayerInterface::showYesNoDialog,
|
|
|
|
LOCPLINT,
|
|
|
|
CGI->generaltexth->allTexts[207],
|
2012-04-09 05:53:50 +03:00
|
|
|
onUpgrade, 0, false,
|
|
|
|
boost::ref(upgResCost));
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
upgrade = new CAdventureMapButton("", CGI->generaltexth->zelp[446].second, dialog, 76, 237, "IVIEWCR", SDLK_u);
|
|
|
|
upgrade->block(!LOCPLINT->cb->getResourceAmount().canAfford(upgradeCost));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dismissFunc)
|
|
|
|
{
|
|
|
|
CFunctionList<void()> onDismiss;
|
|
|
|
onDismiss += dismissFunc;
|
|
|
|
onDismiss += closeFunc;
|
|
|
|
|
|
|
|
boost::function<void()> dialog = boost::bind(&CPlayerInterface::showYesNoDialog,
|
|
|
|
LOCPLINT,
|
2012-02-16 20:10:58 +03:00
|
|
|
CGI->generaltexth->allTexts[12],
|
2012-04-09 05:53:50 +03:00
|
|
|
onDismiss, 0, true, std::vector<CComponent*>());
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
dismiss = new CAdventureMapButton("", CGI->generaltexth->zelp[445].second, dialog, 21, 237, "IVIEWCR2",SDLK_d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreInfoWindow::CCreInfoWindow(int creatureID, bool LClicked, int creatureCount):
|
|
|
|
CWindowObject(PLAYER_COLORED | (LClicked ? 0 : RCLICK_POPUP), "CRSTKPU")
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
const CCreature *creature = CGI->creh->creatures[creatureID];
|
|
|
|
init(creature, NULL, NULL, creatureCount, LClicked);
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreInfoWindow::CCreInfoWindow(const CStack &stack, bool LClicked):
|
|
|
|
CWindowObject(PLAYER_COLORED | (LClicked ? 0 : RCLICK_POPUP), "CRSTKPU")
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
init(stack.getCreature(), &stack, stack.getMyHero(), stack.count, LClicked);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCreInfoWindow::~CCreInfoWindow()
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(CComponent* object, upgResCost)
|
|
|
|
delete object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreInfoWindow::printLine(int position, const std::string &text, int baseVal, int val/*=-1*/, bool range/*=false*/)
|
|
|
|
{
|
|
|
|
infoTexts[position].first = new CLabel(155, 48 + position*19, FONT_SMALL, TOPLEFT, Colors::Cornsilk, text);
|
|
|
|
std::string valueStr;
|
|
|
|
|
|
|
|
if(range && baseVal != val)
|
|
|
|
valueStr = boost::str(boost::format("%d - %d") % baseVal % val);
|
|
|
|
|
|
|
|
else if(baseVal != val && val>=0)
|
|
|
|
valueStr = boost::str(boost::format("%d (%d)") % baseVal % val);
|
|
|
|
|
|
|
|
else
|
|
|
|
valueStr = boost::lexical_cast<std::string>(baseVal);
|
|
|
|
|
|
|
|
infoTexts[position].second = new CLabel(276, 63 + position*19, FONT_SMALL, BOTTOMRIGHT, Colors::Cornsilk, valueStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreInfoWindow::init(const CCreature *creature, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner, int count, bool LClicked)
|
|
|
|
{
|
2012-06-02 18:16:54 +03:00
|
|
|
removeUsedEvents(ALL);
|
2011-12-22 16:05:19 +03:00
|
|
|
if (!LClicked)
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(RCLICK);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
if(!stackNode)
|
|
|
|
stackNode = creature;
|
|
|
|
|
|
|
|
animation = new CCreaturePic(21, 48, creature);
|
|
|
|
|
|
|
|
std::string countStr = boost::lexical_cast<std::string>(count);
|
|
|
|
creatureCount = new CLabel(114, 174, FONT_TIMES, BOTTOMRIGHT, Colors::Cornsilk, countStr);
|
|
|
|
|
|
|
|
creatureName = new CLabel(149, 30, FONT_SMALL, CENTER, Colors::Jasmine, creature->namePl);
|
|
|
|
|
|
|
|
printLine(0, CGI->generaltexth->primarySkillNames[0], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK));
|
|
|
|
printLine(1, CGI->generaltexth->primarySkillNames[1], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE));
|
|
|
|
|
|
|
|
if(stackNode->valOfBonuses(Bonus::SHOTS))
|
|
|
|
printLine(2, CGI->generaltexth->allTexts[198], stackNode->valOfBonuses(Bonus::SHOTS));
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
int dmgMultiply = 1;
|
|
|
|
if(heroOwner && stackNode->hasBonusOfType(Bonus::SIEGE_WEAPON))
|
2012-02-16 20:10:58 +03:00
|
|
|
dmgMultiply += heroOwner->Attack();
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
printLine(3, CGI->generaltexth->allTexts[199], stackNode->getMinDamage() * dmgMultiply, stackNode->getMaxDamage() * dmgMultiply, true);
|
|
|
|
printLine(4, CGI->generaltexth->allTexts[388], creature->valOfBonuses(Bonus::STACK_HEALTH), stackNode->valOfBonuses(Bonus::STACK_HEALTH));
|
|
|
|
printLine(6, CGI->generaltexth->zelp[441].first, creature->valOfBonuses(Bonus::STACKS_SPEED), stackNode->valOfBonuses(Bonus::STACKS_SPEED));
|
|
|
|
|
|
|
|
//setting morale
|
|
|
|
morale = new MoraleLuckBox(true, genRect(42, 42, 22, 186));
|
|
|
|
morale->set(stackNode);
|
|
|
|
//setting luck
|
|
|
|
luck = new MoraleLuckBox(false, genRect(42, 42, 75, 186));
|
|
|
|
luck->set(stackNode);
|
|
|
|
|
|
|
|
if(!LClicked)
|
2012-03-31 00:36:07 +03:00
|
|
|
{
|
2011-12-22 16:05:19 +03:00
|
|
|
abilityText = new CLabel(17, 231, FONT_SMALL, TOPLEFT, Colors::Cornsilk, creature->abilityText);
|
2012-03-31 00:36:07 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
else
|
2012-03-31 00:36:07 +03:00
|
|
|
{
|
2011-12-22 16:05:19 +03:00
|
|
|
abilityText = NULL;
|
2012-03-31 00:36:07 +03:00
|
|
|
ok = new CAdventureMapButton("", CGI->generaltexth->zelp[445].second,
|
|
|
|
boost::bind(&CCreInfoWindow::close,this), 216, 237, "IOKAY.DEF", SDLK_RETURN);
|
2012-05-16 20:29:05 +03:00
|
|
|
ok->assignedKeys.insert(SDLK_ESCAPE);
|
2012-03-31 00:36:07 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
//if we are displying window fo r stack in battle, there are several more things that we need to display
|
|
|
|
if(const CStack *battleStack = dynamic_cast<const CStack*>(stackNode))
|
|
|
|
{
|
|
|
|
//print at most 3 spell effects
|
|
|
|
std::vector<si32> spells = battleStack->activeSpells();
|
|
|
|
for (size_t i=0; i< std::min(spells.size(), size_t(3)); i++)
|
|
|
|
effects.push_back(new CAnimImage("SpellInt", spells[i]+1, 0, 127 + 52*i, 186));
|
|
|
|
|
|
|
|
//print current health
|
|
|
|
printLine(5, CGI->generaltexth->allTexts[200], battleStack->firstHPleft);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-16 20:29:05 +03:00
|
|
|
CIntObject * createCreWindow(
|
|
|
|
const CStack *s, bool lclick/* = false*/)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2012-01-12 18:23:00 +03:00
|
|
|
if(settings["general"]["classicCreatureWindow"].Bool())
|
2012-03-31 00:36:07 +03:00
|
|
|
return new CCreInfoWindow(*s, lclick);
|
2011-12-22 16:05:19 +03:00
|
|
|
else
|
|
|
|
return new CCreatureWindow(*s, CCreatureWindow::BATTLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
CIntObject * createCreWindow(int Cid, int Type, int creatureCount)
|
|
|
|
{
|
2012-01-12 18:23:00 +03:00
|
|
|
if(settings["general"]["classicCreatureWindow"].Bool())
|
2011-12-22 16:05:19 +03:00
|
|
|
return new CCreInfoWindow(Cid, Type, creatureCount);
|
|
|
|
else
|
|
|
|
return new CCreatureWindow(Cid, Type, creatureCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
CIntObject * createCreWindow(const CStackInstance *s, int type, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui)
|
|
|
|
{
|
2012-01-12 18:23:00 +03:00
|
|
|
if(settings["general"]["classicCreatureWindow"].Bool())
|
2011-12-22 16:05:19 +03:00
|
|
|
return new CCreInfoWindow(*s, type==3, Upg, Dsm, ui);
|
|
|
|
else
|
|
|
|
return new CCreatureWindow(*s, type, Upg, Dsm, ui);
|
|
|
|
}
|