1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

All adventure map components now use shared_ptr

This commit is contained in:
Ivan Savenko
2023-02-10 16:26:32 +02:00
parent f8c1c46562
commit cc0c3e5bc9
6 changed files with 150 additions and 134 deletions

View File

@ -13,6 +13,10 @@
#include "adventureMap/CAdvMapInt.h"
#include "adventureMap/mapHandler.h"
#include "adventureMap/CList.h"
#include "adventureMap/CTerrainRect.h"
#include "adventureMap/CInfoBar.h"
#include "adventureMap/CMinimap.h"
#include "battle/BattleInterface.h"
#include "battle/BattleEffectsController.h"
#include "battle/BattleFieldController.h"
@ -251,13 +255,13 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
return;
}
adventureInt->minimap.updateTile(hero->convertToVisitablePos(details.start));
adventureInt->minimap.updateTile(hero->convertToVisitablePos(details.end));
adventureInt->minimap->updateTile(hero->convertToVisitablePos(details.start));
adventureInt->minimap->updateTile(hero->convertToVisitablePos(details.end));
bool directlyAttackingCreature =
details.attackedFrom
&& adventureInt->terrain.currentPath //in case if movement has been canceled in the meantime and path was already erased
&& adventureInt->terrain.currentPath->nodes.size() == 3;//FIXME should be 2 but works nevertheless...
&& adventureInt->terrain->currentPath //in case if movement has been canceled in the meantime and path was already erased
&& adventureInt->terrain->currentPath->nodes.size() == 3;//FIXME should be 2 but works nevertheless...
if(makingTurn && hero->tempOwner == playerID) //we are moving our hero - we may need to update assigned path
{
@ -267,10 +271,10 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
if(details.result == TryMoveHero::TELEPORTATION)
{
if(adventureInt->terrain.currentPath)
if(adventureInt->terrain->currentPath)
{
assert(adventureInt->terrain.currentPath->nodes.size() >= 2);
std::vector<CGPathNode>::const_iterator nodesIt = adventureInt->terrain.currentPath->nodes.end() - 1;
assert(adventureInt->terrain->currentPath->nodes.size() >= 2);
std::vector<CGPathNode>::const_iterator nodesIt = adventureInt->terrain->currentPath->nodes.end() - 1;
if((nodesIt)->coord == hero->convertToVisitablePos(details.start)
&& (nodesIt - 1)->coord == hero->convertToVisitablePos(details.end))
@ -286,8 +290,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
}
}
adventureInt->centerOn(hero, true); //actualizing screen pos
adventureInt->minimap.redraw();
adventureInt->heroList.update(hero);
adventureInt->minimap->redraw();
adventureInt->heroList->update(hero);
return; //teleport - no fancy moving animation
//TODO: smooth disappear / appear effect
}
@ -297,7 +301,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
{
eraseCurrentPathOf(hero, false);
}
else if(adventureInt->terrain.currentPath && hero->pos == details.end) //&& hero is moving
else if(adventureInt->terrain->currentPath && hero->pos == details.end) //&& hero is moving
{
if(details.start != details.end) //so we don't touch path when revisiting with spacebar
removeLastNodeFromPath(hero);
@ -309,7 +313,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
hero->isStanding = true;
stillMoveHero.setn(STOP_MOVE);
GH.totalRedraw();
adventureInt->heroList.update(hero);
adventureInt->heroList->update(hero);
return;
}
@ -333,8 +337,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
}
adventureInt->centerOn(hero); //actualizing screen pos
adventureInt->minimap.redraw();
adventureInt->heroList.redraw();
adventureInt->minimap->redraw();
adventureInt->heroList->redraw();
initMovement(details, hero, hp);
@ -370,8 +374,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
hero->isStanding = true;
//move finished
adventureInt->minimap.redraw();
adventureInt->heroList.update(hero);
adventureInt->minimap->redraw();
adventureInt->heroList->update(hero);
//check if user cancelled movement
{
@ -434,7 +438,7 @@ void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
wanderingHeroes -= hero;
adventureInt->heroList.update(hero);
adventureInt->heroList->update(hero);
if (makingTurn && newSelection)
adventureInt->select(newSelection, true);
else if (adventureInt->selection == hero)
@ -458,7 +462,7 @@ void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
wanderingHeroes.push_back(hero);
adventureInt->heroList.update(hero);
adventureInt->heroList->update(hero);
}
void CPlayerInterface::openTownWindow(const CGTownInstance * town)
{
@ -477,10 +481,10 @@ int3 CPlayerInterface::repairScreenPos(int3 pos)
pos.x = -CGI->mh->frameW;
if (pos.y<-CGI->mh->frameH)
pos.y = -CGI->mh->frameH;
if (pos.x>CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW)
pos.x = CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW;
if (pos.y>CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH)
pos.y = CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH;
if (pos.x>CGI->mh->sizes.x - adventureInt->terrain->tilesw + CGI->mh->frameW)
pos.x = CGI->mh->sizes.x - adventureInt->terrain->tilesw + CGI->mh->frameW;
if (pos.y>CGI->mh->sizes.y - adventureInt->terrain->tilesh + CGI->mh->frameH)
pos.y = CGI->mh->sizes.y - adventureInt->terrain->tilesh + CGI->mh->frameH;
return pos;
}
@ -488,7 +492,7 @@ void CPlayerInterface::activateForSpectator()
{
adventureInt->state = CAdvMapInt::INGAME;
adventureInt->activate();
adventureInt->minimap.activate();
adventureInt->minimap->activate();
}
void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val)
@ -518,13 +522,13 @@ void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero)
EVENT_HANDLER_CALLED_BY_CLIENT;
updateInfo(hero);
if (makingTurn && hero->tempOwner == playerID)
adventureInt->heroList.update(hero);
adventureInt->heroList->update(hero);
}
void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
if (makingTurn && hero->tempOwner == playerID)
adventureInt->heroList.update(hero);
adventureInt->heroList->update(hero);
}
void CPlayerInterface::receivedResource()
{
@ -575,7 +579,7 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
if (town->visitingHero->tempOwner == playerID && !vstd::contains(wanderingHeroes,town->visitingHero)) // our hero
wanderingHeroes.push_back(town->visitingHero);
}
adventureInt->heroList.update();
adventureInt->heroList->update();
adventureInt->updateNextHero(nullptr);
if(castleInt)
@ -681,7 +685,7 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, BuildingID build
}
}
}
adventureInt->townList.update(town);
adventureInt->townList->update(town);
}
void CPlayerInterface::battleStartBefore(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2)
@ -1039,7 +1043,7 @@ void CPlayerInterface::showComp(const Component &comp, std::string message)
waitWhileDialog(); //Fix for mantis #98
CCS->soundh->playSoundFromSet(CCS->soundh->pickupSounds);
adventureInt->infoBar.showComponent(comp, message);
adventureInt->infoBar->showComponent(comp, message);
}
void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component> & components, int soundID)
@ -1197,7 +1201,7 @@ void CPlayerInterface::tileRevealed(const std::unordered_set<int3, ShashInt3> &p
EVENT_HANDLER_CALLED_BY_CLIENT;
//FIXME: wait for dialog? Magi hut/eye would benefit from this but may break other areas
for (auto & po : pos)
adventureInt->minimap.updateTile(po);
adventureInt->minimap->updateTile(po);
if (!pos.empty())
GH.totalRedraw();
}
@ -1206,7 +1210,7 @@ void CPlayerInterface::tileHidden(const std::unordered_set<int3, ShashInt3> &pos
{
EVENT_HANDLER_CALLED_BY_CLIENT;
for (auto & po : pos)
adventureInt->minimap.updateTile(po);
adventureInt->minimap->updateTile(po);
if (!pos.empty())
GH.totalRedraw();
}
@ -1335,7 +1339,7 @@ void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHer
EVENT_HANDLER_CALLED_BY_CLIENT;
auto onEnd = [=](){ cb->selectionMade(0, queryID); };
if (stillMoveHero.get() == DURING_MOVE && adventureInt->terrain.currentPath && adventureInt->terrain.currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons
if (stillMoveHero.get() == DURING_MOVE && adventureInt->terrain->currentPath && adventureInt->terrain->currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons
{
onEnd();
return;
@ -1412,7 +1416,7 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
for(auto & po : pos)
{
if(cb->isVisible(po))
adventureInt->minimap.updateTile(po);
adventureInt->minimap->updateTile(po);
}
if(obj->ID == Obj::TOWN)
{
@ -1421,8 +1425,8 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
else
towns -= obj;
adventureInt->townList.update();
adventureInt->minimap.update();
adventureInt->townList->update();
adventureInt->minimap->update();
}
assert(cb->getTownsInfo().size() == towns.size());
}
@ -1715,8 +1719,8 @@ void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const
}
}
adventureInt->terrain.moveX = (32 - i) * (heroImageNewX - heroImageOldX) / 32;
adventureInt->terrain.moveY = (32 - i) * (heroImageNewY - heroImageOldY) / 32;
adventureInt->terrain->moveX = (32 - i) * (heroImageNewX - heroImageOldX) / 32;
adventureInt->terrain->moveY = (32 - i) * (heroImageNewY - heroImageOldY) / 32;
}
void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &hp, const CGHeroInstance * ho )
@ -1894,14 +1898,14 @@ void CPlayerInterface::eraseCurrentPathOf(const CGHeroInstance * ho, bool checkF
assert(ho == adventureInt->selection);
paths.erase(ho);
adventureInt->terrain.currentPath = nullptr;
adventureInt->terrain->currentPath = nullptr;
adventureInt->updateMoveHero(ho, false);
}
void CPlayerInterface::removeLastNodeFromPath(const CGHeroInstance *ho)
{
adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
if (adventureInt->terrain.currentPath->nodes.size() < 2) //if it was the last one, remove entire path and path with only one tile is not a real path
adventureInt->terrain->currentPath->nodes.erase(adventureInt->terrain->currentPath->nodes.end()-1);
if (adventureInt->terrain->currentPath->nodes.size() < 2) //if it was the last one, remove entire path and path with only one tile is not a real path
eraseCurrentPathOf(ho);
}
@ -1946,8 +1950,8 @@ void CPlayerInterface::acceptTurn()
adventureInt->startTurn();
}
adventureInt->heroList.update();
adventureInt->townList.update();
adventureInt->heroList->update();
adventureInt->townList->update();
const CGHeroInstance * heroToSelect = nullptr;
@ -1972,7 +1976,7 @@ void CPlayerInterface::acceptTurn()
adventureInt->select(wanderingHeroes.front());
//show new day animation and sound on infobar
adventureInt->infoBar.showDate();
adventureInt->infoBar->showDate();
adventureInt->updateNextHero(nullptr);
adventureInt->showAll(screen);
@ -2052,7 +2056,7 @@ void CPlayerInterface::tryDiggging(const CGHeroInstance * h)
void CPlayerInterface::updateInfo(const CGObjectInstance * specific)
{
adventureInt->infoBar.showSelection();
adventureInt->infoBar->showSelection();
}
void CPlayerInterface::battleNewRoundFirst( int round )
@ -2163,14 +2167,14 @@ void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
void CPlayerInterface::artifactPut(const ArtifactLocation &al)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection();
adventureInt->infoBar->showSelection();
askToAssembleArtifact(al);
}
void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection();
adventureInt->infoBar->showSelection();
for(auto isa : GH.listInt)
{
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@ -2184,7 +2188,7 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection();
adventureInt->infoBar->showSelection();
for(auto isa : GH.listInt)
{
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@ -2205,7 +2209,7 @@ void CPlayerInterface::artifactPossibleAssembling(const ArtifactLocation & dst)
void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection();
adventureInt->infoBar->showSelection();
for(auto isa : GH.listInt)
{
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@ -2217,7 +2221,7 @@ void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
{
EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection();
adventureInt->infoBar->showSelection();
for(auto isa : GH.listInt)
{
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@ -2236,7 +2240,7 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player)
}
else
{
adventureInt->infoBar.showSelection();
adventureInt->infoBar->showSelection();
while (GH.listInt.front() != adventureInt && !dynamic_cast<CInfoWindow*>(GH.listInt.front().get())) //don't remove dialogs that expect query answer
GH.popInts(1);
}