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

* refactoring

* moat damage went to config file
This commit is contained in:
mateuszb 2013-02-08 21:17:39 +00:00
parent 140786a04b
commit 9dd60b6dbe
20 changed files with 157 additions and 160 deletions

View File

@ -725,7 +725,7 @@ bool CShootingAnimation::init()
// If the creature id is 149 then it's a arrow tower which has no additional info so get the
// actual arrow tower shooter instead.
const CCreature *shooterInfo = shooter->getCreature();
if (shooterInfo->idNumber == 149)
if (shooterInfo->idNumber == CreatureID::ARROW_TOWERS)
{
int creID = owner->siegeH->town->town->clientInfo.siegeShooter;
shooterInfo = CGI->creh->creatures[creID];

View File

@ -295,7 +295,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
CDefHandler *&projectile = idToProjectile[s->getCreature()->idNumber];
const CCreature * creature;//creature whose shots should be loaded
if (s->getCreature()->idNumber == 149)
if (s->getCreature()->idNumber == CreatureID::ARROW_TOWERS)
creature = CGI->creh->creatures[siegeH->town->town->clientInfo.siegeShooter];
else
creature = s->getCreature();
@ -2179,7 +2179,7 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to)
bool incrementFrame = (animCount%(4/affectingSpeed)==0) && animType!=CCreatureAnim::DEATH &&
animType!=CCreatureAnim::MOVE_START && animType!=CCreatureAnim::HOLDING;
if (creature->idNumber == 149)
if (creature->idNumber == CreatureID::ARROW_TOWERS)
{
// a turret creature has a limited height, so cut it at a certain position; turret creature has no standing anim
unitRect.h = siegeH->town->town->clientInfo.siegeShooterCropHeight;

View File

@ -162,18 +162,18 @@ public:
//////////////////////////////////////////////////////////////////////////
//not working yet, will be implement somewhen later with support for local-sim-based gameplay
void changeSpells(int hid, bool give, const std::set<ui32> &spells) OVERRIDE {};
bool removeObject(int objid) OVERRIDE {return false;};
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<ui32> &spells) OVERRIDE {};
bool removeObject(const CGObjectInstance * obj) OVERRIDE {return false;};
void setBlockVis(int objid, bool bv) OVERRIDE {};
void setOwner(int objid, TPlayerColor owner) OVERRIDE {};
void setOwner(const CGObjectInstance * obj, TPlayerColor owner) OVERRIDE {};
void setHoverName(int objid, MetaString * name) OVERRIDE {};
void changePrimSkill(int ID, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) OVERRIDE {};
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) OVERRIDE {};
void changeSecSkill(int ID, SecondarySkill::SecondarySkill which, int val, bool abs=false) OVERRIDE {};
void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback) OVERRIDE {};
ui32 showBlockingDialog(BlockingDialog *iw) OVERRIDE {return 0;}; //synchronous version of above
void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) OVERRIDE {};
void showThievesGuildWindow(int player, int requestingObjId) OVERRIDE {};
void giveResource(int player, Res::ERes which, int val) OVERRIDE {};
void giveResource(TPlayerColor player, Res::ERes which, int val) OVERRIDE {};
void giveCreatures(const CArmedInstance * objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) OVERRIDE {};
void takeCreatures(int objid, const std::vector<CStackBasicDescriptor> &creatures) OVERRIDE {};
@ -193,8 +193,8 @@ public:
bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) OVERRIDE {return false;};
void showCompInfo(ShowInInfobox * comp) OVERRIDE {};
void heroVisitCastle(int obj, int heroID) OVERRIDE {};
void stopHeroVisitCastle(int obj, int heroID) OVERRIDE {};
void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) OVERRIDE {};
void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) OVERRIDE {};
//void giveHeroArtifact(int artid, int hid, int position){};
//void giveNewArtifact(int hid, int position){};
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, boost::function<void(BattleResult*)> cb = 0, const CGTownInstance *town = NULL) OVERRIDE {}; //use hero=NULL for no hero
@ -205,7 +205,7 @@ public:
void giveHeroBonus(GiveBonus * bonus) OVERRIDE {};
void setMovePoints(SetMovePoints * smp) OVERRIDE {};
void setManaPoints(int hid, int val) OVERRIDE {};
void giveHero(int id, int player) OVERRIDE {};
void giveHero(int id, TPlayerColor player) OVERRIDE {};
void changeObjPos(int objid, int3 newPos, ui8 flags) OVERRIDE {};
void sendAndApply(CPackForClient * info) OVERRIDE {};
void heroExchange(si32 hero1, si32 hero2) OVERRIDE {};

View File

@ -148,6 +148,7 @@
"horde" : [ 2, -1 ],
"mageGuild" : 4,
"warMachine" : "ballista",
"moatDamage" : 70,
"buildings" :
[

View File

@ -151,6 +151,7 @@
"mageGuild" : 5,
"primaryResource" : "mercury",
"warMachine" : "ballista",
"moatDamage" : 70,
"buildings" :
[

View File

@ -146,6 +146,7 @@
"mageGuild" : 5,
"primaryResource" : "sulfur",
"warMachine" : "ballista",
"moatDamage" : 90,
"buildings" :
[

View File

@ -146,6 +146,7 @@
"horde" : [ 0, -1 ],
"mageGuild" : 3,
"warMachine" : "firstAidTent",
"moatDamage" : 90,
"buildings" :
[

View File

@ -147,6 +147,7 @@
"mageGuild" : 5,
"primaryResource" : "mercury",
"warMachine" : "ballista",
"moatDamage" : 90,
"buildings" :
[

View File

@ -150,6 +150,7 @@
"horde" : [ 0, -1 ],
"mageGuild" : 5,
"warMachine" : "firstAidTent",
"moatDamage" : 70,
"buildings" :
[

View File

@ -152,6 +152,7 @@
"mageGuild" : 5,
"primaryResource" : "crystal",
"warMachine" : "firstAidTent",
"moatDamage" : 70,
"buildings" :
[

View File

@ -144,6 +144,7 @@
"horde" : [ 0, -1 ],
"mageGuild" : 3,
"warMachine" : "ammoCart",
"moatDamage" : 70,
"buildings" :
[

View File

@ -147,6 +147,7 @@
"primaryResource" : "gems",
"mageGuild" : 5,
"warMachine" : "ammoCart",
"moatDamage" : -1,
"buildings" :
[

View File

@ -5,6 +5,7 @@
#include "NetPacks.h"
#include "CSpellHandler.h"
#include "VCMI_Lib.h"
#include "CTownHandler.h"
/*
* CBattleCallback.cpp, part of VCMI engine
@ -22,7 +23,7 @@ namespace SiegeStuffThatShouldBeMovedToHandlers // <=== TODO
{
static void retreiveTurretDamageRange(const CStack *turret, double &outMinDmg, double &outMaxDmg)
{
assert(turret->getCreature()->idNumber == 149); //arrow turret
assert(turret->getCreature()->idNumber == CreatureID::ARROW_TOWERS);
switch(turret->position)
{
@ -58,19 +59,6 @@ namespace SiegeStuffThatShouldBeMovedToHandlers // <=== TODO
return stackLeft != destLeft;
}
static int getMoatDamage(int townType)
{
//TODO move to config file
static const int dmgs[] = {70, 70, -1,
90, 70, 90,
70, 90, 70};
if(townType >= 0 && townType < ARRAY_COUNT(dmgs))
return dmgs[townType];
tlog1 << "No moat info for town " << townType << std::endl;
return 0;
}
static EWallParts::EWallParts hexToWallPart(BattleHex hex)
{
//potentially attackable parts of wall
@ -214,7 +202,7 @@ int CBattleInfoEssentials::battleGetMoatDmg() const
if(!town)
return 0;
return getMoatDamage(town->subID);
return town->town->moatDamage;
}
const CGTownInstance * CBattleInfoEssentials::battleGetDefendedTown() const

View File

@ -1689,9 +1689,9 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
return;
}
int relations = cb->gameState()->getPlayerRelations( h->tempOwner, tempOwner );
PlayerRelations::PlayerRelations relations = cb->gameState()->getPlayerRelations( h->tempOwner, tempOwner );
if ( relations == 1 )//ally
if ( relations == PlayerRelations::ALLIES )
return;//do not allow recruiting or capturing
if( !relations && stacksCount() > 0) //object is guarded, owned by enemy
@ -1708,7 +1708,7 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
if(!relations && ID != Obj::WAR_MACHINE_FACTORY)
{
cb->setOwner(id, h->tempOwner);
cb->setOwner(this, h->tempOwner);
}
BlockingDialog bd (true,false);
@ -2087,9 +2087,9 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
}
else
{
cb->setOwner(id, h->tempOwner);
cb->setOwner(this, h->tempOwner);
removeCapitols(h->getOwner());
cb->heroVisitCastle(id, h->id);
cb->heroVisitCastle(this, h);
}
}
else
@ -2102,13 +2102,13 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
scp.amount = 1;
cb->sendAndApply (&scp);
}
cb->heroVisitCastle(id, h->id);
cb->heroVisitCastle(this, h);
}
}
void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const
{
cb->stopHeroVisitCastle(id,h->id);
cb->stopHeroVisitCastle(this, h);
}
void CGTownInstance::initObj()
@ -2252,7 +2252,7 @@ void CGTownInstance::fightOver( const CGHeroInstance *h, BattleResult *result )
if(result->winner == 0)
{
removeCapitols (h->getOwner());
cb->setOwner (id, h->tempOwner); //give control after checkout is done
cb->setOwner (this, h->tempOwner); //give control after checkout is done
FoWChange fw;
fw.player = h->tempOwner;
fw.mode = 1;
@ -2572,7 +2572,7 @@ void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, TExpType
if(result) //player agreed to give res for exp
{
cb->giveResource(cb->getOwner(heroID), static_cast<Res::ERes>(resType), -resVal); //take resource
cb->changePrimSkill(heroID, PrimarySkill::EXPERIENCE, expVal);
cb->changePrimSkill(cb->getHero(heroID), PrimarySkill::EXPERIENCE, expVal);
cb->setObjProperty(id, ObjProperty::VISITORS, heroID); //add to the visitors
}
}
@ -2654,7 +2654,7 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
case Obj::STAR_AXIS:
case Obj::GARDEN_OF_REVELATION:
{
cb->changePrimSkill(heroID, static_cast<PrimarySkill::PrimarySkill>(subid), val);
cb->changePrimSkill(cb->getHero(heroID), static_cast<PrimarySkill::PrimarySkill>(subid), val);
InfoWindow iw;
iw.soundID = sound;
iw.components.push_back(Component(c_id, subid, val, 0));
@ -2673,7 +2673,7 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
iw.player = cb->getOwner(heroID);
iw.text.addTxt(MetaString::ADVOB_TXT,ot);
cb->showInfoDialog(&iw);
cb->changePrimSkill(heroID, PrimarySkill::EXPERIENCE, val);
cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, val);
break;
}
case Obj::TREE_OF_KNOWLEDGE:
@ -2689,7 +2689,7 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
iw.player = cb->getOwner(heroID);
iw.text.addTxt(MetaString::ADVOB_TXT,148);
cb->showInfoDialog(&iw);
cb->changePrimSkill(heroID, PrimarySkill::EXPERIENCE, val);
cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, val);
break;
}
else
@ -2736,10 +2736,10 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
else
{
cb->setObjProperty(id, ObjProperty::VISITORS, heroID); //add to the visitors
cb->changePrimSkill(heroID,PrimarySkill::ATTACK,2);
cb->changePrimSkill(heroID,PrimarySkill::DEFENSE,2);
cb->changePrimSkill(heroID,PrimarySkill::KNOWLEDGE,2);
cb->changePrimSkill(heroID,PrimarySkill::SPELL_POWER,2);
cb->changePrimSkill(h,PrimarySkill::ATTACK,2);
cb->changePrimSkill(h,PrimarySkill::DEFENSE,2);
cb->changePrimSkill(h,PrimarySkill::KNOWLEDGE,2);
cb->changePrimSkill(h,PrimarySkill::SPELL_POWER,2);
}
showInfoDialog(h,txt_id,sound);
break;
@ -2826,7 +2826,7 @@ const std::string & CGVisitableOPH::getHoverText() const
void CGVisitableOPH::arenaSelected( int heroID, int primSkill ) const
{
cb->setObjProperty(id, ObjProperty::VISITORS, heroID); //add to the visitors
cb->changePrimSkill(heroID, static_cast<PrimarySkill::PrimarySkill>(primSkill-1), 2);
cb->changePrimSkill(cb->getHero(heroID), static_cast<PrimarySkill::PrimarySkill>(primSkill-1), 2);
}
void CGVisitableOPH::setPropertyDer( ui8 what, ui32 val )
@ -2843,7 +2843,7 @@ void CGVisitableOPH::schoolSelected(int heroID, ui32 which) const
int base = (ID == Obj::SCHOOL_OF_MAGIC ? 2 : 0);
cb->setObjProperty(id, ObjProperty::VISITORS, heroID); //add to the visitors
cb->giveResource(cb->getOwner(heroID),Res::GOLD,-1000); //take 1000 gold
cb->changePrimSkill(heroID, static_cast<PrimarySkill::PrimarySkill>(base + which-1), +1); //give appropriate skill
cb->changePrimSkill(cb->getHero(heroID), static_cast<PrimarySkill::PrimarySkill>(base + which-1), +1); //give appropriate skill
}
COPWBonus::COPWBonus (int index, CGTownInstance *TOWN)
@ -2963,7 +2963,7 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const
iw.player = cb->getOwner(heroID);
iw.text << VLC->generaltexth->allTexts[mid];
cb->showInfoDialog(&iw);
cb->changePrimSkill (heroID, what, val);
cb->changePrimSkill (cb->getHero(heroID), what, val);
if (town->visitingHero == h)
cb->setObjProperty (town->id, 11, id); //add to visitors
else
@ -3048,7 +3048,7 @@ void CGCreature::endBattle( BattleResult *result ) const
{
if(result->winner==0)
{
cb->removeObject(id);
cb->removeObject(this);
}
else
{
@ -3239,7 +3239,7 @@ void CGCreature::fleeDecision(const CGHeroInstance *h, ui32 pursue) const
}
else
{
cb->removeObject(id);
cb->removeObject(this);
}
}
@ -3450,7 +3450,7 @@ void CGMine::endBattle(BattleResult *result, TPlayerColor attackingPlayer) const
void CGMine::flagMine(TPlayerColor player) const
{
assert(tempOwner != player);
cb->setOwner(id,player); //not ours? flag it!
cb->setOwner(this, player); //not ours? flag it!
MetaString ms;
ms << std::pair<ui8,ui32>(9,subID) << "\n(" << std::pair<ui8,ui32>(6,23+player) << ")";
@ -3543,7 +3543,7 @@ void CGResource::collectRes( int player ) const
sii.text.addTxt(MetaString::ADVOB_TXT,113);
sii.text.addReplacement(MetaString::RES_NAMES, subID);
cb->showCompInfo(&sii);
cb->removeObject(id);
cb->removeObject(this);
}
void CGResource::fightForRes(ui32 agreed, const CGHeroInstance *h) const
@ -3877,7 +3877,7 @@ void CGArtifact::onHeroVisit( const CGHeroInstance * h ) const
void CGArtifact::pick(const CGHeroInstance * h) const
{
cb->giveHeroArtifact(h, storedArtifact, ArtifactPosition::FIRST_AVAILABLE);
cb->removeObject(id);
cb->removeObject(this);
}
void CGArtifact::fightForArt( ui32 agreed, const CGHeroInstance *h ) const
@ -4086,7 +4086,7 @@ void CGPickable::onHeroVisit( const CGHeroInstance * h ) const
}
}
}
cb->removeObject(id);
cb->removeObject(this);
}
void CGPickable::chosen( int which, int heroID ) const
@ -4098,12 +4098,12 @@ void CGPickable::chosen( int which, int heroID ) const
cb->giveResource(cb->getOwner(heroID), Res::GOLD, val1);
break;
case 2: //player pick exp
cb->changePrimSkill(heroID, PrimarySkill::EXPERIENCE, h->calculateXp(val2));
cb->changePrimSkill(cb->getHero(heroID), PrimarySkill::EXPERIENCE, h->calculateXp(val2));
break;
default:
throw std::runtime_error("Unhandled treasure choice");
}
cb->removeObject(id);
cb->removeObject(this);
}
bool CQuest::checkQuest (const CGHeroInstance * h) const
@ -4704,7 +4704,7 @@ void CGSeerHut::completeQuest (const CGHeroInstance * h) const //reward
case EXPERIENCE:
{
TExpType expVal = h->calculateXp(rVal);
cb->changePrimSkill(h->id, PrimarySkill::EXPERIENCE, expVal, false);
cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, expVal, false);
break;
}
case MANA_POINTS:
@ -4726,7 +4726,7 @@ void CGSeerHut::completeQuest (const CGHeroInstance * h) const //reward
cb->giveResource(h->getOwner(), static_cast<Res::ERes>(rID), rVal);
break;
case PRIMARY_SKILL:
cb->changePrimSkill(h->id, static_cast<PrimarySkill::PrimarySkill>(rID), rVal, false);
cb->changePrimSkill(h, static_cast<PrimarySkill::PrimarySkill>(rID), rVal, false);
break;
case SECONDARY_SKILL:
cb->changeSecSkill(h->id, static_cast<SecondarySkill::SecondarySkill>(rID), rVal, false);
@ -4738,7 +4738,7 @@ void CGSeerHut::completeQuest (const CGHeroInstance * h) const //reward
{
std::set<ui32> spell;
spell.insert (rID);
cb->changeSpells(h->id, true, spell);
cb->changeSpells(h, true, spell);
}
break;
case CREATURE:
@ -4790,7 +4790,7 @@ void CGQuestGuard::initObj()
}
void CGQuestGuard::completeQuest(const CGHeroInstance *h) const
{
cb->removeObject(id);
cb->removeObject(this);
}
void CGWitchHut::initObj()
{
@ -5135,7 +5135,7 @@ void CGPandoraBox::open( const CGHeroInstance * h, ui32 accept ) const
&& gainedExp == 0 && manaDiff == 0 && moraleDiff == 0 && luckDiff == 0) //if it gives nothing without battle
{
showInfoDialog(h,15,0);
cb->removeObject(id);
cb->removeObject(this);
}
else //if it gives something without battle
{
@ -5188,11 +5188,11 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con
//give exp
if(expVal)
cb->changePrimSkill(h->id, PrimarySkill::EXPERIENCE, expVal, false);
cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, expVal, false);
//give prim skills
for(int i=0; i<primskills.size(); i++)
if(primskills[i])
cb->changePrimSkill(h->id,static_cast<PrimarySkill::PrimarySkill>(i),primskills[i],false);
cb->changePrimSkill(h,static_cast<PrimarySkill::PrimarySkill>(i),primskills[i],false);
//give sec skills
for(int i=0; i<abilities.size(); i++)
@ -5231,7 +5231,7 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con
}
if(spellsToGive.size())
{
cb->changeSpells(h->id,true,spellsToGive);
cb->changeSpells(h,true,spellsToGive);
cb->showInfoDialog(&iw);
}
}
@ -5349,7 +5349,7 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con
cb->showInfoDialog(&iw);
}
if (!creatures.Slots().size())
cb->removeObject(id); //only when we don't need to display garrison window
cb->removeObject(this); //only when we don't need to display garrison window
}
void CGPandoraBox::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const
@ -5477,7 +5477,7 @@ void CGShrine::onHeroVisit( const CGHeroInstance * h ) const
{
std::set<ui32> spells;
spells.insert(spell);
cb->changeSpells(h->id, true, spells);
cb->changeSpells(h, true, spells);
iw.components.push_back(Component(Component::SPELL,spell,0,0));
}
@ -5538,7 +5538,7 @@ void CGSignBottle::onHeroVisit( const CGHeroInstance * h ) const
cb->showInfoDialog(&iw);
if(ID == Obj::OCEAN_BOTTLE)
cb->removeObject(id);
cb->removeObject(this);
}
//TODO: remove
@ -5573,7 +5573,7 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const
switch (type)
{
case PRIM_SKILL:
cb->changePrimSkill(h->id,static_cast<PrimarySkill::PrimarySkill>(bid),+1);
cb->changePrimSkill(h,static_cast<PrimarySkill::PrimarySkill>(bid),+1);
iw.components.push_back(Component(Component::PRIM_SKILL,bid,+1,0));
break;
case SECONDARY_SKILL:
@ -5584,7 +5584,7 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const
{
std::set<ui32> hlp;
hlp.insert(bid);
cb->changeSpells(h->id,true,hlp);
cb->changeSpells(h,true,hlp);
iw.components.push_back(Component(Component::SPELL,bid,0,0));
}
break;
@ -5594,7 +5594,7 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const
}
cb->showInfoDialog(&iw);
cb->removeObject(id);
cb->removeObject(this);
}
void CGScholar::initObj()
@ -5632,7 +5632,7 @@ void CGGarrison::onHeroVisit (const CGHeroInstance *h) const
//New owner.
if (!ally)
cb->setOwner(id, h->tempOwner);
cb->setOwner(this, h->tempOwner);
cb->showGarrisonDialog(id, h->id, removableUnits, 0);
}
@ -6271,7 +6271,7 @@ void CGPyramid::endBattle (const CGHeroInstance *h, const BattleResult *result)
{
std::set<ui32> spells;
spells.insert (spell);
cb->changeSpells (h->id, true, spells);
cb->changeSpells (h, true, spells);
iw.components.push_back(Component (Component::SPELL, spell, 0, 0));
}
cb->showInfoDialog(&iw);
@ -6372,7 +6372,7 @@ void CGBorderGuard::onHeroVisit( const CGHeroInstance * h ) const
void CGBorderGuard::openGate(const CGHeroInstance *h, ui32 accept) const
{
if (accept)
cb->removeObject(id);
cb->removeObject(this);
}
void CGBorderGate::onHeroVisit( const CGHeroInstance * h ) const //TODO: passability
@ -6480,7 +6480,7 @@ void CGSirens::onHeroVisit( const CGHeroInstance * h ) const
xp = h->calculateXp(xp);
iw.text.addTxt(MetaString::ADVOB_TXT,132);
iw.text.addReplacement(xp);
cb->changePrimSkill(h->id, PrimarySkill::EXPERIENCE, xp, false);
cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, xp, false);
}
else
{
@ -6622,7 +6622,7 @@ void CGShipyard::getOutOffsets( std::vector<int3> &offsets ) const
void CGShipyard::onHeroVisit( const CGHeroInstance * h ) const
{
if(!cb->gameState()->getPlayerRelations(tempOwner, h->tempOwner))
cb->setOwner(id, h->tempOwner);
cb->setOwner(this, h->tempOwner);
auto s = state();
if(s != IBoatGenerator::GOOD)
@ -6763,7 +6763,7 @@ void CGLighthouse::onHeroVisit( const CGHeroInstance * h ) const
if(h->tempOwner != tempOwner)
{
ui8 oldOwner = tempOwner;
cb->setOwner(id,h->tempOwner); //not ours? flag it!
cb->setOwner(this,h->tempOwner); //not ours? flag it!
showInfoDialog(h,69,soundBase::LIGHTHOUSE);
giveBonusTo(h->tempOwner);

View File

@ -421,6 +421,8 @@ void CTownHandler::loadTown(CTown &town, const JsonNode & source)
town.warMachine = CArtHandler::creatureToMachineID(static_cast<CreatureID::CreatureID>(creature));
});
town.moatDamage = source["moatDamage"].Float();
town.mageLevel = source["mageGuild"].Float();
town.names = source["names"].convertTo<std::vector<std::string> >();

View File

@ -102,6 +102,7 @@ public:
ui32 mageLevel; //max available mage guild level
ui16 primaryRes;
ArtifactID::ArtifactID warMachine;
si32 moatDamage;
// Client-only data. Should be moved away from lib
struct ClientInfo
@ -150,7 +151,7 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & names & typeID & creatures & dwellings & dwellingNames & buildings & hordeLvl & mageLevel
& primaryRes & warMachine & clientInfo;
& primaryRes & warMachine & clientInfo & moatDamage;
}
};

View File

@ -203,18 +203,18 @@ public:
class DLL_LINKAGE IGameEventCallback : public IGameEventRealizer
{
public:
virtual void changeSpells(int hid, bool give, const std::set<ui32> &spells)=0;
virtual bool removeObject(int objid)=0;
virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<ui32> &spells)=0;
virtual bool removeObject(const CGObjectInstance * obj)=0;
virtual void setBlockVis(int objid, bool bv)=0;
virtual void setOwner(int objid, TPlayerColor owner)=0;
virtual void setOwner(const CGObjectInstance * objid, TPlayerColor owner)=0;
virtual void setHoverName(int objid, MetaString * name)=0;
virtual void changePrimSkill(int ID, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
virtual void changeSecSkill(int ID, SecondarySkill::SecondarySkill which, int val, bool abs=false)=0;
virtual void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback)=0;
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 showThievesGuildWindow(int player, int requestingObjId) =0;
virtual void giveResource(int player, Res::ERes which, int val)=0;
virtual void giveResource(TPlayerColor player, Res::ERes which, int val)=0;
virtual void giveCreatures(const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) =0;
virtual void takeCreatures(int objid, const std::vector<CStackBasicDescriptor> &creatures) =0;
@ -234,8 +234,8 @@ public:
virtual bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) = 0;
virtual void showCompInfo(ShowInInfobox * comp)=0;
virtual void heroVisitCastle(int obj, int heroID)=0;
virtual void stopHeroVisitCastle(int obj, int heroID)=0;
virtual void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
virtual void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, boost::function<void(BattleResult*)> cb = 0, const CGTownInstance *town = NULL)=0; //use hero=NULL for no hero
virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false)=0; //if any of armies is hero, hero will be used
virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false)=0; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
@ -244,7 +244,7 @@ public:
virtual void giveHeroBonus(GiveBonus * bonus)=0;
virtual void setMovePoints(SetMovePoints * smp)=0;
virtual void setManaPoints(int hid, int val)=0;
virtual void giveHero(int id, int player)=0;
virtual void giveHero(int id, TPlayerColor player)=0;
virtual void changeObjPos(int objid, int3 newPos, ui8 flags)=0;
virtual void sendAndApply(CPackForClient * info)=0;
virtual void heroExchange(si32 hero1, si32 hero2)=0; //when two heroes meet on adventure map

View File

@ -460,10 +460,10 @@ void CGameHandler::levelUpCommander(const CCommanderInstance * c)
}
}
void CGameHandler::changePrimSkill(int ID, PrimarySkill::PrimarySkill which, si64 val, bool abs)
void CGameHandler::changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs)
{
SetPrimSkill sps;
sps.id = ID;
sps.id = hero->id;
sps.which = which;
sps.abs = abs;
sps.val = val;
@ -472,16 +472,15 @@ void CGameHandler::changePrimSkill(int ID, PrimarySkill::PrimarySkill which, si6
//only for exp - hero may level up
if (which == PrimarySkill::EXPERIENCE)
{
levelUpHero(ID);
CGHeroInstance *h = static_cast<CGHeroInstance *>(gs->map->objects[ID].get());
if (h->commander && h->commander->alive)
levelUpHero(hero->id);
if (hero->commander && hero->commander->alive)
{
SetCommanderProperty scp;
scp.heroid = h->id;
scp.heroid = hero->id;
scp.which = SetCommanderProperty::EXPERIENCE;
scp.amount = val;
sendAndApply (&scp);
levelUpCommander (h->commander);
levelUpCommander (hero->commander);
CBonusSystemNode::treeHasChanged();
}
}
@ -717,9 +716,9 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer
//give exp
if (battleResult.data->exp[0] && hero1)
changePrimSkill(hero1->id, PrimarySkill::EXPERIENCE, battleResult.data->exp[0]);
changePrimSkill(hero1, PrimarySkill::EXPERIENCE, battleResult.data->exp[0]);
else if (battleResult.data->exp[1] && hero2)
changePrimSkill(hero2->id, PrimarySkill::EXPERIENCE, battleResult.data->exp[1]);
changePrimSkill(hero2, PrimarySkill::EXPERIENCE, battleResult.data->exp[1]);
else
afterBattleCallback();
}
@ -799,7 +798,7 @@ void CGameHandler::prepareAttack(BattleAttack &bat, const CStack *att, const CSt
bat.flags |= BattleAttack::DEATH_BLOW;
}
if(att->getCreature()->idNumber == 146)
if(att->getCreature()->idNumber == CreatureID::BALLISTA)
{
static const int artilleryLvlToChance[] = {0, 50, 75, 100};
const CGHeroInstance * owner = gs->curB->getHero(att->owner);
@ -1177,7 +1176,7 @@ void CGameHandler::newTurn()
{
if (obj && obj->ID == Obj::PRISON) //give imprisoned hero 0 exp to level him up. easiest to do at this point
{
changePrimSkill (obj->id, PrimarySkill::EXPERIENCE, 0);
changePrimSkill (getHero(obj->id), PrimarySkill::EXPERIENCE, 0);
}
}
}
@ -1658,16 +1657,16 @@ void CGameHandler::setBlockVis(int objid, bool bv)
sendAndApply(&sop);
}
bool CGameHandler::removeObject( int objid )
bool CGameHandler::removeObject( const CGObjectInstance * obj )
{
if(!getObj(objid))
if(!obj || !getObj(obj->id))
{
tlog1 << "Something wrong, that object already has been removed or hasn't existed!\n";
return false;
}
RemoveObject ro;
ro.id = objid;
ro.id = obj->id;
sendAndApply(&ro);
winLoseHandle(255); //eg if monster escaped (removing objs after battle is done dircetly by endBattle, not this function)
@ -1680,11 +1679,11 @@ void CGameHandler::setAmount(int objid, ui32 val)
sendAndApply(&sop);
}
bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255*/ )
bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, TPlayerColor asker /*= 255*/ )
{
const CGHeroInstance *h = getHero(hid);
if(!h || (asker != 255 && (instant || h->getOwner() != gs->currentPlayer)) //not turn of that hero or player can't simply teleport hero (at least not with this function)
if(!h || (asker != GameConstants::NEUTRAL_PLAYER && (instant || h->getOwner() != gs->currentPlayer)) //not turn of that hero or player can't simply teleport hero (at least not with this function)
)
{
tlog1 << "Illegal call to move hero!\n";
@ -1839,7 +1838,7 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255*
}
}
bool CGameHandler::teleportHero(si32 hid, si32 dstid, ui8 source, ui8 asker/* = 255*/)
bool CGameHandler::teleportHero(si32 hid, si32 dstid, ui8 source, TPlayerColor asker/* = 255*/)
{
const CGHeroInstance *h = getHero(hid);
const CGTownInstance *t = getTown(dstid);
@ -1861,16 +1860,16 @@ bool CGameHandler::teleportHero(si32 hid, si32 dstid, ui8 source, ui8 asker/* =
return true;
}
void CGameHandler::setOwner(int objid, ui8 owner)
void CGameHandler::setOwner(const CGObjectInstance * obj, TPlayerColor owner)
{
ui8 oldOwner = getOwner(objid);
SetObjectProperty sop(objid,1,owner);
ui8 oldOwner = getOwner(obj->id);
SetObjectProperty sop(obj->id,1,owner);
sendAndApply(&sop);
winLoseHandle(1<<owner | 1<<oldOwner);
if(owner < GameConstants::PLAYER_LIMIT && getTown(objid)) //town captured
if(owner < GameConstants::PLAYER_LIMIT && dynamic_cast<const CGTownInstance *>(obj)) //town captured
{
const CGTownInstance * town = getTown(objid);
const CGTownInstance * town = dynamic_cast<const CGTownInstance *>(obj);
if (town->hasBuilt(EBuilding::PORTAL_OF_SUMMON, ETownType::DUNGEON))
setPortalDwelling(town, true, false);
@ -1883,7 +1882,6 @@ void CGameHandler::setOwner(int objid, ui8 owner)
}
}
const CGObjectInstance * obj = getObj(objid);
const PlayerState * p = gs->getPlayer(owner);
if((obj->ID == Obj::CREATURE_GENERATOR1 || obj->ID == Obj::CREATURE_GENERATOR4 ) && p && p->dwellings.size()==1)//first dwelling captured
@ -1923,7 +1921,7 @@ ui32 CGameHandler::showBlockingDialog( BlockingDialog *iw )
return 0;
}
void CGameHandler::giveResource(int player, Res::ERes which, int val) //TODO: cap according to Bersy's suggestion
void CGameHandler::giveResource(TPlayerColor player, Res::ERes which, int val) //TODO: cap according to Bersy's suggestion
{
if(!val) return; //don't waste time on empty call
SetResource sr;
@ -1937,7 +1935,7 @@ void CGameHandler::giveCreatures(const CArmedInstance *obj, const CGHeroInstance
{
boost::function<void()> removeOrNot = 0;
if(remove)
removeOrNot = boost::bind(&CGameHandler::removeObject, this, obj->id);
removeOrNot = boost::bind(&CGameHandler::removeObject, this, obj);
COMPLAIN_RET_IF(!creatures.stacksCount(), "Strange, giveCreatures called without args!");
COMPLAIN_RET_IF(obj->stacksCount(), "Cannot give creatures from not-cleared object!");
@ -1990,19 +1988,18 @@ void CGameHandler::showCompInfo(ShowInInfobox * comp)
{
sendToAllClients(comp);
}
void CGameHandler::heroVisitCastle(int obj, int heroID)
void CGameHandler::heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)
{
HeroVisitCastle vc;
vc.hid = heroID;
vc.tid = obj;
vc.hid = hero->id;
vc.tid = obj->id;
vc.flags |= 1;
sendAndApply(&vc);
const CGHeroInstance *h = getHero(heroID);
vistiCastleObjects (getTown(obj), h);
giveSpells (getTown(obj), getHero(heroID));
vistiCastleObjects (obj, hero);
giveSpells (obj, hero);
if(gs->map->victoryCondition.condition == EVictoryConditionType::TRANSPORTITEM)
checkLossVictory(h->tempOwner); //transported artifact?
checkLossVictory(hero->tempOwner); //transported artifact?
}
void CGameHandler::vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h)
@ -2012,11 +2009,11 @@ void CGameHandler::vistiCastleObjects (const CGTownInstance *t, const CGHeroInst
(*i)->onHeroVisit (h);
}
void CGameHandler::stopHeroVisitCastle(int obj, int heroID)
void CGameHandler::stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)
{
HeroVisitCastle vc;
vc.hid = heroID;
vc.tid = obj;
vc.hid = hero->id;
vc.tid = obj->id;
sendAndApply(&vc);
}
@ -2058,10 +2055,10 @@ void CGameHandler::startBattleI( const CArmedInstance *army1, const CArmedInstan
startBattleI(army1, army2, army2->visitablePos(), cb, creatureBank);
}
void CGameHandler::changeSpells( int hid, bool give, const std::set<ui32> &spells )
void CGameHandler::changeSpells( const CGHeroInstance * hero, bool give, const std::set<ui32> &spells )
{
ChangeSpells cs;
cs.hid = hid;
cs.hid = hero->id;
cs.spells = spells;
cs.learn = give;
sendAndApply(&cs);
@ -2093,7 +2090,7 @@ void CGameHandler::setManaPoints( int hid, int val )
sendAndApply(&sm);
}
void CGameHandler::giveHero( int id, int player )
void CGameHandler::giveHero( int id, TPlayerColor player )
{
GiveHero gh;
gh.id = id;
@ -2215,7 +2212,7 @@ void CGameHandler::heroExchange(si32 hero1, si32 hero2)
}
}
void CGameHandler::prepareNewQuery(Query * queryPack, ui8 player, const boost::function<void(ui32)> &callback)
void CGameHandler::prepareNewQuery(Query * queryPack, TPlayerColor player, const boost::function<void(ui32)> &callback)
{
boost::unique_lock<boost::recursive_mutex> lock(gsm);
tlog4 << "Creating a query for player " << (int)player << " with ID=" << QID << std::endl;
@ -2225,14 +2222,14 @@ void CGameHandler::prepareNewQuery(Query * queryPack, ui8 player, const boost::f
QID++;
}
void CGameHandler::applyAndAsk( Query * sel, ui8 player, boost::function<void(ui32)> &callback )
void CGameHandler::applyAndAsk( Query * sel, TPlayerColor player, boost::function<void(ui32)> &callback )
{
boost::unique_lock<boost::recursive_mutex> lock(gsm);
prepareNewQuery(sel, player, callback);
sendAndApply(sel);
}
void CGameHandler::ask( Query * sel, ui8 player, const CFunctionList<void(ui32)> &callback )
void CGameHandler::ask( Query * sel, TPlayerColor player, const CFunctionList<void(ui32)> &callback )
{
boost::unique_lock<boost::recursive_mutex> lock(gsm);
prepareNewQuery(sel, player, callback);
@ -2347,7 +2344,7 @@ void CGameHandler::close()
//exit(0);
}
bool CGameHandler::arrangeStacks( si32 id1, si32 id2, ui8 what, ui8 p1, ui8 p2, si32 val, ui8 player )
bool CGameHandler::arrangeStacks( si32 id1, si32 id2, ui8 what, ui8 p1, ui8 p2, si32 val, TPlayerColor player )
{
const CArmedInstance *s1 = static_cast<CArmedInstance*>(gs->map->objects[id1].get()),
*s2 = static_cast<CArmedInstance*>(gs->map->objects[id2].get());
@ -3075,7 +3072,7 @@ bool CGameHandler::buySecSkill( const IMarket *m, const CGHeroInstance *h, Secon
return true;
}
bool CGameHandler::tradeResources(const IMarket *market, ui32 val, ui8 player, ui32 id1, ui32 id2)
bool CGameHandler::tradeResources(const IMarket *market, ui32 val, TPlayerColor player, ui32 id1, ui32 id2)
{
int r1 = gs->getPlayer(player)->resources[id1],
r2 = gs->getPlayer(player)->resources[id2];
@ -3196,7 +3193,7 @@ bool CGameHandler::setFormation( si32 hid, ui8 formation )
return true;
}
bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, ui8 player)
bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, TPlayerColor player)
{
const PlayerState *p = gs->getPlayer(player);
const CGTownInstance *t = gs->getTown(obj->id);
@ -3270,7 +3267,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, ui8 player)
return true;
}
bool CGameHandler::queryReply(ui32 qid, ui32 answer, ui8 player)
bool CGameHandler::queryReply(ui32 qid, ui32 answer, TPlayerColor player)
{
boost::unique_lock<boost::recursive_mutex> lock(gsm);
states.removeQuery(player, qid);
@ -3517,7 +3514,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
}
//ballista & artillery handling
if(destStack->alive() && stack->getCreature()->idNumber == 146)
if(destStack->alive() && stack->getCreature()->idNumber == CreatureID::BALLISTA)
{
BattleAttack bat2;
bat2.flags |= BattleAttack::SHOT;
@ -3888,7 +3885,7 @@ void CGameHandler::playerMessage( TPlayerColor player, const std::string &messag
else if(message == "vcmiglorfindel") //selected hero gains a new level
{
CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection);
changePrimSkill(hero->id, PrimarySkill::EXPERIENCE, VLC->heroh->reqExp(hero->level+1) - VLC->heroh->reqExp(hero->level));
changePrimSkill(hero, PrimarySkill::EXPERIENCE, VLC->heroh->reqExp(hero->level+1) - VLC->heroh->reqExp(hero->level));
}
else if(message == "vcmisilmaril") //player wins
{
@ -4542,7 +4539,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
if(st->hasBonusOfType(Bonus::POISON))
{
const Bonus * b = st->getBonusLocalFirst(Selector::source(Bonus::SPELL_EFFECT, 71) && Selector::type(Bonus::STACK_HEALTH));
const Bonus * b = st->getBonusLocalFirst(Selector::source(Bonus::SPELL_EFFECT, Spells::POISON) && Selector::type(Bonus::STACK_HEALTH));
if (b) //TODO: what if not?...
{
bte.val = std::max (b->val - 10, -(st->valOfBonuses(Bonus::POISON)));
@ -4833,7 +4830,7 @@ bool CGameHandler::complain( const std::string &problem )
return true;
}
ui32 CGameHandler::getQueryResult( ui8 player, int queryID )
ui32 CGameHandler::getQueryResult( TPlayerColor player, int queryID )
{
//TODO: write
return 0;
@ -5059,12 +5056,12 @@ void CGameHandler::checkLossVictory( TPlayerColor player )
{
auto hlp = p->heroes;
for (auto i = hlp.cbegin(); i != hlp.cend(); i++) //eliminate heroes
removeObject((*i)->id);
removeObject(*i);
for (auto i = gs->map->objects.cbegin(); i != gs->map->objects.cend(); i++) //unflag objs
{
if(*i && (*i)->tempOwner == player)
setOwner((**i).id,GameConstants::NEUTRAL_PLAYER);
setOwner(*i,GameConstants::NEUTRAL_PLAYER);
}
//eliminating one player may cause victory of another:
@ -5629,7 +5626,7 @@ bool CGameHandler::sacrificeCreatures(const IMarket *market, const CGHeroInstanc
int dump, exp;
market->getOffer(crid, 0, dump, exp, EMarketMode::CREATURE_EXP);
exp *= count;
changePrimSkill(hero->id, PrimarySkill::EXPERIENCE, hero->calculateXp(exp));
changePrimSkill(hero, PrimarySkill::EXPERIENCE, hero->calculateXp(exp));
return true;
}
@ -5647,7 +5644,7 @@ bool CGameHandler::sacrificeArtifact(const IMarket * m, const CGHeroInstance * h
m->getOffer(hero->getArtTypeId(slot), 0, dmp, expToGive, EMarketMode::ARTIFACT_EXP);
removeArtifact(al);
changePrimSkill(hero->id, PrimarySkill::EXPERIENCE, expToGive);
changePrimSkill(hero, PrimarySkill::EXPERIENCE, expToGive);
return true;
}
@ -5759,14 +5756,14 @@ void CGameHandler::tryJoiningArmy(const CArmedInstance *src, const CArmedInstanc
}
boost::function<void()> removeOrNot = 0;
if(removeObjWhenFinished)
removeOrNot = boost::bind(&IGameCallback::removeObject,this,src->id);
removeOrNot = boost::bind(&IGameCallback::removeObject,this,src);
showGarrisonDialog(src->id, dst->id, true, removeOrNot); //show garrison window and optionally remove ourselves from map when player ends
}
else //merge
{
moveArmy(src, dst, allowMerging);
if(removeObjWhenFinished)
removeObject(src->id);
removeObject(src);
}
}
@ -5906,7 +5903,7 @@ void CGameHandler::runBattle()
const CGHeroInstance * curOwner = gs->curB->battleGetOwner(next);
if( (next->position < 0 || next->getCreature()->idNumber == 146) //arrow turret or ballista
if( (next->position < 0 || next->getCreature()->idNumber == CreatureID::BALLISTA) //arrow turret or ballista
&& (!curOwner || curOwner->getSecSkillLevel(SecondarySkill::ARTILLERY) == 0)) //hero has no artillery
{
BattleAction attack;
@ -5927,7 +5924,7 @@ void CGameHandler::runBattle()
continue;
}
if(next->getCreature()->idNumber == 145 && (!curOwner || curOwner->getSecSkillLevel(SecondarySkill::BALLISTICS) == 0)) //catapult, hero has no ballistics
if(next->getCreature()->idNumber == CreatureID::CATAPULT && (!curOwner || curOwner->getSecSkillLevel(SecondarySkill::BALLISTICS) == 0)) //catapult, hero has no ballistics
{
BattleAction attack;
static const int wallHexes[] = {50, 183, 182, 130, 62, 29, 12, 95};
@ -5943,7 +5940,7 @@ void CGameHandler::runBattle()
}
if(next->getCreature()->idNumber == 147) //first aid tent
if(next->getCreature()->idNumber == CreatureID::FIRST_AID_TENT)
{
std::vector< const CStack * > possibleStacks;
@ -6155,7 +6152,7 @@ void CGameHandler::spawnWanderingMonsters(CreatureID::CreatureID creatureID)
}
}
bool CGameHandler::isBlockedByQueries(const CPack *pack, int packType, ui8 player)
bool CGameHandler::isBlockedByQueries(const CPack *pack, int packType, TPlayerColor player)
{
//it's always legal to send query reply (we'll check later if it makes sense)
if(packType == typeList.getTypeID<QueryReply>())

View File

@ -100,7 +100,7 @@ public:
std::map<ui32, CFunctionList<void(ui32)> > callbacks; //query id => callback function - for selection and yes/no dialogs
std::map<ui32, std::pair<si32,si32> > allowedExchanges;
bool isBlockedByQueries(const CPack *pack, int packType, ui8 player);
bool isBlockedByQueries(const CPack *pack, int packType, TPlayerColor player);
bool isAllowedExchange(int id1, int id2);
bool isAllowedArrangePack(const ArrangeStacks *pack);
void giveSpells(const CGTownInstance *t, const CGHeroInstance *h);
@ -129,19 +129,19 @@ public:
//////////////////////////////////////////////////////////////////////////
//from IGameCallback
//do sth
void changeSpells(int hid, bool give, const std::set<ui32> &spells) OVERRIDE;
bool removeObject(int objid) OVERRIDE;
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<ui32> &spells) OVERRIDE;
bool removeObject(const CGObjectInstance * obj) OVERRIDE;
void setBlockVis(int objid, bool bv) OVERRIDE;
void setOwner(int objid, ui8 owner) OVERRIDE;
void setOwner(const CGObjectInstance * obj, TPlayerColor owner) OVERRIDE;
void setHoverName(int objid, MetaString * name) OVERRIDE;
void changePrimSkill(int ID, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) OVERRIDE;
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) OVERRIDE;
void changeSecSkill(int ID, SecondarySkill::SecondarySkill which, int val, bool abs=false) OVERRIDE;
//void showInfoDialog(InfoWindow *iw) OVERRIDE;
void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback) OVERRIDE;
ui32 showBlockingDialog(BlockingDialog *iw) OVERRIDE; //synchronous version of above
void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) OVERRIDE;
void showThievesGuildWindow(int player, int requestingObjId) OVERRIDE;
void giveResource(int player, Res::ERes which, int val) OVERRIDE;
void giveResource(TPlayerColor player, Res::ERes which, int val) OVERRIDE;
void giveCreatures(const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) OVERRIDE;
void takeCreatures(int objid, const std::vector<CStackBasicDescriptor> &creatures) OVERRIDE;
@ -161,18 +161,18 @@ public:
bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) OVERRIDE;
void showCompInfo(ShowInInfobox * comp) OVERRIDE;
void heroVisitCastle(int obj, int heroID) OVERRIDE;
void stopHeroVisitCastle(int obj, int heroID) OVERRIDE;
void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) OVERRIDE;
void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) OVERRIDE;
//bool removeArtifact(const CArtifact* art, int hid) OVERRIDE;
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, boost::function<void(BattleResult*)> cb = 0, const CGTownInstance *town = NULL) OVERRIDE; //use hero=NULL for no hero
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false) OVERRIDE; //if any of armies is hero, hero will be used
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false) OVERRIDE; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle//void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb) OVERRIDE; //for hero<=>neutral army
void setAmount(int objid, ui32 val) OVERRIDE;
bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255) OVERRIDE;
bool moveHero(si32 hid, int3 dst, ui8 instant, TPlayerColor asker = GameConstants::NEUTRAL_PLAYER) OVERRIDE;
void giveHeroBonus(GiveBonus * bonus) OVERRIDE;
void setMovePoints(SetMovePoints * smp) OVERRIDE;
void setManaPoints(int hid, int val) OVERRIDE;
void giveHero(int id, int player) OVERRIDE;
void giveHero(int id, TPlayerColor player) OVERRIDE;
void changeObjPos(int objid, int3 newPos, ui8 flags) OVERRIDE;
void heroExchange(si32 hero1, si32 hero2) OVERRIDE;
//////////////////////////////////////////////////////////////////////////
@ -180,7 +180,7 @@ public:
void setPortalDwelling(const CGTownInstance * town, bool forced, bool clear);
bool tryAttackingGuard(const int3 &guardPos, const CGHeroInstance * h);
void visitObjectOnTile(const TerrainTile &t, const CGHeroInstance * h);
bool teleportHero(si32 hid, si32 dstid, ui8 source, ui8 asker = 255);
bool teleportHero(si32 hid, si32 dstid, ui8 source, TPlayerColor asker = GameConstants::NEUTRAL_PLAYER);
void vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h);
void levelUpHero(int ID, SecondarySkill::SecondarySkill skill);//handle client respond and send one more request if needed
void levelUpHero(int ID);//initial call - check if hero have remaining levelups & handle them
@ -204,11 +204,11 @@ public:
void stackTurnTrigger(const CStack * stack);
void handleDamageFromObstacle(const CObstacleInstance &obstacle, const CStack * curStack); //checks if obstacle is land mine and handles possible consequences
void removeObstacle(const CObstacleInstance &obstacle);
bool queryReply( ui32 qid, ui32 answer, ui8 player );
bool hireHero( const CGObjectInstance *obj, ui8 hid, ui8 player );
bool queryReply( ui32 qid, ui32 answer, TPlayerColor player );
bool hireHero( const CGObjectInstance *obj, ui8 hid, TPlayerColor player );
bool buildBoat( ui32 objid );
bool setFormation( si32 hid, ui8 formation );
bool tradeResources(const IMarket *market, ui32 val, ui8 player, ui32 id1, ui32 id2);
bool tradeResources(const IMarket *market, ui32 val, TPlayerColor player, ui32 id1, ui32 id2);
bool sacrificeCreatures(const IMarket *market, const CGHeroInstance *hero, TSlot slot, ui32 count);
bool sendResources(ui32 val, TPlayerColor player, Res::ERes r1, TPlayerColor r2);
bool sellCreatures(ui32 count, const IMarket *market, const CGHeroInstance * hero, ui32 slot, Res::ERes resourceID);
@ -225,7 +225,7 @@ public:
bool buildStructure(si32 tid, si32 bid, bool force=false);//force - for events: no cost, no checkings
bool razeStructure(si32 tid, si32 bid);
bool disbandCreature( si32 id, ui8 pos );
bool arrangeStacks( si32 id1, si32 id2, ui8 what, ui8 p1, ui8 p2, si32 val, ui8 player);
bool arrangeStacks( si32 id1, si32 id2, ui8 what, ui8 p1, ui8 p2, si32 val, TPlayerColor player);
void save(const std::string &fname);
void close();
void handleTimeEvents();
@ -245,9 +245,9 @@ public:
ui32 getQueryResult(TPlayerColor player, int queryID);
void sendMessageToAll(const std::string &message);
void sendMessageTo(CConnection &c, const std::string &message);
void applyAndAsk(Query * sel, ui8 player, boost::function<void(ui32)> &callback);
void prepareNewQuery(Query * queryPack, ui8 player, const boost::function<void(ui32)> &callback = 0); //generates unique query id and writes it to the pack; blocks the player till query is answered (then callback is called)
void ask(Query * sel, ui8 player, const CFunctionList<void(ui32)> &callback);
void applyAndAsk(Query * sel, TPlayerColor player, boost::function<void(ui32)> &callback);
void prepareNewQuery(Query * queryPack, TPlayerColor player, const boost::function<void(ui32)> &callback = 0); //generates unique query id and writes it to the pack; blocks the player till query is answered (then callback is called)
void ask(Query * sel, TPlayerColor player, const CFunctionList<void(ui32)> &callback);
void sendToAllClients(CPackForClient * info);
void sendAndApply(CPackForClient * info);
void applyAndSend(CPackForClient * info);

View File

@ -79,7 +79,7 @@ bool EndTurn::applyGh( CGameHandler *gh )
bool DismissHero::applyGh( CGameHandler *gh )
{
ERROR_IF_NOT_OWNS(hid);
return gh->removeObject(hid);
return gh->removeObject(gh->getObj(hid));
}
bool MoveHero::applyGh( CGameHandler *gh )