mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Moved FoW management from CGObjectInstance to callback
This commit is contained in:
parent
5ebc0e8614
commit
ad632d1e8a
@ -218,6 +218,9 @@ public:
|
||||
void sendAndApply(CPackForClient * info) override {};
|
||||
void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override {};
|
||||
|
||||
void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) override {}
|
||||
void changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide) override {}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
friend class CCallback; //handling players actions
|
||||
friend class CBattleCallback; //handling players actions
|
||||
|
@ -1637,7 +1637,7 @@ void CGameState::initFogOfWar()
|
||||
if(!obj || !vstd::contains(elem.second.players, obj->tempOwner)) continue; //not a flagged object
|
||||
|
||||
std::unordered_set<int3, ShashInt3> tiles;
|
||||
obj->getSightTiles(tiles);
|
||||
getTilesInRange(tiles, obj->getSightCenter(), obj->getSightRadious(), obj->tempOwner, 1);
|
||||
for(int3 tile : tiles)
|
||||
{
|
||||
elem.second.fogOfWarMap[tile.x][tile.y][tile.z] = 1;
|
||||
|
@ -93,6 +93,8 @@ public:
|
||||
virtual void sendAndApply(CPackForClient * info)=0;
|
||||
virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
|
||||
virtual void addQuest(int player, QuestInfo & quest){};
|
||||
virtual void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) = 0;
|
||||
virtual void changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide) = 0;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CNonConstInfoCallback : public CPrivilagedInfoCallback
|
||||
|
@ -177,7 +177,7 @@ DLL_LINKAGE void FoWChange::applyGs( CGameState *gs )
|
||||
case Obj::TOWN:
|
||||
case Obj::ABANDONED_MINE:
|
||||
if(vstd::contains(team->players, o->tempOwner)) //check owned observators
|
||||
o->getSightTiles(tilesRevealed);
|
||||
gs->getTilesInRange(tiles, o->getSightCenter(), o->getSightRadious(), o->tempOwner, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1007,7 +1007,7 @@ void CGTownInstance::battleFinished(const CGHeroInstance *hero, const BattleResu
|
||||
FoWChange fw;
|
||||
fw.player = hero->tempOwner;
|
||||
fw.mode = 1;
|
||||
getSightTiles (fw.tiles); //update visibility for castle structures
|
||||
cb->getTilesInRange(fw.tiles, getSightCenter(), getSightRadious(), tempOwner, 1);
|
||||
cb->sendAndApply (&fw);
|
||||
}
|
||||
}
|
||||
|
@ -246,42 +246,14 @@ void CGObjectInstance::setPropertyDer( ui8 what, ui32 val )
|
||||
|
||||
int3 CGObjectInstance::getSightCenter() const
|
||||
{
|
||||
//return vistiable tile if possible
|
||||
for(int i=0; i < 8; i++)
|
||||
for(int j=0; j < 6; j++)
|
||||
if(visitableAt(i,j))
|
||||
return(pos + int3(i-7, j-5, 0));
|
||||
return pos;
|
||||
return visitablePos();
|
||||
}
|
||||
|
||||
int CGObjectInstance::getSightRadious() const
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
void CGObjectInstance::getSightTiles(std::unordered_set<int3, ShashInt3> &tiles) const //returns reference to the set
|
||||
{
|
||||
cb->getTilesInRange(tiles, getSightCenter(), getSightRadious(), tempOwner, 1);
|
||||
}
|
||||
|
||||
void CGObjectInstance::hideTiles(PlayerColor ourplayer, int radius) const
|
||||
{
|
||||
for (auto i = cb->gameState()->teams.begin(); i != cb->gameState()->teams.end(); i++)
|
||||
{
|
||||
if ( !vstd::contains(i->second.players, ourplayer ))//another team
|
||||
{
|
||||
for (auto & elem : i->second.players)
|
||||
if ( cb->getPlayer(elem)->status == EPlayerStatus::INGAME )//seek for living player (if any)
|
||||
{
|
||||
FoWChange fw;
|
||||
fw.mode = 0;
|
||||
fw.player = elem;
|
||||
cb->getTilesInRange (fw.tiles, pos, radius, (elem), -1);
|
||||
cb->sendAndApply (&fw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int3 CGObjectInstance::getVisitableOffset() const
|
||||
{
|
||||
for(int y = 0; y < appearance.getHeight(); y++)
|
||||
|
@ -121,7 +121,7 @@ public:
|
||||
PlayerColor getOwner() const;
|
||||
void setOwner(PlayerColor ow);
|
||||
|
||||
/// APPEARANCE ACCESSORS ///
|
||||
/** APPEARANCE ACCESSORS **/
|
||||
|
||||
int getWidth() const; //returns width of object graphic in tiles
|
||||
int getHeight() const; //returns height of object graphic in tiles
|
||||
@ -133,14 +133,7 @@ public:
|
||||
std::set<int3> getBlockedOffsets() const; //returns set of relative positions blocked by this object
|
||||
bool isVisitable() const; //returns true if object is visitable
|
||||
|
||||
/// HELPERS THAT SHOULD BE REMOVED ///
|
||||
|
||||
/// fills set with tiles which are visible from this object. TODO: remove?
|
||||
void getSightTiles(std::unordered_set<int3, ShashInt3> &tiles) const;
|
||||
/// Hides tiles visible for any player but ours. TODO: move to callback/game state?
|
||||
void hideTiles(PlayerColor ourplayer, int radius) const;
|
||||
|
||||
/// VIRTUAL METHODS ///
|
||||
/** VIRTUAL METHODS **/
|
||||
|
||||
/// Returns true if player can pass through visitable tiles of this object
|
||||
virtual bool passableFor(PlayerColor color) const;
|
||||
@ -154,7 +147,7 @@ public:
|
||||
/// Called mostly during map randomization to turn random object into a regular one (e.g. "Random Monster" into "Pikeman")
|
||||
virtual void setType(si32 ID, si32 subID);
|
||||
|
||||
///IObjectInterface OVERRIDES
|
||||
/** OVERRIDES OF IObjectInterface **/
|
||||
|
||||
void initObj() override;
|
||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||
|
@ -1048,7 +1048,12 @@ void CGObservatory::onHeroVisit( const CGHeroInstance * h ) const
|
||||
case Obj::COVER_OF_DARKNESS:
|
||||
{
|
||||
iw.text.addTxt (MetaString::ADVOB_TXT, 31);
|
||||
hideTiles(h->tempOwner, 20);
|
||||
for (auto player : cb->gameState()->players)
|
||||
{
|
||||
if (cb->getPlayerStatus(player.first) == EPlayerStatus::INGAME &&
|
||||
cb->getPlayerRelations(player.first, h->tempOwner) == PlayerRelations::ENEMIES)
|
||||
cb->changeFogOfWar(visitablePos(), 20, player.first, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1351,9 +1351,13 @@ void CGameHandler::newTurn()
|
||||
}
|
||||
if (t->hasBonusOfType (Bonus::DARKNESS))
|
||||
{
|
||||
t->hideTiles(t->getOwner(), t->getBonusLocalFirst(Selector::type(Bonus::DARKNESS))->val);
|
||||
for (auto player : gameState()->players)
|
||||
{
|
||||
if (getPlayerStatus(player.first) == EPlayerStatus::INGAME &&
|
||||
getPlayerRelations(player.first, t->tempOwner) == PlayerRelations::ENEMIES)
|
||||
changeFogOfWar(t->visitablePos(), t->getBonusLocalFirst(Selector::type(Bonus::DARKNESS))->val, player.first, true);
|
||||
}
|
||||
}
|
||||
//unhiding what shouldn't be hidden? //that's handled in netpacks client
|
||||
}
|
||||
|
||||
if(newMonth)
|
||||
@ -2523,7 +2527,7 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
|
||||
FoWChange fw;
|
||||
fw.player = t->tempOwner;
|
||||
fw.mode = 1;
|
||||
t->getSightTiles(fw.tiles);
|
||||
getTilesInRange(fw.tiles, t->getSightCenter(), t->getSightRadious(), t->tempOwner, 1);
|
||||
sendAndApply(&fw);
|
||||
|
||||
if(t->visitingHero)
|
||||
@ -6252,6 +6256,22 @@ void CGameHandler::removeAfterVisit(const CGObjectInstance *object)
|
||||
assert("This function needs to be called during the object visit!");
|
||||
}
|
||||
|
||||
void CGameHandler::changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide)
|
||||
{
|
||||
std::unordered_set<int3, ShashInt3> tiles;
|
||||
getTilesInRange(tiles, center, radius, player, hide? -1 : 1);
|
||||
changeFogOfWar(tiles, player, hide);
|
||||
}
|
||||
|
||||
void CGameHandler::changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide)
|
||||
{
|
||||
FoWChange fow;
|
||||
fow.tiles = tiles;
|
||||
fow.player = player;
|
||||
fow.mode = hide? 0 : 1;
|
||||
sendAndApply(&fow);
|
||||
}
|
||||
|
||||
bool CGameHandler::isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero)
|
||||
{
|
||||
if(auto topQuery = queries.topQuery(hero->getOwner()))
|
||||
|
@ -174,6 +174,8 @@ public:
|
||||
void changeObjPos(ObjectInstanceID objid, int3 newPos, ui8 flags) override;
|
||||
void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override;
|
||||
|
||||
void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) override;
|
||||
void changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide) override;
|
||||
|
||||
bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero) override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user