1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "base/plugins.h"
24
25 #include "common/memstream.h"
26 #include "engines/advancedDetector.h"
27 #include "common/system.h"
28 #include "graphics/colormasks.h"
29 #include "graphics/surface.h"
30
31 #include "tony/tony.h"
32 #include "tony/game.h"
33
34 namespace Tony {
35
36 enum {
37 GF_COMPRESSED = (1 << 0)
38 };
39
40 struct TonyGameDescription {
41 ADGameDescription desc;
42 };
43
getFeatures() const44 uint32 TonyEngine::getFeatures() const {
45 return _gameDescription->desc.flags;
46 }
47
getLanguage() const48 Common::Language TonyEngine::getLanguage() const {
49 return _gameDescription->desc.language;
50 }
51
getIsDemo() const52 bool TonyEngine::getIsDemo() const {
53 return _gameDescription->desc.flags & ADGF_DEMO;
54 }
55
isCompressed() const56 bool TonyEngine::isCompressed() const {
57 return _gameDescription->desc.flags & GF_COMPRESSED;
58 }
59
60 } // End of namespace Tony
61
62 static const PlainGameDescriptor tonyGames[] = {
63 {"tony", "Tony Tough and the Night of Roasted Moths"},
64 {0, 0}
65 };
66
67 #include "tony/detection_tables.h"
68
69 class TonyMetaEngine : public AdvancedMetaEngine {
70 public:
TonyMetaEngine()71 TonyMetaEngine() : AdvancedMetaEngine(Tony::gameDescriptions, sizeof(Tony::TonyGameDescription), tonyGames) {
72 }
73
getName() const74 virtual const char *getName() const {
75 return "Tony Tough and the Night of Roasted Moths";
76 }
77
getOriginalCopyright() const78 virtual const char *getOriginalCopyright() const {
79 return "Tony Tough and the Night of Roasted Moths (C) Protonic Interactive";
80 }
81
82 virtual bool hasFeature(MetaEngineFeature f) const;
83 virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const;
84 virtual SaveStateList listSaves(const char *target) const;
85 virtual int getMaximumSaveSlot() const;
86 virtual void removeSaveState(const char *target, int slot) const;
87 SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const;
88 };
89
hasFeature(MetaEngineFeature f) const90 bool TonyMetaEngine::hasFeature(MetaEngineFeature f) const {
91 return
92 (f == kSupportsListSaves) ||
93 (f == kSupportsLoadingDuringStartup) ||
94 (f == kSupportsDeleteSave) ||
95 (f == kSavesSupportMetaInfo) ||
96 (f == kSavesSupportThumbnail);
97 }
98
hasFeature(EngineFeature f) const99 bool Tony::TonyEngine::hasFeature(EngineFeature f) const {
100 return
101 (f == kSupportsRTL) ||
102 (f == kSupportsLoadingDuringRuntime) ||
103 (f == kSupportsSavingDuringRuntime);
104 }
105
createInstance(OSystem * syst,Engine ** engine,const ADGameDescription * desc) const106 bool TonyMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
107 const Tony::TonyGameDescription *gd = (const Tony::TonyGameDescription *)desc;
108 if (gd) {
109 *engine = new Tony::TonyEngine(syst, gd);
110 }
111 return gd != 0;
112 }
113
listSaves(const char * target) const114 SaveStateList TonyMetaEngine::listSaves(const char *target) const {
115 Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
116 Common::StringArray filenames;
117 Common::String saveDesc;
118 Common::String pattern = "tony.0##";
119
120 filenames = saveFileMan->listSavefiles(pattern);
121
122 SaveStateList saveList;
123 for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
124 // Obtain the last 3 digits of the filename, since they correspond to the save slot
125 int slotNum = atoi(file->c_str() + file->size() - 3);
126
127 if (slotNum >= 0 && slotNum <= 999) {
128 byte thumbnailData[160 * 120 * 2];
129 Common::String saveName;
130 byte difficulty;
131
132 if (Tony::RMOptionScreen::loadThumbnailFromSaveState(slotNum, thumbnailData, saveName, difficulty)) {
133 // Add the save name to the savegame list
134 saveList.push_back(SaveStateDescriptor(slotNum, saveName));
135 }
136 }
137 }
138
139 // Sort saves based on slot number.
140 Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
141 return saveList;
142 }
143
getMaximumSaveSlot() const144 int TonyMetaEngine::getMaximumSaveSlot() const {
145 return 99;
146 }
147
removeSaveState(const char * target,int slot) const148 void TonyMetaEngine::removeSaveState(const char *target, int slot) const {
149 Common::String filename = Tony::TonyEngine::getSaveStateFileName(slot);
150
151 g_system->getSavefileManager()->removeSavefile(filename);
152 }
153
querySaveMetaInfos(const char * target,int slot) const154 SaveStateDescriptor TonyMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
155 Common::String saveName;
156 byte difficulty;
157
158 Graphics::Surface *to = new Graphics::Surface();
159 to->create(160, 120, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
160
161 if (Tony::RMOptionScreen::loadThumbnailFromSaveState(slot, (byte *)to->getPixels(), saveName, difficulty)) {
162 #ifdef SCUMM_BIG_ENDIAN
163 uint16 *pixels = (uint16 *)to->getPixels();
164 for (int i = 0; i < to->w * to->h; ++i)
165 pixels[i] = READ_LE_UINT16(pixels + i);
166 #endif
167 // Create the return descriptor
168 SaveStateDescriptor desc(slot, saveName);
169 desc.setDeletableFlag(true);
170 desc.setWriteProtectedFlag(false);
171 desc.setThumbnail(to);
172
173 return desc;
174 }
175
176 delete to;
177 return SaveStateDescriptor();
178 }
179
180 #if PLUGIN_ENABLED_DYNAMIC(TONY)
181 REGISTER_PLUGIN_DYNAMIC(TONY, PLUGIN_TYPE_ENGINE, TonyMetaEngine);
182 #else
183 REGISTER_PLUGIN_STATIC(TONY, PLUGIN_TYPE_ENGINE, TonyMetaEngine);
184 #endif
185