2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2007-04-27 12:58:35 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2007-04-27 12:58:35 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2014-02-18 01:34:18 +00:00
|
|
|
*
|
2007-04-27 12:58:35 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:18 +00:00
|
|
|
*
|
2007-04-27 12:58:35 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-08-09 10:30:40 +00:00
|
|
|
#include "cruise/cruise.h"
|
2007-04-27 12:58:35 +00:00
|
|
|
#include "cruise/cruise_main.h"
|
2007-04-28 04:29:05 +00:00
|
|
|
#include "common/util.h"
|
2007-04-27 12:58:35 +00:00
|
|
|
|
|
|
|
namespace Cruise {
|
|
|
|
|
2007-05-10 07:48:13 +00:00
|
|
|
persoStruct *persoTable[NUM_PERSONS];
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2009-04-05 07:52:21 +00:00
|
|
|
int16 numPoly;
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
void freePerso(int persoIdx) {
|
|
|
|
if (persoTable[persoIdx]) {
|
2009-10-09 08:15:30 +00:00
|
|
|
MemFree(persoTable[persoIdx]);
|
2007-04-27 22:33:45 +00:00
|
|
|
persoTable[persoIdx] = NULL;
|
|
|
|
}
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
void freeCTP() {
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-12-18 20:12:42 +00:00
|
|
|
for (unsigned long int i = 0; i < NUM_PERSONS; i++) {
|
2007-04-27 22:33:45 +00:00
|
|
|
freePerso(i);
|
|
|
|
}
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2010-08-09 10:30:40 +00:00
|
|
|
if (_vm->_polyStruct) {
|
|
|
|
_vm->_polyStructNorm.clear();
|
|
|
|
_vm->_polyStructExp.clear();
|
|
|
|
_vm->_polyStruct = NULL;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
ctpVar17 = NULL;
|
2010-08-09 10:30:40 +00:00
|
|
|
_vm->_polyStruct = NULL;
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
strcpy((char *)currentCtpName, "");
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int pathVar0;
|
|
|
|
|
2007-12-20 18:21:27 +00:00
|
|
|
unsigned int inc_jo;
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
int direction(int x1, int y1, int x2, int y2, int inc_jo1, int inc_jo2) {
|
|
|
|
int h, v, h1, v1;
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
h1 = x1 - x2;
|
2007-04-28 04:29:05 +00:00
|
|
|
h = ABS(h1);
|
2007-04-27 22:33:45 +00:00
|
|
|
v1 = y1 - y2;
|
2007-04-28 04:29:05 +00:00
|
|
|
v = ABS(v1);
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
if (v > h) {
|
|
|
|
if (h > 30)
|
|
|
|
inc_jo = inc_jo1 - inc_jo2;
|
|
|
|
else
|
|
|
|
inc_jo = inc_jo2;
|
|
|
|
|
|
|
|
if (v1 < 0)
|
|
|
|
return (2);
|
|
|
|
else
|
|
|
|
return (0);
|
|
|
|
} else {
|
2007-04-27 12:58:35 +00:00
|
|
|
inc_jo = inc_jo1;
|
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
if (h1 < 0)
|
|
|
|
return (1);
|
|
|
|
else
|
|
|
|
return (3);
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-20 18:21:27 +00:00
|
|
|
int cor_droite(int x1, int y1, int x2, int y2, point* outputTable) {
|
|
|
|
int numOutput = 0;
|
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
int dx;
|
|
|
|
int dy;
|
|
|
|
|
|
|
|
int mD0;
|
|
|
|
int mD1;
|
|
|
|
|
|
|
|
int mA0;
|
|
|
|
int mA1;
|
|
|
|
|
|
|
|
int bp;
|
|
|
|
int cx;
|
|
|
|
int si;
|
|
|
|
|
|
|
|
int ax;
|
|
|
|
int bx;
|
|
|
|
|
2007-12-20 18:21:27 +00:00
|
|
|
outputTable[numOutput].x = x1;
|
|
|
|
outputTable[numOutput].y = y1;
|
|
|
|
numOutput++;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
dx = x2 - x1;
|
|
|
|
dy = y2 - y1;
|
|
|
|
|
|
|
|
mD0 = mD1 = 1;
|
|
|
|
|
|
|
|
if (dx < 0) {
|
|
|
|
dx = -dx;
|
|
|
|
mD0 = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dy < 0) {
|
|
|
|
dy = -dy;
|
|
|
|
mD1 = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dx < dy) {
|
|
|
|
mA0 = 0;
|
|
|
|
bp = dx;
|
|
|
|
cx = dy;
|
|
|
|
|
|
|
|
mA1 = mD1;
|
|
|
|
} else {
|
|
|
|
mA1 = 0;
|
|
|
|
bp = dy;
|
|
|
|
cx = dx;
|
|
|
|
|
|
|
|
mA0 = mD0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bp = bp * 2;
|
|
|
|
dx = bp - cx;
|
|
|
|
si = dx - cx;
|
|
|
|
|
|
|
|
ax = x1;
|
|
|
|
bx = y1;
|
|
|
|
|
|
|
|
while (--cx) {
|
|
|
|
if (dx > 0) {
|
|
|
|
ax += mD0;
|
|
|
|
bx += mD1;
|
|
|
|
dx += si;
|
|
|
|
} else {
|
|
|
|
ax += mA0;
|
|
|
|
bx += mA1;
|
|
|
|
dx += bp;
|
|
|
|
}
|
|
|
|
|
2007-12-20 18:21:27 +00:00
|
|
|
outputTable[numOutput].x = ax;
|
|
|
|
outputTable[numOutput].y = bx;
|
|
|
|
numOutput++;
|
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
flag_obstacle = 0;
|
2007-12-20 18:21:27 +00:00
|
|
|
|
|
|
|
return numOutput;
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
2009-03-03 10:10:35 +00:00
|
|
|
void processActorWalk(MovementEntry &resx_y, int16 *inc_droite, int16 *inc_droite0,
|
2009-01-16 02:43:41 +00:00
|
|
|
int16 *inc_chemin, point* cor_joueur,
|
|
|
|
int16 solution0[NUM_NODES + 3][2], int16 *inc_jo1, int16 *inc_jo2,
|
|
|
|
int16 *dir_perso, int16 *inc_jo0, int16 num) {
|
2014-06-06 20:41:44 +00:00
|
|
|
int u = 0;
|
2007-04-27 12:58:35 +00:00
|
|
|
inc_jo = *inc_jo0;
|
|
|
|
|
2014-06-06 20:41:44 +00:00
|
|
|
int i = *inc_chemin;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
if (!*inc_droite) {
|
2014-06-06 20:41:44 +00:00
|
|
|
int x1 = solution0[i][0];
|
|
|
|
int y1 = solution0[i][1];
|
2007-04-27 12:58:35 +00:00
|
|
|
i++;
|
2007-04-27 22:33:45 +00:00
|
|
|
if (solution0[i][0] != -1) {
|
|
|
|
do {
|
|
|
|
if (solution0[i][0] != -2) {
|
2014-06-06 20:41:44 +00:00
|
|
|
int x2 = solution0[i][0];
|
|
|
|
int y2 = solution0[i][1];
|
2007-04-27 22:33:45 +00:00
|
|
|
if ((x1 == x2) && (y1 == y2)) {
|
2009-03-03 10:10:35 +00:00
|
|
|
resx_y.x = -1;
|
|
|
|
resx_y.y = -1;
|
2007-04-27 12:58:35 +00:00
|
|
|
freePerso(num);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-12-20 18:21:27 +00:00
|
|
|
*inc_droite0 = cor_droite(x1, y1, x2, y2, cor_joueur);
|
2009-03-03 10:10:35 +00:00
|
|
|
*dir_perso = resx_y.direction = direction(x1, y1, x2, y2, *inc_jo1, *inc_jo2);
|
2007-04-27 22:33:45 +00:00
|
|
|
*inc_jo0 = inc_jo;
|
|
|
|
u = 1;
|
|
|
|
} else
|
|
|
|
i++;
|
|
|
|
|
|
|
|
} while (solution0[i][0] != -1 && !u);
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
2007-04-27 22:33:45 +00:00
|
|
|
if (!u) {
|
2009-03-03 10:10:35 +00:00
|
|
|
resx_y.x = -1;
|
|
|
|
resx_y.y = -1;
|
2007-04-27 12:58:35 +00:00
|
|
|
freePerso(num);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2007-04-27 22:33:45 +00:00
|
|
|
*inc_chemin = i;
|
|
|
|
}
|
|
|
|
|
2009-03-03 10:10:35 +00:00
|
|
|
resx_y.x = cor_joueur[*inc_droite].x;
|
|
|
|
resx_y.y = cor_joueur[*inc_droite].y;
|
|
|
|
resx_y.direction = *dir_perso;
|
|
|
|
resx_y.zoom = computeZoom(resx_y.y);
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2009-03-03 10:10:35 +00:00
|
|
|
getPixel(resx_y.x, resx_y.y);
|
2009-04-05 07:52:21 +00:00
|
|
|
resx_y.poly = numPoly;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2009-03-03 10:10:35 +00:00
|
|
|
u = subOp23(resx_y.zoom, inc_jo);
|
2007-04-27 22:33:45 +00:00
|
|
|
if (!u)
|
|
|
|
u = 1;
|
|
|
|
*inc_droite += u;
|
|
|
|
|
|
|
|
if ((*inc_droite) >= (*inc_droite0)) {
|
|
|
|
*inc_droite = 0;
|
2009-03-03 10:10:35 +00:00
|
|
|
resx_y.x = solution0[*inc_chemin][0];
|
|
|
|
resx_y.y = solution0[*inc_chemin][1];
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-03-03 10:10:35 +00:00
|
|
|
void affiche_chemin(int16 persoIdx, MovementEntry &data) {
|
2007-04-27 22:33:45 +00:00
|
|
|
persoStruct *pPerso = persoTable[persoIdx];
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2007-04-27 22:33:45 +00:00
|
|
|
ASSERT(pPerso);
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2009-03-03 10:10:35 +00:00
|
|
|
processActorWalk(data, &pPerso->inc_droite, &pPerso->inc_droite0,
|
2009-01-16 02:43:41 +00:00
|
|
|
&pPerso->inc_chemin, pPerso->coordinates, pPerso->solution,
|
|
|
|
&pPerso->inc_jo1, &pPerso->inc_jo2, &pPerso->dir_perso,
|
|
|
|
&pPerso->inc_jo0, persoIdx);
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Cruise
|