1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* compilation fixes (I didn't test everything, I hope it works)

This commit is contained in:
mateuszb 2009-09-23 12:05:33 +00:00
parent 91b4212c5f
commit e9c991a180
9 changed files with 57 additions and 124 deletions

View File

@ -99,7 +99,7 @@ public:
ui32 showBlockingDialog(BlockingDialog *iw){return 0;}; //synchronous version of above
void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb){};
void giveResource(int player, int which, int val){};
void giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const {};
void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) {};
void showCompInfo(ShowInInfobox * comp){};
void heroVisitCastle(int obj, int heroID){};
void stopHeroVisitCastle(int obj, int heroID){};

View File

@ -1244,7 +1244,7 @@ void CGDwelling::initObj()
void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
{
if(h->tempOwner != tempOwner && army) //object is guarded
if(h->tempOwner != tempOwner && army.slots.size() > 0) //object is guarded
{
BlockingDialog bd;
bd.player = h->tempOwner;
@ -1508,10 +1508,7 @@ 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
{
@ -1535,7 +1532,7 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
if(getOwner() != h->getOwner())
{
//TODO ally check
if(army || visitingHero)
if(army.slots.size() > 0 || visitingHero)
{
const CGHeroInstance *defendingHero = NULL;
if(visitingHero)
@ -1552,7 +1549,6 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
}
else
{
removeCapitols (h->getOwner(), true);
cb->setOwner(id, h->tempOwner);
}
}
@ -1587,7 +1583,6 @@ void CGTownInstance::initObj()
bonusingBuildings.push_back (new CTownBonus(17, this));
break;
}
removeCapitols (getOwner(), false); // destroy other capitols
}
int3 CGTownInstance::getSightCenter() const
@ -1604,35 +1599,10 @@ void CGTownInstance::fightOver( const CGHeroInstance *h, BattleResult *result )
{
if(result->winner == 0)
{
removeCapitols (h->getOwner(), true);
cb->setOwner (id, h->tempOwner); //give control after checkout is done
cb->setOwner(id, h->tempOwner);
}
}
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())
@ -2449,7 +2419,7 @@ void CGVisitableOPW::newTurn() const
void CGVisitableOPW::onHeroVisit( const CGHeroInstance * h ) const
{
int mid, sound = 0; //message id, sound
int mid, sound = 0;
switch (ID)
{
case 55: //mystical garden
@ -3129,38 +3099,6 @@ 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;
@ -3209,7 +3147,7 @@ void CGPandoraBox::open( const CGHeroInstance * h, ui32 accept ) const
{
if (accept)
{
if (army) //if pandora's box is protected by army
if (army.slots.size() > 0) //if pandora's box is protected by army
{
InfoWindow iw;
iw.player = h->tempOwner;
@ -3220,7 +3158,7 @@ void CGPandoraBox::open( const CGHeroInstance * h, ui32 accept ) const
else if (message.size() == 0 && resources.size() == 0
&& primskills.size() == 0 && abilities.size() == 0
&& abilityLevels.size() == 0 && artifacts.size() == 0
&& spells.size() == 0 && creatures == 0
&& spells.size() == 0 && creatures.slots.size() > 0
&& gainedExp == 0 && manaDiff == 0 && moraleDiff == 0 && luckDiff == 0) //if it gives nothing without battle
{
InfoWindow iw;
@ -3421,7 +3359,34 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con
}
cb->showInfoDialog(&iw);
}
cb->giveCreatures (id, h, &creatures);
//check if creatures can be moved to hero army
CCreatureSet heroArmy = h->army;
CCreatureSet ourArmy = creatures;
while(ourArmy.slots.size() > 0)
{
int slot = heroArmy.getSlotFor(ourArmy.slots.begin()->second.first);
if(slot < 0)
break;
heroArmy.slots[slot].first = ourArmy.slots.begin()->second.first;
heroArmy.slots[slot].second += ourArmy.slots.begin()->second.second;
ourArmy.slots.erase(ourArmy.slots.begin());
}
if(ourArmy.slots.size() > 0) //all creatures can be moved to hero army - do that
{
SetGarrisons sg;
sg.garrs[h->id] = heroArmy;
cb->sendAndApply(&sg);
}
else //show garrison window and let player pick creatures
{
SetGarrisons sg;
sg.garrs[id] = creatures;
cb->sendAndApply(&sg);
cb->showGarrisonDialog(id,h->id,true,boost::bind(&IGameCallback::removeObject,cb,id));
}
if(!afterBattle && message.size())
{
@ -3476,7 +3441,7 @@ void CGEvent::onHeroVisit( const CGHeroInstance * h ) const
void CGEvent::activated( const CGHeroInstance * h ) const
{
if(army)
if(army.slots.size() > 0)
{
InfoWindow iw;
iw.player = h->tempOwner;
@ -3691,7 +3656,7 @@ void CGScholar::initObj()
void CGGarrison::onHeroVisit (const CGHeroInstance *h) const
{
if (h->tempOwner != tempOwner && army) {
if (h->tempOwner != tempOwner && army.slots.size() > 0) {
//TODO: Find a way to apply magic garrison effects in battle.
cb->startBattleI(h, this, boost::bind(&CGGarrison::fightOver, this, h, _1));
return;
@ -4211,7 +4176,7 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
iw.text.addReplacement (loot.buildList());
iw.text.addReplacement (h->name);
cb->showInfoDialog(&iw);
cb->giveCreatures (id, h, &ourArmy);
cb->giveCreatures (id, h, ourArmy);
}
cb->setObjProperty (id, 15, 0); //bc = NULL
}
@ -4592,22 +4557,6 @@ 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)
@ -4650,8 +4599,9 @@ 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,7 +441,6 @@ 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();
@ -752,18 +751,6 @@ 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:
@ -961,8 +948,8 @@ public:
void initObj() {};
void setPropertyDer (ui8 what, ui32 val);
void newTurn() const;
virtual void reset (ui32 val) {}; //get new items for Black Market, Tavern, Refugee Camp
void newTurn() const {};
virtual void reset (ui32 val) {};
void onHeroVisit (const CGHeroInstance * h) const {};
virtual void trade (const CGHeroInstance * h) const {};

4
int3.h
View File

@ -87,10 +87,6 @@ public:
{
h & slots & formation;
}
operator bool() const
{
return slots.size() > 0;
}
void sweep()
{
for(TSlots::iterator i=slots.begin(); i!=slots.end(); ++i)

View File

@ -76,7 +76,7 @@ public:
virtual ui32 showBlockingDialog(BlockingDialog *iw) =0; //synchronous version of above //TODO:
virtual void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) =0; //cb will be called when player closes garrison window
virtual void giveResource(int player, int which, int val)=0;
virtual void giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const=0;
virtual void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) =0;
virtual void showCompInfo(ShowInInfobox * comp)=0;
virtual void heroVisitCastle(int obj, int heroID)=0;
virtual void stopHeroVisitCastle(int obj, int heroID)=0;

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:

View File

@ -1570,22 +1570,22 @@ void CGameHandler::giveResource(int player, int which, int val)
sr.val = gs->players.find(player)->second.resources[which]+val;
sendAndApply(&sr);
}
void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const
void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures)
{
if (creatures->slots.size() <= 0)
if (creatures.slots.size() <= 0)
return;
CCreatureSet heroArmy = h->army;
while (*creatures)
while (creatures.slots.size() > 0)
{
int slot = heroArmy.getSlotFor (creatures->slots.begin()->second.first);
int slot = heroArmy.getSlotFor (creatures.slots.begin()->second.first);
if (slot < 0)
break;
heroArmy.slots[slot].first = creatures->slots.begin()->second.first;
heroArmy.slots[slot].second += creatures->slots.begin()->second.second;
creatures->slots.erase (creatures->slots.begin());
heroArmy.slots[slot].first = creatures.slots.begin()->second.first;
heroArmy.slots[slot].second += creatures.slots.begin()->second.second;
creatures.slots.erase (creatures.slots.begin());
}
if (!*creatures) //all creatures can be moved to hero army - do that
if (creatures.slots.size() == 0) //all creatures can be moved to hero army - do that
{
SetGarrisons sg;
sg.garrs[h->id] = heroArmy;
@ -1594,7 +1594,7 @@ void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, const CCr
else //show garrison window and let player pick creatures
{
SetGarrisons sg;
sg.garrs[objid] = *creatures;
sg.garrs[objid] = creatures;
sendAndApply (&sg);
showGarrisonDialog (objid, h->id, true, 0);
return;

View File

@ -115,7 +115,7 @@ public:
ui32 showBlockingDialog(BlockingDialog *iw); //synchronous version of above
void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb);
void giveResource(int player, int which, int val);
void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet *creatures);
void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures);
void showCompInfo(ShowInInfobox * comp);
void heroVisitCastle(int obj, int heroID);
void stopHeroVisitCastle(int obj, int heroID);