ScummVM API documentation
px_route_barriers.h
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  * 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 modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (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, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_PX_ROUTE_BARRIERS_H_INCLUDED
28 #define ICB_PX_ROUTE_BARRIERS_H_INCLUDED
29 
30 // Include headers needed by this file.
31 
32 #include "engines/icb/common/px_common.h"
33 
34 namespace ICB {
35 
36 // These define the filenames for files containing barrier maps and routing maps.
37 #define PX_FILENAME_LINEOFSIGHT "pxwglineofsight"
38 #define PX_FILENAME_ROUTING "pxwgrouting"
39 #define PX_FILENAME_BARRIERLIST "pxwgbarrierlist"
40 
41 #ifndef PC_EXT_LINKED
42 #define PC_EXT_LINKED "linked"
43 #endif
44 
45 #ifndef PSX_EXT_LINKED
46 #define PSX_EXT_LINKED "PSXlinked"
47 #endif
48 
49 #ifdef PX_EXT_LINKED
50 #undef PX_EXT_LINKED
51 #endif
52 
53 #define PX_EXT_LINKED PC_EXT_LINKED
54 
55 // This is the version for these files. The engine checks this runtime to know that it is running with
56 // the correct version of file.
57 #define VERSION_PXWGLINEOFSIGHT 200
58 #define VERSION_PXWGROUTING 200
59 #define VERSION_PXWGBARRIERLIST 200
60 
61 // This is the size of the sides of the cubes that each floor is divided into in centimetres.
62 #define FLOOR_CUBE_SIZE 1000 // 10-metre sides.
63 #define ABOVE_ALL_MODELS 10000 // Set this to be higher than any model point ever.
64 
65 // This is an enumerated type for the barrier (the types listed are just illustrations - they may well be changed).
66 // BRICK - can't walk through it, see through it or shoot through it.
67 // GLASS - can't walk through it; can see through it; not sure about shooting (glass would need to break).
68 // BULLET_PROOF_GLASS - can't walk through it or shoot through it, but can see through it.
69 // THIN_STEEL - can't see through it or walk through it, but can shoot through it.
70 // WIRE_FENCE - can't walk through it, but can see through it; can shoot through it with random success.
71 // UNIT_HEIGHT - special one for stopping characters walking off the edge of ledges etc.
72 // VIEW_FIELD - stops characters walking out of camera field-of-view.
73 // LEFT_NUDGE - use to assist player control going through doors.
74 // RIGHT_NUDGE - ditto last one.
75 enum eBarrierType { BRICK = 0, GLASS, BULLET_PROOF_GLASS, THIN_STEEL, WIRE_FENCE, UNIT_HEIGHT, VIEW_FIELD, LEFT_NUDGE, RIGHT_NUDGE };
76 
77 #define BARRIER_TYPE_CARDINALITY 9 // Must match number of enums in previous type (because C++
78 // doesn't provide a way to get this).
79 
80 // This is an enumerated type for the things that might try to pass through a barrier. Note: the TEST_RAY
81 // is blocked by all types of barrier.
82 enum eBarrierRayType { TEST_RAY, LIGHT, BULLET };
83 
84 #define RAY_TYPE_CARDINALITY 3
85 
86 // Defines a multi-state logic value for use with the barriers.
87 enum eBarrierLogicValue { NO_IMPACT = 0, BLOCKS, ALLOWS, MAYBE, SPECIAL };
88 
89 // This is the truth table that states what kind of ray passes through what
90 // type of barrier.
91 static enum eBarrierLogicValue barrierLogicTable[BARRIER_TYPE_CARDINALITY][RAY_TYPE_CARDINALITY] = {
92  {BLOCKS, BLOCKS, BLOCKS}, {BLOCKS, ALLOWS, SPECIAL}, {BLOCKS, ALLOWS, BLOCKS}, {BLOCKS, BLOCKS, ALLOWS}, {BLOCKS, ALLOWS, MAYBE},
93  {BLOCKS, ALLOWS, ALLOWS}, {BLOCKS, ALLOWS, ALLOWS}, {BLOCKS, ALLOWS, ALLOWS}, {BLOCKS, ALLOWS, ALLOWS}};
94 
95 typedef struct {
96  // these are in both versions
97  PXfloat m_linedist, m_alinedist, m_blinedist;
98 
99  PXfloat m_lpx, m_lpz; // Main barrier
100  PXfloat m_alpx, m_alpz; // End A.
101  PXfloat m_blpx, m_blpz; // End B.
103 
105 public:
106  static inline PXfloat alpx(BarrierCollisionMaths *bmath) {
107  // return m_alpx;
108  return -bmath->m_lpz;
109  }
110 
111  static inline PXfloat alpz(BarrierCollisionMaths *bmath) {
112  // return m_alpz;
113  return bmath->m_lpx;
114  }
115 
116  static inline PXfloat blpx(BarrierCollisionMaths *bmath) {
117  // return m_blpx;
118  return bmath->m_lpz;
119  }
120 
121  static inline PXfloat blpz(BarrierCollisionMaths *bmath) {
122  // return m_blpz;
123  return -bmath->m_lpx;
124  }
125 
126  static void Generate(BarrierCollisionMaths *bmath, PXreal x1, PXreal z1, PXreal x2, PXreal z2) {
127  PXreal dx = x1 - x2;
128  PXreal dz = z1 - z2;
129 
130  int32 nLength = (int32)PXsqrt((PXdouble)(dx * dx + dz * dz));
131 
132  PXfloat xunit = PXreal2PXfloat(dx) / nLength;
133  PXfloat zunit = PXreal2PXfloat(dz) / nLength;
134 
135  bmath->m_lpx = -zunit;
136  bmath->m_lpz = xunit;
137 
138  bmath->m_linedist = (x1 * bmath->m_lpx) + (z1 * bmath->m_lpz);
139 
140  bmath->m_alinedist = (x1 * alpx(bmath)) + (z1 * alpz(bmath));
141 
142  bmath->m_blinedist = (x2 * blpx(bmath)) + (z2 * blpz(bmath));
143  }
144 };
145 
146 typedef struct {
147  PXreal m_x1, m_z1; // Looking down on the model, the position of the first vertical edge of the barrier.
148  PXreal m_x2, m_z2; // Looking down on the model, the position of the second vertical edge.
149  PXreal m_bottom; // The bottom of the barrier.
150  PXreal m_top; // The top of the barrier.
151  eBarrierType m_material; // The material the barrier is made of.
152  PXfloat m_pan; // The barrier's pan value.
153  BarrierCollisionMaths m_bcm; // Some extra figures to speed up barrier collision detection.
154 } RouteBarrier;
155 
156 inline void routeBarrierCreatePan(RouteBarrier *barrier) { barrier->m_pan = PXAngleOfVector(barrier->m_z1 - barrier->m_z2, barrier->m_x1 - barrier->m_x2); }
157 
158 // This holds several barriers. These barriers all at least partly occupy a given cube in space. If one barrier passes
159 // through more than one cube, it will have a duplicate entry in each cube.
160 typedef struct {
161  int32 num_barriers; // The number of barriers referenced in this cube.
162  uint32 barriers; // Offset to an array of barrier indices.
163 } BarrierCube;
164 
165 // This is a horizontal slice through the Max model, containing all the route barriers that pass through this level. The
166 // extremeties of the whole cuboid are given first so that a quick initial check can be done to see if there might be
167 // route barriers in the way.
168 typedef struct {
169  PXreal bottom; // The bottom of the slice.
170  PXreal top; // The top of the slice.
171  PXreal left_edge; // Leftmost edge of the cube of space occupied by this floor slice.
172  PXreal right_edge; // Ditto right edge.
173  PXreal back_edge; // Back edge.
174  PXreal front_edge; // Ditto front edge.
175  uint32 num_cubes; // Number of _route_cubes in this floor (could be calculated by dividing overall cube size by FLOOR_CUBE_SIZE).
176  uint32 row_length; // Size of the rows in the array (eg. 6 cubes could be 1X6, 2X3, 3X2 or 6X1).
177  uint32 offset_cubes[1]; // An array of offsets to cubes (2D array of size row_length * (num_cubes / row_length) ).
178 } BarrierSlice;
179 
180 // This is used in the following definition of _parent_box, and holds one group of barriers.
181 typedef struct {
182  PXreal back, left; // Back/left of the bounding box holding this group of barriers (looking down into the model).
183  PXreal front, right; // Ditto front/right.
184  uint32 num_barriers; // Number of barriers in this group.
185  uint32 barriers[1]; // Array of barrier indices.
186 
187 } ChildGroup;
188 
189 // This holds one parent box entry.
190 typedef struct {
191  PXreal back, left; // Top/left of the parent box (looking down into the model).
192  PXreal front, right; // Ditto bottom/right.
193  uint32 num_barriers; // Number of barriers in the parent (not its children).
194  uint32 barriers; // Offset to an array of barrier indices.
195  uint32 num_specials; // Number of special barriers (eg. field-of-view).
196  uint32 specials; // Offset of the array of special barrier indices.
197  uint32 num_childgroups; // Number of child groups owned by this parent box.
198  uint32 childgroups[1]; // Array of offsets to the child groups.
199 
200 } ParentBox;
201 
202 // This is also a slice through the model, but the data is grouped in a different way which is more suited to routing.
203 typedef struct {
204  PXreal bottom; // The bottom of the slice.
205  PXreal top; // The top of the slice.
206  uint32 num_parent_boxes; // The number of parent boxes in this slice (same as the number of floor rectangles at this height).
207  uint32 parent_boxes[1]; // An array of offsets to parent boxes.
208 
209 } RoutingSlice;
210 
211 inline eBarrierLogicValue IsBarrierTo(eBarrierType eMaterial, eBarrierRayType eRay) { return barrierLogicTable[eMaterial][eRay]; }
212 
213 } // End of namespace ICB
214 
215 #endif // #ifndef _PX_ROUTE_BARRIERS_H_INCLUDED
Definition: px_route_barriers.h:104
Definition: px_route_barriers.h:190
Definition: px_route_barriers.h:168
Definition: actor.h:32
Definition: px_route_barriers.h:203
Definition: px_route_barriers.h:95
Definition: px_route_barriers.h:181
Definition: px_route_barriers.h:160
Definition: px_route_barriers.h:146