mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
* partially done campaign bonus selection
This commit is contained in:
parent
d3bf011270
commit
052e4f08e5
@ -35,6 +35,7 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <cstdlib>
|
||||
#include "CMessage.h"
|
||||
#include "../hch/CSpellHandler.h" /*for campaign bonuses*/
|
||||
/*
|
||||
* CPreGame.cpp, part of VCMI engine
|
||||
*
|
||||
@ -2192,7 +2193,7 @@ void CHotSeatPlayers::enterSelectionScreen()
|
||||
}
|
||||
|
||||
CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap )
|
||||
: ourCampaign(_ourCampaign), whichMap(_whichMap), highlightedRegion(NULL), ourHeader(NULL)
|
||||
: ourCampaign(_ourCampaign), whichMap(_whichMap), highlightedRegion(NULL), ourHeader(NULL), bonuses(NULL)
|
||||
{
|
||||
OBJ_CONSTRUCTION;
|
||||
static const std::string bgNames [] = {"E1_BG.BMP", "G2_BG.BMP", "E2_BG.BMP", "G1_BG.BMP", "G3_BG.BMP", "N1_BG.BMP",
|
||||
@ -2223,10 +2224,15 @@ CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap
|
||||
//campaign description
|
||||
printAtLoc(CGI->generaltexth->allTexts[38], 481, 63, FONT_SMALL, tytulowy, background);
|
||||
|
||||
// std::vector<std::string> *desc = CMessage::breakText(ourCampaign->header.description, 45);
|
||||
// for (int i=0; i<desc->size() ;i++)
|
||||
// printAtLoc((*desc)[i], 481, 86 + i*16, FONT_SMALL, zwykly, background);
|
||||
// delete desc;
|
||||
cmpgDesc = new CTextBox(ourCampaign->header.description, Rect(480, 86, 286, 117), 1);
|
||||
cmpgDesc->showAll(background);
|
||||
|
||||
//map description
|
||||
mapDesc = new CTextBox("", Rect(480, 280, 286, 117), 1);
|
||||
|
||||
//bonus choosing
|
||||
printAtLoc(CGI->generaltexth->allTexts[71], 510, 431, FONT_MEDIUM, zwykly, background); //Choose a bonus:
|
||||
bonuses = new CHighlightableButtonsGroup(0);
|
||||
|
||||
//set left part of window
|
||||
for (int g=0; g<ourCampaign->scenarios.size(); ++g)
|
||||
@ -2262,9 +2268,6 @@ CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap
|
||||
|
||||
SDL_FreeSurface(panel);
|
||||
|
||||
//bonus choosing
|
||||
printAtLoc(CGI->generaltexth->allTexts[71], 510, 431, FONT_MEDIUM, zwykly, background); //Choose a bonus:
|
||||
|
||||
//difficulty
|
||||
printAtLoc("Difficulty", 691, 431, FONT_MEDIUM, zwykly, background); //Difficulty
|
||||
|
||||
@ -2339,6 +2342,10 @@ void CBonusSelection::selectMap( int whichOne )
|
||||
CSelectionScreen::updateStartInfo(curMap, sInfo, ourHeader);
|
||||
sInfo.turnTime = 0;
|
||||
sInfo.whichMapInCampaign = whichOne;
|
||||
|
||||
mapDesc->setTxt(ourHeader->description);
|
||||
|
||||
updateBonusSelection();
|
||||
}
|
||||
|
||||
void CBonusSelection::show( SDL_Surface * to )
|
||||
@ -2346,8 +2353,7 @@ void CBonusSelection::show( SDL_Surface * to )
|
||||
blitAt(background, pos.x, pos.y, to);
|
||||
|
||||
//map name
|
||||
std::string mapDesc = ourHeader->description,
|
||||
mapName = ourHeader->name;
|
||||
std::string mapName = ourHeader->name;
|
||||
|
||||
if (mapName.length())
|
||||
printAtLoc(mapName, 481, 219, FONT_BIG, tytulowy, to);
|
||||
@ -2357,10 +2363,7 @@ void CBonusSelection::show( SDL_Surface * to )
|
||||
//map description
|
||||
printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, tytulowy, to);
|
||||
|
||||
// std::vector<std::string> *desc = CMessage::breakText(mapDesc, 45);
|
||||
// for (int i=0; i<desc->size(); i++)
|
||||
// printAtLoc((*desc)[i], 481, 281 + i*16, FONT_SMALL, zwykly, to);
|
||||
// delete desc;
|
||||
mapDesc->showAll(to); //showAll because CTextBox has no show()
|
||||
|
||||
//map size icon
|
||||
int temp;
|
||||
@ -2400,19 +2403,125 @@ void CBonusSelection::updateBonusSelection()
|
||||
//resource - BORES.DEF
|
||||
//player - ?
|
||||
//hero -?
|
||||
const CCampaignScenario &scenario = ourCampaign->scenarios[sInfo.whichMapInCampaign];
|
||||
const std::vector<CScenarioTravel::STravelBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
|
||||
|
||||
bonuses = new CHighlightableButtonsGroup(0);
|
||||
CDefEssential * twcp = CDefHandler::giveDefEss("TWCRPORT.DEF"); //for yellow border
|
||||
|
||||
bonuses->buttons.clear();
|
||||
{
|
||||
BLOCK_CAPTURING;
|
||||
static const char *bonDefs[] = {"SPELLBON.DEF", "TWCRPORT.DEF", "GSPBUT5.DEF", "ARTIFBON.DEF", "SPELLBON.DEF",
|
||||
"PSKILBON.DEF", "SSKILBON.DEF", "BORES.DEF", "GSPBUT5.DEF", "GSPBUT5.DEF"};
|
||||
|
||||
for(int i = 0; i < 5; i++)
|
||||
for(int i = 0; i < bonDescs.size(); i++)
|
||||
{
|
||||
bonuses->addButton(new CHighlightableButton("", "", 0, 110 + i*32, 450, bonDefs[i], i));
|
||||
bonuses->buttons.back()->pos += Point(68, 0);
|
||||
SDL_Surface *notSelected, *selected;
|
||||
|
||||
CDefEssential * de = CDefHandler::giveDefEss(bonDefs[bonDescs[i].type]);
|
||||
SDL_Surface * surfToDuplicate = NULL;
|
||||
|
||||
std::string desc;
|
||||
switch(bonDescs[i].type)
|
||||
{
|
||||
case 0: //spell
|
||||
surfToDuplicate = de->ourImages[bonDescs[i].info2].bitmap;
|
||||
desc = CGI->generaltexth->allTexts[715];
|
||||
boost::algorithm::replace_first(desc, "%s", CGI->spellh->spells[bonDescs[i].info2].name);
|
||||
break;
|
||||
case 1: //monster
|
||||
surfToDuplicate = de->ourImages[bonDescs[i].info2 + 2].bitmap;
|
||||
desc = CGI->generaltexth->allTexts[717];
|
||||
boost::algorithm::replace_first(desc, "%d", boost::lexical_cast<std::string>(bonDescs[i].info3));
|
||||
boost::algorithm::replace_first(desc, "%s", CGI->creh->creatures[bonDescs[i].info2]->namePl);
|
||||
break;
|
||||
case 2: //building
|
||||
//TODO
|
||||
break;
|
||||
case 3: //artifact
|
||||
surfToDuplicate = de->ourImages[bonDescs[i].info2].bitmap;
|
||||
desc = CGI->generaltexth->allTexts[715];
|
||||
boost::algorithm::replace_first(desc, "%s", CGI->arth->artifacts[bonDescs[i].info2]->Name());
|
||||
break;
|
||||
case 4: //spell scroll
|
||||
surfToDuplicate = de->ourImages[bonDescs[i].info2].bitmap;
|
||||
desc = CGI->generaltexth->allTexts[716];
|
||||
boost::algorithm::replace_first(desc, "%s", CGI->spellh->spells[bonDescs[i].info2].name);
|
||||
break;
|
||||
case 5: //primary skill
|
||||
{
|
||||
int leadingSkill = -1;
|
||||
std::vector<std::pair<int, int>> toPrint; //primary skills to be listed <num, val>
|
||||
const ui8* ptr = reinterpret_cast<const ui8*>(&bonDescs[i].info2);
|
||||
for (int g=0; g<PRIMARY_SKILLS; ++g)
|
||||
{
|
||||
if (leadingSkill == -1 || ptr[g] > ptr[leadingSkill])
|
||||
{
|
||||
leadingSkill = g;
|
||||
}
|
||||
if (ptr[g] != 0)
|
||||
{
|
||||
toPrint.push_back(std::make_pair(g, ptr[g]));
|
||||
}
|
||||
}
|
||||
surfToDuplicate = de->ourImages[leadingSkill].bitmap;
|
||||
desc = CGI->generaltexth->allTexts[715];
|
||||
|
||||
std::string substitute; //text to be printed instead of %s
|
||||
for (int v=0; v<toPrint.size(); ++v)
|
||||
{
|
||||
substitute += boost::lexical_cast<std::string>(toPrint[v].second);
|
||||
substitute += " " + CGI->generaltexth->primarySkillNames[toPrint[v].first];
|
||||
if(v != toPrint.size() - 1)
|
||||
{
|
||||
substitute += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
boost::algorithm::replace_first(desc, "%s", substitute);
|
||||
break;
|
||||
}
|
||||
case 6: //secondary skill
|
||||
surfToDuplicate = de->ourImages[bonDescs[i].info2].bitmap;
|
||||
desc = CGI->generaltexth->allTexts[718];
|
||||
|
||||
boost::algorithm::replace_first(desc, "%s", CGI->generaltexth->levels[bonDescs[i].info3]); //skill level
|
||||
boost::algorithm::replace_first(desc, "%s", CGI->generaltexth->skillName[bonDescs[i].info2]); //skill name
|
||||
|
||||
break;
|
||||
case 7: //resource
|
||||
//TODO
|
||||
break;
|
||||
case 8: //player
|
||||
//TODO
|
||||
break;
|
||||
case 9: //hero
|
||||
//TODO
|
||||
break;
|
||||
}
|
||||
|
||||
bonuses->addButton(new CHighlightableButton(desc, desc, 0, 475 + i*68, 455, bonDefs[bonDescs[i].type], i));
|
||||
|
||||
notSelected = SDL_ConvertSurface(surfToDuplicate, surfToDuplicate->format, surfToDuplicate->flags);
|
||||
selected = SDL_ConvertSurface(notSelected, notSelected->format, notSelected->flags);
|
||||
|
||||
//printing yellow border
|
||||
blitAt(twcp->ourImages[1].bitmap, 0, 0, selected);
|
||||
|
||||
//moving surfaces into button
|
||||
bonuses->buttons.back()->imgs[0].clear();
|
||||
bonuses->buttons.back()->imgs[0].push_back(notSelected);
|
||||
bonuses->buttons.back()->imgs[0].push_back(selected);
|
||||
|
||||
//cleaning
|
||||
delete de;
|
||||
}
|
||||
}
|
||||
|
||||
bonuses->select(0, 0);
|
||||
|
||||
delete twcp;
|
||||
|
||||
}
|
||||
|
||||
void CBonusSelection::startMap()
|
||||
|
@ -275,6 +275,9 @@ class CBonusSelection : public CIntObject
|
||||
SDL_Surface * background;
|
||||
AdventureMapButton * startB, * backB;
|
||||
|
||||
//campaign & map descriptions:
|
||||
CTextBox * cmpgDesc, * mapDesc;
|
||||
|
||||
struct SCampPositions
|
||||
{
|
||||
std::string campPrefix;
|
||||
|
@ -945,13 +945,13 @@ SDLKey numToDigit( SDLKey key )
|
||||
REMOVE_KP(PERIOD)
|
||||
REMOVE_KP(MINUS)
|
||||
REMOVE_KP(PLUS)
|
||||
REMOVE_KP(EQUALS)
|
||||
|
||||
case SDLK_KP_MULTIPLY:
|
||||
return SDLK_ASTERISK;
|
||||
case SDLK_KP_DIVIDE:
|
||||
return SDLK_SLASH;
|
||||
case SDLK_KP_ENTER:
|
||||
REMOVE_KP(EQUALS)
|
||||
|
||||
case SDLK_KP_MULTIPLY:
|
||||
return SDLK_ASTERISK;
|
||||
case SDLK_KP_DIVIDE:
|
||||
return SDLK_SLASH;
|
||||
case SDLK_KP_ENTER:
|
||||
return SDLK_RETURN;
|
||||
default:
|
||||
tlog3 << "Illegal numkey conversion!" << std::endl;
|
||||
|
@ -1,89 +1,89 @@
|
||||
#ifndef __CARTHANDLER_H__
|
||||
#define __CARTHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include "../lib/HeroBonus.h"
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* CArtHandler.h, 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
|
||||
*
|
||||
*/
|
||||
class CDefHandler;
|
||||
|
||||
class DLL_EXPORT CArtifact : public CBonusSystemNode //container for artifacts
|
||||
{
|
||||
std::string name, description; //set if custom
|
||||
public:
|
||||
enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
|
||||
const std::string &Name() const; //getter
|
||||
const std::string &Description() const; //getter
|
||||
bool isBig () const;
|
||||
bool fitsAt (const std::map<ui16, ui32> &artifWorn, ui16 slot) const;
|
||||
bool canBeAssembledTo (const std::map<ui16, ui32> &artifWorn, ui32 artifactID) const;
|
||||
void addBonusesTo (BonusList *otherBonuses) const;
|
||||
void removeBonusesFrom (BonusList *otherBonuses) const;
|
||||
int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
|
||||
|
||||
ui32 price;
|
||||
std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed
|
||||
std::vector<ui32> * constituents; // Artifacts IDs a combined artifact consists of, or NULL.
|
||||
std::vector<ui32> * constituentOf; // Reverse map of constituents.
|
||||
EartClass aClass;
|
||||
si32 id;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & static_cast<CBonusSystemNode&>(*this);;
|
||||
h & name & description & price & possibleSlots & constituents & constituentOf & aClass & id;
|
||||
}
|
||||
|
||||
CArtifact();
|
||||
~CArtifact();
|
||||
|
||||
#ifndef __CARTHANDLER_H__
|
||||
#define __CARTHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include "../lib/HeroBonus.h"
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
* CArtHandler.h, 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
|
||||
*
|
||||
*/
|
||||
class CDefHandler;
|
||||
|
||||
class DLL_EXPORT CArtifact : public CBonusSystemNode //container for artifacts
|
||||
{
|
||||
std::string name, description; //set if custom
|
||||
public:
|
||||
enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
|
||||
const std::string &Name() const; //getter
|
||||
const std::string &Description() const; //getter
|
||||
bool isBig () const;
|
||||
bool fitsAt (const std::map<ui16, ui32> &artifWorn, ui16 slot) const;
|
||||
bool canBeAssembledTo (const std::map<ui16, ui32> &artifWorn, ui32 artifactID) const;
|
||||
void addBonusesTo (BonusList *otherBonuses) const;
|
||||
void removeBonusesFrom (BonusList *otherBonuses) const;
|
||||
int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
|
||||
|
||||
ui32 price;
|
||||
std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed
|
||||
std::vector<ui32> * constituents; // Artifacts IDs a combined artifact consists of, or NULL.
|
||||
std::vector<ui32> * constituentOf; // Reverse map of constituents.
|
||||
EartClass aClass;
|
||||
si32 id;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & static_cast<CBonusSystemNode&>(*this);;
|
||||
h & name & description & price & possibleSlots & constituents & constituentOf & aClass & id;
|
||||
}
|
||||
|
||||
CArtifact();
|
||||
~CArtifact();
|
||||
|
||||
//override
|
||||
void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CArtHandler //handles artifacts
|
||||
{
|
||||
void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER);
|
||||
public:
|
||||
std::vector<CArtifact*> treasures, minors, majors, relics;
|
||||
std::vector<CArtifact *> artifacts;
|
||||
std::vector<CArtifact *> allowedArtifacts;
|
||||
std::set<ui32> bigArtifacts; // Artifacts that cannot be moved to backpack, e.g. war machines.
|
||||
|
||||
void loadArtifacts(bool onlyTxt);
|
||||
void sortArts();
|
||||
void addBonuses();
|
||||
void clear();
|
||||
void clearHlpLists();
|
||||
ui16 getRandomArt (int flags);
|
||||
ui16 getArtSync (ui32 rand, int flags);
|
||||
void getAllowedArts(std::vector<CArtifact*> &out, std::vector<CArtifact*> *arts, int flag);
|
||||
void getAllowed(std::vector<CArtifact*> &out, int flags);
|
||||
void erasePickedArt (si32 id);
|
||||
bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();}
|
||||
void equipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID, ui32 artifactID);
|
||||
void unequipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID);
|
||||
static int convertMachineID(int id, bool creToArt);
|
||||
CArtHandler();
|
||||
~CArtHandler();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & artifacts & allowedArtifacts & treasures & minors & majors & relics;
|
||||
//if(!h.saving) sortArts();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __CARTHANDLER_H__
|
||||
void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CArtHandler //handles artifacts
|
||||
{
|
||||
void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER);
|
||||
public:
|
||||
std::vector<CArtifact*> treasures, minors, majors, relics;
|
||||
std::vector<CArtifact *> artifacts;
|
||||
std::vector<CArtifact *> allowedArtifacts;
|
||||
std::set<ui32> bigArtifacts; // Artifacts that cannot be moved to backpack, e.g. war machines.
|
||||
|
||||
void loadArtifacts(bool onlyTxt);
|
||||
void sortArts();
|
||||
void addBonuses();
|
||||
void clear();
|
||||
void clearHlpLists();
|
||||
ui16 getRandomArt (int flags);
|
||||
ui16 getArtSync (ui32 rand, int flags);
|
||||
void getAllowedArts(std::vector<CArtifact*> &out, std::vector<CArtifact*> *arts, int flag);
|
||||
void getAllowed(std::vector<CArtifact*> &out, int flags);
|
||||
void erasePickedArt (si32 id);
|
||||
bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();}
|
||||
void equipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID, ui32 artifactID);
|
||||
void unequipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID);
|
||||
static int convertMachineID(int id, bool creToArt);
|
||||
CArtHandler();
|
||||
~CArtHandler();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & artifacts & allowedArtifacts & treasures & minors & majors & relics;
|
||||
//if(!h.saving) sortArts();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __CARTHANDLER_H__
|
||||
|
Loading…
Reference in New Issue
Block a user