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 HOPKINS_LINES_H 24 #define HOPKINS_LINES_H 25 26 #include "hopkins/globals.h" 27 28 #include "common/scummsys.h" 29 #include "common/str.h" 30 31 namespace Hopkins { 32 33 class HopkinsEngine; 34 35 struct LigneZoneItem { 36 int _count; 37 int _bobZoneIdx; 38 int16 *_zoneData; 39 }; 40 41 #define INVALID_LINE_VALUE 1300 42 43 #define MAX_LINES 400 44 45 struct RouteItem; 46 47 struct LigneItem { 48 int _lineDataEndIdx; 49 Directions _direction; 50 Directions _directionRouteInc; 51 Directions _directionRouteDec; 52 int16 *_lineData; 53 54 int appendToRouteInc(int from, int to, RouteItem *route, int index); 55 int appendToRouteDec(int from, int to, RouteItem *route, int index); 56 }; 57 58 struct SmoothItem { 59 int _posX; 60 int _posY; 61 }; 62 63 struct SegmentItem { 64 int _minZoneLineIdx; 65 int _maxZoneLineIdx; 66 }; 67 68 struct SquareZoneItem { 69 bool _enabledFl; 70 int _left; 71 int _right; 72 int _top; 73 int _bottom; 74 int _minZoneLineIdx; 75 int _maxZoneLineIdx; 76 bool _squareZoneFl; 77 }; 78 79 struct ZoneItem { 80 int _destX; 81 int _destY; 82 int _spriteIndex; 83 int _verbFl1; 84 int _verbFl2; 85 int _verbFl3; 86 int _verbFl4; 87 int _verbFl5; 88 int _verbFl6; 89 int _verbFl7; 90 int _verbFl8; 91 int _verbFl9; 92 int _verbFl10; 93 bool _enabledFl; 94 int _messageId; 95 }; 96 97 struct RouteItem { 98 int16 _x; 99 int16 _y; 100 Directions _dir; isValidRouteItem101 bool isValid() const { return _x != -1 || _y != -1; } invalidateRouteItem102 void invalidate() { _x = _y = -1; _dir = DIR_NONE; } setRouteItem103 void set(int16 X, int16 Y, Directions dir) { _x = X; _y = Y; _dir = dir; } 104 }; 105 106 107 class LinesManager { 108 private: 109 HopkinsEngine *_vm; 110 111 bool _forceHideText; 112 int _hotspotTextColor; 113 int _pathFindingMaxDepth; 114 SmoothItem _smoothRoute[4000]; 115 Directions _smoothMoveDirection; 116 LigneZoneItem _zoneLine[MAX_LINES+1]; 117 SegmentItem _segment[101]; 118 int _currentSegmentId; 119 int _maxLineIdx; 120 int _lastLine; 121 int _newLineIdx; 122 int _newLineDataIdx; 123 int _newRouteIdx; 124 int _newPosX; 125 int _newPosY; 126 int _oldMouseX, _oldMouseY; 127 int _oldRouteFromX; 128 int _oldRouteFromY; 129 int _oldRouteDestX; 130 int _oldRouteDestY; 131 int _oldZoneNum; 132 133 byte *_largeBuf; 134 RouteItem *_testRoute0; 135 RouteItem *_testRoute1; 136 int16 *_lineBuf; 137 RouteItem _bestRoute[8001]; 138 int _zoneSkipCount; 139 int _oldMouseZoneId; 140 141 int avoidObstacle(int lineIdx, int lineDataIdx, int routeIdx, int destLineIdx, int destLineDataIdx, RouteItem *route); 142 int avoidObstacleOnSegment(int lineIdx, int lineDataIdx, int routeIdx, int destLineIdx, int destLineDataIdx, RouteItem *route, int startLineIdx, int endLineIdx); 143 int checkInventoryHotspotsRow(int posX, int minZoneNum, bool lastRow); 144 void removeZoneLine(int idx); 145 void removeLine(int idx); 146 int checkCollision(int xp, int yp); 147 bool checkCollisionLine(int xp, int yp, int *foundDataIdx, int *foundLineIdx, int startLineIdx, int endLineIdx); 148 bool checkSmoothMove(int fromX, int fromY, int destX, int destY); 149 bool makeSmoothMove(int fromX, int fromY, int destX, int destY); 150 int characterRoute(int fromX, int fromY, int destX, int destY, int startLineIdx, int endLineIdx, int routeIdx); 151 int testLine(int paramX, int paramY, int *testValue, int *foundLineIdx, int *foundDataIdx); 152 void useRoute0(int idx, int curRouteIdx); 153 void useRoute1(int idx, int curRouteIdx); 154 void useRoute2(int idx, int curRouteIdx); 155 int computeYSteps(int idx); 156 int computeRouteIdx(int lineIdx, int dataIdx, int fromX, int fromY, int destX, int destY, int routerIdx, RouteItem *route); 157 158 bool MIRACLE(int fromX, int fromY, int lineIdx, int destLineIdx, int routeIdx); 159 bool PLAN_TEST(int paramX, int paramY, int superRouteIdx, int paramStartLineIdx, int paramEndLineIdx); 160 161 public: 162 RouteItem *_route; 163 RouteItem *_testRoute2; 164 165 int _bobZone[105]; 166 bool _bobZoneFl[105]; 167 ZoneItem _zone[106]; 168 SquareZoneItem _squareZone[101]; 169 LigneItem _lineItem[MAX_LINES]; 170 int _linesNumb; 171 172 LinesManager(HopkinsEngine *vm); 173 ~LinesManager(); 174 void clearAll(); 175 176 void setMaxLineIdx(int idx); 177 int checkInventoryHotspots(int posX, int posY); 178 void addZoneLine(int idx, int fromX, int fromY, int destX, int destY, int bobZoneIdx); 179 void loadLines(const Common::String &file); 180 void addLine(int lineIdx, Directions direction, int fromX, int fromY, int destX, int destY); 181 void initRoute(); 182 RouteItem *findRoute(int fromX, int fromY, int destX, int destY); 183 RouteItem *cityMapCarRoute(int x1, int y1, int x2, int y2); 184 void clearAllZones(); 185 void initSquareZones(); 186 void resetLines(); 187 void resetLinesNumb(); 188 void resetLastLine(); 189 void enableZone(int idx); 190 void disableZone(int idx); 191 void checkZone(); 192 int getMouseZone(); 193 void optimizeRoute(RouteItem *route); 194 }; 195 196 } // End of namespace Hopkins 197 198 #endif /* HOPKINS_FONT_H */ 199