diff --git a/AI/GeniusAI/CGeniusAI.cpp b/AI/GeniusAI/CGeniusAI.cpp index ea146e863..6e4db4043 100644 --- a/AI/GeniusAI/CGeniusAI.cpp +++ b/AI/GeniusAI/CGeniusAI.cpp @@ -1025,7 +1025,7 @@ void CGeniusAI::yourTurn() { static boost::mutex mutex; boost::mutex::scoped_lock lock(mutex); - m_cb->waitTillRealize = true; + m_cb->waitTillRealize = false; static int seed = rand(); srand(seed); // if (m_cb->getDate() == 1) { diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index 759161e61..c984cbc3b 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -2037,7 +2037,7 @@ void CAdvMapInt::mouseMoved( const SDL_MouseMotionEvent & sEvent ) bool CAdvMapInt::isActive() { - return active & ~CIntObject.KEYBOARD; + return active & ~CIntObject::KEYBOARD; } CAdventureOptions::CAdventureOptions() diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 77143aabb..29c2bb73d 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -167,7 +167,9 @@ void CObjectHandler::loadObjects() for(int i=0; i<4; ++i) //reading levels { - BankConfig bc; + banksInfo[g].push_back(new BankConfig); + + BankConfig &bc = *banksInfo[g].back(); std::string buf; char dump; //bc.level is of type char and thus we cannot read directly to it; same for some othre variables @@ -210,8 +212,6 @@ void CObjectHandler::loadObjects() istr >> bc.rewardDifficulty; istr >> buf; bc.easiest = atoi(buf.c_str()); - - banksInfo[g].push_back(bc); } } } @@ -4076,9 +4076,9 @@ void CBank::reset(ui16 var1) //prevents desync ui8 chance = 0; for (ui8 i = 0; i < VLC->objh->banksInfo[index].size(); i++) { - if (var1 < (chance += VLC->objh->banksInfo[index][i].chance)) + if (var1 < (chance += VLC->objh->banksInfo[index][i]->chance)) { - bc = &VLC->objh->banksInfo[index][i]; + bc = VLC->objh->banksInfo[index][i]; break; } } @@ -4125,7 +4125,7 @@ void CBank::setPropertyDer (ui8 what, ui32 val) multiplier = ((float)val)/100; break; case 13: //bank preset - bc = &VLC->objh->banksInfo[index][val]; + bc = VLC->objh->banksInfo[index][val]; break; case 14: reset (val%100); diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 2d7a29ab4..f95e1d214 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -938,7 +938,7 @@ class DLL_EXPORT CBank : public CArmedInstance template void serialize(Handler &h, const int version) { h & static_cast(*this); - h & index & multiplier & artifacts & daycounter; + h & index & multiplier & artifacts & daycounter & bc; } }; class DLL_EXPORT CGPyramid : public CBank @@ -1057,7 +1057,7 @@ class DLL_EXPORT CObjectHandler { public: std::vector cregens; //type 17. dwelling subid -> creature ID - std::map > banksInfo; //[index][preset] + std::map > banksInfo; //[index][preset] std::map creBanksNames; //[crebank index] -> name of this creature bank void loadObjects(); diff --git a/lib/Connection.cpp b/lib/Connection.cpp index 7305789ff..264ab8908 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -47,6 +47,8 @@ CTypeList typeList; void CConnection::init() { + CISer::smartPointerSerialization = false; + COSer::smartPointerSerialization = false; registerTypes(static_cast&>(*this)); registerTypes(static_cast&>(*this)); #ifdef LIL_ENDIAN diff --git a/lib/Connection.h b/lib/Connection.h index e684d886b..0bab69108 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -20,7 +20,7 @@ #include #include -const ui32 version = 713; +const ui32 version = 714; class CConnection; class CGObjectInstance; class CGameState; @@ -255,9 +255,13 @@ public: bool saving; std::map savers; // typeID => CPointerSaver + std::map savedPointers; + bool smartPointerSerialization; + COSer() { saving=true; + smartPointerSerialization = true; } template void registerType(const T * t=NULL) @@ -304,6 +308,22 @@ public: if(!hlp) return; + if(smartPointerSerialization) + { + std::map::iterator i = savedPointers.find(data); + if(i != savedPointers.end()) + { + //this pointer has been already serialized - write only it's id + *this << i->second; + return; + } + + //give id to this pointer + ui32 pid = (ui32)savedPointers.size(); + savedPointers[data] = pid; + *this << pid; + } + //write type identifier ui16 tid = typeList.getTypeID(data); *this << tid; @@ -438,10 +458,14 @@ public: std::map loaders; // typeID => CPointerSaver ui32 myVersion; + std::map loadedPointers; + bool smartPointerSerialization; + CISer() { saving = false; myVersion = version; + smartPointerSerialization = true; } ~CISer() @@ -533,10 +557,28 @@ public: return; } + ui32 pid = -1; //pointer id (or maybe rather pointee id) + std::map::iterator i = loadedPointers.end(); + if(smartPointerSerialization) + { + *this >> pid; //get the id + i = loadedPointers.find(pid); //lookup + + if(i != loadedPointers.end()) + { + //we already got this pointer + data = static_cast(i->second); + return; + } + } + //get type id ui16 tid; *this >> tid; This()->loadPointerHlp(tid, data); + + if(smartPointerSerialization && i == loadedPointers.end()) + loadedPointers[pid] = data; //add loaded pointer to our lookup map } //that part of ptr deserialization was extracted to allow customization of its behavior in derived classes