ScummVM API documentation
router.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) 1994-1998 Revolution Software Ltd.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#ifndef SWORD2_ROUTER_H
25#define SWORD2_ROUTER_H
26
27// This used to be a variable, but it was never set. Actually, it wasn't even
28// initialized!
29//
30// Define this to force the use of slidy router (so solid path not used when
31// ending walk in ANY direction)
32//
33// #define FORCE_SLIDY
34
35#include "sword2/object.h"
36
37namespace Sword2 {
38
39struct WalkData {
40 uint16 frame;
41 int16 x;
42 int16 y;
43 uint8 step;
44 uint8 dir;
45};
46
47struct BarData {
48 int16 x1;
49 int16 y1;
50 int16 x2;
51 int16 y2;
52 int16 xmin;
53 int16 ymin;
54 int16 xmax;
55 int16 ymax;
56 int16 dx; // x2 - x1
57 int16 dy; // y2 - y1
58 int32 co; // co = (y1*dx) - (x1*dy) from an equation for a line y*dx = x*dy + co
59};
60
61struct NodeData {
62 int16 x;
63 int16 y;
64 int16 level;
65 int16 prev;
66 int16 dist;
67};
68
69// because we only have 2 megas in the game!
70#define TOTAL_ROUTE_SLOTS 2
71
72#define MAX_FRAMES_PER_CYCLE 16
73#define NO_DIRECTIONS 8
74#define MAX_FRAMES_PER_CHAR (MAX_FRAMES_PER_CYCLE * NO_DIRECTIONS)
75#define ROUTE_END_FLAG 255
76
77#define MAX_WALKGRIDS 10
78
79#define O_WALKANIM_SIZE 600 // max number of nodes in router output
80#define O_GRID_SIZE 200 // max 200 lines & 200 points
81#define O_ROUTE_SIZE 50 // max number of modules in a route
82
83struct RouteData {
84 int32 x;
85 int32 y;
86 int32 dirS;
87 int32 dirD;
88};
89
90struct PathData {
91 int32 x;
92 int32 y;
93 int32 dir;
94 int32 num;
95};
96
97class Router {
98private:
99 Sword2Engine *_vm;
100
101 int16 _standbyX; // see fnSetStandbyCoords()
102 int16 _standbyY;
103 int16 _standbyDir;
104
105 // stores pointers to mem blocks containing routes created & used by
106 // megas (NULL if slot not in use)
107 WalkData *_routeSlots[TOTAL_ROUTE_SLOTS];
108
109 BarData _bars[O_GRID_SIZE];
110 NodeData _node[O_GRID_SIZE];
111
112 int32 _walkGridList[MAX_WALKGRIDS];
113
114 int32 _nBars;
115 int32 _nNodes;
116
117 int32 _startX, _startY, _startDir;
118 int32 _targetX, _targetY, _targetDir;
119 int32 _scaleA, _scaleB;
120
121 RouteData _route[O_ROUTE_SIZE];
122 PathData _smoothPath[O_ROUTE_SIZE];
123 PathData _modularPath[O_ROUTE_SIZE];
124 int32 _routeLength;
125
126 int32 _framesPerStep;
127 int32 _framesPerChar;
128
129 ObjectWalkdata _walkData;
130
131 int8 _modX[NO_DIRECTIONS];
132 int8 _modY[NO_DIRECTIONS];
133 int32 _diagonalx;
134 int32 _diagonaly;
135
136 int32 _firstStandFrame;
137
138 int32 _firstStandingTurnLeftFrame;
139 int32 _firstStandingTurnRightFrame;
140
141 int32 _firstWalkingTurnLeftFrame; // left walking turn
142 int32 _firstWalkingTurnRightFrame; // right walking turn
143
144 uint32 _firstSlowInFrame[NO_DIRECTIONS];
145
146 int32 _firstSlowOutFrame;
147
148 // number of slow-out frames on for each leading-leg in each direction
149 // ie. total number of slow-out frames = (numberOfSlowOutFrames * 2 *
150 // NO_DIRECTIONS)
151
152 int32 _numberOfSlowOutFrames;
153
154 int32 _stepCount;
155
156 int32 _moduleX;
157 int32 _moduleY;
158 int32 _currentDir;
159 int32 _lastCount;
160 int32 _frame;
161
162 uint8 returnSlotNo(uint32 megaId);
163
164 int32 getRoute();
165 void extractRoute();
166 void loadWalkGrid();
167 void setUpWalkGrid(byte *ob_mega, int32 x, int32 y, int32 dir);
168 void loadWalkData(byte *ob_walkdata);
169 bool scan(int32 level);
170
171 int32 newCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2);
172 bool lineCheck(int32 x1, int32 x2, int32 y1, int32 y2);
173 bool vertCheck(int32 x, int32 y1, int32 y2);
174 bool horizCheck(int32 x1, int32 y, int32 x2);
175 bool check(int32 x1, int32 y1, int32 x2, int32 y2);
176 int32 checkTarget(int32 x, int32 y);
177
178 int32 smoothestPath();
179 void slidyPath();
180
181 void smoothCheck(int32 &steps, int32 best, int32 p, int32 dirS, int32 dirD);
182
183 bool addSlowInFrames(WalkData *walkAnim);
184 void addSlowOutFrames(WalkData *walkAnim);
185 void slidyWalkAnimator(WalkData *walkAnim);
186
187#ifndef FORCE_SLIDY
188 void solidPath();
189 int32 solidWalkAnimator(WalkData *walkAnim);
190#endif
191
192 void plotCross(int16 x, int16 y, uint8 color);
193
194public:
195 Router(Sword2Engine *vm) : _vm(vm), _diagonalx(0), _diagonaly(0) {
196 memset(_routeSlots, 0, sizeof(_routeSlots));
197 memset(_bars, 0, sizeof(_bars));
198 memset(_node, 0, sizeof(_node));
199 memset(_walkGridList, 0, sizeof(_walkGridList));
200 memset(_route, 0, sizeof(_route));
201 memset(_smoothPath, 0, sizeof(_smoothPath));
202 memset(_modularPath, 0, sizeof(_modularPath));
203 memset(_modX, 0, sizeof(_modX));
204 memset(_modY, 0, sizeof(_modY));
205 memset(_firstSlowInFrame, 0, sizeof(_firstSlowInFrame));
206 }
207
208 void setStandbyCoords(int16 x, int16 y, uint8 dir);
209 int whatTarget(int startX, int startY, int destX, int destY);
210
211 // Sprites
212 void setSpriteStatus(byte *ob_graph, uint32 type);
213 void setSpriteShading(byte *ob_graph, uint32 type);
214
215 // Animation
216 int doAnimate(byte *ob_logic, byte *ob_graph, int32 animRes, bool reverse);
217 int megaTableAnimate(byte *ob_logic, byte *ob_graph, byte *ob_mega, byte *animTable, bool reverse);
218
219 // Walking
220 int doWalk(byte *ob_logic, byte *ob_graph, byte *ob_mega, byte *ob_walkdata, int16 target_x, int16 target_y, uint8 target_dir);
221 int walkToAnim(byte *ob_logic, byte *ob_graph, byte *ob_mega, byte *ob_walkdata, uint32 animRes);
222 int walkToTalkToMega(byte *ob_logic, byte *ob_graph, byte *ob_mega, byte *ob_walkdata, uint32 megaId, uint32 separation);
223
224 // Turning
225 int doFace(byte *ob_logic, byte *ob_graph, byte *ob_mega, byte *ob_walkdata, uint8 target_dir);
226 int faceXY(byte *ob_logic, byte *ob_graph, byte *ob_mega, byte *ob_walkdata, int16 target_x, int16 target_y);
227 int faceMega(byte *ob_logic, byte *ob_graph, byte *ob_mega, byte *ob_walkdata, uint32 megaId);
228
229 // Standing
230 void standAt(byte *ob_graph, byte *ob_mega, int32 x, int32 y, int32 dir);
231 void standAfterAnim(byte *ob_graph, byte *ob_mega, uint32 animRes);
232 void standAtAnim(byte *ob_graph, byte *ob_mega, uint32 animRes);
233
234 int32 routeFinder(byte *ob_mega, byte *ob_walkdata, int32 x, int32 y, int32 dir);
235
236 void earlySlowOut(byte *ob_mega, byte *ob_walkdata);
237
238 void allocateRouteMem();
239 WalkData *getRouteMem();
240 void freeRouteMem();
241 void freeAllRouteMem();
242 void addWalkGrid(int32 gridResource);
243 void removeWalkGrid(int32 gridResource);
244 void clearWalkGridList();
245
246 void plotWalkGrid();
247};
248
249} // End of namespace Sword2
250
251#endif
Definition: router.h:97
Definition: sword2.h:99
Definition: animation.h:37
Definition: router.h:47
Definition: router.h:61
Definition: object.h:259
Definition: router.h:90
Definition: router.h:83
Definition: router.h:39