1 /* Copyright (C) 2013-2014 Michal Brzozowski (rusolis@poczta.fm) 2 3 This file is part of KeeperRL. 4 5 KeeperRL is free software; you can redistribute it and/or modify it under the terms of the 6 GNU General Public License as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 KeeperRL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 10 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with this program. 14 If not, see http://www.gnu.org/licenses/ . */ 15 16 #pragma once 17 18 #include "util.h" 19 20 class Square; 21 class SquareArray; 22 23 class FieldOfView { 24 public: 25 FieldOfView(WLevel, VisionId); 26 bool canSee(Vec2 from, Vec2 to); 27 const vector<Vec2>& getVisibleTiles(Vec2 from); 28 void squareChanged(Vec2 pos); 29 30 SERIALIZATION_DECL(FieldOfView) 31 32 const static int sightRange = 30; 33 34 private: 35 36 37 class Visibility { 38 public: 39 40 bool checkVisible(int x,int y) const; 41 const vector<Vec2>& getVisibleTiles() const; 42 43 Visibility(WLevel, VisionId, int x, int y); 44 Visibility(Visibility&&) = default; 45 Visibility& operator = (Visibility&&) = default; 46 47 SERIALIZATION_DECL(Visibility) 48 49 private: 50 char SERIAL(visible)[sightRange * 2 + 1][sightRange * 2 + 1]; 51 vector<Vec2> SERIAL(visibleTiles); 52 void calculate(int,int,int,int, int, int, int, int, 53 function<bool (int, int)> isBlocking, 54 function<void (int, int)> setVisible); 55 void setVisible(WConstLevel, int, int); 56 57 int SERIAL(px); 58 int SERIAL(py); 59 }; 60 61 WLevel SERIAL(level); 62 Table<unique_ptr<Visibility>> SERIAL(visibility); 63 VisionId SERIAL(vision); 64 }; 65 66