2004-04-12 21:40:49 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2004-2006 The ScummVM project
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
|
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Isometric level module - private header
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2007-02-19 17:30:43 +00:00
|
|
|
#ifndef SAGA_ISOMAP_H
|
|
|
|
#define SAGA_ISOMAP_H
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-02-18 00:00:00 +00:00
|
|
|
#include "saga/actor.h"
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
namespace Saga {
|
|
|
|
|
2005-01-28 19:25:41 +00:00
|
|
|
#define SAGA_ISOTILEDATA_LEN 8
|
2004-04-12 21:40:49 +00:00
|
|
|
#define SAGA_ISOTILE_WIDTH 32
|
|
|
|
#define SAGA_ISOTILE_BASEHEIGHT 15
|
2005-02-09 20:30:45 +00:00
|
|
|
#define SAGA_TILE_NOMINAL_H 16
|
|
|
|
#define SAGA_MAX_TILE_H 64
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-28 19:25:41 +00:00
|
|
|
#define SAGA_TILEPLATFORMDATA_LEN 136
|
|
|
|
#define SAGA_PLATFORM_W 8
|
|
|
|
#define SAGA_MAX_PLATFORM_H 16
|
|
|
|
|
|
|
|
#define SAGA_TILEMAP_LEN 514
|
|
|
|
#define SAGA_TILEMAP_W 16
|
|
|
|
#define SAGA_TILEMAP_H 16
|
|
|
|
|
|
|
|
#define SAGA_METATILEDATA_LEN 36
|
|
|
|
|
2005-02-09 20:30:45 +00:00
|
|
|
#define SAGA_MULTI_TILE (1 << 15)
|
|
|
|
|
2005-02-18 00:00:00 +00:00
|
|
|
#define SAGA_SCROLL_LIMIT_X1 32
|
|
|
|
#define SAGA_SCROLL_LIMIT_X2 64
|
|
|
|
#define SAGA_SCROLL_LIMIT_Y1 8
|
|
|
|
#define SAGA_SCROLL_LIMIT_Y2 32
|
|
|
|
|
2005-06-29 20:00:44 +00:00
|
|
|
#define SAGA_DRAGON_SEARCH_CENTER 24
|
|
|
|
#define SAGA_DRAGON_SEARCH_DIAMETER (SAGA_DRAGON_SEARCH_CENTER * 2)
|
|
|
|
|
2005-02-26 11:44:30 +00:00
|
|
|
#define SAGA_SEARCH_CENTER 15
|
|
|
|
#define SAGA_SEARCH_DIAMETER (SAGA_SEARCH_CENTER * 2)
|
|
|
|
#define SAGA_SEARCH_QUEUE_SIZE 128
|
|
|
|
#define SAGA_IMPASSABLE ((1 << kTerrBlock) | (1 << kTerrWater))
|
|
|
|
|
|
|
|
#define SAGA_STRAIGHT_NORMAL_COST 4
|
|
|
|
#define SAGA_DIAG_NORMAL_COST 6
|
|
|
|
|
|
|
|
#define SAGA_STRAIGHT_EASY_COST 2
|
|
|
|
#define SAGA_DIAG_EASY_COST 3
|
|
|
|
|
|
|
|
#define SAGA_STRAIGHT_HARD_COST 9
|
|
|
|
#define SAGA_DIAG_HARD_COST 10
|
2005-02-26 17:37:16 +00:00
|
|
|
#define SAGA_MAX_PATH_DIRECTIONS 256
|
2005-02-26 11:44:30 +00:00
|
|
|
|
|
|
|
enum TerrainTypes {
|
|
|
|
kTerrNone = 0,
|
|
|
|
kTerrPath = 1,
|
|
|
|
kTerrRough = 2,
|
|
|
|
kTerrBlock = 3,
|
|
|
|
kTerrWater = 4,
|
|
|
|
kTerrLast = 5
|
|
|
|
};
|
|
|
|
|
2005-02-09 20:30:45 +00:00
|
|
|
enum TileMapEdgeType {
|
|
|
|
kEdgeTypeBlack = 0,
|
|
|
|
kEdgeTypeFill0 = 1,
|
|
|
|
kEdgeTypeFill1 = 2,
|
|
|
|
kEdgeTypeRpt = 3,
|
|
|
|
kEdgeTypeWrap = 4
|
|
|
|
};
|
|
|
|
|
2005-01-28 19:25:41 +00:00
|
|
|
struct IsoTileData {
|
|
|
|
byte height;
|
|
|
|
int8 attributes;
|
|
|
|
size_t offset;
|
|
|
|
uint16 terrainMask;
|
2005-02-26 11:44:30 +00:00
|
|
|
byte FGDBGDAttr;
|
2005-03-13 17:43:50 +00:00
|
|
|
int8 GetMaskRule() const {
|
2005-02-22 20:18:55 +00:00
|
|
|
return attributes & 0x0F;
|
|
|
|
}
|
2005-03-13 17:43:50 +00:00
|
|
|
byte GetFGDAttr() const {
|
2005-02-26 11:44:30 +00:00
|
|
|
return FGDBGDAttr >> 4;
|
|
|
|
}
|
2005-03-13 17:43:50 +00:00
|
|
|
byte GetBGDAttr() const {
|
2005-02-26 11:44:30 +00:00
|
|
|
return FGDBGDAttr & 0x0F;
|
|
|
|
}
|
2005-03-13 17:43:50 +00:00
|
|
|
uint16 GetFGDMask() const {
|
2005-02-26 11:44:30 +00:00
|
|
|
return 1 << GetFGDAttr();
|
|
|
|
}
|
2005-03-13 17:43:50 +00:00
|
|
|
uint16 GetBGDMask() const {
|
2005-02-26 11:44:30 +00:00
|
|
|
return 1 << GetBGDAttr();
|
|
|
|
}
|
2005-01-28 19:25:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TilePlatformData {
|
2005-07-30 21:11:48 +00:00
|
|
|
int16 metaTile;
|
2005-01-28 19:25:41 +00:00
|
|
|
int16 height;
|
|
|
|
int16 highestPixel;
|
|
|
|
byte vBits;
|
|
|
|
byte uBits;
|
|
|
|
int16 tiles[SAGA_PLATFORM_W][SAGA_PLATFORM_W];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TileMapData {
|
|
|
|
byte edgeType;
|
|
|
|
int16 tilePlatforms[SAGA_TILEMAP_W][SAGA_TILEMAP_H];
|
2004-04-25 14:42:14 +00:00
|
|
|
};
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-28 19:25:41 +00:00
|
|
|
struct MetaTileData {
|
|
|
|
uint16 highestPlatform;
|
|
|
|
uint16 highestPixel;
|
|
|
|
int16 stack[SAGA_MAX_PLATFORM_H];
|
|
|
|
};
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-28 19:25:41 +00:00
|
|
|
struct MultiTileEntryData {
|
|
|
|
int16 offset;
|
|
|
|
byte u;
|
|
|
|
byte v;
|
|
|
|
byte h;
|
|
|
|
byte uSize;
|
|
|
|
byte vSize;
|
|
|
|
byte numStates;
|
|
|
|
byte currentState;
|
|
|
|
};
|
2004-08-02 14:51:48 +00:00
|
|
|
|
2005-02-26 11:44:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
class IsoMap {
|
|
|
|
public:
|
2005-01-28 19:25:41 +00:00
|
|
|
IsoMap(SagaEngine *vm);
|
|
|
|
~IsoMap() {
|
|
|
|
freeMem();
|
|
|
|
}
|
|
|
|
void loadImages(const byte * resourcePointer, size_t resourceLength);
|
|
|
|
void loadMap(const byte * resourcePointer, size_t resourceLength);
|
|
|
|
void loadPlatforms(const byte * resourcePointer, size_t resourceLength);
|
|
|
|
void loadMetaTiles(const byte * resourcePointer, size_t resourceLength);
|
|
|
|
void loadMulti(const byte * resourcePointer, size_t resourceLength);
|
|
|
|
void freeMem();
|
2005-07-09 16:23:45 +00:00
|
|
|
void draw(Surface *ds);
|
|
|
|
void drawSprite(Surface *ds, SpriteList &spriteList, int spriteNumber, const Location &location, const Point &screenPosition, int scale);
|
2005-02-18 00:00:00 +00:00
|
|
|
void adjustScroll(bool jump);
|
|
|
|
void tileCoordsToScreenPoint(const Location &location, Point &position) {
|
|
|
|
position.x = location.u() - location.v() + (128 * SAGA_TILEMAP_W) - _viewScroll.x + 16;
|
2005-03-13 17:43:50 +00:00
|
|
|
position.y = -(location.uv() >> 1) + (128 * SAGA_TILEMAP_W) - _viewScroll.y - location.z;
|
2005-02-18 00:00:00 +00:00
|
|
|
}
|
2005-02-26 17:37:16 +00:00
|
|
|
void screenPointToTileCoords(const Point &position, Location &location);
|
2005-02-26 11:44:30 +00:00
|
|
|
void placeOnTileMap(const Location &start, Location &result, int16 distance, uint16 direction);
|
2005-06-29 20:00:44 +00:00
|
|
|
void findDragonTilePath(ActorData* actor, const Location &start, const Location &end, uint16 initialDirection);
|
2005-07-01 17:29:23 +00:00
|
|
|
bool findNearestChasm(int16 &u0, int16 &v0, uint16 &direction);
|
2005-02-26 17:37:16 +00:00
|
|
|
void findTilePath(ActorData* actor, const Location &start, const Location &end);
|
|
|
|
bool nextTileTarget(ActorData* actor);
|
2005-04-03 15:32:04 +00:00
|
|
|
void setTileDoorState(int doorNumber, int doorState);
|
2005-04-21 01:30:07 +00:00
|
|
|
Point getMapPosition() { return _mapPosition; }
|
2005-04-22 01:38:27 +00:00
|
|
|
void setMapPosition(int x, int y);
|
2005-07-01 17:29:23 +00:00
|
|
|
int16 getTileIndex(int16 u, int16 v, int16 z);
|
2005-04-03 15:32:04 +00:00
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
private:
|
2005-07-09 16:23:45 +00:00
|
|
|
void drawTiles(Surface *ds, const Location *location);
|
|
|
|
void drawMetaTile(Surface *ds, uint16 metaTileIndex, const Point &point, int16 absU, int16 absV);
|
|
|
|
void drawSpriteMetaTile(Surface *ds, uint16 metaTileIndex, const Point &point, Location &location, int16 absU, int16 absV);
|
2005-07-30 21:11:48 +00:00
|
|
|
void drawPlatform(Surface *ds, uint16 platformIndex, const Point &point, int16 absU, int16 absV, int16 absH);
|
|
|
|
void drawSpritePlatform(Surface *ds, uint16 platformIndex, const Point &point, const Location &location, int16 absU, int16 absV, int16 absH);
|
2005-07-09 16:23:45 +00:00
|
|
|
void drawTile(Surface *ds, uint16 tileIndex, const Point &point, const Location *location);
|
2005-02-18 00:00:00 +00:00
|
|
|
int16 smoothSlide(int16 value, int16 min, int16 max) {
|
|
|
|
if (value < min) {
|
|
|
|
if (value < min - 100 || value > min - 4) {
|
|
|
|
value = min;
|
|
|
|
} else {
|
|
|
|
value += 4;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (value > max) {
|
|
|
|
if (value > max + 100 || value < max + 4) {
|
|
|
|
value = max;
|
|
|
|
} else {
|
|
|
|
value -= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
2005-07-30 21:11:48 +00:00
|
|
|
}
|
2005-02-26 11:44:30 +00:00
|
|
|
int16 findMulti(int16 tileIndex, int16 absU, int16 absV, int16 absH);
|
|
|
|
void pushPoint(int16 u, int16 v, uint16 cost, uint16 direction);
|
2005-06-29 20:00:44 +00:00
|
|
|
void pushDragonPoint(int16 u, int16 v, uint16 direction);
|
|
|
|
bool checkDragonPoint(int16 u, int16 v, uint16 direction);
|
2005-02-26 11:44:30 +00:00
|
|
|
void testPossibleDirections(int16 u, int16 v, uint16 terraComp[8], int skipCenter);
|
|
|
|
IsoTileData *getTile(int16 u, int16 v, int16 z);
|
2005-02-22 20:18:55 +00:00
|
|
|
|
2005-02-09 20:30:45 +00:00
|
|
|
|
2005-01-28 19:25:41 +00:00
|
|
|
byte *_tileData;
|
2005-07-30 21:11:48 +00:00
|
|
|
size_t _tileDataLength;
|
2005-01-28 19:25:41 +00:00
|
|
|
uint16 _tilesCount;
|
|
|
|
IsoTileData *_tilesTable;
|
|
|
|
|
|
|
|
uint16 _tilePlatformsCount;
|
|
|
|
TilePlatformData *_tilePlatformList;
|
|
|
|
uint16 _metaTilesCount;
|
|
|
|
MetaTileData *_metaTileList;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-01-28 19:25:41 +00:00
|
|
|
uint16 _multiCount;
|
|
|
|
MultiTileEntryData *_multiTable;
|
2005-02-22 20:18:55 +00:00
|
|
|
uint16 _multiDataCount;
|
|
|
|
int16 *_multiTableData;
|
2005-01-28 19:25:41 +00:00
|
|
|
|
|
|
|
TileMapData _tileMap;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-02-18 00:00:00 +00:00
|
|
|
Point _mapPosition;
|
2005-02-26 11:44:30 +00:00
|
|
|
|
|
|
|
// path finding stuff
|
|
|
|
uint16 _platformHeight;
|
|
|
|
|
2005-06-29 20:00:44 +00:00
|
|
|
struct DragonPathCell {
|
2005-09-03 14:49:43 +00:00
|
|
|
uint8 visited:1,direction:3;
|
2005-06-29 20:00:44 +00:00
|
|
|
};
|
|
|
|
struct DragonTilePoint {
|
|
|
|
int8 u, v;
|
2005-09-03 14:49:43 +00:00
|
|
|
uint8 direction:4;
|
2005-06-29 20:00:44 +00:00
|
|
|
};
|
2005-02-26 11:44:30 +00:00
|
|
|
struct PathCell {
|
|
|
|
uint16 visited:1,direction:3,cost:12;
|
|
|
|
};
|
|
|
|
|
2005-02-11 20:43:48 +00:00
|
|
|
public:
|
2005-02-26 11:44:30 +00:00
|
|
|
struct TilePoint {
|
|
|
|
int8 u, v;
|
|
|
|
uint16 direction:4,cost:12;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2005-06-29 20:00:44 +00:00
|
|
|
struct DragonSearchArray {
|
|
|
|
DragonPathCell cell[SAGA_DRAGON_SEARCH_DIAMETER][SAGA_DRAGON_SEARCH_DIAMETER];
|
|
|
|
DragonTilePoint queue[SAGA_SEARCH_QUEUE_SIZE];
|
|
|
|
DragonTilePoint *getQueue(uint16 i) {
|
|
|
|
assert(i < SAGA_SEARCH_QUEUE_SIZE);
|
|
|
|
return &queue[i];
|
|
|
|
}
|
|
|
|
DragonPathCell *getPathCell(uint16 u, uint16 v) {
|
|
|
|
assert((u < SAGA_DRAGON_SEARCH_DIAMETER) && (v < SAGA_DRAGON_SEARCH_DIAMETER));
|
|
|
|
return &cell[u][v];
|
|
|
|
}
|
|
|
|
};
|
2005-02-26 11:44:30 +00:00
|
|
|
struct SearchArray {
|
|
|
|
PathCell cell[SAGA_SEARCH_DIAMETER][SAGA_SEARCH_DIAMETER];
|
|
|
|
TilePoint queue[SAGA_SEARCH_QUEUE_SIZE];
|
|
|
|
TilePoint *getQueue(uint16 i) {
|
|
|
|
assert(i < SAGA_SEARCH_QUEUE_SIZE);
|
|
|
|
return &queue[i];
|
|
|
|
}
|
|
|
|
PathCell *getPathCell(uint16 u, uint16 v) {
|
|
|
|
assert((u < SAGA_SEARCH_DIAMETER) && (v < SAGA_SEARCH_DIAMETER));
|
|
|
|
return &cell[u][v];
|
|
|
|
}
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-02-26 11:44:30 +00:00
|
|
|
int16 _queueCount;
|
2005-06-29 20:00:44 +00:00
|
|
|
int16 _readCount;
|
2005-02-26 11:44:30 +00:00
|
|
|
SearchArray _searchArray;
|
2005-06-29 20:00:44 +00:00
|
|
|
DragonSearchArray _dragonSearchArray;
|
2005-02-26 17:37:16 +00:00
|
|
|
byte _pathDirections[SAGA_MAX_PATH_DIRECTIONS];
|
|
|
|
|
2005-02-26 11:44:30 +00:00
|
|
|
|
2005-02-11 20:43:48 +00:00
|
|
|
int _viewDiff;
|
2005-02-09 20:30:45 +00:00
|
|
|
Point _viewScroll;
|
2005-02-11 20:43:48 +00:00
|
|
|
Rect _tileClip;
|
2005-01-28 19:25:41 +00:00
|
|
|
|
|
|
|
SagaEngine *_vm;
|
2004-04-25 14:42:14 +00:00
|
|
|
};
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
} // End of namespace Saga
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
#endif
|