From 15a7f43e1119c6411de6ec91cf8ee516c790b1c4 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 26 Sep 2012 13:13:39 +0000 Subject: [PATCH] - fixed #1075, #1080, #1081 - fixed some warnings from cppcheck --- AI/BattleAI/BattleAI.cpp | 6 +- client/AdventureMapClasses.cpp | 4 +- client/AdventureMapClasses.h | 4 +- client/CConfigHandler.cpp | 2 +- client/CConfigHandler.h | 2 +- client/CCreatureWindow.cpp | 1 - client/CHeroWindow.cpp | 4 +- client/CPreGame.cpp | 6 +- client/CVideoHandler.cpp | 2 +- client/GUIClasses.cpp | 4 +- client/GUIClasses.h | 2 +- client/Graphics.cpp | 3 +- client/UIFramework/CIntObjectClasses.cpp | 10 +-- client/UIFramework/CIntObjectClasses.h | 2 +- lib/CCreatureHandler.cpp | 107 +++++++---------------- lib/CGameState.cpp | 2 +- lib/CGameState.h | 2 +- lib/CGeneralTextHandler.cpp | 6 +- lib/CModHandler.cpp | 2 +- lib/CObjectHandler.cpp | 5 +- lib/CSpellHandler.cpp | 8 +- lib/CTownHandler.cpp | 2 +- lib/CTownHandler.h | 15 ++-- lib/Filesystem/CBinaryReader.h | 60 +------------ lib/Filesystem/CResourceLoader.cpp | 6 +- lib/Filesystem/CResourceLoader.h | 6 +- lib/NetPacks.h | 2 +- lib/NetPacksLib.cpp | 2 +- lib/map.cpp | 32 ++++++- lib/map.h | 5 ++ server/CGameHandler.cpp | 18 ++-- 31 files changed, 134 insertions(+), 198 deletions(-) diff --git a/AI/BattleAI/BattleAI.cpp b/AI/BattleAI/BattleAI.cpp index 20c1b0b5e..0d3f54424 100644 --- a/AI/BattleAI/BattleAI.cpp +++ b/AI/BattleAI/BattleAI.cpp @@ -241,7 +241,7 @@ struct AttackPossibility }; template -const Val &getValOr(const std::map &Map, const Key &key, const Key &defaultValue) +const Val &getValOr(const std::map &Map, const Key &key, const Val &defaultValue) { auto i = Map.find(key); if(i != Map.end()) @@ -279,8 +279,8 @@ struct PotentialTargets GenerateAttackInfo = [&](bool shooting, BattleHex hex) -> AttackPossibility { auto bai = BattleAttackInfo(attacker, enemy, shooting); - bai.attackerBonuses = getValOr(state.bonusesOfStacks, bai.attacker, bai.attacker); - bai.defenderBonuses = getValOr(state.bonusesOfStacks, bai.defender, bai.defender); + bai.attackerBonuses = getValOr(state.bonusesOfStacks, bai.attacker, static_cast(bai.attacker)); + bai.defenderBonuses = getValOr(state.bonusesOfStacks, bai.defender, static_cast(bai.defender)); AttackPossibility ap = {enemy, hex, bai, 0, 0}; if(hex.isValid()) diff --git a/client/AdventureMapClasses.cpp b/client/AdventureMapClasses.cpp index 44d8857c2..bef07e45f 100644 --- a/client/AdventureMapClasses.cpp +++ b/client/AdventureMapClasses.cpp @@ -788,7 +788,7 @@ void CInfoBar::CVisibleInfo::loadGameStatus() } } -void CInfoBar::CVisibleInfo::loadComponent(const Component compToDisplay, std::string message) +void CInfoBar::CVisibleInfo::loadComponent(const Component & compToDisplay, std::string message) { assert(children.empty()); // visible info should be re-created to change type @@ -889,7 +889,7 @@ void CInfoBar::showDate() redraw(); } -void CInfoBar::showComponent(const Component comp, std::string message) +void CInfoBar::showComponent(const Component & comp, std::string message) { reset(COMPONENT); visibleInfo->loadComponent(comp, message); diff --git a/client/AdventureMapClasses.h b/client/AdventureMapClasses.h index 320c39fe0..9b42443e5 100644 --- a/client/AdventureMapClasses.h +++ b/client/AdventureMapClasses.h @@ -263,7 +263,7 @@ class CInfoBar : public CIntObject void loadDay(); void loadEnemyTurn(int player); void loadGameStatus(); - void loadComponent(const Component comp, std::string message); + void loadComponent(const Component &comp, std::string message); //can be called multiple times void updateEnemyTurn(double progress); @@ -295,7 +295,7 @@ public: void showDate(); /// show component for 3 seconds. Used to display picked up resources - void showComponent(const Component comp, std::string message); + void showComponent(const Component & comp, std::string message); /// print enemy turn progress void startEnemyTurn(ui8 color); diff --git a/client/CConfigHandler.cpp b/client/CConfigHandler.cpp index 84fa3847d..fe1be35d5 100644 --- a/client/CConfigHandler.cpp +++ b/client/CConfigHandler.cpp @@ -118,7 +118,7 @@ SettingsListener::~SettingsListener() parent.listeners.erase(this); } -void SettingsListener::nodeInvalidated(const std::vector changedPath) +void SettingsListener::nodeInvalidated(const std::vector &changedPath) { if (!callback) return; diff --git a/client/CConfigHandler.h b/client/CConfigHandler.h index fe511b51f..fb38abb22 100644 --- a/client/CConfigHandler.h +++ b/client/CConfigHandler.h @@ -68,7 +68,7 @@ class SettingsListener SettingsListener(SettingsStorage &_parent, const std::vector &_path); // Executes callback if changedpath begins with path - void nodeInvalidated(const std::vector changedPath); + void nodeInvalidated(const std::vector & changedPath); public: SettingsListener(const SettingsListener &sl); diff --git a/client/CCreatureWindow.cpp b/client/CCreatureWindow.cpp index 1db31830d..b9bf054d8 100644 --- a/client/CCreatureWindow.cpp +++ b/client/CCreatureWindow.cpp @@ -471,7 +471,6 @@ void CCreatureWindow::recreateSkillList(int Pos) 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; diff --git a/client/CHeroWindow.cpp b/client/CHeroWindow.cpp index 8339a75d9..9c1ecb6dd 100644 --- a/client/CHeroWindow.cpp +++ b/client/CHeroWindow.cpp @@ -372,8 +372,8 @@ void CHeroWindow::showAll(SDL_Surface * to) //secondary skills for(size_t v=0; vsecSkills.size()); ++v) { - printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], v%2 ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to); - printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], v%2 ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to); + printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], (v%2) ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to); + printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], (v%2) ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to); } //printing special ability diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 58b657b46..e5852c58e 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -151,7 +151,7 @@ void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader * const PlayerInfo &pinfo = mapHeader->players[i]; //neither computer nor human can play - no player - if (!(pinfo.canComputerPlay || pinfo.canComputerPlay)) + if (!(pinfo.canHumanPlay || pinfo.canComputerPlay)) continue; PlayerSettings &pset = sInfo.playerInfos[i]; @@ -1048,8 +1048,8 @@ void SelectionTab::parseMaps(const std::vector &files, int start, in { try { - CCompressedStream stream(std::move(CResourceHandler::get()->load(files[start])), true); - int read = stream.read(mapBuffer, 1500); + TInputStreamPtr stream(Mapa::getMapStream(files[start].getName())); + int read = stream->read(mapBuffer, 1500); if(read < 50 || !mapBuffer[4]) throw std::runtime_error("corrupted map file"); diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index 80d210ca9..1291f48fd 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -317,7 +317,7 @@ bool CSmackPlayer::open( std::string name ) void CSmackPlayer::show( int x, int y, SDL_Surface *dst, bool update) { - int w = data->width, h = data->height; + int w = data->width; int stripe = (-w*2) & (~3); //put frame to the buffer diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index d75aaa4d0..5d2d596dd 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -5093,8 +5093,8 @@ void CTransformerWindow::CItem::update() icon->setFrame(parent->army->getCreature(id)->idNumber + 2); } -CTransformerWindow::CItem::CItem(CTransformerWindow * _parent, int _size, int _id): - id(_id), size(_size), parent(_parent) +CTransformerWindow::CItem::CItem(CTransformerWindow * parent, int size, int id): + id(id), size(size), parent(parent) { OBJ_CONSTRUCTION_CAPTURING_ALL; addUsedEvents(LCLICK); diff --git a/client/GUIClasses.h b/client/GUIClasses.h index af7a8901c..ae4dad156 100644 --- a/client/GUIClasses.h +++ b/client/GUIClasses.h @@ -1062,7 +1062,7 @@ public: void move(); void clickLeft(tribool down, bool previousState); void update(); - CItem(CTransformerWindow * _parent, int _size, int _id); + CItem(CTransformerWindow * parent, int size, int id); }; const CArmedInstance *army;//object with army for transforming (hero or town) diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 9b4bcbacc..7b3eef836 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -228,8 +228,7 @@ void Graphics::loadHeroAnims() std::ostringstream nm; nm << "AH" << std::setw(2) << std::setfill('0') << i << "_.DEF"; loadHeroAnim(nm.str(), rotations, &Graphics::heroAnims); - std::string name = nm.str(); - } + } loadHeroAnim("AB01_.DEF", rotations, &Graphics::boatAnims); loadHeroAnim("AB02_.DEF", rotations, &Graphics::boatAnims); diff --git a/client/UIFramework/CIntObjectClasses.cpp b/client/UIFramework/CIntObjectClasses.cpp index ef700de7a..b206dac75 100644 --- a/client/UIFramework/CIntObjectClasses.cpp +++ b/client/UIFramework/CIntObjectClasses.cpp @@ -434,12 +434,12 @@ void CAdventureMapButton::setPlayerColor(int player) image->playerColored(player); } -void CAdventureMapButton::showAll(SDL_Surface * to) +void CAdventureMapButton::show(SDL_Surface * to) { - CIntObject::showAll(to); + CIntObject::show(to); if (borderEnabled && borderColor.unused == 0) - CSDL_Ext::drawBorder(to, pos.x - 1, pos.y - 1, pos.w + 2, pos.h + 2, int3(borderColor.r, borderColor.g, borderColor.b)); + CSDL_Ext::drawBorder(to, pos.x, pos.y, pos.w, pos.h, int3(borderColor.r, borderColor.g, borderColor.b)); } void CHighlightableButton::select(bool on) @@ -1761,14 +1761,14 @@ void CWindowObject::updateShadow() void CWindowObject::setShadow(bool on) { - vstd::clear_pointer(shadow); - //size of shadow static const int size = 8; if (on == bool(shadow)) return; + vstd::clear_pointer(shadow); + //object too small to cast shadow if (pos.h <= size || pos.w <= size) return; diff --git a/client/UIFramework/CIntObjectClasses.h b/client/UIFramework/CIntObjectClasses.h index 73362385f..73e62fc5f 100644 --- a/client/UIFramework/CIntObjectClasses.h +++ b/client/UIFramework/CIntObjectClasses.h @@ -148,7 +148,7 @@ public: void setIndex(size_t index, bool playerColoredButton=false); void setImage(CAnimation* anim, bool playerColoredButton=false, int animFlags=0); void setPlayerColor(int player); - void showAll(SDL_Surface * to); + void show(SDL_Surface * to); }; /// A button which can be selected/deselected diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index c21166831..8caef7458 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -250,86 +250,51 @@ void CCreatureHandler::loadCreatures() tlog5 << "\t\tReading config/cr_abils.json and ZCRTRAIT.TXT" << std::endl; ////////////reading ZCRTRAIT.TXT /////////////////// - auto textFile = CResourceHandler::get()->loadData(ResourceID("DATA/ZCRTRAIT.TXT")); - std::string buf((char*)textFile.first.get(), textFile.second); - int andame = buf.size(); - int i=0; //buf iterator - int hmcr=0; - for(; i hardcoded @@ -585,7 +546,7 @@ void CCreatureHandler::loadCreatures() commanderLevelPremy.push_back(ParseBonus (bonus.Vector())); } - i = 0; + int i = 0; BOOST_FOREACH (auto skill, config3["skillLevels"].Vector()) { skillLevels.push_back (std::vector()); diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 8fd224517..b4a2f439a 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -387,7 +387,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, TPlayerColor p { CGHeroInstance *ret = NULL; - if(player<0 || player>=GameConstants::PLAYER_LIMIT) + if(player>=GameConstants::PLAYER_LIMIT) { tlog1 << "Cannot pick hero for " << town->Name() << ". Wrong owner!\n"; return NULL; diff --git a/lib/CGameState.h b/lib/CGameState.h index a6f489ba5..7fa572caf 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -477,7 +477,7 @@ struct DLL_LINKAGE QuestInfo //universal interface for human and AI QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) : quest (Quest), obj (Obj), tile (Tile){}; - bool operator== (const QuestInfo qi) const + bool operator== (const QuestInfo & qi) const { return (quest == qi.quest && obj == qi.obj); } diff --git a/lib/CGeneralTextHandler.cpp b/lib/CGeneralTextHandler.cpp index 654c06ddd..0e8864dae 100644 --- a/lib/CGeneralTextHandler.cpp +++ b/lib/CGeneralTextHandler.cpp @@ -118,7 +118,11 @@ float CLegacyConfigParser::readNumber() bool CLegacyConfigParser::isNextEntryEmpty() { - return curr >= end || *curr == '\n' || *curr == '\r' || *curr == '\t'; + char * nextSymbol = curr; + while (nextSymbol < end && *nextSymbol == ' ') + nextSymbol++; //find next meaningfull symbol + + return nextSymbol >= end || *nextSymbol == '\n' || *nextSymbol == '\r' || *nextSymbol == '\t'; } bool CLegacyConfigParser::endLine() diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index cc234ae29..822533e03 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -168,7 +168,7 @@ CCreature * CModHandler::loadCreature (const JsonNode &node) auto bonus = ParseBonus (exp["bonus"]); bonus->duration = Bonus::PERMANENT; const JsonVector &values = exp["values"].Vector(); - int lowerLimit = 1, upperLimit = 255; + int lowerLimit = 1;//, upperLimit = 255; if (values[0].getType() == JsonNode::JsonType::DATA_BOOL) { BOOST_FOREACH (const JsonNode &val, values) diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index b957de4b4..508bfc0e7 100644 --- a/lib/CObjectHandler.cpp +++ b/lib/CObjectHandler.cpp @@ -1500,7 +1500,6 @@ int CGHeroInstance::movementPointsAfterEmbark(int MPsBefore, int basicCost, bool CGHeroInstance::ECanDig CGHeroInstance::diggingStatus() const { - std::string hlp; if(movement < maxMovePoints(true)) return LACK_OF_MOVEMENT; else if(cb->getTile(getPosition(false))->tertype == TerrainTile::water) @@ -2328,11 +2327,11 @@ void CGTownInstance::recreateBuildingsBonuses() addBonusIfBuilt(EBuilding::FOUNTAIN_OF_FORTUNE, Bonus::LUCK, +2); //fountain of fortune addBonusIfBuilt(EBuilding::GRAIL, Bonus::LUCK, +2, make_shared(PLAYER)); //guardian spirit } - else if(subID == ETownType::RAMPART) //tower + else if(subID == ETownType::TOWER) //tower { addBonusIfBuilt(EBuilding::GRAIL, Bonus::PRIMARY_SKILL, +15, PrimarySkill::KNOWLEDGE); //grail } - else if(subID == ETownType::TOWER) //Inferno + else if(subID == ETownType::INFERNO) //Inferno { addBonusIfBuilt(EBuilding::STORMCLOUDS, Bonus::PRIMARY_SKILL, +2, PrimarySkill::SPELL_POWER); //Brimstone Clouds } diff --git a/lib/CSpellHandler.cpp b/lib/CSpellHandler.cpp index 0e4d057a5..fe5d963ac 100644 --- a/lib/CSpellHandler.cpp +++ b/lib/CSpellHandler.cpp @@ -55,15 +55,15 @@ namespace SRSLPraserHelpers switch(direction) { case 0: //top left - return std::make_pair(y%2 ? x-1 : x, y-1); + return std::make_pair((y%2) ? x-1 : x, y-1); case 1: //top right - return std::make_pair(y%2 ? x : x+1, y-1); + return std::make_pair((y%2) ? x : x+1, y-1); case 2: //right return std::make_pair(x+1, y); case 3: //right bottom - return std::make_pair(y%2 ? x : x+1, y+1); + return std::make_pair((y%2) ? x : x+1, y+1); case 4: //left bottom - return std::make_pair(y%2 ? x-1 : x, y+1); + return std::make_pair((y%2) ? x-1 : x, y+1); case 5: //left return std::make_pair(x-1, y); default: diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 9c26d5967..49cb7d7a3 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -285,7 +285,7 @@ void CTownHandler::loadTown(CTown &town, const JsonNode & source) BOOST_FOREACH(const JsonNode &list, source["creatures"].Vector()) { - std::vector level; + std::vector level; BOOST_FOREACH(const JsonNode &node, list.Vector()) { level.push_back(node.Float()); diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index cc0300c9f..f5b0f09ca 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -3,7 +3,7 @@ #include "ConstTransitivePtr.h" #include "ResourceSet.h" #include "int3.h" -//#include "GameConstants.h" +#include "GameConstants.h" /* * CTownHandler.h, part of VCMI engine @@ -29,7 +29,8 @@ class DLL_LINKAGE CBuilding std::string description; public: - si32 tid, bid; //town ID and structure ID + TFaction tid; + si32 bid; //town ID and structure ID TResources resources; std::set requirements; /// set of required buildings, includes upgradeOf; @@ -88,11 +89,11 @@ class DLL_LINKAGE CTown std::vector names; //names of the town instances public: - ui32 typeID;//also works as factionID + TFaction typeID;//also works as factionID /// level -> list of creatures on this tier // TODO: replace with pointers to CCreature - std::vector > creatures; + std::vector > creatures; bmap > buildings; @@ -155,7 +156,7 @@ class CFaction { public: std::string name; //reference name, usually lower case - ui32 factionID; + TFaction factionID; ui32 nativeTerrain; @@ -194,8 +195,8 @@ class DLL_LINKAGE CTownHandler void loadLegacyData(JsonNode & dest); public: - std::map towns; - std::map factions; + std::map towns; + std::map factions; CTownHandler(); //c-tor, set pointer in VLC to this diff --git a/lib/Filesystem/CBinaryReader.h b/lib/Filesystem/CBinaryReader.h index ebef194eb..9d7853765 100644 --- a/lib/Filesystem/CBinaryReader.h +++ b/lib/Filesystem/CBinaryReader.h @@ -68,75 +68,19 @@ public: si64 read(ui8 * data, si64 size); /** - * Reads a unsigned 8 bit integer. Advances the read pointer by one byte. + * Reads integer of various size. Advances the read pointer. * - * @return a unsigned 8 bit integer. + * @return a read integer. * * @throws std::runtime_error if the end of the stream was reached unexpectedly */ ui8 readUInt8(); - - /** - * Reads a signed 8 bit integer. Advances the read pointer by one byte. - * - * @return a signed 8 bit integer. - * - * @throws std::runtime_error if the end of the stream was reached unexpectedly - */ si8 readInt8(); - - /** - * Reads a unsigned 16 bit integer. Advances the read pointer by two bytes. - * - * @return a unsigned 16 bit integer. - * - * @throws std::runtime_error if the end of the stream was reached unexpectedly - */ ui16 readUInt16(); - - /** - * Reads a signed 16 bit integer. Advances the read pointer by two bytes. - * - * @return a signed 16 bit integer. - * - * @throws std::runtime_error if the end of the stream was reached unexpectedly - */ si16 readInt16(); - - /** - * Reads a unsigned 32 bit integer. Advances the read pointer by four bytes. - * - * @return a unsigned 32 bit integer. - * - * @throws std::runtime_error if the end of the stream was reached unexpectedly - */ ui32 readUInt32(); - - /** - * Reads a signed 32 bit integer. Advances the read pointer by four bytes. - * - * @return a signed 32 bit integer. - * - * @throws std::runtime_error if the end of the stream was reached unexpectedly - */ si32 readInt32(); - - /** - * Reads a unsigned 64 bit integer. Advances the read pointer by eight bytes. - * - * @return a unsigned 64 bit integer. - * - * @throws std::runtime_error if the end of the stream was reached unexpectedly - */ ui64 readUInt64(); - - /** - * Reads a signed 64 bit integer. Advances the read pointer by eight bytes. - * - * @return a signed 64 bit integer. - * - * @throws std::runtime_error if the end of the stream was reached unexpectedly - */ si64 readInt64(); private: diff --git a/lib/Filesystem/CResourceLoader.cpp b/lib/Filesystem/CResourceLoader.cpp index 96f2acb42..937fb6ce7 100644 --- a/lib/Filesystem/CResourceLoader.cpp +++ b/lib/Filesystem/CResourceLoader.cpp @@ -336,7 +336,7 @@ void CResourceHandler::initialize() recurseInDir("ALL/MODS", 2); // look for mods. Depth 2 is required for now but won't cause issues if no mods present } -void CResourceHandler::loadDirectory(const std::string mountPoint, const JsonNode & config) +void CResourceHandler::loadDirectory(const std::string &mountPoint, const JsonNode & config) { std::string URI = config["path"].String(); bool writeable = config["writeable"].Bool(); @@ -354,7 +354,7 @@ void CResourceHandler::loadDirectory(const std::string mountPoint, const JsonNod } } -void CResourceHandler::loadArchive(const std::string mountPoint, const JsonNode & config, EResType::Type archiveType) +void CResourceHandler::loadArchive(const std::string &mountPoint, const JsonNode & config, EResType::Type archiveType) { std::string URI = config["path"].String(); std::string filename = initialLoader->getResourceName(ResourceID(URI, archiveType)); @@ -363,7 +363,7 @@ void CResourceHandler::loadArchive(const std::string mountPoint, const JsonNode shared_ptr(new CLodArchiveLoader(filename)), false); } -void CResourceHandler::loadFileSystem(const std::string fsConfigURI) +void CResourceHandler::loadFileSystem(const std::string &fsConfigURI) { auto fsConfigData = initialLoader->loadData(ResourceID(fsConfigURI, EResType::TEXT)); diff --git a/lib/Filesystem/CResourceLoader.h b/lib/Filesystem/CResourceLoader.h index fc159d7de..b0dd77eb0 100644 --- a/lib/Filesystem/CResourceLoader.h +++ b/lib/Filesystem/CResourceLoader.h @@ -376,9 +376,9 @@ public: /** * Will load all filesystem data from Json data at this path (config/filesystem.json) */ - static void loadFileSystem(const std::string fsConfigURI); - static void loadDirectory(const std::string mountPoint, const JsonNode & config); - static void loadArchive(const std::string mountPoint, const JsonNode & config, EResType::Type archiveType); + static void loadFileSystem(const std::string & fsConfigURI); + static void loadDirectory(const std::string & mountPoint, const JsonNode & config); + static void loadArchive(const std::string & mountPoint, const JsonNode & config, EResType::Type archiveType); /** * Experimental. Checks all subfolders of MODS directory for presence of ERA-style mods diff --git a/lib/NetPacks.h b/lib/NetPacks.h index df46618c2..179af578f 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -221,7 +221,7 @@ struct PackageApplied : public CPackForClient //94 struct SystemMessage : public CPackForClient //95 { - SystemMessage(const std::string Text) : text(Text){type = 95;}; + SystemMessage(const std::string & Text) : text(Text){type = 95;}; SystemMessage(){type = 95;}; void applyCl(CClient *cl); diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index b5da63a0b..da071ef2c 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -187,7 +187,7 @@ DLL_LINKAGE void SetAvailableHeroes::applyGs( CGameState *gs ) for (int i = 0; i < GameConstants::AVAILABLE_HEROES_PER_PLAYER; i++) { - CGHeroInstance *h = (hid[i]>=0 ? (CGHeroInstance*)gs->hpool.heroesPool[hid[i]] : NULL); + CGHeroInstance *h = (hid[i]>=0 ? gs->hpool.heroesPool[hid[i]].get() : nullptr); if(h && army[i]) h->setToArmy(army[i]); p->availableHeroes.push_back(h); diff --git a/lib/map.cpp b/lib/map.cpp index d69666533..4e7f68337 100644 --- a/lib/map.cpp +++ b/lib/map.cpp @@ -1,6 +1,7 @@ #include "StdInc.h" #include "map.h" +#include "Filesystem/CBinaryReader.h" #include "Filesystem/CResourceLoader.h" #include "Filesystem/CCompressedStream.h" #include "CObjectHandler.h" @@ -498,18 +499,41 @@ void Mapa::addBlockVisTiles(CGObjectInstance * obj) } } } + +TInputStreamPtr Mapa::getMapStream(std::string URI) +{ + TInputStreamPtr file = CResourceHandler::get()->load(ResourceID(URI, EResType::MAP)); + + CBinaryReader reader(*file.get()); + + ui32 header = reader.readUInt32(); + file->seek(0); //reset file + + switch (header) + { + case 0x00088B1F: // gzip header magic number, reversed for LE + return TInputStreamPtr(new CCompressedStream(std::move(file), true)); + case CMapHeader::WoG : + case CMapHeader::AB : + case CMapHeader::RoE : + case CMapHeader::SoD : + return file; + default : + return TInputStreamPtr(); + } +} + Mapa::Mapa(std::string filename) :grailPos(-1, -1, -1), grailRadious(0) { tlog0<<"Opening map file: "< decompressed(new CCompressedStream( - std::move(CResourceHandler::get()->load(ResourceID(filename, EResType::MAP))), true)); + TInputStreamPtr file = getMapStream(filename); //load file and decompress - size_t mapSize = decompressed->getSize(); + size_t mapSize = file->getSize(); std::unique_ptr data(new ui8 [mapSize] ); - decompressed->read(data.get(), mapSize); + file->read(data.get(), mapSize); tlog0<<"done."< TInputStreamPtr; + /// Struct which describes a single terrain tile struct DLL_LINKAGE TerrainTile { @@ -349,6 +352,8 @@ struct DLL_LINKAGE Mapa : public CMapHeader bool isInTheMap(const int3 &pos) const; bool isWaterTile(const int3 &pos) const; //out-of-pos safe + static TInputStreamPtr getMapStream(std::string URI); + template void serialize(Handler &h, const int formatVersion) { h & static_cast(*this); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index aacd5880c..2b280ead5 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -43,7 +43,7 @@ #ifndef _MSC_VER #include #endif -#include +#include #include extern bool end2; #ifdef min @@ -5297,18 +5297,18 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat ) if (attacker->hasBonusOfType(Bonus::DEATH_STARE)) // spell id 79 { // mechanics of Death Stare as in H3: - // each gorgon have 10% chance to kill (counted separately in H3) -> poisson distribution - // maximum amount that can be killed is (1 + gorgons / 5 ), rounded up + // each gorgon have 10% chance to kill (counted separately in H3) -> binomial distribution + // maximum amount that can be killed is ( gorgons_count / 10 ), rounded up - int staredCreatures = 0; - double mean = double(attacker->count * attacker->valOfBonuses(Bonus::DEATH_STARE, 0)) / 100; + double chanceToKill = double(attacker->count * attacker->valOfBonuses(Bonus::DEATH_STARE, 0)) / 100; + vstd::amin(chanceToKill, 1); //cap at 100% - boost::poisson_distribution<> p(mean); + boost::binomial_distribution<> distr(attacker->count, chanceToKill); boost::mt19937 rng(rand()); - boost::variate_generator > dice (rng, p); - staredCreatures += dice(); + boost::variate_generator > dice (rng, distr); + int staredCreatures = dice(); - int maxToKill = 1 + (attacker->count + 4) / 5; + int maxToKill = (attacker->count * chanceToKill + 99) / 100; vstd::amin(staredCreatures, maxToKill); staredCreatures += attacker->type->level * attacker->valOfBonuses(Bonus::DEATH_STARE, 1);