1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Hopefully fixed #261, #263, #246.

This commit is contained in:
Michał W. Urbańczyk
2009-12-01 21:05:57 +00:00
parent 79592d6fbb
commit a3bfde9a41
4 changed files with 34 additions and 11 deletions

View File

@@ -1276,9 +1276,9 @@ void CGDwelling::setProperty(ui8 what, ui32 val)
if (val != NEUTRAL_PLAYER) //can new owner be neutral? if (val != NEUTRAL_PLAYER) //can new owner be neutral?
cb->gameState()->players[val].dwellings.push_back (this); cb->gameState()->players[val].dwellings.push_back (this);
} }
tempOwner = val;
break; break;
} }
CGObjectInstance::setProperty(what,val);
} }
void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
{ {

View File

@@ -429,7 +429,11 @@ public:
{ {
h & static_cast<CGDwelling&>(*this); h & static_cast<CGDwelling&>(*this);
h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings
& possibleSpells & obligatorySpells & spells & /*strInfo & */events; & possibleSpells & obligatorySpells & spells & /*strInfo & */events & bonusingBuildings;
for (std::vector<CGTownBuilding*>::iterator i = bonusingBuildings.begin(); i!=bonusingBuildings.end(); i++)
(*i)->town = this;
ui8 standardType = (&VLC->townh->towns[subID] == town); ui8 standardType = (&VLC->townh->towns[subID] == town);
h & standardType; h & standardType;

View File

@@ -1,6 +1,7 @@
#ifndef __CGAMESTATE_H__ #ifndef __CGAMESTATE_H__
#define __CGAMESTATE_H__ #define __CGAMESTATE_H__
#include "../global.h" #include "../global.h"
#include <cassert>
#ifndef _MSC_VER #ifndef _MSC_VER
#include "../hch/CCreatureHandler.h" #include "../hch/CCreatureHandler.h"
#include "VCMI_Lib.h" #include "VCMI_Lib.h"
@@ -81,9 +82,19 @@ public:
size = availableHeroes.size(); size = availableHeroes.size();
h & size; h & size;
for(size_t i=0; i < size; i++) for(size_t i=0; i < size; i++)
{
if(availableHeroes[i])
{
h & availableHeroes[i]->subID; h & availableHeroes[i]->subID;
} }
else else
{
ui32 none = 0xffffffff;
h & none;
}
}
}
else
{ {
ui32 hid; ui32 hid;
h & size; h & size;
@@ -390,8 +401,16 @@ public:
{ {
ui32 hlp = i->second.availableHeroes[j]->subID; ui32 hlp = i->second.availableHeroes[j]->subID;
delete i->second.availableHeroes[j]; delete i->second.availableHeroes[j];
if(hlp != 0xffffffff)
{
assert(vstd::contains(hpool.heroesPool, hlp));
i->second.availableHeroes[j] = hpool.heroesPool[hlp]; i->second.availableHeroes[j] = hpool.heroesPool[hlp];
} }
else
{
i->second.availableHeroes[j] = NULL;
}
}
} }
} }
} }

View File

@@ -2441,22 +2441,22 @@ bool CGameHandler::hireHero( ui32 tid, ui8 hid )
hr.tile = t->pos - int3(1,0,0); hr.tile = t->pos - int3(1,0,0);
sendAndApply(&hr); sendAndApply(&hr);
std::map<ui32,CGHeroInstance *> pool = gs->hpool.heroesPool; std::map<ui32,CGHeroInstance *> pool = gs->hpool.heroesPool;
for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
for(std::vector<CGHeroInstance *>::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++)
if(*j)
pool.erase((**j).subID);
SetAvailableHeroes sah; 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]; *h2 = gs->getPlayer(t->tempOwner)->availableHeroes[!hid];
(hid ? sah.hid2 : sah.hid1) = h1 ? h1->subID : -1; (hid ? sah.hid2 : sah.hid1) = h1 ? h1->subID : -1;
(hid ? sah.hid1 : sah.hid2) = h2 ? h2->subID : -1; (hid ? sah.hid1 : sah.hid2) = h2 ? h2->subID : -1;
sah.player = t->tempOwner; sah.player = t->tempOwner;
//sah.flags = hid+1; //without army - why? sah.flags = hid+1;
sendAndApply(&sah); sendAndApply(&sah);
for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
for(std::vector<CGHeroInstance *>::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; SetResource sr;
sr.player = t->tempOwner; sr.player = t->tempOwner;
sr.resid = 6; sr.resid = 6;