1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Added feature #111 - external dwellings increase town growth.

This commit is contained in:
DjWarmonger 2009-10-26 09:11:10 +00:00
parent 7471372074
commit e4417e9204
3 changed files with 41 additions and 12 deletions

View File

@ -1201,8 +1201,6 @@ void CGHeroInstance::recreateArtBonuses()
void CGDwelling::initObj() void CGDwelling::initObj()
{ {
if (getOwner() != 255)
cb->gameState()->players[getOwner()].dwellings.push_back (this);
switch(ID) switch(ID)
{ {
case 17: case 17:
@ -1218,6 +1216,8 @@ void CGDwelling::initObj()
army.slots[0].first = crs->idNumber; army.slots[0].first = crs->idNumber;
army.slots[0].second = (8 - crs->level) * 3; army.slots[0].second = (8 - crs->level) * 3;
} }
if (getOwner() != 255)
cb->gameState()->players[getOwner()].dwellings.push_back (this);
} }
break; break;
@ -1258,6 +1258,25 @@ void CGDwelling::initObj()
} }
} }
void CGDwelling::setProperty(ui8 what, ui32 val)
{
switch (what)
{
case 1: //change owner
if (ID == 17) //single generators
{
if (tempOwner != NEUTRAL_PLAYER)
{
std::vector<CGDwelling *>* dwellings = &cb->gameState()->players[tempOwner].dwellings;
dwellings->erase (std::find(dwellings->begin(), dwellings->end(), this));
}
if (val != NEUTRAL_PLAYER) //can new owner be neutral?
cb->gameState()->players[val].dwellings.push_back (this);
}
tempOwner = val;
break;
}
}
void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
{ {
if(h->tempOwner != tempOwner && army.slots.size() > 0) //object is guarded if(h->tempOwner != tempOwner && army.slots.size() > 0) //object is guarded
@ -1275,12 +1294,7 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
if(h->tempOwner != tempOwner) if(h->tempOwner != tempOwner)
{ {
std::vector<CGDwelling *>* dwellings = &(cb->gameState()->players[tempOwner].dwellings);
dwellings->erase (std::find(dwellings->begin(), dwellings->end(), this));
cb->setOwner(id, h->tempOwner); cb->setOwner(id, h->tempOwner);
dwellings = &(cb->gameState()->players[h->tempOwner].dwellings);
//dwellings->push_back (this);
//cb->gameState()->players[getOwner()].dwellings.push_back (this);
} }
BlockingDialog bd; BlockingDialog bd;
@ -1497,7 +1511,11 @@ int CGTownInstance::creatureGrowth(const int & level) const
ret += garrisonHero->valOfBonuses(HeroBonus::CREATURE_GROWTH, level); ret += garrisonHero->valOfBonuses(HeroBonus::CREATURE_GROWTH, level);
if(visitingHero) if(visitingHero)
ret += visitingHero->valOfBonuses(HeroBonus::CREATURE_GROWTH, level); ret += visitingHero->valOfBonuses(HeroBonus::CREATURE_GROWTH, level);
for (std::vector<CGDwelling*>::const_iterator it = cb->gameState()->players[tempOwner].dwellings.begin(); it != cb->gameState()->players[tempOwner].dwellings.end(); ++it)
{ //foreach?!
if (VLC->creh->creatures[town->basicCreatures[level]].idNumber == (*it)->creatures[0].second[0])
++ret;
}
return ret; return ret;
} }
int CGTownInstance::dailyIncome() const int CGTownInstance::dailyIncome() const
@ -4119,7 +4137,7 @@ void CBank::setPropertyDer (ui8 what, ui32 val)
} }
break; break;
default: default:
tlog1 << "Error: Unexpected army data: " << bc->guards.size() <<" items found"; tlog2 << "Error: Unexpected army data: " << bc->guards.size() <<" items found";
return; return;
} }
} }

View File

@ -329,6 +329,7 @@ public:
} }
void initObj(); void initObj();
void setProperty(ui8 what, ui32 val);
void onHeroVisit(const CGHeroInstance * h) const; void onHeroVisit(const CGHeroInstance * h) const;
void newTurn() const; void newTurn() const;
void heroAcceptsCreatures(const CGHeroInstance *h, ui32 answer) const; void heroAcceptsCreatures(const CGHeroInstance *h, ui32 answer) const;

View File

@ -960,20 +960,30 @@ CGTownInstance *CGameState::getTown(int objid)
return NULL; return NULL;
return static_cast<CGTownInstance *>(map->objects[objid]); return static_cast<CGTownInstance *>(map->objects[objid]);
} }
std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj) std::pair<int,int> CGameState::pickObject (CGObjectInstance *obj)
{ {
switch(obj->ID) switch(obj->ID)
{ {
case 65: //random artifact case 65: //random artifact
return std::pair<int,int>(5,(ran()%136)+7); //the only reasonable range - there are siege weapons and blanks we must ommit return std::pair<int,int>(5,(ran()%136)+7); //the only reasonable range - there are siege weapons and blanks we must ommit
case 66: //random treasure artifact case 66: //random treasure artifact
return std::pair<int,int>(5,VLC->arth->treasures[ran()%VLC->arth->treasures.size()]->id); return std::pair<int,int>(5,VLC->arth->treasures[ran()%VLC->arth->treasures.size()]->id);
case 67: //random minor artifact case 67: //random minor artifact
return std::pair<int,int>(5,VLC->arth->minors[ran()%VLC->arth->minors.size()]->id); return std::pair<int,int>(5,VLC->arth->minors[ran()%VLC->arth->minors.size()]->id);
case 68: //random major artifact case 68: //random major artifact
return std::pair<int,int>(5,VLC->arth->majors[ran()%VLC->arth->majors.size()]->id); return std::pair<int,int>(5,VLC->arth->majors[ran()%VLC->arth->majors.size()]->id);
case 69: //random relic artifact case 69: //random relic artifact
return std::pair<int,int>(5,VLC->arth->relics[ran()%VLC->arth->relics.size()]->id); return std::pair<int,int>(5,VLC->arth->relics[ran()%VLC->arth->relics.size()]->id);
/*case 65: //random artifact //TODO: apply new randndomization system
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_TREASURE | CArtifact::ART_MINOR | CArtifact::ART_MAJOR | CArtifact::ART_RELIC));
case 66: //random treasure artifact
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_TREASURE));
case 67: //random minor artifact
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_MINOR));
case 68: //random major artifact
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_MAJOR));
case 69: //random relic artifact
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_RELIC));*/
case 70: //random hero case 70: //random hero
{ {
return std::pair<int,int>(HEROI_TYPE,pickHero(obj->tempOwner)); return std::pair<int,int>(HEROI_TYPE,pickHero(obj->tempOwner));