1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 #ifndef SLUDGE_FLOOR_H
23 #define SLUDGE_FLOOR_H
24 
25 namespace Common {
26 struct Point;
27 class SeekableReadStream;
28 class WriteStream;
29 }
30 
31 namespace Sludge {
32 
33 class SludgeEngine;
34 struct OnScreenPerson;
35 
36 struct FloorPolygon {
37 	int numVertices;
38 	int *vertexID;
39 };
40 
41 struct Floor {
42 	int originalNum;
43 	Common::Point *vertex;
44 	int numPolygons;
45 	FloorPolygon *polygon;
46 	int **matrix;
47 };
48 
49 class FloorManager {
50 public:
51 	FloorManager(SludgeEngine *vm);
52 	~FloorManager();
53 
54 	bool init();
55 	void kill();
56 
57 	void setFloorNull();
58 	bool setFloor(int fileNum);
59 	void drawFloor();
60 	int inFloor(int x, int y);
isFloorNoPolygon()61 	bool isFloorNoPolygon() { return !_currentFloor || _currentFloor->numPolygons == 0; }
62 
63 	// For Person collision detection
64 	bool handleClosestPoint(int &setX, int &setY, int &setPoly);
65 	bool doBorderStuff(OnScreenPerson *moveMe);
66 
67 	// Save & load
68 	void save(Common::WriteStream *stream);
69 	bool load(Common::SeekableReadStream *stream);
70 
71 private:
72 	Floor *_currentFloor;
73 	SludgeEngine *_vm;
74 
75 	bool getMatchingCorners(FloorPolygon &, FloorPolygon &, int &, int &);
76 	bool closestPointOnLine(int &closestX, int &closestY, int x1, int y1, int x2, int y2, int xP, int yP);
77 	bool pointInFloorPolygon(FloorPolygon &floorPoly, int x, int y);
78 	bool polysShareSide(FloorPolygon &a, FloorPolygon &b);
79 	void dumpFloor(int fileNum);
80 };
81 
82 } // End of namespace Sludge
83 
84 #endif
85