2012-10-02 11:44:23 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hopkins/lines.h"
|
2013-02-15 21:20:24 +00:00
|
|
|
|
2012-10-02 11:44:23 +00:00
|
|
|
#include "hopkins/graphics.h"
|
|
|
|
#include "hopkins/hopkins.h"
|
|
|
|
|
2013-02-15 21:20:24 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/textconsole.h"
|
|
|
|
|
2012-10-02 11:44:23 +00:00
|
|
|
namespace Hopkins {
|
|
|
|
|
2013-03-20 06:47:39 +00:00
|
|
|
LinesManager::LinesManager(HopkinsEngine *vm) {
|
|
|
|
_vm = vm;
|
2013-02-16 12:46:13 +00:00
|
|
|
|
2013-01-10 21:09:37 +00:00
|
|
|
for (int i = 0; i < MAX_LINES; ++i) {
|
2012-12-30 23:18:08 +00:00
|
|
|
Common::fill((byte *)&_zoneLine[i], (byte *)&_zoneLine[i] + sizeof(LigneZoneItem), 0);
|
2013-02-20 07:30:16 +00:00
|
|
|
Common::fill((byte *)&_lineItem[i], (byte *)&_lineItem[i] + sizeof(LigneItem), 0);
|
2012-10-06 13:36:13 +00:00
|
|
|
}
|
2013-02-12 22:48:03 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 4000; ++i)
|
2013-01-26 13:54:57 +00:00
|
|
|
Common::fill((byte *)&_smoothRoute[i], (byte *)&_smoothRoute[i] + sizeof(SmoothItem), 0);
|
2013-02-12 22:48:03 +00:00
|
|
|
|
2013-02-16 09:55:07 +00:00
|
|
|
for (int i = 0; i < 8001; ++i)
|
2013-02-20 07:30:16 +00:00
|
|
|
_bestRoute[i].set(0, 0, DIR_NONE);
|
2013-02-12 22:48:03 +00:00
|
|
|
|
2013-01-27 19:20:36 +00:00
|
|
|
for (int i = 0; i < 101; ++i) {
|
2013-01-27 22:30:40 +00:00
|
|
|
Common::fill((byte *)&_segment[i], (byte *)&_segment[i] + sizeof(SegmentItem), 0);
|
|
|
|
Common::fill((byte *)&_squareZone[i], (byte *)&_squareZone[i] + sizeof(SquareZoneItem), 0);
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
2012-10-06 13:36:13 +00:00
|
|
|
|
2013-02-12 22:48:03 +00:00
|
|
|
for (int i = 0; i < 105; ++i) {
|
|
|
|
BOBZONE[i] = 0;
|
|
|
|
BOBZONE_FLAG[i] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 106; ++i)
|
|
|
|
Common::fill((byte *)&ZONEP[i], (byte *)&ZONEP[i] + sizeof(ZonePItem), 0);
|
|
|
|
|
2013-01-01 23:57:00 +00:00
|
|
|
_linesNumb = 0;
|
2013-02-20 07:30:16 +00:00
|
|
|
_newLineIdx = 0;
|
|
|
|
_newLineDataIdx = 0;
|
|
|
|
_newRouteIdx = 0;
|
|
|
|
_newPosX = 0;
|
|
|
|
_newPosY = 0;
|
2013-02-18 00:19:41 +00:00
|
|
|
_smoothMoveDirection = DIR_NONE;
|
2013-01-27 11:53:00 +00:00
|
|
|
_lastLine = 0;
|
2013-01-27 13:32:05 +00:00
|
|
|
_maxLineIdx = 0;
|
2013-01-27 14:22:57 +00:00
|
|
|
_pathFindingMaxDepth = 0;
|
2013-03-05 07:26:51 +00:00
|
|
|
_testRoute0 = NULL;
|
2013-03-06 07:28:18 +00:00
|
|
|
_testRoute1 = NULL;
|
|
|
|
_testRoute2 = NULL;
|
2013-02-20 07:30:16 +00:00
|
|
|
_lineBuf = (int16 *)g_PTRNUL;
|
2013-02-16 09:55:07 +00:00
|
|
|
_route = (RouteItem *)g_PTRNUL;
|
2013-01-27 21:28:10 +00:00
|
|
|
_currentSegmentId = 0;
|
2013-02-20 07:30:16 +00:00
|
|
|
_largeBuf = g_PTRNUL;
|
2013-03-24 16:42:18 +00:00
|
|
|
_zoneSkipCount = 0;
|
2013-03-24 19:39:16 +00:00
|
|
|
_hotspotTextColor = 0;
|
2013-03-24 18:38:48 +00:00
|
|
|
_forceHideText = false;
|
2013-03-24 21:11:52 +00:00
|
|
|
_oldMouseZoneId = 0;
|
|
|
|
_oldMouseX = 0;
|
|
|
|
_oldMouseY = 0;
|
2013-03-24 22:44:39 +00:00
|
|
|
_oldRouteFromX = 0;
|
|
|
|
_oldRouteFromY = 0;
|
|
|
|
_oldRouteDestX = 0;
|
|
|
|
_oldRouteDestY = 0;
|
|
|
|
_oldZoneNum = 0;
|
2013-01-27 21:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LinesManager::~LinesManager() {
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->freeMemory(_largeBuf);
|
|
|
|
_vm->_globals->freeMemory((byte *) _testRoute0);
|
|
|
|
_vm->_globals->freeMemory((byte *) _testRoute1);
|
|
|
|
_vm->_globals->freeMemory((byte *) _testRoute2);
|
2012-10-06 13:36:13 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 06:47:39 +00:00
|
|
|
int LigneItem::appendToRouteInc(int from, int to, RouteItem *route, int index) {
|
|
|
|
if (to == -1)
|
|
|
|
to = _lineDataEndIdx;
|
|
|
|
|
|
|
|
for (int i = from; i < to; ++i)
|
|
|
|
route[index++].set(_lineData[2*i], _lineData[2*i+1], _directionRouteInc);
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
int LigneItem::appendToRouteDec(int from, int to, RouteItem *route, int index) {
|
|
|
|
if (from == -1)
|
|
|
|
from = _lineDataEndIdx - 1;
|
|
|
|
|
|
|
|
for (int i = from; i > to; --i)
|
|
|
|
route[index++].set(_lineData[2*i], _lineData[2*i+1], _directionRouteDec);
|
|
|
|
return index;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 11:53:00 +00:00
|
|
|
/**
|
|
|
|
* Load lines
|
|
|
|
*/
|
|
|
|
void LinesManager::loadLines(const Common::String &file) {
|
|
|
|
resetLines();
|
|
|
|
_linesNumb = 0;
|
|
|
|
_lastLine = 0;
|
2013-03-19 20:57:28 +00:00
|
|
|
byte *ptr = _vm->_fileManager->loadFile(file);
|
2013-02-18 00:37:21 +00:00
|
|
|
for (int idx = 0; READ_LE_INT16((uint16 *)ptr + (idx * 5)) != -1; idx++) {
|
2013-01-27 11:53:00 +00:00
|
|
|
addLine(idx,
|
2013-02-18 00:37:21 +00:00
|
|
|
(Directions)READ_LE_INT16((uint16 *)ptr + (idx * 5)),
|
|
|
|
READ_LE_INT16((uint16 *)ptr + (idx * 5) + 1),
|
|
|
|
READ_LE_INT16((uint16 *)ptr + (idx * 5) + 2),
|
|
|
|
READ_LE_INT16((uint16 *)ptr + (idx * 5) + 3),
|
|
|
|
READ_LE_INT16((uint16 *)ptr + (idx * 5) + 4));
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
|
|
|
initRoute();
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->freeMemory(ptr);
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 22:15:52 +00:00
|
|
|
/**
|
|
|
|
* Check Hotspots in Inventory screen
|
|
|
|
* Returns the ID of the hotspot under mouse
|
|
|
|
*/
|
|
|
|
int LinesManager::checkInventoryHotspots(int posX, int posY) {
|
|
|
|
int hotspotId = 0;
|
|
|
|
if (posY >= 120 && posY <= 153)
|
2013-01-11 23:38:23 +00:00
|
|
|
hotspotId = checkInventoryHotspotsRow(posX, 1, false);
|
2013-01-10 22:15:52 +00:00
|
|
|
if (posY >= 154 && posY <= 191)
|
2013-01-11 23:38:23 +00:00
|
|
|
hotspotId = checkInventoryHotspotsRow(posX, 7, false);
|
2013-01-10 22:15:52 +00:00
|
|
|
if (posY >= 192 && posY <= 229)
|
2013-01-11 23:38:23 +00:00
|
|
|
hotspotId = checkInventoryHotspotsRow(posX, 13, false);
|
2013-01-10 22:15:52 +00:00
|
|
|
if (posY >= 230 && posY <= 267)
|
2013-01-11 23:38:23 +00:00
|
|
|
hotspotId = checkInventoryHotspotsRow(posX, 19, false);
|
2013-01-10 22:15:52 +00:00
|
|
|
if (posY >= 268 && posY <= 306)
|
2013-01-11 23:38:23 +00:00
|
|
|
hotspotId = checkInventoryHotspotsRow(posX, 25, true);
|
2013-03-20 06:36:06 +00:00
|
|
|
if (posY >= 268 && posY <= 288 && posX >= _vm->_graphicsManager->_scrollOffset + 424 && posX <= _vm->_graphicsManager->_scrollOffset + 478)
|
2013-01-10 22:15:52 +00:00
|
|
|
hotspotId = 30;
|
2013-03-20 06:36:06 +00:00
|
|
|
if (posY >= 290 && posY <= 306 && posX >= _vm->_graphicsManager->_scrollOffset + 424 && posX <= _vm->_graphicsManager->_scrollOffset + 478)
|
2013-01-10 22:15:52 +00:00
|
|
|
hotspotId = 31;
|
2013-03-20 06:36:06 +00:00
|
|
|
if (posY < 114 || posY > 306 || posX < _vm->_graphicsManager->_scrollOffset + 152 || posX > _vm->_graphicsManager->_scrollOffset + 484)
|
2013-01-10 22:15:52 +00:00
|
|
|
hotspotId = 32;
|
|
|
|
|
|
|
|
return hotspotId;
|
2012-10-03 12:15:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 22:15:52 +00:00
|
|
|
/**
|
|
|
|
* Check the hotspots in an inventory line
|
|
|
|
* Returns the hotspot Id under the mouse, if any.
|
|
|
|
*/
|
2013-01-11 23:38:23 +00:00
|
|
|
int LinesManager::checkInventoryHotspotsRow(int posX, int minZoneNum, bool lastRow) {
|
2012-12-30 23:18:08 +00:00
|
|
|
int result = minZoneNum;
|
2013-02-22 18:23:21 +00:00
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
if (posX >= _vm->_graphicsManager->_scrollOffset + 158 && posX < _vm->_graphicsManager->_scrollOffset + 208)
|
2012-12-30 23:18:08 +00:00
|
|
|
return result;
|
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
if (posX >= _vm->_graphicsManager->_scrollOffset + 208 && posX < _vm->_graphicsManager->_scrollOffset + 266) {
|
2012-12-30 23:18:08 +00:00
|
|
|
result += 1;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
if (posX >= _vm->_graphicsManager->_scrollOffset + 266 && posX < _vm->_graphicsManager->_scrollOffset + 320) {
|
2012-12-30 23:18:08 +00:00
|
|
|
result += 2;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
if (posX >= _vm->_graphicsManager->_scrollOffset + 320 && posX < _vm->_graphicsManager->_scrollOffset + 370) {
|
2012-12-30 23:18:08 +00:00
|
|
|
result += 3;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
if (posX >= _vm->_graphicsManager->_scrollOffset + 370 && posX < _vm->_graphicsManager->_scrollOffset + 424) {
|
2012-12-30 23:18:08 +00:00
|
|
|
result += 4;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
if (!lastRow && posX >= _vm->_graphicsManager->_scrollOffset + 424 && posX <= _vm->_graphicsManager->_scrollOffset + 478) {
|
2012-12-30 23:18:08 +00:00
|
|
|
result += 5;
|
|
|
|
return result;
|
2012-10-03 12:15:39 +00:00
|
|
|
}
|
2012-12-30 23:18:08 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-10-03 12:15:39 +00:00
|
|
|
}
|
|
|
|
|
2012-12-30 23:18:08 +00:00
|
|
|
/**
|
|
|
|
* Add Zone Line
|
|
|
|
*/
|
2013-03-09 08:41:15 +00:00
|
|
|
void LinesManager::addZoneLine(int idx, int fromX, int fromY, int destX, int destY, int bobZoneIdx) {
|
2012-10-13 10:14:18 +00:00
|
|
|
int16 *zoneData;
|
2012-10-02 11:44:23 +00:00
|
|
|
|
2013-03-09 08:41:15 +00:00
|
|
|
if (fromX == fromY && fromY == destX && fromY == destY) {
|
2013-02-12 22:48:03 +00:00
|
|
|
BOBZONE_FLAG[bobZoneIdx] = true;
|
2013-03-09 08:41:15 +00:00
|
|
|
BOBZONE[bobZoneIdx] = fromY;
|
2012-12-30 23:18:08 +00:00
|
|
|
} else {
|
2013-01-27 13:58:47 +00:00
|
|
|
assert (idx <= MAX_LINES);
|
2013-03-20 06:27:42 +00:00
|
|
|
_zoneLine[idx]._zoneData = (int16 *)_vm->_globals->freeMemory((byte *)_zoneLine[idx]._zoneData);
|
2012-12-12 07:05:04 +00:00
|
|
|
|
2013-03-09 08:41:15 +00:00
|
|
|
int distX = abs(fromX - destX);
|
|
|
|
int distY = abs(fromY - destY);
|
|
|
|
int maxDist = 1;
|
|
|
|
if (distX <= distY)
|
|
|
|
maxDist += distY;
|
2012-10-02 11:44:23 +00:00
|
|
|
else
|
2013-03-09 08:41:15 +00:00
|
|
|
maxDist += distX;
|
2012-10-13 10:14:18 +00:00
|
|
|
|
2013-03-20 06:27:42 +00:00
|
|
|
zoneData = (int16 *)_vm->_globals->allocMemory(2 * sizeof(int16) * maxDist + (4 * sizeof(int16)));
|
2013-01-27 22:30:40 +00:00
|
|
|
assert(zoneData != (int16 *)g_PTRNUL);
|
|
|
|
|
|
|
|
_zoneLine[idx]._zoneData = zoneData;
|
2012-10-02 11:44:23 +00:00
|
|
|
|
2012-11-23 23:16:44 +00:00
|
|
|
int16 *dataP = zoneData;
|
2013-03-09 08:41:15 +00:00
|
|
|
int stepX = 1000 * distX / maxDist;
|
|
|
|
int stepY = 1000 * distY / maxDist;
|
|
|
|
if (destX < fromX)
|
|
|
|
stepX = -stepX;
|
|
|
|
if (destY < fromY)
|
|
|
|
stepY = -stepY;
|
|
|
|
int smoothPosX = 1000 * fromX;
|
|
|
|
int smoothPosY = 1000 * fromY;
|
|
|
|
for (int i = 0; i < maxDist; i++) {
|
|
|
|
*dataP++ = smoothPosX / 1000;
|
|
|
|
*dataP++ = smoothPosY / 1000;
|
|
|
|
|
|
|
|
smoothPosX += stepX;
|
|
|
|
smoothPosY += stepY;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2012-10-13 10:14:18 +00:00
|
|
|
*dataP++ = -1;
|
|
|
|
*dataP++ = -1;
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2013-03-09 08:41:15 +00:00
|
|
|
_zoneLine[idx]._count = maxDist;
|
2013-01-27 22:49:20 +00:00
|
|
|
_zoneLine[idx]._bobZoneIdx = bobZoneIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 00:50:29 +00:00
|
|
|
/**
|
|
|
|
* Add Line
|
|
|
|
*/
|
2013-03-09 08:41:15 +00:00
|
|
|
void LinesManager::addLine(int lineIdx, Directions direction, int fromX, int fromY, int destX, int destY) {
|
2013-02-26 22:27:55 +00:00
|
|
|
assert (lineIdx <= MAX_LINES);
|
2013-01-02 14:04:12 +00:00
|
|
|
|
2013-02-26 22:27:55 +00:00
|
|
|
if (_linesNumb < lineIdx)
|
|
|
|
_linesNumb = lineIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
|
2013-03-20 06:27:42 +00:00
|
|
|
_lineItem[lineIdx]._lineData = (int16 *)_vm->_globals->freeMemory((byte *)_lineItem[lineIdx]._lineData);
|
2013-03-09 08:41:15 +00:00
|
|
|
int distX = abs(fromX - destX) + 1;
|
|
|
|
int distY = abs(fromY - destY) + 1;
|
|
|
|
int maxDist = distY;
|
|
|
|
if (distX > maxDist)
|
|
|
|
maxDist = distX;
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2013-03-20 06:27:42 +00:00
|
|
|
byte *zoneData = _vm->_globals->allocMemory(4 * maxDist + 8);
|
2013-03-09 08:41:15 +00:00
|
|
|
assert (zoneData != g_PTRNUL);
|
2012-10-24 22:13:31 +00:00
|
|
|
|
2013-03-09 08:41:15 +00:00
|
|
|
Common::fill(zoneData, zoneData + 4 * maxDist + 8, 0);
|
|
|
|
_lineItem[lineIdx]._lineData = (int16 *)zoneData;
|
2012-10-19 22:16:25 +00:00
|
|
|
|
2013-02-26 22:27:55 +00:00
|
|
|
int16 *curLineData = _lineItem[lineIdx]._lineData;
|
2013-03-09 08:41:15 +00:00
|
|
|
int stepX = 1000 * distX / (maxDist - 1);
|
|
|
|
int stepY = 1000 * distY / (maxDist - 1);
|
|
|
|
if (destX < fromX)
|
|
|
|
stepX = -stepX;
|
|
|
|
if (destY < fromY)
|
|
|
|
stepY = -stepY;
|
|
|
|
int dirX = (int)stepX / 1000; // -1: Left, 0: None, 1: Right
|
|
|
|
int dirY = (int)stepY / 1000; // -1: Up, 0: None, 1: Right
|
2013-02-26 07:06:08 +00:00
|
|
|
if (!dirX) {
|
|
|
|
if (dirY == -1) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_UP;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_DOWN;
|
2013-02-26 07:06:08 +00:00
|
|
|
} else if (dirY == 1) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_DOWN;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_UP;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-26 07:06:08 +00:00
|
|
|
// If dirY == 0, no move
|
|
|
|
} else if (dirX == 1) {
|
|
|
|
if (dirY == -1) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_UP_RIGHT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_DOWN_LEFT;
|
2013-02-26 07:06:08 +00:00
|
|
|
} else if (!dirY) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_RIGHT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_LEFT;
|
2013-02-26 07:06:08 +00:00
|
|
|
} else if (dirY == 1) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_DOWN_RIGHT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_UP_LEFT;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-26 07:06:08 +00:00
|
|
|
} else if (dirX == -1) {
|
|
|
|
if (dirY == 1) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_DOWN_LEFT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_UP_RIGHT;
|
2013-02-26 07:06:08 +00:00
|
|
|
} else if (!dirY) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_LEFT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_RIGHT;
|
2013-02-26 07:06:08 +00:00
|
|
|
} else if (dirY == -1) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_UP_LEFT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_DOWN_RIGHT;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-26 07:06:08 +00:00
|
|
|
|
|
|
|
// Second pass to soften cases where dirY == 0
|
|
|
|
if (dirX == 1) {
|
2013-03-09 08:41:15 +00:00
|
|
|
if (stepY > 250 && stepY <= 999) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_DOWN_RIGHT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_UP_LEFT;
|
2013-03-09 08:41:15 +00:00
|
|
|
} else if (stepY < -250 && stepY > -1000) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_UP_RIGHT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_DOWN_LEFT;
|
2013-02-26 07:06:08 +00:00
|
|
|
}
|
|
|
|
} else if (dirX == -1) {
|
2013-03-09 08:41:15 +00:00
|
|
|
if (stepY > 250 && stepY <= 999) {
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_DOWN_LEFT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_UP_RIGHT;
|
2013-03-09 08:41:15 +00:00
|
|
|
} else if (stepY < -250 && stepY > -1000) {
|
2013-02-26 07:06:08 +00:00
|
|
|
// In the original code, the test was on positive values and
|
|
|
|
// was impossible to meet.
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._directionRouteInc = DIR_UP_LEFT;
|
|
|
|
_lineItem[lineIdx]._directionRouteDec = DIR_DOWN_RIGHT;
|
2013-02-26 07:06:08 +00:00
|
|
|
}
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-26 07:06:08 +00:00
|
|
|
|
2013-03-09 08:41:15 +00:00
|
|
|
stepX = 1000 * distX / maxDist;
|
|
|
|
stepY = 1000 * distY / maxDist;
|
|
|
|
if (destX < fromX)
|
|
|
|
stepX = -stepX;
|
|
|
|
if (destY < fromY)
|
|
|
|
stepY = -stepY;
|
|
|
|
int smoothPosX = 1000 * fromX;
|
|
|
|
int smoothPosY = 1000 * fromY;
|
|
|
|
for (int i = 0; i < maxDist - 1; i++) {
|
|
|
|
curLineData[0] = smoothPosX / 1000;
|
|
|
|
curLineData[1] = smoothPosY / 1000;
|
2013-02-26 07:06:08 +00:00
|
|
|
curLineData += 2;
|
2012-12-22 00:28:31 +00:00
|
|
|
|
2013-03-09 08:41:15 +00:00
|
|
|
smoothPosX += stepX;
|
|
|
|
smoothPosY += stepY;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-09 08:41:15 +00:00
|
|
|
curLineData[0] = destX;
|
|
|
|
curLineData[1] = destY;
|
2012-10-19 22:16:25 +00:00
|
|
|
|
2013-02-26 07:06:08 +00:00
|
|
|
curLineData += 2;
|
|
|
|
curLineData[0] = -1;
|
|
|
|
curLineData[1] = -1;
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2013-03-09 08:41:15 +00:00
|
|
|
_lineItem[lineIdx]._lineDataEndIdx = maxDist;
|
2013-02-26 22:27:55 +00:00
|
|
|
_lineItem[lineIdx]._direction = direction;
|
2013-01-27 21:53:20 +00:00
|
|
|
|
|
|
|
++_linesNumb;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 07:28:15 +00:00
|
|
|
/**
|
|
|
|
* Check collision line
|
|
|
|
*/
|
|
|
|
bool LinesManager::checkCollisionLine(int xp, int yp, int *foundDataIdx, int *foundLineIdx, int startLineIdx, int endLineIdx) {
|
|
|
|
int16 *lineData;
|
|
|
|
|
|
|
|
int left = xp + 4;
|
|
|
|
int right = xp - 4;
|
|
|
|
int top = yp + 4;
|
|
|
|
int bottom = yp - 4;
|
|
|
|
|
|
|
|
*foundDataIdx = -1;
|
|
|
|
*foundLineIdx = -1;
|
|
|
|
|
|
|
|
for (int curLineIdx = startLineIdx; curLineIdx <= endLineIdx; curLineIdx++) {
|
2013-02-20 07:30:16 +00:00
|
|
|
lineData = _lineItem[curLineIdx]._lineData;
|
2013-01-10 07:28:15 +00:00
|
|
|
|
|
|
|
if (lineData == (int16 *)g_PTRNUL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool collisionFl = true;
|
|
|
|
int lineStartX = lineData[0];
|
|
|
|
int lineStartY = lineData[1];
|
2013-02-20 07:30:16 +00:00
|
|
|
int lineDataIdx = 2 * _lineItem[curLineIdx]._lineDataEndIdx;
|
2013-01-10 07:28:15 +00:00
|
|
|
int lineEndX = lineData[lineDataIdx - 2];
|
|
|
|
int lineEndY = lineData[lineDataIdx - 1];
|
|
|
|
if (lineStartX >= lineEndX) {
|
|
|
|
if (right > lineStartX || left < lineEndX)
|
|
|
|
collisionFl = false;
|
|
|
|
} else { // lineStartX < lineEndX
|
|
|
|
if (left < lineStartX || right > lineEndX)
|
|
|
|
collisionFl = false;
|
|
|
|
}
|
|
|
|
if (lineStartY >= lineEndY) {
|
|
|
|
if (bottom > lineStartY || top < lineEndY)
|
|
|
|
collisionFl = false;
|
|
|
|
} else { // lineStartY < lineEndY
|
|
|
|
if (top < lineStartY || bottom > lineEndY)
|
|
|
|
collisionFl = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!collisionFl)
|
|
|
|
continue;
|
|
|
|
|
2013-02-20 07:30:16 +00:00
|
|
|
for (int idx = 0; idx < _lineItem[curLineIdx]._lineDataEndIdx; idx++) {
|
2013-01-10 07:28:15 +00:00
|
|
|
int lineX = lineData[0];
|
|
|
|
int lineY = lineData[1];
|
|
|
|
lineData += 2;
|
|
|
|
|
|
|
|
if ((xp == lineX || xp + 1 == lineX) && (yp == lineY || yp + 1 == lineY)) {
|
|
|
|
*foundDataIdx = idx;
|
|
|
|
*foundLineIdx = curLineIdx;
|
|
|
|
return true;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-10 07:28:15 +00:00
|
|
|
return false;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:10:16 +00:00
|
|
|
/**
|
|
|
|
* Init route
|
|
|
|
*/
|
|
|
|
void LinesManager::initRoute() {
|
2013-02-20 07:30:16 +00:00
|
|
|
int lineX = _lineItem[0]._lineData[0];
|
|
|
|
int lineY = _lineItem[0]._lineData[1];
|
2013-01-10 19:10:16 +00:00
|
|
|
|
|
|
|
int lineIdx = 1;
|
|
|
|
for (;;) {
|
2013-02-20 07:30:16 +00:00
|
|
|
int curDataIdx = _lineItem[lineIdx]._lineDataEndIdx;
|
|
|
|
int16 *curLineData = _lineItem[lineIdx]._lineData;
|
2013-01-10 19:10:16 +00:00
|
|
|
|
|
|
|
int curLineX = curLineData[2 * curDataIdx - 2];
|
|
|
|
int curLineY = curLineData[2 * curDataIdx - 1];
|
2013-03-20 06:36:06 +00:00
|
|
|
if (_vm->_graphicsManager->_maxX == curLineX || _vm->_graphicsManager->_maxY == curLineY ||
|
|
|
|
_vm->_graphicsManager->_minX == curLineX || _vm->_graphicsManager->_minY == curLineY ||
|
2013-01-10 19:10:16 +00:00
|
|
|
(lineX == curLineX && lineY == curLineY))
|
|
|
|
break;
|
2013-01-10 21:09:37 +00:00
|
|
|
if (lineIdx == MAX_LINES)
|
2012-10-02 11:44:23 +00:00
|
|
|
error("ERROR - LAST LINE NOT FOUND");
|
2012-12-31 00:09:06 +00:00
|
|
|
|
2013-02-20 07:30:16 +00:00
|
|
|
int16 *nextLineData = _lineItem[lineIdx + 1]._lineData;
|
2013-01-10 19:10:16 +00:00
|
|
|
if (nextLineData[0] != curLineX && nextLineData[1] != curLineY)
|
|
|
|
break;
|
|
|
|
++lineIdx;
|
|
|
|
}
|
|
|
|
|
2013-01-27 11:53:00 +00:00
|
|
|
_lastLine = lineIdx;
|
2013-01-10 21:09:37 +00:00
|
|
|
for (int idx = 1; idx < MAX_LINES; idx++) {
|
2013-02-20 07:30:16 +00:00
|
|
|
if ((_lineItem[idx]._lineDataEndIdx < _maxLineIdx) && (idx != _lastLine + 1)) {
|
|
|
|
_lineItem[idx]._directionRouteInc = _lineItem[idx - 1]._directionRouteInc;
|
|
|
|
_lineItem[idx]._directionRouteDec = _lineItem[idx - 1]._directionRouteDec;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2012-12-17 23:37:52 +00:00
|
|
|
}
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2012-10-20 16:59:06 +00:00
|
|
|
// Avoid
|
2013-02-26 07:21:28 +00:00
|
|
|
int LinesManager::CONTOURNE(int lineIdx, int lineDataIdx, int routeIdx, int destLineIdx, int destLineDataIdx, RouteItem *route) {
|
|
|
|
int curLineIdx = lineIdx;
|
|
|
|
int curLineDataIdx = lineDataIdx;
|
|
|
|
int curRouteIdx = routeIdx;
|
|
|
|
if (lineIdx < destLineIdx) {
|
|
|
|
curRouteIdx = _lineItem[lineIdx].appendToRouteInc(lineDataIdx, -1, route, curRouteIdx);
|
|
|
|
|
|
|
|
for (int i = lineIdx + 1; i < destLineIdx; i++)
|
|
|
|
curRouteIdx = _lineItem[i].appendToRouteInc(0, -1, route, curRouteIdx);
|
|
|
|
|
|
|
|
curLineDataIdx = 0;
|
|
|
|
curLineIdx = destLineIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-26 07:21:28 +00:00
|
|
|
if (curLineIdx > destLineIdx) {
|
|
|
|
curRouteIdx = _lineItem[curLineIdx].appendToRouteDec(curLineDataIdx, 0, route, curRouteIdx);
|
|
|
|
for (int i = curLineIdx - 1; i > destLineIdx; i--)
|
|
|
|
curRouteIdx = _lineItem[i].appendToRouteDec(-1, 0, route, curRouteIdx);
|
|
|
|
curLineDataIdx = _lineItem[destLineIdx]._lineDataEndIdx - 1;
|
|
|
|
curLineIdx = destLineIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-26 07:21:28 +00:00
|
|
|
if (curLineIdx == destLineIdx) {
|
|
|
|
if (destLineDataIdx >= curLineDataIdx) {
|
|
|
|
curRouteIdx = _lineItem[destLineIdx].appendToRouteInc(curLineDataIdx, destLineDataIdx, route, curRouteIdx);
|
2012-10-02 11:44:23 +00:00
|
|
|
} else {
|
2013-02-26 07:21:28 +00:00
|
|
|
curRouteIdx = _lineItem[destLineIdx].appendToRouteDec(curLineDataIdx, destLineDataIdx, route, curRouteIdx);
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-26 07:21:28 +00:00
|
|
|
return curRouteIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2012-10-20 16:59:06 +00:00
|
|
|
// Avoid 1
|
2013-02-26 07:21:28 +00:00
|
|
|
int LinesManager::CONTOURNE1(int lineIdx, int lineDataIdx, int routeIdx, int destLineIdx, int destLineDataIdx, RouteItem *route, int a8, int a9) {
|
|
|
|
int curLineIdx = lineIdx;
|
|
|
|
int curLineDataIdx = lineDataIdx;
|
|
|
|
int curRouteIdx = routeIdx;
|
|
|
|
if (destLineIdx < lineIdx) {
|
|
|
|
curRouteIdx = _lineItem[lineIdx].appendToRouteInc(lineDataIdx, -1, route, curRouteIdx);
|
2013-03-10 22:53:03 +00:00
|
|
|
int wrkLineIdx = lineIdx + 1;
|
|
|
|
if (wrkLineIdx == a9 + 1)
|
|
|
|
wrkLineIdx = a8;
|
|
|
|
while (destLineIdx != wrkLineIdx) {
|
|
|
|
curRouteIdx = _lineItem[wrkLineIdx].appendToRouteInc(0, -1, route, curRouteIdx);
|
|
|
|
++wrkLineIdx;
|
|
|
|
if (a9 + 1 == wrkLineIdx)
|
|
|
|
wrkLineIdx = a8;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-26 07:21:28 +00:00
|
|
|
curLineDataIdx = 0;
|
|
|
|
curLineIdx = destLineIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-26 07:21:28 +00:00
|
|
|
if (destLineIdx > curLineIdx) {
|
|
|
|
curRouteIdx = _lineItem[curLineIdx].appendToRouteDec(curLineDataIdx, 0, route, curRouteIdx);
|
2013-03-10 22:53:03 +00:00
|
|
|
int wrkLineIdx = curLineIdx - 1;
|
|
|
|
if (wrkLineIdx == a8 - 1)
|
|
|
|
wrkLineIdx = a9;
|
|
|
|
while (destLineIdx != wrkLineIdx) {
|
|
|
|
curRouteIdx = _lineItem[wrkLineIdx].appendToRouteDec(-1, 0, route, curRouteIdx);
|
|
|
|
--wrkLineIdx;
|
|
|
|
if (a8 - 1 == wrkLineIdx)
|
|
|
|
wrkLineIdx = a9;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-26 07:21:28 +00:00
|
|
|
curLineDataIdx = _lineItem[destLineIdx]._lineDataEndIdx - 1;
|
|
|
|
curLineIdx = destLineIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-26 07:21:28 +00:00
|
|
|
if (destLineIdx == curLineIdx) {
|
|
|
|
if (destLineDataIdx >= curLineDataIdx) {
|
|
|
|
curRouteIdx = _lineItem[destLineIdx].appendToRouteInc(curLineDataIdx, destLineDataIdx, route, curRouteIdx);
|
2012-10-02 11:44:23 +00:00
|
|
|
} else {
|
2013-02-26 07:21:28 +00:00
|
|
|
curRouteIdx = _lineItem[destLineIdx].appendToRouteDec(curLineDataIdx, destLineDataIdx, route, curRouteIdx);
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-26 07:21:28 +00:00
|
|
|
return curRouteIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 22:27:55 +00:00
|
|
|
bool LinesManager::MIRACLE(int fromX, int fromY, int lineIdx, int destLineIdx, int routeIdx) {
|
2013-03-07 07:23:28 +00:00
|
|
|
int newLinesDataIdx = 0;
|
|
|
|
int newLinesIdx = 0;
|
2013-03-06 23:27:47 +00:00
|
|
|
int lineIdxLeft = 0;
|
|
|
|
int lineDataIdxLeft = 0;
|
|
|
|
int lineIdxRight = 0;
|
|
|
|
int lineDataIdxRight = 0;
|
|
|
|
int linesIdxUp = 0;
|
|
|
|
int linesDataIdxUp = 0;
|
|
|
|
int lineIdxDown = 0;
|
|
|
|
int lineDataIdxDown = 0;
|
2012-10-02 11:44:23 +00:00
|
|
|
|
2013-02-15 22:57:23 +00:00
|
|
|
int curX = fromX;
|
|
|
|
int curY = fromY;
|
2013-02-26 22:27:55 +00:00
|
|
|
int curLineIdx = lineIdx;
|
2013-03-06 23:27:47 +00:00
|
|
|
int tmpRouteIdx = routeIdx;
|
2013-02-26 22:27:55 +00:00
|
|
|
int dummyDataIdx;
|
|
|
|
if (checkCollisionLine(fromX, fromY, &dummyDataIdx, &curLineIdx, 0, _linesNumb)) {
|
|
|
|
switch (_lineItem[curLineIdx]._direction) {
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_UP:
|
2013-02-15 22:57:23 +00:00
|
|
|
curY -= 2;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_UP_RIGHT:
|
2013-02-15 22:57:23 +00:00
|
|
|
curY -= 2;
|
|
|
|
curX += 2;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_RIGHT:
|
2013-02-15 22:57:23 +00:00
|
|
|
curX += 2;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN_RIGHT:
|
2013-02-15 22:57:23 +00:00
|
|
|
curY += 2;
|
|
|
|
curX += 2;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN:
|
2013-02-15 22:57:23 +00:00
|
|
|
curY += 2;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN_LEFT:
|
2013-02-15 22:57:23 +00:00
|
|
|
curY += 2;
|
|
|
|
curX -= 2;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_LEFT:
|
2013-02-15 22:57:23 +00:00
|
|
|
curX -= 2;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_UP_LEFT:
|
2013-02-15 22:57:23 +00:00
|
|
|
curY -= 2;
|
|
|
|
curX -= 2;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-19 04:43:19 +00:00
|
|
|
default:
|
|
|
|
break;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
|
|
|
|
int stepVertIncCount = 0;
|
|
|
|
for (int i = curY; curY + 200 > i; i++) {
|
|
|
|
if (checkCollisionLine(curX, i, &lineDataIdxDown, &lineIdxDown, 0, _lastLine) == 1 && lineIdxDown <= _lastLine)
|
2012-10-02 11:44:23 +00:00
|
|
|
break;
|
2013-03-06 23:27:47 +00:00
|
|
|
lineDataIdxDown = 0;
|
|
|
|
lineIdxDown = -1;
|
2013-03-07 07:23:28 +00:00
|
|
|
++stepVertIncCount;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
|
|
|
|
int stepVertDecCount = 0;
|
|
|
|
for (int i = curY; curY - 200 < i; i--) {
|
|
|
|
if (checkCollisionLine(curX, i, &linesDataIdxUp, &linesIdxUp, 0, _lastLine) == 1 && linesIdxUp <= _lastLine)
|
2012-10-02 11:44:23 +00:00
|
|
|
break;
|
2013-03-06 23:27:47 +00:00
|
|
|
linesDataIdxUp = 0;
|
|
|
|
linesIdxUp = -1;
|
2013-03-07 07:23:28 +00:00
|
|
|
++stepVertDecCount;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
|
|
|
|
int stepHoriIncCount = 0;
|
|
|
|
for (int i = curX; curX + 200 > i; i++) {
|
|
|
|
if (checkCollisionLine(i, curY, &lineDataIdxRight, &lineIdxRight, 0, _lastLine) == 1 && lineIdxRight <= _lastLine)
|
2012-10-02 11:44:23 +00:00
|
|
|
break;
|
2013-03-06 23:27:47 +00:00
|
|
|
lineDataIdxRight = 0;
|
|
|
|
lineIdxRight = -1;
|
2013-03-07 07:23:28 +00:00
|
|
|
++stepHoriIncCount;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
|
|
|
|
int stepHoriDecCount = 0;
|
|
|
|
for (int i = curX; curX - 200 < i; i--) {
|
|
|
|
if (checkCollisionLine(i, curY, &lineDataIdxLeft, &lineIdxLeft, 0, _lastLine) == 1 && lineIdxLeft <= _lastLine)
|
2012-10-02 11:44:23 +00:00
|
|
|
break;
|
2013-03-06 23:27:47 +00:00
|
|
|
lineDataIdxLeft = 0;
|
|
|
|
lineIdxLeft = -1;
|
2013-03-07 07:23:28 +00:00
|
|
|
++stepHoriDecCount;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
|
2013-02-26 22:27:55 +00:00
|
|
|
if (destLineIdx > curLineIdx) {
|
2013-03-06 23:27:47 +00:00
|
|
|
if (linesIdxUp != -1 && linesIdxUp <= curLineIdx)
|
|
|
|
linesIdxUp = -1;
|
|
|
|
if (lineIdxRight != -1 && curLineIdx >= lineIdxRight)
|
|
|
|
lineIdxRight = -1;
|
|
|
|
if (lineIdxDown != -1 && curLineIdx >= lineIdxDown)
|
|
|
|
lineIdxDown = -1;
|
|
|
|
if (lineIdxLeft != -1 && curLineIdx >= lineIdxLeft)
|
|
|
|
lineIdxLeft = -1;
|
|
|
|
if (linesIdxUp != -1 && destLineIdx < linesIdxUp)
|
|
|
|
linesIdxUp = -1;
|
|
|
|
if (lineIdxRight != -1 && destLineIdx < lineIdxRight)
|
|
|
|
lineIdxRight = -1;
|
|
|
|
if (lineIdxDown != -1 && destLineIdx < lineIdxDown)
|
|
|
|
lineIdxDown = -1;
|
|
|
|
if (lineIdxLeft != -1 && destLineIdx < lineIdxLeft)
|
|
|
|
lineIdxLeft = -1;
|
2013-02-26 22:27:55 +00:00
|
|
|
} else if (destLineIdx < curLineIdx) {
|
2013-03-06 23:27:47 +00:00
|
|
|
if (linesIdxUp != -1 && linesIdxUp >= curLineIdx)
|
|
|
|
linesIdxUp = -1;
|
|
|
|
if (lineIdxRight != -1 && curLineIdx <= lineIdxRight)
|
|
|
|
lineIdxRight = -1;
|
|
|
|
if (lineIdxDown != -1 && curLineIdx <= lineIdxDown)
|
|
|
|
lineIdxDown = -1;
|
|
|
|
if (lineIdxLeft != -1 && curLineIdx <= lineIdxLeft)
|
|
|
|
lineIdxLeft = -1;
|
|
|
|
if (linesIdxUp != -1 && destLineIdx > linesIdxUp)
|
|
|
|
linesIdxUp = -1;
|
|
|
|
if (lineIdxRight != -1 && destLineIdx > lineIdxRight)
|
|
|
|
lineIdxRight = -1;
|
|
|
|
if (lineIdxDown != -1 && destLineIdx > lineIdxDown)
|
|
|
|
lineIdxDown = -1;
|
|
|
|
if (lineIdxLeft != -1 && destLineIdx > lineIdxLeft)
|
|
|
|
lineIdxLeft = -1;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-06 23:27:47 +00:00
|
|
|
if (linesIdxUp != -1 || lineIdxRight != -1 || lineIdxDown != -1 || lineIdxLeft != -1) {
|
2013-02-18 00:19:41 +00:00
|
|
|
Directions newDir = DIR_NONE;
|
2013-02-26 22:27:55 +00:00
|
|
|
if (destLineIdx > curLineIdx) {
|
2013-03-06 23:27:47 +00:00
|
|
|
if (lineIdxDown <= linesIdxUp && lineIdxRight <= linesIdxUp && lineIdxLeft <= linesIdxUp && linesIdxUp > curLineIdx)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_UP;
|
2013-03-06 23:27:47 +00:00
|
|
|
if (lineIdxDown <= lineIdxRight && linesIdxUp <= lineIdxRight && lineIdxLeft <= lineIdxRight && curLineIdx < lineIdxRight)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_RIGHT;
|
2013-03-06 23:27:47 +00:00
|
|
|
if (linesIdxUp <= lineIdxDown && lineIdxRight <= lineIdxDown && lineIdxLeft <= lineIdxDown && curLineIdx < lineIdxDown)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_DOWN;
|
2013-03-06 23:27:47 +00:00
|
|
|
if (lineIdxDown <= lineIdxLeft && lineIdxRight <= lineIdxLeft && linesIdxUp <= lineIdxLeft && curLineIdx < lineIdxLeft)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_LEFT;
|
2013-02-26 22:27:55 +00:00
|
|
|
} else if (destLineIdx < curLineIdx) {
|
2013-03-06 23:27:47 +00:00
|
|
|
if (linesIdxUp == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
linesIdxUp = INVALID_LINE_VALUE;
|
2013-03-06 23:27:47 +00:00
|
|
|
if (lineIdxRight == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
lineIdxRight = INVALID_LINE_VALUE;
|
2013-03-06 23:27:47 +00:00
|
|
|
if (lineIdxDown == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
lineIdxDown = INVALID_LINE_VALUE;
|
2013-03-06 23:27:47 +00:00
|
|
|
if (lineIdxLeft == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
lineIdxLeft = INVALID_LINE_VALUE;
|
|
|
|
if (linesIdxUp != INVALID_LINE_VALUE && lineIdxDown >= linesIdxUp && lineIdxRight >= linesIdxUp && lineIdxLeft >= linesIdxUp && linesIdxUp < curLineIdx)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_UP;
|
2013-03-11 06:25:45 +00:00
|
|
|
if (lineIdxRight != INVALID_LINE_VALUE && lineIdxDown >= lineIdxRight && linesIdxUp >= lineIdxRight && lineIdxLeft >= lineIdxRight && curLineIdx > lineIdxRight)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_RIGHT;
|
2013-03-11 06:25:45 +00:00
|
|
|
if (lineIdxDown != INVALID_LINE_VALUE && linesIdxUp >= lineIdxDown && lineIdxRight >= lineIdxDown && lineIdxLeft >= lineIdxDown && curLineIdx > lineIdxDown)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_DOWN;
|
2013-03-11 06:25:45 +00:00
|
|
|
if (lineIdxLeft != INVALID_LINE_VALUE && lineIdxDown >= lineIdxLeft && lineIdxRight >= lineIdxLeft && linesIdxUp >= lineIdxLeft && curLineIdx > lineIdxLeft)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_LEFT;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-15 22:41:05 +00:00
|
|
|
|
2013-02-18 00:19:41 +00:00
|
|
|
switch(newDir) {
|
|
|
|
case DIR_UP:
|
2013-03-07 07:23:28 +00:00
|
|
|
newLinesIdx = linesIdxUp;
|
|
|
|
newLinesDataIdx = linesDataIdxUp;
|
|
|
|
for (int i = 0; i < stepVertDecCount; i++) {
|
|
|
|
if (checkCollisionLine(curX, curY - i, &linesDataIdxUp, &linesIdxUp, _lastLine + 1, _linesNumb) && _lastLine < linesIdxUp) {
|
|
|
|
int tmpRouteIdxUp = GENIAL(linesIdxUp, linesDataIdxUp, curX, curY - i, curX, curY - stepVertDecCount, tmpRouteIdx, &_bestRoute[0]);
|
2013-03-06 23:27:47 +00:00
|
|
|
if (tmpRouteIdxUp == -1)
|
2013-02-15 22:41:05 +00:00
|
|
|
return false;
|
2013-03-06 23:27:47 +00:00
|
|
|
tmpRouteIdx = tmpRouteIdxUp;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosY != -1)
|
2013-03-07 07:23:28 +00:00
|
|
|
i = _newPosY - curY;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
_bestRoute[tmpRouteIdx].set(curX, curY - i, DIR_UP);
|
2013-03-06 23:27:47 +00:00
|
|
|
tmpRouteIdx++;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
_newLineIdx = newLinesIdx;
|
|
|
|
_newLineDataIdx = newLinesDataIdx;
|
2013-03-06 23:27:47 +00:00
|
|
|
_newRouteIdx = tmpRouteIdx;
|
2013-02-15 22:41:05 +00:00
|
|
|
return true;
|
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_RIGHT:
|
2013-03-07 07:23:28 +00:00
|
|
|
newLinesIdx = lineIdxRight;
|
|
|
|
newLinesDataIdx = lineDataIdxRight;
|
|
|
|
for (int i = 0; i < stepHoriIncCount; i++) {
|
|
|
|
if (checkCollisionLine(i + curX, curY, &linesDataIdxUp, &linesIdxUp, _lastLine + 1, _linesNumb) && _lastLine < linesIdxUp) {
|
|
|
|
int tmpRouteIdxRight = GENIAL(linesIdxUp, linesDataIdxUp, i + curX, curY, stepHoriIncCount + curX, curY, tmpRouteIdx, &_bestRoute[0]);
|
2013-03-06 23:27:47 +00:00
|
|
|
if (tmpRouteIdxRight == -1)
|
2013-02-15 22:41:05 +00:00
|
|
|
return false;
|
2013-03-06 23:27:47 +00:00
|
|
|
tmpRouteIdx = tmpRouteIdxRight;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosX != -1)
|
2013-03-07 07:23:28 +00:00
|
|
|
i = _newPosX - curX;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
_bestRoute[tmpRouteIdx].set(i + curX, curY, DIR_RIGHT);
|
2013-03-06 23:27:47 +00:00
|
|
|
tmpRouteIdx++;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
_newLineIdx = newLinesIdx;
|
|
|
|
_newLineDataIdx = newLinesDataIdx;
|
2013-03-06 23:27:47 +00:00
|
|
|
_newRouteIdx = tmpRouteIdx;
|
2013-02-15 22:41:05 +00:00
|
|
|
return true;
|
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN:
|
2013-03-07 07:23:28 +00:00
|
|
|
newLinesIdx = lineIdxDown;
|
|
|
|
newLinesDataIdx = lineDataIdxDown;
|
|
|
|
for (int i = 0; i < stepVertIncCount; i++) {
|
|
|
|
if (checkCollisionLine(curX, i + curY, &linesDataIdxUp, &linesIdxUp, _lastLine + 1, _linesNumb) && _lastLine < linesIdxUp) {
|
|
|
|
int tmpRouteIdxDown = GENIAL(linesIdxUp, linesDataIdxUp, curX, i + curY, curX, stepVertIncCount + curY, tmpRouteIdx, &_bestRoute[0]);
|
2013-03-06 23:27:47 +00:00
|
|
|
if (tmpRouteIdxDown == -1)
|
2013-02-15 22:41:05 +00:00
|
|
|
return false;
|
2013-03-06 23:27:47 +00:00
|
|
|
tmpRouteIdx = tmpRouteIdxDown;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosY != -1)
|
2013-03-07 07:23:28 +00:00
|
|
|
i = curY - _newPosY;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
_bestRoute[tmpRouteIdx].set(curX, i + curY, DIR_DOWN);
|
2013-03-06 23:27:47 +00:00
|
|
|
tmpRouteIdx++;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
_newLineIdx = newLinesIdx;
|
|
|
|
_newLineDataIdx = newLinesDataIdx;
|
2013-03-06 23:27:47 +00:00
|
|
|
_newRouteIdx = tmpRouteIdx;
|
2013-02-15 22:41:05 +00:00
|
|
|
return true;
|
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_LEFT:
|
2013-03-07 07:23:28 +00:00
|
|
|
newLinesIdx = lineIdxLeft;
|
|
|
|
newLinesDataIdx = lineDataIdxLeft;
|
|
|
|
for (int i = 0; i < stepHoriDecCount; i++) {
|
|
|
|
if (checkCollisionLine(curX - i, curY, &linesDataIdxUp, &linesIdxUp, _lastLine + 1, _linesNumb) && _lastLine < linesIdxUp) {
|
|
|
|
int tmpRouteIdxLeft = GENIAL(linesIdxUp, linesDataIdxUp, curX - i, curY, curX - stepHoriDecCount, curY, tmpRouteIdx, &_bestRoute[0]);
|
2013-03-06 23:27:47 +00:00
|
|
|
if (tmpRouteIdxLeft == -1)
|
2013-02-15 22:41:05 +00:00
|
|
|
return false;
|
2013-03-06 23:27:47 +00:00
|
|
|
tmpRouteIdx = tmpRouteIdxLeft;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosX != -1)
|
2013-03-07 07:23:28 +00:00
|
|
|
i = curX - _newPosX;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
_bestRoute[tmpRouteIdx].set(curX - i, curY, DIR_LEFT);
|
2013-03-06 23:27:47 +00:00
|
|
|
tmpRouteIdx++;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-07 07:23:28 +00:00
|
|
|
_newLineIdx = newLinesIdx;
|
|
|
|
_newLineDataIdx = newLinesDataIdx;
|
2013-03-06 23:27:47 +00:00
|
|
|
_newRouteIdx = tmpRouteIdx;
|
2013-02-15 22:41:05 +00:00
|
|
|
return true;
|
|
|
|
break;
|
2013-02-19 04:43:19 +00:00
|
|
|
default:
|
|
|
|
break;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-11 00:50:29 +00:00
|
|
|
return false;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 22:27:55 +00:00
|
|
|
int LinesManager::GENIAL(int lineIdx, int dataIdx, int fromX, int fromY, int destX, int destY, int routerIdx, RouteItem *route) {
|
2013-02-26 07:21:28 +00:00
|
|
|
int result = routerIdx;
|
2013-01-27 14:22:57 +00:00
|
|
|
++_pathFindingMaxDepth;
|
|
|
|
if (_pathFindingMaxDepth > 10) {
|
2013-01-12 10:55:44 +00:00
|
|
|
warning("PathFinding - Max depth reached");
|
2013-02-26 07:21:28 +00:00
|
|
|
route[routerIdx].invalidate();
|
2012-10-02 11:44:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-03-12 22:22:56 +00:00
|
|
|
int lineX = _lineItem[lineIdx]._lineData[0];
|
|
|
|
int lineY = _lineItem[lineIdx]._lineData[1];
|
|
|
|
int startLineIdx = lineIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
|
2013-03-12 22:22:56 +00:00
|
|
|
int curLineDataEndIdx;
|
2013-02-06 22:50:59 +00:00
|
|
|
bool loopCond = false;
|
2012-12-04 20:36:53 +00:00
|
|
|
for (;;) {
|
2013-03-18 06:59:26 +00:00
|
|
|
int curLineIdx = startLineIdx - 1;
|
|
|
|
int endLineIdx = 2 * _lineItem[startLineIdx - 1]._lineDataEndIdx;
|
2012-10-19 22:16:25 +00:00
|
|
|
|
2013-03-12 22:22:56 +00:00
|
|
|
int16 *lineData = _lineItem[startLineIdx - 1]._lineData;
|
|
|
|
if (lineData == (int16 *)g_PTRNUL)
|
2012-10-02 11:44:23 +00:00
|
|
|
break;
|
2013-03-18 06:59:26 +00:00
|
|
|
while (lineData[endLineIdx - 2] != lineX || lineY != lineData[endLineIdx - 1]) {
|
|
|
|
--curLineIdx;
|
|
|
|
if (_lastLine - 1 != curLineIdx) {
|
|
|
|
endLineIdx = 2 * _lineItem[curLineIdx]._lineDataEndIdx;
|
|
|
|
lineData = _lineItem[curLineIdx]._lineData;
|
2013-03-12 22:22:56 +00:00
|
|
|
if (lineData != (int16 *)g_PTRNUL)
|
2012-10-02 11:44:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-02-06 22:50:59 +00:00
|
|
|
loopCond = true;
|
|
|
|
break;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-06 22:50:59 +00:00
|
|
|
if (loopCond)
|
|
|
|
break;
|
2012-10-19 22:16:25 +00:00
|
|
|
|
2013-03-18 06:59:26 +00:00
|
|
|
startLineIdx = curLineIdx;
|
2013-03-12 22:22:56 +00:00
|
|
|
lineX = lineData[0];
|
|
|
|
lineY = lineData[1];
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-06 22:50:59 +00:00
|
|
|
|
2013-03-12 22:22:56 +00:00
|
|
|
int lastIdx = _lineItem[lineIdx]._lineDataEndIdx - 1;
|
|
|
|
int lastPosX = _lineItem[lineIdx]._lineData[(2 * lastIdx)];
|
|
|
|
int lastPosY = _lineItem[lineIdx]._lineData[(2 * lastIdx) + 1];
|
|
|
|
int endLineIdx = lineIdx;
|
2013-01-27 11:04:24 +00:00
|
|
|
int foundLineIdx, foundDataIdx;
|
2013-02-06 22:50:59 +00:00
|
|
|
loopCond = false;
|
2012-10-19 22:16:25 +00:00
|
|
|
for (;;) {
|
2013-03-12 22:22:56 +00:00
|
|
|
int curLineIdx = endLineIdx + 1;
|
|
|
|
int nextLineDataEndIdx = 2 * _lineItem[curLineIdx]._lineDataEndIdx;
|
|
|
|
int16 *lineData = _lineItem[curLineIdx]._lineData;
|
|
|
|
if (lineData == (int16 *)g_PTRNUL)
|
2012-10-02 11:44:23 +00:00
|
|
|
break;
|
2012-12-04 20:36:53 +00:00
|
|
|
for (;;) {
|
2013-03-12 22:22:56 +00:00
|
|
|
curLineDataEndIdx = nextLineDataEndIdx;
|
|
|
|
if (lineData[0] == lastPosX && lastPosY == lineData[1])
|
2013-01-24 07:04:58 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-12 22:22:56 +00:00
|
|
|
++curLineIdx;
|
|
|
|
if (curLineIdx != _linesNumb + 1) {
|
|
|
|
nextLineDataEndIdx = 2 * _lineItem[curLineIdx]._lineDataEndIdx;
|
|
|
|
lineData = _lineItem[curLineIdx]._lineData;
|
|
|
|
if (lineData != (int16 *)g_PTRNUL)
|
2012-10-02 11:44:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-02-06 22:50:59 +00:00
|
|
|
loopCond = true;
|
|
|
|
break;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-06 22:50:59 +00:00
|
|
|
if (loopCond)
|
|
|
|
break;
|
|
|
|
|
2013-03-12 22:22:56 +00:00
|
|
|
endLineIdx = curLineIdx;
|
|
|
|
lastPosX = lineData[curLineDataEndIdx - 2];
|
|
|
|
lastPosY = lineData[curLineDataEndIdx - 1];
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-06 22:50:59 +00:00
|
|
|
|
2013-03-09 08:41:15 +00:00
|
|
|
int distX = abs(fromX - destX) + 1;
|
|
|
|
int distY = abs(fromY - destY) + 1;
|
|
|
|
int maxDist = distY;
|
|
|
|
if (distX > distY)
|
|
|
|
maxDist = distX;
|
|
|
|
int stepX = 1000 * distX / maxDist;
|
|
|
|
int stepY = 1000 * distY / maxDist;
|
|
|
|
int smoothPosX = 1000 * fromX;
|
|
|
|
int smoothPosY = 1000 * fromY;
|
2013-02-26 22:27:55 +00:00
|
|
|
if (destX < fromX)
|
2013-03-09 08:41:15 +00:00
|
|
|
stepX = -stepX;
|
2013-02-26 22:27:55 +00:00
|
|
|
if (destY < fromY)
|
2013-03-09 08:41:15 +00:00
|
|
|
stepY = -stepY;
|
|
|
|
if (maxDist > 800)
|
|
|
|
maxDist = 800;
|
2012-10-20 06:06:57 +00:00
|
|
|
|
2013-02-20 07:30:16 +00:00
|
|
|
Common::fill(&_lineBuf[0], &_lineBuf[1000], 0);
|
2013-01-12 10:55:44 +00:00
|
|
|
int bugLigIdx = 0;
|
2013-03-09 08:41:15 +00:00
|
|
|
for (int i = 0; i < maxDist + 1; i++) {
|
|
|
|
_lineBuf[bugLigIdx] = smoothPosX / 1000;
|
|
|
|
_lineBuf[bugLigIdx + 1] = smoothPosY / 1000;
|
|
|
|
smoothPosX += stepX;
|
|
|
|
smoothPosY += stepY;
|
2013-01-12 10:55:44 +00:00
|
|
|
bugLigIdx += 2;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-01-12 10:55:44 +00:00
|
|
|
bugLigIdx -= 2;
|
2013-03-18 06:59:26 +00:00
|
|
|
int destDataIdx = 0;
|
|
|
|
int destLineIdx = -1;
|
2013-03-14 07:05:09 +00:00
|
|
|
int bufX = 0;
|
|
|
|
int bufY = 0;
|
2013-03-18 06:59:26 +00:00
|
|
|
for (int i = maxDist + 1; i > 0; i--) {
|
2013-03-12 22:22:56 +00:00
|
|
|
if (checkCollisionLine(_lineBuf[bugLigIdx], _lineBuf[bugLigIdx + 1], &foundDataIdx, &foundLineIdx, startLineIdx, endLineIdx) && _lastLine < foundLineIdx) {
|
2013-03-18 06:59:26 +00:00
|
|
|
destLineIdx = foundLineIdx;
|
|
|
|
destDataIdx = foundDataIdx;
|
2013-03-14 07:05:09 +00:00
|
|
|
bufX = _lineBuf[bugLigIdx];
|
|
|
|
bufY = _lineBuf[bugLigIdx + 1];
|
2012-12-22 00:28:31 +00:00
|
|
|
break;
|
2013-01-12 10:55:44 +00:00
|
|
|
}
|
|
|
|
bugLigIdx -= 2;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-15 06:46:30 +00:00
|
|
|
int maxLineX = 0;
|
|
|
|
int minLineX = 0;
|
|
|
|
int maxLineY = 0;
|
|
|
|
int minLineY = 0;
|
2013-03-12 22:22:56 +00:00
|
|
|
for (int i = startLineIdx; i <= endLineIdx; ++i) {
|
2013-02-20 07:30:16 +00:00
|
|
|
int16 *lineData = _lineItem[i]._lineData;
|
2013-01-12 10:55:44 +00:00
|
|
|
if (lineData == (int16 *)g_PTRNUL)
|
2012-10-19 22:16:25 +00:00
|
|
|
error("error in genial routine");
|
2013-03-12 22:22:56 +00:00
|
|
|
if (i == startLineIdx) {
|
2013-03-15 06:46:30 +00:00
|
|
|
minLineY = MIN(lineData[1], lineData[2 * _lineItem[i]._lineDataEndIdx - 1]);
|
|
|
|
maxLineY = MAX(lineData[1], lineData[2 * _lineItem[i]._lineDataEndIdx - 1]);
|
|
|
|
|
|
|
|
minLineX = MIN(lineData[0], lineData[2 * _lineItem[i]._lineDataEndIdx - 2]);
|
|
|
|
maxLineX = MAX(lineData[0], lineData[2 * _lineItem[i]._lineDataEndIdx - 2]);
|
2012-10-02 11:44:23 +00:00
|
|
|
} else {
|
2013-03-15 06:46:30 +00:00
|
|
|
if (lineData[1] < lineData[2 * _lineItem[i]._lineDataEndIdx - 1] && lineData[1] < minLineY)
|
|
|
|
minLineY = lineData[1];
|
|
|
|
if (lineData[2 * _lineItem[i]._lineDataEndIdx - 1] < lineData[1] && lineData[2 * _lineItem[i]._lineDataEndIdx - 1] < minLineY)
|
|
|
|
minLineY = lineData[2 * _lineItem[i]._lineDataEndIdx - 1];
|
|
|
|
if (lineData[1] > lineData[2 * _lineItem[i]._lineDataEndIdx - 1] && lineData[1] > maxLineY)
|
|
|
|
maxLineY = lineData[1];
|
|
|
|
if (lineData[2 * _lineItem[i]._lineDataEndIdx - 1] > lineData[1] && lineData[2 * _lineItem[i]._lineDataEndIdx - 1] > maxLineY)
|
|
|
|
maxLineY = lineData[2 * _lineItem[i]._lineDataEndIdx - 1];
|
|
|
|
if (lineData[0] < lineData[2 * _lineItem[i]._lineDataEndIdx - 2] && minLineX > lineData[0])
|
|
|
|
minLineX = lineData[0];
|
|
|
|
if (lineData[2 * _lineItem[i]._lineDataEndIdx - 2] < lineData[0] && minLineX > lineData[2 * _lineItem[i]._lineDataEndIdx - 2])
|
|
|
|
minLineX = lineData[2 * _lineItem[i]._lineDataEndIdx - 2];
|
|
|
|
if (lineData[0] > lineData[2 * _lineItem[i]._lineDataEndIdx - 2] && maxLineX < lineData[0])
|
|
|
|
maxLineX = lineData[0];
|
|
|
|
if (lineData[2 * _lineItem[i]._lineDataEndIdx - 2] > lineData[0] && maxLineX < lineData[2 * _lineItem[i]._lineDataEndIdx - 2])
|
|
|
|
maxLineX = lineData[2 * _lineItem[i]._lineDataEndIdx - 2];
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-15 06:46:30 +00:00
|
|
|
|
|
|
|
minLineX -= 2;
|
|
|
|
minLineY -= 2;
|
|
|
|
maxLineX += 2;
|
|
|
|
maxLineY += 2;
|
|
|
|
if (destX >= minLineX && destX <= maxLineX && destY >= minLineY && destY <= maxLineY) {
|
2013-03-14 07:05:09 +00:00
|
|
|
int curY = destY;
|
|
|
|
int linesIdxUp = -1;
|
2013-01-12 10:55:44 +00:00
|
|
|
for (;;) {
|
2013-03-14 07:05:09 +00:00
|
|
|
--curY;
|
|
|
|
if (!checkCollisionLine(destX, curY, &foundDataIdx, &foundLineIdx, startLineIdx, endLineIdx))
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-14 07:05:09 +00:00
|
|
|
linesIdxUp = foundLineIdx;
|
2013-03-15 06:46:30 +00:00
|
|
|
if (!curY || minLineY > curY)
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-14 07:05:09 +00:00
|
|
|
curY = destY;
|
|
|
|
int lineIdxDown = -1;
|
2013-01-12 10:55:44 +00:00
|
|
|
for (;;) {
|
2013-03-14 07:05:09 +00:00
|
|
|
++curY;
|
|
|
|
if (!checkCollisionLine(destX, curY, &foundDataIdx, &foundLineIdx, startLineIdx, endLineIdx))
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-14 07:05:09 +00:00
|
|
|
lineIdxDown = foundLineIdx;
|
2013-03-20 06:27:42 +00:00
|
|
|
if (_vm->_globals->_characterMaxPosY <= curY || maxLineY <= curY)
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-14 07:05:09 +00:00
|
|
|
int curX = destX;
|
|
|
|
int lineIdxRight = -1;
|
2013-01-12 10:55:44 +00:00
|
|
|
for (;;) {
|
2013-03-14 07:05:09 +00:00
|
|
|
++curX;
|
|
|
|
if (!checkCollisionLine(curX, destY, &foundDataIdx, &foundLineIdx, startLineIdx, endLineIdx))
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-14 07:05:09 +00:00
|
|
|
lineIdxRight = foundLineIdx;
|
2013-01-12 10:55:44 +00:00
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
if (_vm->_graphicsManager->_maxX <= curX || maxLineX <= curX)
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-14 07:05:09 +00:00
|
|
|
curX = destX;
|
|
|
|
int lineIdxLeft = -1;
|
2013-01-12 10:55:44 +00:00
|
|
|
for(;;) {
|
2013-03-14 07:05:09 +00:00
|
|
|
--curX;
|
|
|
|
if (!checkCollisionLine(curX, destY, &foundDataIdx, &foundLineIdx, startLineIdx, endLineIdx))
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
2013-03-14 07:05:09 +00:00
|
|
|
lineIdxLeft = foundLineIdx;
|
2013-03-15 06:46:30 +00:00
|
|
|
if (curX <= 0 || minLineX >= curX)
|
2013-03-02 19:19:45 +00:00
|
|
|
break;
|
2013-01-12 10:55:44 +00:00
|
|
|
}
|
2013-03-14 07:05:09 +00:00
|
|
|
if (lineIdxRight != -1 && lineIdxLeft != -1 && linesIdxUp != -1 && lineIdxDown != -1) {
|
2013-02-26 07:21:28 +00:00
|
|
|
route[routerIdx].invalidate();
|
2013-01-11 00:50:29 +00:00
|
|
|
return -1;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-14 07:05:09 +00:00
|
|
|
if (bufX < fromX - 1 || bufX > fromX + 1 || bufY < fromY - 1 || bufY > fromY + 1) {
|
|
|
|
_newPosX = bufX;
|
|
|
|
_newPosY = bufY;
|
2013-03-18 06:59:26 +00:00
|
|
|
if (lineIdx < destLineIdx) {
|
|
|
|
int stepCount = 0;
|
|
|
|
int curLineIdx = lineIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
do {
|
2013-03-18 06:59:26 +00:00
|
|
|
if (curLineIdx == startLineIdx - 1)
|
|
|
|
curLineIdx = endLineIdx;
|
|
|
|
++stepCount;
|
|
|
|
--curLineIdx;
|
|
|
|
if (curLineIdx == startLineIdx - 1)
|
|
|
|
curLineIdx = endLineIdx;
|
|
|
|
} while (destLineIdx != curLineIdx);
|
|
|
|
if (abs(destLineIdx - lineIdx) == stepCount) {
|
2013-02-20 07:30:16 +00:00
|
|
|
if (dataIdx > abs(_lineItem[lineIdx]._lineDataEndIdx / 2)) {
|
2013-03-18 06:59:26 +00:00
|
|
|
result = CONTOURNE(lineIdx, dataIdx, routerIdx, destLineIdx, destDataIdx, route);
|
2012-10-02 11:44:23 +00:00
|
|
|
} else {
|
2013-03-18 06:59:26 +00:00
|
|
|
result = CONTOURNE1(lineIdx, dataIdx, routerIdx, destLineIdx, destDataIdx, route, startLineIdx, endLineIdx);
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-18 06:59:26 +00:00
|
|
|
if (abs(destLineIdx - lineIdx) < stepCount)
|
|
|
|
result = CONTOURNE(lineIdx, dataIdx, result, destLineIdx, destDataIdx, route);
|
|
|
|
if (stepCount < abs(destLineIdx - lineIdx))
|
|
|
|
result = CONTOURNE1(lineIdx, dataIdx, result, destLineIdx, destDataIdx, route, startLineIdx, endLineIdx);
|
|
|
|
}
|
|
|
|
if (lineIdx > destLineIdx) {
|
|
|
|
int destStepCount = abs(lineIdx - destLineIdx);
|
|
|
|
int curLineIdx = lineIdx;
|
|
|
|
int curStepCount = 0;
|
2012-10-02 11:44:23 +00:00
|
|
|
do {
|
2013-03-18 06:59:26 +00:00
|
|
|
if (curLineIdx == endLineIdx + 1)
|
|
|
|
curLineIdx = startLineIdx;
|
|
|
|
++curStepCount;
|
|
|
|
++curLineIdx;
|
|
|
|
if (curLineIdx == endLineIdx + 1)
|
|
|
|
curLineIdx = startLineIdx;
|
|
|
|
} while (destLineIdx != curLineIdx);
|
|
|
|
if (destStepCount == curStepCount) {
|
2013-02-20 07:30:16 +00:00
|
|
|
if (dataIdx > abs(_lineItem[lineIdx]._lineDataEndIdx / 2)) {
|
2013-03-18 06:59:26 +00:00
|
|
|
result = CONTOURNE1(lineIdx, dataIdx, result, destLineIdx, destDataIdx, route, startLineIdx, endLineIdx);
|
2012-10-02 11:44:23 +00:00
|
|
|
} else {
|
2013-03-18 06:59:26 +00:00
|
|
|
result = CONTOURNE(lineIdx, dataIdx, result, destLineIdx, destDataIdx, route);
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-18 06:59:26 +00:00
|
|
|
if (destStepCount < curStepCount)
|
|
|
|
result = CONTOURNE(lineIdx, dataIdx, result, destLineIdx, destDataIdx, route);
|
|
|
|
if (curStepCount < destStepCount)
|
|
|
|
result = CONTOURNE1(lineIdx, dataIdx, result, destLineIdx, destDataIdx, route, startLineIdx, endLineIdx);
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-18 06:59:26 +00:00
|
|
|
if (lineIdx == destLineIdx)
|
|
|
|
result = CONTOURNE(lineIdx, dataIdx, result, lineIdx, destDataIdx, route);
|
2013-01-12 10:55:44 +00:00
|
|
|
for(;;) {
|
2013-02-20 07:30:16 +00:00
|
|
|
if (!checkCollisionLine(_newPosX, _newPosY, &foundDataIdx, &foundLineIdx, _lastLine + 1, _linesNumb))
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
|
|
|
|
2013-02-20 07:30:16 +00:00
|
|
|
switch (_lineItem[foundLineIdx]._direction) {
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_UP:
|
2013-02-20 07:30:16 +00:00
|
|
|
--_newPosY;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_UP_RIGHT:
|
2013-02-20 07:30:16 +00:00
|
|
|
--_newPosY;
|
|
|
|
++_newPosX;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_RIGHT:
|
2013-02-20 07:30:16 +00:00
|
|
|
++_newPosX;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN_RIGHT:
|
2013-02-20 07:30:16 +00:00
|
|
|
++_newPosY;
|
|
|
|
++_newPosX;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN:
|
2013-02-20 07:30:16 +00:00
|
|
|
++_newPosY;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN_LEFT:
|
2013-02-20 07:30:16 +00:00
|
|
|
++_newPosY;
|
|
|
|
--_newPosX;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_LEFT:
|
2013-02-20 07:30:16 +00:00
|
|
|
--_newPosX;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_UP_LEFT:
|
2013-02-20 07:30:16 +00:00
|
|
|
--_newPosY;
|
|
|
|
--_newPosX;
|
2013-01-27 11:04:24 +00:00
|
|
|
break;
|
2013-02-19 04:43:19 +00:00
|
|
|
default:
|
|
|
|
break;
|
2013-01-12 10:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-02 11:44:23 +00:00
|
|
|
} else {
|
2013-02-20 07:30:16 +00:00
|
|
|
_newPosX = -1;
|
|
|
|
_newPosY = -1;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-01-24 07:04:58 +00:00
|
|
|
return result;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2012-10-20 16:59:06 +00:00
|
|
|
// Avoid 2
|
2013-02-16 09:55:07 +00:00
|
|
|
RouteItem *LinesManager::PARCOURS2(int fromX, int fromY, int destX, int destY) {
|
2013-01-27 11:04:24 +00:00
|
|
|
int foundLineIdx;
|
|
|
|
int foundDataIdx;
|
2013-02-22 07:18:13 +00:00
|
|
|
int curLineY = 0;
|
|
|
|
int curLineX = 0;
|
2013-03-11 06:25:45 +00:00
|
|
|
int stepArr[9];
|
2013-03-10 22:53:03 +00:00
|
|
|
int deltaArr[9];
|
2013-02-22 07:18:13 +00:00
|
|
|
int collLineDataIdxArr[9];
|
|
|
|
int collLineIdxArr[9];
|
2012-11-18 00:48:28 +00:00
|
|
|
|
2013-01-24 19:50:48 +00:00
|
|
|
int clipDestX = destX;
|
|
|
|
int clipDestY = destY;
|
2013-02-22 07:18:13 +00:00
|
|
|
int curLineIdx = 0;
|
|
|
|
int curLineDataIdx = 0;
|
|
|
|
int lineIdx = 0;
|
|
|
|
int lineDataIdx = 0;
|
2013-02-18 00:19:41 +00:00
|
|
|
Directions newDir = DIR_NONE;
|
2012-10-22 11:31:46 +00:00
|
|
|
if (destY <= 24)
|
2013-01-12 10:55:44 +00:00
|
|
|
clipDestY = 25;
|
2013-03-20 06:27:42 +00:00
|
|
|
if (!_vm->_globals->_checkDistanceFl) {
|
2013-03-24 22:44:39 +00:00
|
|
|
if (abs(fromX - _oldRouteFromX) <= 4 && abs(fromY - _oldRouteFromY) <= 4 &&
|
|
|
|
abs(_oldRouteDestX - destX) <= 4 && abs(_oldRouteDestY - clipDestY) <= 4)
|
2013-02-16 09:55:07 +00:00
|
|
|
return (RouteItem *)g_PTRNUL;
|
2013-01-12 10:55:44 +00:00
|
|
|
|
2013-01-27 11:04:24 +00:00
|
|
|
if (abs(fromX - destX) <= 4 && abs(fromY - clipDestY) <= 4)
|
2013-02-16 09:55:07 +00:00
|
|
|
return (RouteItem *)g_PTRNUL;
|
2013-01-12 10:55:44 +00:00
|
|
|
|
2013-03-24 22:44:39 +00:00
|
|
|
if (_oldZoneNum > 0 && _vm->_objectsManager->_zoneNum > 0 && _oldZoneNum == _vm->_objectsManager->_zoneNum)
|
2013-02-16 09:55:07 +00:00
|
|
|
return (RouteItem *)g_PTRNUL;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->_checkDistanceFl = false;
|
2013-03-24 22:44:39 +00:00
|
|
|
_oldZoneNum = _vm->_objectsManager->_zoneNum;
|
|
|
|
_oldRouteFromX = fromX;
|
|
|
|
_oldRouteDestX = destX;
|
|
|
|
_oldRouteFromY = fromY;
|
|
|
|
_oldRouteDestY = clipDestY;
|
2013-01-27 14:22:57 +00:00
|
|
|
_pathFindingMaxDepth = 0;
|
2013-02-22 07:18:13 +00:00
|
|
|
int routeIdx = 0;
|
2012-10-22 11:31:46 +00:00
|
|
|
if (destX <= 19)
|
2013-01-12 10:55:44 +00:00
|
|
|
clipDestX = 20;
|
|
|
|
if (clipDestY <= 19)
|
|
|
|
clipDestY = 20;
|
2013-03-20 06:36:06 +00:00
|
|
|
if (clipDestX > _vm->_graphicsManager->_maxX - 10)
|
|
|
|
clipDestX = _vm->_graphicsManager->_maxX - 10;
|
2013-03-20 06:27:42 +00:00
|
|
|
if (clipDestY > _vm->_globals->_characterMaxPosY)
|
|
|
|
clipDestY = _vm->_globals->_characterMaxPosY;
|
2013-01-12 10:55:44 +00:00
|
|
|
|
2013-01-27 11:04:24 +00:00
|
|
|
if (abs(fromX - clipDestX) <= 3 && abs(fromY - clipDestY) <= 3)
|
2013-02-16 09:55:07 +00:00
|
|
|
return (RouteItem *)g_PTRNUL;
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2013-01-24 19:50:48 +00:00
|
|
|
for (int i = 0; i <= 8; ++i) {
|
2013-02-22 07:18:13 +00:00
|
|
|
collLineIdxArr[i] = -1;
|
|
|
|
collLineDataIdxArr[i] = 0;
|
2013-03-11 06:25:45 +00:00
|
|
|
deltaArr[i] = INVALID_LINE_VALUE;
|
|
|
|
stepArr[i] = INVALID_LINE_VALUE;
|
2012-10-17 10:08:19 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 07:23:38 +00:00
|
|
|
if (characterRoute(fromX, fromY, clipDestX, clipDestY, -1, -1, 0) == 1)
|
2013-02-20 07:30:16 +00:00
|
|
|
return _bestRoute;
|
2013-01-24 07:34:35 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
int tmpDelta = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int tmpY = clipDestY; tmpY < _vm->_graphicsManager->_maxY; tmpY++, tmpDelta++) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(clipDestX, tmpY, &collLineDataIdxArr[DIR_DOWN], &collLineIdxArr[DIR_DOWN], 0, _lastLine) && collLineIdxArr[DIR_DOWN] <= _lastLine)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
collLineDataIdxArr[DIR_DOWN] = 0;
|
|
|
|
collLineIdxArr[DIR_DOWN] = -1;
|
2013-01-24 19:50:48 +00:00
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
deltaArr[DIR_DOWN] = tmpDelta;
|
2013-01-24 07:34:35 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
tmpDelta = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int tmpY = clipDestY; tmpY > _vm->_graphicsManager->_minY; tmpY--, tmpDelta++) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(clipDestX, tmpY, &collLineDataIdxArr[DIR_UP], &collLineIdxArr[DIR_UP], 0, _lastLine) && collLineIdxArr[DIR_UP] <= _lastLine)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
collLineDataIdxArr[DIR_UP] = 0;
|
|
|
|
collLineIdxArr[DIR_UP] = -1;
|
|
|
|
if (deltaArr[DIR_DOWN] < tmpDelta && collLineIdxArr[DIR_DOWN] != -1)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
deltaArr[DIR_UP] = tmpDelta;
|
2013-01-24 07:34:35 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
tmpDelta = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int tmpX = clipDestX; tmpX < _vm->_graphicsManager->_maxX; tmpX++) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(tmpX, clipDestY, &collLineDataIdxArr[DIR_RIGHT], &collLineIdxArr[DIR_RIGHT], 0, _lastLine) && collLineIdxArr[DIR_RIGHT] <= _lastLine)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
collLineDataIdxArr[DIR_RIGHT] = 0;
|
|
|
|
collLineIdxArr[DIR_RIGHT] = -1;
|
|
|
|
++tmpDelta;
|
|
|
|
if (deltaArr[DIR_UP] < tmpDelta && collLineIdxArr[DIR_UP] != -1)
|
2013-01-24 07:34:35 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
if (deltaArr[DIR_DOWN] < tmpDelta && collLineIdxArr[DIR_DOWN] != -1)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
deltaArr[DIR_RIGHT] = tmpDelta;
|
2013-01-24 07:34:35 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
tmpDelta = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int tmpX = clipDestX; tmpX > _vm->_graphicsManager->_minX; tmpX--) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(tmpX, clipDestY, &collLineDataIdxArr[DIR_LEFT], &collLineIdxArr[DIR_LEFT], 0, _lastLine) && collLineIdxArr[DIR_LEFT] <= _lastLine)
|
|
|
|
break;
|
|
|
|
collLineDataIdxArr[DIR_LEFT] = 0;
|
|
|
|
collLineIdxArr[DIR_LEFT] = -1;
|
|
|
|
++tmpDelta;
|
|
|
|
if (deltaArr[DIR_UP] < tmpDelta && collLineIdxArr[DIR_UP] != -1)
|
|
|
|
break;
|
|
|
|
if (deltaArr[DIR_DOWN] < tmpDelta && collLineIdxArr[DIR_DOWN] != -1)
|
|
|
|
break;
|
|
|
|
if (deltaArr[DIR_RIGHT] < tmpDelta && collLineIdxArr[DIR_RIGHT] != -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
deltaArr[DIR_LEFT] = tmpDelta;
|
|
|
|
|
|
|
|
if (collLineIdxArr[DIR_UP] < 0 || _lastLine < collLineIdxArr[DIR_UP])
|
|
|
|
collLineIdxArr[DIR_UP] = -1;
|
|
|
|
if (collLineIdxArr[DIR_RIGHT] < 0 || _lastLine < collLineIdxArr[DIR_RIGHT])
|
|
|
|
collLineIdxArr[DIR_RIGHT] = -1;
|
|
|
|
if (collLineIdxArr[DIR_DOWN] < 0 || _lastLine < collLineIdxArr[DIR_DOWN])
|
|
|
|
collLineIdxArr[DIR_DOWN] = -1;
|
|
|
|
if (collLineIdxArr[DIR_LEFT] < 0 || _lastLine < collLineIdxArr[DIR_LEFT])
|
|
|
|
collLineIdxArr[DIR_LEFT] = -1;
|
|
|
|
if (collLineIdxArr[DIR_UP] < 0)
|
2013-03-11 06:25:45 +00:00
|
|
|
deltaArr[DIR_UP] = INVALID_LINE_VALUE;
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_RIGHT] < 0)
|
2013-03-11 06:25:45 +00:00
|
|
|
deltaArr[DIR_RIGHT] = INVALID_LINE_VALUE;
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_DOWN] < 0)
|
2013-03-11 06:25:45 +00:00
|
|
|
deltaArr[DIR_DOWN] = INVALID_LINE_VALUE;
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_LEFT] < 0)
|
2013-03-11 06:25:45 +00:00
|
|
|
deltaArr[DIR_LEFT] = INVALID_LINE_VALUE;
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_UP] == -1 && collLineIdxArr[DIR_RIGHT] == -1 && collLineIdxArr[DIR_DOWN] == -1 && collLineIdxArr[DIR_LEFT] == -1)
|
2013-02-16 09:55:07 +00:00
|
|
|
return (RouteItem *)g_PTRNUL;
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_DOWN] != -1 && deltaArr[DIR_UP] >= deltaArr[DIR_DOWN] && deltaArr[DIR_RIGHT] >= deltaArr[DIR_DOWN] && deltaArr[DIR_LEFT] >= deltaArr[DIR_DOWN]) {
|
|
|
|
curLineIdx = collLineIdxArr[DIR_DOWN];
|
|
|
|
curLineDataIdx = collLineDataIdxArr[DIR_DOWN];
|
|
|
|
} else if (collLineIdxArr[DIR_UP] != -1 && deltaArr[DIR_DOWN] >= deltaArr[DIR_UP] && deltaArr[DIR_RIGHT] >= deltaArr[DIR_UP] && deltaArr[DIR_LEFT] >= deltaArr[DIR_UP]) {
|
|
|
|
curLineIdx = collLineIdxArr[DIR_UP];
|
|
|
|
curLineDataIdx = collLineDataIdxArr[DIR_UP];
|
|
|
|
} else if (collLineIdxArr[DIR_RIGHT] != -1 && deltaArr[DIR_UP] >= deltaArr[DIR_RIGHT] && deltaArr[DIR_DOWN] >= deltaArr[DIR_RIGHT] && deltaArr[DIR_LEFT] >= deltaArr[DIR_RIGHT]) {
|
|
|
|
curLineIdx = collLineIdxArr[DIR_RIGHT];
|
|
|
|
curLineDataIdx = collLineDataIdxArr[DIR_RIGHT];
|
|
|
|
} else if (collLineIdxArr[DIR_LEFT] != -1 && deltaArr[DIR_DOWN] >= deltaArr[DIR_LEFT] && deltaArr[DIR_RIGHT] >= deltaArr[DIR_LEFT] && deltaArr[DIR_UP] >= deltaArr[DIR_LEFT]) {
|
|
|
|
curLineIdx = collLineIdxArr[DIR_LEFT];
|
|
|
|
curLineDataIdx = collLineDataIdxArr[DIR_LEFT];
|
2013-01-24 19:50:48 +00:00
|
|
|
}
|
2012-10-17 10:08:19 +00:00
|
|
|
|
2013-01-24 19:50:48 +00:00
|
|
|
for (int i = 0; i <= 8; ++i) {
|
2013-02-22 07:18:13 +00:00
|
|
|
collLineIdxArr[i] = -1;
|
|
|
|
collLineDataIdxArr[i] = 0;
|
2013-03-11 06:25:45 +00:00
|
|
|
deltaArr[i] = INVALID_LINE_VALUE;
|
|
|
|
stepArr[i] = INVALID_LINE_VALUE;
|
2013-01-24 19:50:48 +00:00
|
|
|
}
|
2013-01-24 07:34:35 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
tmpDelta = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int tmpY = fromY; tmpY < _vm->_graphicsManager->_maxY; tmpY++, tmpDelta++) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(fromX, tmpY, &collLineDataIdxArr[DIR_DOWN], &collLineIdxArr[DIR_DOWN], 0, _lastLine) && collLineIdxArr[DIR_DOWN] <= _lastLine)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
collLineDataIdxArr[DIR_DOWN] = 0;
|
|
|
|
collLineIdxArr[DIR_DOWN] = -1;
|
2013-01-24 19:50:48 +00:00
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
deltaArr[DIR_DOWN] = tmpDelta + 1;
|
2013-01-24 07:34:35 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
tmpDelta = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int tmpY = fromY; tmpY > _vm->_graphicsManager->_minY; tmpY--) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(fromX, tmpY, &collLineDataIdxArr[DIR_UP], &collLineIdxArr[DIR_UP], 0, _lastLine) && collLineIdxArr[DIR_UP] <= _lastLine)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
collLineDataIdxArr[DIR_UP] = 0;
|
|
|
|
collLineIdxArr[DIR_UP] = -1;
|
|
|
|
++tmpDelta;
|
|
|
|
if (collLineIdxArr[DIR_DOWN] != -1 && tmpDelta > 80)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
deltaArr[DIR_UP] = tmpDelta + 1;
|
2013-01-24 07:34:35 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
tmpDelta = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int tmpX = fromX; tmpX < _vm->_graphicsManager->_maxX; tmpX++) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(tmpX, fromY, &collLineDataIdxArr[DIR_RIGHT], &collLineIdxArr[DIR_RIGHT], 0, _lastLine) && collLineIdxArr[DIR_RIGHT] <= _lastLine)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
collLineDataIdxArr[DIR_RIGHT] = 0;
|
|
|
|
collLineIdxArr[DIR_RIGHT] = -1;
|
|
|
|
++tmpDelta;
|
|
|
|
if ((collLineIdxArr[DIR_DOWN] != -1 || collLineIdxArr[DIR_UP] != -1) && (tmpDelta > 100))
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
deltaArr[DIR_RIGHT] = tmpDelta + 1;
|
2013-01-24 19:50:48 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
tmpDelta = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int tmpX = fromX; tmpX > _vm->_graphicsManager->_minX; tmpX--) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(tmpX, fromY, &collLineDataIdxArr[DIR_LEFT], &collLineIdxArr[DIR_LEFT], 0, _lastLine) && collLineIdxArr[DIR_LEFT] <= _lastLine)
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
collLineDataIdxArr[DIR_LEFT] = 0;
|
|
|
|
collLineIdxArr[DIR_LEFT] = -1;
|
|
|
|
++tmpDelta;
|
|
|
|
if ((collLineIdxArr[DIR_DOWN] != -1 || collLineIdxArr[DIR_UP] != -1 || collLineIdxArr[DIR_RIGHT] != -1) && (tmpDelta > 100))
|
2013-01-24 19:50:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
deltaArr[DIR_LEFT] = tmpDelta + 1;
|
2013-01-24 19:50:48 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_UP] != -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
stepArr[DIR_UP] = abs(collLineIdxArr[DIR_UP] - curLineIdx);
|
2013-01-24 19:50:48 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_RIGHT] != -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
stepArr[DIR_RIGHT] = abs(collLineIdxArr[DIR_RIGHT] - curLineIdx);
|
2013-01-24 19:50:48 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_DOWN] != -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
stepArr[DIR_DOWN] = abs(collLineIdxArr[DIR_DOWN] - curLineIdx);
|
2013-01-24 19:50:48 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_LEFT] != -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
stepArr[DIR_LEFT] = abs(collLineIdxArr[DIR_LEFT] - curLineIdx);
|
2013-01-24 19:50:48 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
if (collLineIdxArr[DIR_UP] == -1 && collLineIdxArr[DIR_RIGHT] == -1 && collLineIdxArr[DIR_DOWN] == -1 && collLineIdxArr[DIR_LEFT] == -1)
|
2013-01-24 19:50:48 +00:00
|
|
|
error("Nearest point not found");
|
|
|
|
|
2013-03-11 06:25:45 +00:00
|
|
|
int delta = 0;
|
|
|
|
if (collLineIdxArr[DIR_UP] != -1 && stepArr[DIR_RIGHT] >= stepArr[DIR_UP] && stepArr[DIR_DOWN] >= stepArr[DIR_UP] && stepArr[DIR_LEFT] >= stepArr[DIR_UP]) {
|
2013-03-10 22:53:03 +00:00
|
|
|
lineIdx = collLineIdxArr[DIR_UP];
|
2013-03-11 06:25:45 +00:00
|
|
|
delta = deltaArr[DIR_UP];
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_UP;
|
2013-03-10 22:53:03 +00:00
|
|
|
lineDataIdx = collLineDataIdxArr[DIR_UP];
|
2013-03-11 06:25:45 +00:00
|
|
|
} else if (collLineIdxArr[DIR_DOWN] != -1 && stepArr[DIR_RIGHT] >= stepArr[DIR_DOWN] && stepArr[DIR_UP] >= stepArr[DIR_DOWN] && stepArr[DIR_LEFT] >= stepArr[DIR_DOWN]) {
|
2013-03-10 22:53:03 +00:00
|
|
|
lineIdx = collLineIdxArr[DIR_DOWN];
|
2013-03-11 06:25:45 +00:00
|
|
|
delta = deltaArr[DIR_DOWN];
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_DOWN;
|
2013-03-10 22:53:03 +00:00
|
|
|
lineDataIdx = collLineDataIdxArr[DIR_DOWN];
|
2013-03-11 06:25:45 +00:00
|
|
|
} else if (collLineIdxArr[DIR_RIGHT] != -1 && stepArr[DIR_UP] >= stepArr[DIR_RIGHT] && stepArr[DIR_DOWN] >= stepArr[DIR_RIGHT] && stepArr[DIR_LEFT] >= stepArr[DIR_RIGHT]) {
|
2013-03-10 22:53:03 +00:00
|
|
|
lineIdx = collLineIdxArr[DIR_RIGHT];
|
2013-03-11 06:25:45 +00:00
|
|
|
delta = deltaArr[DIR_RIGHT];
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_RIGHT;
|
2013-03-10 22:53:03 +00:00
|
|
|
lineDataIdx = collLineDataIdxArr[DIR_RIGHT];
|
2013-03-11 06:25:45 +00:00
|
|
|
} else if (collLineIdxArr[DIR_LEFT] != -1 && stepArr[DIR_UP] >= stepArr[DIR_LEFT] && stepArr[DIR_DOWN] >= stepArr[DIR_LEFT] && stepArr[DIR_RIGHT] >= stepArr[DIR_LEFT]) {
|
2013-03-10 22:53:03 +00:00
|
|
|
lineIdx = collLineIdxArr[DIR_LEFT];
|
2013-03-11 06:25:45 +00:00
|
|
|
delta = deltaArr[DIR_LEFT];
|
2013-02-18 00:19:41 +00:00
|
|
|
newDir = DIR_LEFT;
|
2013-03-10 22:53:03 +00:00
|
|
|
lineDataIdx = collLineDataIdxArr[DIR_LEFT];
|
2013-01-24 19:50:48 +00:00
|
|
|
}
|
2013-01-24 07:34:35 +00:00
|
|
|
|
2013-03-11 06:25:45 +00:00
|
|
|
int bestRouteNum = characterRoute(fromX, fromY, clipDestX, clipDestY, lineIdx, curLineIdx, 0);
|
2013-02-06 22:50:59 +00:00
|
|
|
|
2013-03-11 06:25:45 +00:00
|
|
|
if (bestRouteNum == 1)
|
2013-02-20 07:30:16 +00:00
|
|
|
return _bestRoute;
|
2013-02-06 22:50:59 +00:00
|
|
|
|
2013-03-11 06:25:45 +00:00
|
|
|
if (bestRouteNum == 2) {
|
2013-02-22 07:18:13 +00:00
|
|
|
lineIdx = _newLineIdx;
|
|
|
|
lineDataIdx = _newLineDataIdx;
|
|
|
|
routeIdx = _newRouteIdx;
|
2013-02-06 22:50:59 +00:00
|
|
|
} else {
|
2013-03-11 06:25:45 +00:00
|
|
|
switch (newDir) {
|
|
|
|
case DIR_UP:
|
|
|
|
for (int deltaY = 0; deltaY < delta; deltaY++) {
|
2013-02-06 22:50:59 +00:00
|
|
|
if (checkCollisionLine(fromX, fromY - deltaY, &foundDataIdx, &foundLineIdx, _lastLine + 1, _linesNumb) && _lastLine < foundLineIdx) {
|
2013-03-11 06:25:45 +00:00
|
|
|
int tmpRouteIdx = GENIAL(foundLineIdx, foundDataIdx, fromX, fromY - deltaY, fromX, fromY - delta, routeIdx, _bestRoute);
|
2013-02-22 07:18:13 +00:00
|
|
|
if (tmpRouteIdx == -1) {
|
|
|
|
_bestRoute[routeIdx].invalidate();
|
2013-02-20 07:30:16 +00:00
|
|
|
return &_bestRoute[0];
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
routeIdx = tmpRouteIdx;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosY != -1)
|
|
|
|
deltaY = fromY - _newPosY;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
_bestRoute[routeIdx].set(fromX, fromY - deltaY, DIR_UP);
|
|
|
|
routeIdx++;
|
2013-01-26 00:57:06 +00:00
|
|
|
}
|
2013-03-11 06:25:45 +00:00
|
|
|
break;
|
|
|
|
case DIR_DOWN:
|
|
|
|
for (int deltaY = 0; deltaY < delta; deltaY++) {
|
2013-02-06 22:50:59 +00:00
|
|
|
if (checkCollisionLine(fromX, deltaY + fromY, &foundDataIdx, &foundLineIdx, _lastLine + 1, _linesNumb)
|
|
|
|
&& _lastLine < foundLineIdx) {
|
2013-03-11 06:25:45 +00:00
|
|
|
int tmpRouteIdx = GENIAL(foundLineIdx, foundDataIdx, fromX, deltaY + fromY, fromX, delta + fromY, routeIdx, &_bestRoute[0]);
|
2013-02-22 07:18:13 +00:00
|
|
|
if (tmpRouteIdx == -1) {
|
|
|
|
_bestRoute[routeIdx].invalidate();
|
2013-02-20 07:30:16 +00:00
|
|
|
return &_bestRoute[0];
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
routeIdx = tmpRouteIdx;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosY != -1)
|
|
|
|
deltaY = _newPosY - fromY;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
_bestRoute[routeIdx].set(fromX, fromY + deltaY, DIR_DOWN);
|
|
|
|
routeIdx++;
|
2013-01-26 00:57:06 +00:00
|
|
|
}
|
2013-03-11 06:25:45 +00:00
|
|
|
break;
|
|
|
|
case DIR_LEFT:
|
|
|
|
for (int deltaX = 0; deltaX < delta; deltaX++) {
|
2013-02-06 22:50:59 +00:00
|
|
|
if (checkCollisionLine(fromX - deltaX, fromY, &foundDataIdx, &foundLineIdx, _lastLine + 1, _linesNumb) && _lastLine < foundLineIdx) {
|
2013-03-11 06:25:45 +00:00
|
|
|
int tmpRouteIdx = GENIAL(foundLineIdx, foundDataIdx, fromX - deltaX, fromY, fromX - delta, fromY, routeIdx, &_bestRoute[0]);
|
2013-02-22 07:18:13 +00:00
|
|
|
if (tmpRouteIdx == -1) {
|
|
|
|
_bestRoute[routeIdx].invalidate();
|
2013-02-20 07:30:16 +00:00
|
|
|
return &_bestRoute[0];
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
routeIdx = tmpRouteIdx;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosX != -1)
|
|
|
|
deltaX = fromX - _newPosX;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
_bestRoute[routeIdx].set(fromX - deltaX, fromY, DIR_LEFT);
|
|
|
|
routeIdx++;
|
2013-01-26 00:57:06 +00:00
|
|
|
}
|
2013-03-11 06:25:45 +00:00
|
|
|
break;
|
|
|
|
case DIR_RIGHT:
|
|
|
|
for (int deltaX = 0; deltaX < delta; deltaX++) {
|
2013-02-06 22:50:59 +00:00
|
|
|
if (checkCollisionLine(deltaX + fromX, fromY, &foundDataIdx, &foundLineIdx, _lastLine + 1, _linesNumb) && _lastLine < foundLineIdx) {
|
2013-03-11 06:25:45 +00:00
|
|
|
int tmpRouteIdx = GENIAL(foundLineIdx, foundDataIdx, deltaX + fromX, fromY, delta + fromX, fromY, routeIdx, &_bestRoute[0]);
|
2013-02-22 07:18:13 +00:00
|
|
|
if (tmpRouteIdx == -1) {
|
|
|
|
_bestRoute[routeIdx].invalidate();
|
2013-02-20 07:30:16 +00:00
|
|
|
return &_bestRoute[0];
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
routeIdx = tmpRouteIdx;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosX != -1)
|
|
|
|
deltaX = _newPosX - fromX;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
_bestRoute[routeIdx].set(fromX + deltaX, fromY, DIR_RIGHT);
|
|
|
|
routeIdx++;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-03-11 06:25:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-01-24 19:50:48 +00:00
|
|
|
}
|
2013-02-06 22:50:59 +00:00
|
|
|
}
|
2013-02-06 23:23:17 +00:00
|
|
|
|
|
|
|
bool loopCond;
|
|
|
|
do {
|
|
|
|
loopCond = false;
|
2013-02-22 07:18:13 +00:00
|
|
|
if (lineIdx < curLineIdx) {
|
|
|
|
for (int i = lineDataIdx; _lineItem[lineIdx]._lineDataEndIdx > i; ++i) {
|
|
|
|
curLineX = _lineItem[lineIdx]._lineData[2 * i];
|
|
|
|
curLineY = _lineItem[lineIdx]._lineData[2 * i + 1];
|
|
|
|
_bestRoute[routeIdx].set(_lineItem[lineIdx]._lineData[2 * i], _lineItem[lineIdx]._lineData[2 * i + 1], _lineItem[lineIdx]._directionRouteInc);
|
|
|
|
routeIdx++;
|
2013-02-06 23:23:17 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
for (int idx = lineIdx + 1; idx < curLineIdx; idx++) {
|
|
|
|
for (int dataIdx = 0; _lineItem[idx]._lineDataEndIdx > dataIdx; dataIdx++) {
|
|
|
|
curLineX = _lineItem[idx]._lineData[2 * dataIdx];
|
|
|
|
curLineY = _lineItem[idx]._lineData[2 * dataIdx + 1];
|
|
|
|
_bestRoute[routeIdx].set(_lineItem[idx]._lineData[2 * dataIdx], _lineItem[idx]._lineData[2 * dataIdx + 1], _lineItem[idx]._directionRouteInc);
|
|
|
|
routeIdx++;
|
|
|
|
if (_lineItem[idx]._lineDataEndIdx > 30 && dataIdx == _lineItem[idx]._lineDataEndIdx / 2) {
|
2013-03-11 06:25:45 +00:00
|
|
|
bestRouteNum = characterRoute(_lineItem[idx]._lineData[2 * dataIdx], _lineItem[idx]._lineData[2 * dataIdx + 1], clipDestX, clipDestY, idx, curLineIdx, routeIdx);
|
|
|
|
if (bestRouteNum == 1)
|
2013-02-20 07:30:16 +00:00
|
|
|
return &_bestRoute[0];
|
2013-03-11 06:25:45 +00:00
|
|
|
if (bestRouteNum == 2 || MIRACLE(curLineX, curLineY, idx, curLineIdx, routeIdx)) {
|
2013-02-22 07:18:13 +00:00
|
|
|
lineIdx = _newLineIdx;
|
|
|
|
lineDataIdx = _newLineDataIdx;
|
|
|
|
routeIdx = _newRouteIdx;
|
2013-02-06 23:23:17 +00:00
|
|
|
loopCond = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-24 19:50:48 +00:00
|
|
|
}
|
2013-02-06 23:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (loopCond)
|
|
|
|
break;
|
|
|
|
|
2013-03-11 06:25:45 +00:00
|
|
|
bestRouteNum = characterRoute(curLineX, curLineY, clipDestX, clipDestY, idx, curLineIdx, routeIdx);
|
|
|
|
if (bestRouteNum == 1)
|
2013-02-20 07:30:16 +00:00
|
|
|
return &_bestRoute[0];
|
2013-03-11 06:25:45 +00:00
|
|
|
if (bestRouteNum == 2 || MIRACLE(curLineX, curLineY, idx, curLineIdx, routeIdx)) {
|
2013-02-22 07:18:13 +00:00
|
|
|
lineIdx = _newLineIdx;
|
|
|
|
lineDataIdx = _newLineDataIdx;
|
|
|
|
routeIdx = _newRouteIdx;
|
2013-02-06 23:23:17 +00:00
|
|
|
loopCond = true;
|
|
|
|
break;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-02-06 22:50:59 +00:00
|
|
|
}
|
2013-02-06 23:23:17 +00:00
|
|
|
if (loopCond)
|
|
|
|
continue;
|
|
|
|
|
2013-02-22 07:18:13 +00:00
|
|
|
lineDataIdx = 0;
|
|
|
|
lineIdx = curLineIdx;
|
2013-02-06 22:50:59 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
if (lineIdx > curLineIdx) {
|
|
|
|
for (int dataIdx = lineDataIdx; dataIdx > 0; dataIdx--) {
|
|
|
|
curLineX = _lineItem[lineIdx]._lineData[2 * dataIdx];
|
|
|
|
curLineY = _lineItem[lineIdx]._lineData[2 * dataIdx + 1];
|
2013-02-06 23:23:17 +00:00
|
|
|
|
2013-02-22 07:18:13 +00:00
|
|
|
_bestRoute[routeIdx].set(_lineItem[lineIdx]._lineData[2 * dataIdx], _lineItem[lineIdx]._lineData[2 * dataIdx + 1], _lineItem[lineIdx]._directionRouteDec);
|
|
|
|
routeIdx++;
|
2013-02-06 23:23:17 +00:00
|
|
|
}
|
2013-03-11 06:25:45 +00:00
|
|
|
for (int i = lineIdx - 1; i > curLineIdx; i--) {
|
|
|
|
for (int dataIdx = _lineItem[i]._lineDataEndIdx - 1; dataIdx > -1; dataIdx--) {
|
|
|
|
curLineX = _lineItem[i]._lineData[2 * dataIdx];
|
|
|
|
curLineY = _lineItem[i]._lineData[2 * dataIdx + 1];
|
|
|
|
_bestRoute[routeIdx].set(_lineItem[i]._lineData[2 * dataIdx], _lineItem[i]._lineData[2 * dataIdx + 1], _lineItem[i]._directionRouteDec);
|
2013-02-22 07:18:13 +00:00
|
|
|
routeIdx++;
|
2013-03-11 06:25:45 +00:00
|
|
|
if (_lineItem[i]._lineDataEndIdx > 30 && dataIdx == _lineItem[i]._lineDataEndIdx / 2) {
|
|
|
|
bestRouteNum = characterRoute(curLineX, curLineY, clipDestX, clipDestY, i, curLineIdx, routeIdx);
|
|
|
|
if (bestRouteNum == 1)
|
2013-02-20 07:30:16 +00:00
|
|
|
return &_bestRoute[0];
|
2013-03-11 06:25:45 +00:00
|
|
|
if (bestRouteNum == 2 || MIRACLE(curLineX, curLineY, i, curLineIdx, routeIdx)) {
|
2013-02-22 07:18:13 +00:00
|
|
|
lineIdx = _newLineIdx;
|
|
|
|
lineDataIdx = _newLineDataIdx;
|
|
|
|
routeIdx = _newRouteIdx;
|
2013-02-06 23:23:17 +00:00
|
|
|
loopCond = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-18 23:52:48 +00:00
|
|
|
|
|
|
|
if (loopCond)
|
|
|
|
break;
|
|
|
|
|
2013-03-11 06:25:45 +00:00
|
|
|
bestRouteNum = characterRoute(curLineX, curLineY, clipDestX, clipDestY, i, curLineIdx, routeIdx);
|
|
|
|
if (bestRouteNum == 1)
|
2013-02-20 07:30:16 +00:00
|
|
|
return &_bestRoute[0];
|
2013-03-11 06:25:45 +00:00
|
|
|
if (bestRouteNum == 2 || MIRACLE(curLineX, curLineY, i, curLineIdx, routeIdx)) {
|
2013-02-22 07:18:13 +00:00
|
|
|
lineIdx = _newLineIdx;
|
|
|
|
lineDataIdx = _newLineDataIdx;
|
|
|
|
routeIdx = _newRouteIdx;
|
2013-02-18 23:52:48 +00:00
|
|
|
loopCond = true;
|
|
|
|
break;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-06 23:23:17 +00:00
|
|
|
|
|
|
|
if (!loopCond) {
|
2013-02-22 07:18:13 +00:00
|
|
|
lineDataIdx = _lineItem[curLineIdx]._lineDataEndIdx - 1;
|
|
|
|
lineIdx = curLineIdx;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-06 23:23:17 +00:00
|
|
|
} while (loopCond);
|
|
|
|
|
2013-02-22 07:18:13 +00:00
|
|
|
if (lineIdx == curLineIdx) {
|
2013-03-15 06:46:30 +00:00
|
|
|
if (lineDataIdx <= curLineDataIdx)
|
2013-02-22 07:18:13 +00:00
|
|
|
routeIdx = _lineItem[curLineIdx].appendToRouteInc(lineDataIdx, curLineDataIdx, _bestRoute, routeIdx);
|
2013-03-15 06:46:30 +00:00
|
|
|
else
|
2013-02-22 07:18:13 +00:00
|
|
|
routeIdx = _lineItem[curLineIdx].appendToRouteDec(lineDataIdx, curLineDataIdx, _bestRoute, routeIdx);
|
2013-02-06 22:50:59 +00:00
|
|
|
}
|
2013-02-22 07:18:13 +00:00
|
|
|
if (characterRoute(_bestRoute[routeIdx - 1]._x, _bestRoute[routeIdx - 1]._y, clipDestX, clipDestY, -1, -1, routeIdx) != 1) {
|
|
|
|
_bestRoute[routeIdx].invalidate();
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
2013-01-26 00:57:06 +00:00
|
|
|
|
2013-02-20 07:30:16 +00:00
|
|
|
return &_bestRoute[0];
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 07:28:18 +00:00
|
|
|
void LinesManager::_useRoute0(int idx, int curRouteIdx) {
|
2013-03-05 07:26:51 +00:00
|
|
|
if (idx) {
|
|
|
|
int i = 0;
|
|
|
|
do {
|
|
|
|
assert(curRouteIdx <= 8000);
|
|
|
|
_bestRoute[curRouteIdx++] = _testRoute0[i++];
|
|
|
|
} while (_testRoute0[i].isValid());
|
|
|
|
}
|
|
|
|
_bestRoute[curRouteIdx].invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinesManager::useRoute1(int idx, int curRouteIdx) {
|
|
|
|
if (idx) {
|
|
|
|
int i = 0;
|
|
|
|
do {
|
|
|
|
assert(curRouteIdx <= 8000);
|
2013-03-06 07:28:18 +00:00
|
|
|
_bestRoute[curRouteIdx++] = _testRoute1[i++];
|
|
|
|
} while (_testRoute1[i].isValid());
|
2013-03-05 07:26:51 +00:00
|
|
|
}
|
|
|
|
_bestRoute[curRouteIdx].invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinesManager::useRoute2(int idx, int curRouteIdx) {
|
|
|
|
if (idx) {
|
|
|
|
int i = 0;
|
|
|
|
do {
|
|
|
|
assert(curRouteIdx <= 8000);
|
2013-03-06 07:28:18 +00:00
|
|
|
_bestRoute[curRouteIdx++] = _testRoute2[i++];
|
|
|
|
} while (_testRoute2[i].isValid());
|
2013-03-05 07:26:51 +00:00
|
|
|
}
|
|
|
|
_bestRoute[curRouteIdx].invalidate();
|
|
|
|
}
|
|
|
|
|
2013-02-26 22:27:55 +00:00
|
|
|
int LinesManager::characterRoute(int fromX, int fromY, int destX, int destY, int startLineIdx, int endLineIdx, int routeIdx) {
|
2013-03-06 22:47:33 +00:00
|
|
|
int collDataIdxRoute2 = 0;
|
2012-12-30 23:18:08 +00:00
|
|
|
bool colResult = false;
|
2012-10-02 12:41:13 +00:00
|
|
|
|
2013-01-27 11:04:24 +00:00
|
|
|
int curX = fromX;
|
|
|
|
int curY = fromY;
|
2013-02-26 22:27:55 +00:00
|
|
|
int curRouteIdx = routeIdx;
|
2013-03-06 22:47:33 +00:00
|
|
|
bool dummyLineFl = false;
|
2013-02-26 22:27:55 +00:00
|
|
|
if (startLineIdx == -1 && endLineIdx == -1)
|
2013-03-06 22:47:33 +00:00
|
|
|
dummyLineFl = true;
|
2013-01-27 11:04:24 +00:00
|
|
|
int foundDataIdx;
|
2013-02-26 22:27:55 +00:00
|
|
|
int foundLineIdx = startLineIdx;
|
2013-01-27 11:04:24 +00:00
|
|
|
if (checkCollisionLine(fromX, fromY, &foundDataIdx, &foundLineIdx, 0, _linesNumb)) {
|
2013-02-20 07:30:16 +00:00
|
|
|
switch (_lineItem[foundLineIdx]._direction) {
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_UP:
|
2013-01-27 11:04:24 +00:00
|
|
|
curY -= 2;
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_UP_RIGHT:
|
2013-01-27 11:04:24 +00:00
|
|
|
curY -= 2;
|
|
|
|
curX += 2;
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_RIGHT:
|
2013-01-27 11:04:24 +00:00
|
|
|
curX += 2;
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN_RIGHT:
|
2013-01-27 11:04:24 +00:00
|
|
|
curY += 2;
|
|
|
|
curX += 2;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN:
|
2013-01-27 11:04:24 +00:00
|
|
|
curY += 2;
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_DOWN_LEFT:
|
2013-01-27 11:04:24 +00:00
|
|
|
curY += 2;
|
|
|
|
curX -= 2;
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_LEFT:
|
2013-01-27 11:04:24 +00:00
|
|
|
curX -= 2;
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
2013-02-18 00:19:41 +00:00
|
|
|
case DIR_UP_LEFT:
|
2013-01-27 11:04:24 +00:00
|
|
|
curY -= 2;
|
|
|
|
curX -= 2;
|
2013-01-12 10:55:44 +00:00
|
|
|
break;
|
2013-02-19 04:43:19 +00:00
|
|
|
default:
|
|
|
|
break;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-12 22:22:56 +00:00
|
|
|
int oldX = curX;
|
|
|
|
int oldY = curY;
|
2013-03-06 22:47:33 +00:00
|
|
|
int idxRoute0 = 0;
|
|
|
|
int collLineIdxRoute0 = -1;
|
|
|
|
int collLineIdxRoute1 = -1;
|
|
|
|
int collLineIdxRoute2 = -1;
|
2012-10-21 11:25:05 +00:00
|
|
|
|
2013-03-10 10:39:58 +00:00
|
|
|
int distX, distY;
|
2013-02-16 13:35:29 +00:00
|
|
|
int repeatFlag = 0;
|
2013-03-06 22:47:33 +00:00
|
|
|
int collDataIdxRoute0 = 0;
|
|
|
|
int collDataIdxRoute1 = 0;
|
2012-10-21 11:25:05 +00:00
|
|
|
for (;;) {
|
2013-03-06 22:47:33 +00:00
|
|
|
int newX = curX;
|
|
|
|
int newY = curY;
|
2013-01-27 11:04:24 +00:00
|
|
|
if (destX >= curX - 2 && destX <= curX + 2 && destY >= curY - 2 && destY <= curY + 2) {
|
2013-03-05 07:26:51 +00:00
|
|
|
_testRoute0[idxRoute0].invalidate();
|
2013-03-06 07:28:18 +00:00
|
|
|
_useRoute0(idxRoute0, curRouteIdx);
|
2013-03-05 07:26:51 +00:00
|
|
|
return 1;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-06 22:47:33 +00:00
|
|
|
distX = abs(curX - destX) + 1;
|
|
|
|
distY = abs(curY - destY) + 1;
|
|
|
|
int maxDist;
|
|
|
|
if (distX > distY)
|
|
|
|
maxDist = distX;
|
|
|
|
else
|
|
|
|
maxDist = distY;
|
|
|
|
maxDist--;
|
|
|
|
assert(maxDist != 0);
|
2013-03-09 13:45:25 +00:00
|
|
|
int stepX = 1000 * distX / maxDist;
|
|
|
|
int stepY = 1000 * distY / maxDist;
|
2013-01-27 11:04:24 +00:00
|
|
|
if (destX < curX)
|
2013-03-09 13:45:25 +00:00
|
|
|
stepX = -stepX;
|
2013-01-27 11:04:24 +00:00
|
|
|
if (destY < curY)
|
2013-03-09 13:45:25 +00:00
|
|
|
stepY = -stepY;
|
|
|
|
int vertDirection = (int16)stepX / 1000;
|
|
|
|
int horzDirection = (int16)stepY / 1000;
|
2013-03-06 22:47:33 +00:00
|
|
|
Directions newDirection = DIR_NONE;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (horzDirection == -1 && (stepX >= 0 && stepX <= 150))
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (vertDirection == 1 && (stepY >= -1 && stepY <= 150))
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_RIGHT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (horzDirection == 1 && (stepX >= -150 && stepX <= 150))
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_DOWN;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (vertDirection == -1 && (stepY >= -150 && stepY <= 150))
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_LEFT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (horzDirection == -1 && (stepX >= -150 && stepX <= 0))
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP;
|
2013-01-31 06:48:44 +00:00
|
|
|
|
2013-03-06 22:47:33 +00:00
|
|
|
if (newDirection == DIR_NONE && !checkSmoothMove(curX, newY, destX, destY) && !makeSmoothMove(curX, newY, destX, destY)) {
|
2013-02-16 13:35:29 +00:00
|
|
|
newDirection = _smoothMoveDirection;
|
2013-03-10 10:39:58 +00:00
|
|
|
int smoothRouteIdx = 0;
|
|
|
|
for (smoothRouteIdx = 0; _smoothRoute[smoothRouteIdx]._posX != -1 && _smoothRoute[smoothRouteIdx]._posY != -1; ++smoothRouteIdx) {
|
|
|
|
if (checkCollisionLine(_smoothRoute[smoothRouteIdx]._posX, _smoothRoute[smoothRouteIdx]._posY, &collDataIdxRoute0, &collLineIdxRoute0, 0, _linesNumb)) {
|
2013-03-06 22:47:33 +00:00
|
|
|
if (collLineIdxRoute0 > _lastLine)
|
|
|
|
collLineIdxRoute0 = -1;
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-10 10:39:58 +00:00
|
|
|
_testRoute0[idxRoute0].set(_smoothRoute[smoothRouteIdx]._posX, _smoothRoute[smoothRouteIdx]._posY, newDirection);
|
2013-03-05 07:26:51 +00:00
|
|
|
idxRoute0++;
|
2013-02-16 13:35:29 +00:00
|
|
|
|
|
|
|
if (repeatFlag == 1) {
|
|
|
|
repeatFlag = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-10 10:39:58 +00:00
|
|
|
if (repeatFlag != 2 && _smoothRoute[smoothRouteIdx]._posX != -1 && _smoothRoute[smoothRouteIdx]._posY != -1)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
repeatFlag = 1;
|
2013-03-10 10:39:58 +00:00
|
|
|
newX = _smoothRoute[smoothRouteIdx - 1]._posX;
|
|
|
|
newY = _smoothRoute[smoothRouteIdx - 1]._posY;
|
2013-02-16 13:35:29 +00:00
|
|
|
}
|
2013-03-09 13:45:25 +00:00
|
|
|
int newDistX = abs(newX - destX) + 1;
|
|
|
|
int newDistY = abs(newY - destY) + 1;
|
|
|
|
int newMaxDist = newDistY;
|
|
|
|
if (newDistX > newDistY)
|
|
|
|
newMaxDist = newDistX;
|
|
|
|
if (newMaxDist <= 10) {
|
2013-03-05 07:26:51 +00:00
|
|
|
_testRoute0[idxRoute0].invalidate();
|
2013-03-06 07:28:18 +00:00
|
|
|
_useRoute0(idxRoute0, curRouteIdx);
|
2013-03-05 07:26:51 +00:00
|
|
|
return 1;
|
2013-02-16 13:35:29 +00:00
|
|
|
}
|
2013-03-10 10:39:58 +00:00
|
|
|
int newStepX = 1000 * newDistX / (newMaxDist - 1);
|
|
|
|
int newStepY = 1000 * newDistY / (newMaxDist - 1);
|
2013-03-06 22:47:33 +00:00
|
|
|
if (destX < newX)
|
2013-03-09 13:45:25 +00:00
|
|
|
newStepX = -newStepX;
|
2013-03-06 22:47:33 +00:00
|
|
|
if (destY < newY)
|
2013-03-09 13:45:25 +00:00
|
|
|
newStepY = -newStepY;
|
|
|
|
int newVertDirection = newStepX / 1000;
|
|
|
|
int newHorzDirection = newStepY / 1000;
|
2013-03-10 10:39:58 +00:00
|
|
|
int newSmoothX = 1000 * newX;
|
|
|
|
int newSmoothY = 1000 * newY;
|
|
|
|
int curPosX = newSmoothX / 1000;
|
|
|
|
int curPosY = newSmoothY / 1000;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (!(newStepX / 1000) && newHorzDirection == -1)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newVertDirection == 1) {
|
|
|
|
if (newHorzDirection == -1)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP_RIGHT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (!newHorzDirection)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_RIGHT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newHorzDirection == 1)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_DOWN_RIGHT;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-09 13:45:25 +00:00
|
|
|
if (!newVertDirection && newHorzDirection == 1)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_DOWN;
|
2013-03-09 13:45:25 +00:00
|
|
|
if ((newVertDirection != -1) && (newHorzDirection == -1)) {
|
|
|
|
if (newStepX >= 0 && newStepX < 510)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP;
|
2013-03-09 13:45:25 +00:00
|
|
|
else if (newStepX >= 510 && newStepX <= 1000)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP_RIGHT;
|
2013-01-12 13:50:53 +00:00
|
|
|
} else {
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newHorzDirection == 1)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_DOWN_LEFT;
|
2013-03-09 13:45:25 +00:00
|
|
|
else if (!newHorzDirection)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_LEFT;
|
2013-03-09 13:45:25 +00:00
|
|
|
else if (newHorzDirection == -1) {
|
|
|
|
if (newStepX >= 0 && newStepX < 510)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP;
|
2013-03-09 13:45:25 +00:00
|
|
|
else if (newStepX >= 510 && newStepX <= 1000)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP_RIGHT;
|
2013-01-12 13:50:53 +00:00
|
|
|
else
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP_LEFT;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newVertDirection == 1) {
|
|
|
|
if (newStepY >= -1000 && newStepY <= -510)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP_RIGHT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newStepY >= -510 && newStepY <= 510)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_RIGHT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newStepY >= 510 && newStepY <= 1000)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_DOWN_RIGHT;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newHorzDirection == 1) {
|
|
|
|
if (newStepX >= 510 && newStepX <= 1000)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_DOWN_RIGHT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newStepX >= -510 && newStepX <= 510)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_DOWN;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newStepX >= -1000 && newStepX <= -510)
|
2013-02-18 22:52:55 +00:00
|
|
|
newDirection = DIR_DOWN_LEFT;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newVertDirection == -1) {
|
|
|
|
if (newStepY >= 510 && newStepY <= 1000)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_DOWN_LEFT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newStepY >= -510 && newStepY <= 510)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_LEFT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newStepY >= -1000 && newStepY <= -510)
|
2013-02-18 22:52:55 +00:00
|
|
|
newDirection = DIR_UP_LEFT;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newHorzDirection == -1) {
|
|
|
|
if (newStepX >= -1000 && newStepX <= -510)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP_LEFT;
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newStepX >= -510 && newStepX <= 0)
|
2013-02-18 00:19:41 +00:00
|
|
|
newDirection = DIR_UP;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-09 13:45:25 +00:00
|
|
|
if (newMaxDist + 1 <= 0) {
|
2013-03-05 07:26:51 +00:00
|
|
|
_testRoute0[idxRoute0].invalidate();
|
2013-03-06 07:28:18 +00:00
|
|
|
_useRoute0(idxRoute0, curRouteIdx);
|
2013-03-05 07:26:51 +00:00
|
|
|
return 1;
|
2013-02-16 13:35:29 +00:00
|
|
|
}
|
2013-03-10 10:39:58 +00:00
|
|
|
int curDist = 0;
|
2013-03-09 13:45:25 +00:00
|
|
|
while (!checkCollisionLine(curPosX, curPosY, &collDataIdxRoute0, &collLineIdxRoute0, 0, _linesNumb)) {
|
|
|
|
_testRoute0[idxRoute0].set(curPosX, curPosY, newDirection);
|
|
|
|
newSmoothX += newStepX;
|
|
|
|
newSmoothY += newStepY;
|
|
|
|
curPosX = newSmoothX / 1000;
|
|
|
|
curPosY = newSmoothY / 1000;
|
2013-03-05 07:26:51 +00:00
|
|
|
idxRoute0++;
|
2013-03-10 10:39:58 +00:00
|
|
|
++curDist;
|
|
|
|
if (curDist >= newMaxDist + 1) {
|
2013-03-05 07:26:51 +00:00
|
|
|
_testRoute0[idxRoute0].invalidate();
|
2013-03-06 07:28:18 +00:00
|
|
|
_useRoute0(idxRoute0, curRouteIdx);
|
2013-03-05 07:26:51 +00:00
|
|
|
return 1;
|
2013-02-16 13:35:29 +00:00
|
|
|
}
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-06 22:47:33 +00:00
|
|
|
if (_lastLine >= collLineIdxRoute0)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
2013-03-09 13:45:25 +00:00
|
|
|
int tmpRouteIdx = GENIAL(collLineIdxRoute0, collDataIdxRoute0, curPosX, curPosY, destX, destY, idxRoute0, _testRoute0);
|
2013-03-06 23:27:47 +00:00
|
|
|
if (tmpRouteIdx == -1) {
|
2013-03-06 07:28:18 +00:00
|
|
|
_useRoute0(idxRoute0, curRouteIdx);
|
2013-03-05 07:26:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2013-03-06 23:27:47 +00:00
|
|
|
idxRoute0 = tmpRouteIdx;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosX != -1 || _newPosY != -1) {
|
2013-03-06 22:47:33 +00:00
|
|
|
collLineIdxRoute0 = -1;
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-01-27 11:04:24 +00:00
|
|
|
curX = -1;
|
|
|
|
curY = -1;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-01-12 13:50:53 +00:00
|
|
|
|
2013-03-05 07:26:51 +00:00
|
|
|
_testRoute0[idxRoute0].invalidate();
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2013-03-06 22:47:33 +00:00
|
|
|
int idxRoute1 = 0;
|
2013-03-10 10:39:58 +00:00
|
|
|
int posXRoute1 = oldX;
|
|
|
|
int posYRoute1 = oldY;
|
2013-02-16 13:35:29 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
2013-03-06 22:47:33 +00:00
|
|
|
if (destX >= posXRoute1 - 2 && destX <= posXRoute1 + 2 && destY >= posYRoute1 - 2 && destY <= posYRoute1 + 2) {
|
2013-03-06 07:28:18 +00:00
|
|
|
_testRoute1[idxRoute1].invalidate();
|
2013-03-05 07:26:51 +00:00
|
|
|
useRoute1(idxRoute1, curRouteIdx);
|
|
|
|
return 1;
|
2013-02-16 13:35:29 +00:00
|
|
|
}
|
2013-03-06 22:47:33 +00:00
|
|
|
while (posXRoute1 != destX) {
|
|
|
|
if (checkCollisionLine(posXRoute1, posYRoute1, &collDataIdxRoute1, &collLineIdxRoute1, 0, _linesNumb)) {
|
|
|
|
if (collLineIdxRoute1 > _lastLine)
|
|
|
|
collLineIdxRoute1 = -1;
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-02-16 13:35:29 +00:00
|
|
|
|
2013-03-06 22:47:33 +00:00
|
|
|
if (posXRoute1 < destX)
|
|
|
|
_testRoute1[idxRoute1++].set(posXRoute1++, posYRoute1, DIR_RIGHT);
|
2013-02-16 13:35:29 +00:00
|
|
|
else
|
2013-03-06 22:47:33 +00:00
|
|
|
_testRoute1[idxRoute1++].set(posXRoute1--, posYRoute1, DIR_LEFT);
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-06 22:47:33 +00:00
|
|
|
if (posXRoute1 != destX)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-06 22:47:33 +00:00
|
|
|
int curPosY = posYRoute1;
|
2013-03-06 07:28:18 +00:00
|
|
|
while (curPosY != destY) {
|
2013-03-06 22:47:33 +00:00
|
|
|
if (checkCollisionLine(destX, curPosY, &collDataIdxRoute1, &collLineIdxRoute1, 0, _linesNumb)) {
|
|
|
|
if (collLineIdxRoute1 <= _lastLine)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-06 23:27:47 +00:00
|
|
|
int tmpRouteIdx = GENIAL(collLineIdxRoute1, collDataIdxRoute1, destX, curPosY, destX, destY, idxRoute1, _testRoute1);
|
|
|
|
if (tmpRouteIdx == -1) {
|
2013-03-05 07:26:51 +00:00
|
|
|
useRoute1(idxRoute1, curRouteIdx);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-03-06 23:27:47 +00:00
|
|
|
idxRoute1 = tmpRouteIdx;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosX != -1 && _newPosY != -1)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2012-10-19 11:19:50 +00:00
|
|
|
|
2013-03-06 07:28:18 +00:00
|
|
|
if (curPosY < destY)
|
|
|
|
_testRoute1[idxRoute1++].set(destX, curPosY++, DIR_DOWN);
|
2013-02-16 13:35:29 +00:00
|
|
|
else
|
2013-03-06 07:28:18 +00:00
|
|
|
_testRoute1[idxRoute1++].set(destX, curPosY--, DIR_UP);
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-06 07:28:18 +00:00
|
|
|
if (curPosY == destY) {
|
|
|
|
_testRoute1[idxRoute1].invalidate();
|
2013-03-05 07:26:51 +00:00
|
|
|
useRoute1(idxRoute1, curRouteIdx);
|
|
|
|
return 1;
|
2013-02-16 13:35:29 +00:00
|
|
|
}
|
2013-03-06 22:47:33 +00:00
|
|
|
if (collLineIdxRoute1 <= _lastLine)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
2013-03-06 22:47:33 +00:00
|
|
|
posXRoute1 = _newPosX;
|
|
|
|
posYRoute1 = _newPosY;
|
|
|
|
bool colRes = checkCollisionLine(_newPosX, _newPosY, &collDataIdxRoute1, &collLineIdxRoute1, 0, _lastLine);
|
|
|
|
if (colRes && collLineIdxRoute1 <= _lastLine)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-02-16 13:35:29 +00:00
|
|
|
|
2013-03-06 07:28:18 +00:00
|
|
|
_testRoute1[idxRoute1].invalidate();
|
2013-03-05 07:26:51 +00:00
|
|
|
idxRoute1 = 0;
|
2013-03-10 10:39:58 +00:00
|
|
|
int posXRoute2 = oldX;
|
|
|
|
int posYRoute2 = oldY;
|
2013-02-16 13:35:29 +00:00
|
|
|
while (true) {
|
2013-03-06 07:28:18 +00:00
|
|
|
int curPosX;
|
2013-03-06 22:47:33 +00:00
|
|
|
if (destX >= posXRoute2 - 2 && destX <= posXRoute2 + 2 && destY >= posYRoute2 - 2 && destY <= posYRoute2 + 2) {
|
2013-03-06 07:28:18 +00:00
|
|
|
_testRoute2[idxRoute1].invalidate();
|
2013-03-05 07:26:51 +00:00
|
|
|
useRoute2(idxRoute1, curRouteIdx);
|
|
|
|
return 1;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-01-12 13:50:53 +00:00
|
|
|
|
2013-03-10 10:39:58 +00:00
|
|
|
int curPosYRoute2 = posYRoute2;
|
|
|
|
while (curPosYRoute2 != destY) {
|
|
|
|
if (checkCollisionLine(posXRoute2, curPosYRoute2, &collDataIdxRoute2, &collLineIdxRoute2, 0, _linesNumb)) {
|
2013-03-06 22:47:33 +00:00
|
|
|
if (collLineIdxRoute2 > _lastLine)
|
|
|
|
collLineIdxRoute2 = -1;
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-02-16 13:35:29 +00:00
|
|
|
|
2013-03-10 10:39:58 +00:00
|
|
|
if (curPosYRoute2 < destY)
|
|
|
|
_testRoute2[idxRoute1++].set(posXRoute2, curPosYRoute2++, DIR_DOWN);
|
2013-02-16 13:35:29 +00:00
|
|
|
else
|
2013-03-10 10:39:58 +00:00
|
|
|
_testRoute2[idxRoute1++].set(posXRoute2, curPosYRoute2--, DIR_UP);
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-10 10:39:58 +00:00
|
|
|
if (curPosYRoute2 != destY)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-10 10:39:58 +00:00
|
|
|
curPosX = posXRoute2;
|
2013-03-06 07:28:18 +00:00
|
|
|
while (curPosX != destX) {
|
2013-03-06 22:47:33 +00:00
|
|
|
if (checkCollisionLine(curPosX, destY, &collDataIdxRoute2, &collLineIdxRoute2, 0, _linesNumb)) {
|
|
|
|
if (collLineIdxRoute2 <= _lastLine)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-06 22:47:33 +00:00
|
|
|
int tmpRouteIdx = GENIAL(collLineIdxRoute2, collDataIdxRoute2, curPosX, destY, destX, destY, idxRoute1, _testRoute2);
|
2013-03-06 07:28:18 +00:00
|
|
|
if (tmpRouteIdx == -1) {
|
2013-03-05 07:26:51 +00:00
|
|
|
useRoute2(idxRoute1, curRouteIdx);
|
|
|
|
return 1;
|
2013-02-16 13:35:29 +00:00
|
|
|
}
|
2013-03-06 07:28:18 +00:00
|
|
|
idxRoute1 = tmpRouteIdx;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_newPosX != -1 && _newPosY != -1)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-01-26 00:57:06 +00:00
|
|
|
|
2013-03-06 07:28:18 +00:00
|
|
|
if (curPosX < destX)
|
|
|
|
_testRoute2[idxRoute1++].set(curPosX++, destY, DIR_RIGHT);
|
2013-02-16 13:35:29 +00:00
|
|
|
else
|
2013-03-06 07:28:18 +00:00
|
|
|
_testRoute2[idxRoute1++].set(curPosX--, destY, DIR_LEFT);
|
2013-02-16 13:35:29 +00:00
|
|
|
}
|
2013-03-06 07:28:18 +00:00
|
|
|
if (curPosX == destX) {
|
2013-03-06 22:47:33 +00:00
|
|
|
collLineIdxRoute2 = -1;
|
2013-03-06 07:28:18 +00:00
|
|
|
_testRoute2[idxRoute1].invalidate();
|
2013-03-05 07:26:51 +00:00
|
|
|
useRoute2(idxRoute1, curRouteIdx);
|
|
|
|
return 1;
|
2013-01-26 00:57:06 +00:00
|
|
|
}
|
2013-03-06 22:47:33 +00:00
|
|
|
if (collLineIdxRoute2 <= _lastLine)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-06 22:47:33 +00:00
|
|
|
posXRoute2 = _newPosX;
|
|
|
|
posYRoute2 = _newPosY;
|
|
|
|
colResult = checkCollisionLine(_newPosX, _newPosY, &collDataIdxRoute2, &collLineIdxRoute2, 0, _lastLine);
|
|
|
|
if (colResult && collLineIdxRoute2 <= _lastLine)
|
2013-02-16 13:35:29 +00:00
|
|
|
break;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-02-16 13:35:29 +00:00
|
|
|
|
2013-03-06 07:28:18 +00:00
|
|
|
_testRoute2[idxRoute1].invalidate();
|
2013-02-16 13:35:29 +00:00
|
|
|
|
2013-03-06 22:47:33 +00:00
|
|
|
if (!dummyLineFl) {
|
2013-02-26 22:27:55 +00:00
|
|
|
if (endLineIdx > foundLineIdx) {
|
2013-03-06 22:47:33 +00:00
|
|
|
if (_testRoute0[0]._x != -1 && collLineIdxRoute0 > foundLineIdx && collLineIdxRoute1 <= collLineIdxRoute0 && collLineIdxRoute2 <= collLineIdxRoute0 && endLineIdx >= collLineIdxRoute0) {
|
|
|
|
_newLineIdx = collLineIdxRoute0;
|
|
|
|
_newLineDataIdx = collDataIdxRoute0;
|
2013-02-16 13:35:29 +00:00
|
|
|
int i = 0;
|
|
|
|
do {
|
2013-02-26 22:27:55 +00:00
|
|
|
assert(curRouteIdx <= 8000);
|
2013-03-05 07:26:51 +00:00
|
|
|
_bestRoute[curRouteIdx++] = _testRoute0[i++];
|
|
|
|
} while (_testRoute0[i].isValid());
|
2013-02-26 22:27:55 +00:00
|
|
|
_newRouteIdx = curRouteIdx;
|
2013-02-16 13:35:29 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2013-03-06 22:47:33 +00:00
|
|
|
if (_testRoute1[0]._x != -1 && foundLineIdx < collLineIdxRoute1 && collLineIdxRoute2 <= collLineIdxRoute1 && collLineIdxRoute0 <= collLineIdxRoute1 && endLineIdx >= collLineIdxRoute1) {
|
|
|
|
_newLineIdx = collLineIdxRoute1;
|
|
|
|
_newLineDataIdx = collDataIdxRoute1;
|
2013-02-16 13:35:29 +00:00
|
|
|
int i = 0;
|
|
|
|
do {
|
2013-02-26 22:27:55 +00:00
|
|
|
assert(curRouteIdx <= 8000);
|
2013-03-06 07:28:18 +00:00
|
|
|
_bestRoute[curRouteIdx++] = _testRoute1[i++];
|
|
|
|
} while (_testRoute1[i].isValid());
|
2013-02-26 22:27:55 +00:00
|
|
|
_newRouteIdx = curRouteIdx;
|
2013-02-16 13:35:29 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2013-03-06 22:47:33 +00:00
|
|
|
if (_testRoute2[0]._x != -1 && foundLineIdx < collLineIdxRoute2 && collLineIdxRoute1 < collLineIdxRoute2 && collLineIdxRoute0 < collLineIdxRoute2 && endLineIdx >= collLineIdxRoute2) {
|
|
|
|
_newLineIdx = collLineIdxRoute2;
|
|
|
|
_newLineDataIdx = collDataIdxRoute2;
|
2013-02-16 13:35:29 +00:00
|
|
|
int i = 0;
|
|
|
|
do {
|
2013-02-26 22:27:55 +00:00
|
|
|
assert(curRouteIdx <= 8000);
|
2013-03-06 07:28:18 +00:00
|
|
|
_bestRoute[curRouteIdx++] = _testRoute2[i++];
|
|
|
|
} while (_testRoute2[i].isValid());
|
2013-02-26 22:27:55 +00:00
|
|
|
_newRouteIdx = curRouteIdx;
|
2013-02-16 13:35:29 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
2013-02-26 22:27:55 +00:00
|
|
|
if (endLineIdx < foundLineIdx) {
|
2013-03-06 22:47:33 +00:00
|
|
|
if (collLineIdxRoute0 == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
collLineIdxRoute0 = INVALID_LINE_VALUE;
|
2013-03-06 22:47:33 +00:00
|
|
|
if (collLineIdxRoute1 == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
collLineIdxRoute0 = INVALID_LINE_VALUE;
|
2013-03-06 22:47:33 +00:00
|
|
|
if (collLineIdxRoute2 == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
collLineIdxRoute0 = INVALID_LINE_VALUE;
|
2013-03-06 22:47:33 +00:00
|
|
|
if (_testRoute1[0]._x != -1 && collLineIdxRoute1 < foundLineIdx && collLineIdxRoute2 >= collLineIdxRoute1 && collLineIdxRoute0 >= collLineIdxRoute1 && endLineIdx <= collLineIdxRoute1) {
|
|
|
|
_newLineIdx = collLineIdxRoute1;
|
|
|
|
_newLineDataIdx = collDataIdxRoute1;
|
2013-02-16 13:35:29 +00:00
|
|
|
int i = 0;
|
|
|
|
do {
|
2013-02-26 22:27:55 +00:00
|
|
|
assert(curRouteIdx <= 8000);
|
2013-03-06 07:28:18 +00:00
|
|
|
_bestRoute[curRouteIdx++] = _testRoute1[i++];
|
|
|
|
} while (_testRoute1[i].isValid());
|
2013-02-26 22:27:55 +00:00
|
|
|
_newRouteIdx = curRouteIdx;
|
2013-02-16 13:35:29 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2013-03-06 22:47:33 +00:00
|
|
|
if (_testRoute2[0]._x != -1 && foundLineIdx > collLineIdxRoute2 && collLineIdxRoute1 >= collLineIdxRoute2 && collLineIdxRoute0 >= collLineIdxRoute2 && endLineIdx <= collLineIdxRoute2) {
|
|
|
|
_newLineIdx = collLineIdxRoute2;
|
|
|
|
_newLineDataIdx = collDataIdxRoute2;
|
2013-02-16 13:35:29 +00:00
|
|
|
int i = 0;
|
|
|
|
do {
|
2013-02-26 22:27:55 +00:00
|
|
|
assert(curRouteIdx <= 8000);
|
2013-03-06 07:28:18 +00:00
|
|
|
_bestRoute[curRouteIdx++] = _testRoute2[i++];
|
|
|
|
} while (_testRoute2[i].isValid());
|
2013-02-26 22:27:55 +00:00
|
|
|
_newRouteIdx = curRouteIdx;
|
2013-02-16 13:35:29 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2013-03-18 06:59:26 +00:00
|
|
|
// CHECKME: Checking essai0[0]._x might make more sense here?
|
2013-03-06 22:47:33 +00:00
|
|
|
if (_testRoute1[0]._x != -1 && foundLineIdx > collLineIdxRoute0 && collLineIdxRoute1 >= collLineIdxRoute0 && collLineIdxRoute2 >= collLineIdxRoute0 && endLineIdx <= collLineIdxRoute0) {
|
|
|
|
_newLineIdx = collLineIdxRoute0;
|
|
|
|
_newLineDataIdx = collDataIdxRoute0;
|
2013-02-16 13:35:29 +00:00
|
|
|
int i = 0;
|
|
|
|
do {
|
2013-02-26 22:27:55 +00:00
|
|
|
assert(curRouteIdx <= 8000);
|
2013-03-05 07:26:51 +00:00
|
|
|
_bestRoute[curRouteIdx++] = _testRoute0[i++];
|
|
|
|
} while (_testRoute0[i].isValid());
|
2013-02-26 22:27:55 +00:00
|
|
|
_newRouteIdx = curRouteIdx;
|
2013-02-16 13:35:29 +00:00
|
|
|
return 2;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-01-26 00:57:06 +00:00
|
|
|
}
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-02-16 13:35:29 +00:00
|
|
|
return 0;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 09:55:07 +00:00
|
|
|
RouteItem *LinesManager::cityMapCarRoute(int x1, int y1, int x2, int y2) {
|
|
|
|
RouteItem *result;
|
2013-01-27 11:53:00 +00:00
|
|
|
int arrDelta[10];
|
|
|
|
int arrDataIdx[10];
|
|
|
|
int arrLineIdx[10];
|
|
|
|
|
|
|
|
int clipX2 = x2;
|
|
|
|
int clipY2 = y2;
|
|
|
|
if (x2 <= 14)
|
|
|
|
clipX2 = 15;
|
|
|
|
if (y2 <= 14)
|
|
|
|
clipY2 = 15;
|
2013-03-20 06:36:06 +00:00
|
|
|
if (clipX2 > _vm->_graphicsManager->_maxX - 10)
|
|
|
|
clipX2 = _vm->_graphicsManager->_maxX - 10;
|
2013-01-27 11:53:00 +00:00
|
|
|
if (clipY2 > 445)
|
|
|
|
clipY2 = 440;
|
|
|
|
|
|
|
|
int delta = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (delta = 0; clipY2 + delta < _vm->_graphicsManager->_maxY; delta++) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(clipX2, clipY2 + delta, &arrDataIdx[DIR_DOWN], &arrLineIdx[DIR_DOWN], 0, _lastLine) && arrLineIdx[DIR_DOWN] <= _lastLine)
|
2013-01-27 11:53:00 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
arrDataIdx[DIR_DOWN] = 0;
|
|
|
|
arrLineIdx[DIR_DOWN] = -1;
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
arrDelta[DIR_DOWN] = delta;
|
2013-01-27 11:53:00 +00:00
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
for (delta = 0; clipY2 - delta > _vm->_graphicsManager->_minY; delta++) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(clipX2, clipY2 - delta , &arrDataIdx[DIR_UP], &arrLineIdx[DIR_UP], 0, _lastLine) && arrLineIdx[DIR_UP] <= _lastLine)
|
2013-01-27 11:53:00 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
arrDataIdx[DIR_UP] = 0;
|
|
|
|
arrLineIdx[DIR_UP] = -1;
|
|
|
|
if (arrDelta[DIR_DOWN] < delta && arrLineIdx[DIR_DOWN] != -1)
|
2013-01-27 11:53:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
arrDelta[DIR_UP] = delta;
|
2013-01-27 11:53:00 +00:00
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
for (delta = 0; clipX2 + delta < _vm->_graphicsManager->_maxX; delta++) {
|
2013-03-21 06:49:02 +00:00
|
|
|
if (checkCollisionLine(clipX2 + delta, clipY2, &arrDataIdx[DIR_RIGHT], &arrLineIdx[DIR_RIGHT], 0, _lastLine) && arrLineIdx[DIR_RIGHT] <= _lastLine)
|
2013-01-27 11:53:00 +00:00
|
|
|
break;
|
2013-03-21 06:49:02 +00:00
|
|
|
arrDataIdx[DIR_RIGHT] = 0;
|
|
|
|
arrLineIdx[DIR_RIGHT] = -1;
|
2013-03-18 07:19:33 +00:00
|
|
|
if ((arrDelta[DIR_UP] <= delta && arrLineIdx[DIR_UP] != -1) || (arrDelta[DIR_DOWN] <= delta && arrLineIdx[DIR_DOWN] != -1))
|
2013-01-27 11:53:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-21 06:49:02 +00:00
|
|
|
arrDelta[DIR_RIGHT] = delta;
|
2013-01-27 11:53:00 +00:00
|
|
|
|
2013-03-20 06:36:06 +00:00
|
|
|
for (delta = 0; clipX2 - delta > _vm->_graphicsManager->_minX; delta++) {
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(clipX2 - delta, clipY2, &arrDataIdx[DIR_LEFT], &arrLineIdx[DIR_LEFT], 0, _lastLine) && arrLineIdx[DIR_LEFT] <= _lastLine)
|
2013-01-27 11:53:00 +00:00
|
|
|
break;
|
2013-03-10 22:53:03 +00:00
|
|
|
arrDataIdx[DIR_LEFT] = 0;
|
|
|
|
arrLineIdx[DIR_LEFT] = -1;
|
2013-03-21 06:49:02 +00:00
|
|
|
if ((arrDelta[DIR_UP] <= delta && arrLineIdx[DIR_UP] != -1) || (arrDelta[DIR_RIGHT] <= delta && arrLineIdx[DIR_RIGHT] != -1) || (arrDelta[DIR_DOWN] <= delta && arrLineIdx[DIR_DOWN] != -1))
|
2013-01-27 11:53:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-10 22:53:03 +00:00
|
|
|
arrDelta[DIR_LEFT] = delta;
|
2013-01-27 11:53:00 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
if (arrLineIdx[DIR_UP] == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
arrDelta[DIR_UP] = INVALID_LINE_VALUE;
|
2013-03-21 06:49:02 +00:00
|
|
|
if (arrLineIdx[DIR_RIGHT] == -1)
|
|
|
|
arrDelta[DIR_RIGHT] = INVALID_LINE_VALUE;
|
2013-03-10 22:53:03 +00:00
|
|
|
if (arrLineIdx[DIR_DOWN] == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
arrDelta[DIR_DOWN] = INVALID_LINE_VALUE;
|
2013-03-10 22:53:03 +00:00
|
|
|
if (arrLineIdx[DIR_LEFT] == -1)
|
2013-03-11 06:25:45 +00:00
|
|
|
arrDelta[DIR_LEFT] = INVALID_LINE_VALUE;
|
2013-03-21 06:49:02 +00:00
|
|
|
if (arrLineIdx[DIR_UP] != -1 || arrLineIdx[DIR_RIGHT] != -1 || arrLineIdx[DIR_DOWN] != -1 || arrLineIdx[DIR_LEFT] != -1) {
|
2013-03-26 23:51:35 +00:00
|
|
|
int curLineDataIdx = 0;
|
|
|
|
int curLineIdx = 0;
|
2013-03-21 06:49:02 +00:00
|
|
|
if (arrLineIdx[DIR_DOWN] != -1 && arrDelta[DIR_UP] >= arrDelta[DIR_DOWN] && arrDelta[DIR_RIGHT] >= arrDelta[DIR_DOWN] && arrDelta[DIR_LEFT] >= arrDelta[DIR_DOWN]) {
|
2013-03-10 22:53:03 +00:00
|
|
|
curLineIdx = arrLineIdx[DIR_DOWN];
|
|
|
|
curLineDataIdx = arrDataIdx[DIR_DOWN];
|
2013-03-21 06:49:02 +00:00
|
|
|
} else if (arrLineIdx[DIR_UP] != -1 && arrDelta[DIR_DOWN] >= arrDelta[DIR_UP] && arrDelta[DIR_RIGHT] >= arrDelta[DIR_UP] && arrDelta[DIR_LEFT] >= arrDelta[DIR_UP]) {
|
2013-03-10 22:53:03 +00:00
|
|
|
curLineIdx = arrLineIdx[DIR_UP];
|
|
|
|
curLineDataIdx = arrDataIdx[DIR_UP];
|
2013-03-21 06:49:02 +00:00
|
|
|
} else if (arrLineIdx[DIR_RIGHT] != -1 && arrDelta[DIR_UP] >= arrDelta[DIR_RIGHT] && arrDelta[DIR_DOWN] >= arrDelta[DIR_RIGHT] && arrDelta[DIR_LEFT] >= arrDelta[DIR_RIGHT]) {
|
|
|
|
curLineIdx = arrLineIdx[DIR_RIGHT];
|
|
|
|
curLineDataIdx = arrDataIdx[DIR_RIGHT];
|
|
|
|
} else if (arrLineIdx[DIR_LEFT] != -1 && arrDelta[DIR_DOWN] >= arrDelta[DIR_LEFT] && arrDelta[DIR_RIGHT] >= arrDelta[DIR_LEFT] && arrDelta[DIR_UP] >= arrDelta[DIR_LEFT]) {
|
2013-03-10 22:53:03 +00:00
|
|
|
curLineIdx = arrLineIdx[DIR_LEFT];
|
|
|
|
curLineDataIdx = arrDataIdx[DIR_LEFT];
|
2013-03-07 07:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i <= 8; i++) {
|
|
|
|
arrLineIdx[i] = -1;
|
|
|
|
arrDataIdx[i] = 0;
|
2013-03-11 06:25:45 +00:00
|
|
|
arrDelta[i] = INVALID_LINE_VALUE;
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
2013-03-26 23:51:35 +00:00
|
|
|
|
|
|
|
int superRouteIdx = 0;
|
|
|
|
int curRouteDataIdx = 0;
|
|
|
|
int curRouteLineIdx = 0;
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(x1, y1, &arrDataIdx[DIR_UP], &arrLineIdx[DIR_UP], 0, _lastLine)) {
|
2013-03-12 22:22:56 +00:00
|
|
|
curRouteLineIdx = arrLineIdx[DIR_UP];
|
|
|
|
curRouteDataIdx = arrDataIdx[DIR_UP];
|
2013-03-10 22:53:03 +00:00
|
|
|
} else if (checkCollisionLine(x1, y1, &arrDataIdx[DIR_UP], &arrLineIdx[DIR_UP], 0, _linesNumb)) {
|
2013-03-07 07:41:17 +00:00
|
|
|
int curRouteIdx = 0;
|
|
|
|
int curRouteX;
|
2013-01-27 11:53:00 +00:00
|
|
|
for (;;) {
|
2013-03-07 07:41:17 +00:00
|
|
|
curRouteX = _testRoute2[curRouteIdx]._x;
|
|
|
|
int curRouteY = _testRoute2[curRouteIdx]._y;
|
2013-03-21 06:18:38 +00:00
|
|
|
Directions curRouteDir = _testRoute2[curRouteIdx]._dir;
|
2013-03-07 07:41:17 +00:00
|
|
|
curRouteIdx++;
|
2013-01-27 11:53:00 +00:00
|
|
|
|
2013-03-10 22:53:03 +00:00
|
|
|
if (checkCollisionLine(curRouteX, curRouteY, &arrDataIdx[DIR_UP], &arrLineIdx[DIR_UP], 0, _lastLine))
|
2013-01-27 11:53:00 +00:00
|
|
|
break;
|
|
|
|
|
2013-03-21 06:18:38 +00:00
|
|
|
_bestRoute[superRouteIdx].set(curRouteX, curRouteY, curRouteDir);
|
2013-01-27 11:53:00 +00:00
|
|
|
|
2013-03-21 06:18:38 +00:00
|
|
|
_testRoute0[superRouteIdx].set(curRouteX, curRouteY, curRouteDir);
|
2013-02-16 09:55:07 +00:00
|
|
|
superRouteIdx++;
|
2013-03-07 07:41:17 +00:00
|
|
|
if (curRouteX == -1)
|
2013-01-27 11:53:00 +00:00
|
|
|
break;;
|
|
|
|
}
|
2013-03-07 07:41:17 +00:00
|
|
|
if (curRouteX != -1) {
|
2013-03-12 22:22:56 +00:00
|
|
|
curRouteLineIdx = arrLineIdx[DIR_UP];
|
|
|
|
curRouteDataIdx = arrDataIdx[DIR_UP];
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-03-12 22:22:56 +00:00
|
|
|
curRouteLineIdx = 1;
|
|
|
|
curRouteDataIdx = 1;
|
2013-01-27 11:53:00 +00:00
|
|
|
superRouteIdx = 0;
|
|
|
|
}
|
2013-02-07 06:57:16 +00:00
|
|
|
bool loopFl = true;
|
|
|
|
while (loopFl) {
|
|
|
|
loopFl = false;
|
2013-03-12 22:22:56 +00:00
|
|
|
if (curRouteLineIdx < curLineIdx) {
|
|
|
|
superRouteIdx = _lineItem[curRouteLineIdx].appendToRouteInc(curRouteDataIdx, _lineItem[curRouteLineIdx]._lineDataEndIdx - 2, _bestRoute, superRouteIdx);
|
|
|
|
for (int j = curRouteLineIdx + 1; j < curLineIdx; ++j) {
|
2013-03-07 07:41:17 +00:00
|
|
|
if (PLAN_TEST(_lineItem[j]._lineData[0], _lineItem[j]._lineData[1], superRouteIdx, j, curLineIdx)) {
|
2013-03-12 22:22:56 +00:00
|
|
|
curRouteLineIdx = _newLineIdx;
|
|
|
|
curRouteDataIdx = _newLineDataIdx;
|
2013-02-20 07:30:16 +00:00
|
|
|
superRouteIdx = _newRouteIdx;
|
2013-02-07 06:57:16 +00:00
|
|
|
loopFl = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_lineItem[j]._lineDataEndIdx - 2 > 0) {
|
|
|
|
superRouteIdx = _lineItem[j].appendToRouteInc(0, _lineItem[j]._lineDataEndIdx - 2, _bestRoute, superRouteIdx);
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-07 06:57:16 +00:00
|
|
|
if (loopFl)
|
|
|
|
continue;
|
2013-03-12 22:22:56 +00:00
|
|
|
curRouteDataIdx = 0;
|
|
|
|
curRouteLineIdx = curLineIdx;
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
2013-03-12 22:22:56 +00:00
|
|
|
if (curRouteLineIdx > curLineIdx) {
|
|
|
|
superRouteIdx = _lineItem[curRouteLineIdx].appendToRouteDec(curRouteDataIdx, 0, _bestRoute, superRouteIdx);
|
|
|
|
for (int l = curRouteLineIdx - 1; l > curLineIdx; --l) {
|
2013-03-07 07:41:17 +00:00
|
|
|
if (PLAN_TEST(_lineItem[l]._lineData[2 * _lineItem[l]._lineDataEndIdx - 2], _lineItem[l]._lineData[2 * _lineItem[l]._lineDataEndIdx - 1], superRouteIdx, l, curLineIdx)) {
|
2013-03-12 22:22:56 +00:00
|
|
|
curRouteLineIdx = _newLineIdx;
|
|
|
|
curRouteDataIdx = _newLineDataIdx;
|
2013-02-20 07:30:16 +00:00
|
|
|
superRouteIdx = _newRouteIdx;
|
2013-02-07 06:57:16 +00:00
|
|
|
loopFl = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-27 11:53:00 +00:00
|
|
|
|
2013-02-20 07:30:16 +00:00
|
|
|
superRouteIdx = _lineItem[l].appendToRouteDec(_lineItem[l]._lineDataEndIdx - 2, 0, _bestRoute, superRouteIdx);
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
2013-02-07 06:57:16 +00:00
|
|
|
if (loopFl)
|
|
|
|
continue;
|
|
|
|
|
2013-03-12 22:22:56 +00:00
|
|
|
curRouteDataIdx = _lineItem[curLineIdx]._lineDataEndIdx - 1;
|
|
|
|
curRouteLineIdx = curLineIdx;
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
2013-03-12 22:22:56 +00:00
|
|
|
if (curRouteLineIdx == curLineIdx) {
|
|
|
|
if (curRouteDataIdx <= curLineDataIdx) {
|
|
|
|
superRouteIdx = _lineItem[curLineIdx].appendToRouteInc(curRouteDataIdx, curLineDataIdx, _bestRoute, superRouteIdx);
|
2013-02-07 06:57:16 +00:00
|
|
|
} else {
|
2013-03-12 22:22:56 +00:00
|
|
|
superRouteIdx = _lineItem[curLineIdx].appendToRouteDec(curRouteDataIdx, curLineDataIdx, _bestRoute, superRouteIdx);
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-20 07:30:16 +00:00
|
|
|
_bestRoute[superRouteIdx].invalidate();
|
|
|
|
result = &_bestRoute[0];
|
2013-01-27 11:53:00 +00:00
|
|
|
} else {
|
2013-02-16 09:55:07 +00:00
|
|
|
result = (RouteItem *)g_PTRNUL;
|
2013-01-27 11:53:00 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-01-26 13:54:57 +00:00
|
|
|
bool LinesManager::checkSmoothMove(int fromX, int fromY, int destX, int destY) {
|
|
|
|
int distX = abs(fromX - destX) + 1;
|
|
|
|
int distY = abs(fromY - destY) + 1;
|
|
|
|
if (distX > distY)
|
|
|
|
distY = distX;
|
|
|
|
if (distY <= 10)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
int stepX = 1000 * distX / (distY - 1);
|
|
|
|
int stepY = 1000 * distY / (distY - 1);
|
|
|
|
if (destX < fromX)
|
|
|
|
stepX = -stepX;
|
|
|
|
if (destY < fromY)
|
|
|
|
stepY = -stepY;
|
|
|
|
|
|
|
|
int smoothPosX = 1000 * fromX;
|
|
|
|
int smoothPosY = 1000 * fromY;
|
|
|
|
int newPosX = fromX;
|
|
|
|
int newPosY = fromY;
|
|
|
|
|
|
|
|
if (distY + 1 > 0) {
|
|
|
|
int stepCount = 0;
|
2013-03-09 00:08:11 +00:00
|
|
|
int foundLineIdx;
|
|
|
|
int foundDataIdx;
|
2013-01-27 11:53:00 +00:00
|
|
|
while (!checkCollisionLine(newPosX, newPosY, &foundDataIdx, &foundLineIdx, 0, _linesNumb) || foundLineIdx > _lastLine) {
|
2013-01-26 13:54:57 +00:00
|
|
|
smoothPosX += stepX;
|
|
|
|
smoothPosY += stepY;
|
|
|
|
newPosX = smoothPosX / 1000;
|
|
|
|
newPosY = smoothPosY / 1000;
|
|
|
|
++stepCount;
|
|
|
|
if (stepCount >= distY + 1)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-01-26 13:54:57 +00:00
|
|
|
return false;
|
2012-10-02 11:44:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 13:54:57 +00:00
|
|
|
bool LinesManager::makeSmoothMove(int fromX, int fromY, int destX, int destY) {
|
|
|
|
int curX = fromX;
|
|
|
|
int curY = fromY;
|
|
|
|
if (fromX > destX && destY > fromY) {
|
|
|
|
int hopkinsIdx = 36;
|
|
|
|
int smoothIdx = 0;
|
|
|
|
int stepCount = 0;
|
|
|
|
while (curX > destX && destY > curY) {
|
2013-03-20 06:27:42 +00:00
|
|
|
int realSpeedX = _vm->_globals->_hopkinsItem[hopkinsIdx]._speedX;
|
|
|
|
int realSpeedY = _vm->_globals->_hopkinsItem[hopkinsIdx]._speedY;
|
|
|
|
int spriteSize = _vm->_globals->_spriteSize[curY];
|
2013-01-11 23:38:23 +00:00
|
|
|
if (spriteSize < 0) {
|
2013-03-20 06:36:06 +00:00
|
|
|
realSpeedX = _vm->_graphicsManager->zoomOut(realSpeedX, -spriteSize);
|
|
|
|
realSpeedY = _vm->_graphicsManager->zoomOut(realSpeedY, -spriteSize);
|
2013-01-11 23:38:23 +00:00
|
|
|
} else if (spriteSize > 0) {
|
2013-03-20 06:36:06 +00:00
|
|
|
realSpeedX = _vm->_graphicsManager->zoomIn(realSpeedX, spriteSize);
|
|
|
|
realSpeedY = _vm->_graphicsManager->zoomIn(realSpeedY, spriteSize);
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-03-08 06:56:53 +00:00
|
|
|
for (int i = 0; i < realSpeedX; i++) {
|
2013-01-26 13:54:57 +00:00
|
|
|
--curX;
|
|
|
|
_smoothRoute[smoothIdx]._posX = curX;
|
2013-03-08 06:56:53 +00:00
|
|
|
if (curY != curY + realSpeedY)
|
2013-01-26 13:54:57 +00:00
|
|
|
curY++;
|
|
|
|
_smoothRoute[smoothIdx]._posY = curY;
|
2013-01-11 23:38:23 +00:00
|
|
|
smoothIdx++;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-01-11 23:38:23 +00:00
|
|
|
++hopkinsIdx;
|
|
|
|
if (hopkinsIdx == 48)
|
|
|
|
hopkinsIdx = 36;
|
2013-01-26 13:54:57 +00:00
|
|
|
++stepCount;
|
|
|
|
}
|
|
|
|
if (stepCount > 5) {
|
|
|
|
_smoothRoute[smoothIdx]._posX = -1;
|
|
|
|
_smoothRoute[smoothIdx]._posY = -1;
|
2013-02-18 00:19:41 +00:00
|
|
|
_smoothMoveDirection = DIR_DOWN_LEFT;
|
2013-01-26 13:54:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (fromX < destX && destY > fromY) {
|
|
|
|
int hopkinsIdx = 36;
|
|
|
|
int smoothIdx = 0;
|
|
|
|
int stepCount = 0;
|
|
|
|
while (curX < destX && destY > curY) {
|
2013-03-20 06:27:42 +00:00
|
|
|
int realSpeedX = _vm->_globals->_hopkinsItem[hopkinsIdx]._speedX;
|
|
|
|
int realSpeedY = _vm->_globals->_hopkinsItem[hopkinsIdx]._speedY;
|
|
|
|
int spriteSize = _vm->_globals->_spriteSize[curY];
|
2013-01-11 23:38:23 +00:00
|
|
|
if (spriteSize < 0) {
|
2013-03-20 06:36:06 +00:00
|
|
|
realSpeedX = _vm->_graphicsManager->zoomOut(realSpeedX, -spriteSize);
|
|
|
|
realSpeedY = _vm->_graphicsManager->zoomOut(realSpeedY, -spriteSize);
|
2013-01-26 13:54:57 +00:00
|
|
|
} else if (spriteSize > 0) {
|
2013-03-20 06:36:06 +00:00
|
|
|
realSpeedX = _vm->_graphicsManager->zoomIn(realSpeedX, spriteSize);
|
|
|
|
realSpeedY = _vm->_graphicsManager->zoomIn(realSpeedY, spriteSize);
|
2013-01-11 23:38:23 +00:00
|
|
|
}
|
2013-03-08 06:56:53 +00:00
|
|
|
for (int i = 0; i < realSpeedX; i++) {
|
2013-01-26 13:54:57 +00:00
|
|
|
++curX;
|
|
|
|
_smoothRoute[smoothIdx]._posX = curX;
|
2013-03-08 06:56:53 +00:00
|
|
|
if (curY != curY + realSpeedY)
|
2013-01-26 13:54:57 +00:00
|
|
|
curY++;
|
|
|
|
_smoothRoute[smoothIdx]._posY = curY;
|
2013-01-11 23:38:23 +00:00
|
|
|
smoothIdx++;
|
|
|
|
}
|
2013-01-26 13:54:57 +00:00
|
|
|
++hopkinsIdx;
|
|
|
|
if (hopkinsIdx == 48)
|
|
|
|
hopkinsIdx = 36;
|
|
|
|
++stepCount;
|
|
|
|
}
|
|
|
|
if (stepCount > 5) {
|
|
|
|
_smoothRoute[smoothIdx]._posX = -1;
|
|
|
|
_smoothRoute[smoothIdx]._posY = -1;
|
2013-02-18 00:19:41 +00:00
|
|
|
_smoothMoveDirection = DIR_DOWN_RIGHT;
|
2013-01-26 13:54:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (fromX > destX && destY < fromY) {
|
|
|
|
int hopkinsIdx = 12;
|
|
|
|
int smoothIdx = 0;
|
|
|
|
int stepCount = 0;
|
|
|
|
while (curX > destX && destY < curY) {
|
2013-03-20 06:36:06 +00:00
|
|
|
int realSpeedX = _vm->_graphicsManager->zoomOut(_vm->_globals->_hopkinsItem[hopkinsIdx]._speedX, 25);
|
|
|
|
int realSpeedY = _vm->_graphicsManager->zoomOut(_vm->_globals->_hopkinsItem[hopkinsIdx]._speedY, 25);
|
2013-01-26 13:54:57 +00:00
|
|
|
int oldY = curY;
|
2013-03-08 06:56:53 +00:00
|
|
|
for (int i = 0; i < realSpeedX; i++) {
|
2013-01-26 13:54:57 +00:00
|
|
|
--curX;
|
|
|
|
_smoothRoute[smoothIdx]._posX = curX;
|
2013-03-08 06:56:53 +00:00
|
|
|
if ((uint16)curY != (uint16)oldY + realSpeedY)
|
2013-01-26 13:54:57 +00:00
|
|
|
curY--;
|
|
|
|
_smoothRoute[smoothIdx]._posY = curY;
|
2013-01-11 23:38:23 +00:00
|
|
|
smoothIdx++;
|
|
|
|
}
|
2013-01-26 13:54:57 +00:00
|
|
|
++hopkinsIdx;
|
|
|
|
if (hopkinsIdx == 24)
|
|
|
|
hopkinsIdx = 12;
|
|
|
|
++stepCount;
|
|
|
|
}
|
|
|
|
if (stepCount > 5) {
|
|
|
|
_smoothRoute[smoothIdx]._posX = -1;
|
|
|
|
_smoothRoute[smoothIdx]._posY = -1;
|
2013-02-18 00:19:41 +00:00
|
|
|
_smoothMoveDirection = DIR_UP_LEFT;
|
2013-01-26 13:54:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (fromX < destX && destY < fromY) {
|
|
|
|
int hopkinsIdx = 12;
|
|
|
|
int smoothIdx = 0;
|
|
|
|
int stepCount = 0;
|
|
|
|
while (curX < destX && destY < curY) {
|
|
|
|
int oldY = curY;
|
2013-03-20 06:36:06 +00:00
|
|
|
int realSpeedX = _vm->_graphicsManager->zoomOut(_vm->_globals->_hopkinsItem[hopkinsIdx]._speedX, 25);
|
|
|
|
int realSpeedY = _vm->_graphicsManager->zoomOut(_vm->_globals->_hopkinsItem[hopkinsIdx]._speedY, 25);
|
2013-03-12 22:22:56 +00:00
|
|
|
for (int i = 0; i < realSpeedX; i++) {
|
2013-01-26 13:54:57 +00:00
|
|
|
++curX;
|
|
|
|
_smoothRoute[smoothIdx]._posX = curX;
|
2013-03-12 22:22:56 +00:00
|
|
|
if ((uint16)curY != (uint16)oldY + realSpeedY)
|
2013-01-26 13:54:57 +00:00
|
|
|
curY--;
|
|
|
|
_smoothRoute[smoothIdx]._posY = curY;
|
2013-01-11 23:38:23 +00:00
|
|
|
smoothIdx++;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2013-01-26 13:54:57 +00:00
|
|
|
++hopkinsIdx;
|
|
|
|
if (hopkinsIdx == 24)
|
|
|
|
hopkinsIdx = 12;
|
|
|
|
++stepCount;
|
2013-01-11 23:38:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 13:54:57 +00:00
|
|
|
if (stepCount > 5) {
|
|
|
|
_smoothRoute[smoothIdx]._posX = -1;
|
|
|
|
_smoothRoute[smoothIdx]._posY = -1;
|
2013-02-18 00:19:41 +00:00
|
|
|
_smoothMoveDirection = DIR_UP_RIGHT;
|
2013-01-26 13:54:57 +00:00
|
|
|
return false;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-26 13:54:57 +00:00
|
|
|
return true;
|
2012-10-02 12:41:13 +00:00
|
|
|
}
|
2012-10-02 11:44:23 +00:00
|
|
|
|
2013-03-09 00:08:11 +00:00
|
|
|
bool LinesManager::PLAN_TEST(int paramX, int paramY, int superRouteIdx, int paramStartLineIdx, int paramEndLineIdx) {
|
2013-03-08 06:56:53 +00:00
|
|
|
int sideTestUp;
|
|
|
|
int sideTestDown;
|
|
|
|
int sideTestLeft;
|
|
|
|
int sideTestRight;
|
2013-01-11 18:19:49 +00:00
|
|
|
int lineIdxTestUp;
|
|
|
|
int lineIdxTestDown;
|
|
|
|
int lineIdxTestLeft;
|
|
|
|
int lineIdxTestRight;
|
2013-03-09 00:08:11 +00:00
|
|
|
int dataIdxTestUp;
|
|
|
|
int dataIdxTestDown;
|
|
|
|
int dataIdxTestLeft;
|
|
|
|
int dataIdxTestRight;
|
2013-01-11 18:19:49 +00:00
|
|
|
|
2013-03-08 06:56:53 +00:00
|
|
|
int idxTestUp = testLine(paramX, paramY - 2, &sideTestUp, &lineIdxTestUp, &dataIdxTestUp);
|
|
|
|
int idxTestDown = testLine(paramX, paramY + 2, &sideTestDown, &lineIdxTestDown, &dataIdxTestDown);
|
|
|
|
int idxTestLeft = testLine(paramX - 2, paramY, &sideTestLeft, &lineIdxTestLeft, &dataIdxTestLeft);
|
|
|
|
int idxTestRight = testLine(paramX + 2, paramY, &sideTestRight, &lineIdxTestRight, &dataIdxTestRight);
|
2013-01-11 18:19:49 +00:00
|
|
|
if (idxTestUp == -1 && idxTestDown == -1 && idxTestLeft == -1 && idxTestRight == -1)
|
2013-01-11 00:50:29 +00:00
|
|
|
return false;
|
2013-01-11 18:19:49 +00:00
|
|
|
|
2013-03-09 00:08:11 +00:00
|
|
|
// Direction: 1 = Up, 2 = Down, 3 = Left, 4 = Right
|
|
|
|
int direction;
|
|
|
|
if (paramStartLineIdx == -1 || paramEndLineIdx == -1) {
|
2013-01-11 18:19:49 +00:00
|
|
|
if (idxTestUp != -1)
|
2013-03-09 00:08:11 +00:00
|
|
|
direction = 1;
|
2013-01-11 18:19:49 +00:00
|
|
|
else if (idxTestDown != -1)
|
2013-03-09 00:08:11 +00:00
|
|
|
direction = 2;
|
2013-01-11 18:19:49 +00:00
|
|
|
else if (idxTestLeft != -1)
|
2013-03-09 00:08:11 +00:00
|
|
|
direction = 3;
|
2013-01-11 18:19:49 +00:00
|
|
|
else if (idxTestRight != -1)
|
2013-03-09 00:08:11 +00:00
|
|
|
direction = 4;
|
2013-01-11 18:19:49 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
} else {
|
2013-03-09 00:08:11 +00:00
|
|
|
int stepCountUp = 100;
|
|
|
|
int stepCountDown = 100;
|
|
|
|
int stepCountLeft = 100;
|
|
|
|
int stepCountRight = 100;
|
|
|
|
int paramStepCount = abs(paramStartLineIdx - paramEndLineIdx);
|
2013-01-11 18:19:49 +00:00
|
|
|
if (idxTestUp != -1) {
|
2013-03-09 00:08:11 +00:00
|
|
|
stepCountUp = abs(lineIdxTestUp - paramEndLineIdx);
|
2013-01-11 18:19:49 +00:00
|
|
|
}
|
|
|
|
if (idxTestDown != -1) {
|
2013-03-09 00:08:11 +00:00
|
|
|
stepCountDown = abs(lineIdxTestDown - paramEndLineIdx);
|
2013-01-11 18:19:49 +00:00
|
|
|
}
|
|
|
|
if (idxTestLeft != -1) {
|
2013-03-09 00:08:11 +00:00
|
|
|
stepCountLeft = abs(lineIdxTestLeft - paramEndLineIdx);
|
2013-01-11 18:19:49 +00:00
|
|
|
}
|
|
|
|
if (idxTestRight != -1) {
|
2013-03-09 00:08:11 +00:00
|
|
|
stepCountRight = abs(lineIdxTestRight - paramEndLineIdx);
|
2013-01-11 18:19:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 00:08:11 +00:00
|
|
|
if (stepCountUp < paramStepCount && stepCountUp <= stepCountDown && stepCountUp <= stepCountLeft && stepCountUp <= stepCountRight)
|
|
|
|
direction = 1;
|
|
|
|
else if (paramStepCount > stepCountDown && stepCountUp >= stepCountDown && stepCountLeft >= stepCountDown && stepCountRight >= stepCountDown)
|
|
|
|
direction = 2;
|
|
|
|
else if (stepCountLeft < paramStepCount && stepCountLeft <= stepCountUp && stepCountLeft <= stepCountDown && stepCountLeft <= stepCountRight)
|
|
|
|
direction = 3;
|
|
|
|
else if (stepCountRight < paramStepCount && stepCountRight <= stepCountUp && stepCountRight <= stepCountDown && stepCountRight <= stepCountLeft)
|
|
|
|
direction = 4;
|
2013-01-11 18:19:49 +00:00
|
|
|
else
|
|
|
|
return false;
|
2012-10-04 12:44:29 +00:00
|
|
|
}
|
2013-01-11 18:19:49 +00:00
|
|
|
|
2013-03-08 06:56:53 +00:00
|
|
|
int sideTest = 0;
|
2013-01-11 18:19:49 +00:00
|
|
|
int idxTest = 0;
|
2013-03-09 00:08:11 +00:00
|
|
|
if (direction == 1) {
|
2013-01-11 18:19:49 +00:00
|
|
|
idxTest = idxTestUp;
|
2013-03-08 06:56:53 +00:00
|
|
|
sideTest = sideTestUp;
|
2013-02-20 07:30:16 +00:00
|
|
|
_newLineIdx = lineIdxTestUp;
|
|
|
|
_newLineDataIdx = dataIdxTestUp;
|
2013-03-09 00:08:11 +00:00
|
|
|
} else if (direction == 2) {
|
2013-01-11 18:19:49 +00:00
|
|
|
idxTest = idxTestDown;
|
2013-03-08 06:56:53 +00:00
|
|
|
sideTest = sideTestDown;
|
2013-02-20 07:30:16 +00:00
|
|
|
_newLineIdx = lineIdxTestDown;
|
|
|
|
_newLineDataIdx = dataIdxTestDown;
|
2013-03-09 00:08:11 +00:00
|
|
|
} else if (direction == 3) {
|
2013-01-11 18:19:49 +00:00
|
|
|
idxTest = idxTestLeft;
|
2013-03-08 06:56:53 +00:00
|
|
|
sideTest = sideTestLeft;
|
2013-02-20 07:30:16 +00:00
|
|
|
_newLineIdx = lineIdxTestLeft;
|
|
|
|
_newLineDataIdx = dataIdxTestLeft;
|
2013-03-09 00:08:11 +00:00
|
|
|
} else if (direction == 4) {
|
2013-01-11 18:19:49 +00:00
|
|
|
idxTest = idxTestRight;
|
2013-03-08 06:56:53 +00:00
|
|
|
sideTest = sideTestRight;
|
2013-02-20 07:30:16 +00:00
|
|
|
_newLineIdx = lineIdxTestRight;
|
|
|
|
_newLineDataIdx = dataIdxTestRight;
|
2012-10-04 12:44:29 +00:00
|
|
|
}
|
2013-01-11 18:19:49 +00:00
|
|
|
|
2013-02-26 22:27:55 +00:00
|
|
|
int routeIdx = superRouteIdx;
|
2013-03-08 06:56:53 +00:00
|
|
|
if (sideTest == 1) {
|
2013-02-26 22:27:55 +00:00
|
|
|
routeIdx = _lineItem[idxTest].appendToRouteInc(0, -1, _bestRoute, routeIdx);
|
2013-03-08 06:56:53 +00:00
|
|
|
} else if (sideTest == 2) {
|
2013-02-26 22:27:55 +00:00
|
|
|
routeIdx = _lineItem[idxTest].appendToRouteDec(-1, -1, _bestRoute, routeIdx);
|
2012-10-04 12:44:29 +00:00
|
|
|
}
|
2013-02-26 22:27:55 +00:00
|
|
|
_newRouteIdx = routeIdx;
|
2013-01-11 00:50:29 +00:00
|
|
|
return true;
|
2012-10-04 12:44:29 +00:00
|
|
|
}
|
|
|
|
|
2012-10-20 16:59:06 +00:00
|
|
|
// Test line
|
2013-02-21 07:23:38 +00:00
|
|
|
int LinesManager::testLine(int paramX, int paramY, int *a3, int *foundLineIdx, int *foundDataIdx) {
|
2013-01-11 07:16:47 +00:00
|
|
|
int16 *lineData;
|
|
|
|
int lineDataEndIdx;
|
|
|
|
int collLineIdx;
|
|
|
|
int collDataIdx;
|
|
|
|
|
2013-01-27 11:53:00 +00:00
|
|
|
for (int idx = _lastLine + 1; idx < _linesNumb + 1; idx++) {
|
2013-02-20 07:30:16 +00:00
|
|
|
lineData = _lineItem[idx]._lineData;
|
|
|
|
lineDataEndIdx = _lineItem[idx]._lineDataEndIdx;
|
2013-01-11 18:19:49 +00:00
|
|
|
if (lineData[0] == paramX && lineData[1] == paramY) {
|
2012-10-04 12:44:29 +00:00
|
|
|
*a3 = 1;
|
2013-01-11 07:16:47 +00:00
|
|
|
int posX = lineData[2 * (lineDataEndIdx - 1)];
|
|
|
|
int posY = lineData[2 * (lineDataEndIdx - 1) + 1];
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_lineItem[idx]._directionRouteInc == DIR_DOWN || _lineItem[idx]._directionRouteInc == DIR_UP)
|
2013-01-11 07:16:47 +00:00
|
|
|
posY += 2;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_lineItem[idx]._directionRouteInc == DIR_RIGHT || _lineItem[idx]._directionRouteDec == DIR_LEFT)
|
2013-01-11 07:16:47 +00:00
|
|
|
posX += 2;
|
2013-01-27 11:53:00 +00:00
|
|
|
if (!checkCollisionLine(posX, posY, &collDataIdx, &collLineIdx, 0, _lastLine))
|
2013-01-11 07:16:47 +00:00
|
|
|
error("Error in test line");
|
|
|
|
*foundLineIdx = collLineIdx;
|
|
|
|
*foundDataIdx = collDataIdx;
|
|
|
|
return idx;
|
|
|
|
}
|
2013-01-11 18:19:49 +00:00
|
|
|
if (lineData[2 * (lineDataEndIdx - 1)] == paramX && lineData[2 * (lineDataEndIdx - 1) + 1] == paramY) {
|
2012-10-04 12:44:29 +00:00
|
|
|
*a3 = 2;
|
2013-01-11 07:16:47 +00:00
|
|
|
int posX = lineData[0];
|
|
|
|
int posY = lineData[1];
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_lineItem[idx]._directionRouteInc == DIR_DOWN || _lineItem[idx]._directionRouteInc == DIR_UP)
|
2013-01-11 07:16:47 +00:00
|
|
|
posY -= 2;
|
2013-02-20 07:30:16 +00:00
|
|
|
if (_lineItem[idx]._directionRouteInc == DIR_RIGHT || _lineItem[idx]._directionRouteDec == DIR_LEFT)
|
2013-01-11 07:16:47 +00:00
|
|
|
posX -= 2;
|
2013-01-27 11:53:00 +00:00
|
|
|
if (!checkCollisionLine(posX, posY, &collDataIdx, &collLineIdx, 0, _lastLine))
|
2013-01-11 07:16:47 +00:00
|
|
|
error("Error in test line");
|
|
|
|
*foundLineIdx = collLineIdx;
|
|
|
|
*foundDataIdx = collDataIdx;
|
|
|
|
return idx;
|
2012-10-04 12:44:29 +00:00
|
|
|
}
|
2013-01-11 07:16:47 +00:00
|
|
|
}
|
|
|
|
return -1;
|
2012-10-04 12:44:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 19:20:36 +00:00
|
|
|
int LinesManager::CALC_PROPRE(int idx) {
|
2013-03-20 06:27:42 +00:00
|
|
|
int size = _vm->_globals->_spriteSize[idx];
|
|
|
|
if (_vm->_globals->_characterType == 1) {
|
2013-01-27 19:20:36 +00:00
|
|
|
if (size < 0)
|
|
|
|
size = -size;
|
|
|
|
size = 20 * (5 * size - 100) / -80;
|
2013-03-20 06:27:42 +00:00
|
|
|
} else if (_vm->_globals->_characterType == 2) {
|
2013-01-27 19:20:36 +00:00
|
|
|
if (size < 0)
|
|
|
|
size = -size;
|
|
|
|
size = 20 * (5 * size - 165) / -67;
|
|
|
|
}
|
|
|
|
|
2013-02-19 20:12:57 +00:00
|
|
|
int retVal = 25;
|
2013-01-27 19:20:36 +00:00
|
|
|
if (size < 0)
|
2013-03-20 06:36:06 +00:00
|
|
|
retVal = _vm->_graphicsManager->zoomOut(25, -size);
|
2013-01-27 19:20:36 +00:00
|
|
|
else if (size > 0)
|
2013-03-20 06:36:06 +00:00
|
|
|
retVal = _vm->_graphicsManager->zoomIn(25, size);
|
2013-01-27 19:20:36 +00:00
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2013-02-16 09:55:07 +00:00
|
|
|
void LinesManager::PACOURS_PROPRE(RouteItem *route) {
|
2013-02-19 17:06:05 +00:00
|
|
|
int routeIdx = 0;
|
|
|
|
Directions oldDir = DIR_NONE;
|
|
|
|
int route0Y = route[0]._y;
|
|
|
|
Directions curDir = route[0]._dir;
|
|
|
|
if (route[0]._x == -1 && route0Y == -1)
|
2013-01-27 19:20:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (;;) {
|
2013-02-19 17:06:05 +00:00
|
|
|
if (oldDir != DIR_NONE && curDir != oldDir) {
|
|
|
|
int oldRouteIdx = routeIdx;
|
|
|
|
int routeCount = 0;
|
2013-03-18 06:59:26 +00:00
|
|
|
int routeNum = CALC_PROPRE(route0Y);
|
2013-02-19 17:06:05 +00:00
|
|
|
int curRouteX = route[routeIdx]._x;
|
|
|
|
int curRouteY = route[routeIdx]._y;
|
|
|
|
while (curRouteX != -1 || curRouteY != -1) {
|
|
|
|
int idx = routeIdx;
|
|
|
|
++routeIdx;
|
|
|
|
++routeCount;
|
|
|
|
if (route[idx]._dir != curDir)
|
2013-01-27 19:20:36 +00:00
|
|
|
break;
|
2013-02-19 17:06:05 +00:00
|
|
|
curRouteX = route[routeIdx]._x;
|
|
|
|
curRouteY = route[routeIdx]._y;
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
2013-03-18 06:59:26 +00:00
|
|
|
if (routeCount < routeNum) {
|
2013-02-19 17:06:05 +00:00
|
|
|
int idx = oldRouteIdx;
|
|
|
|
for (int i = 0; i < routeCount; i++) {
|
|
|
|
route[idx]._dir = oldDir;
|
|
|
|
idx++;
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
2013-02-19 17:06:05 +00:00
|
|
|
curDir = oldDir;
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
2013-02-19 17:06:05 +00:00
|
|
|
routeIdx = oldRouteIdx;
|
|
|
|
if (curRouteX == -1 && curRouteY == -1)
|
2013-01-27 19:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-02-19 17:06:05 +00:00
|
|
|
routeIdx++;
|
|
|
|
oldDir = curDir;
|
|
|
|
route0Y = route[routeIdx]._y;
|
|
|
|
curDir = route[routeIdx]._dir;
|
|
|
|
if (route[routeIdx]._x == -1 && route0Y == -1)
|
2013-01-27 19:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 07:18:13 +00:00
|
|
|
int LinesManager::getMouseZone() {
|
2013-01-27 19:20:36 +00:00
|
|
|
int result;
|
|
|
|
|
2013-03-19 19:40:55 +00:00
|
|
|
int xp = _vm->_eventsManager->_mousePos.x + _vm->_eventsManager->_mouseOffset.x;
|
|
|
|
int yp = _vm->_eventsManager->_mousePos.y + _vm->_eventsManager->_mouseOffset.y;
|
|
|
|
if ((_vm->_eventsManager->_mousePos.y + _vm->_eventsManager->_mouseOffset.y) > 19) {
|
2013-01-27 19:20:36 +00:00
|
|
|
for (int bobZoneId = 0; bobZoneId <= 48; bobZoneId++) {
|
2013-02-12 22:48:03 +00:00
|
|
|
int bobId = BOBZONE[bobZoneId];
|
2013-03-20 06:56:16 +00:00
|
|
|
if (bobId && BOBZONE_FLAG[bobZoneId] && _vm->_objectsManager->_bob[bobId]._bobMode && _vm->_objectsManager->_bob[bobId]._frameIndex != 250 &&
|
|
|
|
!_vm->_objectsManager->_bob[bobId]._disabledAnimationFl && xp > _vm->_objectsManager->_bob[bobId]._oldX &&
|
|
|
|
xp < _vm->_objectsManager->_bob[bobId]._oldWidth + _vm->_objectsManager->_bob[bobId]._oldX && yp > _vm->_objectsManager->_bob[bobId]._oldY) {
|
|
|
|
if (yp < _vm->_objectsManager->_bob[bobId]._oldHeight + _vm->_objectsManager->_bob[bobId]._oldY) {
|
2013-02-12 22:48:03 +00:00
|
|
|
if (ZONEP[bobZoneId]._spriteIndex == -1) {
|
|
|
|
ZONEP[bobZoneId]._destX = 0;
|
|
|
|
ZONEP[bobZoneId]._destY = 0;
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
2013-02-12 22:48:03 +00:00
|
|
|
if (!ZONEP[bobZoneId]._destX && !ZONEP[bobZoneId]._destY) {
|
2013-03-20 06:56:16 +00:00
|
|
|
ZONEP[bobZoneId]._destX = _vm->_objectsManager->_bob[bobId]._oldWidth + _vm->_objectsManager->_bob[bobId]._oldX;
|
|
|
|
ZONEP[bobZoneId]._destY = _vm->_objectsManager->_bob[bobId]._oldHeight + _vm->_objectsManager->_bob[bobId]._oldY + 6;
|
2013-02-12 22:48:03 +00:00
|
|
|
ZONEP[bobZoneId]._spriteIndex = -1;
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
|
|
|
return bobZoneId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-27 21:28:10 +00:00
|
|
|
_currentSegmentId = 0;
|
2013-01-27 19:20:36 +00:00
|
|
|
for (int squareZoneId = 0; squareZoneId <= 99; squareZoneId++) {
|
2013-02-21 07:23:38 +00:00
|
|
|
if (ZONEP[squareZoneId]._enabledFl && _squareZone[squareZoneId]._enabledFl
|
2013-01-27 22:30:40 +00:00
|
|
|
&& _squareZone[squareZoneId]._left <= xp && _squareZone[squareZoneId]._right >= xp
|
|
|
|
&& _squareZone[squareZoneId]._top <= yp && _squareZone[squareZoneId]._bottom >= yp) {
|
2013-01-29 07:35:14 +00:00
|
|
|
if (_squareZone[squareZoneId]._squareZoneFl)
|
|
|
|
return _zoneLine[_squareZone[squareZoneId]._minZoneLineIdx]._bobZoneIdx;
|
|
|
|
|
2013-01-27 22:30:40 +00:00
|
|
|
_segment[_currentSegmentId]._minZoneLineIdx = _squareZone[squareZoneId]._minZoneLineIdx;
|
|
|
|
_segment[_currentSegmentId]._maxZoneLineIdx = _squareZone[squareZoneId]._maxZoneLineIdx;
|
2013-01-27 21:28:10 +00:00
|
|
|
++_currentSegmentId;
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-29 07:35:14 +00:00
|
|
|
if (!_currentSegmentId)
|
2013-01-27 19:20:36 +00:00
|
|
|
return -1;
|
2013-01-29 07:35:14 +00:00
|
|
|
|
2013-01-27 19:20:36 +00:00
|
|
|
|
|
|
|
int colRes1 = 0;
|
|
|
|
for (int yCurrent = yp; yCurrent >= 0; --yCurrent) {
|
2013-02-21 07:23:38 +00:00
|
|
|
colRes1 = checkCollision(xp, yCurrent);
|
2013-02-12 22:48:03 +00:00
|
|
|
if (colRes1 != -1 && ZONEP[colRes1]._enabledFl)
|
2013-01-27 19:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-29 07:35:14 +00:00
|
|
|
if (colRes1 == -1)
|
2013-01-27 19:20:36 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
int colRes2 = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int j = yp; j < _vm->_graphicsManager->_maxY; ++j) {
|
2013-02-21 07:23:38 +00:00
|
|
|
colRes2 = checkCollision(xp, j);
|
2013-02-12 22:48:03 +00:00
|
|
|
if (colRes2 != -1 && ZONEP[colRes1]._enabledFl)
|
2013-01-27 19:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-29 07:35:14 +00:00
|
|
|
if (colRes2 == -1)
|
2013-01-27 19:20:36 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
int colRes3 = 0;
|
|
|
|
for (int k = xp; k >= 0; --k) {
|
2013-02-21 07:23:38 +00:00
|
|
|
colRes3 = checkCollision(k, yp);
|
2013-02-12 22:48:03 +00:00
|
|
|
if (colRes3 != -1 && ZONEP[colRes1]._enabledFl)
|
2013-01-27 19:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-01-29 07:35:14 +00:00
|
|
|
if (colRes3 == -1)
|
2013-01-27 19:20:36 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
int colRes4 = 0;
|
2013-03-20 06:36:06 +00:00
|
|
|
for (int xCurrent = xp; _vm->_graphicsManager->_maxX > xCurrent; ++xCurrent) {
|
2013-02-21 07:23:38 +00:00
|
|
|
colRes4 = checkCollision(xCurrent, yp);
|
2013-02-12 22:48:03 +00:00
|
|
|
if (colRes4 != -1 && ZONEP[colRes1]._enabledFl)
|
2013-01-27 19:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-01-29 07:35:14 +00:00
|
|
|
if (colRes1 == colRes2 && colRes1 == colRes3 && colRes1 == colRes4)
|
2013-01-27 19:20:36 +00:00
|
|
|
result = colRes1;
|
2013-01-29 07:35:14 +00:00
|
|
|
else
|
2013-01-27 19:20:36 +00:00
|
|
|
result = -1;
|
2013-01-29 07:35:14 +00:00
|
|
|
|
2013-01-27 19:20:36 +00:00
|
|
|
} else {
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-02-21 07:23:38 +00:00
|
|
|
int LinesManager::checkCollision(int xp, int yp) {
|
2013-01-27 21:28:10 +00:00
|
|
|
if (_currentSegmentId <= 0)
|
2013-01-27 19:20:36 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
int xMax = xp + 4;
|
|
|
|
int xMin = xp - 4;
|
|
|
|
|
2013-01-27 21:28:10 +00:00
|
|
|
for (int idx = 0; idx <= _currentSegmentId; ++idx) {
|
2013-01-27 22:30:40 +00:00
|
|
|
int curZoneLineIdx = _segment[idx]._minZoneLineIdx;
|
|
|
|
if (_segment[idx]._maxZoneLineIdx < curZoneLineIdx)
|
2013-01-27 19:20:36 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
int yMax = yp + 4;
|
|
|
|
int yMin = yp - 4;
|
|
|
|
|
|
|
|
do {
|
2013-03-02 17:48:11 +00:00
|
|
|
LigneZoneItem *curZoneLine = &_zoneLine[curZoneLineIdx];
|
|
|
|
int16 *dataP = curZoneLine->_zoneData;
|
2013-01-27 19:20:36 +00:00
|
|
|
if (dataP != (int16 *)g_PTRNUL) {
|
2013-03-02 17:48:11 +00:00
|
|
|
int count = curZoneLine->_count;
|
|
|
|
int startX = dataP[0];
|
|
|
|
int startY = dataP[1];
|
|
|
|
int destX = dataP[count * 2 - 2];
|
|
|
|
int destY = dataP[count * 2 - 1];
|
2013-01-27 19:20:36 +00:00
|
|
|
|
|
|
|
bool flag = true;
|
2013-03-02 17:48:11 +00:00
|
|
|
if ((startX < destX && (xMax < startX || xMin > destX)) ||
|
|
|
|
(startX >= destX && (xMin > startX || xMax < destX)) ||
|
|
|
|
(startY < destY && (yMax < startY || yMin > destY)) ||
|
|
|
|
(startY >= destY && (yMin > startY || yMax < destY)))
|
2013-01-27 19:20:36 +00:00
|
|
|
flag = false;
|
|
|
|
|
2013-03-02 17:48:11 +00:00
|
|
|
if (flag && curZoneLine->_count > 0) {
|
2013-01-27 19:20:36 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
int xCheck = *dataP++;
|
|
|
|
int yCheck = *dataP++;
|
|
|
|
|
|
|
|
if ((xp == xCheck || (xp + 1) == xCheck) && (yp == yCheck))
|
2013-03-02 17:48:11 +00:00
|
|
|
return curZoneLine->_bobZoneIdx;
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-27 22:30:40 +00:00
|
|
|
} while (++curZoneLineIdx <= _segment[idx]._maxZoneLineIdx);
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Square Zone
|
|
|
|
void LinesManager::CARRE_ZONE() {
|
|
|
|
for (int idx = 0; idx < 100; ++idx) {
|
2013-03-02 17:48:11 +00:00
|
|
|
SquareZoneItem *curZone = &_squareZone[idx];
|
|
|
|
curZone->_enabledFl = false;
|
|
|
|
curZone->_squareZoneFl = false;
|
|
|
|
curZone->_left = 1280;
|
|
|
|
curZone->_right = 0;
|
|
|
|
curZone->_top = 460;
|
|
|
|
curZone->_bottom = 0;
|
|
|
|
curZone->_minZoneLineIdx = 401;
|
|
|
|
curZone->_maxZoneLineIdx = 0;
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int idx = 0; idx < MAX_LINES; ++idx) {
|
2013-02-15 22:57:23 +00:00
|
|
|
int16 *dataP = _zoneLine[idx]._zoneData;
|
2013-01-27 19:20:36 +00:00
|
|
|
if (dataP == (int16 *)g_PTRNUL)
|
|
|
|
continue;
|
|
|
|
|
2013-03-02 17:48:11 +00:00
|
|
|
SquareZoneItem *curZone = &_squareZone[_zoneLine[idx]._bobZoneIdx];
|
|
|
|
curZone->_enabledFl = true;
|
|
|
|
if (curZone->_maxZoneLineIdx < idx)
|
|
|
|
curZone->_maxZoneLineIdx = idx;
|
|
|
|
if (curZone->_minZoneLineIdx > idx)
|
|
|
|
curZone->_minZoneLineIdx = idx;
|
2013-01-27 19:20:36 +00:00
|
|
|
|
2013-02-15 22:57:23 +00:00
|
|
|
for (int i = 0; i < _zoneLine[idx]._count; i++) {
|
2013-01-27 19:20:36 +00:00
|
|
|
int zoneX = *dataP++;
|
|
|
|
int zoneY = *dataP++;
|
|
|
|
|
2013-03-26 07:11:53 +00:00
|
|
|
curZone->_left = MIN(curZone->_left, zoneX);
|
|
|
|
curZone->_right = MAX(curZone->_right, zoneX);
|
|
|
|
curZone->_top = MIN(curZone->_top, zoneY);
|
|
|
|
curZone->_bottom = MAX(curZone->_bottom, zoneY);
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int idx = 0; idx < 100; idx++) {
|
2013-01-27 22:30:40 +00:00
|
|
|
int zoneWidth = abs(_squareZone[idx]._left - _squareZone[idx]._right);
|
|
|
|
int zoneHeight = abs(_squareZone[idx]._top - _squareZone[idx]._bottom);
|
2013-01-27 19:20:36 +00:00
|
|
|
if (zoneWidth == zoneHeight)
|
2013-01-27 22:30:40 +00:00
|
|
|
_squareZone[idx]._squareZoneFl = true;
|
2013-01-27 19:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-27 21:28:10 +00:00
|
|
|
void LinesManager::clearAll() {
|
2013-02-12 22:48:03 +00:00
|
|
|
for (int idx = 0; idx < 105; ++idx) {
|
2013-02-15 22:57:23 +00:00
|
|
|
ZONEP[idx]._destX = 0;
|
|
|
|
ZONEP[idx]._destY = 0;
|
|
|
|
ZONEP[idx]._spriteIndex = 0;
|
2013-02-12 22:48:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 07:26:51 +00:00
|
|
|
_testRoute0 = (RouteItem *)g_PTRNUL;
|
2013-03-06 07:28:18 +00:00
|
|
|
_testRoute1 = (RouteItem *)g_PTRNUL;
|
|
|
|
_testRoute2 = (RouteItem *)g_PTRNUL;
|
2013-02-20 07:30:16 +00:00
|
|
|
_lineBuf = (int16 *)g_PTRNUL;
|
2013-02-18 22:52:55 +00:00
|
|
|
_route = (RouteItem *)g_PTRNUL;
|
2013-01-27 21:28:10 +00:00
|
|
|
|
|
|
|
for (int idx = 0; idx < MAX_LINES; ++idx) {
|
2013-02-20 07:30:16 +00:00
|
|
|
_lineItem[idx]._lineDataEndIdx = 0;
|
|
|
|
_lineItem[idx]._direction = DIR_NONE;
|
|
|
|
_lineItem[idx]._directionRouteInc = DIR_NONE;
|
|
|
|
_lineItem[idx]._directionRouteDec = DIR_NONE;
|
|
|
|
_lineItem[idx]._lineData = (int16 *)g_PTRNUL;
|
2013-01-27 21:28:10 +00:00
|
|
|
|
2013-02-15 22:57:23 +00:00
|
|
|
_zoneLine[idx]._count = 0;
|
|
|
|
_zoneLine[idx]._bobZoneIdx = 0;
|
|
|
|
_zoneLine[idx]._zoneData = (int16 *)g_PTRNUL;
|
2013-01-27 21:28:10 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 22:57:23 +00:00
|
|
|
for (int idx = 0; idx < 100; ++idx)
|
2013-02-21 07:23:38 +00:00
|
|
|
_squareZone[idx]._enabledFl = false;
|
2013-01-27 21:28:10 +00:00
|
|
|
|
2013-03-18 06:59:26 +00:00
|
|
|
_testRoute0 = new RouteItem[8334];
|
|
|
|
_testRoute1 = new RouteItem[8334];
|
|
|
|
_testRoute2 = new RouteItem[8334];
|
|
|
|
if (!_testRoute0)
|
|
|
|
_testRoute0 = (RouteItem*)g_PTRNUL;
|
|
|
|
if (!_testRoute1)
|
|
|
|
_testRoute1 = (RouteItem*)g_PTRNUL;
|
|
|
|
if (!_testRoute2)
|
|
|
|
_testRoute2 = (RouteItem*)g_PTRNUL;
|
2013-02-16 09:55:07 +00:00
|
|
|
|
2013-03-20 06:27:42 +00:00
|
|
|
_largeBuf = _vm->_globals->allocMemory(10000);
|
2013-03-18 06:59:26 +00:00
|
|
|
_lineBuf = (int16 *)(_largeBuf);
|
2013-01-27 21:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all zones and reset nextLine
|
|
|
|
*/
|
|
|
|
void LinesManager::clearAllZones() {
|
|
|
|
for (int idx = 0; idx < MAX_LINES; ++idx)
|
|
|
|
removeZoneLine(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove Zone Line
|
|
|
|
*/
|
|
|
|
void LinesManager::removeZoneLine(int idx) {
|
|
|
|
assert (idx <= MAX_LINES);
|
2013-03-20 06:27:42 +00:00
|
|
|
_zoneLine[idx]._zoneData = (int16 *)_vm->_globals->freeMemory((byte *)_zoneLine[idx]._zoneData);
|
2013-01-27 21:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LinesManager::resetLines() {
|
|
|
|
for (int idx = 0; idx < MAX_LINES; ++idx) {
|
|
|
|
removeLine(idx);
|
2013-02-20 07:30:16 +00:00
|
|
|
_lineItem[idx]._lineDataEndIdx = 0;
|
|
|
|
_lineItem[idx]._lineData = (int16 *)g_PTRNUL;
|
2013-01-27 21:28:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove Line
|
|
|
|
void LinesManager::removeLine(int idx) {
|
|
|
|
if (idx > MAX_LINES)
|
|
|
|
error("Attempting to add a line obstacle > MAX_LIGNE.");
|
2013-03-20 06:27:42 +00:00
|
|
|
_lineItem[idx]._lineData = (int16 *)_vm->_globals->freeMemory((byte *)_lineItem[idx]._lineData);
|
2013-01-27 21:28:10 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 21:53:20 +00:00
|
|
|
void LinesManager::setMaxLineIdx(int idx) {
|
|
|
|
_maxLineIdx = idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinesManager::resetLastLine() {
|
|
|
|
_lastLine = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinesManager::resetLinesNumb() {
|
|
|
|
_linesNumb = 0;
|
|
|
|
}
|
2013-02-12 22:48:03 +00:00
|
|
|
|
|
|
|
void LinesManager::enableZone(int idx) {
|
|
|
|
if (BOBZONE[idx]) {
|
|
|
|
BOBZONE_FLAG[idx] = true;
|
|
|
|
} else {
|
|
|
|
ZONEP[idx]._enabledFl = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinesManager::disableZone(int idx) {
|
|
|
|
if (BOBZONE[idx]) {
|
|
|
|
BOBZONE_FLAG[idx] = false;
|
|
|
|
} else {
|
|
|
|
ZONEP[idx]._enabledFl = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinesManager::checkZone() {
|
2013-03-19 19:40:55 +00:00
|
|
|
int mouseX = _vm->_eventsManager->getMouseX();
|
|
|
|
int mouseY = _vm->_eventsManager->getMouseY();
|
2013-02-12 22:48:03 +00:00
|
|
|
int oldMouseY = mouseY;
|
2013-03-20 06:27:42 +00:00
|
|
|
if (_vm->_globals->_cityMapEnabledFl
|
2013-03-19 19:40:55 +00:00
|
|
|
|| _vm->_eventsManager->_startPos.x >= mouseX
|
2013-03-20 06:36:06 +00:00
|
|
|
|| (mouseY = _vm->_graphicsManager->_scrollOffset + 54, mouseX >= mouseY)
|
2013-02-12 22:48:03 +00:00
|
|
|
|| (mouseY = oldMouseY - 1, mouseY < 0 || mouseY > 59)) {
|
2013-03-20 06:56:16 +00:00
|
|
|
if (_vm->_objectsManager->_visibleFl)
|
|
|
|
_vm->_objectsManager->_eraseVisibleCounter = 4;
|
|
|
|
_vm->_objectsManager->_visibleFl = false;
|
2013-02-12 22:48:03 +00:00
|
|
|
} else {
|
2013-03-20 06:56:16 +00:00
|
|
|
_vm->_objectsManager->_visibleFl = true;
|
2013-02-12 22:48:03 +00:00
|
|
|
}
|
2013-03-20 06:56:16 +00:00
|
|
|
if (_vm->_objectsManager->_forceZoneFl) {
|
2013-03-24 16:42:18 +00:00
|
|
|
_zoneSkipCount = 100;
|
2013-03-24 21:11:52 +00:00
|
|
|
_oldMouseZoneId = -1;
|
|
|
|
_oldMouseX = -200;
|
|
|
|
_oldMouseY = -220;
|
2013-03-20 06:56:16 +00:00
|
|
|
_vm->_objectsManager->_forceZoneFl = false;
|
2013-02-12 22:48:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-24 16:42:18 +00:00
|
|
|
_zoneSkipCount++;
|
|
|
|
if (_zoneSkipCount <= 1)
|
2013-02-12 22:48:03 +00:00
|
|
|
return;
|
|
|
|
|
2013-03-24 16:42:18 +00:00
|
|
|
if (_vm->_globals->_freezeCharacterFl || (_route == (RouteItem *)g_PTRNUL) || _zoneSkipCount > 4) {
|
|
|
|
_zoneSkipCount = 0;
|
2013-02-12 22:48:03 +00:00
|
|
|
int zoneId;
|
2013-03-24 21:11:52 +00:00
|
|
|
if (_oldMouseX != mouseX || _oldMouseY != oldMouseY) {
|
2013-02-22 07:18:13 +00:00
|
|
|
zoneId = getMouseZone();
|
2013-02-12 22:48:03 +00:00
|
|
|
} else {
|
2013-03-24 21:11:52 +00:00
|
|
|
zoneId = _oldMouseZoneId;
|
2013-02-12 22:48:03 +00:00
|
|
|
}
|
2013-03-24 21:11:52 +00:00
|
|
|
if (_oldMouseZoneId != zoneId) {
|
2013-03-20 06:36:06 +00:00
|
|
|
_vm->_graphicsManager->SETCOLOR4(251, 100, 100, 100);
|
2013-03-19 19:40:55 +00:00
|
|
|
_vm->_eventsManager->_mouseCursorId = 4;
|
|
|
|
_vm->_eventsManager->changeMouseCursor(4);
|
2013-03-24 18:38:48 +00:00
|
|
|
if (_forceHideText) {
|
2013-03-20 00:00:12 +00:00
|
|
|
_vm->_fontManager->hideText(5);
|
2013-03-24 18:38:48 +00:00
|
|
|
_forceHideText = false;
|
2013-02-12 22:48:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (zoneId != -1) {
|
2013-02-20 07:30:16 +00:00
|
|
|
if (ZONEP[zoneId]._verbFl1 || ZONEP[zoneId]._verbFl2 ||
|
|
|
|
ZONEP[zoneId]._verbFl3 || ZONEP[zoneId]._verbFl4 ||
|
|
|
|
ZONEP[zoneId]._verbFl5 || ZONEP[zoneId]._verbFl6 ||
|
|
|
|
ZONEP[zoneId]._verbFl7 || ZONEP[zoneId]._verbFl8 ||
|
|
|
|
ZONEP[zoneId]._verbFl9 || ZONEP[zoneId]._verbFl10) {
|
2013-03-24 21:11:52 +00:00
|
|
|
if (_oldMouseZoneId != zoneId) {
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_fontManager->initTextBuffers(5, ZONEP[zoneId]._messageId, _vm->_globals->_zoneFilename, 0, 430, 0, 0, 252);
|
2013-03-20 00:00:12 +00:00
|
|
|
_vm->_fontManager->showText(5);
|
2013-03-24 18:38:48 +00:00
|
|
|
_forceHideText = true;
|
2013-02-12 22:48:03 +00:00
|
|
|
}
|
2013-03-24 19:39:16 +00:00
|
|
|
_hotspotTextColor += 25;
|
|
|
|
if (_hotspotTextColor > 100)
|
|
|
|
_hotspotTextColor = 0;
|
|
|
|
_vm->_graphicsManager->SETCOLOR4(251, _hotspotTextColor, _hotspotTextColor, _hotspotTextColor);
|
2013-03-19 19:40:55 +00:00
|
|
|
if (_vm->_eventsManager->_mouseCursorId == 4) {
|
2013-02-20 07:30:16 +00:00
|
|
|
if (ZONEP[zoneId]._verbFl1 == 2) {
|
2013-03-19 19:40:55 +00:00
|
|
|
_vm->_eventsManager->changeMouseCursor(16);
|
|
|
|
_vm->_eventsManager->_mouseCursorId = 16;
|
2013-03-20 06:56:16 +00:00
|
|
|
_vm->_objectsManager->setVerb(16);
|
2013-02-12 22:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2013-03-20 06:36:06 +00:00
|
|
|
_vm->_graphicsManager->SETCOLOR4(251, 100, 100, 100);
|
2013-03-19 19:40:55 +00:00
|
|
|
_vm->_eventsManager->_mouseCursorId = 4;
|
|
|
|
_vm->_eventsManager->changeMouseCursor(4);
|
2013-02-12 22:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-20 06:56:16 +00:00
|
|
|
_vm->_objectsManager->_zoneNum = zoneId;
|
2013-03-24 21:11:52 +00:00
|
|
|
_oldMouseX = mouseX;
|
|
|
|
_oldMouseY = oldMouseY;
|
|
|
|
_oldMouseZoneId = zoneId;
|
2013-03-20 06:27:42 +00:00
|
|
|
if (_vm->_globals->_freezeCharacterFl && (_vm->_eventsManager->_mouseCursorId == 4)) {
|
2013-02-12 22:48:03 +00:00
|
|
|
if (zoneId != -1 && zoneId != 0)
|
2013-03-20 06:56:16 +00:00
|
|
|
_vm->_objectsManager->handleRightButton();
|
2013-02-12 22:48:03 +00:00
|
|
|
}
|
2013-03-20 06:27:42 +00:00
|
|
|
if ((_vm->_globals->_cityMapEnabledFl && zoneId == -1) || !zoneId) {
|
2013-03-20 06:56:16 +00:00
|
|
|
_vm->_objectsManager->setVerb(0);
|
2013-03-19 19:40:55 +00:00
|
|
|
_vm->_eventsManager->_mouseCursorId = 0;
|
|
|
|
_vm->_eventsManager->changeMouseCursor(0);
|
2013-02-12 22:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-02 11:44:23 +00:00
|
|
|
} // End of namespace Hopkins
|