1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-15 20:03:15 +02:00

* fixes for previous commit

This commit is contained in:
mateuszb
2009-09-23 12:42:14 +00:00
parent e9c991a180
commit dce07fe1c9
4 changed files with 103 additions and 6 deletions

View File

@@ -1508,7 +1508,10 @@ CGTownInstance::CGTownInstance()
}
CGTownInstance::~CGTownInstance()
{}
{
for (std::vector<CGTownBuilding*>::const_iterator i = bonusingBuildings.begin(); i != bonusingBuildings.end(); i++)
delete *i;
}
int CGTownInstance::spellsAtLevel(int level, bool checkGuild) const
{
@@ -1549,6 +1552,7 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
}
else
{
removeCapitols (h->getOwner(), true);
cb->setOwner(id, h->tempOwner);
}
}
@@ -1583,6 +1587,7 @@ void CGTownInstance::initObj()
bonusingBuildings.push_back (new CTownBonus(17, this));
break;
}
removeCapitols (getOwner(), false); // destroy other capitols
}
int3 CGTownInstance::getSightCenter() const
@@ -1599,10 +1604,37 @@ void CGTownInstance::fightOver( const CGHeroInstance *h, BattleResult *result )
{
if(result->winner == 0)
{
cb->setOwner(id, h->tempOwner);
removeCapitols (h->getOwner(), true);
cb->setOwner (id, h->tempOwner); //give control after checkout is done
}
}
void CGTownInstance::removeCapitols (ui8 owner, bool me) const
{
if (hasCapitol()) // search for older capitol
{
PlayerState* state = cb->gameState()->getPlayer (owner);
for (std::vector<CGTownInstance*>::const_iterator i = state->towns.begin(); i < state->towns.end(); ++i)
{
if (*i != this && (*i)->hasCapitol())
{
if (me)
{
RazeStructures rs;
rs.tid = id;
rs.bid.insert(13);
si16 builded = destroyed;
cb->sendAndApply(&rs);
//cb->gameState()->getTown(id)->builtBuildings.erase(13); //destroy local capitol
return;
}
else
(*i)->builtBuildings.erase(13); //destroy all other capitols at the beginning of game
}
}
}
}
void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h ) const
{
if(visitors.find(h->id)==visitors.end())
@@ -3099,6 +3131,38 @@ void CGBonusingObject::initObj()
}
}
void CGMagicSpring::onHeroVisit(const CGHeroInstance * h) const
{
int messageID;
InfoWindow iw;
iw.player = h->tempOwner;
iw.soundID = soundBase::GENIE;
if (!visited)
{
if (h->mana > h->manaLimit())
messageID = 76;
else
{
messageID = 74;
cb->setManaPoints (h->id, 2 * h->manaLimit());
cb->setObjProperty (id, 5, true);
}
}
else
messageID = 75;
iw.text << std::pair<ui8,ui32>(11,messageID);
cb->showInfoDialog(&iw);
}
const std::string & CGMagicSpring::getHoverText() const
{
hoverName = VLC->generaltexth->names[ID];
if(!visited)
hoverName += " " + VLC->generaltexth->allTexts[353]; //not visited
else
hoverName += " " + VLC->generaltexth->allTexts[352]; //visited
return hoverName;
}
void CGMagicWell::onHeroVisit( const CGHeroInstance * h ) const
{
int message;
@@ -4557,6 +4621,25 @@ void CCartographer::buyMap (const CGHeroInstance *h, ui32 accept) const
}
}
void CShop::newTurn() const
{
switch (ID)
{
case 7: //ArtMerchant aka. Black Market
if (cb->getDate(0)%28 == 1)
{
cb->setObjProperty (id, 13, 0);
cb->setObjProperty (id, 14, rand());
}
break;
case 78: //Refugee Camp
case 95: //Tavern
if (cb->getDate(0)%7 == 1)
cb->setObjProperty (id, 14, rand());
break;
}
}
void CShop::setPropertyDer (ui8 what, ui32 val)
{
switch (what)

View File

@@ -441,6 +441,7 @@ public:
bool hasCapitol() const;
int dailyIncome() const; //calculates daily income of this town
int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
void removeCapitols (ui8 owner, bool me) const;
CGTownInstance();
virtual ~CGTownInstance();
@@ -751,6 +752,19 @@ public:
}
};
class DLL_EXPORT CGMagicSpring : public CGVisitableOPW
{///unfortunatelly, this one is quite different than others
public:
void onHeroVisit(const CGHeroInstance * h) const;
const std::string & getHoverText() const;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGObjectInstance&>(*this);
h & visited;
}
};
class DLL_EXPORT CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
{
public:
@@ -948,8 +962,8 @@ public:
void initObj() {};
void setPropertyDer (ui8 what, ui32 val);
void newTurn() const {};
virtual void reset (ui32 val) {};
void newTurn() const;
virtual void reset (ui32 val) {}; //get new items for Black Market, Tavern, Refugee Camp
void onHeroVisit (const CGHeroInstance * h) const {};
virtual void trade (const CGHeroInstance * h) const {};

View File

@@ -42,7 +42,7 @@ void registerTypes1(Serializer &s)
s.template registerType<CGShrine>();
s.template registerType<CGQuestGuard>();
s.template registerType<CGBonusingObject>();
//s.template registerType<CGMagicSpring>();
s.template registerType<CGMagicSpring>();
s.template registerType<CGMagicWell>();
s.template registerType<CGObservatory>();
s.template registerType<CGKeys>();

View File

@@ -1950,7 +1950,7 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
}
case 48: //Magic Spring
{
//nobj = new CGMagicSpring();
nobj = new CGMagicSpring();
break;
}
default: