diff --git a/CCallback.cpp b/CCallback.cpp index f58a241f4..1739ec160 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -158,7 +158,7 @@ const CGTownInstance * CCallback::getTownInfo(int val, bool mode) const //mode = boost::shared_lock lock(*gs->mx); if (!mode) { - const std::vector &towns = gs->players[gs->currentPlayer].towns; + const std::vector > &towns = gs->players[gs->currentPlayer].towns; if(val < towns.size()) return towns[val]; else diff --git a/client/CGameInfo.h b/client/CGameInfo.h index 3503d2bcd..f8ff69d45 100644 --- a/client/CGameInfo.h +++ b/client/CGameInfo.h @@ -51,7 +51,7 @@ struct Mapa; */ class CGameInfo { - CGameState * state; //don't touch it in client's code + ConstTransitivePtr state; //don't touch it in client's code public: ConstTransitivePtr arth; ConstTransitivePtr heroh; @@ -73,7 +73,7 @@ public: CGameInfo(); }; -// ConstTransitivePtr state; //don't touch it in client's code +// // public: // // ConstTransitivePtr generaltexth; diff --git a/client/Client.cpp b/client/Client.cpp index 7e0af5d78..123902e7b 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -173,7 +173,7 @@ void initVillagesCapitols(Mapa * map) ifs>>ccc; for(int i=0;istate->villages[i]; @@ -182,11 +182,11 @@ void initVillagesCapitols(Mapa * map) else n = CGI->state->capitols[i%ccc]; - ifs >> n->name; + ifs >> const_cast(n)->name; if(!n) tlog1 << "*HUGE* Warning - missing town def for " << i << std::endl; else - map->defy.push_back(n); + map->defy.push_back(const_cast(n)); } } @@ -364,7 +364,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) tlog0 <<"\tSending/Getting info to/from the server: "<state; + gs = const_cast(CGI)->state; gs->scenarioOps = si; gs->init(si, sum, seed); @@ -399,7 +399,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) playerint[color]->init(cb); } - serv->addStdVecItems(CGI->state); + serv->addStdVecItems(const_cast(CGI)->state); hotSeat = (humanPlayers > 1); playerint[255] = CAIHandler::getNewAI(cb,conf.cc.defaultAI); diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index 72cb7cd3c..366d7e759 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -294,7 +294,7 @@ void CMapHandler::initObjectRects() } } } -static void processDef (CGDefInfo* def) +static void processDef (const CGDefInfo* def) { if(def->id == EVENTI_TYPE) { @@ -335,11 +335,11 @@ static void processDef (CGDefInfo* def) CSDL_Ext::alphaTransform(ourDef->ourImages[yy].bitmap); } } -void CMapHandler::initHeroDef(CGHeroInstance * h) +void CMapHandler::initHeroDef(const CGHeroInstance * h) { graphics->advmapobjGraphics[h->defInfo->id][h->defInfo->subid] = graphics->flags1[0]; - h->defInfo->width =graphics->getDef(h)->ourImages[0].bitmap->w/32; - h->defInfo->height = graphics->getDef(h)->ourImages[0].bitmap->h/32; +// h->defInfo->width =graphics->getDef(h)->ourImages[0].bitmap->w/32; +// h->defInfo->height = graphics->getDef(h)->ourImages[0].bitmap->h/32; } void CMapHandler::init() { diff --git a/client/mapHandler.h b/client/mapHandler.h index 00ca0ef69..4c563981f 100644 --- a/client/mapHandler.h +++ b/client/mapHandler.h @@ -110,7 +110,7 @@ public: bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist) bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope) - void initHeroDef(CGHeroInstance * h); + void initHeroDef(const CGHeroInstance * h); void init(); void calculateBlockedPos(); void initObjectRects(); diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 469a98951..a2fbf8e93 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1053,7 +1053,7 @@ std::string CStack::nodeName() const return oss.str(); } -CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, const CTown *town, std::map &available, const CHeroClass *bannedClass /*= NULL*/) const +CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, const CTown *town, bmap > &available, const CHeroClass *bannedClass /*= NULL*/) const { CGHeroInstance *ret = NULL; @@ -1067,7 +1067,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co if(native) { - for(std::map::iterator i=available.begin(); i!=available.end(); i++) + for(bmap >::iterator i=available.begin(); i!=available.end(); i++) { if(pavailable.find(i->first)->second & 1<second->type->heroType/2 == town->typeID) @@ -1089,7 +1089,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co { int sum=0, r; - for(std::map::iterator i=available.begin(); i!=available.end(); i++) + for(bmap >::iterator i=available.begin(); i!=available.end(); i++) { if(pavailable.find(i->first)->second & 1<second->type->heroClass != bannedClass) @@ -1921,7 +1921,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) break; } } - std::vector & heroes = players[humanPlayer].heroes; + std::vector > & heroes = players[humanPlayer].heroes; if (chosenBonus.info1 == 0xFFFD) //most powerful { @@ -3952,7 +3952,7 @@ struct statsHLP static const CGHeroInstance * findBestHero(CGameState * gs, int color) { - std::vector &h = gs->players[color].heroes; + std::vector > &h = gs->players[color].heroes; if(!h.size()) return NULL; //best hero will be that with highest exp @@ -4140,11 +4140,11 @@ int CGameState::lossCheck( ui8 player ) const return false; } -std::map CGameState::unusedHeroesFromPool() +bmap > CGameState::unusedHeroesFromPool() { - std::map pool = hpool.heroesPool; + bmap > pool = hpool.heroesPool; for ( std::map::iterator i = players.begin() ; i != players.end();i++) - for(std::vector::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++) + for(std::vector< ConstTransitivePtr >::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++) if(*j) pool.erase((**j).subID); diff --git a/lib/CGameState.h b/lib/CGameState.h index 379ac748c..3d745f0d9 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -21,6 +21,8 @@ #include "../tchar_amigaos4.h" #endif +#include "ConstTransitivePtr.h" + /* * CGameState.h, part of VCMI engine @@ -131,12 +133,11 @@ public: ui8 human; //true if human controlled player, false for AI ui32 currentSelection; //id of hero/town, 0xffffffff if none ui8 team; - //std::vector > > * fogOfWarMap; //pointer to team's fog of war std::vector resources; - std::vector heroes; - std::vector towns; - std::vector availableHeroes; //heroes available in taverns - std::vector dwellings; //used for town growth + std::vector > heroes; + std::vector > towns; + std::vector > availableHeroes; //heroes available in taverns + std::vector > dwellings; //used for town growth ui8 enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory ui8 status; //0 - in game, 1 - loser, 2 - winner <- uses EStatus enum @@ -432,24 +433,24 @@ struct DLL_EXPORT CPathsInfo class DLL_EXPORT CGameState { public: - StartInfo* scenarioOps, *initialOpts; //second one is a copy of settings received from pregame (not randomized) + ConstTransitivePtr scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized) CCampaignState *campaign; ui32 seed; ui8 currentPlayer; //ID of player currently having turn BattleInfo *curB; //current battle ui32 day; //total number of days in game - Mapa * map; - std::map players; //ID <-> player state - std::map teams; //ID <-> team state - std::map villages, forts, capitols; //def-info for town graphics + ConstTransitivePtr map; + bmap players; //ID <-> player state + bmap teams; //ID <-> team state + bmap > villages, forts, capitols; //def-info for town graphics CBonusSystemNode globalEffects; struct DLL_EXPORT HeroesPool { - std::map heroesPool; //[subID] - heroes available to buy; NULL if not available - std::map pavailable; // [subid] -> which players can recruit hero (binary flags) + bmap > heroesPool; //[subID] - heroes available to buy; NULL if not available + bmap pavailable; // [subid] -> which players can recruit hero (binary flags) - CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, std::map &available, const CHeroClass *bannedClass = NULL) const; + CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, bmap > &available, const CHeroClass *bannedClass = NULL) const; template void serialize(Handler &h, const int version) { @@ -496,7 +497,7 @@ public: ui8 checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 if no winner bool checkForStandardLoss(ui8 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 - std::map unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns + bmap > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns bool isVisible(int3 pos, int player); bool isVisible(const CGObjectInstance *obj, int player); diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 4cb0ec934..0edfcd8f8 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -266,7 +266,7 @@ DLL_EXPORT void RemoveObject::applyGs( CGameState *gs ) if(obj->ID==HEROI_TYPE) { CGHeroInstance *h = static_cast(obj); - std::vector::iterator nitr = std::find(gs->map->heroes.begin(), gs->map->heroes.end(),h); + std::vector >::iterator nitr = std::find(gs->map->heroes.begin(), gs->map->heroes.end(),h); gs->map->heroes.erase(nitr); int player = h->tempOwner; nitr = std::find(gs->getPlayer(player)->heroes.begin(), gs->getPlayer(player)->heroes.end(), h); diff --git a/lib/map.cpp b/lib/map.cpp index 270c3e832..01e888184 100644 --- a/lib/map.cpp +++ b/lib/map.cpp @@ -516,7 +516,7 @@ Mapa::~Mapa() } delete [] terrain; } - for(std::list::iterator i = events.begin(); i != events.end(); i++) + for(std::list >::iterator i = events.begin(); i != events.end(); i++) delete *i; } @@ -1287,6 +1287,15 @@ void Mapa::readDefInfo( const unsigned char * bufor, int &i) } } +class _HERO_SORTER +{ +public: + bool operator()(const ConstTransitivePtr & a, const ConstTransitivePtr & b) + { + return a->subID < b->subID; + } +}; + void Mapa::readObjects( const unsigned char * bufor, int &i) { int howManyObjs = readNormalNr(bufor,i, 4); i+=4; @@ -1934,7 +1943,7 @@ void Mapa::readObjects( const unsigned char * bufor, int &i) heroes.push_back(static_cast(nobj)); } - std::sort(heroes.begin(), heroes.end(), boost::bind(&CGHeroInstance::subID, _1) < boost::bind(&CGHeroInstance::subID, _2)); + std::sort(heroes.begin(), heroes.end(), _HERO_SORTER()); } void Mapa::readEvents( const unsigned char * bufor, int &i ) diff --git a/lib/map.h b/lib/map.h index b41fc2dda..177c69e45 100644 --- a/lib/map.h +++ b/lib/map.h @@ -269,22 +269,22 @@ struct DLL_EXPORT Mapa : public CMapHeader TerrainTile*** terrain; std::vector rumors; std::vector disposedHeroes; - std::vector predefinedHeroes; - std::vector defy; // list of .def files with definitions from .h3m (may be custom) + std::vector > predefinedHeroes; + std::vector > defy; // list of .def files with definitions from .h3m (may be custom) std::vector allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed std::vector allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed std::vector allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed - std::list events; + std::list > events; int3 grailPos; int grailRadious; std::vector< ConstTransitivePtr > objects; - std::vector heroes; - std::vector towns; + std::vector< ConstTransitivePtr > heroes; + std::vector< ConstTransitivePtr > towns; std::vector< ConstTransitivePtr > artInstances; //stores all artifacts - std::map monsters; - std::map heroesToBeat; + bmap > monsters; + bmap > heroesToBeat; void initFromBytes( const unsigned char * bufor); //creates map from decompressed .h3m data diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 81bcf4d28..5a63667fe 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -933,7 +933,7 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa ssi.creatures = town->creatures; ssi.creatures[CREATURES_PER_TOWN].second.clear();//remove old one - const std::vector &dwellings = gs->getPlayer(town->tempOwner)->dwellings; + const std::vector > &dwellings = gs->getPlayer(town->tempOwner)->dwellings; if (dwellings.empty())//no dwellings - just remove { sendAndApply(&ssi); @@ -1008,7 +1008,7 @@ void CGameHandler::newTurn() else n.specialWeek = NewTurn::NO_ACTION; //don't remove bonuses - std::map pool = gs->hpool.heroesPool; + bmap > pool = gs->hpool.heroesPool; for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) { @@ -1079,7 +1079,7 @@ void CGameHandler::newTurn() // townID, creatureID, amount std::map > newCreas;//creatures that needs to be added by town events - for(std::vector::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns + for(std::vector >::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns { ui8 player = (*j)->tempOwner; if(gs->getDate(1)==7) //first day of week @@ -1176,7 +1176,7 @@ void CGameHandler::newTurn() n2.day = gs->day; n2.resetBuilded = true; - for(std::vector::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns + for(std::vector >::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns { SetAvailableCreatures sac; sac.tid = (**j).id; @@ -3559,7 +3559,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, ui8 player) } - CGHeroInstance *nh = p->availableHeroes[hid]; + const CGHeroInstance *nh = p->availableHeroes[hid]; assert(nh); HeroRecruited hr; @@ -3570,7 +3570,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, ui8 player) sendAndApply(&hr); - std::map pool = gs->unusedHeroesFromPool(); + bmap > pool = gs->unusedHeroesFromPool(); const CGHeroInstance *theOtherHero = p->availableHeroes[!hid]; const CGHeroInstance *newHero = gs->hpool.pickHeroFor(false, player, getNativeTown(player), pool, theOtherHero->type->heroClass); @@ -4700,8 +4700,8 @@ void CGameHandler::checkLossVictory( ui8 player ) } else //player lost -> all his objects become unflagged (neutral) { - std::vector hlp = p->heroes; - for (std::vector::const_iterator i = hlp.begin(); i != hlp.end(); i++) //eliminate heroes + std::vector > hlp = p->heroes; + for (std::vector >::const_iterator i = hlp.begin(); i != hlp.end(); i++) //eliminate heroes removeObject((*i)->id); for (std::vector >::const_iterator i = gs->map->objects.begin(); i != gs->map->objects.end(); i++) //unflag objs