Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add support for Rockford maps

  • Loading branch information...
commit 23c35af8bff90c23eda6f8a69167320e0e85ec50 1 parent c40f455
Adam Nielsen authored September 08, 2012
1  README
@@ -44,6 +44,7 @@ Editing maps for the following games are supported:
44 44
   * Hocus Pocus (partial)
45 45
   * Jill of the Jungle (partial)
46 46
   * Monster Bash (partial)
  47
+  * Rockford
47 48
   * Wacky Wheels
48 49
   * Word Rescue
49 50
   * Xargon (partial)
2  src/Makefile.am
@@ -9,6 +9,7 @@ libgamemaps_la_SOURCES += fmt-map-cosmo.cpp
9 9
 libgamemaps_la_SOURCES += fmt-map-ddave.cpp
10 10
 libgamemaps_la_SOURCES += fmt-map-harry.cpp
11 11
 libgamemaps_la_SOURCES += fmt-map-hocus.cpp
  12
+libgamemaps_la_SOURCES += fmt-map-rockford.cpp
12 13
 libgamemaps_la_SOURCES += fmt-map-wacky.cpp
13 14
 libgamemaps_la_SOURCES += fmt-map-wordresc.cpp
14 15
 libgamemaps_la_SOURCES += fmt-map-xargon.cpp
@@ -25,6 +26,7 @@ EXTRA_libgamemaps_la_SOURCES += fmt-map-cosmo.hpp
25 26
 EXTRA_libgamemaps_la_SOURCES += fmt-map-ddave.hpp
26 27
 EXTRA_libgamemaps_la_SOURCES += fmt-map-harry.hpp
27 28
 EXTRA_libgamemaps_la_SOURCES += fmt-map-hocus.hpp
  29
+EXTRA_libgamemaps_la_SOURCES += fmt-map-rockford.hpp
28 30
 EXTRA_libgamemaps_la_SOURCES += fmt-map-wacky.hpp
29 31
 EXTRA_libgamemaps_la_SOURCES += fmt-map-wordresc.hpp
30 32
 EXTRA_libgamemaps_la_SOURCES += fmt-map-xargon.hpp
236  src/fmt-map-rockford.cpp
... ...
@@ -0,0 +1,236 @@
  1
+/**
  2
+ * @file   fmt-map-rockford.cpp
  3
+ * @brief  MapType and Map2D implementation for Rockford levels.
  4
+ *
  5
+ * This file format is fully documented on the ModdingWiki:
  6
+ *   http://www.shikadi.net/moddingwiki/Rockford
  7
+ *
  8
+ * Copyright (C) 2010-2012 Adam Nielsen <malvineous@shikadi.net>
  9
+ *
  10
+ * This program is free software: you can redistribute it and/or modify
  11
+ * it under the terms of the GNU General Public License as published by
  12
+ * the Free Software Foundation, either version 3 of the License, or
  13
+ * (at your option) any later version.
  14
+ *
  15
+ * This program is distributed in the hope that it will be useful,
  16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18
+ * GNU General Public License for more details.
  19
+ *
  20
+ * You should have received a copy of the GNU General Public License
  21
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  22
+ */
  23
+
  24
+#include <boost/scoped_array.hpp>
  25
+#include <camoto/iostream_helpers.hpp>
  26
+#include "map2d-generic.hpp"
  27
+#include "fmt-map-rockford.hpp"
  28
+
  29
+#define ROCKFORD_TILE_WIDTH  16
  30
+#define ROCKFORD_TILE_HEIGHT 16
  31
+
  32
+/// Width of a map, in tiles.
  33
+#define ROCKFORD_MAP_WIDTH   40
  34
+
  35
+/// Height of a map, in tiles.
  36
+#define ROCKFORD_MAP_HEIGHT  22
  37
+
  38
+/// Map code to write for locations with no tile set.
  39
+#define ROCKFORD_DEFAULT_BGTILE     0x00
  40
+
  41
+/// This is the largest valid tile code in the background layer.
  42
+#define ROCKFORD_MAX_VALID_TILECODE   (10*20) // number of tiles in tileset
  43
+
  44
+namespace camoto {
  45
+namespace gamemaps {
  46
+
  47
+using namespace camoto::gamegraphics;
  48
+
  49
+RockfordBackgroundLayer::RockfordBackgroundLayer(ItemPtrVectorPtr& items,
  50
+	ItemPtrVectorPtr& validItems)
  51
+	:	GenericMap2D::Layer(
  52
+			"Background",
  53
+			Map2D::Layer::NoCaps,
  54
+			0, 0,
  55
+			0, 0,
  56
+			items, validItems
  57
+		)
  58
+{
  59
+}
  60
+
  61
+ImagePtr RockfordBackgroundLayer::imageFromCode(unsigned int code,
  62
+	VC_TILESET& tileset)
  63
+{
  64
+	if (tileset.size() < 1) return ImagePtr(); // no tileset?!
  65
+	const Tileset::VC_ENTRYPTR& images = tileset[0]->getItems();
  66
+
  67
+	// Special case for one image!
  68
+	if (code == 3) code++;
  69
+
  70
+	if (code >= images.size()) return ImagePtr(); // out of range
  71
+	return tileset[0]->openImage(images[code]);
  72
+}
  73
+
  74
+std::string RockfordMapType::getMapCode() const
  75
+{
  76
+	return "map-rockford";
  77
+}
  78
+
  79
+std::string RockfordMapType::getFriendlyName() const
  80
+{
  81
+	return "Rockford level";
  82
+}
  83
+
  84
+std::vector<std::string> RockfordMapType::getFileExtensions() const
  85
+{
  86
+	std::vector<std::string> vcExtensions;
  87
+	vcExtensions.push_back("bin");
  88
+	return vcExtensions;
  89
+}
  90
+
  91
+std::vector<std::string> RockfordMapType::getGameList() const
  92
+{
  93
+	std::vector<std::string> vcGames;
  94
+	vcGames.push_back("Rockford");
  95
+	return vcGames;
  96
+}
  97
+
  98
+MapType::Certainty RockfordMapType::isInstance(stream::input_sptr psMap) const
  99
+{
  100
+	stream::pos lenMap = psMap->size();
  101
+
  102
+	// Make sure there's enough data to read the map dimensions
  103
+	// TESTED BY: fmt_map_rockford_isinstance_c01
  104
+	if (lenMap != ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT) return MapType::DefinitelyNo;
  105
+
  106
+	psMap->seekg(0, stream::start);
  107
+
  108
+	// Read in the map and make sure all the tile codes are within range
  109
+	uint8_t *bg = new uint8_t[ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT];
  110
+	boost::scoped_array<uint8_t> scoped_bg(bg);
  111
+	stream::len r = psMap->try_read(bg, ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT);
  112
+	if (r != ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT) return MapType::DefinitelyNo; // read error
  113
+	for (unsigned int i = 0; i < ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT; i++) {
  114
+		// Make sure each tile is within range
  115
+		// TESTED BY: fmt_map_rockford_isinstance_c03
  116
+		if (bg[i] > ROCKFORD_MAX_VALID_TILECODE) {
  117
+			return MapType::DefinitelyNo;
  118
+		}
  119
+	}
  120
+
  121
+	// TESTED BY: fmt_map_rockford_isinstance_c00
  122
+	return MapType::DefinitelyYes;
  123
+}
  124
+
  125
+MapPtr RockfordMapType::create(SuppData& suppData) const
  126
+{
  127
+	// TODO: Implement
  128
+	throw stream::error("Not implemented yet!");
  129
+}
  130
+
  131
+MapPtr RockfordMapType::open(stream::input_sptr input, SuppData& suppData) const
  132
+{
  133
+	input->seekg(0, stream::start);
  134
+
  135
+	// Read the background layer
  136
+	uint8_t *bg = new uint8_t[ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT];
  137
+	boost::scoped_array<uint8_t> scoped_bg(bg);
  138
+	input->read(bg, ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT);
  139
+
  140
+	Map2D::Layer::ItemPtrVectorPtr tiles(new Map2D::Layer::ItemPtrVector());
  141
+	tiles->reserve(ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT);
  142
+	for (unsigned int i = 0; i < ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT; i++) {
  143
+		// The default tile actually has an image, so don't exclude it
  144
+		//if (bg[i] == ROCKFORD_DEFAULT_BGTILE) continue;
  145
+
  146
+		Map2D::Layer::ItemPtr t(new Map2D::Layer::Item());
  147
+		t->type = Map2D::Layer::Item::Default;
  148
+		t->x = i % ROCKFORD_MAP_WIDTH;
  149
+		t->y = i / ROCKFORD_MAP_WIDTH;
  150
+		t->code = bg[i];
  151
+		tiles->push_back(t);
  152
+	}
  153
+
  154
+	Map2D::Layer::ItemPtrVectorPtr validBGItems(new Map2D::Layer::ItemPtrVector());
  155
+	unsigned int validItems[] = {
  156
+		0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  157
+		0x08, 0x09, 0x0A, 0x0B, 0x0C,
  158
+		0x10,
  159
+		0x28, 0x2C, 0x2D, 0x2E,
  160
+		0x30, 0x34, 0x35, 0x36, 0x37,
  161
+		0x38,
  162
+		0x53,
  163
+		0x70, 0x74, 0x7C,
  164
+		0x80, 0x82, 0x84, 0x88,
  165
+		0xC4,
  166
+	};
  167
+	for (unsigned int i = 0; i < sizeof(validItems) / sizeof(unsigned int); i++) {
  168
+		Map2D::Layer::ItemPtr t(new Map2D::Layer::Item());
  169
+		t->type = Map2D::Layer::Item::Default;
  170
+		t->x = 0;
  171
+		t->y = 0;
  172
+		t->code = i;
  173
+		validBGItems->push_back(t);
  174
+	}
  175
+	Map2D::LayerPtr bgLayer(new RockfordBackgroundLayer(tiles, validBGItems));
  176
+
  177
+	Map2D::LayerPtrVector layers;
  178
+	layers.push_back(bgLayer);
  179
+
  180
+	Map2DPtr map(new GenericMap2D(
  181
+		Map::AttributePtrVectorPtr(), NO_GFX_CALLBACK,
  182
+		Map2D::HasViewport,
  183
+		320, 176, // viewport size
  184
+		ROCKFORD_MAP_WIDTH, ROCKFORD_MAP_HEIGHT,
  185
+		ROCKFORD_TILE_WIDTH, ROCKFORD_TILE_HEIGHT,
  186
+		layers, Map2D::PathPtrVectorPtr()
  187
+	));
  188
+
  189
+	return map;
  190
+}
  191
+
  192
+void RockfordMapType::write(MapPtr map, stream::expanding_output_sptr output,
  193
+	ExpandingSuppData& suppData) const
  194
+{
  195
+	Map2DPtr map2d = boost::dynamic_pointer_cast<Map2D>(map);
  196
+	if (!map2d) throw stream::error("Cannot write this type of map as this format.");
  197
+	if (map2d->getLayerCount() != 1)
  198
+		throw stream::error("Incorrect layer count for this format.");
  199
+
  200
+	unsigned int mapWidth, mapHeight;
  201
+	map2d->getMapSize(&mapWidth, &mapHeight);
  202
+	if ((mapWidth != ROCKFORD_MAP_WIDTH) || (mapHeight != ROCKFORD_MAP_HEIGHT)) {
  203
+		throw stream::error("Incorrect layer size for this format.");
  204
+	}
  205
+
  206
+	Map2D::LayerPtr layer = map2d->getLayer(0);
  207
+
  208
+	// Write the background layer
  209
+	uint8_t *bg = new uint8_t[ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT];
  210
+	boost::scoped_array<uint8_t> scoped_bg(bg);
  211
+	memset(bg, ROCKFORD_DEFAULT_BGTILE, ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT);
  212
+	const Map2D::Layer::ItemPtrVectorPtr items = layer->getAllItems();
  213
+	for (Map2D::Layer::ItemPtrVector::const_iterator i = items->begin();
  214
+		i != items->end();
  215
+		i++
  216
+	) {
  217
+		if (((*i)->x > mapWidth) || ((*i)->y > mapHeight)) {
  218
+			throw stream::error("Layer has tiles outside map boundary!");
  219
+		}
  220
+		bg[(*i)->y * mapWidth + (*i)->x] = (*i)->code;
  221
+	}
  222
+
  223
+	output->write(bg, ROCKFORD_MAP_WIDTH * ROCKFORD_MAP_HEIGHT);
  224
+	output->flush();
  225
+	return;
  226
+}
  227
+
  228
+SuppFilenames RockfordMapType::getRequiredSupps(stream::input_sptr input,
  229
+	const std::string& filename) const
  230
+{
  231
+	SuppFilenames supps;
  232
+	return supps;
  233
+}
  234
+
  235
+} // namespace gamemaps
  236
+} // namespace camoto
60  src/fmt-map-rockford.hpp
... ...
@@ -0,0 +1,60 @@
  1
+/**
  2
+ * @file   fmt-map-rockford.hpp
  3
+ * @brief  MapType and Map2D implementation for Rockford maps.
  4
+ *
  5
+ * Copyright (C) 2010-2012 Adam Nielsen <malvineous@shikadi.net>
  6
+ *
  7
+ * This program is free software: you can redistribute it and/or modify
  8
+ * it under the terms of the GNU General Public License as published by
  9
+ * the Free Software Foundation, either version 3 of the License, or
  10
+ * (at your option) any later version.
  11
+ *
  12
+ * This program is distributed in the hope that it will be useful,
  13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15
+ * GNU General Public License for more details.
  16
+ *
  17
+ * You should have received a copy of the GNU General Public License
  18
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19
+ */
  20
+
  21
+#ifndef _CAMOTO_GAMEMAPS_MAP_ROCKFORD_HPP_
  22
+#define _CAMOTO_GAMEMAPS_MAP_ROCKFORD_HPP_
  23
+
  24
+#include "base-maptype.hpp"
  25
+#include "map2d-generic.hpp"
  26
+
  27
+namespace camoto {
  28
+namespace gamemaps {
  29
+
  30
+/// Rockford level reader/writer.
  31
+class RockfordMapType: virtual public BaseMapType
  32
+{
  33
+	public:
  34
+		virtual std::string getMapCode() const;
  35
+		virtual std::string getFriendlyName() const;
  36
+		virtual std::vector<std::string> getFileExtensions() const;
  37
+		virtual std::vector<std::string> getGameList() const;
  38
+		virtual Certainty isInstance(stream::input_sptr psMap) const;
  39
+		virtual MapPtr create(SuppData& suppData) const;
  40
+		virtual MapPtr open(stream::input_sptr input, SuppData& suppData) const;
  41
+		virtual void write(MapPtr map, stream::expanding_output_sptr output,
  42
+			ExpandingSuppData& suppData) const;
  43
+		virtual SuppFilenames getRequiredSupps(stream::input_sptr input,
  44
+			const std::string& filename) const;
  45
+};
  46
+
  47
+class RockfordBackgroundLayer: virtual public GenericMap2D::Layer
  48
+{
  49
+	public:
  50
+		RockfordBackgroundLayer(ItemPtrVectorPtr& items,
  51
+			ItemPtrVectorPtr& validItems);
  52
+
  53
+		virtual gamegraphics::ImagePtr imageFromCode(unsigned int code,
  54
+			camoto::gamegraphics::VC_TILESET& tileset);
  55
+};
  56
+
  57
+} // namespace gamemaps
  58
+} // namespace camoto
  59
+
  60
+#endif // _CAMOTO_GAMEMAPS_MAP_ROCKFORD_HPP_
2  src/main.cpp
@@ -28,6 +28,7 @@
28 28
 #include "fmt-map-cosmo.hpp"
29 29
 #include "fmt-map-harry.hpp"
30 30
 #include "fmt-map-hocus.hpp"
  31
+#include "fmt-map-rockford.hpp"
31 32
 #include "fmt-map-wacky.hpp"
32 33
 #include "fmt-map-wordresc.hpp"
33 34
 #include "fmt-map-xargon.hpp"
@@ -64,6 +65,7 @@ ActualManager::ActualManager()
64 65
 	this->vcTypes.push_back(MapTypePtr(new HarryMapType()));
65 66
 	this->vcTypes.push_back(MapTypePtr(new HocusMapType()));
66 67
 	this->vcTypes.push_back(MapTypePtr(new JillMapType()));
  68
+	this->vcTypes.push_back(MapTypePtr(new RockfordMapType()));
67 69
 	this->vcTypes.push_back(MapTypePtr(new WackyMapType()));
68 70
 	this->vcTypes.push_back(MapTypePtr(new WordRescueMapType()));
69 71
 	this->vcTypes.push_back(MapTypePtr(new XargonMapType()));

0 notes on commit 23c35af

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