diff --git a/AI/BattleAI/BattleAI.cpp b/AI/BattleAI/BattleAI.cpp index a9bc08f31..bb0e529e8 100644 --- a/AI/BattleAI/BattleAI.cpp +++ b/AI/BattleAI/BattleAI.cpp @@ -67,7 +67,7 @@ auto sum(const Container & c, Pred p) -> decltype(p(*boost::begin(c))) CBattleAI::CBattleAI(void) - : side(-1), cb(NULL) + : side(-1) { print("created"); } diff --git a/AI/BattleAI/BattleAI.h b/AI/BattleAI/BattleAI.h index a2cbde293..939bf7e31 100644 --- a/AI/BattleAI/BattleAI.h +++ b/AI/BattleAI/BattleAI.h @@ -83,8 +83,9 @@ struct AttackPossibility }; template -const Val &getValOr(const std::map &Map, const Key &key, const Val2 &defaultValue) +const Val getValOr(const std::map &Map, const Key &key, const Val2 defaultValue) { + //returning references here won't work: defaultValue must be converted into Val, creating temporary auto i = Map.find(key); if(i != Map.end()) return i->second; diff --git a/AI/StupidAI/StupidAI.cpp b/AI/StupidAI/StupidAI.cpp index daaaea22d..322739975 100644 --- a/AI/StupidAI/StupidAI.cpp +++ b/AI/StupidAI/StupidAI.cpp @@ -8,7 +8,7 @@ shared_ptr cbc; CStupidAI::CStupidAI(void) - : side(-1), cb(NULL) + : side(-1) { print("created"); } diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 66c412892..617d02d84 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -411,7 +411,6 @@ bool compareDanger(const CGObjectInstance *lhs, const CGObjectInstance *rhs) VCAI::VCAI(void) { LOG_TRACE(logAi); - myCb = nullptr; makingTurn = nullptr; } diff --git a/client/CHeroWindow.cpp b/client/CHeroWindow.cpp index 564d17813..47727fbc7 100644 --- a/client/CHeroWindow.cpp +++ b/client/CHeroWindow.cpp @@ -166,6 +166,16 @@ CHeroWindow::CHeroWindow(const CGHeroInstance *hero): new CAnimImage("PSKIL42", 4, 0, 20, 230, false); new CAnimImage("PSKIL42", 5, 0, 242, 111, false); + // various texts + new CLabel( 52, 99, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[1]); + new CLabel(123, 99, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[2]); + new CLabel(193, 99, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[3]); + new CLabel(262, 99, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[4]); + + new CLabel( 69, 183, FONT_SMALL, TOPLEFT, Colors::YELLOW, CGI->generaltexth->jktexts[5]); + new CLabel( 69, 232, FONT_SMALL, TOPLEFT, Colors::YELLOW, CGI->generaltexth->jktexts[6]); + new CLabel(213, 232, FONT_SMALL, TOPLEFT, Colors::YELLOW, CGI->generaltexth->jktexts[7]); + update(hero); } @@ -272,7 +282,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded /*= fals //setting formations formations->onChange = 0; formations->select(curHero->formation,true); - formations->onChange = boost::bind(&CCallback::setFormation, LOCPLINT->cb, curHero, _1); + formations->onChange = boost::bind(&CCallback::setFormation, LOCPLINT->cb.get(), curHero, _1); morale->set(&heroWArt); luck->set(&heroWArt); @@ -284,7 +294,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded /*= fals void CHeroWindow::dismissCurrent() { CFunctionList ony = boost::bind(&CHeroWindow::close,this); - ony += boost::bind(&CCallback::dismissHero,LOCPLINT->cb,curHero); + ony += boost::bind(&CCallback::dismissHero, LOCPLINT->cb.get(), curHero); LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[22], ony, 0, false); } @@ -335,12 +345,6 @@ void CHeroWindow::showAll(SDL_Surface * to) boost::algorithm::replace_first(secondLine,"%d",boost::lexical_cast(curHero->level)); boost::algorithm::replace_first(secondLine,"%s",curHero->type->heroClass->name); printAtMiddleLoc(secondLine, 190, 65, FONT_MEDIUM, Colors::WHITE, to); - - //primary skills names - printAtMiddleLoc(CGI->generaltexth->jktexts[1], 52, 99, FONT_SMALL, Colors::YELLOW, to); - printAtMiddleLoc(CGI->generaltexth->jktexts[2], 123, 99, FONT_SMALL, Colors::YELLOW, to); - printAtMiddleLoc(CGI->generaltexth->jktexts[3], 193, 99, FONT_SMALL, Colors::YELLOW, to); - printAtMiddleLoc(CGI->generaltexth->jktexts[4], 262, 99, FONT_SMALL, Colors::YELLOW, to); //printing primary skills' amounts for(int m=0; m<4; ++m) @@ -358,15 +362,11 @@ void CHeroWindow::showAll(SDL_Surface * to) } //printing special ability - printAtLoc(CGI->generaltexth->jktexts[5].substr(1, CGI->generaltexth->jktexts[5].size()-2), 69, 183, FONT_SMALL, Colors::YELLOW, to); printAtLoc(curHero->type->specName, 69, 205, FONT_SMALL, Colors::WHITE, to); - - //printing necessery texts - printAtLoc(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 232, FONT_SMALL, Colors::YELLOW, to); std::ostringstream expstr; expstr << curHero->exp; printAtLoc(expstr.str(), 68, 252, FONT_SMALL, Colors::WHITE, to); - printAtLoc(CGI->generaltexth->jktexts[7].substr(1, CGI->generaltexth->jktexts[7].size()-2), 213, 232, FONT_SMALL, Colors::YELLOW, to); + std::ostringstream manastr; manastr << curHero->mana << '/' << heroWArt.manaLimit(); printAtLoc(manastr.str(), 211, 252, FONT_SMALL, Colors::WHITE, to); diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 28f8cc1c3..5e9167422 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -767,7 +767,7 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i } cb->unregisterBattleInterface(autofightingAI); - autofightingAI = nullptr; + autofightingAI.reset(); } CBattleInterface *b = battleInt; @@ -804,7 +804,7 @@ void CPlayerInterface::battleEnd(const BattleResult *br) { isAutoFightOn = false; cb->unregisterBattleInterface(autofightingAI); - autofightingAI = nullptr; + autofightingAI.reset(); if(!battleInt) { diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 1360cf928..33f4a3169 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -920,7 +920,7 @@ void CSelectionScreen::startScenario() saveGameName = "Saves/" + sel->txt->text; CFunctionList overWrite; - overWrite += boost::bind(&CCallback::save, LOCPLINT->cb, saveGameName); + overWrite += boost::bind(&CCallback::save, LOCPLINT->cb.get(), saveGameName); overWrite += bind(&CGuiHandler::popIntTotally, &GH, this); if(CResourceHandler::get()->existsResource(ResourceID(saveGameName, EResType::CLIENT_SAVEGAME))) diff --git a/client/Client.cpp b/client/Client.cpp index 31b4e5cce..851eb5851 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -464,7 +464,7 @@ void CClient::serialize( Handler &h, const int version ) h & pid & dllname & isHuman; LOG_TRACE_PARAMS(logGlobal, "Loading player %s interface", pid); - shared_ptr nInt = nullptr; + shared_ptr nInt; if(dllname.length()) { if(pid == PlayerColor::NEUTRAL) @@ -579,7 +579,7 @@ void CClient::battleStarted(const BattleInfo * info) // if(battleCallbacks.count(side)) // battleCallbacks[side]->setBattle(info); - shared_ptr att = nullptr, def = nullptr; + shared_ptr att, def; //If quick combat is not, do not prepare interfaces for battleint if(!settings["adventure"]["quickCombat"].Bool()) diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 415d856de..5600d9014 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -165,8 +165,7 @@ void CTownTooltip::init(const InfoAboutTown &town) if(town.details) { - if (town.details->hallLevel) - new CAnimImage("ITMTLS", town.details->hallLevel, 0, 67, 31); + new CAnimImage("ITMTLS", town.details->hallLevel, 0, 67, 31); if (town.details->goldIncome) new CLabel(157, 58, FONT_TINY, CENTER, Colors::WHITE, @@ -322,8 +321,8 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState) bool canDismiss = getObj()->tempOwner == LOCPLINT->playerID && (getObj()->stacksCount()>1 || !getObj()->needsLastStack()); boost::function upgr = NULL; boost::function dism = NULL; - if (canUpgrade) upgr = boost::bind(&CCallback::upgradeCreature, LOCPLINT->cb, getObj(), ID, pom.newID[0]); - if (canDismiss) dism = boost::bind(&CCallback::dismissCreature, LOCPLINT->cb, getObj(), ID); + if (canUpgrade) upgr = boost::bind(&CCallback::upgradeCreature, LOCPLINT->cb.get(), getObj(), ID, pom.newID[0]); + if (canDismiss) dism = boost::bind(&CCallback::dismissCreature, LOCPLINT->cb.get(), getObj(), ID); owner->selectSlot(nullptr); owner->setSplittingMode(false); @@ -1280,7 +1279,7 @@ CSelWindow::CSelWindow(const std::string &Text, PlayerColor player, int charperl buttons.back()->assignedKeys.insert(SDLK_ESCAPE); //last button - reacts on escape if(buttons.size() > 1 && askID.getNum() >= 0) //cancel button functionality - buttons.back()->callback += boost::bind(&CCallback::selectionMade,LOCPLINT->cb,0,askID); + buttons.back()->callback += boost::bind(&CCallback::selectionMade,LOCPLINT->cb.get(),0,askID); for(int i=0;iartType->id, combination->id, true, - boost::bind(&CCallback::assembleArtifacts, LOCPLINT->cb, ourOwner->curHero, slotID, true, combination->id), + boost::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), ourOwner->curHero, slotID, true, combination->id), 0); if(assemblyPossibilities.size() > 2) @@ -4278,7 +4277,7 @@ void CArtPlace::clickRight(tribool down, bool previousState) ourArt->artType->id, 0, false, - boost::bind(&CCallback::assembleArtifacts, LOCPLINT->cb, ourOwner->curHero, slotID, false, ArtifactID()), + boost::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), ourOwner->curHero, slotID, false, ArtifactID()), 0); return; } diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index fb942bd0f..a9faa981a 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -59,8 +59,10 @@ cl->battleints[player]->function(__VA_ARGS__); \ \ if(cl->additionalBattleInts.count(player)) \ + { \ BOOST_FOREACH(auto bInt, cl->additionalBattleInts[player])\ bInt->function(__VA_ARGS__); \ + } \ } while (0); #define BATTLE_INTERFACE_CALL_RECEIVERS(function,...) \ diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index df372abc4..b5d969456 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -92,12 +92,11 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect, shared_ptr att, shared_ptr defen) - : queue(NULL), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), + : background(nullptr), queue(NULL), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(NULL), stackToActivate(NULL), selectedStack(NULL), mouseHoveredStack(-1), lastMouseHoveredStackAnimationTime(-1), previouslyHoveredHex(-1), - currentlyHoveredHex(-1), attackingHex(-1), tacticianInterface(NULL), stackCanCastSpell(false), creatureCasting(false), spellDestSelectMode(false), spellSelMode(NO_LOCATION), spellToCast(NULL), sp(NULL), + currentlyHoveredHex(-1), attackingHex(-1), stackCanCastSpell(false), creatureCasting(false), spellDestSelectMode(false), spellSelMode(NO_LOCATION), spellToCast(NULL), sp(NULL), siegeH(NULL), attackerInt(att), defenderInt(defen), curInt(att), animIDhelper(0), - givenCommand(NULL), myTurn(false), resWindow(NULL), moveStarted(false), moveSh(-1), bresult(NULL), - background(nullptr) + givenCommand(NULL), myTurn(false), resWindow(NULL), moveStarted(false), moveSh(-1), bresult(NULL) { OBJ_CONSTRUCTION; diff --git a/client/battle/CBattleInterface.h b/client/battle/CBattleInterface.h index 216937740..acb3b67dd 100644 --- a/client/battle/CBattleInterface.h +++ b/client/battle/CBattleInterface.h @@ -227,6 +227,8 @@ public: bool moveStarted; //if true, the creature that is already moving is going to make its first step int moveSh; // sound handler used when moving a unit + const BattleResult * bresult; //result of a battle; if non-zero then display when all animations end + //button handle funcs: void bOptionsf(); void bSurrenderf(); @@ -265,7 +267,6 @@ public: void hexLclicked(int whichOne); //hex only call-in void stackIsCatapulting(const CatapultAttack & ca); //called when a stack is attacking walls void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed - const BattleResult * bresult; //result of a battle; if non-zero then display when all animations end void displayBattleFinished(); //displays battle result void spellCast(const BattleSpellCast * sc); //called when a hero casts a spell void battleStacksEffectsSet(const SetStackEffect & sse); //called when a specific effect is set to stacks diff --git a/client/battle/CBattleInterfaceClasses.cpp b/client/battle/CBattleInterfaceClasses.cpp index bfee56934..e11191033 100644 --- a/client/battle/CBattleInterfaceClasses.cpp +++ b/client/battle/CBattleInterfaceClasses.cpp @@ -345,8 +345,6 @@ CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect } else { - int bestMonsterID = -1; - ui32 bestPower = 0; auto stacks = owner.cb->battleGetAllStacks(); vstd::erase_if(stacks, [i](const CStack *stack) //erase stack of other side and not coming from garrison { return stack->attackerOwned == i || !stack->base; }); diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index 0ac937e98..baddbfe2d 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -285,7 +285,24 @@ std::vector CCreatureHandler::loadLegacyData(size_t dataSize) CLegacyConfigParser parser("DATA/CRTRAITS.TXT"); parser.endLine(); // header - parser.endLine(); + + // this file is a bit different in some of Russian localisations: + //ENG: Singular Plural Wood ... + //RUS: Singular Plural Plural2 Wood ... + // Try to detect which version this is by header + // TODO: use 3rd name? Stand for "whose", e.g. pikemans' + size_t namesCount; + { + if ( parser.readString() != "Singular" || parser.readString() != "Plural" ) + throw std::runtime_error("Incorrect format of CrTraits.txt"); + + if (parser.readString() == "Plural2") + namesCount = 3; + else + namesCount = 2; + + parser.endLine(); + } for (size_t i=0; i CCreatureHandler::loadLegacyData(size_t dataSize) JsonNode data; data["name"]["singular"].String() = parser.readString(); + + if (namesCount == 3) + parser.readString(); + data["name"]["plural"].String() = parser.readString(); for(int v=0; v<7; ++v) diff --git a/lib/CGameInterface.cpp b/lib/CGameInterface.cpp index 9e2b441c2..a01c67128 100644 --- a/lib/CGameInterface.cpp +++ b/lib/CGameInterface.cpp @@ -195,7 +195,7 @@ void CAdventureAI::battleSpellCast(const BattleSpellCast *sc) void CAdventureAI::battleEnd(const BattleResult *br) { battleAI->battleEnd(br); - battleAI = nullptr; + battleAI.reset(); } void CAdventureAI::battleStacksHealedRes(const std::vector > & healedStacks, bool lifeDrain, bool tentHeal, si32 lifeDrainFrom) diff --git a/lib/CGameInterface.h b/lib/CGameInterface.h index 2d7d233ab..6b218b9e4 100644 --- a/lib/CGameInterface.h +++ b/lib/CGameInterface.h @@ -112,7 +112,7 @@ public: class DLL_LINKAGE CAdventureAI : public CGlobalAI { public: - CAdventureAI() : battleAI(NULL), cbc(NULL) {}; + CAdventureAI() {}; shared_ptr battleAI; shared_ptr cbc; diff --git a/lib/CGeneralTextHandler.cpp b/lib/CGeneralTextHandler.cpp index 50470b2fa..73095ce54 100644 --- a/lib/CGeneralTextHandler.cpp +++ b/lib/CGeneralTextHandler.cpp @@ -103,7 +103,7 @@ std::string CLegacyConfigParser::readString() else ret = extractNormalString();//string without quotes - copy till \t or \r - curr++; + curr++; return ret; } @@ -122,7 +122,7 @@ float CLegacyConfigParser::readNumber() return result; } -bool CLegacyConfigParser::isNextEntryEmpty() +bool CLegacyConfigParser::isNextEntryEmpty() const { char * nextSymbol = curr; while (nextSymbol < end && *nextSymbol == ' ') @@ -136,7 +136,7 @@ bool CLegacyConfigParser::endLine() while (curr < end && *curr != '\n') readString(); - curr++; + curr++; return curr < end; } diff --git a/lib/CGeneralTextHandler.h b/lib/CGeneralTextHandler.h index d4c4bc377..8a1952f23 100644 --- a/lib/CGeneralTextHandler.h +++ b/lib/CGeneralTextHandler.h @@ -46,7 +46,7 @@ public: } /// returns true if next entry is empty - bool isNextEntryEmpty(); + bool isNextEntryEmpty() const; /// end current line bool endLine(); diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 4c0195432..d209e0126 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -470,7 +470,7 @@ void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNod { auto object = loadFromJson(data); object->ID = HeroTypeID(heroes.size()); - object->imageIndex = heroes.size() + 8; // 2 special frames + some extra portraits + object->imageIndex = heroes.size() + 10; // 2 special frames + some extra portraits heroes.push_back(object);