2003-03-07 14:52:24 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2003-2005 The ScummVM project
|
2003-03-07 14:52:24 +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.
|
|
|
|
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-10-05 20:21:20 +00:00
|
|
|
#include "sky/compact.h"
|
|
|
|
#include "sky/disk.h"
|
|
|
|
#include "sky/grid.h"
|
|
|
|
#include "sky/logic.h"
|
2004-12-15 06:48:08 +00:00
|
|
|
#include "sky/compact.h"
|
2003-03-07 14:52:24 +00:00
|
|
|
|
2004-01-03 01:58:58 +00:00
|
|
|
namespace Sky {
|
|
|
|
|
2003-03-07 14:52:24 +00:00
|
|
|
#define GRID_FILE_START 60000
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
int8 Grid::_gridConvertTable[] = {
|
2003-03-07 14:52:24 +00:00
|
|
|
|
2003-04-29 13:06:01 +00:00
|
|
|
0, //0
|
2003-03-07 14:52:24 +00:00
|
|
|
1, //1
|
|
|
|
2, //2
|
|
|
|
3, //3
|
|
|
|
4, //4
|
|
|
|
5, //5
|
|
|
|
6, //6
|
|
|
|
7, //7
|
|
|
|
8, //8
|
|
|
|
9, //9
|
|
|
|
10, //10
|
|
|
|
11, //11
|
|
|
|
12, //12
|
|
|
|
13, //13
|
|
|
|
14, //14
|
|
|
|
15, //15
|
|
|
|
16, //16
|
|
|
|
17, //17
|
|
|
|
18, //18
|
|
|
|
19, //19
|
|
|
|
20, //20
|
|
|
|
21, //21
|
|
|
|
22, //22
|
|
|
|
23, //23
|
|
|
|
24, //24
|
|
|
|
25, //25
|
|
|
|
26, //26
|
|
|
|
27, //27
|
|
|
|
28, //28
|
|
|
|
29, //29
|
|
|
|
30, //30
|
|
|
|
31, //31
|
|
|
|
32, //32
|
|
|
|
33, //33
|
|
|
|
34, //34
|
|
|
|
-1, //35
|
|
|
|
35, //36
|
|
|
|
36, //37
|
|
|
|
37, //38
|
|
|
|
38, //39
|
|
|
|
39, //40
|
|
|
|
40, //41
|
|
|
|
41, //42
|
|
|
|
-1, //43
|
|
|
|
42, //44
|
|
|
|
43, //45
|
|
|
|
44, //46
|
|
|
|
45, //47
|
|
|
|
46, //48
|
|
|
|
-1, //49
|
|
|
|
-1, //50
|
|
|
|
-1, //51
|
|
|
|
-1, //52
|
|
|
|
-1, //53
|
|
|
|
-1, //54
|
|
|
|
-1, //55
|
|
|
|
-1, //56
|
|
|
|
-1, //57
|
|
|
|
-1, //58
|
|
|
|
-1, //59
|
|
|
|
-1, //60
|
|
|
|
-1, //61
|
|
|
|
-1, //62
|
|
|
|
-1, //63
|
|
|
|
-1, //64
|
|
|
|
47, //65
|
|
|
|
TOT_NO_GRIDS, //66
|
|
|
|
48, //67
|
|
|
|
49, //68
|
|
|
|
50, //69
|
|
|
|
51, //70
|
|
|
|
52, //71
|
|
|
|
53, //72
|
|
|
|
54, //73
|
|
|
|
55, //74
|
|
|
|
56, //75
|
|
|
|
57, //76
|
|
|
|
58, //77
|
|
|
|
59, //78
|
|
|
|
60, //79
|
|
|
|
-1, //80
|
|
|
|
61, //81
|
|
|
|
62, //82
|
|
|
|
-1, //83
|
|
|
|
-1, //84
|
|
|
|
-1, //85
|
|
|
|
-1, //86
|
|
|
|
-1, //87
|
|
|
|
-1, //88
|
|
|
|
TOT_NO_GRIDS, //89
|
|
|
|
63, //90
|
|
|
|
64, //91
|
|
|
|
65, //92
|
|
|
|
66, //93
|
|
|
|
67, //94
|
|
|
|
68, //95
|
|
|
|
69, //96
|
|
|
|
};
|
|
|
|
|
2004-12-15 06:48:08 +00:00
|
|
|
Grid::Grid(Disk *pDisk, SkyCompact *skyCompact) {
|
2004-11-11 10:14:35 +00:00
|
|
|
for (int cnt = 0; cnt < TOT_NO_GRIDS; cnt++)
|
|
|
|
_gameGrids[cnt] = NULL;
|
2003-05-14 21:25:03 +00:00
|
|
|
_skyDisk = pDisk;
|
2004-12-15 06:48:08 +00:00
|
|
|
_skyCompact = skyCompact;
|
2003-04-25 23:14:41 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
Grid::~Grid(void) {
|
2004-11-11 10:14:35 +00:00
|
|
|
for (uint8 cnt = 0; cnt < TOT_NO_GRIDS; cnt++)
|
|
|
|
if (_gameGrids[cnt])
|
|
|
|
free(_gameGrids[cnt]);
|
2003-04-25 23:14:41 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void Grid::loadGrids(void) {
|
2003-04-25 23:14:41 +00:00
|
|
|
// no endian conversion necessary as I'm using uint8* instead of uint32*
|
2004-11-11 10:14:35 +00:00
|
|
|
for (uint8 cnt = 0; cnt < TOT_NO_GRIDS; cnt++) {
|
|
|
|
if (_gameGrids[cnt])
|
|
|
|
free(_gameGrids[cnt]);
|
|
|
|
_gameGrids[cnt] = _skyDisk->loadFile(GRID_FILE_START + cnt);
|
|
|
|
}
|
2003-10-05 20:21:20 +00:00
|
|
|
if (!SkyEngine::isDemo()) { // single disk demos never get that far
|
2003-06-01 21:21:10 +00:00
|
|
|
// Reloading the grids can sometimes cause problems eg when reichs door is
|
|
|
|
// open the door grid bit gets replaced so you can't get back in (or out)
|
2004-01-03 15:57:57 +00:00
|
|
|
if (Logic::_scriptVariables[REICH_DOOR_FLAG])
|
2004-12-15 06:48:08 +00:00
|
|
|
removeGrid(256, 280, 1, _skyCompact->fetchCpt(CPT_REICH_DOOR_20));
|
|
|
|
//removeGrid(256, 280, 1, &SkyCompact::reich_door_20);
|
2003-06-01 21:21:10 +00:00
|
|
|
}
|
2003-03-07 14:52:24 +00:00
|
|
|
}
|
|
|
|
|
2004-11-11 10:14:35 +00:00
|
|
|
bool Grid::getGridValues(Compact *cpt, uint8 *resGrid, uint32 *resBitNum, uint32 *resWidth) {
|
2004-12-15 06:48:08 +00:00
|
|
|
uint16 width = SkyCompact::getMegaSet(cpt)->gridWidth;
|
2004-11-11 10:14:35 +00:00
|
|
|
return getGridValues(cpt->xcood, cpt->ycood, width, cpt, resGrid, resBitNum, resWidth);
|
2003-04-25 23:14:41 +00:00
|
|
|
}
|
|
|
|
|
2004-11-11 10:14:35 +00:00
|
|
|
bool Grid::getGridValues(uint32 x, uint32 y, uint32 width, Compact *cpt, uint8 *resGrid, uint32 *resBitNum, uint32 *resWidth) {
|
2003-04-25 23:14:41 +00:00
|
|
|
uint32 bitPos;
|
2004-11-11 10:14:35 +00:00
|
|
|
if (y < TOP_LEFT_Y)
|
|
|
|
return false; // off screen
|
2003-04-25 23:14:41 +00:00
|
|
|
y -= TOP_LEFT_Y;
|
|
|
|
y >>= 3; // convert to blocks
|
2004-11-11 10:14:35 +00:00
|
|
|
if (y >= GAME_SCREEN_HEIGHT >> 3)
|
|
|
|
return false; // off screen
|
2003-04-25 23:14:41 +00:00
|
|
|
bitPos = y * 40;
|
|
|
|
width++;
|
|
|
|
x >>= 3; // convert to blocks
|
|
|
|
|
2003-07-01 01:29:29 +00:00
|
|
|
if (x < (TOP_LEFT_X >> 3)) { // at least partially off screen
|
2004-11-11 10:14:35 +00:00
|
|
|
if (x + width < (TOP_LEFT_X >> 3))
|
|
|
|
return false; // completely off screen
|
2003-07-01 01:29:29 +00:00
|
|
|
else {
|
|
|
|
width -= (TOP_LEFT_X >> 3) - x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
x -= TOP_LEFT_X >> 3;
|
|
|
|
|
2004-11-11 10:14:35 +00:00
|
|
|
if ((GAME_SCREEN_WIDTH >> 3) <= x)
|
|
|
|
return false; // off screen
|
2003-07-01 01:29:29 +00:00
|
|
|
if ((GAME_SCREEN_WIDTH >> 3) < x + width) // partially off screen
|
|
|
|
width = (GAME_SCREEN_WIDTH >> 3) - x;
|
|
|
|
|
2003-10-01 09:40:28 +00:00
|
|
|
bitPos += x;
|
2004-11-11 10:14:35 +00:00
|
|
|
assert((_gridConvertTable[cpt->screen] >= 0) && (_gridConvertTable[cpt->screen] < TOT_NO_GRIDS));
|
|
|
|
*resGrid = (uint8)_gridConvertTable[cpt->screen];
|
|
|
|
|
2003-06-17 12:27:03 +00:00
|
|
|
uint32 tmpBits = 0x1F - (bitPos&0x1F);
|
2003-04-25 23:14:41 +00:00
|
|
|
bitPos &= ~0x1F; // divide into dword address and bit number
|
2003-06-17 12:27:03 +00:00
|
|
|
bitPos += tmpBits;
|
2003-04-25 23:14:41 +00:00
|
|
|
*resBitNum = bitPos;
|
|
|
|
*resWidth = width;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void Grid::removeObjectFromWalk(Compact *cpt) {
|
2003-04-25 23:14:41 +00:00
|
|
|
uint32 bitNum, width;
|
2004-11-11 10:14:35 +00:00
|
|
|
uint8 gridIdx;
|
|
|
|
if (getGridValues(cpt, &gridIdx, &bitNum, &width))
|
|
|
|
removeObjectFromWalk(gridIdx, bitNum, width);
|
2003-04-25 23:14:41 +00:00
|
|
|
}
|
|
|
|
|
2004-11-11 10:14:35 +00:00
|
|
|
void Grid::removeObjectFromWalk(uint8 gridIdx, uint32 bitNum, uint32 width) {
|
2003-04-25 23:14:41 +00:00
|
|
|
for (uint32 cnt = 0; cnt < width; cnt++) {
|
2004-11-11 10:14:35 +00:00
|
|
|
_gameGrids[gridIdx][bitNum >> 3] &= ~(1 << (bitNum & 0x7));
|
2003-04-25 23:14:41 +00:00
|
|
|
if ((bitNum & 0x1F) == 0)
|
|
|
|
bitNum += 0x3F;
|
2004-11-11 10:14:35 +00:00
|
|
|
else
|
|
|
|
bitNum--;
|
2003-04-25 23:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void Grid::objectToWalk(Compact *cpt) {
|
2003-04-25 23:14:41 +00:00
|
|
|
uint32 bitNum, width;
|
2004-11-11 10:14:35 +00:00
|
|
|
uint8 gridIdx;
|
|
|
|
if (getGridValues(cpt, &gridIdx, &bitNum, &width))
|
|
|
|
objectToWalk(gridIdx, bitNum, width);
|
2003-04-25 23:14:41 +00:00
|
|
|
}
|
|
|
|
|
2004-11-11 10:14:35 +00:00
|
|
|
void Grid::objectToWalk(uint8 gridIdx, uint32 bitNum, uint32 width) {
|
2003-04-25 23:14:41 +00:00
|
|
|
for (uint32 cnt = 0; cnt < width; cnt++) {
|
2004-11-11 10:14:35 +00:00
|
|
|
_gameGrids[gridIdx][bitNum >> 3] |= (1 << (bitNum & 0x7));
|
2003-04-25 23:14:41 +00:00
|
|
|
if ((bitNum & 0x1F) == 0)
|
|
|
|
bitNum += 0x3F;
|
2004-11-11 10:14:35 +00:00
|
|
|
else
|
|
|
|
bitNum--;
|
2003-04-25 23:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void Grid::plotGrid(uint32 x, uint32 y, uint32 width, Compact *cpt) {
|
2003-04-25 23:14:41 +00:00
|
|
|
uint32 resBitPos, resWidth;
|
2004-11-11 10:14:35 +00:00
|
|
|
uint8 resGridIdx;
|
|
|
|
if (getGridValues(x, y, width-1, cpt, &resGridIdx, &resBitPos, &resWidth))
|
|
|
|
objectToWalk(resGridIdx, resBitPos, resWidth);
|
2003-04-25 23:14:41 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 15:57:57 +00:00
|
|
|
void Grid::removeGrid(uint32 x, uint32 y, uint32 width, Compact *cpt) {
|
2003-04-25 23:14:41 +00:00
|
|
|
uint32 resBitPos, resWidth;
|
2004-11-11 10:14:35 +00:00
|
|
|
uint8 resGridIdx;
|
|
|
|
if (getGridValues(x, y, width, cpt, &resGridIdx, &resBitPos, &resWidth))
|
|
|
|
removeObjectFromWalk(resGridIdx, resBitPos, resWidth);
|
2003-04-25 23:14:41 +00:00
|
|
|
}
|
2003-04-27 15:02:52 +00:00
|
|
|
|
2004-11-11 10:14:35 +00:00
|
|
|
uint8 *Grid::giveGrid(uint32 pScreen) {
|
|
|
|
assert((_gridConvertTable[pScreen] >= 0) && (_gridConvertTable[pScreen] < TOT_NO_GRIDS));
|
|
|
|
return _gameGrids[_gridConvertTable[pScreen]];
|
2003-04-27 15:02:52 +00:00
|
|
|
}
|
2004-01-03 01:58:58 +00:00
|
|
|
|
|
|
|
} // End of namespace Sky
|