From 9ec431c37bbb13e01da68ad27b1a875ca1c2d32f Mon Sep 17 00:00:00 2001 From: paracelsus Date: Thu, 7 Mar 2013 19:17:23 +0000 Subject: [PATCH] Synchronization with trunk (again), elimination of some warnings --- client/CCreatureWindow.cpp | 26 +- client/CCreatureWindow.h | 1 - client/CPreGame.cpp | 2 +- client/CQuestLog.cpp | 4 +- client/GUIClasses.cpp | 6 +- client/UIFramework/CGuiHandler.cpp | 4 +- client/UIFramework/CGuiHandler.h | 2 +- client/UIFramework/CIntObjectClasses.cpp | 4 +- client/mapHandler.cpp | 24 +- lib/BattleState.cpp | 2 +- lib/BattleState.h | 2 - lib/CArtHandler.cpp | 14 +- lib/CArtHandler.h | 6 +- lib/CBattleCallback.cpp | 6 +- lib/CBattleCallback.h | 2 +- lib/CBonusTypeHandler.cpp | 337 +++++++++++++++++++++++ lib/CBonusTypeHandler.h | 93 +++++++ lib/CCreatureHandler.cpp | 26 +- lib/CCreatureHandler.h | 6 +- lib/CCreatureSet.cpp | 336 +--------------------- lib/CCreatureSet.h | 3 +- lib/CGameState.cpp | 48 ++-- lib/CGameState.h | 4 - lib/CMakeLists.txt | 2 + lib/CModHandler.cpp | 2 +- lib/CObjectHandler.cpp | 34 +-- lib/CObjectHandler.h | 8 +- lib/CSpellHandler.cpp | 4 +- lib/CSpellHandler.h | 2 +- lib/HeroBonus.cpp | 2 +- lib/IBonusTypeHandler.h | 25 ++ lib/IGameCallback.cpp | 3 +- lib/Mapping/CCampaignHandler.cpp | 4 +- lib/Mapping/CMapEditManager.cpp | 6 +- lib/NetPacksLib.cpp | 36 ++- lib/ResourceSet.h | 8 +- lib/VCMIDirs.cpp | 2 +- lib/VCMI_Lib.cpp | 99 +++---- lib/VCMI_Lib.h | 10 +- lib/VCMI_lib.cbp | 6 + lib/VCMI_lib.vcxproj | 4 +- 41 files changed, 677 insertions(+), 538 deletions(-) create mode 100644 lib/CBonusTypeHandler.cpp create mode 100644 lib/CBonusTypeHandler.h create mode 100644 lib/IBonusTypeHandler.h diff --git a/client/CCreatureWindow.cpp b/client/CCreatureWindow.cpp index 1cdccd298..6d2735a3c 100644 --- a/client/CCreatureWindow.cpp +++ b/client/CCreatureWindow.cpp @@ -22,13 +22,13 @@ #include "../lib/CArtHandler.h" #include "../lib/NetPacks.h" //ArtifactLocation #include "../lib/CModHandler.h" +#include "../lib/IBonusTypeHandler.h" #include "UIFramework/CGuiHandler.h" #include "UIFramework/CIntObjectClasses.h" using namespace CSDL_Ext; -class CBonusItem; class CCreatureArtifactInstance; class CSelectableSkill; @@ -269,24 +269,24 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * } } - int magicResistance = 0; //handle it separately :/ + + //handle Magic resistance separately :/ + const IBonusBearer *temp = stack; + if (battleStack) { - magicResistance = battleStack->magicResistance(); //include Aura of Resistance - } - else - { - magicResistance = stack->magicResistance(); //include Resiatance hero skill + temp = battleStack; } + + int magicResistance = temp->magicResistance(); + if (magicResistance) { - std::map >::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(magicResistance)); Bonus b; b.type = Bonus::MAGIC_RESISTANCE; + + text = VLC->getBth()->bonusToString(&b,temp,false); + const std::string description = VLC->getBth()->bonusToString(&b,temp,true); bonusItems.push_back (new CBonusItem(genRect(0, 0, 251, 57), text, description, stack->bonusToGraphics(&b))); } @@ -392,7 +392,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * } } - if (CGI->modh->modules.STACK_EXP) + if (CGI->modh->modules.STACK_ARTIFACT) { creArt = true; } diff --git a/client/CCreatureWindow.h b/client/CCreatureWindow.h index 66e4add4d..9b138c3b8 100644 --- a/client/CCreatureWindow.h +++ b/client/CCreatureWindow.h @@ -117,7 +117,6 @@ public: CBonusItem(const Rect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName); ~CBonusItem(); - void setBonus(const Bonus &bonus); void showAll(); }; diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index a8d746bf4..b1be9bdf7 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -3467,7 +3467,7 @@ void CBonusSelection::updateBonusSelection() desc = CGI->generaltexth->allTexts[715]; std::string substitute; //text to be printed instead of %s - for (int v=0; v(toPrint[v].second); substitute += " " + CGI->generaltexth->primarySkillNames[toPrint[v].first]; diff --git a/client/CQuestLog.cpp b/client/CQuestLog.cpp index e8d8d85aa..86cdc4a92 100644 --- a/client/CQuestLog.cpp +++ b/client/CQuestLog.cpp @@ -136,7 +136,7 @@ void CQuestLog::init() if (quests.size() > QUEST_COUNT) slider = new CSlider(203, 199, 230, boost::bind (&CQuestLog::sliderMoved, this, _1), QUEST_COUNT, quests.size(), false, 0); - for (int i = 0; i < quests.size(); ++i) + for (size_t i = 0; i < quests.size(); ++i) { MetaString text; quests[i].quest->getRolloverText (text, false); @@ -169,7 +169,7 @@ void CQuestLog::showAll() void CQuestLog::recreateQuestList (int newpos) { - for (int i = 0; i < labels.size(); ++i) + for (size_t i = 0; i < labels.size(); ++i) { labels[i]->pos = Rect (pos.x + 28, pos.y + 207 + (i-newpos) * 25, 173, 23); if (i >= newpos && i < newpos + QUEST_COUNT) diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 97c26d65a..7e84be4a9 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -5110,10 +5110,10 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2) } //heroes related thing - for(int b=0; bsecSkills.size(); ++g) + for(size_t g=0; gsecSkills.size(); ++g) { int skill = heroInst[b]->secSkills[g].first, level = heroInst[b]->secSkills[g].second; // <1, 3> @@ -5242,7 +5242,7 @@ CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio): auto & puzzleMap = CGI->townh->factions[faction].puzzleMap; - for(int g=0; ghovered = false; } } - for(int i=0; ihover(true); hlp[i]->hovered = true; diff --git a/client/UIFramework/CGuiHandler.h b/client/UIFramework/CGuiHandler.h index c00979e0b..e69a29f81 100644 --- a/client/UIFramework/CGuiHandler.h +++ b/client/UIFramework/CGuiHandler.h @@ -84,7 +84,7 @@ public: void popInt(IShowActivatable *top); //removes given interface from the top and activates next void popIntTotally(IShowActivatable *top); //deactivates, deletes, removes given interface from the top and activates next void pushInt(IShowActivatable *newInt); //deactivate old top interface, activates this one and pushes to the top - void popInts(int howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front + void popInts(size_t howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front IShowActivatable *topInt(); //returns top interface void updateTime(); //handles timeInterested diff --git a/client/UIFramework/CIntObjectClasses.cpp b/client/UIFramework/CIntObjectClasses.cpp index 30835dc10..7bb3b53b6 100644 --- a/client/UIFramework/CIntObjectClasses.cpp +++ b/client/UIFramework/CIntObjectClasses.cpp @@ -1342,8 +1342,8 @@ void CTextBox::recalculateLines(const std::string &Txt) vstd::clear_pointer(slider); lines.clear(); const IFont * f = graphics->fonts[font]; - int lineHeight = f->getLineHeight(); - int lineCapacity = pos.h / lineHeight; + size_t lineHeight = f->getLineHeight(); + size_t lineCapacity = pos.h / lineHeight; lines = CMessage::breakText(Txt, pos.w, font); if (lines.size() > lineCapacity) //we need to add a slider diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index d874d10ce..78f165a69 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -371,7 +371,7 @@ void CMapHandler::init() offsetX = (mapW - (2*frameW+1)*32)/2; offsetY = (mapH - (2*frameH+1)*32)/2; - for(int i=0;iheroes.size();i++) + for(size_t i=0; iheroes.size(); ++i) { if( !graphics->getDef(map->heroes[i]) ) { @@ -461,7 +461,7 @@ void CMapHandler::terrainRect( int3 top_tile, ui8 anim, const std::vector< std:: // printing terrain srx = srx_init; - for (int bx = 0; bx < dx; bx++, srx+=32) + for (size_t bx = 0; bx < dx; bx++, srx+=32) { // Skip column if not in map if (top_tile.x+bx < 0 || top_tile.x+bx >= sizes.x) @@ -469,7 +469,7 @@ void CMapHandler::terrainRect( int3 top_tile, ui8 anim, const std::vector< std:: sry = sry_init; - for (int by=0; by < dy; by++, sry+=32) + for (size_t by=0; by < dy; by++, sry+=32) { int3 pos(top_tile.x+bx, top_tile.y+by, top_tile.z); //blitted tile position @@ -518,7 +518,7 @@ void CMapHandler::terrainRect( int3 top_tile, ui8 anim, const std::vector< std:: //blit objects const std::vector < std::pair > &objects = tile.objects; - for(int h=0; h < objects.size(); ++h) + for(size_t h=0; h < objects.size(); ++h) { const CGObjectInstance *obj = objects[h].first; if (!graphics->getDef(obj)) @@ -676,11 +676,11 @@ void CMapHandler::terrainRect( int3 top_tile, ui8 anim, const std::vector< std:: // printing borders srx = srx_init; - for (int bx = 0; bx < dx; bx++, srx+=32) + for (size_t bx = 0; bx < dx; bx++, srx+=32) { sry = sry_init; - for (int by = 0; byFoWfullHide; delete graphics->FoWpartialHide; - for(int i=0; i < roadDefs.size(); i++) + for(size_t i=0; i < roadDefs.size(); i++) delete roadDefs[i]; - for(int i=0; i < staticRiverDefs.size(); i++) + for(size_t i=0; i < staticRiverDefs.size(); i++) delete staticRiverDefs[i]; - for(int i=0; i < terrainGraphics.size(); ++i) + for(size_t i=0; i < terrainGraphics.size(); ++i) { - for(int j=0; j < terrainGraphics[i].size(); ++j) + for(size_t j=0; j < terrainGraphics[i].size(); ++j) SDL_FreeSurface(terrainGraphics[i][j]); } terrainGraphics.clear(); diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index 6ba349098..2e6bbc409 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -55,7 +55,7 @@ int BattleInfo::getAvaliableHex(CreatureID creID, bool attackerOwned, int initia auto accessibility = getAccesibility(); std::set occupyable; - for(int i = 0; i < accessibility.size(); i++) + for(size_t i = 0; i < accessibility.size(); ++i) if(accessibility.accessible(i, twoHex, attackerOwned)) occupyable.insert(i); diff --git a/lib/BattleState.h b/lib/BattleState.h index f8a6cbd26..9bf813743 100644 --- a/lib/BattleState.h +++ b/lib/BattleState.h @@ -79,8 +79,6 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallb BattleInfo(); ~BattleInfo(){}; - ////////////////////////////////////////////////////////////////////////// - //void getBonuses(BonusList &out, const CSelector &selector, const CBonusSystemNode *root = NULL) const; ////////////////////////////////////////////////////////////////////////// CStack * getStackT(BattleHex tileID, bool onlyAlive = true); CStack * getStack(int stackID, bool onlyAlive = true); diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index de088993f..40db13f17 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -161,7 +161,7 @@ CArtHandler::~CArtHandler() { } -void CArtHandler::loadArtifacts(bool onlyTxt) +void CArtHandler::load(bool onlyTxt) { if (onlyTxt) return; // looks to be broken anyway... @@ -203,7 +203,7 @@ void CArtHandler::loadArtifacts(bool onlyTxt) art->price= parser.readNumber(); - for(int j=0; jpossibleSlots[ArtBearer::HERO].push_back(ArtifactPosition(artSlots[j])); @@ -416,7 +416,7 @@ ArtifactID CArtHandler::getArtSync (ui32 rand, int flags, bool erasePicked) if (arts->empty()) //restock available arts fillList(*arts, flag); - for (int i = 0; i < arts->size(); ++i) + for (size_t i = 0; i < arts->size(); ++i) { CArtifact *art = (*arts)[i]; out.push_back(art); @@ -553,7 +553,7 @@ void CArtHandler::initAllowedArtifactsList(const std::vector &allowed) allowedArtifacts.push_back(artifacts[i]); } } - for (int i = GameConstants::ARTIFACTS_QUANTITY; i < artifacts.size(); ++i) //allow all new artifacts by default + for (size_t i = GameConstants::ARTIFACTS_QUANTITY; i < artifacts.size(); ++i) //allow all new artifacts by default { if (legalArtifact(ArtifactID(i))) allowedArtifacts.push_back(artifacts[i]); @@ -612,7 +612,7 @@ boost::optional&> CArtHandler::listFromClass( CArtifact: void CArtHandler::fillList( std::vector &listToBeFilled, CArtifact::EartClass artifactClass ) { assert(listToBeFilled.empty()); - for (int i = 0; i < allowedArtifacts.size(); ++i) + for (size_t i = 0; i < allowedArtifacts.size(); ++i) { if (allowedArtifacts[i]->aClass == artifactClass) listToBeFilled.push_back(allowedArtifacts[i]); @@ -1022,7 +1022,7 @@ ArtifactPosition CArtifactSet::getArtPos(int aid, bool onlyWorn /*= true*/) cons if(onlyWorn) return ArtifactPosition::PRE_FIRST; - for(int i = 0; i < artifactsInBackpack.size(); i++) + for(size_t i = 0; i < artifactsInBackpack.size(); ++i) if(artifactsInBackpack[i].artifact->artType->id == aid) return ArtifactPosition(GameConstants::BACKPACK_START + i); @@ -1035,7 +1035,7 @@ ArtifactPosition CArtifactSet::getArtPos(const CArtifactInstance *art) const if(i.second.artifact == art) return i.first; - for(int i = 0; i < artifactsInBackpack.size(); i++) + for(size_t i = 0; i < artifactsInBackpack.size(); ++i) if(artifactsInBackpack[i].artifact == art) return ArtifactPosition(GameConstants::BACKPACK_START + i); diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index 9273db159..1286bd910 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -59,8 +59,8 @@ public: bool isBig () const; int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other - std::string nodeName() const override; - void addNewBonus(Bonus *b) override; + std::string nodeName() const OVERRIDE; + void addNewBonus(Bonus *b) OVERRIDE; virtual void levelUpArtifact (CArtifactInstance * art){}; @@ -198,7 +198,7 @@ public: std::set bigArtifacts; // Artifacts that cannot be moved to backpack, e.g. war machines. std::set growingArtifacts; - void loadArtifacts(bool onlyTxt); + void load(bool onlyTxt = false); /// load artifact from json structure void load(std::string objectID, const JsonNode & node); /// load one artifact from json config diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index e5f6e35a3..b7a0fba0f 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -493,7 +493,7 @@ const CStack* CBattleInfoCallback::battleGetStackByPos(BattleHex pos, bool onlyA return nullptr; } -void CBattleInfoCallback::battleGetStackQueue(std::vector &out, const int howMany, const int turn /*= 0*/, int lastMoved /*= -1*/) const +void CBattleInfoCallback::battleGetStackQueue(std::vector &out, const size_t howMany, const int turn /*= 0*/, int lastMoved /*= -1*/) const { RETURN_IF_NOT_BATTLE(); @@ -606,10 +606,10 @@ void CBattleInfoCallback::battleGetStackQueue(std::vector &out, toMove++; } - for(int i = 0; i < 4; i++) + for(size_t i = 0; i < 4; ++i) boost::sort(phase[i], CMP_stack(i, turn > 0 ? turn : 0)); - for(size_t i = 0; i < phase[0].size() && i < howMany; i++) + for(size_t i = 0; i < phase[0].size() && i < howMany; ++i) out.push_back(phase[0][i]); if(out.size() == howMany) diff --git a/lib/CBattleCallback.h b/lib/CBattleCallback.h index d339ae517..c74fcdcb6 100644 --- a/lib/CBattleCallback.h +++ b/lib/CBattleCallback.h @@ -221,7 +221,7 @@ public: //battle shared_ptr battleGetObstacleOnPos(BattleHex tile, bool onlyBlocking = true) const; //blocking obstacles makes tile inaccessible, others cause special effects (like Land Mines, Moat, Quicksands) const CStack * battleGetStackByPos(BattleHex pos, bool onlyAlive = true) const; //returns stack info by given pos - void battleGetStackQueue(std::vector &out, const int howMany, const int turn = 0, int lastMoved = -1) const; + void battleGetStackQueue(std::vector &out, const size_t howMany, const int turn = 0, int lastMoved = -1) const; void battleGetStackCountOutsideHexes(bool *ac) const; // returns hexes which when in front of a stack cause us to move the amount box back diff --git a/lib/CBonusTypeHandler.cpp b/lib/CBonusTypeHandler.cpp new file mode 100644 index 000000000..f347675f0 --- /dev/null +++ b/lib/CBonusTypeHandler.cpp @@ -0,0 +1,337 @@ +/* + * CBonusTypeHandler.cpp, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#include "StdInc.h" +#include "CBonusTypeHandler.h" + +#include "JsonNode.h" +#include "Filesystem/CResourceLoader.h" +#include "Filesystem/ISimpleResourceLoader.h" + + +#include "VCMI_Lib.h" +#include "CCreatureHandler.h" +#include "CSpellHandler.h" + +///Helpers + +static inline void jsonSetString(const JsonNode& source, const std::string& name, std::string& dest) +{ + const JsonNode& val = source[name]; + if(!val.isNull()) + { + dest = val.String(); + } +} + +static inline void jsonSetBool(const JsonNode& source, const std::string& name, bool& dest) +{ + const JsonNode& val = source[name]; + if(!val.isNull()) + { + dest = val.Bool(); + } +} + +///MacroString + +MacroString::MacroString(const std::string &format) +{ + static const std::string MACRO_START = "${"; + static const std::string MACRO_END = "}"; + static const size_t MACRO_START_L = 2; + static const size_t MACRO_END_L = 1; + + size_t end_pos = 0; + size_t start_pos = std::string::npos; + + tlog5 << "Parsing format " << format << std::endl; + + do + { + start_pos = format.find(MACRO_START, end_pos); + + if (!(start_pos == std::string::npos)) + { + //chunk before macro + items.push_back(Item(Item::STRING,format.substr(end_pos, start_pos-end_pos))); + + start_pos += MACRO_START_L; + end_pos = format.find(MACRO_END, start_pos); + + if (end_pos == std::string::npos) + { + tlog2 << "Format error in: " << format <