1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #ifndef WALKAREA_H
29 #define WALKAREA_H
30 
31 #include "engines/icb/common/px_rcutypes.h"
32 
33 namespace ICB {
34 
35 #define INTEGER_WALKAREA_API_SCHEMA 1
36 
37 struct __point { // 3D integer coordinate representation
__point__point38 	__point(void) : x(0), y(0), z(0) { ; }
__point__point39 	__point(int32 X, int32 Y, int32 Z) : x(X), y(Y), z(Z) { ; }
40 
41 	int32 x;
42 	int32 y;
43 	int32 z;
44 };
45 
46 struct __aWalkArea{
47 	char name[32];         // Name of the walkarea
48 	char cameraCluster[8]; // Hashed cameraName value
49 
50 	// Bounding box dimensions
51 	int32 x; // Top-left corner x coordinate (Revolution space)
52 	int32 y; // Top-left corner y coordinate (Revolution space)
53 	int32 z; // Top-left corner z coordinate (Revolution space)
54 	int32 w; // Width
55 	int32 h; // Height
56 
57 	// THE AREA DEFINITION (All in Revolution space)
58 	uint32 noPoints;   // Number of verteces\knots in 2D spline
59 	__point points[1]; // The points themselves (spline is always closed)
60 
61 	char cameraName[1]; // Name of associated camera (DWORD aligned)
62 };
63 
64 class INTEGER_WalkAreaFile {
65 public:
66 	uint32 schema; // The format version
67 	char ID[4];    // ID "WGA"
68 
69 	// Class methods
70 
INTEGER_WalkAreaFile()71 	INTEGER_WalkAreaFile() { ; }
~INTEGER_WalkAreaFile()72 	~INTEGER_WalkAreaFile() { ; }
73 
GetSchema(void)74 	uint32 GetSchema(void) const { return schema; }
GetNoAreas(void)75 	uint32 GetNoAreas(void) const { return noAreas; }
76 
77 	// Get pointer to a specific WalkArea
78 	inline const __aWalkArea *GetWalkArea(uint32 number) const;
79 	inline uint32 GetNoPoints(uint32 number) const;
80 	inline int32 GetBox_X(uint32 number) const;
81 	inline int32 GetBox_Y(uint32 number) const;
82 	inline int32 GetBox_Z(uint32 number) const;
83 	inline int32 GetBox_W(uint32 number) const;
84 	inline int32 GetBox_H(uint32 number) const;
85 
86 	bool8 GetAreaName(uint32 number, const char *&name) const;
87 	bool8 GetCluster(uint32 number, const char *&cluster) const;
88 	bool8 GetPoint(uint32 area, uint32 number, __point &point) const;
89 	bool8 GetCameraName(uint32 number, const char *&name) const;
90 
91 private:
92 	uint32 noAreas;
93 	uint32 offsetTable[1];
94 };
95 
GetWalkArea(uint32 number)96 inline const __aWalkArea *INTEGER_WalkAreaFile::GetWalkArea(uint32 number) const { return ((const __aWalkArea *)(((const char *)this) + offsetTable[number])); }
97 
GetNoPoints(uint32 number)98 inline uint32 INTEGER_WalkAreaFile::GetNoPoints(uint32 number) const { return (GetWalkArea(number)->noPoints); }
99 
GetBox_X(uint32 number)100 inline int32 INTEGER_WalkAreaFile::GetBox_X(uint32 number) const { return (GetWalkArea(number)->x); }
101 
GetBox_Y(uint32 number)102 inline int32 INTEGER_WalkAreaFile::GetBox_Y(uint32 number) const { return (GetWalkArea(number)->y); }
103 
GetBox_Z(uint32 number)104 inline int32 INTEGER_WalkAreaFile::GetBox_Z(uint32 number) const { return (GetWalkArea(number)->z); }
105 
GetBox_W(uint32 number)106 inline int32 INTEGER_WalkAreaFile::GetBox_W(uint32 number) const { return (GetWalkArea(number)->w); }
107 
GetBox_H(uint32 number)108 inline int32 INTEGER_WalkAreaFile::GetBox_H(uint32 number) const { return (GetWalkArea(number)->h); }
109 
GetAreaName(uint32 number,const char * & name)110 inline bool8 INTEGER_WalkAreaFile::GetAreaName(uint32 number, const char *&name) const {
111 	if (number >= noAreas)
112 		return FALSE8;
113 
114 	name = GetWalkArea(number)->name;
115 
116 	return TRUE8;
117 }
118 
GetCluster(uint32 number,const char * & cluster)119 inline bool8 INTEGER_WalkAreaFile::GetCluster(uint32 number, const char *&cluster) const {
120 	if (number >= noAreas)
121 		return FALSE8;
122 
123 	cluster = GetWalkArea(number)->cameraCluster;
124 
125 	return TRUE8;
126 }
127 
GetPoint(uint32 area,uint32 number,__point & point)128 inline bool8 INTEGER_WalkAreaFile::GetPoint(uint32 area, uint32 number, __point &point) const {
129 	if (area >= noAreas)
130 		return FALSE8;
131 
132 	point.x = GetWalkArea(area)->points[number].x;
133 	point.y = GetWalkArea(area)->points[number].y;
134 	point.z = GetWalkArea(area)->points[number].z;
135 
136 	return TRUE8;
137 }
138 
GetCameraName(uint32 number,const char * & name)139 inline bool8 INTEGER_WalkAreaFile::GetCameraName(uint32 number, const char *&name) const {
140 	if (number >= noAreas)
141 		return FALSE8;
142 
143 	// Get the address of the start of the cameraName (by asking for a point that isn't there
144 	name = (const char *)&GetWalkArea(number)->points[GetNoPoints(number)];
145 
146 	return TRUE8;
147 }
148 
149 } // End of namespace ICB
150 
151 #endif
152