From fbe9ada52957958382141729451d1c001f9586bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Mon, 11 Nov 2013 14:28:16 +0100 Subject: [PATCH 2/2] Replace bmap with C++11's std::map, improve project const-ness The C++11's std::map has const T & at( const Key& key ) const; element access method, making bmap redundant. Removed bmap, as it only introduced const operator[] at expense of expanding one more, already available, template - this could also slight improve build times. In few places also improved constness, especially where containers were involved. Tested with clang 3.3, gcc 4.8.2 --- AI/VCAI/VCAI.cpp | 4 +- Global.h | 56 +--------- client/CCastleInterface.cpp | 30 +++--- client/NetPacksClient.cpp | 14 +-- lib/CArtHandler.cpp | 4 +- lib/CArtHandler.h | 4 +- lib/CDefObjInfoHandler.h | 6 +- lib/CGameState.cpp | 14 +-- lib/CGameState.h | 12 +-- lib/CObjectHandler.cpp | 10 +- lib/CTownHandler.h | 4 +- lib/GameConstants.cpp | 2 +- lib/GameConstants.h | 2 +- lib/HeroBonus.cpp | 4 +- lib/HeroBonus.h | 4 +- lib/IGameCallback.cpp | 6 +- lib/StartInfo.h | 2 +- lib/mapping/CCampaignHandler.cpp | 2 +- lib/mapping/CCampaignHandler.h | 2 +- lib/mapping/CMap.h | 2 +- server/CGameHandler.cpp | 223 ++++++++++++++++++++------------------- 21 files changed, 177 insertions(+), 230 deletions(-) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 1a27ad5..caf2fa9 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -962,7 +962,7 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsi for(const auto & buildID : toBuild) { - const CBuilding *b = t->town->buildings[buildID]; + const CBuilding *b = t->town->buildings.at(buildID); EBuildingState::EBuildingState canBuild = cb->canBuildStructure(t, buildID); if(canBuild == EBuildingState::ALLOWED) @@ -977,7 +977,7 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsi } else if(canBuild == EBuildingState::NO_RESOURCES) { - TResources cost = t->town->buildings[buildID]->resources; + TResources cost = t->town->buildings.at(buildID)->resources; for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; i++) { int diff = currentRes[i] - cost[i] + income[i]; diff --git a/Global.h b/Global.h index 7addc61..b3a3861 100644 --- a/Global.h +++ b/Global.h @@ -225,53 +225,6 @@ template char (&_ArrayCountObj(const T (&)[N]))[N]; /* ---------------------------------------------------------------------------- */ /* VCMI standard library */ /* ---------------------------------------------------------------------------- */ -//a normal std::map with a const operator[] for sanity -template -class bmap : public std::map -{ -public: - const ValT & operator[](KeyT key) const - { - return this->find(key)->second; - } - ValT & operator[](KeyT key) - { - return static_cast &>(*this)[key]; - } - template void serialize(Handler &h, const int version) - { - h & static_cast &>(*this); - } - - bmap() - {} - explicit bmap(const typename std::map::key_compare& _Pred) - : std::map(_Pred) - {} - - bmap(const typename std::map::key_compare& _Pred, const typename std::map::allocator_type& _Al) - : std::map(_Pred, _Al) - {} - - template - bmap(_Iter _First, _Iter _Last) - : std::map(_First, _Last) - {} - - template - bmap(_Iter _First, _Iter _Last, - const typename std::map::key_compare& _Pred) - : std::map(_First, _Last, _Pred) - {} - - template - bmap(_Iter _First, _Iter _Last, - const typename std::map::key_compare& _Pred, const typename std::map::allocator_type& _Al) - : std::map(_First, _Last, _Pred, _Al) - {} - -}; - template std::ostream &operator<<(std::ostream &out, const boost::optional &opt) { @@ -314,13 +267,6 @@ namespace vstd return c.find(i)!=c.end(); } - //returns true if bmap c contains item i - template - bool contains(const bmap & c, const Item2 &i) - { - return c.find(i)!=c.end(); - } - //returns true if unordered set c contains item i template bool contains(const std::unordered_set & c, const Item &i) @@ -520,7 +466,7 @@ namespace vstd } } - //works for map and bmap, maybe something else + //works for map and std::map, maybe something else template void erase_if(std::map &container, Predicate pred) { diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index 8e17903..af61125 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -43,7 +43,7 @@ const CBuilding * CBuildingRect::getBuilding() return nullptr; if (str->hiddenUpgrade) // hidden upgrades, e.g. hordes - return base (dwelling for hordes) - return town->town->buildings[str->building->getBase()]; + return town->town->buildings.at(str->building->getBase()); return str->building; } @@ -117,7 +117,7 @@ void CBuildingRect::clickRight(tribool down, bool previousState) if( !CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image { BuildingID bid = getBuilding()->bid; - const CBuilding *bld = town->town->buildings[bid]; + const CBuilding *bld = town->town->buildings.at(bid); if (bid < BuildingID::DWELL_FIRST) { CRClickPopup::createAndPush(CInfoWindow::genText(bld->Name(), bld->Description()), @@ -212,14 +212,14 @@ std::string CBuildingRect::getSubtitle()//hover text for building int bid = getBuilding()->bid; if (bid<30)//non-dwellings - only buiding name - return town->town->buildings[getBuilding()->bid]->Name(); + return town->town->buildings.at(getBuilding()->bid)->Name(); else//dwellings - recruit %creature% { auto & availableCreatures = town->creatures[(bid-30)%GameConstants::CREATURES_PER_TOWN].second; if(availableCreatures.size()) { int creaID = availableCreatures.back();//taking last of available creatures - return CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creaID]->namePl; + return CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures.at(creaID)->namePl; } else { @@ -258,12 +258,12 @@ CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstanc { OBJ_CONSTRUCTION_CAPTURING_ALL; - const CCreature * creature = CGI->creh->creatures[Town->creatures[level].second.back()]; + const CCreature * creature = CGI->creh->creatures.at(Town->creatures.at(level).second.back()); title = new CLabel(80, 30, FONT_SMALL, CENTER, Colors::WHITE, creature->namePl); animation = new CCreaturePic(30, 44, creature, true, true); - std::string text = boost::lexical_cast(Town->creatures[level].first); + std::string text = boost::lexical_cast(Town->creatures.at(level).first); available = new CLabel(80,190, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[217] + text); costPerTroop = new CLabel(80, 227, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[346]); @@ -506,7 +506,7 @@ void CCastleBuildings::recreate() for(auto & entry : groups) { - const CBuilding * build = town->town->buildings[entry.first]; + const CBuilding * build = town->town->buildings.at(entry.first); const CStructure * toAdd = *boost::max_element(entry.second, [=](const CStructure * a, const CStructure * b) { @@ -529,11 +529,11 @@ CCastleBuildings::~CCastleBuildings() void CCastleBuildings::addBuilding(BuildingID building) { //FIXME: implement faster method without complete recreation of town - BuildingID base = town->town->buildings[building]->getBase(); + BuildingID base = town->town->buildings.at(building)->getBase(); recreate(); - auto & structures = groups[base]; + auto & structures = groups.at(base); for(CBuildingRect * rect : buildings) { @@ -1114,7 +1114,7 @@ CTownInfo::CTownInfo(int posX, int posY, const CGTownInstance* Town, bool townHa return; picture = new CAnimImage("ITMCL.DEF", town->fortLevel()-1); } - building = town->town->buildings[BuildingID(buildID)]; + building = town->town->buildings.at(BuildingID(buildID)); pos = picture->pos; } @@ -1298,7 +1298,7 @@ CHallInterface::CHallInterface(const CGTownInstance *Town): Rect barRect(5, 556, 740, 18); statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false)); - title = new CLabel(399, 12, FONT_MEDIUM, CENTER, Colors::WHITE, town->town->buildings[BuildingID(town->hallLevel()+BuildingID::VILLAGE_HALL)]->Name()); + title = new CLabel(399, 12, FONT_MEDIUM, CENTER, Colors::WHITE, town->town->buildings.at(BuildingID(town->hallLevel()+BuildingID::VILLAGE_HALL))->Name()); exit = new CAdventureMapButton(CGI->generaltexth->hcommands[8], "", boost::bind(&CHallInterface::close,this), 748, 556, "TPMAGE1.DEF", SDLK_RETURN); exit->assignedKeys.insert(SDLK_ESCAPE); @@ -1313,7 +1313,7 @@ CHallInterface::CHallInterface(const CGTownInstance *Town): for(auto & elem : boxList[row][col])//we are looking for the first not build structure { auto buildingID = elem; - building = town->town->buildings[buildingID]; + building = town->town->buildings.at(buildingID); if(!vstd::contains(town->builtBuildings,buildingID)) break; @@ -1354,7 +1354,7 @@ std::string CBuildWindow::getTextForState(int state) { if (vstd::contains(town->builtBuildings, i)) continue;//skipping constructed buildings - ret+= town->town->buildings[i]->Name() + ", "; + ret+= town->town->buildings.at(i)->Name() + ", "; } ret.erase(ret.size()-2); } @@ -1426,7 +1426,7 @@ CFortScreen::CFortScreen(const CGTownInstance * town): if (fortSize > GameConstants::CREATURES_PER_TOWN && town->creatures.back().second.empty()) fortSize--; - const CBuilding *fortBuilding = town->town->buildings[BuildingID(town->fortLevel()+6)]; + const CBuilding *fortBuilding = town->town->buildings.at(BuildingID(town->fortLevel()+6)); title = new CLabel(400, 12, FONT_BIG, CENTER, Colors::WHITE, fortBuilding->Name()); std::string text = boost::str(boost::format(CGI->generaltexth->fcommands[6]) % fortBuilding->Name()); @@ -1558,7 +1558,7 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance * values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[194], CGI->generaltexth->fcommands[5], town->creatureGrowth(level))); creatureName = new CLabel(78, 11, FONT_SMALL, CENTER, Colors::WHITE, creature->namePl); - dwellingName = new CLabel(78, 101, FONT_SMALL, CENTER, Colors::WHITE, town->town->buildings[buildingID]->Name()); + dwellingName = new CLabel(78, 101, FONT_SMALL, CENTER, Colors::WHITE, town->town->buildings.at(buildingID)->Name()); if (vstd::contains(town->builtBuildings, buildingID)) { diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index d89f70a..1278a0b 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -412,11 +412,11 @@ void NewStructures::applyCl( CClient *cl ) { if(id == BuildingID::CAPITOL) //fort or capitol { - town->defInfo = const_cast(CGI->dobjinfo->capitols[town->subID].get()); + town->defInfo = const_cast(CGI->dobjinfo->capitols.at(town->subID).get()); } if(id == BuildingID::FORT) { - town->defInfo = const_cast(CGI->dobjinfo->gobjs[Obj::TOWN][town->subID].get()); + town->defInfo = const_cast(CGI->dobjinfo->gobjs.at(Obj::TOWN).at(town->subID).get()); } if(vstd::contains(cl->playerint,town->tempOwner)) cl->playerint[town->tempOwner]->buildChanged(town,id,1); @@ -429,7 +429,7 @@ void RazeStructures::applyCl (CClient *cl) { if (id == BuildingID::CAPITOL) //fort or capitol { - town->defInfo = const_cast(CGI->dobjinfo->gobjs[Obj::TOWN][town->subID].get()); + town->defInfo = const_cast(CGI->dobjinfo->gobjs.at(Obj::TOWN).at(town->subID).get()); } if(vstd::contains (cl->playerint,town->tempOwner)) cl->playerint[town->tempOwner]->buildChanged (town,id,2); @@ -535,7 +535,7 @@ void InfoWindow::applyCl( CClient *cl ) text.toString(str); if(vstd::contains(cl->playerint,player)) - cl->playerint[player]->showInfoDialog(str,comps,(soundBase::soundID)soundID); + cl->playerint.at(player)->showInfoDialog(str,comps,(soundBase::soundID)soundID); else logNetwork->warnStream() << "We received InfoWindow for not our player..."; } @@ -578,7 +578,7 @@ void BlockingDialog::applyCl( CClient *cl ) text.toString(str); if(vstd::contains(cl->playerint,player)) - cl->playerint[player]->showBlockingDialog(str,components,queryID,(soundBase::soundID)soundID,selection(),cancel()); + cl->playerint.at(player)->showBlockingDialog(str,components,queryID,(soundBase::soundID)soundID,selection(),cancel()); else logNetwork->warnStream() << "We received YesNoDialog for not our player..."; } @@ -591,7 +591,7 @@ void GarrisonDialog::applyCl(CClient *cl) if(!vstd::contains(cl->playerint,h->getOwner())) return; - cl->playerint[h->getOwner()]->showGarrisonDialog(obj,h,removableUnits,queryID); + cl->playerint.at(h->getOwner())->showGarrisonDialog(obj,h,removableUnits,queryID); } void ExchangeDialog::applyCl(CClient *cl) @@ -948,7 +948,7 @@ void SetAvailableArtifacts::applyCl(CClient *cl) void TradeComponents::applyCl(CClient *cl) {///Shop handler - switch (CGI->mh->map->objects[objectid]->ID) + switch (CGI->mh->map->objects.at(objectid)->ID) { case Obj::BLACK_MARKET: break; diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index c6c59d3..9c24207 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -689,7 +689,7 @@ void CArtifactInstance::init() ArtifactPosition CArtifactInstance::firstAvailableSlot(const CArtifactSet *h) const { - for(auto slot : artType->possibleSlots[h->bearerType()]) + for(auto slot : artType->possibleSlots.at(h->bearerType())) { if(canBePutAt(h, slot)) //if(artType->fitsAt(h->artifWorn, slot)) { @@ -1095,7 +1095,7 @@ bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn /*= false*/) const const ArtSlotInfo * CArtifactSet::getSlot(ArtifactPosition pos) const { if(vstd::contains(artifactsWorn, pos)) - return &artifactsWorn[pos]; + return &artifactsWorn.at(pos); if(pos >= ArtifactPosition::AFTER_LAST ) { int backpackPos = (int)pos - GameConstants::BACKPACK_START; diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index 94429f4..dffa718 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -66,7 +66,7 @@ public: virtual void levelUpArtifact (CArtifactInstance * art){}; ui32 price; - bmap > possibleSlots; //Bearer Type => ids of slots where artifact can be placed + std::map > possibleSlots; //Bearer Type => ids of slots where artifact can be placed std::unique_ptr > constituents; // Artifacts IDs a combined artifact consists of, or nullptr. std::vector constituentOf; // Reverse map of constituents - combined arts that include this art EartClass aClass; @@ -266,7 +266,7 @@ class DLL_LINKAGE CArtifactSet { public: std::vector artifactsInBackpack; //hero's artifacts from bag - bmap artifactsWorn; //map; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 + std::map artifactsWorn; //map; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 ArtSlotInfo &retreiveNewArtSlot(ArtifactPosition slot); void setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked); diff --git a/lib/CDefObjInfoHandler.h b/lib/CDefObjInfoHandler.h index 8374d74..0085483 100644 --- a/lib/CDefObjInfoHandler.h +++ b/lib/CDefObjInfoHandler.h @@ -49,10 +49,10 @@ void fetchInfoFromMSK(); class DLL_LINKAGE CDefObjInfoHandler { public: - bmap > > gobjs; + std::map > > gobjs; - bmap > capitols; - bmap > villages; + std::map > capitols; + std::map > villages; CDefObjInfoHandler(); ~CDefObjInfoHandler(); diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 8307b12..a70ce1c 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -375,7 +375,7 @@ static CGObjectInstance * createObject(Obj id, int subid, int3 pos, PlayerColor return nobj; } -CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, PlayerColor player, const CTown *town, bmap > &available, const CHeroClass *bannedClass /*= nullptr*/) const +CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, PlayerColor player, const CTown *town, std::map > &available, const CHeroClass *bannedClass /*= nullptr*/) const { CGHeroInstance *ret = nullptr; @@ -1352,13 +1352,13 @@ void CGameState::init(StartInfo * si) if (vstd::contains(vti->builtBuildings,(-31-i))) //if we have horde for this level { vti->builtBuildings.erase(BuildingID(-31-i));//remove old ID - if (vti->town->hordeLvl[0] == i)//if town first horde is this one + if (vti->town->hordeLvl.at(0) == i)//if town first horde is this one { vti->builtBuildings.insert(BuildingID::HORDE_1);//add it if (vstd::contains(vti->builtBuildings,(BuildingID::DWELL_UP_FIRST+i)))//if we have upgraded dwelling as well vti->builtBuildings.insert(BuildingID::HORDE_1_UPGR);//add it as well } - if (vti->town->hordeLvl[1] == i)//if town second horde is this one + if (vti->town->hordeLvl.at(1) == i)//if town second horde is this one { vti->builtBuildings.insert(BuildingID::HORDE_2); if (vstd::contains(vti->builtBuildings,(BuildingID::DWELL_UP_FIRST+i))) @@ -1380,9 +1380,9 @@ void CGameState::init(StartInfo * si) if (vstd::contains(ev.buildings,(-31-i))) //if we have horde for this level { ev.buildings.erase(BuildingID(-31-i)); - if (vti->town->hordeLvl[0] == i) + if (vti->town->hordeLvl.at(0) == i) ev.buildings.insert(BuildingID::HORDE_1); - if (vti->town->hordeLvl[1] == i) + if (vti->town->hordeLvl.at(1) == i) ev.buildings.insert(BuildingID::HORDE_2); } } @@ -2445,9 +2445,9 @@ int CGameState::lossCheck( PlayerColor player ) const return false; } -bmap > CGameState::unusedHeroesFromPool() +std::map > CGameState::unusedHeroesFromPool() { - bmap > pool = hpool.heroesPool; + std::map > pool = hpool.heroesPool; for ( auto i = players.cbegin() ; i != players.cend();i++) for(auto j = i->second.availableHeroes.cbegin(); j != i->second.availableHeroes.cend(); j++) if(*j) diff --git a/lib/CGameState.h b/lib/CGameState.h index 0b4a300..80f4a1d 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -364,16 +364,16 @@ public: ConstTransitivePtr curB; //current battle ui32 day; //total number of days in game ConstTransitivePtr map; - bmap players; - bmap teams; + std::map players; + std::map teams; CBonusSystemNode globalEffects; struct DLL_LINKAGE HeroesPool { - bmap > heroesPool; //[subID] - heroes available to buy; nullptr if not available - bmap pavailable; // [subid] -> which players can recruit hero (binary flags) + std::map > heroesPool; //[subID] - heroes available to buy; nullptr if not available + std::map pavailable; // [subid] -> which players can recruit hero (binary flags) - CGHeroInstance * pickHeroFor(bool native, PlayerColor player, const CTown *town, bmap > &available, const CHeroClass *bannedClass = nullptr) const; + CGHeroInstance * pickHeroFor(bool native, PlayerColor player, const CTown *town, std::map > &available, const CHeroClass *bannedClass = nullptr) const; template void serialize(Handler &h, const int version) { @@ -409,7 +409,7 @@ public: PlayerColor checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 (NEUTRAL) if no winner bool checkForStandardLoss(PlayerColor player) const; //checks if given player lost the game void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild - bmap > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns + std::map > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns BattleInfo * setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town); void buildBonusSystemTree(); diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index 99b892f..7636a16 100644 --- a/lib/CObjectHandler.cpp +++ b/lib/CObjectHandler.cpp @@ -2115,7 +2115,7 @@ int CGTownInstance::creatureDwellingLevel(int dwelling) const } int CGTownInstance::getHordeLevel(const int & HID) const//HID - 0 or 1; returns creature level or -1 if that horde structure is not present { - return town->hordeLvl[HID]; + return town->hordeLvl.at(HID); } int CGTownInstance::creatureGrowth(const int & level) const { @@ -2142,11 +2142,11 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const else if (hasBuilt(BuildingID::CITADEL)) ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::CITADEL, castleBonus = base / 2)); - if(town->hordeLvl[0] == level)//horde 1 + if(town->hordeLvl.at(0) == level)//horde 1 if(hasBuilt(BuildingID::HORDE_1)) ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::HORDE_1, creature->hordeGrowth)); - if(town->hordeLvl[1] == level)//horde 2 + if(town->hordeLvl.at(1) == level)//horde 2 if(hasBuilt(BuildingID::HORDE_2)) ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::HORDE_2, creature->hordeGrowth)); @@ -2620,7 +2620,7 @@ bool CGTownInstance::addBonusIfBuilt(BuildingID building, Bonus::BonusType type, if(hasBuilt(building)) { std::ostringstream descr; - descr << town->buildings[building]->Name() << " "; + descr << town->buildings.at(building)->Name() << " "; if(val > 0) descr << "+"; else if(val < 0) @@ -2695,7 +2695,7 @@ int CGTownInstance::getTownLevel() const // count all buildings that are not upgrades return boost::range::count_if(builtBuildings, [&](const BuildingID & build) { - return town->buildings[build] && town->buildings[build]->upgrade == -1; + return town->buildings.at(build) && town->buildings.at(build)->upgrade == -1; }); } diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index b2d32cd..89b393a 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -137,13 +137,13 @@ public: // TODO: replace with pointers to CCreature std::vector > creatures; - bmap > buildings; + std::map > buildings; std::vector dwellings; //defs for adventure map dwellings for new towns, [0] means tier 1 creatures etc. std::vector dwellingNames; // should be removed at least from configs in favor of auto-detection - bmap hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present) + std::map hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present) ui32 mageLevel; //max available mage guild level ui16 primaryRes; ArtifactID warMachine; diff --git a/lib/GameConstants.cpp b/lib/GameConstants.cpp index 860575c..c197e05 100644 --- a/lib/GameConstants.cpp +++ b/lib/GameConstants.cpp @@ -76,7 +76,7 @@ ID_LIKE_OPERATORS(BuildingID, BuildingID::EBuildingID) ID_LIKE_OPERATORS(BFieldType, BFieldType::EBFieldType) -bmap > & Obj::toDefObjInfo() const +std::map > & Obj::toDefObjInfo() const { return VLC->dobjinfo->gobjs[*this]; } diff --git a/lib/GameConstants.h b/lib/GameConstants.h index ef12ef4..0ace697 100644 --- a/lib/GameConstants.h +++ b/lib/GameConstants.h @@ -609,7 +609,7 @@ public: ID_LIKE_CLASS_COMMON(Obj, EObj) - bmap > & toDefObjInfo() const; + std::map > & toDefObjInfo() const; EObj num; }; diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index 3075e38..998b347 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -58,12 +58,12 @@ const std::map bonusLimitEffect = boost::assign BONUS_ITEM(ONLY_MELEE_FIGHT) BONUS_ITEM(ONLY_ENEMY_ARMY); -const bmap bonusLimiterMap = boost::assign::map_list_of +const std::map bonusLimiterMap = boost::assign::map_list_of ("SHOOTER_ONLY", make_shared(Bonus::SHOOTER)) ("DRAGON_NATURE", make_shared(Bonus::DRAGON_NATURE)) ("IS_UNDEAD", make_shared(Bonus::UNDEAD)); -const bmap bonusPropagatorMap = boost::assign::map_list_of +const std::map bonusPropagatorMap = boost::assign::map_list_of ("BATTLE_WIDE", make_shared(CBonusSystemNode::BATTLE)) ("VISITED_TOWN_AND_VISITOR", make_shared(CBonusSystemNode::TOWN_AND_VISITOR)) ("PLAYER_PROPAGATOR", make_shared(CBonusSystemNode::PLAYER)) diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index a6609fe..aaf94bf 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -967,8 +967,8 @@ extern DLL_LINKAGE const std::map bonusValueMap; extern DLL_LINKAGE const std::map bonusSourceMap; extern DLL_LINKAGE const std::map bonusDurationMap; extern DLL_LINKAGE const std::map bonusLimitEffect; -extern DLL_LINKAGE const bmap bonusLimiterMap; -extern DLL_LINKAGE const bmap bonusPropagatorMap; +extern DLL_LINKAGE const std::map bonusLimiterMap; +extern DLL_LINKAGE const std::map bonusPropagatorMap; // BonusList template that requires full interface of CBonusSystemNode diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index d70ef3b..2ead614 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -570,7 +570,7 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow if(!t->town->buildings.count(ID)) return EBuildingState::BUILDING_ERROR; - const CBuilding * pom = t->town->buildings[ID]; + const CBuilding * pom = t->town->buildings.at(ID); if(t->hasBuilt(ID)) //already built @@ -637,7 +637,7 @@ std::set CGameInfoCallback::getBuildingRequiments( const CGTownInsta std::set used; used.insert(ID); - auto reqs = t->town->buildings[ID]->requirements; + auto reqs = t->town->buildings.at(ID)->requirements; bool found; do @@ -648,7 +648,7 @@ std::set CGameInfoCallback::getBuildingRequiments( const CGTownInsta if(used.find(*i)==used.end()) //we haven't added requirements for this building { found = true; - auto & requires = t->town->buildings[*i]->requirements; + auto & requires = t->town->buildings.at(*i)->requirements; used.insert(*i); for(auto & require : requires) diff --git a/lib/StartInfo.h b/lib/StartInfo.h index 14755fc..b3ea179 100644 --- a/lib/StartInfo.h +++ b/lib/StartInfo.h @@ -73,7 +73,7 @@ struct StartInfo EMode mode; ui8 difficulty; //0=easy; 4=impossible - typedef bmap TPlayerInfos; + typedef std::map TPlayerInfos; TPlayerInfos playerInfos; //color indexed ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack) diff --git a/lib/mapping/CCampaignHandler.cpp b/lib/mapping/CCampaignHandler.cpp index 45080ff..ff6f660 100644 --- a/lib/mapping/CCampaignHandler.cpp +++ b/lib/mapping/CCampaignHandler.cpp @@ -456,7 +456,7 @@ const CCampaignScenario & CCampaignState::getCurrentScenario() const ui8 CCampaignState::currentBonusID() const { - return chosenCampaignBonuses[currentMap]; + return chosenCampaignBonuses.at(currentMap); } CCampaignState::CCampaignState() diff --git a/lib/mapping/CCampaignHandler.h b/lib/mapping/CCampaignHandler.h index d1e2b17..1eba3ce 100644 --- a/lib/mapping/CCampaignHandler.h +++ b/lib/mapping/CCampaignHandler.h @@ -151,7 +151,7 @@ public: std::vector mapsConquered, mapsRemaining; ui8 currentMap; - bmap chosenCampaignBonuses; //used only for mode CAMPAIGN + std::map chosenCampaignBonuses; //used only for mode CAMPAIGN //void initNewCampaign(const StartInfo &si); void mapConquered(const std::vector & heroes); diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index 29dcf82..e4ce01b 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -378,7 +378,7 @@ public: std::vector< ConstTransitivePtr > heroesOnMap; /// associative list to identify which hero/creature id belongs to which object id(index for objects) - bmap questIdentifierToId; + std::map questIdentifierToId; unique_ptr editManager; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index b9f287b..5143917 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -102,7 +102,7 @@ static void giveExp(BattleResult &r) r.exp[1] = 0; for(auto i = r.casualties[!r.winner].begin(); i!=r.casualties[!r.winner].end(); i++) { - r.exp[r.winner] += VLC->creh->creatures[i->first]->valOfBonuses(Bonus::STACK_HEALTH) * i->second; + r.exp[r.winner] += VLC->creh->creatures.at(i->first)->valOfBonuses(Bonus::STACK_HEALTH) * i->second; } } @@ -111,7 +111,7 @@ PlayerStatus PlayerStatuses::operator[](PlayerColor player) boost::unique_lock l(mx); if(players.find(player) != players.end()) { - return players[player]; + return players.at(player); } else { @@ -247,7 +247,7 @@ void CGameHandler::levelUpCommander (const CCommanderInstance * c, int skill) auto difference = [](std::vector< std::vector > skillLevels, std::vector secondarySkills, int skill)->int { int s = std::min (skill, (int)ECommander::SPELL_POWER); //spell power level controls also casts and resistance - return skillLevels[skill][secondarySkills[s]] - (secondarySkills[s] ? skillLevels[skill][secondarySkills[s]-1] : 0); + return skillLevels.at(skill).at(secondarySkills.at(s)) - (secondarySkills.at(s) ? skillLevels.at(skill).at(secondarySkills.at(s)-1) : 0); }; switch (skill) @@ -291,13 +291,13 @@ void CGameHandler::levelUpCommander (const CCommanderInstance * c, int skill) scp.which = SetCommanderProperty::SECONDARY_SKILL; scp.additionalInfo = skill; - scp.amount = c->secondarySkills[skill] + 1; + scp.amount = c->secondarySkills.at(skill) + 1; sendAndApply (&scp); } else if (skill >= 100) { scp.which = SetCommanderProperty::SPECIAL_SKILL; - scp.accumulatedBonus = *VLC->creh->skillRequirements[skill-100].first; + scp.accumulatedBonus = *VLC->creh->skillRequirements.at(skill-100).first; scp.additionalInfo = skill; //unnormalized sendAndApply (&scp); } @@ -325,14 +325,14 @@ void CGameHandler::levelUpCommander(const CCommanderInstance * c) for (int i = 0; i <= ECommander::SPELL_POWER; ++i) { - if (c->secondarySkills[i] < ECommander::MAX_SKILL_LEVEL) + if (c->secondarySkills.at(i) < ECommander::MAX_SKILL_LEVEL) clu.skills.push_back(i); } int i = 100; for (auto specialSkill : VLC->creh->skillRequirements) { - if (c->secondarySkills[specialSkill.second.first] == ECommander::MAX_SKILL_LEVEL - && c->secondarySkills[specialSkill.second.second] == ECommander::MAX_SKILL_LEVEL + if (c->secondarySkills.at(specialSkill.second.first) == ECommander::MAX_SKILL_LEVEL + && c->secondarySkills.at(specialSkill.second.second) == ECommander::MAX_SKILL_LEVEL && !vstd::contains (c->specialSKills, i)) clu.skills.push_back (i); ++i; @@ -433,8 +433,8 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer if (hero2) battleResult.data->exp[1] = hero2->calculateXp(battleResult.data->exp[1]); - const CArmedInstance *bEndArmy1 = gs->curB->sides[0].armyObject; - const CArmedInstance *bEndArmy2 = gs->curB->sides[1].armyObject; + const CArmedInstance *bEndArmy1 = gs->curB->sides.at(0).armyObject; + const CArmedInstance *bEndArmy2 = gs->curB->sides.at(1).armyObject; const BattleResult::EResult result = battleResult.get()->result; auto findBattleQuery = [this] () -> shared_ptr @@ -485,7 +485,7 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer { int maxLevel = eagleEyeLevel + 1; double eagleEyeChance = finishingBattle->winnerHero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::EAGLE_EYE); - for(const CSpell *sp : gs->curB->sides[!battleResult.data->winner].usedSpellsHistory) + for(const CSpell *sp : gs->curB->sides.at(!battleResult.data->winner).usedSpellsHistory) if(sp->level <= maxLevel && !vstd::contains(finishingBattle->winnerHero->spells, sp->id) && rand() % 100 < eagleEyeChance) cs.spells.insert(sp->id); } @@ -695,10 +695,10 @@ void CGameHandler::battleAfterLevelUp( const BattleResult &result ) if(result.result == BattleResult::ESCAPE) //retreat { sah.army[0].clear(); - sah.army[0].setCreature(SlotID(0), finishingBattle->loserHero->type->initialArmy[0].creature, 1); + sah.army[0].setCreature(SlotID(0), finishingBattle->loserHero->type->initialArmy.at(0).creature, 1); } - if(const CGHeroInstance *another = getPlayer(finishingBattle->loser)->availableHeroes[1]) + if(const CGHeroInstance *another = getPlayer(finishingBattle->loser)->availableHeroes.at(1)) sah.hid[1] = another->subID; else sah.hid[1] = -1; @@ -765,7 +765,7 @@ void CGameHandler::prepareAttack(BattleAttack &bat, const CStack *att, const CSt if (bonus && (bat.shot())) //TODO: make it work in meele? { bat.bsa.front().flags |= BattleStackAttacked::EFFECT; - bat.bsa.front().effect = VLC->spellh->spells[bonus->subtype]->mainEffectAnim; //hopefully it does not interfere with any other effect? + bat.bsa.front().effect = VLC->spellh->spells.at(bonus->subtype)->mainEffectAnim; //hopefully it does not interfere with any other effect? std::set attackedCreatures = gs->curB->getAffectedCreatures(SpellID(bonus->subtype).toSpell(), bonus->val, att->owner, targetHex); //TODO: get exact attacked hex for defender @@ -1069,7 +1069,7 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa return; } - if (forced || town->creatures[GameConstants::CREATURES_PER_TOWN].second.empty())//we need to change creature + if (forced || town->creatures.at(GameConstants::CREATURES_PER_TOWN).second.empty())//we need to change creature { SetAvailableCreatures ssi; ssi.tid = town->id; @@ -1084,13 +1084,13 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa } ui32 dwellpos = rand()%dwellings.size();//take random dwelling - ui32 creapos = rand()%dwellings[dwellpos]->creatures.size();//for multi-creature dwellings like Golem Factory - CreatureID creature = dwellings[dwellpos]->creatures[creapos].second[0]; + ui32 creapos = rand()%dwellings.at(dwellpos)->creatures.size();//for multi-creature dwellings like Golem Factory + CreatureID creature = dwellings.at(dwellpos)->creatures.at(creapos).second[0]; if (clear) - ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = std::max((ui32)1, (VLC->creh->creatures[creature]->growth)/2); + ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = std::max((ui32)1, (VLC->creh->creatures.at(creature)->growth)/2); else - ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = VLC->creh->creatures[creature]->growth; + ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = VLC->creh->creatures.at(creature)->growth; ssi.creatures[GameConstants::CREATURES_PER_TOWN].second.push_back(creature); sendAndApply(&ssi); } @@ -1180,7 +1180,7 @@ void CGameHandler::newTurn() } } - bmap > pool = gs->hpool.heroesPool; + std::map > pool = gs->hpool.heroesPool; for (auto & elem : gs->players) { @@ -1189,7 +1189,7 @@ void CGameHandler::newTurn() else if(elem.first >= PlayerColor::PLAYER_LIMIT) assert(0); //illegal player number! - std::pair playerGold(elem.first, elem.second.resources[Res::GOLD]); + std::pair playerGold(elem.first, elem.second.resources.at(Res::GOLD)); hadGold.insert(playerGold); if(newWeek) //new heroes in tavern @@ -1254,24 +1254,24 @@ void CGameHandler::newTurn() if(!firstTurn) if (t->hasBuilt(BuildingID::TREASURY, ETownType::RAMPART) && player < PlayerColor::PLAYER_LIMIT) - n.res[player][Res::GOLD] += hadGold[player]/10; //give 10% of starting gold + n.res[player][Res::GOLD] += hadGold.at(player)/10; //give 10% of starting gold if (!vstd::contains(n.cres, t->id)) { n.cres[t->id].tid = t->id; n.cres[t->id].creatures = t->creatures; } - auto & sac = n.cres[t->id]; + auto & sac = n.cres.at(t->id); for (int k=0; k < GameConstants::CREATURES_PER_TOWN; k++) //creature growths { if(t->creatureDwellingLevel(k) >= 0)//there is dwelling (k-level) { - ui32 &availableCount = sac.creatures[k].first; - const CCreature *cre = VLC->creh->creatures[t->creatures[k].second.back()]; + ui32 &availableCount = sac.creatures.at(k).first; + const CCreature *cre = VLC->creh->creatures.at(t->creatures.at(k).second.back()); if (n.specialWeek == NewTurn::PLAGUE) - availableCount = t->creatures[k].first / 2; //halve their number, no growth + availableCount = t->creatures.at(k).first / 2; //halve their number, no growth else { if(firstTurn) //first day of game: use only basic growths @@ -1280,7 +1280,7 @@ void CGameHandler::newTurn() availableCount += t->creatureGrowth(k); //Deity of fire week - upgrade both imps and upgrades - if (n.specialWeek == NewTurn::DEITYOFFIRE && vstd::contains(t->creatures[k].second, n.creatureid)) + if (n.specialWeek == NewTurn::DEITYOFFIRE && vstd::contains(t->creatures.at(k).second, n.creatureid)) availableCount += 15; if( cre->idNumber == n.creatureid ) //bonus week, effect applies only to identical creatures @@ -1321,11 +1321,11 @@ void CGameHandler::newTurn() fw.mode = 1; fw.player = player; // find all hidden tiles - auto & fow = gs->getPlayerTeam(player)->fogOfWarMap; + const auto & fow = gs->getPlayerTeam(player)->fogOfWarMap; for (size_t i=0; i lock(states.mx); - while(states.players[i->first].makingTurn && !end2) + while(states.players.at(i->first).makingTurn && !end2) { static time_duration p = milliseconds(200); states.cv.timed_wait(lock,p); @@ -1579,10 +1579,10 @@ void CGameHandler::giveSpells( const CGTownInstance *t, const CGHeroInstance *h } else { - for(int j=0; jspellsAtLevel(i+1,true) && jspells[i].size(); j++) + for(int j=0; jspellsAtLevel(i+1,true) && jspells.at(i).size(); j++) { - if(!vstd::contains(h->spells,t->spells[i][j])) - cs.spells.insert(t->spells[i][j]); + if(!vstd::contains(h->spells,t->spells.at(i).at(j))) + cs.spells.insert(t->spells.at(i).at(j)); } } } @@ -1859,7 +1859,7 @@ void CGameHandler::giveResource(PlayerColor player, Res::ERes which, int val) // SetResource sr; sr.player = player; sr.resid = which; - sr.val = gs->players.find(player)->second.resources[which] + val; + sr.val = gs->players.find(player)->second.resources.at(which) + val; sendAndApply(&sr); } @@ -2383,7 +2383,7 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID, if(!t->town->buildings.count(requestedID)) COMPLAIN_RETF("Town of faction %s does not have info about building ID=%s!", t->town->faction->name % tid); - const CBuilding * requestedBuilding = t->town->buildings[requestedID]; + const CBuilding * requestedBuilding = t->town->buildings.at(requestedID); //Vector with future list of built building and buildings in auto-mode that are not yet built. std::vector buildingsThatWillBe, remainingAutoBuildings; @@ -2422,7 +2422,7 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID, int level = (buildingID - BuildingID::DWELL_FIRST) % GameConstants::CREATURES_PER_TOWN; int upgradeNumber = (buildingID - BuildingID::DWELL_FIRST) / GameConstants::CREATURES_PER_TOWN; - if (upgradeNumber >= t->town->creatures[level].size()) + if (upgradeNumber >= t->town->creatures.at(level).size()) { complain(boost::str(boost::format("Error ecountered when building dwelling (bid=%s):" "no creature found (upgrade number %d, level %d!") @@ -2430,7 +2430,7 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID, return; } - CCreature * crea = VLC->creh->creatures[t->town->creatures[level][upgradeNumber]]; + CCreature * crea = VLC->creh->creatures.at(t->town->creatures.at(level).at(upgradeNumber)); SetAvailableCreatures ssi; ssi.tid = t->id; @@ -2458,7 +2458,7 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID, auto allRequirementsFullfilled = [&buildingsThatWillBe, t](const CBuilding *b) { for(auto requirementID : b->requirements) - if(!vstd::contains(buildingsThatWillBe, t->town->buildings[requirementID])) + if(!vstd::contains(buildingsThatWillBe, t->town->buildings.at(requirementID))) return false; return true; @@ -2562,7 +2562,7 @@ bool CGameHandler::recruitCreatures( ObjectInstanceID objid, CreatureID crid, ui { const CGDwelling *dw = static_cast(gs->getObj(objid)); const CArmedInstance *dst = nullptr; - const CCreature *c = VLC->creh->creatures[crid]; + const CCreature *c = VLC->creh->creatures.at(crid); bool warMachine = c->hasBonusOfType(Bonus::SIEGE_WEAPON); //TODO: test for owning @@ -2585,10 +2585,10 @@ bool CGameHandler::recruitCreatures( ObjectInstanceID objid, CreatureID crid, ui { if ( (fromLvl != -1) && ( level !=fromLvl ) ) continue; - const auto &cur = dw->creatures[level]; //current level info + const auto &cur = dw->creatures.at(level); //current level info int i = 0; for(; i < cur.second.size(); i++) //look for crid among available creatures list on current level - if(cur.second[i] == crid) + if(cur.second.at(i) == crid) break; if(i < cur.second.size()) @@ -2601,7 +2601,7 @@ bool CGameHandler::recruitCreatures( ObjectInstanceID objid, CreatureID crid, ui SlotID slot = dst->getSlotFor(crid); if( (!found && complain("Cannot recruit: no such creatures!")) - || (cram > VLC->creh->creatures[crid]->maxAmount(gs->getPlayer(dst->tempOwner)->resources) && complain("Cannot recruit: lack of resources!")) + || (cram > VLC->creh->creatures.at(crid)->maxAmount(gs->getPlayer(dst->tempOwner)->resources) && complain("Cannot recruit: lack of resources!")) || (cram<=0 && complain("Cannot recruit: cram <= 0!")) || (!slot.validSlot() && !warMachine && complain("Cannot recruit: no available slot!"))) { @@ -2657,7 +2657,7 @@ bool CGameHandler::upgradeCreature( ObjectInstanceID objid, SlotID pos, Creature UpgradeInfo ui = gs->getUpgradeInfo(obj->getStack(pos)); PlayerColor player = obj->tempOwner; const PlayerState *p = getPlayer(player); - int crQuantity = obj->stacks[pos]->count; + int crQuantity = obj->stacks.at(pos)->count; int newIDpos= vstd::find_pos(ui.newID, upgID);//get position of new id in UpgradeInfo //check if upgrade is possible @@ -2665,7 +2665,7 @@ bool CGameHandler::upgradeCreature( ObjectInstanceID objid, SlotID pos, Creature { return false; } - TResources totalCost = ui.cost[newIDpos] * crQuantity; + TResources totalCost = ui.cost.at(newIDpos) * crQuantity; //check if player has enough resources if(!p->resources.canAfford(totalCost)) @@ -2678,7 +2678,7 @@ bool CGameHandler::upgradeCreature( ObjectInstanceID objid, SlotID pos, Creature sendAndApply(&sr); //upgrade creature - changeStackType(StackLocation(obj, pos), VLC->creh->creatures[upgID]); + changeStackType(StackLocation(obj, pos), VLC->creh->creatures.at(upgID)); return true; } @@ -2852,7 +2852,7 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition if(assemble) { - CArtifact *combinedArt = VLC->arth->artifacts[assembleTo]; + CArtifact *combinedArt = VLC->arth->artifacts.at(assembleTo); if(!combinedArt->constituents) COMPLAIN_RET("assembleArtifacts: Artifact being attempted to assemble is not a combined artifacts!"); if(!vstd::contains(destArtifact->assemblyPossibilities(hero), combinedArt)) @@ -2896,10 +2896,10 @@ bool CGameHandler::buyArtifact( ObjectInstanceID hid, ArtifactID aid ) } else if(aid < 7 && aid > 3) //war machine { - int price = VLC->arth->artifacts[aid]->price; + int price = VLC->arth->artifacts.at(aid)->price; if(( hero->getArt(ArtifactPosition(9+aid)) && complain("Hero already has this machine!")) - || (gs->getPlayer(hero->getOwner())->resources[Res::GOLD] < price && complain("Not enough gold!"))) + || (gs->getPlayer(hero->getOwner())->resources.at(Res::GOLD) < price && complain("Not enough gold!"))) { return false; } @@ -2907,7 +2907,7 @@ bool CGameHandler::buyArtifact( ObjectInstanceID hid, ArtifactID aid ) || ((town->hasBuilt(BuildingID::BALLISTA_YARD, ETownType::STRONGHOLD)) && aid == ArtifactID::BALLISTA)) { giveResource(hero->getOwner(),Res::GOLD,-price); - giveHeroNewArtifact(hero, VLC->arth->artifacts[aid], ArtifactPosition(9+aid)); + giveHeroNewArtifact(hero, VLC->arth->artifacts.at(aid), ArtifactPosition(9+aid)); return true; } else @@ -2964,7 +2964,7 @@ bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, Res::E sendAndApply(&saa); - giveHeroNewArtifact(h, VLC->arth->artifacts[aid], ArtifactPosition::FIRST_AVAILABLE); + giveHeroNewArtifact(h, VLC->arth->artifacts.at(aid), ArtifactPosition::FIRST_AVAILABLE); return true; } @@ -3003,7 +3003,7 @@ bool CGameHandler::buySecSkill( const IMarket *m, const CGHeroInstance *h, Secon if (!h->canLearnSkill()) COMPLAIN_RET("Hero can't learn any more skills"); - if (h->type->heroClass->secSkillProbability[skill]==0)//can't learn this skill (like necromancy for most of non-necros) + if (h->type->heroClass->secSkillProbability.at(skill)==0)//can't learn this skill (like necromancy for most of non-necros) COMPLAIN_RET("The hero can't learn this skill!"); if(!vstd::contains(m->availableItemsIds(EMarketMode::RESOURCE_SKILL), skill)) @@ -3024,8 +3024,8 @@ bool CGameHandler::buySecSkill( const IMarket *m, const CGHeroInstance *h, Secon bool CGameHandler::tradeResources(const IMarket *market, ui32 val, PlayerColor player, ui32 id1, ui32 id2) { - int r1 = gs->getPlayer(player)->resources[id1], - r2 = gs->getPlayer(player)->resources[id2]; + int r1 = gs->getPlayer(player)->resources.at(id1), + r2 = gs->getPlayer(player)->resources.at(id2); vstd::amin(val, r1); //can't trade more resources than have @@ -3108,7 +3108,7 @@ bool CGameHandler::transformInUndead(const IMarket *market, const CGHeroInstance else resCreature = 56; - changeStackType(StackLocation(army, slot), VLC->creh->creatures[resCreature]); + changeStackType(StackLocation(army, slot), VLC->creh->creatures.at(resCreature)); return true; } @@ -3121,7 +3121,8 @@ bool CGameHandler::sendResources(ui32 val, PlayerColor player, Res::ERes r1, Pla return false; } - si32 curRes1 = gs->getPlayer(player)->resources[r1], curRes2 = gs->getPlayer(r2)->resources[r1]; + si32 curRes1 = gs->getPlayer(player)->resources.at(r1), + curRes2 = gs->getPlayer(r2)->resources.at(r1); val = std::min(si32(val),curRes1); SetResource sr; @@ -3150,7 +3151,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl static const int GOLD_NEEDED = 2500; //common preconditions - if( (p->resources[Res::GOLD]resources.at(Res::GOLD)= GameConstants::MAX_HEROES_PER_PLAYER && complain("Cannot hire hero, only 8 wandering heroes are allowed!"))) return false; @@ -3167,7 +3168,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl } - const CGHeroInstance *nh = p->availableHeroes[hid]; + const CGHeroInstance *nh = p->availableHeroes.at(hid); if (!nh) { complain ("Hero is not available for hiring!"); @@ -3182,9 +3183,9 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl sendAndApply(&hr); - bmap > pool = gs->unusedHeroesFromPool(); + std::map > pool = gs->unusedHeroesFromPool(); - const CGHeroInstance *theOtherHero = p->availableHeroes[!hid]; + const CGHeroInstance *theOtherHero = p->availableHeroes.at(!hid); const CGHeroInstance *newHero = nullptr; if (theOtherHero) //on XXL maps all heroes can be imprisoned :( newHero = gs->hpool.pickHeroFor(false, player, getNativeTown(player), pool, theOtherHero->type->heroClass); @@ -3207,7 +3208,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl SetResource sr; sr.player = player; sr.resid = Res::GOLD; - sr.val = p->resources[Res::GOLD] - GOLD_NEEDED; + sr.val = p->resources.at(Res::GOLD) - GOLD_NEEDED; sendAndApply(&sr); if(t) @@ -3319,7 +3320,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) //defensive stance //TODO: remove this bonus when stack becomes active SetStackEffect sse; sse.effect.push_back( Bonus(Bonus::STACK_GETS_TURN, Bonus::PRIMARY_SKILL, Bonus::OTHER, 20, -1, PrimarySkill::DEFENSE, Bonus::PERCENT_TO_ALL) ); - sse.effect.push_back( Bonus(Bonus::STACK_GETS_TURN, Bonus::PRIMARY_SKILL, Bonus::OTHER, gs->curB->stacks[ba.stackNumber]->valOfBonuses(Bonus::DEFENSIVE_STANCE), + sse.effect.push_back( Bonus(Bonus::STACK_GETS_TURN, Bonus::PRIMARY_SKILL, Bonus::OTHER, gs->curB->stacks.at(ba.stackNumber)->valOfBonuses(Bonus::DEFENSIVE_STANCE), -1, PrimarySkill::DEFENSE, Bonus::ADDITIVE_VALUE)); sse.stacks.push_back(ba.stackNumber); sendAndApply(&sse); @@ -3335,7 +3336,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) } case Battle::RETREAT: //retreat/flee { - if(!gs->curB->battleCanFlee(gs->curB->sides[ba.side].color)) + if(!gs->curB->battleCanFlee(gs->curB->sides.at(ba.side).color)) complain("Cannot retreat!"); else setBattleResult(BattleResult::ESCAPE, !ba.side); //surrendering side loses @@ -3343,7 +3344,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) } case Battle::SURRENDER: { - PlayerColor player = gs->curB->sides[ba.side].color; + PlayerColor player = gs->curB->sides.at(ba.side).color; int cost = gs->curB->battleGetSurrenderCost(player); if(cost < 0) complain("Cannot surrender!"); @@ -3535,7 +3536,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) auto onExit = vstd::makeScopeGuard([&]{ sendAndApply(&end_action); }); //if we started than we have to finish const CGHeroInstance * attackingHero = gs->curB->battleGetFightingHero(ba.side); - CHeroHandler::SBallisticsLevelInfo sbi = VLC->heroh->ballistics[attackingHero->getSecSkillLevel(SecondarySkill::BALLISTICS)]; + CHeroHandler::SBallisticsLevelInfo sbi = VLC->heroh->ballistics.at(attackingHero->getSecSkillLevel(SecondarySkill::BALLISTICS)); EWallParts::EWallParts desiredTarget = gs->curB->battleHexToWallPart(ba.destinationTile); if(desiredTarget < 0) @@ -3547,7 +3548,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) //in successive iterations damage is dealt but not yet subtracted from wall's HPs auto ¤tHP = gs->curB->si.wallState; - if (currentHP[desiredTarget] == EWallState::DESTROYED || currentHP[desiredTarget] == EWallState::NONE) + if (currentHP.at(desiredTarget) == EWallState::DESTROYED || currentHP.at(desiredTarget) == EWallState::NONE) { complain("catapult tried to attack already destroyed wall part!"); break; @@ -3560,8 +3561,8 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) do // catapult has chance to attack desired target. Othervice - attacks randomly { - if(currentHP[attackedPart] != EWallState::DESTROYED && // this part can be hit - currentHP[attackedPart] != EWallState::NONE && + if(currentHP.at(attackedPart) != EWallState::DESTROYED && // this part can be hit + currentHP.at(attackedPart) != EWallState::NONE && rand()%100 < getCatapultHitChance(attackedPart, sbi))//hit is successful { hitSuccessfull = true; @@ -3571,13 +3572,13 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) std::vector allowedTargets; for (size_t i=0; i< currentHP.size(); i++) { - if (currentHP[i] != EWallState::DESTROYED && - currentHP[i] != EWallState::NONE) + if (currentHP.at(i) != EWallState::DESTROYED && + currentHP.at(i) != EWallState::NONE) allowedTargets.push_back(EWallParts::EWallParts(i)); } if (allowedTargets.empty()) break; - attackedPart = allowedTargets[rand()%allowedTargets.size()]; + attackedPart = allowedTargets.at(rand()%allowedTargets.size()); } } while (!hitSuccessfull); @@ -3602,7 +3603,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) { if(dmgRand <= dmgChance[damage]) { - currentHP[attackedPart] = SiegeInfo::applyDamage(EWallState::EWallState(currentHP[attackedPart]), damage); + currentHP[attackedPart] = SiegeInfo::applyDamage(EWallState::EWallState(currentHP.at(attackedPart)), damage); attack.damageDealt = damage; break; @@ -3711,7 +3712,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) ui64 targetHealth = destStack->getCreature()->MaxHealth() * destStack->baseAmount; ui64 canRiseHp = std::min(targetHealth, risedHp); - ui32 canRiseAmount = canRiseHp / VLC->creh->creatures[bsa.creID]->MaxHealth(); + ui32 canRiseAmount = canRiseHp / VLC->creh->creatures.at(bsa.creID)->MaxHealth(); bsa.amount = std::min(canRiseAmount, destStack->baseAmount); @@ -3805,7 +3806,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message sm.val = 999; if(!h->hasSpellbook()) //hero doesn't have spellbook - giveHeroNewArtifact(h, VLC->arth->artifacts[0], ArtifactPosition::SPELLBOOK); //give spellbook + giveHeroNewArtifact(h, VLC->arth->artifacts.at(0), ArtifactPosition::SPELLBOOK); //give spellbook sendAndApply(&cs); sendAndApply(&sm); @@ -3836,7 +3837,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message else if(message == "vcmiainur") //gives 5 archangels into each slot { CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); - const CCreature *archangel = VLC->creh->creatures[13]; + const CCreature *archangel = VLC->creh->creatures.at(13); if(!hero) return; for(int i = 0; i < GameConstants::ARMY_SIZE; i++) @@ -3846,7 +3847,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message else if(message == "vcmiangband") //gives 10 black knight into each slot { CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); - const CCreature *blackKnight = VLC->creh->creatures[66]; + const CCreature *blackKnight = VLC->creh->creatures.at(66); if(!hero) return; for(int i = 0; i < GameConstants::ARMY_SIZE; i++) @@ -3859,11 +3860,11 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message if(!hero) return; if(!hero->getArt(ArtifactPosition::MACH1)) - giveHeroNewArtifact(hero, VLC->arth->artifacts[4], ArtifactPosition::MACH1); + giveHeroNewArtifact(hero, VLC->arth->artifacts.at(4), ArtifactPosition::MACH1); if(!hero->getArt(ArtifactPosition::MACH2)) - giveHeroNewArtifact(hero, VLC->arth->artifacts[5], ArtifactPosition::MACH2); + giveHeroNewArtifact(hero, VLC->arth->artifacts.at(5), ArtifactPosition::MACH2); if(!hero->getArt(ArtifactPosition::MACH3)) - giveHeroNewArtifact(hero, VLC->arth->artifacts[6], ArtifactPosition::MACH3); + giveHeroNewArtifact(hero, VLC->arth->artifacts.at(6), ArtifactPosition::MACH3); } else if(message == "vcminahar") //1000000 movement points { @@ -3894,7 +3895,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message for(int i=0;imap->width;i++) for(int j=0;jmap->height;j++) for(int k = 0; k < (gs->map->twoLevel ? 2 : 1); k++) - if(!gs->getPlayerTeam(fc.player)->fogOfWarMap[i][j][k]) + if(!gs->getPlayerTeam(fc.player)->fogOfWarMap.at(i).at(j).at(k)) hlp_tab[lastUnc++] = int3(i,j,k); fc.tiles.insert(hlp_tab, hlp_tab + lastUnc); delete [] hlp_tab; @@ -3918,13 +3919,13 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); if(!hero) return; for (int g = 7; g < VLC->arth->artifacts.size(); ++g) //including artifacts from mods - giveHeroNewArtifact(hero, VLC->arth->artifacts[g], ArtifactPosition::PRE_FIRST); + giveHeroNewArtifact(hero, VLC->arth->artifacts.at(g), ArtifactPosition::PRE_FIRST); } else cheated = false; if(cheated) { - SystemMessage temp_message(VLC->generaltexth->allTexts[260]); + SystemMessage temp_message(VLC->generaltexth->allTexts.at(260)); sendAndApply(&temp_message); checkLossVictory(player);//Player enter win code or got required art\creature } @@ -4077,7 +4078,7 @@ void CGameHandler::handleSpellCasting( SpellID spellID, int spellLvl, BattleHex continue; BattleStackAttacked bsa; - if ((destination > -1 && (attackedCre)->coversPos(destination)) || (spell->range[spellLvl] == "X" || mode == ECastingMode::ENCHANTER_CASTING)) + if ((destination > -1 && (attackedCre)->coversPos(destination)) || (spell->range.at(spellLvl) == "X" || mode == ECastingMode::ENCHANTER_CASTING)) //display effect only upon primary target of area spell //FIXME: if no stack is attacked, ther eis no animation and interface freezes { @@ -4271,7 +4272,7 @@ void CGameHandler::handleSpellCasting( SpellID spellID, int spellLvl, BattleHex //land mines or quicksand patches are handled as spell created obstacles for (int i = 0; i < patchesToPut; i++) - placeObstacle(availableTiles[i]); + placeObstacle(availableTiles.at(i)); } break; @@ -4330,7 +4331,7 @@ void CGameHandler::handleSpellCasting( SpellID spellID, int spellLvl, BattleHex int percentBonus = caster ? caster->valOfBonuses(Bonus::SPECIFIC_SPELL_DAMAGE, spellID.toEnum()) : 0; bsa.amount = usedSpellPower - * SpellID(spellID).toSpell()->powers[spellLvl] + * SpellID(spellID).toSpell()->powers.at(spellLvl) * (100 + percentBonus) / 100.0; //new feature - percentage bonus if(bsa.amount) sendAndApply(&bsa); @@ -4430,7 +4431,7 @@ void CGameHandler::handleSpellCasting( SpellID spellID, int spellLvl, BattleHex } //Magic Mirror effect - if (spell->isNegative() && mode != ECastingMode::MAGIC_MIRROR && spell->level && spell->range[0] == "0") //it is actual spell and can be reflected to single target, no recurrence + if (spell->isNegative() && mode != ECastingMode::MAGIC_MIRROR && spell->level && spell->range.at(0) == "0") //it is actual spell and can be reflected to single target, no recurrence { for(auto & attackedCre : attackedCres) { @@ -4441,15 +4442,15 @@ void CGameHandler::handleSpellCasting( SpellID spellID, int spellLvl, BattleHex std::vector & battleStacks = gs->curB->stacks; for (auto & battleStack : battleStacks) { - if(battleStack->owner == gs->curB->sides[casterSide].color) //get enemy stacks which can be affected by this spell + if(battleStack->owner == gs->curB->sides.at(casterSide).color) //get enemy stacks which can be affected by this spell { if (!gs->curB->battleIsImmune(nullptr, spell, ECastingMode::MAGIC_MIRROR, battleStack->position)) mirrorTargets.push_back(battleStack); } } - if (mirrorTargets.size()) + if (!mirrorTargets.empty()) { - int targetHex = mirrorTargets[rand() % mirrorTargets.size()]->position; + int targetHex = mirrorTargets.at(rand() % mirrorTargets.size())->position; handleSpellCasting(spellID, 0, targetHex, 1 - casterSide, (attackedCre)->owner, nullptr, (caster ? caster : nullptr), usedSpellPower, ECastingMode::MAGIC_MIRROR, (attackedCre)); } } @@ -4626,7 +4627,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st) } BonusList bl = *(st->getBonuses(Selector::type(Bonus::ENCHANTER))); int side = gs->curB->whatSide(st->owner); - if (bl.size() && st->casts && !gs->curB->sides[side].enchanterCounter) + if (bl.size() && st->casts && !gs->curB->sides.at(side).enchanterCounter) { int index = rand() % bl.size(); SpellID spellID = SpellID(bl[index]->subtype); @@ -4759,8 +4760,8 @@ void CGameHandler::handleTimeEvents() for (int i=0; iresources[i] != n.res[player][i]) //if resource had changed, we add it to the dialog - iw.components.push_back(Component(Component::RESOURCE,i,n.res[player][i]-was[i],0)); + if(ev.resources.at(i) && pinfo->resources.at(i) != n.res.at(player).at(i)) //if resource had changed, we add it to the dialog + iw.components.push_back(Component(Component::RESOURCE,i,n.res.at(player).at(i)-was.at(i),0)); } @@ -4846,11 +4847,11 @@ void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n) for(si32 i=0;icreatureDwellingLevel(i) >= 0 && ev.creatures[i])//there is dwelling + if(town->creatureDwellingLevel(i) >= 0 && ev.creatures.at(i))//there is dwelling { - sac.creatures[i].first += ev.creatures[i]; + sac.creatures[i].first += ev.creatures.at(i); iw.components.push_back(Component(Component::CREATURE, - town->creatures[i].second.back(), ev.creatures[i], 0)); + town->creatures.at(i).second.back(), ev.creatures.at(i), 0)); } } sendAndApply(&iw); //show dialog @@ -4952,10 +4953,10 @@ bool CGameHandler::isAllowedExchange( ObjectInstanceID id1, ObjectInstanceID id2 //Ongoing garrison exchange if(auto dialog = std::dynamic_pointer_cast(queries.topQuery(o1->tempOwner))) { - if(dialog->exchangingArmies[0] == o1 && dialog->exchangingArmies[1] == o2) + if(dialog->exchangingArmies.at(0) == o1 && dialog->exchangingArmies.at(1) == o2) return true; - if(dialog->exchangingArmies[1] == o1 && dialog->exchangingArmies[0] == o2) + if(dialog->exchangingArmies.at(1) == o1 && dialog->exchangingArmies.at(0) == o2) return true; } } @@ -5304,7 +5305,7 @@ bool CGameHandler::dig( const CGHeroInstance *h ) iw.text.addTxt(MetaString::GENERAL_TXT, 58); //"Congratulations! After spending many hours digging here, your hero has uncovered the " iw.text.addTxt(MetaString::ART_NAMES, 2); iw.soundID = soundBase::ULTIMATEARTIFACT; - giveHeroNewArtifact(h, VLC->arth->artifacts[2], ArtifactPosition::PRE_FIRST); //give grail + giveHeroNewArtifact(h, VLC->arth->artifacts.at(2), ArtifactPosition::PRE_FIRST); //give grail sendAndApply(&iw); iw.soundID = soundBase::invalid; @@ -5387,7 +5388,7 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat ) return; attackCasting(bat, Bonus::SPELL_AFTER_ATTACK, attacker); - if(bat.bsa[0].newAmount <= 0) + if(bat.bsa.at(0).newAmount <= 0) { //don't try death stare or acid breath on dead stack (crash!) return; @@ -5411,11 +5412,11 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat ) int maxToKill = (attacker->count + cap - 1) / cap; //not much more than chance * count vstd::amin(staredCreatures, maxToKill); - staredCreatures += (attacker->level() * attacker->valOfBonuses(Bonus::DEATH_STARE, 1)) / gs->curB->battleGetStackByID(bat.bsa[0].stackAttacked)->level(); + staredCreatures += (attacker->level() * attacker->valOfBonuses(Bonus::DEATH_STARE, 1)) / gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked)->level(); if (staredCreatures) { - if (bat.bsa[0].newAmount > 0) //TODO: death stare was not originally available for multiple-hex attacks, but... - handleSpellCasting(SpellID::DEATH_STARE, 0, gs->curB->battleGetStackByID(bat.bsa[0].stackAttacked)->position, + if (bat.bsa.at(0).newAmount > 0) //TODO: death stare was not originally available for multiple-hex attacks, but... + handleSpellCasting(SpellID::DEATH_STARE, 0, gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked)->position, !attacker->attackerOwned, attacker->owner, nullptr, nullptr, staredCreatures, ECastingMode::AFTER_ATTACK_CASTING, attacker); } } @@ -5429,7 +5430,7 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat ) } if (acidDamage) { - handleSpellCasting(SpellID::ACID_BREATH_DAMAGE, 0, gs->curB->battleGetStackByID(bat.bsa[0].stackAttacked)->position, + handleSpellCasting(SpellID::ACID_BREATH_DAMAGE, 0, gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked)->position, !attacker->attackerOwned, attacker->owner, nullptr, nullptr, acidDamage * attacker->count, ECastingMode::AFTER_ATTACK_CASTING, attacker); } @@ -5458,7 +5459,7 @@ bool CGameHandler::castSpell(const CGHeroInstance *h, SpellID spellID, const int case SpellID::SUMMON_BOAT: { //check if spell works at all - if(rand() % 100 >= s->powers[schoolLevel]) //power is % chance of success + if(rand() % 100 >= s->powers.at(schoolLevel)) //power is % chance of success { InfoWindow iw; iw.player = h->tempOwner; @@ -5520,7 +5521,7 @@ bool CGameHandler::castSpell(const CGHeroInstance *h, SpellID spellID, const int case SpellID::SCUTTLE_BOAT: { //check if spell works at all - if(rand() % 100 >= s->powers[schoolLevel]) //power is % chance of success + if(rand() % 100 >= s->powers.at(schoolLevel)) //power is % chance of success { InfoWindow iw; iw.player = h->tempOwner; @@ -5551,7 +5552,7 @@ bool CGameHandler::castSpell(const CGHeroInstance *h, SpellID spellID, const int COMPLAIN_RET("Destination tile doesn't exist!"); if(!h->movement) COMPLAIN_RET("Hero needs movement points to cast Dimension Door!"); - if(h->getBonusesCount(Bonus::SPELL_EFFECT, SpellID::DIMENSION_DOOR) >= s->powers[schoolLevel]) //limit casts per turn + if(h->getBonusesCount(Bonus::SPELL_EFFECT, SpellID::DIMENSION_DOOR) >= s->powers.at(schoolLevel)) //limit casts per turn { InfoWindow iw; iw.player = h->tempOwner; @@ -6214,7 +6215,7 @@ void CGameHandler::spawnWanderingMonsters(CreatureID creatureID) ui32 amount = tiles.size() / 200; //Chance is 0.5% for each tile std::random_shuffle(tiles.begin(), tiles.end()); logGlobal->traceStream() << "Spawning wandering monsters. Found " << tiles.size() << " free tiles. Creature type: " << creatureID; - const CCreature *cre = VLC->creh->creatures[creatureID]; + const CCreature *cre = VLC->creh->creatures.at(creatureID); for (int i = 0; i < amount; ++i) { tile = tiles.begin(); @@ -6292,7 +6293,7 @@ bool CGameHandler::isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, con void CGameHandler::duelFinished() { auto si = getStartInfo(); - auto getName = [&](int i){ return si->getIthPlayersSettings(gs->curB->sides[i].color).name; }; + auto getName = [&](int i){ return si->getIthPlayersSettings(gs->curB->sides.at(i).color).name; }; int casualtiesPoints = 0; logGlobal->debugStream() << boost::format("Winner side %d\nWinner casualties:") -- 1.8.4.2