diff --git a/CCallback.cpp b/CCallback.cpp index 62dabb24b..295d5d8fb 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -232,7 +232,7 @@ const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) const //mode = } else //object id { - return static_cast(gs->map->objects[val]); + return static_cast(+gs->map->objects[val]); } return NULL; } @@ -599,7 +599,7 @@ const CGTownInstance *CCallback::battleGetDefendedTown() if(!gs->curB || gs->curB->tid == -1) return NULL; - return static_cast(gs->map->objects[gs->curB->tid]); + return static_cast(+gs->map->objects[gs->curB->tid]); } ui8 CCallback::battleGetWallState(int partOfWall) @@ -705,7 +705,7 @@ std::vector < const CGObjectInstance * > CCallback::getFlaggableObjects(int3 pos std::vector < const CGObjectInstance * > ret; - std::vector < std::pair > & objs = CGI->mh->ttiles[pos.x][pos.y][pos.z].objects; + const std::vector < std::pair > & objs = CGI->mh->ttiles[pos.x][pos.y][pos.z].objects; for(size_t b=0; btempOwner!=254 && !((objs[b].first->defInfo->blockMap[pos.y - objs[b].first->pos.y + 5] >> (objs[b].first->pos.x - pos.x)) & 1)) diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index 6e38f6957..d36a4b7b7 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -56,7 +56,7 @@ int hordeToDwellingID(int bid)//helper, converts horde buiding ID into correspon } } -CBuildingRect::CBuildingRect(Structure *Str) +CBuildingRect::CBuildingRect(const Structure *Str) :CShowableAnim(0, 0, Str->defName, CShowableAnim::FLAG_BASE), moi(false), str(Str) { @@ -901,7 +901,7 @@ void CCastleInterface::recreateBuildings() { if(CGI->townh->structures[town->subID].find(*i)!=CGI->townh->structures[town->subID].end()) //we have info about that structure { - Structure * st = CGI->townh->structures[town->subID][*i]; + const Structure * st = CGI->townh->structures[town->subID][*i]; if(st->group<0) //no group - just add it { buildings.push_back(new CBuildingRect(st)); @@ -1777,7 +1777,7 @@ void CFortScreen::draw( CCastleInterface * owner, bool first) for(int i=0;i state; //don't touch it in client's code +// public: +// ConstTransitivePtr arth; +// ConstTransitivePtr heroh; +// ConstTransitivePtr creh; +// ConstTransitivePtr spellh; +// ConstTransitivePtr objh; +// ConstTransitivePtr dobjinfo; +// ConstTransitivePtr generaltexth; diff --git a/client/CHeroWindow.cpp b/client/CHeroWindow.cpp index e0b404630..703becbb2 100644 --- a/client/CHeroWindow.cpp +++ b/client/CHeroWindow.cpp @@ -70,7 +70,6 @@ CHeroWindow::CHeroWindow(const CGHeroInstance *hero) { OBJ_CONSTRUCTION_CAPTURING_ALL; garr = NULL; - curBack = NULL; curHero = NULL; player = hero->tempOwner; @@ -181,7 +180,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) { delete garr; OBJ_CONSTRUCTION_CAPTURING_ALL; - garr = new CGarrisonInt(80, 493, 8, Point(), curBack->bg, Point(16,486), curHero); + garr = new CGarrisonInt(80, 493, 8, Point(), background->bg, Point(16,486), curHero); } AdventureMapButton * split = NULL; @@ -320,10 +319,10 @@ void CHeroWindow::showAll(SDL_Surface * to) } //morale and luck printing - blitAt(graphics->luck42->ourImages[curHero->LuckVal()+3].bitmap, 239, 182, to); - blitAt(graphics->morale42->ourImages[curHero->MoraleVal()+3].bitmap, 181, 182, to); + blitAtLoc(graphics->luck42->ourImages[curHero->LuckVal()+3].bitmap, 239, 182, to); + blitAtLoc(graphics->morale42->ourImages[curHero->MoraleVal()+3].bitmap, 181, 182, to); - blitAt(flags->ourImages[player].bitmap, 606, 8, to); + blitAtLoc(flags->ourImages[player].bitmap, 606, 8, to); //hero list blitting @@ -334,7 +333,7 @@ void CHeroWindow::showAll(SDL_Surface * to) // Only display heroes that are not in garrison continue; - blitAt(graphics->portraitSmall[cur->portrait], 611, 87+pos*54, to); + blitAtLoc(graphics->portraitSmall[cur->portrait], 611, 87+pos*54, to); //printing yellow border if(cur->name == curHero->name) { @@ -354,13 +353,13 @@ void CHeroWindow::showAll(SDL_Surface * to) //secondary skills for(size_t v=0; vsecSkills.size()); ++v) { - blitAt(graphics->abils44->ourImages[curHero->secSkills[v].first*3+3+curHero->secSkills[v].second-1].bitmap, v%2 ? 161 : 18, 276 + 48 * (v/2), to); + blitAtLoc(graphics->abils44->ourImages[curHero->secSkills[v].first*3+3+curHero->secSkills[v].second-1].bitmap, v%2 ? 161 : 18, 276 + 48 * (v/2), to); printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], v%2 ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, zwykly, to); printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], v%2 ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, zwykly, to); } //printing special ability - blitAt(graphics->un44->ourImages[curHero->subID].bitmap, 18, 180, to); + blitAtLoc(graphics->un44->ourImages[curHero->subID].bitmap, 18, 180, to); printAtLoc(CGI->generaltexth->jktexts[5].substr(1, CGI->generaltexth->jktexts[5].size()-2), 69, 183, FONT_SMALL, tytulowy, to); printAtLoc(CGI->generaltexth->hTxts[curHero->subID].bonusName, 69, 205, FONT_SMALL, zwykly, to); diff --git a/client/CHeroWindow.h b/client/CHeroWindow.h index f1eae3bd9..9714a3a19 100644 --- a/client/CHeroWindow.h +++ b/client/CHeroWindow.h @@ -42,7 +42,7 @@ class CHeroWindow: public CWindowWithGarrison { enum ELabel {}; std::map labels; - CPicture *background, *curBack; + CPicture *background; CGStatusBar * ourBar; //heroWindow's statusBar //general graphics diff --git a/client/CKingdomInterface.cpp b/client/CKingdomInterface.cpp index 28a4e9c79..d77490ce6 100644 --- a/client/CKingdomInterface.cpp +++ b/client/CKingdomInterface.cpp @@ -254,7 +254,7 @@ void CKingdomInterface::showAll( SDL_Surface * to/*=NULL*/) ObjList[i]->hoverText = ""; int skipCount=0, curPos=objPos<0?(-objPos):0; - for (std::map >::iterator it=objList.begin(); it!= objList.end(); it++) + for (std::map >::iterator it=objList.begin(); it!= objList.end(); it++) { if (skipCount > objList; //dwelling ID, count, hover text + std::map > objList; //dwelling ID, count, hover text std::vector ObjList;//list of dwellings AdventureMapButton* ObjUp, *ObjDown, *ObjTop, *ObjBottom;//buttons for dwellings list diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index 49fe6a104..790526538 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -419,7 +419,10 @@ void CMapHandler::init() // top_tile top left tile to draw. Not necessarily visible. // extRect, extRect = map window on screen // moveX, moveY: when a hero is in movement indicates how to shift the map. Range is -31 to + 31. -void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode) +void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, + const std::vector< std::vector< std::vector > > * visibilityMap, + bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, + int moveX, int moveY, bool puzzleMode) const { // Width and height of the portion of the map to process. Units in tiles. unsigned int dx = tilesW; @@ -778,7 +781,7 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vect SDL_SetClipRect(extSurf, &prevClip); //restoring clip_rect } -std::pair CMapHandler::getVisBitmap( const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap ) +std::pair CMapHandler::getVisBitmap( const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap ) const { static const int visBitmaps[256] = {-1, 34, -1, 4, 22, 22, 4, 4, 36, 36, 38, 38, 47, 47, 38, 38, 3, 25, 12, 12, 3, 25, 12, 12, 9, 9, 6, 6, 9, 9, 6, 6, 35, 34, 4, 4, 22, 22, 4, 4, 36, 36, 38, 38, 47, 47, 38, 38, 26, 49, 28, 28, 26, 49, 28, diff --git a/client/mapHandler.h b/client/mapHandler.h index 0c64fa23f..00ca0ef69 100644 --- a/client/mapHandler.h +++ b/client/mapHandler.h @@ -102,7 +102,7 @@ public: CMapHandler(); //c-tor ~CMapHandler(); //d-tor - std::pair getVisBitmap(const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap); //returns appropriate bitmap and info if alpha blitting is necessary + std::pair getVisBitmap(const int3 & pos, const std::vector< std::vector< std::vector > > & visibilityMap) const; //returns appropriate bitmap and info if alpha blitting is necessary std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position void getTerrainDescr(const int3 &pos, std::string & out, bool terName); //if tername == false => empty string when tile is clear @@ -118,7 +118,7 @@ public: void roadsRiverTerrainInit(); void prepareFOWDefs(); - void terrainRect(int3 top_tile, unsigned char anim, const std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode); + void terrainRect(int3 top_tile, unsigned char anim, const std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode) const; void updateWater(); unsigned char getHeroFrameNum(unsigned char dir, bool isMoving) const; //terrainRect helper function void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper diff --git a/global.h b/global.h index 2f192a15f..9d3531055 100644 --- a/global.h +++ b/global.h @@ -91,6 +91,7 @@ const int HEROI_TYPE = 34, CREI_TYPE = 54, EVENTI_TYPE = 26; +const int CRE_LEVELS = 10; const int F_NUMBER = 9; //factions (town types) quantity const int PLAYER_LIMIT = 8; //player limit per map const int ALL_PLAYERS = 255; //bitfield @@ -166,6 +167,28 @@ enum EAlignment template char (&_ArrayCountObj(const T (&)[N]))[N]; #define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) + + +//a normal std::map with consted operator[] for sanity +template +class bmap : public std::map +{ +public: + const ValT & operator[](KeyT key) const + { + const_iterator it = find(*this, key); + return it->second; + } + ValT & operator[](KeyT key) + { + return static_cast &>(*this)[key]; + } + template void serialize(Handler &h, const int version) + { + h & static_cast &>(*this); + } +}; + namespace vstd { template @@ -178,6 +201,11 @@ namespace vstd { return c.find(i)!=c.end(); } + template + bool contains(const bmap & c, const Item2 &i) //returns true if map c contains item i + { + return c.find(i)!=c.end(); + } template typename Container2::iterator findFirstNot(Container1 &c1, Container2 &c2)//returns first element of c2 not present in c1 { diff --git a/hch/CArtHandler.cpp b/hch/CArtHandler.cpp index f9972ba10..89c947ca5 100644 --- a/hch/CArtHandler.cpp +++ b/hch/CArtHandler.cpp @@ -12,6 +12,7 @@ #include #include #include "../lib/VCMI_Lib.h" +#include "CSpellHandler.h" extern CLodHandler *bitmaph; using namespace boost::assign; @@ -171,6 +172,10 @@ int CArtifact::getArtClassSerial() const return -1; } +std::string CArtifact::nodeName() const +{ + return "Artifact: " + Name(); +} // void CArtifact::getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const // { // //combined artifact carries bonuses from its parts @@ -199,7 +204,7 @@ CArtHandler::CArtHandler() CArtHandler::~CArtHandler() { - for (std::vector::iterator it = artifacts.begin(); it != artifacts.end(); ++it) + for (std::vector< ConstTransitivePtr >::iterator it = artifacts.begin(); it != artifacts.end(); ++it) { delete (*it)->constituents; delete (*it)->constituentOf; @@ -436,7 +441,7 @@ void CArtHandler::erasePickedArt (si32 id) } ui16 CArtHandler::getRandomArt(int flags) { - std::vector out; + std::vector > out; getAllowed(out, flags); ui16 id = out[ran() % out.size()]->id; erasePickedArt (id); @@ -444,12 +449,12 @@ ui16 CArtHandler::getRandomArt(int flags) } ui16 CArtHandler::getArtSync (ui32 rand, int flags) { - std::vector out; + std::vector > out; getAllowed(out, flags); CArtifact *art = out[rand % out.size()]; return art->id; } -void CArtHandler::getAllowed(std::vector &out, int flags) +void CArtHandler::getAllowed(std::vector > &out, int flags) { if (flags & CArtifact::ART_TREASURE) getAllowedArts (out, &treasures, CArtifact::ART_TREASURE); @@ -465,7 +470,7 @@ void CArtHandler::getAllowed(std::vector &out, int flags) std::fill_n (out.begin(), 64, artifacts[2]); //magic } } -void CArtHandler::getAllowedArts(std::vector &out, std::vector *arts, int flag) +void CArtHandler::getAllowedArts(std::vector > &out, std::vector *arts, int flag) { if (arts->empty()) //restock avaliable arts { @@ -854,3 +859,39 @@ void CArtHandler::initAllowedArtifactsList(const std::vector &allowed) allowedArtifacts.push_back(artifacts[i]); } } + +CArtifactInstance::CArtifactInstance() +{ + init(); +} + +CArtifactInstance::CArtifactInstance( CArtifact *Art) +{ + init(); + setType(Art); + +} + +void CArtifactInstance::setType( CArtifact *Art ) +{ + art = Art; + attachTo(Art); +} + +std::string CArtifactInstance::nodeName() const +{ + return "Artifact instance of " + (art ? art->Name() : std::string("uninitialized")) + " type"; +} + +CArtifactInstance * CArtifactInstance::createScroll( const CSpell *s) +{ + CArtifactInstance *ret = new CArtifactInstance(VLC->arth->artifacts[93]); + Bonus *b = new Bonus(Bonus::PERMANENT, Bonus::SPELL, Bonus::ARTIFACT_INSTANCE, -1, s->id ); + ret->addNewBonus(b); + return ret; +} + +void CArtifactInstance::init() +{ + art = NULL; +} \ No newline at end of file diff --git a/hch/CArtHandler.h b/hch/CArtHandler.h index d45b58e7c..087545ab6 100644 --- a/hch/CArtHandler.h +++ b/hch/CArtHandler.h @@ -4,8 +4,8 @@ #include "../lib/HeroBonus.h" #include #include -#include -#include + +#include "../lib/ConstTransitivePtr.h" /* * CArtHandler.h, part of VCMI engine @@ -36,6 +36,7 @@ public: virtual void SetProperty (int mod){}; virtual void Init(){}; int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other + std::string nodeName() const OVERRIDE; ui32 price; std::vector possibleSlots; //ids of slots where artifact can be placed @@ -57,6 +58,28 @@ public: //void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const; }; +class DLL_EXPORT CArtifactInstance : public CBonusSystemNode +{ +public: + ConstTransitivePtr art; + si32 id; //id of the instance + + CArtifactInstance(); + CArtifactInstance(CArtifact *Art); + + void init(); + std::string nodeName() const OVERRIDE; + void setType(CArtifact *Art); + + template void serialize(Handler &h, const int version) + { + h & static_cast(*this); + h & art & id; + } + + static CArtifactInstance *createScroll(const CSpell *s); +}; + class DLL_EXPORT IModableArt : public CArtifact //artifact which can have different properties, such as scroll or banner { //used only for dynamic cast :P public: @@ -118,7 +141,7 @@ class DLL_EXPORT CArtHandler //handles artifacts void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER, ILimiter * limiter = NULL); public: std::vector treasures, minors, majors, relics; - std::vector artifacts; + std::vector< ConstTransitivePtr > artifacts; std::vector allowedArtifacts; std::set bigArtifacts; // Artifacts that cannot be moved to backpack, e.g. war machines. std::map modableArtifacts; //1-scroll, 2-banner, 3-commander art with progressive bonus @@ -130,8 +153,8 @@ public: void clearHlpLists(); ui16 getRandomArt (int flags); ui16 getArtSync (ui32 rand, int flags); - void getAllowedArts(std::vector &out, std::vector *arts, int flag); - void getAllowed(std::vector &out, int flags); + void getAllowedArts(std::vector > &out, std::vector *arts, int flag); + void getAllowed(std::vector > &out, int flags); void erasePickedArt (si32 id); bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();} void equipArtifact (std::map &artifWorn, ui16 slotID, const CArtifact* art); diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index 452807af6..b522d655b 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -463,8 +463,8 @@ void CCreatureHandler::loadCreatures() } ifs.close(); ifs.clear(); - for(i=1;i<=10;i++) - levelCreatures.insert(std::pair >(i,std::vector())); + for(i = 1; i <= CRE_LEVELS; i++) + levelCreatures[i]; tlog5 << "\t\tReading config/monsters.txt" << std::endl; ifs.open(DATA_DIR "/config/monsters.txt"); diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index 276ea2ba9..6f314e31e 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -10,6 +10,7 @@ #include "../lib/HeroBonus.h" #include "../lib/CGameState.h" #include "../lib/CCreatureSet.h" +#include "../lib/ConstTransitivePtr.h" /* * CCreatureHandler.h, part of VCMI engine @@ -104,11 +105,11 @@ public: CBonusSystemNode *globalEffects; std::set notUsedMonsters; std::set doubledCreatures; //they get double week - std::vector creatures; //creature ID -> creature info - std::map > levelCreatures; //level -> list of creatures - std::map nameToID; - std::map idToProjectile; - std::map idToProjectileSpin; //if true, appropriate projectile is spinning during flight + std::vector > creatures; //creature ID -> creature info + bmap > > levelCreatures; //level -> list of creatures + bmap nameToID; + bmap idToProjectile; + bmap idToProjectileSpin; //if true, appropriate projectile is spinning during flight std::vector factionAlignments; //1 for good, 0 for neutral and -1 for evil with faction ID as index int factionToTurretCreature[F_NUMBER]; //which creature's animation should be used to dispaly creature in turret while siege diff --git a/hch/CHeroHandler.h b/hch/CHeroHandler.h index 7010d352f..192833a6c 100644 --- a/hch/CHeroHandler.h +++ b/hch/CHeroHandler.h @@ -5,6 +5,8 @@ #include #include +#include "../lib/ConstTransitivePtr.h" + /* * CHeroHandler.h, part of VCMI engine * @@ -118,7 +120,7 @@ const int PUZZLES_PER_FACTION = 48; class DLL_EXPORT CHeroHandler { public: - std::vector heroes; //changed from nodrze + std::vector< ConstTransitivePtr > heroes; //changed from nodrze std::vector heroClasses; std::vector expPerLevel; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value diff --git a/hch/CMusicHandler.cpp b/hch/CMusicHandler.cpp index b228e00d4..ba64614d5 100644 --- a/hch/CMusicHandler.cpp +++ b/hch/CMusicHandler.cpp @@ -148,7 +148,7 @@ soundBase::soundID CSoundHandler::getSoundID(std::string &fileName) return it->second; } -void CSoundHandler::initCreaturesSounds(std::vector &creatures) +void CSoundHandler::initCreaturesSounds(std::vector > &creatures) { tlog5 << "\t\tReading config/cr_sounds.txt" << std::endl; std::ifstream ifs(DATA_DIR "/config/cr_sounds.txt"); @@ -172,7 +172,7 @@ void CSoundHandler::initCreaturesSounds(std::vector &creatures) { int id = -1; - std::map::iterator i = CGI->creh->nameToID.find(cname); + bmap::const_iterator i = CGI->creh->nameToID.find(cname); if(i != CGI->creh->nameToID.end()) id = i->second; else @@ -238,7 +238,7 @@ void CSoundHandler::initSpellsSounds(std::vector &spells) if (str.good() || (str.eof() && soundfile != "")) { - CSpell &s = CGI->spellh->spells[spellid]; + const CSpell &s = CGI->spellh->spells[spellid]; if (s.soundID != soundBase::invalid) tlog1 << "Spell << " << spellid << " already has a sound" << std::endl; diff --git a/hch/CMusicHandler.h b/hch/CMusicHandler.h index 699d3ab89..794f70847 100644 --- a/hch/CMusicHandler.h +++ b/hch/CMusicHandler.h @@ -80,7 +80,7 @@ public: void init(); void release(); - void initCreaturesSounds(std::vector &creatures); + void initCreaturesSounds(std::vector > &creatures); void initSpellsSounds(std::vector &spells); void setVolume(unsigned int percent); diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 1faae2d43..3a4f338a4 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -1105,7 +1105,7 @@ void CGHeroInstance::initObj() break; case 9://upgrade creatures { - std::vector* creatures = &VLC->creh->creatures; + std::vector< ConstTransitivePtr >* creatures = &VLC->creh->creatures; bonus->type = Bonus::SPECIAL_UPGRADE; bonus->subtype = it->subtype; //base id bonus->additionalInfo = it->additionalinfo; //target id @@ -1161,7 +1161,7 @@ void CGHeroInstance::UpdateSpeciality() { if (speciality.growthsWithLevel) { - std::vector* creatures = &VLC->creh->creatures; + std::vector< ConstTransitivePtr > & creatures = VLC->creh->creatures; BOOST_FOREACH(Bonus *it, speciality.bonuses) { @@ -1171,14 +1171,14 @@ void CGHeroInstance::UpdateSpeciality() it->val = (speciality.valOfBonuses(Bonus::SPECIAL_SECONDARY_SKILL, it->subtype) * level); break; //use only hero skills as bonuses to avoid feedback loop case Bonus::PRIMARY_SKILL: //for crearures, that is - int creLevel = (*creatures)[it->additionalInfo]->level; + int creLevel = creatures[it->additionalInfo]->level; if(!creLevel) { if(it->additionalInfo == 146) creLevel = 5; //treat ballista as 5-level else { - tlog2 << "Warning: unknown level of " << (*creatures)[it->additionalInfo]->namePl << std::endl; + tlog2 << "Warning: unknown level of " << creatures[it->additionalInfo]->namePl << std::endl; continue; } } @@ -1188,10 +1188,10 @@ void CGHeroInstance::UpdateSpeciality() switch (it->subtype) { case PrimarySkill::ATTACK: - param = (*creatures)[it->additionalInfo]->attack; + param = creatures[it->additionalInfo]->attack; break; case PrimarySkill::DEFENSE: - param = (*creatures)[it->additionalInfo]->defence; + param = creatures[it->additionalInfo]->defence; break; } it->val = ceil(param * (1 + primSkillModifier)) - param; //yep, overcomplicated but matches original @@ -3014,7 +3014,7 @@ int CGCreature::takenAction(const CGHeroInstance *h, bool allowJoin) const std::set myKindCres; //what creatures are the same kind as we myKindCres.insert(subID); //we myKindCres.insert(VLC->creh->creatures[subID]->upgrades.begin(),VLC->creh->creatures[subID]->upgrades.end()); //our upgrades - for(std::vector::iterator i=VLC->creh->creatures.begin(); i!=VLC->creh->creatures.end(); i++) + for(std::vector >::iterator i=VLC->creh->creatures.begin(); i!=VLC->creh->creatures.end(); i++) if(vstd::contains((*i)->upgrades, (ui32) id)) //it's our base creatures myKindCres.insert((*i)->idNumber); @@ -3616,9 +3616,12 @@ void CGArtifact::onHeroVisit( const CGHeroInstance * h ) const } break; case 93: - iw.components.push_back (Component(Component::SPELL, spell,0,0)); - iw.text.addTxt (MetaString::ADVOB_TXT,135); - iw.text.addReplacement(MetaString::SPELL_NAME, spell); + { + int spellID = art->getBonus(Selector::type(Bonus::SPELL))->subtype; + iw.components.push_back (Component(Component::SPELL, spellID,0,0)); + iw.text.addTxt (MetaString::ADVOB_TXT,135); + iw.text.addReplacement(MetaString::SPELL_NAME, spellID); + } break; } @@ -3648,7 +3651,7 @@ void CGArtifact::pick(const CGHeroInstance * h) const if (ID == 93) //scroll { NewArtifact na; - na.value = spell; + //na.value = spell; na.artid = subID; cb->sendAndApply(&na); cb->giveNewArtifact(h->id, -2); diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 131f0d247..0c76c3aa8 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -23,6 +23,7 @@ * */ +class CArtifactInstance; struct MetaString; struct BattleInfo; class IGameCallback; @@ -266,6 +267,10 @@ public: ui8 inTownGarrison; // if hero is in town garrison const CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison const CGBoat *boat; //set to CGBoat when sailing + + std::vector gartifacts; //hero's artifacts from bag + std::map gartifWorn; //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::vector artifacts; //hero's artifacts from bag std::map artifWorn; //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::set spells; //known spells (spell IDs) @@ -764,8 +769,9 @@ public: class DLL_EXPORT CGArtifact : public CArmedInstance { public: + CArtifactInstance *art; + std::string message; - ui32 spell; //if it's spell scroll void onHeroVisit(const CGHeroInstance * h) const; void fightForArt(ui32 agreed, const CGHeroInstance *h) const; void endBattle(BattleResult *result, const CGHeroInstance *h) const; @@ -775,7 +781,7 @@ public: template void serialize(Handler &h, const int version) { h & static_cast(*this); - h & message & spell; + h & message & art; } }; diff --git a/hch/CSpellHandler.h b/hch/CSpellHandler.h index c8e38b328..a7ab9a75f 100644 --- a/hch/CSpellHandler.h +++ b/hch/CSpellHandler.h @@ -41,7 +41,7 @@ public: std::vector range; //description of spell's range in SRSL by magic school level std::set rangeInHexes(unsigned int centralHex, ui8 schoolLvl ) const; //convert range to specific hexes si16 mainEffectAnim; //main spell effect animation, in AC format (or -1 when none) - soundBase::soundID soundID; // spell sound id + mutable soundBase::soundID soundID; // spell sound id template void serialize(Handler &h, const int version) { diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index d41a58d56..306f80a52 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1157,7 +1157,7 @@ CGHeroInstance *CGameState::getHero(int objid) { if(objid<0 || objid>=map->objects.size() || map->objects[objid]->ID!=HEROI_TYPE) return NULL; - return static_cast(map->objects[objid]); + return static_cast(+map->objects[objid]); } const CGHeroInstance * CGameState::getHero( int objid ) const @@ -1247,13 +1247,13 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) { for(unsigned int i=0;iobjects.size();i++) { - if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) + if(map->objects[i]->ID==77 && dynamic_cast(+map->objects[i])->identifier == info->identifier) { randomizeObject(map->objects[i]); //we have to randomize the castle first faction = map->objects[i]->subID; break; } - else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(map->objects[i])->identifier == info->identifier) + else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(+map->objects[i])->identifier == info->identifier) { faction = map->objects[i]->subID; break; @@ -1288,13 +1288,13 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) { for(unsigned int i=0;iobjects.size();i++) { - if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) + if(map->objects[i]->ID==77 && dynamic_cast(+map->objects[i])->identifier == info->identifier) { randomizeObject(map->objects[i]); //we have to randomize the castle first faction = map->objects[i]->subID; break; } - else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(map->objects[i])->identifier == info->identifier) + else if(map->objects[i]->ID==TOWNI_TYPE && dynamic_cast(+map->objects[i])->identifier == info->identifier) { faction = map->objects[i]->subID; break; @@ -2180,7 +2180,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) { map->objects[i]->initObj(); if(map->objects[i]->ID == 62) //prison also needs to initialize hero - static_cast(map->objects[i])->initHero(); + static_cast(+map->objects[i])->initHero(); } CGTeleport::postInit(); //pairing subterranean gates } @@ -2242,7 +2242,7 @@ int CGameState::battleGetBattlefieldType(int3 tile) if(dynamic_cast(t.visitableObjects.front())) return 12; - const std::vector & objs = map->objects; + const std::vector > & objs = map->objects; for(int g=0; gpos.x - tile.x < 0 || objs[g]->pos.x - tile.x >= 8 @@ -3789,7 +3789,7 @@ int CGameState::victoryCheck( ui8 player ) const const CArmedInstance *ai = NULL; if(map->objects[i] && map->objects[i]->tempOwner == player //object controlled by player - && (ai = dynamic_cast(map->objects[i]))) //contains army + && (ai = dynamic_cast(+map->objects[i]))) //contains army { for(TSlots::const_iterator i=ai->Slots().begin(); i!=ai->Slots().end(); ++i) //iterate through army if(i->second->type->idNumber == map->victoryCondition.ID) //it's searched creature diff --git a/lib/Connection.cpp b/lib/Connection.cpp index 8be453501..f2e15b53c 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -405,6 +405,6 @@ void CSerializer::addStdVecItems(CGameState *gs, LibClasses *lib) registerVectoredType(&lib->heroh->heroes, &CHero::ID); registerVectoredType(&lib->creh->creatures, &CCreature::idNumber); registerVectoredType(&lib->arth->artifacts, &CArtifact::id); - registerVectoredType(&gs->map->artInstances, &IModableArt::ID); + registerVectoredType(&gs->map->artInstances, &CArtifactInstance::id); smartVectorMembersSerialization = true; } diff --git a/lib/Connection.h b/lib/Connection.h index 8be1f008c..2d20d14ea 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -23,6 +23,8 @@ #include #include +#include "ConstTransitivePtr.h" + const ui32 version = 727; class CConnection; class CGObjectInstance; @@ -232,10 +234,10 @@ struct SerializationLevel template struct VectorisedObjectInfo { - const std::vector *vector; //pointer to the appropriate vector + const std::vector > *vector; //pointer to the appropriate vector const si32 T::*idPtr; //pointer to the field representing the position in the vector - VectorisedObjectInfo(const std::vector *Vector, const si32 T::*IdPtr) + VectorisedObjectInfo(const std::vector< ConstTransitivePtr > *Vector, const si32 T::*IdPtr) :vector(Vector), idPtr(IdPtr) { } @@ -259,6 +261,11 @@ public: { vectors[&typeid(T)] = VectorisedObjectInfo(Vector, IdPtr); } + template + void registerVectoredType(const std::vector > *Vector, const si32 T::*IdPtr) + { + vectors[&typeid(T)] = VectorisedObjectInfo(Vector, IdPtr); + } template const VectorisedObjectInfo *getVectorisedTypeInfo() @@ -290,7 +297,7 @@ public: assert(oInfo.vector); assert(oInfo.vector->size() > id); - return (*oInfo.vector)[id]; + return const_cast(+(*oInfo.vector)[id]); } template diff --git a/lib/ConstTransitivePtr.h b/lib/ConstTransitivePtr.h index e05909b23..d4ba296bc 100644 --- a/lib/ConstTransitivePtr.h +++ b/lib/ConstTransitivePtr.h @@ -9,10 +9,26 @@ public: : ptr(Ptr) {} + const T& operator*() const + { + return *ptr; + } + T& operator*() + { + return *ptr; + } operator const T*() const { return ptr; } + T* operator+() + { + return ptr; + } + const T* operator+() const + { + return ptr; + } operator T*() { return ptr; diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index 39875844e..6e7cf4691 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -164,6 +164,11 @@ Bonus * CBonusSystemNode::getBonus(const CSelector &selector) return NULL; } +const Bonus * CBonusSystemNode::getBonus( const CSelector &selector ) const +{ + return (const_cast(this))->getBonus(selector); +} + void CBonusSystemNode::getModifiersWDescr(TModDescr &out, Bonus::BonusType type, int subtype /*= -1 */) const { getModifiersWDescr(out, Selector::typeSybtype(type, subtype)); diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 3e8fb7c49..9bae1552f 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -184,6 +184,7 @@ struct DLL_EXPORT Bonus enum BonusSource { ARTIFACT, + ARTIFACT_INSTANCE, OBJECT, CASTED_SPELL, CREATURE_ABILITY, @@ -404,6 +405,7 @@ public: ui16 MaxHealth() const; //get max HP of stack with all modifiers + const Bonus *getBonus(const CSelector &selector) const; //non-const interface void getParents(TNodes &out); //retrieves list of parent nodes (nodes to inherit bonuses from), source is the prinary asker Bonus *getBonus(const CSelector &selector); diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index ee171dbfa..e1b4b08a9 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -54,7 +54,7 @@ const CGTownInstance* IGameCallback::getTown(int objid) { const CGObjectInstance *obj = getObj(objid, false); if(obj) - return dynamic_cast(gs->map->objects[objid]); + return dynamic_cast(+gs->map->objects[objid]); else return NULL; } diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index b4f86f08e..5520f288a 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -413,7 +413,7 @@ DLL_EXPORT void RazeStructures::applyGs( CGameState *gs ) } DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs ) { - CGDwelling *dw = dynamic_cast(gs->map->objects[tid]); + CGDwelling *dw = dynamic_cast(+gs->map->objects[tid]); assert(dw); dw->creatures = creatures; } @@ -581,28 +581,28 @@ DLL_EXPORT void NewObject::applyGs( CGameState *gs ) } DLL_EXPORT void NewArtifact::applyGs( CGameState *gs ) { - IModableArt * art; - - std::map::iterator itr = VLC->arth->modableArtifacts.find(artid); - switch (itr->second) - { - case 1: - art = new CScroll; - break; - case 2: - art = new CCustomizableArt; - break; - case 3: - art = new CCommanderArt; - break; - default: - tlog1<<"unhandled customizable artifact!\n"; - }; - *art = *static_cast(VLC->arth->artifacts[artid]); //copy properties - art->ID = gs->map->artInstances.size(); - art->SetProperty (value); //init scroll, banner, commander art - art->Init(); //set bonuses for new instance - gs->map->artInstances.push_back(art); +// IModableArt * art; +// +// std::map::iterator itr = VLC->arth->modableArtifacts.find(artid); +// switch (itr->second) +// { +// case 1: +// art = new CScroll; +// break; +// case 2: +// art = new CCustomizableArt; +// break; +// case 3: +// art = new CCommanderArt; +// break; +// default: +// tlog1<<"unhandled customizable artifact!\n"; +// }; +// *art = *static_cast(+VLC->arth->artifacts[artid]); //copy properties +// art->ID = gs->map->artInstances.size(); +// art->SetProperty (value); //init scroll, banner, commander art +// art->Init(); //set bonuses for new instance +// gs->map->artInstances.push_back(art); } DLL_EXPORT const CStackInstance * StackLocation::getStack() @@ -687,7 +687,7 @@ DLL_EXPORT void SetAvailableArtifacts::applyGs( CGameState *gs ) { if(id >= 0) { - if(CGBlackMarket *bm = dynamic_cast(gs->map->objects[id])) + if(CGBlackMarket *bm = dynamic_cast(+gs->map->objects[id])) { bm->artifacts = arts; } diff --git a/lib/map.cpp b/lib/map.cpp index 1bbd11ae8..c032268d4 100644 --- a/lib/map.cpp +++ b/lib/map.cpp @@ -11,6 +11,7 @@ #include "../hch/CCreatureHandler.h" #include #include +#include "../hch/CSpellHandler.h" /* * map.cpp, part of VCMI engine @@ -1558,11 +1559,24 @@ void Mapa::readObjects( const unsigned char * bufor, int &i) } i+=4; } + + CArtifactInstance *innerArt = NULL; if(defInfo->id==93) { - art->spell = readNormalNr(bufor,i); + int spellID = readNormalNr(bufor,i); i+=4; + innerArt = CArtifactInstance::createScroll(&VLC->spellh->spells[spellID]); } + else if(art->ID == 5) //specific artifact + { + innerArt = new CArtifactInstance(VLC->arth->artifacts[art->subID]); + } + else + { + innerArt = new CArtifactInstance(); + } + art->art = innerArt; + addNewArtifactInstance(innerArt); break; } case 76: case 79: //random resource; resource @@ -2087,6 +2101,12 @@ void Mapa::checkForObjectives() } } +void Mapa::addNewArtifactInstance( CArtifactInstance *art ) +{ + art->id = artInstances.size(); + artInstances.push_back(art); +} + LossCondition::LossCondition() { obj = NULL; diff --git a/lib/map.h b/lib/map.h index f73f43e8e..b41fc2dda 100644 --- a/lib/map.h +++ b/lib/map.h @@ -14,6 +14,8 @@ #include "../hch/CDefObjInfoHandler.h" #endif +#include "ConstTransitivePtr.h" + /* * map.h, part of VCMI engine * @@ -24,6 +26,7 @@ * */ +class CArtifactInstance; class CGDefInfo; class CGObjectInstance; class CGHeroInstance; @@ -276,10 +279,10 @@ struct DLL_EXPORT Mapa : public CMapHeader int3 grailPos; int grailRadious; - std::vector objects; + std::vector< ConstTransitivePtr > objects; std::vector heroes; std::vector towns; - std::vector artInstances; //stores single scrolls + std::vector< ConstTransitivePtr > artInstances; //stores all artifacts std::map monsters; std::map heroesToBeat; @@ -298,7 +301,7 @@ struct DLL_EXPORT Mapa : public CMapHeader int loadSeerHut( const unsigned char * bufor, int i, CGObjectInstance *& nobj); void checkForObjectives(); - + void addNewArtifactInstance(CArtifactInstance *art); void addBlockVisTiles(CGObjectInstance * obj); void removeBlockVisTiles(CGObjectInstance * obj, bool total=false); Mapa(std::string filename); //creates map structure from .h3m file @@ -411,9 +414,9 @@ struct DLL_EXPORT Mapa : public CMapHeader { if(!objects[i]) continue; if(objects[i]->ID == HEROI_TYPE) - heroes.push_back(static_cast(objects[i])); + heroes.push_back(static_cast(+objects[i])); else if(objects[i]->ID == TOWNI_TYPE) - towns.push_back(static_cast(objects[i])); + towns.push_back(static_cast(+objects[i])); addBlockVisTiles(objects[i]); //recreate blockvis map } diff --git a/nodrze.h b/nodrze.h index 14a06abb6..66fe685df 100644 --- a/nodrze.h +++ b/nodrze.h @@ -126,7 +126,7 @@ public: bool operator+=(T * co); //add bool operator+=(T co); //add bool operator-=(T co); //remove - bool operator-=(T * co); //remove + bool operator-=(T * co); //ve T* operator%(T * co); // search and return pointer bool operator&(T co); // check if exist bool operator&(T * co); // check if exist diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index cbb7d9de7..5ddff8c00 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -199,7 +199,7 @@ void CGameHandler::levelUpHero(int ID, int skill) void CGameHandler::levelUpHero(int ID) { - CGHeroInstance *hero = static_cast(gs->map->objects[ID]); + CGHeroInstance *hero = static_cast(+gs->map->objects[ID]); if (hero->exp < VLC->heroh->reqExp(hero->level+1)) // no more level-ups return; @@ -2198,49 +2198,49 @@ void CGameHandler::giveHeroArtifact(int artid, int hid, int position) //pos==-1 } void CGameHandler::giveNewArtifact(int hid, int position) { - const CGHeroInstance* h = getHero(hid); - CArtifact * art = gs->map->artInstances.back(); //we use it only to immediatelly equip new artifact - - SetHeroArtifacts sha; - sha.hid = hid; - sha.artifacts = h->artifacts; - sha.artifWorn = h->artifWorn; - - if(position<0) - { - if(position == -2) - { - int i; - for(i=0; ipossibleSlots.size(); i++) //try to put artifact into first available slot - { - if( !vstd::contains(sha.artifWorn, art->possibleSlots[i]) ) - { - //we've found a free suitable slot - VLC->arth->equipArtifact(sha.artifWorn, art->possibleSlots[i], art); - break; - } - } - if(i == art->possibleSlots.size() && !art->isBig()) //if haven't find proper slot, use backpack or discard big artifact - sha.artifacts.push_back(art); - } - else if (!art->isBig()) //should be -1 => put artifact into backpack - { - sha.artifacts.push_back(art); - } - } - else - { - if(!vstd::contains(sha.artifWorn,ui16(position))) - { - VLC->arth->equipArtifact(sha.artifWorn, position, art); - } - else if (!art->isBig()) - { - sha.artifacts.push_back(art); - } - } - - sendAndApply(&sha); +// const CGHeroInstance* h = getHero(hid); +// CArtifact * art = gs->map->artInstances.back(); //we use it only to immediatelly equip new artifact +// +// SetHeroArtifacts sha; +// sha.hid = hid; +// sha.artifacts = h->artifacts; +// sha.artifWorn = h->artifWorn; +// +// if(position<0) +// { +// if(position == -2) +// { +// int i; +// for(i=0; ipossibleSlots.size(); i++) //try to put artifact into first available slot +// { +// if( !vstd::contains(sha.artifWorn, art->possibleSlots[i]) ) +// { +// //we've found a free suitable slot +// VLC->arth->equipArtifact(sha.artifWorn, art->possibleSlots[i], art); +// break; +// } +// } +// if(i == art->possibleSlots.size() && !art->isBig()) //if haven't find proper slot, use backpack or discard big artifact +// sha.artifacts.push_back(art); +// } +// else if (!art->isBig()) //should be -1 => put artifact into backpack +// { +// sha.artifacts.push_back(art); +// } +// } +// else +// { +// if(!vstd::contains(sha.artifWorn,ui16(position))) +// { +// VLC->arth->equipArtifact(sha.artifWorn, position, art); +// } +// else if (!art->isBig()) +// { +// sha.artifacts.push_back(art); +// } +// } +// +// sendAndApply(&sha); } bool CGameHandler::removeArtifact(const CArtifact* art, int hid) { @@ -2585,8 +2585,8 @@ void CGameHandler::close() bool CGameHandler::arrangeStacks( si32 id1, si32 id2, ui8 what, ui8 p1, ui8 p2, si32 val, ui8 player ) { - CArmedInstance *s1 = static_cast(gs->map->objects[id1]), - *s2 = static_cast(gs->map->objects[id2]); + CArmedInstance *s1 = static_cast(+gs->map->objects[id1]), + *s2 = static_cast(+gs->map->objects[id2]); CCreatureSet &S1 = *s1, &S2 = *s2; StackLocation sl1(s1, p1), sl2(s2, p2); @@ -2688,7 +2688,7 @@ int CGameHandler::getPlayerAt( CConnection *c ) const bool CGameHandler::disbandCreature( si32 id, ui8 pos ) { - CArmedInstance *s1 = static_cast(gs->map->objects[id]); + CArmedInstance *s1 = static_cast(+gs->map->objects[id]); if(!vstd::contains(s1->slots,pos)) { complain("Illegal call to disbandCreature - no such stack in army!"); @@ -2701,7 +2701,7 @@ bool CGameHandler::disbandCreature( si32 id, ui8 pos ) bool CGameHandler::buildStructure( si32 tid, si32 bid, bool force /*=false*/ ) { - CGTownInstance * t = static_cast(gs->map->objects[tid]); + CGTownInstance * t = static_cast(+gs->map->objects[tid]); CBuilding * b = VLC->buildh->buildings[t->subID][bid]; if( !force && gs->canBuildStructure(t,bid) != 7) @@ -2811,7 +2811,7 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid, bool force /*=false*/ ) bool CGameHandler::razeStructure (si32 tid, si32 bid) { ///incomplete, simply erases target building - CGTownInstance * t = static_cast(gs->map->objects[tid]); + CGTownInstance * t = static_cast(+gs->map->objects[tid]); if (t->builtBuildings.find(bid) == t->builtBuildings.end()) return false; RazeStructures rs; @@ -2840,7 +2840,7 @@ void CGameHandler::sendMessageToAll( const std::string &message ) bool CGameHandler::recruitCreatures( si32 objid, ui32 crid, ui32 cram, si32 fromLvl ) { - const CGDwelling *dw = static_cast(gs->map->objects[objid]); + const CGDwelling *dw = static_cast(+gs->map->objects[objid]); const CArmedInstance *dst = NULL; const CCreature *c = VLC->creh->creatures[crid]; bool warMachine = c->hasBonusOfType(Bonus::SIEGE_WEAPON); @@ -2929,7 +2929,7 @@ bool CGameHandler::recruitCreatures( si32 objid, ui32 crid, ui32 cram, si32 from bool CGameHandler::upgradeCreature( ui32 objid, ui8 pos, ui32 upgID ) { - CArmedInstance *obj = static_cast(gs->map->objects[objid]); + CArmedInstance *obj = static_cast(+gs->map->objects[objid]); assert(obj->hasStackAtSlot(pos)); UpgradeInfo ui = gs->getUpgradeInfo(obj->getStack(pos)); int player = obj->tempOwner; @@ -4704,7 +4704,7 @@ void CGameHandler::checkLossVictory( ui8 player ) 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 + for (std::vector >::const_iterator i = gs->map->objects.begin(); i != gs->map->objects.end(); i++) //unflag objs { if(*i && (*i)->tempOwner == player) setOwner((**i).id,NEUTRAL_PLAYER); @@ -4848,7 +4848,7 @@ void CGameHandler::getLossVicMessage( ui8 player, ui8 standard, bool victory, In bool CGameHandler::dig( const CGHeroInstance *h ) { - for (std::vector::const_iterator i = gs->map->objects.begin(); i != gs->map->objects.end(); i++) //unflag objs + for (std::vector >::const_iterator i = gs->map->objects.begin(); i != gs->map->objects.end(); i++) //unflag objs { if(*i && (*i)->ID == 124 && (*i)->pos == h->getPosition()) {