1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Towns belonging to specific player will now allow only one capitol. Function triggers on InitObj and after siege.

This commit is contained in:
DjWarmonger 2009-09-22 11:28:05 +00:00
parent 027b948a07
commit 1f92b2af2c
4 changed files with 49 additions and 8 deletions

View File

@ -768,6 +768,7 @@ public:
std::map<ui16, Component> avaliable, chosen, bought;
bool swapItem (ui16 which, bool choose);
virtual void Buy() {};
};
class CArtMerchantWindow : public CShopWindow
{};

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
{
@ -1583,6 +1586,7 @@ void CGTownInstance::initObj()
bonusingBuildings.push_back (new CTownBonus(17, this));
break;
}
removeCapitols (getOwner(), false); // destroy other capitols
}
int3 CGTownInstance::getSightCenter() const
@ -1599,10 +1603,30 @@ 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)
{
cb->gameState()->getTown(id)->builtBuildings.erase(13); //destroy local capitol
return;
}
else
(*i)->builtBuildings.erase(13); //destroy all other capitols
}
}
}
}
void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h ) const
{
if(visitors.find(h->id)==visitors.end())
@ -4557,6 +4581,22 @@ 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)
@ -4599,9 +4639,8 @@ void CGArtMerchant::reset(ui32 val)
}
for (ui8 n = 0; n < count; n++)
{
index = arts.begin() + val % arts.size();
avaliable [avaliable.size()] = new Component (Component::ARTIFACT, (*index)->id, 0, 0);
avaliable[avaliable.size()] = new Component (Component::ARTIFACT, (*index)->id, 0, 0);
arts.erase(index);
val *= (id + n * i); //randomize
}

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();
@ -948,8 +949,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

@ -593,7 +593,7 @@ struct NewTurn : public CPackForClient //101
struct Component : public CPack //2002 helper for object scrips informations
{
enum {PRIM_SKILL,SEC_SKILL,RESOURCE,CREATURE,ARTIFACT,EXPERIENCE,SPELL, MORALE=8, LUCK};
enum {PRIM_SKILL, SEC_SKILL, RESOURCE, CREATURE, ARTIFACT, EXPERIENCE, SPELL, MORALE=8, LUCK, HERO};
ui16 id, subtype; //id uses ^^^ enums, when id==EXPPERIENCE subtype==0 means exp points and subtype==1 levels)
si32 val; // + give; - take
si16 when; // 0 - now; +x - within x days; -x - per x days