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 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef SWORD1_ROUTER_H
23#define SWORD1_ROUTER_H
24
25#include "sword1/object.h"
26
27namespace Sword1 {
28
29#include "common/pack-start.h" // START STRUCT PACKING
30
31struct BarData {
32 int16 x1;
33 int16 y1;
34 int16 x2;
35 int16 y2;
36 int16 xmin;
37 int16 ymin;
38 int16 xmax;
39 int16 ymax;
40 int16 dx; // x2 - x1
41 int16 dy; // y2 - y1
42 int32 co; // co = (y1*dx) - (x1*dy) from an equation for a line y*dx = x*dy + co
43} PACKED_STRUCT;
44
45struct NodeData {
46 int16 x;
47 int16 y;
48 int16 level;
49 int16 prev;
50 int16 dist;
51} PACKED_STRUCT;
52
53#include "common/pack-end.h" // END STRUCT PACKING
54
55struct FloorData {
56 int32 nbars;
57 BarData *bars;
58 int32 nnodes;
59 NodeData *node;
60};
61
62struct RouteData {
63 int32 x;
64 int32 y;
65 int32 dirS;
66 int32 dirD;
67};
68
69struct PathData {
70 int32 x;
71 int32 y;
72 int32 dir;
73 int32 num;
74};
75
76#define MAX_FRAMES_PER_CYCLE 16
77#define NO_DIRECTIONS 8
78#define MAX_FRAMES_PER_CHAR (MAX_FRAMES_PER_CYCLE * NO_DIRECTIONS)
79#define ROUTE_END_FLAG 255
80
81#define O_GRID_SIZE 200
82#define O_ROUTE_SIZE 50
83
84class ObjectMan;
85class ResMan;
86class Screen;
87
88extern int whatTarget(int32 startX, int32 startY, int32 destX, int32 destY);
89
90class Router {
91public:
92 Router(ObjectMan *pObjMan, ResMan *pResMan);
93 int32 routeFinder(int32 id, Object *mega, int32 x, int32 y, int32 dir);
94 void setPlayerTarget(int32 x, int32 y, int32 dir, int32 stance);
95
96 // these should be private but are read by Screen for debugging:
97 BarData _bars[O_GRID_SIZE];
98 NodeData _node[O_GRID_SIZE];
99
100 int32 _nBars;
101 int32 _nNodes;
102
103private:
104 // when the player collides with another mega, we'll receive a ReRouteRequest here.
105 // that's why we need to remember the player's target coordinates
106 int32 _playerTargetX, _playerTargetY, _playerTargetDir, _playerTargetStance;
107
108 ObjectMan *_objMan;
109 ResMan *_resMan;
110
111 int32 _startX, _startY, _startDir;
112 int32 _targetX, _targetY, _targetDir;
113 int32 _scaleA, _scaleB;
114
115 int32 megaId;
116
117 RouteData _route[O_ROUTE_SIZE];
118 PathData _smoothPath[O_ROUTE_SIZE];
119 PathData _modularPath[O_ROUTE_SIZE];
120 int32 _routeLength;
121
122 int32 _framesPerStep, _framesPerChar;
123 uint8 _nWalkFrames, _nTurnFrames;
124 int32 _dx[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR];
125 int32 _dy[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR];
126 int32 _modX[NO_DIRECTIONS];
127 int32 _modY[NO_DIRECTIONS];
128 int32 _diagonalx, _diagonaly;
129 int32 standFrames;
130 int32 turnFramesLeft, turnFramesRight;
131 int32 walkFramesLeft, walkFramesRight; // left/right walking turn
132 int32 slowInFrames, slowOutFrames;
133
134 bool _slidyWalkAnimatorState;
135
136 int32 LoadWalkResources(Object *mega, int32 x, int32 y, int32 dir);
137 int32 getRoute();
138 int32 checkTarget(int32 x, int32 y);
139
140 bool scan(int32 level);
141 int32 newCheck(int32 status, int32 x1, int32 x2, int32 y1, int32 y2);
142 bool check(int32 x1, int32 y1, int32 x2, int32 y2);
143 bool horizCheck(int32 x1, int32 y, int32 x2);
144 bool vertCheck(int32 x, int32 y1, int32 y2);
145 bool lineCheck(int32 x1, int32 y1, int32 x2, int32 y2);
146
147 void extractRoute();
148
149 void slidyPath();
150 void slidyWalkAnimator(WalkData *walkAnim);
151
152 int32 smoothestPath();
153 void smoothCheck(int32 &steps, int32 best, int32 p, int32 dirS, int32 dirD);
154
155 void solidPath();
156 int32 solidWalkAnimator(WalkData *walkAnim);
157};
158
159} // End of namespace Sword1
160
161#endif //BSROUTER_H
Definition: objectman.h:33
Definition: resman.h:65
Definition: router.h:90
Definition: screen.h:75
Definition: animation.h:38
Definition: router.h:31
Definition: router.h:55
Definition: router.h:45
Definition: object.h:62
Definition: router.h:69
Definition: router.h:62
Definition: object.h:54