From a3bfde9a410cee11fa56892b5998655f28ee6d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Tue, 1 Dec 2009 21:05:57 +0000 Subject: [PATCH] Hopefully fixed #261, #263, #246. --- hch/CObjectHandler.cpp | 2 +- hch/CObjectHandler.h | 6 +++++- lib/CGameState.h | 23 +++++++++++++++++++++-- server/CGameHandler.cpp | 14 +++++++------- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index abfeb7926..b03ca9481 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -1276,9 +1276,9 @@ void CGDwelling::setProperty(ui8 what, ui32 val) if (val != NEUTRAL_PLAYER) //can new owner be neutral? cb->gameState()->players[val].dwellings.push_back (this); } - tempOwner = val; break; } + CGObjectInstance::setProperty(what,val); } void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const { diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 2c3dc6c79..0ae1f738b 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -429,7 +429,11 @@ public: { h & static_cast(*this); h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings - & possibleSpells & obligatorySpells & spells & /*strInfo & */events; + & possibleSpells & obligatorySpells & spells & /*strInfo & */events & bonusingBuildings; + + for (std::vector::iterator i = bonusingBuildings.begin(); i!=bonusingBuildings.end(); i++) + (*i)->town = this; + ui8 standardType = (&VLC->townh->towns[subID] == town); h & standardType; diff --git a/lib/CGameState.h b/lib/CGameState.h index 8b7ff10c7..a0d59cff2 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -1,6 +1,7 @@ #ifndef __CGAMESTATE_H__ #define __CGAMESTATE_H__ #include "../global.h" +#include #ifndef _MSC_VER #include "../hch/CCreatureHandler.h" #include "VCMI_Lib.h" @@ -81,7 +82,17 @@ public: size = availableHeroes.size(); h & size; for(size_t i=0; i < size; i++) - h & availableHeroes[i]->subID; + { + if(availableHeroes[i]) + { + h & availableHeroes[i]->subID; + } + else + { + ui32 none = 0xffffffff; + h & none; + } + } } else { @@ -390,7 +401,15 @@ public: { ui32 hlp = i->second.availableHeroes[j]->subID; delete i->second.availableHeroes[j]; - i->second.availableHeroes[j] = hpool.heroesPool[hlp]; + if(hlp != 0xffffffff) + { + assert(vstd::contains(hpool.heroesPool, hlp)); + i->second.availableHeroes[j] = hpool.heroesPool[hlp]; + } + else + { + i->second.availableHeroes[j] = NULL; + } } } } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index d2f8ada8f..304901170 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2441,22 +2441,22 @@ bool CGameHandler::hireHero( ui32 tid, ui8 hid ) hr.tile = t->pos - int3(1,0,0); sendAndApply(&hr); + std::map pool = gs->hpool.heroesPool; + for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + for(std::vector::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++) + if(*j) + pool.erase((**j).subID); SetAvailableHeroes sah; - CGHeroInstance *h1 = gs->hpool.pickHeroFor(false,t->tempOwner,t->town, pool), //new hero + CGHeroInstance *h1 = gs->hpool.pickHeroFor(false,t->tempOwner,t->town, pool), *h2 = gs->getPlayer(t->tempOwner)->availableHeroes[!hid]; (hid ? sah.hid2 : sah.hid1) = h1 ? h1->subID : -1; (hid ? sah.hid1 : sah.hid2) = h2 ? h2->subID : -1; sah.player = t->tempOwner; - //sah.flags = hid+1; //without army - why? + sah.flags = hid+1; sendAndApply(&sah); - for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) - for(std::vector::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++) - if(*j) - pool.erase((**j).subID); //hero is removed from available lists - SetResource sr; sr.player = t->tempOwner; sr.resid = 6;