mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Refactoring, fixed #1255
This commit is contained in:
@ -2661,7 +2661,7 @@ void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h ) const
|
|||||||
{
|
{
|
||||||
if(!vstd::contains(visitors, h->id))
|
if(!vstd::contains(visitors, h->id))
|
||||||
{
|
{
|
||||||
onNAHeroVisit(h->id, false);
|
onNAHeroVisit (h, false);
|
||||||
switch(ID)
|
switch(ID)
|
||||||
{
|
{
|
||||||
case Obj::TREE_OF_KNOWLEDGE:
|
case Obj::TREE_OF_KNOWLEDGE:
|
||||||
@ -2677,7 +2677,7 @@ void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h ) const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
onNAHeroVisit(h->id, true);
|
onNAHeroVisit(h, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2699,18 +2699,17 @@ void CGVisitableOPH::initObj()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGVisitableOPH::treeSelected( ObjectInstanceID heroID, ui32 result) const
|
void CGVisitableOPH::treeSelected (const CGHeroInstance * h, ui32 result) const
|
||||||
{
|
{
|
||||||
if(result) //player agreed to give res for exp
|
if(result) //player agreed to give res for exp
|
||||||
{
|
{
|
||||||
auto h = cb->getHero(heroID);
|
|
||||||
si64 expToGive = VLC->heroh->reqExp(h->level+1) - VLC->heroh->reqExp(h->level);;
|
si64 expToGive = VLC->heroh->reqExp(h->level+1) - VLC->heroh->reqExp(h->level);;
|
||||||
cb->giveResources(cb->getOwner(heroID), -treePrice);
|
cb->giveResources (h->getOwner(), -treePrice);
|
||||||
cb->changePrimSkill(cb->getHero(heroID), PrimarySkill::EXPERIENCE, expToGive);
|
cb->changePrimSkill (h, PrimarySkill::EXPERIENCE, expToGive);
|
||||||
cb->setObjProperty(id, ObjProperty::VISITORS, heroID.getNum()); //add to the visitors
|
cb->setObjProperty (id, ObjProperty::VISITORS, h->id.getNum()); //add to the visitors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CGVisitableOPH::onNAHeroVisit(ObjectInstanceID heroID, bool alreadyVisited) const
|
void CGVisitableOPH::onNAHeroVisit (const CGHeroInstance * h, bool alreadyVisited) const
|
||||||
{
|
{
|
||||||
Component::EComponentType c_id = Component::PRIM_SKILL; //most used here
|
Component::EComponentType c_id = Component::PRIM_SKILL; //most used here
|
||||||
int subid=0, ot=0, sound = 0;
|
int subid=0, ot=0, sound = 0;
|
||||||
@ -2779,7 +2778,7 @@ void CGVisitableOPH::onNAHeroVisit(ObjectInstanceID heroID, bool alreadyVisited)
|
|||||||
sd.text.addTxt(MetaString::ADVOB_TXT,ot);
|
sd.text.addTxt(MetaString::ADVOB_TXT,ot);
|
||||||
sd.components.push_back(Component(c_id, PrimarySkill::ATTACK, 2, 0));
|
sd.components.push_back(Component(c_id, PrimarySkill::ATTACK, 2, 0));
|
||||||
sd.components.push_back(Component(c_id, PrimarySkill::DEFENSE, 2, 0));
|
sd.components.push_back(Component(c_id, PrimarySkill::DEFENSE, 2, 0));
|
||||||
sd.player = cb->getOwner(heroID);
|
sd.player = h->getOwner();
|
||||||
cb->showBlockingDialog(&sd);
|
cb->showBlockingDialog(&sd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2788,23 +2787,22 @@ void CGVisitableOPH::onNAHeroVisit(ObjectInstanceID heroID, bool alreadyVisited)
|
|||||||
case Obj::STAR_AXIS:
|
case Obj::STAR_AXIS:
|
||||||
case Obj::GARDEN_OF_REVELATION:
|
case Obj::GARDEN_OF_REVELATION:
|
||||||
{
|
{
|
||||||
cb->changePrimSkill(cb->getHero(heroID), static_cast<PrimarySkill::PrimarySkill>(subid), val);
|
cb->changePrimSkill (h, static_cast<PrimarySkill::PrimarySkill>(subid), val);
|
||||||
InfoWindow iw;
|
InfoWindow iw;
|
||||||
iw.soundID = sound;
|
iw.soundID = sound;
|
||||||
iw.components.push_back(Component(c_id, subid, val, 0));
|
iw.components.push_back(Component(c_id, subid, val, 0));
|
||||||
iw.text.addTxt(MetaString::ADVOB_TXT,ot);
|
iw.text.addTxt(MetaString::ADVOB_TXT,ot);
|
||||||
iw.player = cb->getOwner(heroID);
|
iw.player = h->getOwner();
|
||||||
cb->showInfoDialog(&iw);
|
cb->showInfoDialog(&iw);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Obj::LEARNING_STONE: //give exp
|
case Obj::LEARNING_STONE: //give exp
|
||||||
{
|
{
|
||||||
const CGHeroInstance *h = cb->getHero(heroID);
|
|
||||||
val = h->calculateXp(val);
|
val = h->calculateXp(val);
|
||||||
InfoWindow iw;
|
InfoWindow iw;
|
||||||
iw.soundID = sound;
|
iw.soundID = sound;
|
||||||
iw.components.push_back(Component(c_id,subid,val,0));
|
iw.components.push_back (Component(c_id,subid,val,0));
|
||||||
iw.player = cb->getOwner(heroID);
|
iw.player = h->getOwner();
|
||||||
iw.text.addTxt(MetaString::ADVOB_TXT,ot);
|
iw.text.addTxt(MetaString::ADVOB_TXT,ot);
|
||||||
cb->showInfoDialog(&iw);
|
cb->showInfoDialog(&iw);
|
||||||
cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, val);
|
cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, val);
|
||||||
@ -2812,18 +2810,17 @@ void CGVisitableOPH::onNAHeroVisit(ObjectInstanceID heroID, bool alreadyVisited)
|
|||||||
}
|
}
|
||||||
case Obj::TREE_OF_KNOWLEDGE:
|
case Obj::TREE_OF_KNOWLEDGE:
|
||||||
{
|
{
|
||||||
const CGHeroInstance *h = cb->getHero(heroID);
|
val = VLC->heroh->reqExp (h->level + val) - VLC->heroh->reqExp(h->level);
|
||||||
val = VLC->heroh->reqExp(h->level+val) - VLC->heroh->reqExp(h->level);
|
|
||||||
if(!treePrice.nonZero())
|
if(!treePrice.nonZero())
|
||||||
{
|
{
|
||||||
cb->setObjProperty(id, ObjProperty::VISITORS, heroID.getNum()); //add to the visitors
|
cb->setObjProperty (id, ObjProperty::VISITORS, h->id.getNum()); //add to the visitors
|
||||||
InfoWindow iw;
|
InfoWindow iw;
|
||||||
iw.soundID = sound;
|
iw.soundID = sound;
|
||||||
iw.components.push_back(Component(c_id,subid,1,0));
|
iw.components.push_back (Component(c_id,subid,1,0));
|
||||||
iw.player = cb->getOwner(heroID);
|
iw.player = h->getOwner();
|
||||||
iw.text.addTxt(MetaString::ADVOB_TXT,148);
|
iw.text.addTxt (MetaString::ADVOB_TXT,148);
|
||||||
cb->showInfoDialog(&iw);
|
cb->showInfoDialog (&iw);
|
||||||
cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, val);
|
cb->changePrimSkill (h, PrimarySkill::EXPERIENCE, val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2842,16 +2839,15 @@ void CGVisitableOPH::onNAHeroVisit(ObjectInstanceID heroID, bool alreadyVisited)
|
|||||||
|
|
||||||
BlockingDialog sd (true, false);
|
BlockingDialog sd (true, false);
|
||||||
sd.soundID = sound;
|
sd.soundID = sound;
|
||||||
sd.player = cb->getOwner(heroID);
|
sd.player = h->getOwner();
|
||||||
sd.text.addTxt(MetaString::ADVOB_TXT,ot);
|
sd.text.addTxt (MetaString::ADVOB_TXT,ot);
|
||||||
sd.addResourceComponents(treePrice);
|
sd.addResourceComponents (treePrice);
|
||||||
cb->showBlockingDialog(&sd);
|
cb->showBlockingDialog (&sd);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Obj::LIBRARY_OF_ENLIGHTENMENT:
|
case Obj::LIBRARY_OF_ENLIGHTENMENT:
|
||||||
{
|
{
|
||||||
const CGHeroInstance *h = cb->getHero(heroID);
|
|
||||||
int txt_id = 66;
|
int txt_id = 66;
|
||||||
if(h->level < 10 - 2*h->getSecSkillLevel(SecondarySkill::DIPLOMACY)) //not enough level
|
if(h->level < 10 - 2*h->getSecSkillLevel(SecondarySkill::DIPLOMACY)) //not enough level
|
||||||
{
|
{
|
||||||
@ -2859,11 +2855,11 @@ void CGVisitableOPH::onNAHeroVisit(ObjectInstanceID heroID, bool alreadyVisited)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cb->setObjProperty(id, ObjProperty::VISITORS, heroID.getNum()); //add to the visitors
|
cb->setObjProperty(id, ObjProperty::VISITORS, h->id.getNum()); //add to the visitors
|
||||||
cb->changePrimSkill(h,PrimarySkill::ATTACK,2);
|
cb->changePrimSkill (h, PrimarySkill::ATTACK, 2);
|
||||||
cb->changePrimSkill(h,PrimarySkill::DEFENSE,2);
|
cb->changePrimSkill (h, PrimarySkill::DEFENSE, 2);
|
||||||
cb->changePrimSkill(h,PrimarySkill::KNOWLEDGE,2);
|
cb->changePrimSkill (h, PrimarySkill::KNOWLEDGE, 2);
|
||||||
cb->changePrimSkill(h,PrimarySkill::SPELL_POWER,2);
|
cb->changePrimSkill (h, PrimarySkill::SPELL_POWER, 2);
|
||||||
}
|
}
|
||||||
showInfoDialog(h,txt_id,sound);
|
showInfoDialog(h,txt_id,sound);
|
||||||
break;
|
break;
|
||||||
@ -2872,15 +2868,15 @@ void CGVisitableOPH::onNAHeroVisit(ObjectInstanceID heroID, bool alreadyVisited)
|
|||||||
case Obj::SCHOOL_OF_WAR:
|
case Obj::SCHOOL_OF_WAR:
|
||||||
{
|
{
|
||||||
int skill = (ID==Obj::SCHOOL_OF_MAGIC ? 2 : 0);
|
int skill = (ID==Obj::SCHOOL_OF_MAGIC ? 2 : 0);
|
||||||
if(cb->getResource(cb->getOwner(heroID), Res::GOLD) < 1000) //not enough resources
|
if (cb->getResource (h->getOwner(), Res::GOLD) < 1000) //not enough resources
|
||||||
{
|
{
|
||||||
showInfoDialog(heroID,ot+2,sound);
|
showInfoDialog (h->getOwner(), ot+2, sound);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BlockingDialog sd(true,true);
|
BlockingDialog sd(true,true);
|
||||||
sd.soundID = sound;
|
sd.soundID = sound;
|
||||||
sd.player = cb->getOwner(heroID);
|
sd.player = h->getOwner();
|
||||||
sd.text.addTxt(MetaString::ADVOB_TXT,ot);
|
sd.text.addTxt(MetaString::ADVOB_TXT,ot);
|
||||||
sd.components.push_back(Component(c_id, skill, +1, 0));
|
sd.components.push_back(Component(c_id, skill, +1, 0));
|
||||||
sd.components.push_back(Component(c_id, skill+1, +1, 0));
|
sd.components.push_back(Component(c_id, skill+1, +1, 0));
|
||||||
@ -2893,7 +2889,7 @@ void CGVisitableOPH::onNAHeroVisit(ObjectInstanceID heroID, bool alreadyVisited)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ot++;
|
ot++;
|
||||||
showInfoDialog(heroID,ot,sound);
|
showInfoDialog (h->getOwner(),ot,sound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2937,20 +2933,20 @@ const std::string & CGVisitableOPH::getHoverText() const
|
|||||||
hoverName = VLC->generaltexth->names[ID];
|
hoverName = VLC->generaltexth->names[ID];
|
||||||
if(pom >= 0)
|
if(pom >= 0)
|
||||||
hoverName += ("\n" + VLC->generaltexth->xtrainfo[pom]);
|
hoverName += ("\n" + VLC->generaltexth->xtrainfo[pom]);
|
||||||
const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer());
|
const CGHeroInstance *h = cb->getSelectedHero (cb->getCurrentPlayer());
|
||||||
if(h)
|
if(h)
|
||||||
{
|
{
|
||||||
hoverName += "\n\n";
|
hoverName += "\n\n";
|
||||||
bool visited = vstd::contains(visitors,h->id);
|
bool visited = vstd::contains (visitors, h->id);
|
||||||
hoverName += visitedTxt(visited);
|
hoverName += visitedTxt (visited);
|
||||||
}
|
}
|
||||||
return hoverName;
|
return hoverName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGVisitableOPH::arenaSelected( ObjectInstanceID heroID, int primSkill ) const
|
void CGVisitableOPH::arenaSelected(const CGHeroInstance * h, int primSkill ) const
|
||||||
{
|
{
|
||||||
cb->setObjProperty(id, ObjProperty::VISITORS, heroID.getNum()); //add to the visitors
|
cb->setObjProperty(id, ObjProperty::VISITORS, h->id.getNum()); //add to the visitors
|
||||||
cb->changePrimSkill(cb->getHero(heroID), static_cast<PrimarySkill::PrimarySkill>(primSkill-1), 2);
|
cb->changePrimSkill(h, static_cast<PrimarySkill::PrimarySkill>(primSkill-1), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGVisitableOPH::setPropertyDer( ui8 what, ui32 val )
|
void CGVisitableOPH::setPropertyDer( ui8 what, ui32 val )
|
||||||
@ -2959,32 +2955,33 @@ void CGVisitableOPH::setPropertyDer( ui8 what, ui32 val )
|
|||||||
visitors.insert(ObjectInstanceID(val));
|
visitors.insert(ObjectInstanceID(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGVisitableOPH::schoolSelected(ObjectInstanceID heroID, ui32 which) const
|
void CGVisitableOPH::schoolSelected(const CGHeroInstance * h, ui32 which) const
|
||||||
{
|
{
|
||||||
if(!which) //player refused to pay
|
if(!which) //player refused to pay
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int base = (ID == Obj::SCHOOL_OF_MAGIC ? 2 : 0);
|
int base = (ID == Obj::SCHOOL_OF_MAGIC ? 2 : 0);
|
||||||
cb->setObjProperty(id, ObjProperty::VISITORS, heroID.getNum()); //add to the visitors
|
cb->setObjProperty (id, ObjProperty::VISITORS, h->id.getNum()); //add to the visitors
|
||||||
cb->giveResource(cb->getOwner(heroID),Res::GOLD,-1000); //take 1000 gold
|
cb->giveResource (h->getOwner(),Res::GOLD,-1000); //take 1000 gold
|
||||||
cb->changePrimSkill(cb->getHero(heroID), static_cast<PrimarySkill::PrimarySkill>(base + which-1), +1); //give appropriate skill
|
cb->changePrimSkill (h, static_cast<PrimarySkill::PrimarySkill>(base + which-1), +1); //give appropriate skill
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGVisitableOPH::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
|
void CGVisitableOPH::blockingDialogAnswered(const CGHeroInstance *h, ui32 answer) const
|
||||||
{
|
{
|
||||||
switch (ID)
|
switch (ID)
|
||||||
{
|
{
|
||||||
case Obj::ARENA:
|
case Obj::ARENA:
|
||||||
arenaSelected(hero->id, answer);
|
arenaSelected(h, answer);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Obj::TREE_OF_KNOWLEDGE:
|
case Obj::TREE_OF_KNOWLEDGE:
|
||||||
treeSelected(hero->id, answer);
|
treeSelected(h, answer);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Obj::SCHOOL_OF_MAGIC:
|
case Obj::SCHOOL_OF_MAGIC:
|
||||||
case Obj::SCHOOL_OF_WAR:
|
case Obj::SCHOOL_OF_WAR:
|
||||||
schoolSelected(id, answer);
|
schoolSelected(h, answer);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -505,11 +505,11 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void setPropertyDer(ui8 what, ui32 val) override;//synchr
|
void setPropertyDer(ui8 what, ui32 val) override;//synchr
|
||||||
private:
|
private:
|
||||||
void onNAHeroVisit(ObjectInstanceID heroID, bool alreadyVisited) const;
|
void onNAHeroVisit(const CGHeroInstance * h, bool alreadyVisited) const;
|
||||||
///dialog callbacks
|
///dialog callbacks
|
||||||
void treeSelected(ObjectInstanceID heroID, ui32 result) const;
|
void treeSelected(const CGHeroInstance * h, ui32 result) const;
|
||||||
void schoolSelected(ObjectInstanceID heroID, ui32 which) const;
|
void schoolSelected(const CGHeroInstance * h, ui32 which) const;
|
||||||
void arenaSelected(ObjectInstanceID heroID, int primSkill) const;
|
void arenaSelected(const CGHeroInstance * h, int primSkill) const;
|
||||||
};
|
};
|
||||||
class DLL_LINKAGE CGTownBuilding : public IObjectInterface
|
class DLL_LINKAGE CGTownBuilding : public IObjectInterface
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
class CLegacyConfigParser;
|
class CLegacyConfigParser;
|
||||||
class JsonNode;
|
class JsonNode;
|
||||||
class CTown;
|
class CTown;
|
||||||
|
class CFaction;
|
||||||
|
|
||||||
/// a typical building encountered in every castle ;]
|
/// a typical building encountered in every castle ;]
|
||||||
/// this is structure available to both client and server
|
/// this is structure available to both client and server
|
||||||
|
Reference in New Issue
Block a user