mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Remove ConstTransitivePtr from hero and town instances
This commit is contained in:
@@ -595,16 +595,16 @@ HeroSlots::HeroSlots(const CGTownInstance * Town, Point garrPos, Point visitPos,
|
||||
garr(Garrison)
|
||||
{
|
||||
OBJECT_CONSTRUCTION;
|
||||
garrisonedHero = std::make_shared<CHeroGSlot>(garrPos.x, garrPos.y, 0, town->garrisonHero, this);
|
||||
visitingHero = std::make_shared<CHeroGSlot>(visitPos.x, visitPos.y, 1, town->visitingHero, this);
|
||||
garrisonedHero = std::make_shared<CHeroGSlot>(garrPos.x, garrPos.y, 0, town->getGarrisonHero(), this);
|
||||
visitingHero = std::make_shared<CHeroGSlot>(visitPos.x, visitPos.y, 1, town->getVisitingHero(), this);
|
||||
}
|
||||
|
||||
HeroSlots::~HeroSlots() = default;
|
||||
|
||||
void HeroSlots::update()
|
||||
{
|
||||
garrisonedHero->set(town->garrisonHero);
|
||||
visitingHero->set(town->visitingHero);
|
||||
garrisonedHero->set(town->getGarrisonHero());
|
||||
visitingHero->set(town->getVisitingHero());
|
||||
}
|
||||
|
||||
void HeroSlots::swapArmies()
|
||||
@@ -612,9 +612,9 @@ void HeroSlots::swapArmies()
|
||||
bool allow = true;
|
||||
|
||||
//moving hero out of town - check if it is allowed
|
||||
if (town->garrisonHero)
|
||||
if (town->getGarrisonHero())
|
||||
{
|
||||
if (!town->visitingHero && GAME->interface()->cb->howManyHeroes(false) >= GAME->interface()->cb->getSettings().getInteger(EGameSettings::HEROES_PER_PLAYER_ON_MAP_CAP))
|
||||
if (!town->getVisitingHero() && GAME->interface()->cb->howManyHeroes(false) >= GAME->interface()->cb->getSettings().getInteger(EGameSettings::HEROES_PER_PLAYER_ON_MAP_CAP))
|
||||
{
|
||||
std::string text = LIBRARY->generaltexth->translate("core.genrltxt.18"); //You already have %d adventuring heroes under your command.
|
||||
boost::algorithm::replace_first(text,"%d",std::to_string(GAME->interface()->cb->howManyHeroes(false)));
|
||||
@@ -622,7 +622,7 @@ void HeroSlots::swapArmies()
|
||||
GAME->interface()->showInfoDialog(text, std::vector<std::shared_ptr<CComponent>>(), soundBase::sound_todo);
|
||||
allow = false;
|
||||
}
|
||||
else if (town->garrisonHero->stacksCount() == 0)
|
||||
else if (town->getGarrisonHero()->stacksCount() == 0)
|
||||
{
|
||||
//This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside.
|
||||
GAME->interface()->showInfoDialog(LIBRARY->generaltexth->translate("core.genrltxt.19"), {}, soundBase::sound_todo);
|
||||
@@ -630,9 +630,9 @@ void HeroSlots::swapArmies()
|
||||
}
|
||||
}
|
||||
|
||||
if(!town->garrisonHero && town->visitingHero) //visiting => garrison, merge armies: town army => hero army
|
||||
if(!town->getGarrisonHero() && town->getVisitingHero()) //visiting => garrison, merge armies: town army => hero army
|
||||
{
|
||||
if(!town->visitingHero->canBeMergedWith(*town))
|
||||
if(!town->getVisitingHero()->canBeMergedWith(*town))
|
||||
{
|
||||
GAME->interface()->showInfoDialog(LIBRARY->generaltexth->allTexts[275], std::vector<std::shared_ptr<CComponent>>(), soundBase::sound_todo);
|
||||
allow = false;
|
||||
@@ -809,10 +809,10 @@ void CCastleBuildings::removeBuilding(BuildingID building)
|
||||
|
||||
const CGHeroInstance * CCastleBuildings::getHero()
|
||||
{
|
||||
if(town->visitingHero)
|
||||
return town->visitingHero;
|
||||
if(town->getVisitingHero())
|
||||
return town->getVisitingHero();
|
||||
else
|
||||
return town->garrisonHero;
|
||||
return town->getGarrisonHero();
|
||||
}
|
||||
|
||||
void CCastleBuildings::buildingClicked(BuildingID building)
|
||||
@@ -983,7 +983,7 @@ bool CCastleBuildings::buildingTryActivateCustomUI(BuildingID buildingToTest, Bu
|
||||
|
||||
void CCastleBuildings::enterRewardable(BuildingID building)
|
||||
{
|
||||
if (town->visitingHero == nullptr)
|
||||
if (town->getVisitingHero() == nullptr)
|
||||
{
|
||||
MetaString message;
|
||||
message.appendTextID("core.genrltxt.273"); // only visiting heroes may visit %s
|
||||
@@ -993,7 +993,7 @@ void CCastleBuildings::enterRewardable(BuildingID building)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (town->rewardableBuildings.at(building)->wasVisited(town->visitingHero))
|
||||
if (town->rewardableBuildings.at(building)->wasVisited(town->getVisitingHero()))
|
||||
enterBuilding(building);
|
||||
else
|
||||
GAME->interface()->cb->visitTownBuilding(town, building);
|
||||
@@ -1002,7 +1002,7 @@ void CCastleBuildings::enterRewardable(BuildingID building)
|
||||
|
||||
void CCastleBuildings::enterBlacksmith(BuildingID building, ArtifactID artifactID)
|
||||
{
|
||||
const CGHeroInstance *hero = town->visitingHero;
|
||||
const CGHeroInstance *hero = town->getVisitingHero();
|
||||
if(!hero)
|
||||
{
|
||||
GAME->interface()->showInfoDialog(boost::str(boost::format(LIBRARY->generaltexth->allTexts[273]) % town->getTown()->buildings.find(building)->second->getNameTranslated()));
|
||||
@@ -1040,7 +1040,7 @@ void CCastleBuildings::enterBuilding(BuildingID building)
|
||||
|
||||
void CCastleBuildings::enterCastleGate(BuildingID building)
|
||||
{
|
||||
if (!town->visitingHero)
|
||||
if (!town->getVisitingHero())
|
||||
{
|
||||
GAME->interface()->showInfoDialog(LIBRARY->generaltexth->allTexts[126]);
|
||||
return;//only visiting hero can use castle gates
|
||||
@@ -1051,7 +1051,7 @@ void CCastleBuildings::enterCastleGate(BuildingID building)
|
||||
for(auto & Town : Towns)
|
||||
{
|
||||
const CGTownInstance *t = Town;
|
||||
if (t->id != this->town->id && t->visitingHero == nullptr && //another town, empty and this is
|
||||
if (t->id != this->town->id && t->getVisitingHero() == nullptr && //another town, empty and this is
|
||||
t->getFactionID() == town->getFactionID() && //the town of the same faction
|
||||
t->hasBuilt(BuildingSubID::CASTLE_GATE)) //and the town has a castle gate
|
||||
{
|
||||
@@ -1169,7 +1169,7 @@ void CCastleBuildings::enterMagesGuild()
|
||||
|
||||
void CCastleBuildings::enterTownHall()
|
||||
{
|
||||
if(town->visitingHero && town->visitingHero->hasArt(ArtifactID::GRAIL) &&
|
||||
if(town->getVisitingHero() && town->getVisitingHero()->hasArt(ArtifactID::GRAIL) &&
|
||||
!town->hasBuilt(BuildingID::GRAIL)) //hero has grail, but town does not have it
|
||||
{
|
||||
if(!vstd::contains(town->forbiddenBuildings, BuildingID::GRAIL))
|
||||
@@ -1427,7 +1427,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
|
||||
center();
|
||||
updateShadow();
|
||||
|
||||
garr = std::make_shared<CGarrisonInt>(Point(305, 387), 4, Point(0,96), town->getUpperArmy(), town->visitingHero);
|
||||
garr = std::make_shared<CGarrisonInt>(Point(305, 387), 4, Point(0,96), town->getUpperArmy(), town->getVisitingHero());
|
||||
garr->setRedrawParent(true);
|
||||
|
||||
heroes = std::make_shared<HeroSlots>(town, Point(241, 387), Point(241, 483), garr, true);
|
||||
@@ -1476,7 +1476,7 @@ CCastleInterface::~CCastleInterface()
|
||||
void CCastleInterface::updateGarrisons()
|
||||
{
|
||||
garr->setArmy(town->getUpperArmy(), EGarrisonType::UPPER);
|
||||
garr->setArmy(town->visitingHero, EGarrisonType::LOWER);
|
||||
garr->setArmy(town->getVisitingHero(), EGarrisonType::LOWER);
|
||||
garr->recreateSlots();
|
||||
heroes->update();
|
||||
|
||||
@@ -1485,15 +1485,15 @@ void CCastleInterface::updateGarrisons()
|
||||
|
||||
bool CCastleInterface::holdsGarrison(const CArmedInstance * army)
|
||||
{
|
||||
return army == town || army == town->getUpperArmy() || army == town->visitingHero;
|
||||
return army == town || army == town->getUpperArmy() || army == town->getVisitingHero();
|
||||
}
|
||||
|
||||
void CCastleInterface::close()
|
||||
{
|
||||
if(town->tempOwner == GAME->interface()->playerID) //we may have opened window for an allied town
|
||||
{
|
||||
if(town->visitingHero && town->visitingHero->tempOwner == GAME->interface()->playerID)
|
||||
GAME->interface()->localState->setSelection(town->visitingHero);
|
||||
if(town->getVisitingHero() && town->getVisitingHero()->tempOwner == GAME->interface()->playerID)
|
||||
GAME->interface()->localState->setSelection(town->getVisitingHero());
|
||||
else
|
||||
GAME->interface()->localState->setSelection(town);
|
||||
}
|
||||
@@ -1503,9 +1503,9 @@ void CCastleInterface::close()
|
||||
void CCastleInterface::castleTeleport(int where)
|
||||
{
|
||||
const CGTownInstance * dest = GAME->interface()->cb->getTown(ObjectInstanceID(where));
|
||||
GAME->interface()->localState->setSelection(town->visitingHero);//according to assert(ho == adventureInt->selection) in the eraseCurrentPathOf
|
||||
GAME->interface()->cb->teleportHero(town->visitingHero, dest);
|
||||
GAME->interface()->localState->erasePath(town->visitingHero);
|
||||
GAME->interface()->localState->setSelection(town->getVisitingHero());//according to assert(ho == adventureInt->selection) in the eraseCurrentPathOf
|
||||
GAME->interface()->cb->teleportHero(town->getVisitingHero(), dest);
|
||||
GAME->interface()->localState->erasePath(town->getVisitingHero());
|
||||
}
|
||||
|
||||
void CCastleInterface::townChange()
|
||||
@@ -1605,22 +1605,22 @@ void CCastleInterface::keyPressed(EShortcut key)
|
||||
case EShortcut::TOWN_OPEN_THIEVES_GUILD:
|
||||
break;
|
||||
case EShortcut::TOWN_OPEN_HERO_EXCHANGE:
|
||||
if (town->visitingHero && town->garrisonHero)
|
||||
GAME->interface()->showHeroExchange(town->visitingHero->id, town->garrisonHero->id);
|
||||
if (town->getVisitingHero() && town->getGarrisonHero())
|
||||
GAME->interface()->showHeroExchange(town->getVisitingHero()->id, town->getGarrisonHero()->id);
|
||||
break;
|
||||
case EShortcut::TOWN_OPEN_HERO:
|
||||
if (town->visitingHero)
|
||||
GAME->interface()->openHeroWindow(town->visitingHero);
|
||||
else if (town->garrisonHero)
|
||||
GAME->interface()->openHeroWindow(town->garrisonHero);
|
||||
if (town->getVisitingHero())
|
||||
GAME->interface()->openHeroWindow(town->getVisitingHero());
|
||||
else if (town->getGarrisonHero())
|
||||
GAME->interface()->openHeroWindow(town->getGarrisonHero());
|
||||
break;
|
||||
case EShortcut::TOWN_OPEN_VISITING_HERO:
|
||||
if (town->visitingHero)
|
||||
GAME->interface()->openHeroWindow(town->visitingHero);
|
||||
if (town->getVisitingHero())
|
||||
GAME->interface()->openHeroWindow(town->getVisitingHero());
|
||||
break;
|
||||
case EShortcut::TOWN_OPEN_GARRISONED_HERO:
|
||||
if (town->garrisonHero)
|
||||
GAME->interface()->openHeroWindow(town->garrisonHero);
|
||||
if (town->getGarrisonHero())
|
||||
GAME->interface()->openHeroWindow(town->getGarrisonHero());
|
||||
break;
|
||||
case EShortcut::TOWN_SWAP_ARMIES:
|
||||
heroes->swapArmies();
|
||||
|
||||
Reference in New Issue
Block a user