26 |
|
|
27 |
#include "oxyd.hh" |
#include "oxyd.hh" |
28 |
#include "enigma.hh" |
#include "enigma.hh" |
29 |
|
#include "sound.hh" |
30 |
|
|
31 |
#include "oxydlib/DatFile.h" |
#include "oxydlib/DatFile.h" |
32 |
|
#include "oxydlib/VecUtils.h" |
33 |
|
#include "oxydlib/FileUtils.h" |
34 |
|
|
35 |
#include <string> |
#include <string> |
36 |
#include <cstdio> |
#include <cstdio> |
37 |
|
#include <cstdlib> |
38 |
|
#include <cassert> |
39 |
#include <iostream> |
#include <iostream> |
40 |
|
|
|
|
|
41 |
using namespace std; |
using namespace std; |
42 |
|
using namespace enigma; |
43 |
using namespace enigma::oxyd; |
using namespace enigma::oxyd; |
44 |
|
|
45 |
namespace |
namespace |
46 |
{ |
{ |
47 |
struct GameInfo { |
struct GameInfo { |
48 |
|
GameInfo(); |
49 |
|
GameInfo (const string &game_, const string &datfile_); |
50 |
|
|
51 |
GameInfo (const string &game_="", const string &datfile_="") |
// Variables. |
52 |
: game(game_), datfile(datfile_), is_present(false) |
string game; |
53 |
{} |
string datfile; |
54 |
|
bool is_present; |
55 |
string game; |
string datfile_path; |
|
string datfile; |
|
|
bool is_present; |
|
|
string datfile_path; |
|
56 |
}; |
}; |
57 |
|
|
58 |
vector<GameInfo> games; |
map <string,string> soundfx_map; |
59 |
} |
} |
60 |
|
|
61 |
|
GameInfo::GameInfo() |
62 |
|
: is_present(false) |
63 |
|
{} |
64 |
|
|
65 |
|
|
66 |
|
GameInfo::GameInfo (const string &game_, const string &datfile_) |
67 |
|
: game(game_), datfile(datfile_), is_present(false) |
68 |
|
{ |
69 |
|
string fname; |
70 |
|
if (FindFile (datfile, datfile_path)) { |
71 |
|
enigma::Log << "Found " << game << " data file\n"; |
72 |
|
is_present = true; |
73 |
|
} |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
//---------------------------------------- |
78 |
|
// local variables |
79 |
|
//---------------------------------------- |
80 |
|
namespace |
81 |
|
{ |
82 |
|
vector<GameInfo> games; |
83 |
|
DatFile *datfile = 0; |
84 |
|
} |
85 |
|
|
86 |
void enigma::oxyd::Init() |
void enigma::oxyd::Init() |
87 |
{ |
{ |
88 |
games.clear(); |
games.clear(); |
89 |
games.push_back(GameInfo("Per.Oxyd", "peroxyd.dat")); |
games.resize(OxydVersion_Count); |
90 |
games.push_back(GameInfo("Oxyd magnum", "oxydmibm.dat")); |
games[OxydVersion_PerOxyd] = GameInfo("Per.Oxyd", "peroxyd.dat"); |
91 |
games.push_back(GameInfo("Oxyd", "oxyd1ibm.dat")); |
games[OxydVersion_Oxyd1] = GameInfo("Oxyd 1", "oxyd1ibm.dat"); |
92 |
|
games[OxydVersion_OxydMagnum] = GameInfo("Oxyd magnum", "oxydmibm.dat"); |
93 |
|
games[OxydVersion_OxydExtra] = GameInfo("Oxyd extra", "oxydex.dat"); |
94 |
|
|
95 |
|
soundfx_map["boink"] = "OXJUMP.SDD"; |
96 |
|
soundfx_map["st-oxydopen"] = "OXMEMOP.SDD"; |
97 |
|
soundfx_map["st-oxydopened"] = "OXMEMOK.SDD"; |
98 |
|
soundfx_map["st-oxydclose"] = "OXMEMCL.SDD"; |
99 |
|
soundfx_map["finished"] = "OXFINITO.SDD"; |
100 |
|
soundfx_map["dooropen"] = "OXMOTOR.SDD"; |
101 |
|
soundfx_map["doorclose"] = "OXMOTOR.SDD"; |
102 |
|
soundfx_map["fart"] = "OXUNTITL.SDD"; |
103 |
|
soundfx_map["pickup"] = "OXINVENT.SDD"; |
104 |
|
soundfx_map["invrotate"] = "OXINVROT.SDD"; |
105 |
|
soundfx_map["it-triggerdown"]= "OXSWON.SDD"; |
106 |
|
soundfx_map["it-triggerup"] = "OXSWOFF.SDD"; |
107 |
|
soundfx_map["shatter"] = "OXKLIRR.SDD"; |
108 |
|
|
109 |
|
soundfx_map["explosion2"] = "OXCRASH1.SDD"; |
110 |
|
soundfx_map["explosion1"] = "OXCRASH2.SDD"; |
111 |
|
soundfx_map["impulse"] = "OXWOUOU.SDD"; |
112 |
|
soundfx_map["st-move"] = "OXMOVE.SDD"; |
113 |
|
soundfx_map["rotate-left"] = "OXMAGIC4.SDD"; |
114 |
|
soundfx_map["rotate-right"] = "OXMAGIC3.SDD"; |
115 |
|
soundfx_map["st-magic"] = "OXMAGIC.SDD"; |
116 |
|
|
117 |
|
soundfx_map["st-metal"] = "OXKLICK2.SDD"; |
118 |
|
soundfx_map["st-stone"] = "OXKLICK1.SDD"; |
119 |
|
soundfx_map["st-thud"] = "OXKLICK5.SDD"; |
120 |
|
soundfx_map["drown"] = "OXBLOOP.SDD"; |
121 |
|
soundfx_map["thief"] = "OXTHIEF.SDD"; |
122 |
|
soundfx_map["warp"] = "OXTRANS.SDD"; |
123 |
|
} |
124 |
|
|
125 |
string fname; |
bool |
126 |
|
enigma::oxyd::FoundOxyd (OxydVersion ver) |
127 |
for (int i=0; i<games.size(); ++i) { |
{ |
128 |
if (FindFile (games[i].datfile, games[i].datfile_path)) |
return games[ver].is_present; |
129 |
enigma::Log << "Found " << games[i].game << " data file\n"; |
} |
130 |
|
|
131 |
|
bool |
132 |
|
enigma::oxyd::OpenDatFile (OxydVersion ver) |
133 |
|
{ |
134 |
|
assert(datfile == 0); |
135 |
|
|
136 |
|
if (FoundOxyd(ver)) { |
137 |
|
string fname = games[ver].datfile_path; |
138 |
|
ByteVec data; |
139 |
|
readFile (fname, &data); |
140 |
|
|
141 |
|
datfile = new DatFile; |
142 |
|
string errmsg; |
143 |
|
if (!parseDatFile (data, ver, datfile, &errmsg)) { |
144 |
|
enigma::Log << "Error loading " << fname << ": " << errmsg << endl; |
145 |
|
delete datfile; |
146 |
|
} else { |
147 |
|
enigma::Log << "Loaded "<< fname << endl; |
148 |
|
} |
149 |
|
} |
150 |
|
return false; |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
Mix_Chunk * |
156 |
|
enigma::oxyd::LoadSound (const std::string &name) |
157 |
|
{ |
158 |
|
Mix_Chunk *chunk = 0; |
159 |
|
if (datfile) { |
160 |
|
string chunkname = soundfx_map[name]; |
161 |
|
const ByteVec *snddata = datfile->getChunk(chunkname); |
162 |
|
if (snddata) { |
163 |
|
enigma::Log << "Loaded sound file " << name << " =^= " << chunkname<<endl; |
164 |
|
const int offset = 16; |
165 |
|
return sound::ChunkFromRaw (&(*snddata)[0], snddata->size()-offset, |
166 |
|
6000, AUDIO_S8, 1); |
167 |
|
} |
168 |
} |
} |
169 |
|
return chunk; |
170 |
} |
} |