Skip to content
Browse files

Add support for Catacomb and Catacomb II tilesets

  • Loading branch information...
1 parent 3e63337 commit ce76464828c03de6dce4bbbf91893c8add794754 @Malvineous committed Apr 29, 2012
Showing with 466 additions and 1 deletion.
  1. +1 −0 README
  2. +2 −0 src/Makefile.am
  3. +4 −1 src/main.cpp
  4. +312 −0 src/tls-catacomb.cpp
  5. +147 −0 src/tls-catacomb.hpp
View
1 README
@@ -24,6 +24,7 @@ use any external palette data.
This library is still in the preliminary stages, so only the following formats
have been implemented:
+ * Catacomb/Catacomb II (tiles)
* Captain Comic (tiles, sprites and fullscreen images)
* Cosmo's Cosmic Adventures (tiles)
* Crystal Caves (tiles)
View
2 src/Makefile.am
@@ -23,6 +23,7 @@ libgamegraphics_la_SOURCES += pal-gmf-harry.cpp
libgamegraphics_la_SOURCES += subimage.cpp
libgamegraphics_la_SOURCES += tileset-fat.cpp
libgamegraphics_la_SOURCES += tls-bash.cpp
+libgamegraphics_la_SOURCES += tls-catacomb.cpp
libgamegraphics_la_SOURCES += tls-ccaves-sub.cpp
libgamegraphics_la_SOURCES += tls-ccaves-main.cpp
libgamegraphics_la_SOURCES += tls-ccomic.cpp
@@ -56,6 +57,7 @@ EXTRA_libgamegraphics_la_SOURCES += pal-gmf-harry.hpp
EXTRA_libgamegraphics_la_SOURCES += subimage.hpp
EXTRA_libgamegraphics_la_SOURCES += tileset-fat.hpp
EXTRA_libgamegraphics_la_SOURCES += tls-bash.hpp
+EXTRA_libgamegraphics_la_SOURCES += tls-catacomb.hpp
EXTRA_libgamegraphics_la_SOURCES += tls-ccaves-sub.hpp
EXTRA_libgamegraphics_la_SOURCES += tls-ccaves-main.hpp
EXTRA_libgamegraphics_la_SOURCES += tls-ccomic.hpp
View
5 src/main.cpp
@@ -2,7 +2,7 @@
* @file main.cpp
* @brief Entry point for libgamegraphics.
*
- * Copyright (C) 2010-2011 Adam Nielsen <malvineous@shikadi.net>
+ * Copyright (C) 2010-2012 Adam Nielsen <malvineous@shikadi.net>
*
* 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
@@ -24,6 +24,7 @@
// Include all the file formats for the Manager to load
#include "tls-bash.hpp"
+#include "tls-catacomb.hpp"
#include "tls-ccaves-sub.hpp"
#include "tls-ccaves-main.hpp"
#include "tls-ccomic.hpp"
@@ -59,6 +60,8 @@ Manager::Manager()
{
this->vcTilesetTypes.push_back(TilesetTypePtr(new MonsterBashBackgroundTilesetType()));
this->vcTilesetTypes.push_back(TilesetTypePtr(new MonsterBashForegroundTilesetType()));
+ this->vcTilesetTypes.push_back(TilesetTypePtr(new CatacombCGATilesetType()));
+ this->vcTilesetTypes.push_back(TilesetTypePtr(new CatacombEGATilesetType()));
this->vcTilesetTypes.push_back(TilesetTypePtr(new CCavesMainTilesetType()));
this->vcTilesetTypes.push_back(TilesetTypePtr(new CCavesSubTilesetType()));
this->vcTilesetTypes.push_back(TilesetTypePtr(new CComicSpriteType()));
View
312 src/tls-catacomb.cpp
@@ -0,0 +1,312 @@
+/**
+ * @file tls-catacomb.cpp
+ * @brief Catacomb/Catacomb II CGA and EGA tilesets
+ *
+ * This file format is fully documented on the ModdingWiki:
+ * http://www.shikadi.net/moddingwiki/Catacomb_Tileset_Format
+ *
+ * Copyright (C) 2010-2012 Adam Nielsen <malvineous@shikadi.net>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <camoto/iostream_helpers.hpp>
+#include "img-ega-planar.hpp"
+#include "img-cga.hpp"
+#include "tls-catacomb.hpp"
+
+namespace camoto {
+namespace gamegraphics {
+
+/// Offset of first tileset in a tileset collection.
+#define CAT_FIRST_TILE_OFFSET 0
+
+#define CAT_TILE_WIDTH 8
+#define CAT_TILE_HEIGHT 8
+
+/// Number of bytes per tile in the CGA tileset
+#define CAT_CGA_TILESIZE 16
+
+/// Number of bytes per tile in the EGA tileset
+#define CAT_EGA_TILESIZE 32
+
+/// Number of planes per tile
+#define CAT_NUMPLANES 4
+
+/// Number of tiles in the Catacomb I tileset
+#define CATI_NUMTILES 1462
+
+/// Number of tiles in the Catacomb II tileset
+#define CATII_NUMTILES 1618
+
+CatacombTilesetType::CatacombTilesetType()
+ throw ()
+{
+}
+
+CatacombTilesetType::~CatacombTilesetType()
+ throw ()
+{
+}
+
+std::vector<std::string> CatacombTilesetType::getFileExtensions() const
+ throw ()
+{
+ std::vector<std::string> vcExtensions;
+ vcExtensions.push_back("cat");
+ vcExtensions.push_back("ca2");
+ return vcExtensions;
+}
+
+std::vector<std::string> CatacombTilesetType::getGameList() const
+ throw ()
+{
+ std::vector<std::string> vcGames;
+ vcGames.push_back("Catacomb");
+ vcGames.push_back("Catacomb II");
+ return vcGames;
+}
+
+SuppFilenames CatacombTilesetType::getRequiredSupps(const std::string& filenameGraphics) const
+ throw ()
+{
+ // No supplemental types/empty list
+ return SuppFilenames();
+}
+
+
+//
+// CatacombEGATilesetType
+//
+
+CatacombEGATilesetType::CatacombEGATilesetType()
+ throw ()
+{
+}
+
+CatacombEGATilesetType::~CatacombEGATilesetType()
+ throw ()
+{
+}
+
+std::string CatacombEGATilesetType::getCode() const
+ throw ()
+{
+ return "tls-catacomb-ega";
+}
+
+std::string CatacombEGATilesetType::getFriendlyName() const
+ throw ()
+{
+ return "Catacomb EGA Tileset";
+}
+
+CatacombEGATilesetType::Certainty CatacombEGATilesetType::isInstance(stream::input_sptr psGraphics) const
+ throw (stream::error)
+{
+ stream::pos len = psGraphics->size();
+
+ // Catacomb I
+ if (len == CATI_NUMTILES * CAT_EGA_TILESIZE) return PossiblyYes;
+
+ // Catacomb II
+ if (len == CATII_NUMTILES * CAT_EGA_TILESIZE) return PossiblyYes;
+
+ return DefinitelyNo;
+}
+
+TilesetPtr CatacombEGATilesetType::create(stream::inout_sptr psGraphics,
+ SuppData& suppData) const
+ throw (stream::error)
+{
+ psGraphics->seekp(0, stream::start);
+ // Zero tiles, 0x0
+ return TilesetPtr(new CatacombTileset(psGraphics, CAT_EGA));
+}
+
+TilesetPtr CatacombEGATilesetType::open(stream::inout_sptr psGraphics,
+ SuppData& suppData) const
+ throw (stream::error)
+{
+ return TilesetPtr(new CatacombTileset(psGraphics, CAT_EGA));
+}
+
+
+//
+// CatacombCGATilesetType
+//
+
+CatacombCGATilesetType::CatacombCGATilesetType()
+ throw ()
+{
+}
+
+CatacombCGATilesetType::~CatacombCGATilesetType()
+ throw ()
+{
+}
+
+std::string CatacombCGATilesetType::getCode() const
+ throw ()
+{
+ return "tls-catacomb-cga";
+}
+
+std::string CatacombCGATilesetType::getFriendlyName() const
+ throw ()
+{
+ return "Catacomb CGA Tileset";
+}
+
+CatacombCGATilesetType::Certainty CatacombCGATilesetType::isInstance(stream::input_sptr psGraphics) const
+ throw (stream::error)
+{
+ stream::pos len = psGraphics->size();
+
+ // Catacomb I
+ if (len == CATI_NUMTILES * CAT_CGA_TILESIZE) return PossiblyYes;
+
+ // Catacomb II
+ if (len == CATII_NUMTILES * CAT_CGA_TILESIZE) return PossiblyYes;
+
+ return DefinitelyNo;
+}
+
+TilesetPtr CatacombCGATilesetType::create(stream::inout_sptr psGraphics,
+ SuppData& suppData) const
+ throw (stream::error)
+{
+ psGraphics->seekp(0, stream::start);
+ // Zero tiles, 0x0
+ return TilesetPtr(new CatacombTileset(psGraphics, CAT_CGA));
+}
+
+TilesetPtr CatacombCGATilesetType::open(stream::inout_sptr psGraphics,
+ SuppData& suppData) const
+ throw (stream::error)
+{
+ return TilesetPtr(new CatacombTileset(psGraphics, CAT_CGA));
+}
+
+
+//
+// CatacombTileset
+//
+
+CatacombTileset::CatacombTileset(stream::inout_sptr data,
+ CatacombImageType imageType)
+ throw (stream::error)
+ : FATTileset(data, CAT_FIRST_TILE_OFFSET),
+ imageType(imageType)
+{
+ unsigned int tileSize;
+ switch (this->imageType) {
+ case CAT_EGA: tileSize = CAT_EGA_TILESIZE; break;
+ case CAT_CGA: tileSize = CAT_CGA_TILESIZE; break;
+ }
+ stream::pos len = this->data->size();
+
+ this->data->seekg(0, stream::start);
+ int numImages = len / tileSize;
+
+ this->items.reserve(numImages);
+ for (int i = 0; i < numImages; i++) {
+ FATEntry *fat = new FATEntry();
+ EntryPtr ep(fat);
+ fat->isValid = true;
+ fat->attr = 0;
+ fat->index = i;
+ fat->offset = i * tileSize;
+ fat->size = tileSize;
+ fat->lenHeader = 0;
+ this->items.push_back(ep);
+ }
+
+}
+
+CatacombTileset::~CatacombTileset()
+ throw ()
+{
+}
+
+int CatacombTileset::getCaps()
+ throw ()
+{
+ return 0;
+}
+
+void CatacombTileset::resize(EntryPtr& id, stream::len newSize)
+ throw (stream::error)
+{
+ unsigned int tileSize;
+ switch (this->imageType) {
+ case CAT_EGA: tileSize = CAT_EGA_TILESIZE; break;
+ case CAT_CGA: tileSize = CAT_CGA_TILESIZE; break;
+ }
+ if (newSize != tileSize) {
+ throw stream::error("tiles in this tileset are a fixed size");
+ }
+ return;
+}
+
+void CatacombTileset::getTilesetDimensions(unsigned int *width, unsigned int *height)
+ throw ()
+{
+ *width = CAT_TILE_WIDTH;
+ *height = CAT_TILE_HEIGHT;
+ return;
+}
+
+unsigned int CatacombTileset::getLayoutWidth()
+ throw ()
+{
+ return 2;
+}
+
+ImagePtr CatacombTileset::createImageInstance(const EntryPtr& id,
+ stream::inout_sptr content)
+ throw (stream::error)
+{
+ ImagePtr conv;
+ switch (this->imageType) {
+ case CAT_EGA: {
+ PLANE_LAYOUT planes;
+ planes[PLANE_BLUE] = 1;
+ planes[PLANE_GREEN] = 2;
+ planes[PLANE_RED] = 3;
+ planes[PLANE_INTENSITY] = 4;
+ planes[PLANE_HITMAP] = 0;
+ planes[PLANE_OPACITY] = 0;
+
+ EGAPlanarImage *ega = new EGAPlanarImage();
+ ega->setParams(
+ content, 0, CAT_TILE_WIDTH, CAT_TILE_HEIGHT, planes
+ );
+
+ conv.reset(ega);
+ break;
+ }
+ case CAT_CGA: {
+ CGAImage *cga = new CGAImage(content, 0, CAT_TILE_WIDTH, CAT_TILE_HEIGHT,
+ CGAImage::CyanMagentaBright);
+ conv.reset(cga);
+ break;
+ }
+ }
+ assert(conv);
+ return conv;
+}
+
+} // namespace gamegraphics
+} // namespace camoto
View
147 src/tls-catacomb.hpp
@@ -0,0 +1,147 @@
+/**
+ * @file tls-catacomb.hpp
+ * @brief Catacomb/Catacomb II CGA and EGA tilesets
+ *
+ * Copyright (C) 2010-2012 Adam Nielsen <malvineous@shikadi.net>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _CAMOTO_TLS_CATACOMB_HPP_
+#define _CAMOTO_TLS_CATACOMB_HPP_
+
+#include <camoto/gamegraphics/tilesettype.hpp>
+#include "tileset-fat.hpp"
+
+namespace camoto {
+namespace gamegraphics {
+
+/// Flag for tileset image type.
+enum CatacombImageType {
+ CAT_CGA = 0,
+ CAT_EGA = 1
+};
+
+/// Common code for Catacomb tilesets.
+class CatacombTilesetType: virtual public TilesetType
+{
+ public:
+ CatacombTilesetType()
+ throw ();
+
+ virtual ~CatacombTilesetType()
+ throw ();
+
+ virtual std::vector<std::string> getFileExtensions() const
+ throw ();
+
+ virtual std::vector<std::string> getGameList() const
+ throw ();
+
+ virtual SuppFilenames getRequiredSupps(const std::string& filenameGraphics) const
+ throw ();
+};
+
+/// CGA-specific code for Catacomb tilesets.
+class CatacombCGATilesetType: virtual public CatacombTilesetType
+{
+ public:
+ CatacombCGATilesetType()
+ throw ();
+
+ virtual ~CatacombCGATilesetType()
+ throw ();
+
+ virtual std::string getCode() const
+ throw ();
+
+ virtual std::string getFriendlyName() const
+ throw ();
+
+ virtual Certainty isInstance(stream::input_sptr fsGraphics) const
+ throw (stream::error);
+
+ virtual TilesetPtr create(stream::inout_sptr psGraphics,
+ SuppData& suppData) const
+ throw (stream::error);
+
+ virtual TilesetPtr open(stream::inout_sptr fsGraphics,
+ SuppData& suppData) const
+ throw (stream::error);
+};
+
+/// EGA-specific code for Catacomb tilesets.
+class CatacombEGATilesetType: virtual public CatacombTilesetType
+{
+ public:
+ CatacombEGATilesetType()
+ throw ();
+
+ virtual ~CatacombEGATilesetType()
+ throw ();
+
+ virtual std::string getCode() const
+ throw ();
+
+ virtual std::string getFriendlyName() const
+ throw ();
+
+ virtual Certainty isInstance(stream::input_sptr fsGraphics) const
+ throw (stream::error);
+
+ virtual TilesetPtr create(stream::inout_sptr psGraphics,
+ SuppData& suppData) const
+ throw (stream::error);
+
+ virtual TilesetPtr open(stream::inout_sptr fsGraphics,
+ SuppData& suppData) const
+ throw (stream::error);
+};
+
+/// Tileset format handler.
+class CatacombTileset: virtual public FATTileset
+{
+ public:
+ CatacombTileset(stream::inout_sptr data, CatacombImageType imageType)
+ throw (stream::error);
+
+ virtual ~CatacombTileset()
+ throw ();
+
+ virtual int getCaps()
+ throw ();
+
+ void resize(EntryPtr& id, stream::len newSize)
+ throw (stream::error);
+
+ virtual void getTilesetDimensions(unsigned int *width, unsigned int *height)
+ throw ();
+
+ virtual unsigned int getLayoutWidth()
+ throw ();
+
+ // FATTileset
+
+ virtual ImagePtr createImageInstance(const EntryPtr& id,
+ stream::inout_sptr content)
+ throw (stream::error);
+
+ protected:
+ CatacombImageType imageType;
+};
+
+} // namespace gamegraphics
+} // namespace camoto
+
+#endif // _CAMOTO_TLS_CATACOMB_HPP_

0 comments on commit ce76464

Please sign in to comment.
Something went wrong with that request. Please try again.