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