1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

two patches/pull requests from janisozaur

- replace our custom bmap with std::map::at()
- compile fixes for editor
This commit is contained in:
Ivan Savenko
2013-11-12 10:45:42 +00:00
parent f56cccb716
commit 3560bbb7f3
23 changed files with 999 additions and 1052 deletions

View File

@@ -959,13 +959,13 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsi
TResources currentRes = cb->getResourceAmount(); TResources currentRes = cb->getResourceAmount();
TResources income = estimateIncome(); TResources income = estimateIncome();
//TODO: calculate if we have enough resources to build it in maxDays //TODO: calculate if we have enough resources to build it in maxDays
for(const auto & buildID : toBuild) 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); EBuildingState::EBuildingState canBuild = cb->canBuildStructure(t, buildID);
if(canBuild == EBuildingState::ALLOWED) if(canBuild == EBuildingState::ALLOWED)
{ {
if(!containsSavedRes(b->resources)) if(!containsSavedRes(b->resources))
{ {
@@ -974,13 +974,13 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsi
return true; return true;
} }
continue; continue;
} }
else if(canBuild == EBuildingState::NO_RESOURCES) 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++) for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; i++)
{ {
int diff = currentRes[i] - cost[i] + income[i]; int diff = currentRes[i] - cost[i] + income[i];
if(diff < 0) if(diff < 0)
saving[i] = 1; saving[i] = 1;
} }

View File

@@ -222,59 +222,12 @@ template<typename T, size_t N> char (&_ArrayCountObj(const T (&)[N]))[N];
// should be used for variables that becomes unused in release builds (e.g. only used for assert checks) // should be used for variables that becomes unused in release builds (e.g. only used for assert checks)
#define UNUSED(VAR) ((void)VAR) #define UNUSED(VAR) ((void)VAR)
/* ---------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */
/* VCMI standard library */ /* VCMI standard library */
/* ---------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */
//a normal std::map with a const operator[] for sanity template<typename T>
template<typename KeyT, typename ValT> std::ostream &operator<<(std::ostream &out, const boost::optional<T> &opt)
class bmap : public std::map<KeyT, ValT> {
{
public:
const ValT & operator[](KeyT key) const
{
return this->find(key)->second;
}
ValT & operator[](KeyT key)
{
return static_cast<std::map<KeyT, ValT> &>(*this)[key];
}
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<std::map<KeyT, ValT> &>(*this);
}
bmap()
{}
explicit bmap(const typename std::map<KeyT, ValT>::key_compare& _Pred)
: std::map<KeyT, ValT>(_Pred)
{}
bmap(const typename std::map<KeyT, ValT>::key_compare& _Pred, const typename std::map<KeyT, ValT>::allocator_type& _Al)
: std::map<KeyT, ValT>(_Pred, _Al)
{}
template<class _Iter>
bmap(_Iter _First, _Iter _Last)
: std::map<KeyT, ValT>(_First, _Last)
{}
template<class _Iter>
bmap(_Iter _First, _Iter _Last,
const typename std::map<KeyT, ValT>::key_compare& _Pred)
: std::map<KeyT, ValT>(_First, _Last, _Pred)
{}
template<class _Iter>
bmap(_Iter _First, _Iter _Last,
const typename std::map<KeyT, ValT>::key_compare& _Pred, const typename std::map<KeyT, ValT>::allocator_type& _Al)
: std::map<KeyT, ValT>(_First, _Last, _Pred, _Al)
{}
};
template<typename T>
std::ostream &operator<<(std::ostream &out, const boost::optional<T> &opt)
{
if(opt) if(opt)
return out << *opt; return out << *opt;
else else
@@ -311,19 +264,12 @@ namespace vstd
template <typename V, typename Item, typename Item2> template <typename V, typename Item, typename Item2>
bool contains(const std::map<Item,V> & c, const Item2 &i) bool contains(const std::map<Item,V> & c, const Item2 &i)
{ {
return c.find(i)!=c.end(); return c.find(i)!=c.end();
} }
//returns true if bmap c contains item i //returns true if unordered set c contains item i
template <typename V, typename Item, typename Item2> template <typename Item>
bool contains(const bmap<Item,V> & c, const Item2 &i) bool contains(const std::unordered_set<Item> & c, const Item &i)
{
return c.find(i)!=c.end();
}
//returns true if unordered set c contains item i
template <typename Item>
bool contains(const std::unordered_set<Item> & c, const Item &i)
{ {
return c.find(i)!=c.end(); return c.find(i)!=c.end();
} }
@@ -517,13 +463,13 @@ namespace vstd
auto tmpItr = itr++; auto tmpItr = itr++;
if(pred(*tmpItr)) if(pred(*tmpItr))
setContainer.erase(tmpItr); setContainer.erase(tmpItr);
} }
} }
//works for map and bmap, maybe something else //works for map and std::map, maybe something else
template<typename Key, typename Val, typename Predicate> template<typename Key, typename Val, typename Predicate>
void erase_if(std::map<Key, Val> &container, Predicate pred) void erase_if(std::map<Key, Val> &container, Predicate pred)
{ {
auto itr = container.begin(); auto itr = container.begin();
auto endItr = container.end(); auto endItr = container.end();
while(itr != endItr) while(itr != endItr)

View File

@@ -40,13 +40,13 @@ using namespace boost::assign;
const CBuilding * CBuildingRect::getBuilding() const CBuilding * CBuildingRect::getBuilding()
{ {
if (!str->building) if (!str->building)
return nullptr; return nullptr;
if (str->hiddenUpgrade) // hidden upgrades, e.g. hordes - return base (dwelling for hordes) 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; return str->building;
} }
CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str) CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str)
:CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE | CShowableAnim::USE_RLE), :CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE | CShowableAnim::USE_RLE),
@@ -114,13 +114,13 @@ void CBuildingRect::clickRight(tribool down, bool previousState)
{ {
if((!area) || (!((bool)down)) || (this!=parent->selectedBuilding) || getBuilding() == nullptr) if((!area) || (!((bool)down)) || (this!=parent->selectedBuilding) || getBuilding() == nullptr)
return; return;
if( !CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image if( !CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image
{ {
BuildingID bid = getBuilding()->bid; BuildingID bid = getBuilding()->bid;
const CBuilding *bld = town->town->buildings[bid]; const CBuilding *bld = town->town->buildings.at(bid);
if (bid < BuildingID::DWELL_FIRST) if (bid < BuildingID::DWELL_FIRST)
{ {
CRClickPopup::createAndPush(CInfoWindow::genText(bld->Name(), bld->Description()), CRClickPopup::createAndPush(CInfoWindow::genText(bld->Name(), bld->Description()),
new CComponent(CComponent::building, bld->town->faction->index, bld->bid)); new CComponent(CComponent::building, bld->town->faction->index, bld->bid));
} }
else else
@@ -209,20 +209,20 @@ std::string CBuildingRect::getSubtitle()//hover text for building
if (!getBuilding()) if (!getBuilding())
return ""; return "";
int bid = getBuilding()->bid; int bid = getBuilding()->bid;
if (bid<30)//non-dwellings - only buiding name 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% else//dwellings - recruit %creature%
{ {
auto & availableCreatures = town->creatures[(bid-30)%GameConstants::CREATURES_PER_TOWN].second; auto & availableCreatures = town->creatures[(bid-30)%GameConstants::CREATURES_PER_TOWN].second;
if(availableCreatures.size()) if(availableCreatures.size())
{ {
int creaID = availableCreatures.back();//taking last of available creatures 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 else
{ {
logGlobal->warnStream() << "Problem: dwelling with id " << bid << " offers no creatures!"; logGlobal->warnStream() << "Problem: dwelling with id " << bid << " offers no creatures!";
return "#ERROR#"; return "#ERROR#";
} }
@@ -255,18 +255,18 @@ void CBuildingRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstance *Town, int level): CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstance *Town, int level):
CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "CRTOINFO", Point(centerX, centerY)) CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "CRTOINFO", Point(centerX, centerY))
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; 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); title = new CLabel(80, 30, FONT_SMALL, CENTER, Colors::WHITE, creature->namePl);
animation = new CCreaturePic(30, 44, creature, true, true); animation = new CCreaturePic(30, 44, creature, true, true);
std::string text = boost::lexical_cast<std::string>(Town->creatures[level].first); std::string text = boost::lexical_cast<std::string>(Town->creatures.at(level).first);
available = new CLabel(80,190, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[217] + text); 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]); costPerTroop = new CLabel(80, 227, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[346]);
for(int i = 0; i<GameConstants::RESOURCE_QUANTITY; i++) for(int i = 0; i<GameConstants::RESOURCE_QUANTITY; i++)
{ {
if(creature->cost[i]) if(creature->cost[i])
@@ -503,13 +503,13 @@ void CCastleBuildings::recreate()
groups[structure->building->getBase()].push_back(structure); groups[structure->building->getBase()].push_back(structure);
} }
} }
for(auto & entry : groups) 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) const CStructure * toAdd = *boost::max_element(entry.second, [=](const CStructure * a, const CStructure * b)
{ {
return build->getDistance(a->building->bid) return build->getDistance(a->building->bid)
< build->getDistance(b->building->bid); < build->getDistance(b->building->bid);
}); });
@@ -526,17 +526,17 @@ CCastleBuildings::~CCastleBuildings()
{ {
} }
void CCastleBuildings::addBuilding(BuildingID building) void CCastleBuildings::addBuilding(BuildingID building)
{ {
//FIXME: implement faster method without complete recreation of town //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(); recreate();
auto & structures = groups[base]; auto & structures = groups.at(base);
for(CBuildingRect * rect : buildings) for(CBuildingRect * rect : buildings)
{ {
if (vstd::contains(structures, rect->str)) if (vstd::contains(structures, rect->str))
{ {
//reset animation //reset animation
@@ -1111,13 +1111,13 @@ CTownInfo::CTownInfo(int posX, int posY, const CGTownInstance* Town, bool townHa
{ {
buildID = 6 + town->fortLevel(); buildID = 6 + town->fortLevel();
if (buildID == 6) if (buildID == 6)
return; return;
picture = new CAnimImage("ITMCL.DEF", town->fortLevel()-1); picture = new CAnimImage("ITMCL.DEF", town->fortLevel()-1);
} }
building = town->town->buildings[BuildingID(buildID)]; building = town->town->buildings.at(BuildingID(buildID));
pos = picture->pos; pos = picture->pos;
} }
void CTownInfo::hover(bool on) void CTownInfo::hover(bool on)
{ {
if(on) if(on)
@@ -1295,13 +1295,13 @@ CHallInterface::CHallInterface(const CGTownInstance *Town):
resdatabar = new CMinorResDataBar; resdatabar = new CMinorResDataBar;
resdatabar->pos.x += pos.x; resdatabar->pos.x += pos.x;
resdatabar->pos.y += pos.y; resdatabar->pos.y += pos.y;
Rect barRect(5, 556, 740, 18); Rect barRect(5, 556, 740, 18);
statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false)); 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], "", exit = new CAdventureMapButton(CGI->generaltexth->hcommands[8], "",
boost::bind(&CHallInterface::close,this), 748, 556, "TPMAGE1.DEF", SDLK_RETURN); boost::bind(&CHallInterface::close,this), 748, 556, "TPMAGE1.DEF", SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE); exit->assignedKeys.insert(SDLK_ESCAPE);
auto & boxList = town->town->clientInfo.hallSlots; auto & boxList = town->town->clientInfo.hallSlots;
boxes.resize(boxList.size()); boxes.resize(boxList.size());
@@ -1310,13 +1310,13 @@ CHallInterface::CHallInterface(const CGTownInstance *Town):
for(size_t col=0; col<boxList[row].size(); col++) //for each box for(size_t col=0; col<boxList[row].size(); col++) //for each box
{ {
const CBuilding *building = nullptr; const CBuilding *building = nullptr;
for(auto & elem : boxList[row][col])//we are looking for the first not build structure for(auto & elem : boxList[row][col])//we are looking for the first not build structure
{ {
auto buildingID = elem; auto buildingID = elem;
building = town->town->buildings[buildingID]; building = town->town->buildings.at(buildingID);
if(!vstd::contains(town->builtBuildings,buildingID)) if(!vstd::contains(town->builtBuildings,buildingID))
break; break;
} }
int posX = pos.w/2 - boxList[row].size()*154/2 - (boxList[row].size()-1)*20 + 194*col, int posX = pos.w/2 - boxList[row].size()*154/2 - (boxList[row].size()-1)*20 + 194*col,
posY = 35 + 104*row; posY = 35 + 104*row;
@@ -1351,13 +1351,13 @@ std::string CBuildWindow::getTextForState(int state)
std::set<BuildingID> reqs= LOCPLINT->cb->getBuildingRequiments(town, building->bid); std::set<BuildingID> reqs= LOCPLINT->cb->getBuildingRequiments(town, building->bid);
for(const auto & i : reqs) for(const auto & i : reqs)
{ {
if (vstd::contains(town->builtBuildings, i)) if (vstd::contains(town->builtBuildings, i))
continue;//skipping constructed buildings continue;//skipping constructed buildings
ret+= town->town->buildings[i]->Name() + ", "; ret+= town->town->buildings.at(i)->Name() + ", ";
} }
ret.erase(ret.size()-2); ret.erase(ret.size()-2);
} }
} }
return ret; return ret;
} }
@@ -1423,13 +1423,13 @@ CFortScreen::CFortScreen(const CGTownInstance * town):
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
ui32 fortSize = town->creatures.size(); ui32 fortSize = town->creatures.size();
if (fortSize > GameConstants::CREATURES_PER_TOWN && town->creatures.back().second.empty()) if (fortSize > GameConstants::CREATURES_PER_TOWN && town->creatures.back().second.empty())
fortSize--; 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()); 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()); std::string text = boost::str(boost::format(CGI->generaltexth->fcommands[6]) % fortBuilding->Name());
exit = new CAdventureMapButton(text, "", boost::bind(&CFortScreen::close,this) ,748, 556, "TPMAGE1", SDLK_RETURN); exit = new CAdventureMapButton(text, "", boost::bind(&CFortScreen::close,this) ,748, 556, "TPMAGE1", SDLK_RETURN);
exit->assignedKeys.insert(SDLK_ESCAPE); exit->assignedKeys.insert(SDLK_ESCAPE);
@@ -1555,13 +1555,13 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance *
sizes.y+=21; sizes.y+=21;
values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[193], CGI->generaltexth->fcommands[4], creature->valOfBonuses(Bonus::STACKS_SPEED))); values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[193], CGI->generaltexth->fcommands[4], creature->valOfBonuses(Bonus::STACKS_SPEED)));
sizes.y+=20; sizes.y+=20;
values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[194], CGI->generaltexth->fcommands[5], town->creatureGrowth(level))); 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); 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)) if (vstd::contains(town->builtBuildings, buildingID))
{ {
ui32 available = town->creatures[level].first; ui32 available = town->creatures[level].first;
std::string availableText = CGI->generaltexth->allTexts[217]+ boost::lexical_cast<std::string>(available); std::string availableText = CGI->generaltexth->allTexts[217]+ boost::lexical_cast<std::string>(available);
availableCount = new CLabel(78, 119, FONT_SMALL, CENTER, Colors::WHITE, availableText); availableCount = new CLabel(78, 119, FONT_SMALL, CENTER, Colors::WHITE, availableText);

View File

@@ -409,30 +409,30 @@ void NewStructures::applyCl( CClient *cl )
{ {
CGTownInstance *town = GS(cl)->getTown(tid); CGTownInstance *town = GS(cl)->getTown(tid);
for(const auto & id : bid) for(const auto & id : bid)
{ {
if(id == BuildingID::CAPITOL) //fort or capitol if(id == BuildingID::CAPITOL) //fort or capitol
{ {
town->defInfo = const_cast<CGDefInfo*>(CGI->dobjinfo->capitols[town->subID].get()); town->defInfo = const_cast<CGDefInfo*>(CGI->dobjinfo->capitols.at(town->subID).get());
} }
if(id == BuildingID::FORT) if(id == BuildingID::FORT)
{ {
town->defInfo = const_cast<CGDefInfo*>(CGI->dobjinfo->gobjs[Obj::TOWN][town->subID].get()); town->defInfo = const_cast<CGDefInfo*>(CGI->dobjinfo->gobjs.at(Obj::TOWN).at(town->subID).get());
} }
if(vstd::contains(cl->playerint,town->tempOwner)) if(vstd::contains(cl->playerint,town->tempOwner))
cl->playerint[town->tempOwner]->buildChanged(town,id,1); cl->playerint[town->tempOwner]->buildChanged(town,id,1);
} }
} }
void RazeStructures::applyCl (CClient *cl) void RazeStructures::applyCl (CClient *cl)
{ {
CGTownInstance *town = GS(cl)->getTown(tid); CGTownInstance *town = GS(cl)->getTown(tid);
for(const auto & id : bid) for(const auto & id : bid)
{ {
if (id == BuildingID::CAPITOL) //fort or capitol if (id == BuildingID::CAPITOL) //fort or capitol
{ {
town->defInfo = const_cast<CGDefInfo*>(CGI->dobjinfo->gobjs[Obj::TOWN][town->subID].get()); town->defInfo = const_cast<CGDefInfo*>(CGI->dobjinfo->gobjs.at(Obj::TOWN).at(town->subID).get());
} }
if(vstd::contains (cl->playerint,town->tempOwner)) if(vstd::contains (cl->playerint,town->tempOwner))
cl->playerint[town->tempOwner]->buildChanged (town,id,2); cl->playerint[town->tempOwner]->buildChanged (town,id,2);
} }
} }
@@ -532,13 +532,13 @@ void InfoWindow::applyCl( CClient *cl )
comps.push_back(&elem); comps.push_back(&elem);
} }
std::string str; std::string str;
text.toString(str); text.toString(str);
if(vstd::contains(cl->playerint,player)) 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 else
logNetwork->warnStream() << "We received InfoWindow for not our player..."; logNetwork->warnStream() << "We received InfoWindow for not our player...";
} }
void SetObjectProperty::applyCl( CClient *cl ) void SetObjectProperty::applyCl( CClient *cl )
{ {
@@ -575,26 +575,26 @@ void CommanderLevelUp::applyCl( CClient *cl )
void BlockingDialog::applyCl( CClient *cl ) void BlockingDialog::applyCl( CClient *cl )
{ {
std::string str; std::string str;
text.toString(str); text.toString(str);
if(vstd::contains(cl->playerint,player)) 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 else
logNetwork->warnStream() << "We received YesNoDialog for not our player..."; logNetwork->warnStream() << "We received YesNoDialog for not our player...";
} }
void GarrisonDialog::applyCl(CClient *cl) void GarrisonDialog::applyCl(CClient *cl)
{ {
const CGHeroInstance *h = cl->getHero(hid); const CGHeroInstance *h = cl->getHero(hid);
const CArmedInstance *obj = static_cast<const CArmedInstance*>(cl->getObj(objid)); const CArmedInstance *obj = static_cast<const CArmedInstance*>(cl->getObj(objid));
if(!vstd::contains(cl->playerint,h->getOwner())) if(!vstd::contains(cl->playerint,h->getOwner()))
return; 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) void ExchangeDialog::applyCl(CClient *cl)
{ {
assert(heroes[0] && heroes[1]); assert(heroes[0] && heroes[1]);
INTERFACE_CALL_IF_PRESENT(heroes[0]->tempOwner, heroExchangeStarted, heroes[0]->id, heroes[1]->id, queryID); INTERFACE_CALL_IF_PRESENT(heroes[0]->tempOwner, heroExchangeStarted, heroes[0]->id, heroes[1]->id, queryID);
@@ -945,13 +945,13 @@ void SetAvailableArtifacts::applyCl(CClient *cl)
INTERFACE_CALL_IF_PRESENT(cl->getTile(bm->visitablePos())->visitableObjects.back()->tempOwner, availableArtifactsChanged, bm); INTERFACE_CALL_IF_PRESENT(cl->getTile(bm->visitablePos())->visitableObjects.back()->tempOwner, availableArtifactsChanged, bm);
} }
} }
void TradeComponents::applyCl(CClient *cl) void TradeComponents::applyCl(CClient *cl)
{///Shop handler {///Shop handler
switch (CGI->mh->map->objects[objectid]->ID) switch (CGI->mh->map->objects.at(objectid)->ID)
{ {
case Obj::BLACK_MARKET: case Obj::BLACK_MARKET:
break; break;
case Obj::TAVERN: case Obj::TAVERN:
break; break;
case Obj::DEN_OF_THIEVES: case Obj::DEN_OF_THIEVES:

View File

@@ -2,7 +2,7 @@
#include "Editor.h" #include "Editor.h"
#include "../lib/VCMI_Lib.h" #include "../lib/VCMI_Lib.h"
#include "../lib/VCMIDirs.h" #include "../lib/VCMIDirs.h"
#include "../lib/filesystem/CResourceLoader.h" #include "../lib/filesystem/Filesystem.h"
#include "../lib/CGeneralTextHandler.h" #include "../lib/CGeneralTextHandler.h"
#include "../lib/mapping/CMap.h" #include "../lib/mapping/CMap.h"
#include "../lib/mapping/CMapService.h" #include "../lib/mapping/CMapService.h"
@@ -13,7 +13,7 @@ Editor::Editor(QWidget *parent)
{ {
// Setup default logging(enough for now) // Setup default logging(enough for now)
console = new CConsoleHandler; console = new CConsoleHandler;
CBasicLogConfigurator logConfig(VCMIDirs::get().localPath() + "/VCMI_Editor_log.txt", console); CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() + "/VCMI_Editor_log.txt", console);
logConfig.configureDefault(); logConfig.configureDefault();
preinitDLL(console); preinitDLL(console);

View File

@@ -686,13 +686,13 @@ void CArtifactInstance::init()
id = static_cast<ArtifactInstanceID>(ArtifactID::NONE); //to be randomized id = static_cast<ArtifactInstanceID>(ArtifactID::NONE); //to be randomized
setNodeType(ARTIFACT_INSTANCE); setNodeType(ARTIFACT_INSTANCE);
} }
ArtifactPosition CArtifactInstance::firstAvailableSlot(const CArtifactSet *h) const 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)) if(canBePutAt(h, slot)) //if(artType->fitsAt(h->artifWorn, slot))
{ {
//we've found a free suitable slot. //we've found a free suitable slot.
return slot; return slot;
} }
@@ -1092,13 +1092,13 @@ bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn /*= false*/) const
return getArtPos(aid, onlyWorn) != ArtifactPosition::PRE_FIRST; return getArtPos(aid, onlyWorn) != ArtifactPosition::PRE_FIRST;
} }
const ArtSlotInfo * CArtifactSet::getSlot(ArtifactPosition pos) const const ArtSlotInfo * CArtifactSet::getSlot(ArtifactPosition pos) const
{ {
if(vstd::contains(artifactsWorn, pos)) if(vstd::contains(artifactsWorn, pos))
return &artifactsWorn[pos]; return &artifactsWorn.at(pos);
if(pos >= ArtifactPosition::AFTER_LAST ) if(pos >= ArtifactPosition::AFTER_LAST )
{ {
int backpackPos = (int)pos - GameConstants::BACKPACK_START; int backpackPos = (int)pos - GameConstants::BACKPACK_START;
if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size()) if(backpackPos < 0 || backpackPos >= artifactsInBackpack.size())
return nullptr; return nullptr;
else else

View File

@@ -63,13 +63,13 @@ public:
std::string nodeName() const override; std::string nodeName() const override;
void addNewBonus(Bonus *b) override; void addNewBonus(Bonus *b) override;
virtual void levelUpArtifact (CArtifactInstance * art){}; virtual void levelUpArtifact (CArtifactInstance * art){};
ui32 price; ui32 price;
bmap<ArtBearer::ArtBearer, std::vector<ArtifactPosition> > possibleSlots; //Bearer Type => ids of slots where artifact can be placed std::map<ArtBearer::ArtBearer, std::vector<ArtifactPosition> > possibleSlots; //Bearer Type => ids of slots where artifact can be placed
std::unique_ptr<std::vector<CArtifact *> > constituents; // Artifacts IDs a combined artifact consists of, or nullptr. std::unique_ptr<std::vector<CArtifact *> > constituents; // Artifacts IDs a combined artifact consists of, or nullptr.
std::vector<CArtifact *> constituentOf; // Reverse map of constituents - combined arts that include this art std::vector<CArtifact *> constituentOf; // Reverse map of constituents - combined arts that include this art
EartClass aClass; EartClass aClass;
ArtifactID id; ArtifactID id;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
@@ -263,13 +263,13 @@ struct DLL_LINKAGE ArtSlotInfo
}; };
class DLL_LINKAGE CArtifactSet class DLL_LINKAGE CArtifactSet
{ {
public: public:
std::vector<ArtSlotInfo> artifactsInBackpack; //hero's artifacts from bag std::vector<ArtSlotInfo> artifactsInBackpack; //hero's artifacts from bag
bmap<ArtifactPosition, ArtSlotInfo> artifactsWorn; //map<position,artifact_id>; 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<ArtifactPosition, ArtSlotInfo> artifactsWorn; //map<position,artifact_id>; 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); ArtSlotInfo &retreiveNewArtSlot(ArtifactPosition slot);
void setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked); void setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked);
void eraseArtSlot(ArtifactPosition slot); void eraseArtSlot(ArtifactPosition slot);
const ArtSlotInfo *getSlot(ArtifactPosition pos) const; const ArtSlotInfo *getSlot(ArtifactPosition pos) const;

View File

@@ -46,16 +46,16 @@ public:
CGDefInfo(); CGDefInfo();
void fetchInfoFromMSK(); void fetchInfoFromMSK();
}; };
class DLL_LINKAGE CDefObjInfoHandler class DLL_LINKAGE CDefObjInfoHandler
{ {
public: public:
bmap<int, bmap<int, ConstTransitivePtr<CGDefInfo> > > gobjs; std::map<int, std::map<int, ConstTransitivePtr<CGDefInfo> > > gobjs;
bmap<TFaction, ConstTransitivePtr<CGDefInfo> > capitols; std::map<TFaction, ConstTransitivePtr<CGDefInfo> > capitols;
bmap<TFaction, ConstTransitivePtr<CGDefInfo> > villages; std::map<TFaction, ConstTransitivePtr<CGDefInfo> > villages;
CDefObjInfoHandler(); CDefObjInfoHandler();
~CDefObjInfoHandler(); ~CDefObjInfoHandler();
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

View File

@@ -375,7 +375,7 @@ static CGObjectInstance * createObject(Obj id, int subid, int3 pos, PlayerColor
return nobj; return nobj;
} }
CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, PlayerColor player, const CTown *town, bmap<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass /*= nullptr*/) const CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, PlayerColor player, const CTown *town, std::map<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass /*= nullptr*/) const
{ {
CGHeroInstance *ret = nullptr; CGHeroInstance *ret = nullptr;
@@ -1340,13 +1340,13 @@ void CGameState::init(StartInfo * si)
if (vstd::contains(vti->builtBuildings,(-31-i))) //if we have horde for this level if (vstd::contains(vti->builtBuildings,(-31-i))) //if we have horde for this level
{ {
vti->builtBuildings.erase(BuildingID(-31-i));//remove old ID 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 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 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 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); vti->builtBuildings.insert(BuildingID::HORDE_2);
if (vstd::contains(vti->builtBuildings,(BuildingID::DWELL_UP_FIRST+i))) if (vstd::contains(vti->builtBuildings,(BuildingID::DWELL_UP_FIRST+i)))
@@ -1357,7 +1357,7 @@ void CGameState::init(StartInfo * si)
//Early check for #1444-like problems //Early check for #1444-like problems
for(auto building : vti->builtBuildings) for(auto building : vti->builtBuildings)
{ {
assert(vti->town->buildings[building]); assert(vti->town->buildings.at(building) != nullptr);
UNUSED(building); UNUSED(building);
} }
@@ -1368,9 +1368,9 @@ void CGameState::init(StartInfo * si)
if (vstd::contains(ev.buildings,(-31-i))) //if we have horde for this level if (vstd::contains(ev.buildings,(-31-i))) //if we have horde for this level
{ {
ev.buildings.erase(BuildingID(-31-i)); 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); 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); ev.buildings.insert(BuildingID::HORDE_2);
} }
} }
@@ -2433,9 +2433,9 @@ int CGameState::lossCheck( PlayerColor player ) const
return false; return false;
} }
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > CGameState::unusedHeroesFromPool() std::map<ui32, ConstTransitivePtr<CGHeroInstance> > CGameState::unusedHeroesFromPool()
{ {
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > pool = hpool.heroesPool; std::map<ui32, ConstTransitivePtr<CGHeroInstance> > pool = hpool.heroesPool;
for ( auto i = players.cbegin() ; i != players.cend();i++) for ( auto i = players.cbegin() ; i != players.cend();i++)
for(auto j = i->second.availableHeroes.cbegin(); j != i->second.availableHeroes.cend(); j++) for(auto j = i->second.availableHeroes.cbegin(); j != i->second.availableHeroes.cend(); j++)
if(*j) if(*j)

View File

@@ -361,22 +361,22 @@ class DLL_LINKAGE CGameState : public CNonConstInfoCallback
public: public:
ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized) ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
PlayerColor currentPlayer; //ID of player currently having turn PlayerColor currentPlayer; //ID of player currently having turn
ConstTransitivePtr<BattleInfo> curB; //current battle ConstTransitivePtr<BattleInfo> curB; //current battle
ui32 day; //total number of days in game ui32 day; //total number of days in game
ConstTransitivePtr<CMap> map; ConstTransitivePtr<CMap> map;
bmap<PlayerColor, PlayerState> players; std::map<PlayerColor, PlayerState> players;
bmap<TeamID, TeamState> teams; std::map<TeamID, TeamState> teams;
CBonusSystemNode globalEffects; CBonusSystemNode globalEffects;
struct DLL_LINKAGE HeroesPool struct DLL_LINKAGE HeroesPool
{ {
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > heroesPool; //[subID] - heroes available to buy; nullptr if not available std::map<ui32, ConstTransitivePtr<CGHeroInstance> > heroesPool; //[subID] - heroes available to buy; nullptr if not available
bmap<ui32,ui8> pavailable; // [subid] -> which players can recruit hero (binary flags) std::map<ui32,ui8> pavailable; // [subid] -> which players can recruit hero (binary flags)
CGHeroInstance * pickHeroFor(bool native, PlayerColor player, const CTown *town, bmap<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass = nullptr) const; CGHeroInstance * pickHeroFor(bool native, PlayerColor player, const CTown *town, std::map<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass = nullptr) const;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & heroesPool & pavailable; h & heroesPool & pavailable;
} }
} hpool; //we have here all heroes available on this map that are not hired } hpool; //we have here all heroes available on this map that are not hired
@@ -406,13 +406,13 @@ public:
std::vector<CGObjectInstance*> guardingCreatures (int3 pos) const; std::vector<CGObjectInstance*> guardingCreatures (int3 pos) const;
int victoryCheck(PlayerColor player) const; //checks if given player is winner; -1 if std victory, 1 if special victory, 0 else int victoryCheck(PlayerColor player) const; //checks if given player is winner; -1 if std victory, 1 if special victory, 0 else
int lossCheck(PlayerColor player) const; //checks if given player is loser; -1 if std loss, 1 if special, 0 else int lossCheck(PlayerColor player) const; //checks if given player is loser; -1 if std loss, 1 if special, 0 else
PlayerColor checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 (NEUTRAL) if no winner 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 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 void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns std::map<ui32, ConstTransitivePtr<CGHeroInstance> > 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); BattleInfo * setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance * heroes[2], bool creatureBank, const CGTownInstance *town);
void buildBonusSystemTree(); void buildBonusSystemTree();
void attachArmedObjects(); void attachArmedObjects();
void buildGlobalTeamPlayerTree(); void buildGlobalTeamPlayerTree();
void deserializationFix(); void deserializationFix();

View File

@@ -2112,13 +2112,13 @@ int CGTownInstance::creatureDwellingLevel(int dwelling) const
if (!hasBuilt(BuildingID(BuildingID::DWELL_FIRST+dwelling+i*GameConstants::CREATURES_PER_TOWN))) if (!hasBuilt(BuildingID(BuildingID::DWELL_FIRST+dwelling+i*GameConstants::CREATURES_PER_TOWN)))
return i-1; return i-1;
} }
} }
int CGTownInstance::getHordeLevel(const int & HID) const//HID - 0 or 1; returns creature level or -1 if that horde structure is not present 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 int CGTownInstance::creatureGrowth(const int & level) const
{ {
return getGrowthInfo(level).totalGrowth(); return getGrowthInfo(level).totalGrowth();
} }
@@ -2139,17 +2139,17 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
if (hasBuilt(BuildingID::CASTLE)) if (hasBuilt(BuildingID::CASTLE))
ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::CASTLE, castleBonus = base)); ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::CASTLE, castleBonus = base));
else if (hasBuilt(BuildingID::CITADEL)) else if (hasBuilt(BuildingID::CITADEL))
ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::CITADEL, castleBonus = base / 2)); 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)) if(hasBuilt(BuildingID::HORDE_1))
ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::HORDE_1, creature->hordeGrowth)); 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)) if(hasBuilt(BuildingID::HORDE_2))
ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::HORDE_2, creature->hordeGrowth)); ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::HORDE_2, creature->hordeGrowth));
int dwellingBonus = 0; int dwellingBonus = 0;
if(const PlayerState *p = cb->getPlayer(tempOwner, false)) if(const PlayerState *p = cb->getPlayer(tempOwner, false))
{ {
@@ -2617,13 +2617,13 @@ bool CGTownInstance::addBonusIfBuilt(BuildingID building, Bonus::BonusType type,
bool CGTownInstance::addBonusIfBuilt(BuildingID building, Bonus::BonusType type, int val, TPropagatorPtr & prop, int subtype /*= -1*/) bool CGTownInstance::addBonusIfBuilt(BuildingID building, Bonus::BonusType type, int val, TPropagatorPtr & prop, int subtype /*= -1*/)
{ {
if(hasBuilt(building)) if(hasBuilt(building))
{ {
std::ostringstream descr; std::ostringstream descr;
descr << town->buildings[building]->Name() << " "; descr << town->buildings.at(building)->Name() << " ";
if(val > 0) if(val > 0)
descr << "+"; descr << "+";
else if(val < 0) else if(val < 0)
descr << "-"; descr << "-";
descr << val; descr << val;
@@ -2692,13 +2692,13 @@ bool CGTownInstance::armedGarrison() const
int CGTownInstance::getTownLevel() const int CGTownInstance::getTownLevel() const
{ {
// count all buildings that are not upgrades // count all buildings that are not upgrades
return boost::range::count_if(builtBuildings, [&](const BuildingID & build) 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;
}); });
} }
CBonusSystemNode * CGTownInstance::whatShouldBeAttached() CBonusSystemNode * CGTownInstance::whatShouldBeAttached()
{ {
return &townAndVis; return &townAndVis;

View File

@@ -134,19 +134,19 @@ public:
std::vector<std::string> names; //names of the town instances std::vector<std::string> names; //names of the town instances
/// level -> list of creatures on this tier /// level -> list of creatures on this tier
// TODO: replace with pointers to CCreature // TODO: replace with pointers to CCreature
std::vector<std::vector<CreatureID> > creatures; std::vector<std::vector<CreatureID> > creatures;
bmap<BuildingID, ConstTransitivePtr<CBuilding> > buildings; std::map<BuildingID, ConstTransitivePtr<CBuilding> > buildings;
std::vector<std::string> dwellings; //defs for adventure map dwellings for new towns, [0] means tier 1 creatures etc. std::vector<std::string> dwellings; //defs for adventure map dwellings for new towns, [0] means tier 1 creatures etc.
std::vector<std::string> dwellingNames; std::vector<std::string> dwellingNames;
// should be removed at least from configs in favor of auto-detection // should be removed at least from configs in favor of auto-detection
bmap<int,int> hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present) std::map<int,int> hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present)
ui32 mageLevel; //max available mage guild level ui32 mageLevel; //max available mage guild level
ui16 primaryRes; ui16 primaryRes;
ArtifactID warMachine; ArtifactID warMachine;
si32 moatDamage; si32 moatDamage;
// default chance for hero of specific class to appear in tavern, if field "tavern" was not set // default chance for hero of specific class to appear in tavern, if field "tavern" was not set
// resulting chance = sqrt(town.chance * heroClass.chance) // resulting chance = sqrt(town.chance * heroClass.chance)

View File

@@ -73,13 +73,13 @@ ID_LIKE_OPERATORS(SpellID, SpellID::ESpellID)
ID_LIKE_OPERATORS(BuildingID, BuildingID::EBuildingID) ID_LIKE_OPERATORS(BuildingID, BuildingID::EBuildingID)
ID_LIKE_OPERATORS(BFieldType, BFieldType::EBFieldType) ID_LIKE_OPERATORS(BFieldType, BFieldType::EBFieldType)
bmap<int, ConstTransitivePtr<CGDefInfo> > & Obj::toDefObjInfo() const std::map<int, ConstTransitivePtr<CGDefInfo> > & Obj::toDefObjInfo() const
{ {
return VLC->dobjinfo->gobjs[*this]; return VLC->dobjinfo->gobjs[*this];
} }
CArtifact * ArtifactID::toArtifact() const CArtifact * ArtifactID::toArtifact() const
{ {

View File

@@ -606,13 +606,13 @@ public:
}; };
Obj(EObj _num = NO_OBJ) : num(_num) Obj(EObj _num = NO_OBJ) : num(_num)
{} {}
ID_LIKE_CLASS_COMMON(Obj, EObj) ID_LIKE_CLASS_COMMON(Obj, EObj)
bmap<int, ConstTransitivePtr<CGDefInfo> > & toDefObjInfo() const; std::map<int, ConstTransitivePtr<CGDefInfo> > & toDefObjInfo() const;
EObj num; EObj num;
}; };
ID_LIKE_OPERATORS_DECLS(Obj, Obj::EObj) ID_LIKE_OPERATORS_DECLS(Obj, Obj::EObj)

View File

@@ -55,18 +55,18 @@ const std::map<std::string, ui16> bonusDurationMap = boost::assign::map_list_of
const std::map<std::string, Bonus::LimitEffect> bonusLimitEffect = boost::assign::map_list_of const std::map<std::string, Bonus::LimitEffect> bonusLimitEffect = boost::assign::map_list_of
BONUS_ITEM(NO_LIMIT) BONUS_ITEM(NO_LIMIT)
BONUS_ITEM(ONLY_DISTANCE_FIGHT) BONUS_ITEM(ONLY_DISTANCE_FIGHT)
BONUS_ITEM(ONLY_MELEE_FIGHT) BONUS_ITEM(ONLY_MELEE_FIGHT)
BONUS_ITEM(ONLY_ENEMY_ARMY); BONUS_ITEM(ONLY_ENEMY_ARMY);
const bmap<std::string, TLimiterPtr> bonusLimiterMap = boost::assign::map_list_of const std::map<std::string, TLimiterPtr> bonusLimiterMap = boost::assign::map_list_of
("SHOOTER_ONLY", make_shared<HasAnotherBonusLimiter>(Bonus::SHOOTER)) ("SHOOTER_ONLY", make_shared<HasAnotherBonusLimiter>(Bonus::SHOOTER))
("DRAGON_NATURE", make_shared<HasAnotherBonusLimiter>(Bonus::DRAGON_NATURE)) ("DRAGON_NATURE", make_shared<HasAnotherBonusLimiter>(Bonus::DRAGON_NATURE))
("IS_UNDEAD", make_shared<HasAnotherBonusLimiter>(Bonus::UNDEAD)); ("IS_UNDEAD", make_shared<HasAnotherBonusLimiter>(Bonus::UNDEAD));
const bmap<std::string, TPropagatorPtr> bonusPropagatorMap = boost::assign::map_list_of const std::map<std::string, TPropagatorPtr> bonusPropagatorMap = boost::assign::map_list_of
("BATTLE_WIDE", make_shared<CPropagatorNodeType>(CBonusSystemNode::BATTLE)) ("BATTLE_WIDE", make_shared<CPropagatorNodeType>(CBonusSystemNode::BATTLE))
("VISITED_TOWN_AND_VISITOR", make_shared<CPropagatorNodeType>(CBonusSystemNode::TOWN_AND_VISITOR)) ("VISITED_TOWN_AND_VISITOR", make_shared<CPropagatorNodeType>(CBonusSystemNode::TOWN_AND_VISITOR))
("PLAYER_PROPAGATOR", make_shared<CPropagatorNodeType>(CBonusSystemNode::PLAYER)) ("PLAYER_PROPAGATOR", make_shared<CPropagatorNodeType>(CBonusSystemNode::PLAYER))
("HERO", make_shared<CPropagatorNodeType>(CBonusSystemNode::HERO)); ("HERO", make_shared<CPropagatorNodeType>(CBonusSystemNode::HERO));

View File

@@ -964,14 +964,14 @@ namespace Selector
extern DLL_LINKAGE const std::map<std::string, Bonus::BonusType> bonusNameMap; extern DLL_LINKAGE const std::map<std::string, Bonus::BonusType> bonusNameMap;
extern DLL_LINKAGE const std::map<std::string, Bonus::ValueType> bonusValueMap; extern DLL_LINKAGE const std::map<std::string, Bonus::ValueType> bonusValueMap;
extern DLL_LINKAGE const std::map<std::string, Bonus::BonusSource> bonusSourceMap; extern DLL_LINKAGE const std::map<std::string, Bonus::BonusSource> bonusSourceMap;
extern DLL_LINKAGE const std::map<std::string, ui16> bonusDurationMap; extern DLL_LINKAGE const std::map<std::string, ui16> bonusDurationMap;
extern DLL_LINKAGE const std::map<std::string, Bonus::LimitEffect> bonusLimitEffect; extern DLL_LINKAGE const std::map<std::string, Bonus::LimitEffect> bonusLimitEffect;
extern DLL_LINKAGE const bmap<std::string, TLimiterPtr> bonusLimiterMap; extern DLL_LINKAGE const std::map<std::string, TLimiterPtr> bonusLimiterMap;
extern DLL_LINKAGE const bmap<std::string, TPropagatorPtr> bonusPropagatorMap; extern DLL_LINKAGE const std::map<std::string, TPropagatorPtr> bonusPropagatorMap;
// BonusList template that requires full interface of CBonusSystemNode // BonusList template that requires full interface of CBonusSystemNode
template <class InputIterator> template <class InputIterator>
void BonusList::insert(const int position, InputIterator first, InputIterator last) void BonusList::insert(const int position, InputIterator first, InputIterator last)
{ {

View File

@@ -567,13 +567,13 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
{ {
ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", EBuildingState::TOWN_NOT_OWNED); ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", EBuildingState::TOWN_NOT_OWNED);
if(!t->town->buildings.count(ID)) if(!t->town->buildings.count(ID))
return EBuildingState::BUILDING_ERROR; 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 if(t->hasBuilt(ID)) //already built
return EBuildingState::ALREADY_PRESENT; return EBuildingState::ALREADY_PRESENT;
//can we build it? //can we build it?
@@ -634,24 +634,24 @@ std::set<BuildingID> CGameInfoCallback::getBuildingRequiments( const CGTownInsta
{ {
ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", std::set<BuildingID>()); ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", std::set<BuildingID>());
ERROR_RET_VAL_IF(!t->town->buildings.count(ID), "No such building!", std::set<BuildingID>()); ERROR_RET_VAL_IF(!t->town->buildings.count(ID), "No such building!", std::set<BuildingID>());
std::set<int> used; std::set<int> used;
used.insert(ID); used.insert(ID);
auto reqs = t->town->buildings[ID]->requirements; auto reqs = t->town->buildings.at(ID)->requirements;
bool found; bool found;
do do
{ {
found = false; found = false;
for(auto i=reqs.begin();i!=reqs.end();i++) for(auto i=reqs.begin();i!=reqs.end();i++)
{ {
if(used.find(*i)==used.end()) //we haven't added requirements for this building if(used.find(*i)==used.end()) //we haven't added requirements for this building
{ {
found = true; found = true;
auto & requires = t->town->buildings[*i]->requirements; auto & requires = t->town->buildings.at(*i)->requirements;
used.insert(*i); used.insert(*i);
for(auto & require : requires) for(auto & require : requires)
reqs.insert(require);//creating full list of requirements reqs.insert(require);//creating full list of requirements
} }
} }

View File

@@ -453,7 +453,7 @@ DLL_LINKAGE void NewStructures::applyGs( CGameState *gs )
CGTownInstance *t = gs->getTown(tid); CGTownInstance *t = gs->getTown(tid);
for(const auto & id : bid) for(const auto & id : bid)
{ {
assert(t->town->buildings[id]); assert(t->town->buildings.at(id) != nullptr);
t->builtBuildings.insert(id); t->builtBuildings.insert(id);
} }
t->builded = builded; t->builded = builded;

View File

@@ -70,13 +70,13 @@ struct StartInfo
{ {
enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN, DUEL, INVALID = 255}; enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN, DUEL, INVALID = 255};
EMode mode; EMode mode;
ui8 difficulty; //0=easy; 4=impossible ui8 difficulty; //0=easy; 4=impossible
typedef bmap<PlayerColor, PlayerSettings> TPlayerInfos; typedef std::map<PlayerColor, PlayerSettings> TPlayerInfos;
TPlayerInfos playerInfos; //color indexed TPlayerInfos playerInfos; //color indexed
ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack) ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack)
ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
ui32 mapfileChecksum; //0 if not relevant ui32 mapfileChecksum; //0 if not relevant
ui8 turnTime; //in minutes, 0=unlimited ui8 turnTime; //in minutes, 0=unlimited

View File

@@ -453,13 +453,13 @@ const CCampaignScenario & CCampaignState::getCurrentScenario() const
{ {
return camp->scenarios[currentMap]; return camp->scenarios[currentMap];
} }
ui8 CCampaignState::currentBonusID() const ui8 CCampaignState::currentBonusID() const
{ {
return chosenCampaignBonuses[currentMap]; return chosenCampaignBonuses.at(currentMap);
} }
CCampaignState::CCampaignState() CCampaignState::CCampaignState()
{} {}
CCampaignState::CCampaignState( unique_ptr<CCampaign> _camp ) : camp(std::move(_camp)) CCampaignState::CCampaignState( unique_ptr<CCampaign> _camp ) : camp(std::move(_camp))

View File

@@ -148,13 +148,13 @@ class DLL_LINKAGE CCampaignState
public: public:
unique_ptr<CCampaign> camp; unique_ptr<CCampaign> camp;
std::string campaignName; std::string campaignName;
std::vector<ui8> mapsConquered, mapsRemaining; std::vector<ui8> mapsConquered, mapsRemaining;
ui8 currentMap; ui8 currentMap;
bmap<ui8, ui8> chosenCampaignBonuses; //used only for mode CAMPAIGN std::map<ui8, ui8> chosenCampaignBonuses; //used only for mode CAMPAIGN
//void initNewCampaign(const StartInfo &si); //void initNewCampaign(const StartInfo &si);
void mapConquered(const std::vector<CGHeroInstance*> & heroes); void mapConquered(const std::vector<CGHeroInstance*> & heroes);
boost::optional<CScenarioTravel::STravelBonus> getBonusForCurrentMap() const; boost::optional<CScenarioTravel::STravelBonus> getBonusForCurrentMap() const;
const CCampaignScenario &getCurrentScenario() const; const CCampaignScenario &getCurrentScenario() const;
ui8 currentBonusID() const; ui8 currentBonusID() const;

View File

@@ -375,13 +375,13 @@ public:
std::vector< ConstTransitivePtr<CGHeroInstance> > allHeroes; //indexed by [hero_type_id]; on map, disposed, prisons, etc. std::vector< ConstTransitivePtr<CGHeroInstance> > allHeroes; //indexed by [hero_type_id]; on map, disposed, prisons, etc.
//Helper lists //Helper lists
std::vector< ConstTransitivePtr<CGHeroInstance> > heroesOnMap; std::vector< ConstTransitivePtr<CGHeroInstance> > heroesOnMap;
/// associative list to identify which hero/creature id belongs to which object id(index for objects) /// associative list to identify which hero/creature id belongs to which object id(index for objects)
bmap<si32, ObjectInstanceID> questIdentifierToId; std::map<si32, ObjectInstanceID> questIdentifierToId;
unique_ptr<CMapEditManager> editManager; unique_ptr<CMapEditManager> editManager;
private: private:
TerrainTile*** terrain; TerrainTile*** terrain;

File diff suppressed because it is too large Load Diff