2004-04-12 21:40:49 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2005 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Isometric level module
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/gfx.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/isomap.h"
|
2004-12-15 00:24:12 +00:00
|
|
|
#include "saga/stream.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
IsoMap::IsoMap(Gfx *gfx) {
|
|
|
|
_gfx = gfx;
|
|
|
|
_init = 1;
|
2004-10-09 07:39:46 +00:00
|
|
|
_tiles_loaded = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
int IsoMap::loadTileset(const byte *tileres_p, size_t tileres_len) {
|
2004-10-27 21:32:28 +00:00
|
|
|
ISOTILE_ENTRY first_entry;
|
|
|
|
ISOTILE_ENTRY *tile_tbl;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 i;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
assert((_init) && (!_tiles_loaded));
|
2004-04-12 21:40:49 +00:00
|
|
|
assert((tileres_p != NULL) && (tileres_len > 0));
|
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
MemoryReadStreamEndian readS(tileres_p, tileres_len, IS_BIG_ENDIAN);
|
2004-05-04 03:33:03 +00:00
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
readS.readUint16(); // skip
|
|
|
|
first_entry.tile_offset = readS.readUint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
_tile_ct = first_entry.tile_offset / SAGA_ISOTILE_ENTRY_LEN;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-01 10:02:41 +00:00
|
|
|
readS.seek(0);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
tile_tbl = (ISOTILE_ENTRY *)malloc(_tile_ct * sizeof *tile_tbl);
|
2004-04-12 21:40:49 +00:00
|
|
|
if (tile_tbl == NULL) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return MEM;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
for (i = 0; i < _tile_ct; i++) {
|
2004-08-01 10:02:41 +00:00
|
|
|
tile_tbl[i].tile_h = readS.readByte();
|
2004-10-28 07:31:16 +00:00
|
|
|
tile_tbl[i].mask_rule = readS.readByte();
|
2004-12-15 00:24:12 +00:00
|
|
|
tile_tbl[i].tile_offset = readS.readUint16();
|
|
|
|
tile_tbl[i].terrain_mask = readS.readSint16();
|
|
|
|
tile_tbl[i].mask = readS.readSint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
_tiles_loaded = 1;
|
|
|
|
_tile_tbl = tile_tbl;
|
|
|
|
_tileres_p = tileres_p;
|
|
|
|
_tileres_len = tileres_len;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
int IsoMap::loadMetaTileset(const byte *mtileres_p, size_t mtileres_len) {
|
2004-10-27 21:32:28 +00:00
|
|
|
ISO_METATILE_ENTRY *mtile_tbl;
|
2004-04-30 23:02:23 +00:00
|
|
|
uint16 mtile_ct;
|
|
|
|
uint16 ct;
|
2004-04-12 21:40:49 +00:00
|
|
|
int i;
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
assert(_init);
|
2004-04-12 21:40:49 +00:00
|
|
|
assert((mtileres_p != NULL) && (mtileres_len > 0));
|
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
MemoryReadStreamEndian readS(mtileres_p, mtileres_len, IS_BIG_ENDIAN);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
mtile_ct = mtileres_len / SAGA_METATILE_ENTRY_LEN;
|
2004-10-27 21:32:28 +00:00
|
|
|
mtile_tbl = (ISO_METATILE_ENTRY *)malloc(mtile_ct * sizeof *mtile_tbl);
|
2004-04-12 21:40:49 +00:00
|
|
|
if (mtile_tbl == NULL) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return MEM;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (ct = 0; ct < mtile_ct; ct++) {
|
2004-12-15 00:24:12 +00:00
|
|
|
mtile_tbl[ct].mtile_n = readS.readUint16();
|
|
|
|
mtile_tbl[ct].height = readS.readSint16();
|
|
|
|
mtile_tbl[ct].highest_pixel = readS.readSint16();
|
2004-10-30 10:31:00 +00:00
|
|
|
mtile_tbl[ct].v_bits = readS.readByte();
|
|
|
|
mtile_tbl[ct].u_bits = readS.readByte();
|
2004-04-12 21:40:49 +00:00
|
|
|
for (i = 0; i < SAGA_METATILE_SIZE; i++) {
|
2004-12-15 00:24:12 +00:00
|
|
|
mtile_tbl[ct].tile_tbl[i] = readS.readUint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
_mtile_ct = mtile_ct;
|
|
|
|
_mtile_tbl = mtile_tbl;
|
|
|
|
_mtileres_p = mtileres_p;
|
|
|
|
_mtileres_len = mtileres_len;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
_mtiles_loaded = 1;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
int IsoMap::loadMetamap(const byte *mm_res_p, size_t mm_res_len) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int i;
|
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
MemoryReadStreamEndian readS(mm_res_p, mm_res_len, IS_BIG_ENDIAN);
|
|
|
|
_metamap_n = readS.readSint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
for (i = 0; i < SAGA_METAMAP_SIZE; i++) {
|
2004-12-15 00:24:12 +00:00
|
|
|
_metamap_tbl[i] = readS.readUint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
_mm_res_p = mm_res_p;
|
|
|
|
_mm_res_len = mm_res_len;
|
|
|
|
_metamap_loaded = 1;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int IsoMap::draw(SURFACE *dst_s) {
|
|
|
|
GAME_DISPLAYINFO disp_info;
|
2004-12-22 13:09:47 +00:00
|
|
|
|
|
|
|
_vm->getDisplayInfo(&disp_info);
|
2004-10-22 07:21:17 +00:00
|
|
|
Rect iso_rect(disp_info.logical_w, disp_info.scene_h);
|
2004-10-30 22:34:08 +00:00
|
|
|
drawRect(dst_s, &iso_rect, 0);
|
2004-08-02 14:51:48 +00:00
|
|
|
drawMetamap(dst_s, -1000, -500);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int IsoMap::drawMetamap(SURFACE *dst_s, int map_x, int map_y) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int meta_base_x = map_x;
|
|
|
|
int meta_base_y = map_y;
|
|
|
|
int meta_xi;
|
|
|
|
int meta_yi;
|
|
|
|
int meta_x;
|
|
|
|
int meta_y;
|
|
|
|
int meta_idx;
|
|
|
|
|
|
|
|
for (meta_yi = SAGA_METAMAP_H - 1; meta_yi >= 0; meta_yi--) {
|
|
|
|
meta_x = meta_base_x;
|
|
|
|
meta_y = meta_base_y;
|
|
|
|
for (meta_xi = SAGA_METAMAP_W - 1; meta_xi >= 0; meta_xi--) {
|
|
|
|
meta_idx = meta_xi + (meta_yi * 16);
|
2004-08-02 14:51:48 +00:00
|
|
|
drawMetaTile(dst_s, _metamap_tbl[meta_idx], meta_x, meta_y);
|
2004-04-12 21:40:49 +00:00
|
|
|
meta_x += 128;
|
|
|
|
meta_y += 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_base_x -= 128;
|
|
|
|
meta_base_y += 64;
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int IsoMap::drawMetaTile(SURFACE *dst_s, uint16 mtile_i, int mtile_x, int mtile_y) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int tile_xi;
|
|
|
|
int tile_yi;
|
|
|
|
int tile_x;
|
|
|
|
int tile_y;
|
|
|
|
int tile_base_x;
|
|
|
|
int tile_base_y;
|
|
|
|
int tile_i;
|
2004-10-27 21:32:28 +00:00
|
|
|
ISO_METATILE_ENTRY *mtile_p;
|
2004-08-02 14:51:48 +00:00
|
|
|
assert(_init && _mtiles_loaded);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
if (mtile_i >= _mtile_ct) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
mtile_p = &_mtile_tbl[mtile_i];
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
tile_base_x = mtile_x;
|
|
|
|
tile_base_y = mtile_y;
|
|
|
|
|
|
|
|
for (tile_yi = SAGA_METATILE_H - 1; tile_yi >= 0; tile_yi--) {
|
|
|
|
tile_y = tile_base_y;
|
|
|
|
tile_x = tile_base_x;
|
|
|
|
for (tile_xi = SAGA_METATILE_W - 1; tile_xi >= 0; tile_xi--) {
|
|
|
|
tile_i = tile_xi + (tile_yi * SAGA_METATILE_W);
|
2004-08-02 14:51:48 +00:00
|
|
|
drawTile(dst_s, mtile_p->tile_tbl[tile_i], tile_x, tile_y);
|
2004-04-12 21:40:49 +00:00
|
|
|
tile_x += SAGA_ISOTILE_WIDTH / 2;
|
|
|
|
tile_y += SAGA_ISOTILE_BASEHEIGHT / 2 + 1;
|
|
|
|
}
|
|
|
|
tile_base_x -= SAGA_ISOTILE_WIDTH / 2;
|
|
|
|
tile_base_y += SAGA_ISOTILE_BASEHEIGHT / 2 + 1;
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
int IsoMap::drawTile(SURFACE *dst_s, uint16 tile_i, int tile_x, int tile_y) {
|
2004-04-30 23:02:23 +00:00
|
|
|
const byte *tile_p;
|
|
|
|
const byte *read_p;
|
|
|
|
byte *draw_p;
|
2004-04-12 21:40:49 +00:00
|
|
|
int draw_x;
|
|
|
|
int draw_y;
|
|
|
|
int tile_h;
|
|
|
|
int w_count = 0;
|
|
|
|
int row;
|
|
|
|
int bg_runct;
|
|
|
|
int fg_runct;
|
|
|
|
int ct;
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
assert(_init && _tiles_loaded);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
if (tile_i >= _tile_ct) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* temporary x clip */
|
|
|
|
if (tile_x < 0) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* temporary x clip */
|
|
|
|
if (tile_x >= 320 - 32) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-02 14:51:48 +00:00
|
|
|
tile_p = _tileres_p + _tile_tbl[tile_i].tile_offset;
|
|
|
|
tile_h = _tile_tbl[tile_i].tile_h;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
read_p = tile_p;
|
2004-10-30 22:13:48 +00:00
|
|
|
draw_p = (byte *)dst_s->pixels + tile_x + (tile_y * dst_s->pitch);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
draw_x = tile_x;
|
|
|
|
draw_y = tile_y;
|
|
|
|
|
|
|
|
if (tile_h > SAGA_ISOTILE_BASEHEIGHT) {
|
|
|
|
draw_y = tile_y - (tile_h - SAGA_ISOTILE_BASEHEIGHT);
|
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// temporary y clip
|
2004-04-12 21:40:49 +00:00
|
|
|
if (draw_y < 0) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (row = 0; row < tile_h; row++) {
|
2004-10-30 22:13:48 +00:00
|
|
|
draw_p = (byte *)dst_s->pixels + draw_x + ((draw_y + row) * dst_s->pitch);
|
2004-04-12 21:40:49 +00:00
|
|
|
w_count = 0;
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// temporary y clip
|
2004-04-12 21:40:49 +00:00
|
|
|
if ((draw_y + row) >= 137) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
bg_runct = *read_p++;
|
|
|
|
w_count += bg_runct;
|
|
|
|
if (w_count >= SAGA_ISOTILE_WIDTH) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_p += bg_runct;
|
|
|
|
fg_runct = *read_p++;
|
|
|
|
w_count += fg_runct;
|
|
|
|
|
|
|
|
for (ct = 0; ct < fg_runct; ct++) {
|
|
|
|
*draw_p++ = *read_p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|