bool GraphicAnimation::isVisible(const CViewport &vp, const CPosition &pos) { // invisible graphics always invisible if (!g) { return false; } PixelSize graphicSize(g->Width, g->Height); PixelDiff margin(PixelTileSize.x - 1, PixelTileSize.y - 1); PixelPos position(pos.x, pos.y); Vec2i minPos = Map.MapPixelPosToTilePos(position); Vec2i maxPos = Map.MapPixelPosToTilePos(position + graphicSize + margin); Map.Clamp(minPos); Map.Clamp(maxPos); if (!vp.AnyMapAreaVisibleInViewport(minPos, maxPos)) { return false; } Vec2i p; for (p.x = minPos.x; p.x <= maxPos.x; ++p.x) { for (p.y = minPos.y; p.y <= maxPos.y; ++p.y) { if (ReplayRevealMap || Map.Field(p)->playerInfo.IsTeamVisible(*ThisPlayer)) { return true; } } } return false; }
/** ** Check missile visibility in a given viewport. ** ** @param vp Viewport to be checked. ** @param missile Missile pointer to check if visible. ** ** @return Returns true if visible, false otherwise. */ static int MissileVisibleInViewport(const CViewport &vp, const Missile &missile) { Vec2i boxmin; Vec2i boxmax; GetMissileMapArea(missile, boxmin, boxmax); if (!vp.AnyMapAreaVisibleInViewport(boxmin, boxmax)) { return 0; } Vec2i pos; for (pos.x = boxmin.x; pos.x <= boxmax.x; ++pos.x) { for (pos.y = boxmin.y; pos.y <= boxmax.y; ++pos.y) { if (ReplayRevealMap || Map.Field(pos)->playerInfo.IsTeamVisible(*ThisPlayer)) { return 1; } } } return 0; }