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 
23 #ifndef QUEEN_GRID_H
24 #define QUEEN_GRID_H
25 
26 #include "common/util.h"
27 #include "queen/structs.h"
28 
29 namespace Queen {
30 
31 enum GridScreen {
32 	GS_ROOM  = 0,
33 	GS_PANEL = 1,
34 	GS_COUNT = 2
35 };
36 
37 class QueenEngine;
38 
39 class Grid {
40 public:
41 
42 	Grid(QueenEngine *vm);
43 	~Grid();
44 
45 	//! read areas data from specified stream
46 	void readDataFrom(uint16 numObjects, uint16 numRooms, byte *&ptr);
47 
48 	//! defines a new zone
49 	void setZone(GridScreen screen, uint16 zoneNum, uint16 x1, uint16 y1, uint16 x2, uint16 y2);
50 
51 	//! defines a new zone
52 	void setZone(GridScreen screen, uint16 zoneNum, const Box &box);
53 
54 	//! find the zone number containing the specified point
55 	uint16 findZoneForPos(GridScreen screen, uint16 x, uint16 y) const;
56 
57 	//! find the area number containing the specified point
58 	uint16 findAreaForPos(GridScreen screen, uint16 x, uint16 y) const;
59 
60 	//! clear the zones for current room
61 	void clear(GridScreen screen);
62 
63 	//! setup objects zones for the specified room
64 	void setupNewRoom(uint16 room, uint16 firstRoomObjNum);
65 
66 	//! setup panel zones
67 	void setupPanel();
68 
69 	//! draw the zones for current room (debug only)
70 	void drawZones();
71 
72 	//! retuns a reference to the specified zone
73 	const Box *zone(GridScreen screen, uint16 index) const;
74 
75 	//! get the verb for the specified cursor position
76 	Verb findVerbUnderCursor(int16 cursorx, int16 cursory) const;
77 
78 	//! get the object for the specified cursor position
79 	uint16 findObjectUnderCursor(int16 cursorx, int16 cursory) const;
80 
81 	//! get the object for the specified zone number
82 	uint16 findObjectNumber(uint16 zoneNum) const;
83 
84 	//! get scale for the specified position
85 	uint16 findScale(uint16 x, uint16 y) const;
86 
87 	//! returns a reference to the specfied room area
area(int room,int num)88 	Area *area(int room, int num) const { return &_area[room][num]; }
89 
90 	//! returns the number of areas in this room
areaMax(int room)91 	uint16 areaMax(int room) const { return _areaMax[room]; }
92 
93 	//! returns the number of objects in this room
objMax(int room)94 	uint16 objMax(int room) const { return _objMax[room]; }
95 
96 	void saveState(byte *&ptr);
97 	void loadState(uint32 ver, byte *&ptr);
98 
99 	enum {
100 		MAX_ZONES_NUMBER = 32,
101 		MAX_AREAS_NUMBER = 11
102 	};
103 
104 
105 private:
106 
107 	struct ZoneSlot {
108 		bool valid;
109 		Box box;
110 	};
111 
112 	//! current room zones
113 	ZoneSlot _zones[GS_COUNT][MAX_ZONES_NUMBER];
114 
115 	//! number of objects for each room
116 	int16 *_objMax;
117 
118 	//! number of areas for each room
119 	int16 *_areaMax;
120 
121 	//! areas for each room
122 	Area (*_area)[MAX_AREAS_NUMBER];
123 
124 	//! total number of room areas
125 	uint16 _numRoomAreas;
126 
127 	//! box/zone for each objects
128 	Box *_objectBox;
129 
130 	QueenEngine *_vm;
131 };
132 
133 
134 } // End of namespace Queen
135 
136 #endif
137