summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/graphic/graphic.cpp41
-rw-r--r--src/graphic/graphic.h2
-rw-r--r--src/gui/window.cpp2
-rw-r--r--src/map.cpp116
-rw-r--r--src/map.h40
-rw-r--r--src/resources/mapreader.cpp10
7 files changed, 112 insertions, 101 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f7a8cfbb..696cc366 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -106,6 +106,6 @@ INCLUDES= $(all_includes)
# the library search path.
tmw_LDFLAGS = $(all_libraries) $(LIBSDL_RPATH) -lguichan_sdl -lguichan `pkg-config --libs libxml-2.0`
-tmw_CXXFLAGS = $(LIBSDL_CFLAGS) `pkg-config --cflags libxml-2.0`
+tmw_CXXFLAGS = -Wall $(LIBSDL_CFLAGS) `pkg-config --cflags libxml-2.0`
tmw_LDADD = $(LIBSDL_LIBS) -lguichan_opengl -lguichan -lGL -lphysfs
tmw_TARGET = ../tmw
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index 2e681fb0..9fdda40b 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -307,12 +307,12 @@ Engine::Engine()
statsWindow->setPosition(
screen->w - 5 - statsWindow->getWidth(),
statusWindow->getHeight() + 20);
-
+
setupWindow = new Setup();
setupWindow->setVisible(false);
-
+
minimap = new Minimap();
-
+
equipmentWindow = new EquipmentWindow();
equipmentWindow->setVisible(false);
@@ -325,19 +325,15 @@ Engine::Engine()
"core/graphics/sprites/npcs.png");
Image *emotionbmp = resman->getImage(
"core/graphics/sprites/emotions.png");
- Image *tilesetbmp = resman->getImage(
- "core/graphics/tiles/desert.png");
Image *monsterbitmap = resman->getImage(
"core/graphics/sprites/monsters.png");
if (!npcbmp) error("Unable to load npcs.png");
if (!emotionbmp) error("Unable to load emotions.png");
- if (!tilesetbmp) error("Unable to load desert.png");
if (!monsterbitmap) error("Unable to load monsters.png");
npcset = new Spriteset(npcbmp, 50, 80);
emotionset = new Spriteset(emotionbmp, 19, 19);
- tileset = new Spriteset(tilesetbmp, 32, 32);
monsterset = new Spriteset(monsterbitmap, 60, 60);
}
@@ -355,8 +351,7 @@ Engine::~Engine()
delete setupWindow;
delete minimap;
delete equipmentWindow;
-
- delete tileset;
+
delete monsterset;
delete npcset;
delete emotionset;
@@ -384,21 +379,18 @@ void Engine::draw()
// Draw tiles below nodes
for (int j = 0; j < 20; j++) {
for (int i = 0; i < 26; i++) {
- int tile0 = tiledMap.getTile(i + camera_x, j + camera_y, 0);
- int tile1 = tiledMap.getTile(i + camera_x, j + camera_y, 1);
+ Image *tile0 = tiledMap.getTile(i + camera_x, j + camera_y, 0);
+ Image *tile1 = tiledMap.getTile(i + camera_x, j + camera_y, 1);
- if (tile0 < (int)tileset->spriteset.size()) {
- tileset->spriteset[tile0]->draw(screen,
- i * 32 - offset_x, j * 32 - offset_y);
+ if (tile0) {
+ tile0->draw(screen, i * 32 - offset_x, j * 32 - offset_y);
}
- if (tile1 > 0 && tile1 < (int)tileset->spriteset.size()) {
- tileset->spriteset[tile1]->draw(screen,
- i * 32 - offset_x, j * 32 - offset_y);
+ if (tile1) {
+ tile1->draw(screen, i * 32 - offset_x, j * 32 - offset_y);
}
-
}
}
-
+
// Draw nodes
std::list<Being*>::iterator beingIterator = beings.begin();
while (beingIterator != beings.end())
@@ -501,7 +493,7 @@ void Engine::draw()
}
}
}
-
+
if (being->action == MONSTER_DEAD && being->frame >= 20) {
delete being;
beingIterator = beings.erase(beingIterator);
@@ -517,11 +509,10 @@ void Engine::draw()
// Draw tiles above nodes
for (int j = 0; j < 20; j++) {
for (int i = 0; i < 26; i++) {
- int tile = tiledMap.getTile(i + camera_x, j + camera_y, 2);
+ Image *tile = tiledMap.getTile(i + camera_x, j + camera_y, 2);
- if (tile > 0 && tile < (int)tileset->spriteset.size()) {
- tileset->spriteset[tile]->draw(
- screen, i * 32 - offset_x, j * 32 - offset_y);
+ if (tile) {
+ tile->draw(screen, i * 32 - offset_x, j * 32 - offset_y);
#ifdef DEBUG
guiGraphics->setColor(gcn::Color(0, 0, 0));
@@ -547,7 +538,7 @@ void Engine::draw()
guiGraphics->setColor(gcn::Color(255, 0, 0));
guiGraphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8));
- Tile *tile = tiledMap.getTile(debugPath->x, debugPath->y);
+ MetaTile *tile = tiledMap.getMetaTile(debugPath->x, debugPath->y);
std::stringstream cost;
cost << tile->Gcost;
diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h
index 126cfcb4..36154464 100644
--- a/src/graphic/graphic.h
+++ b/src/graphic/graphic.h
@@ -169,7 +169,7 @@ class Graphics : public gcn::SDLGraphics {
*/
class Engine {
private:
- Spriteset *tileset, *emotionset, *npcset, *monsterset;
+ Spriteset *emotionset, *npcset, *monsterset;
public:
Engine();
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 83a0b283..c17e4c76 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -123,7 +123,7 @@ void Window::draw(gcn::Graphics* graphics)
// Draw title
graphics->setFont(getFont());
- graphics->drawText(caption, 4, 4, gcn::Graphics::LEFT);
+ graphics->drawText(caption, 7, 5, gcn::Graphics::LEFT);
drawChildren(graphics);
}
diff --git a/src/map.cpp b/src/map.cpp
index f172ad56..ee029af8 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -24,7 +24,8 @@
#include "main.h"
#include "map.h"
#include "log.h"
-#include "being.h"
+#include "resources/resourcemanager.h"
+#include "graphic/spriteset.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
@@ -70,13 +71,13 @@ struct MAP {
};
-Tile::Tile():
+MetaTile::MetaTile():
whichList(0)
{
}
-Location::Location(int x, int y, Tile *tile):
+Location::Location(int x, int y, MetaTile *tile):
x(x), y(y), tile(tile)
{
}
@@ -92,7 +93,8 @@ Map::Map():
tileWidth(32), tileHeight(32),
onClosedList(1), onOpenList(2)
{
- tiles = new Tile[width * height];
+ metaTiles = new MetaTile[width * height];
+ tiles = new Image*[width * height * 3];
}
Map::Map(int width, int height):
@@ -100,11 +102,13 @@ Map::Map(int width, int height):
tileWidth(32), tileHeight(32),
onClosedList(1), onOpenList(2)
{
- tiles = new Tile[width * height];
+ metaTiles = new MetaTile[width * height];
+ tiles = new Image*[width * height * 3];
}
Map::~Map()
{
+ delete[] metaTiles;
delete[] tiles;
}
@@ -123,29 +127,45 @@ bool Map::load(const std::string &mapFile)
setSize(OLD_MAP_WIDTH, OLD_MAP_HEIGHT);
+ // Load the default tileset
+ ResourceManager *resman = ResourceManager::getInstance();
+ Image *tilesetbmp = resman->getImage("core/graphics/tiles/desert.png");
+ if (!tilesetbmp) error("Unable to load desert.png");
+ Spriteset *tileset = new Spriteset(tilesetbmp, 32, 32);
+
// Transfer tile data
- int x, y;
+ int x, y, a;
for (y = 0; y < OLD_MAP_HEIGHT; y++) {
for (x = 0; x < OLD_MAP_WIDTH; x++) {
- unsigned short id;
-
- // Layer 0
- id = MAKEWORD(oldMap.tiles[x][y].data[1] & 0x00c0,
- oldMap.tiles[x][y].data[0]);
- id >>= 6;
- setTile(x, y, 0, id);
-
- // Layer 1
- id = MAKEWORD(oldMap.tiles[x][y].data[2] & 0x00f0,
- oldMap.tiles[x][y].data[1] & 0x003f);
- id >>= 4;
- setTile(x, y, 1, id);
-
- // Layer 2
- id = MAKEWORD(oldMap.tiles[x][y].data[3] & 0x00fc,
- oldMap.tiles[x][y].data[2] & 0x000f);
- id >>= 2;
- setTile(x, y, 2, id);
+ unsigned short id = 0;
+
+ for (a = 0; a < 3; a++) {
+ // Different interpretation for each layer
+ switch (a) {
+ case 0:
+ id = MAKEWORD(oldMap.tiles[x][y].data[1] & 0x00c0,
+ oldMap.tiles[x][y].data[0]);
+ id >>= 6;
+ break;
+ case 1:
+ id = MAKEWORD(oldMap.tiles[x][y].data[2] & 0x00f0,
+ oldMap.tiles[x][y].data[1] & 0x003f);
+ id >>= 4;
+ break;
+ case 2:
+ id = MAKEWORD(oldMap.tiles[x][y].data[3] & 0x00fc,
+ oldMap.tiles[x][y].data[2] & 0x000f);
+ id >>= 2;
+ break;
+ }
+
+ if (id < tileset->spriteset.size() && (a == 0 || id > 0)) {
+ setTile(x, y, a, tileset->spriteset[id]);
+ }
+ else {
+ setTile(x, y, a, NULL);
+ }
+ }
// Walkability
setWalk(x, y, (oldMap.tiles[x][y].data[3] & 0x0002) > 0);
@@ -173,21 +193,20 @@ void Map::setSize(int width, int height)
{
this->width = width;
this->height = height;
+ delete[] metaTiles;
delete[] tiles;
- tiles = new Tile[width * height];
+ metaTiles = new MetaTile[width * height];
+ tiles = new Image*[width * height * 3];
}
-void Map::setWalk(int x, int y, bool walkable) {
- if (walkable) {
- tiles[x + y * width].flags |= TILE_WALKABLE;
- }
- else {
- tiles[x + y * width].flags &= ~TILE_WALKABLE;
- }
+void Map::setWalk(int x, int y, bool walkable)
+{
+ metaTiles[x + y * width].walkable = walkable;
}
-bool Map::getWalk(int x, int y) {
- bool ret = (tiles[x + y * width].flags & TILE_WALKABLE) != 0;
+bool Map::getWalk(int x, int y)
+{
+ bool ret = metaTiles[x + y * width].walkable;
if (ret) {
// Check for colliding into a being
@@ -195,7 +214,7 @@ bool Map::getWalk(int x, int y) {
while (i != beings.end() && ret) {
Being *being = (*i);
if (being->x == x && being->y == y) {
- ret = false;
+ return false;
}
i++;
}
@@ -204,19 +223,19 @@ bool Map::getWalk(int x, int y) {
return ret;
}
-void Map::setTile(int x, int y, int layer, int id)
+void Map::setTile(int x, int y, int layer, Image *img)
{
- tiles[x + y * width].layers[layer] = id;
+ tiles[x + y * width + layer * (width * height)] = img;
}
-int Map::getTile(int x, int y, int layer)
+Image *Map::getTile(int x, int y, int layer)
{
- return tiles[x + y * width].layers[layer];
+ return tiles[x + y * width + layer * (width * height)];
}
-Tile *Map::getTile(int x, int y)
+MetaTile *Map::getMetaTile(int x, int y)
{
- return &tiles[x + y * width];
+ return &metaTiles[x + y * width];
}
int Map::getWidth()
@@ -248,7 +267,7 @@ PATH_NODE *Map::findPath(int startX, int startY, int destX, int destY)
if (!getWalk(destX, destY)) return NULL;
// Reset starting tile's G cost to 0
- Tile *startTile = getTile(startX, startY);
+ MetaTile *startTile = getMetaTile(startX, startY);
startTile->Gcost = 0;
// Add the start point to the open list
@@ -291,7 +310,7 @@ PATH_NODE *Map::findPath(int startX, int startY, int destX, int destY)
continue;
}
- Tile *newTile = getTile(x, y);
+ MetaTile *newTile = getMetaTile(x, y);
// Skip if the tile is on the closed list or is not walkable
if (newTile->whichList == onClosedList || !getWalk(x, y))
@@ -304,11 +323,10 @@ PATH_NODE *Map::findPath(int startX, int startY, int destX, int destY)
// walkable tiles.
if (dx != 0 && dy != 0)
{
- Tile *t1 = getTile(curr.x, curr.y + dy);
- Tile *t2 = getTile(curr.x + dx, curr.y);
+ MetaTile *t1 = getMetaTile(curr.x, curr.y + dy);
+ MetaTile *t2 = getMetaTile(curr.x + dx, curr.y);
- if ((t1->flags & TILE_WALKABLE) == 0 ||
- (t2->flags & TILE_WALKABLE) == 0)
+ if (!(t1->walkable && t2->walkable))
{
continue;
}
@@ -377,7 +395,7 @@ PATH_NODE *Map::findPath(int startX, int startY, int destX, int destY)
while (pathX != startX || pathY != startY)
{
// Find out the next parent
- Tile *tile = getTile(pathX, pathY);
+ MetaTile *tile = getMetaTile(pathX, pathY);
pathX = tile->parentX;
pathY = tile->parentY;
diff --git a/src/map.h b/src/map.h
index 4a131e37..ce5725da 100644
--- a/src/map.h
+++ b/src/map.h
@@ -25,30 +25,29 @@
#define _TMW_MAP_H
#include "being.h"
-
-// Tile flags
-#define TILE_WALKABLE 1
-#define TILE_ANIMATED 2
+#include "resources/image.h"
/**
- * A tile on a tile map.
+ * A meta tile stores additional information about a location on a tile map.
+ * This is information that doesn't need to be repeated for each tile in each
+ * layer of the map.
*/
-class Tile
+class MetaTile
{
public:
/**
* Constructor.
*/
- Tile();
-
- // Tile data
- int layers[3];
- char flags;
+ MetaTile();
// Pathfinding members
- int Fcost, Gcost, Hcost;
- int whichList;
- int parentX, parentY;
+ int Fcost; /**< Estimation of total path cost */
+ int Gcost; /**< Cost from start to this location */
+ int Hcost; /**< Estimated cost to goal */
+ int whichList; /**< No list, open list or closed list */
+ int parentX; /**< X coordinate of parent tile */
+ int parentY; /**< Y coordinate of parent tile */
+ bool walkable; /**< Can beings walk on this tile */
};
/**
@@ -60,7 +59,7 @@ class Location
/**
* Constructor.
*/
- Location(int x, int y, Tile *tile);
+ Location(int x, int y, MetaTile *tile);
/**
* Comparison operator.
@@ -68,7 +67,7 @@ class Location
bool operator< (const Location &loc) const;
int x, y;
- Tile *tile;
+ MetaTile *tile;
};
/**
@@ -110,17 +109,17 @@ class Map
/**
* Set tile ID.
*/
- void setTile(int x, int y, int layer, int id);
+ void setTile(int x, int y, int layer, Image *img);
/**
* Get tile ID.
*/
- int getTile(int x, int y, int layer);
+ Image *getTile(int x, int y, int layer);
/**
* Get tile reference.
*/
- Tile *getTile(int x, int y);
+ MetaTile *getMetaTile(int x, int y);
/**
* Set walkability flag for a tile
@@ -160,7 +159,8 @@ class Map
private:
int width, height;
int tileWidth, tileHeight;
- Tile *tiles;
+ MetaTile *metaTiles;
+ Image **tiles;
// Pathfinding members
int onClosedList, onOpenList;
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 031188c1..a3f42829 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -88,8 +88,9 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path)
int w = getProperty(node, "width", 0);
int h = getProperty(node, "height", 0);
- int tilew = getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH);
- int tileh = getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT);
+ // We only support tile width of 32 at the moment
+ //int tilew = getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH);
+ //int tileh = getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT);
int layerNr = 0;
Map* map = new Map(w, h);
@@ -124,8 +125,9 @@ void MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
{
if (xmlStrEqual(node->name, BAD_CAST "tile") && y < h)
{
- int gid = getProperty(node, "gid", -1);
- map->setTile(x, y, layer, (gid > -1) ? gid : 0);
+ //int gid = getProperty(node, "gid", -1);
+ // TODO: Convert gid to Image* and set the tile
+ //map->setTile(x, y, layer, (gid > -1) ? gid : 0);
x++;
if (x == w) {x = 0; y++;}