00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028
00029 #if !defined __cplusplus
00030 #error C++ compiler required
00031 #endif
00032
00033
00034 #include <exception>
00035 #include <sstream>
00036 #include <stdexcept>
00037 #include <string>
00038
00039
00040 #include "global.hpp"
00041 #include "lump.hpp"
00042 #include "things.hpp"
00043 #include "wadentry.hpp"
00044
00045 using namespace Doomwad;
00046
00047 const size_t Thing::LENGTH = 0x0000000A;
00048 const size_t HexenThing::LENGTH = 0x00000014;
00049
00050 const std::string Things::NAME = "THINGS";
00051 const std::string HexenThings::NAME = "THINGS";
00052
00053
00054 const uint16 Thing::EAST = 0x0000;
00055 const uint16 Thing::NORTHEAST = 0x002D;
00056 const uint16 Thing::NORTH = 0x005A;
00057 const uint16 Thing::NORTHWEST = 0x0087;
00058 const uint16 Thing::WEST = 0x00B4;
00059 const uint16 Thing::SOUTHWEST = 0x00E1;
00060 const uint16 Thing::SOUTH = 0x010E;
00061 const uint16 Thing::SOUTHEAST = 0x013B;
00062
00063
00064 const uint16 Thing::SKILL1 = 0x0001;
00065 const uint16 Thing::SKILL2 = 0x0002;
00066 const uint16 Thing::SKILL3 = 0x0004;
00067 const uint16 Thing::DEAF = 0x0008;
00068 const uint16 Thing::MULTI = 0x0010;
00069 const uint16 Thing::BOOM_NODM = 0x0020;
00070 const uint16 Thing::BOOM_NOCO = 0x0040;
00071 const uint16 Thing::MBF_FRIENDLY = 0x0080;
00072
00073 const uint16 HexenThing::IN_SP = 0x0100;
00074 const uint16 HexenThing::IN_COOP = 0x0200;
00075 const uint16 HexenThing::IN_DM = 0x0400;
00076 const uint16 HexenThing::TRANSLUCENT = 0x0800;
00077 const uint16 HexenThing::INVISIBLE = 0x1000;
00078 const uint16 HexenThing::FRIENDLY = 0x2000;
00079 const uint16 HexenThing::STANDSTILL = 0x4000;
00080
00092 Thing::Thing (int16 _x, int16 _y, uint16 _angle, uint16 _type, uint16 _flags) throw () : x (_x), y (_y), angle (_angle), type (_type), flags (_flags)
00093 {
00094 }
00095
00099 Thing::~Thing (void) throw ()
00100 {
00101 }
00102
00103 size_t Thing::getLength (void) const throw ()
00104 {
00105 return LENGTH;
00106 }
00107
00108 bool Thing::write (Lump &lump, Lump::size_type i) const throw ()
00109 {
00110 try
00111 {
00112 lump.setInt16 (this->x, i);
00113 lump.setInt16 (this->y, i + 2);
00114 lump.setUInt16 (this->angle, i + 4);
00115 lump.setUInt16 (this->type, i + 6);
00116 lump.setUInt16 (this->flags, i + 8);
00117 }
00118 catch (std::range_error &e)
00119 {
00120 return false;
00121 }
00122 return true;
00123 }
00124
00125 bool Thing::read (const Lump &lump, Lump::size_type i) throw ()
00126 {
00127 try
00128 {
00129 this->x = lump.getInt16 (i);
00130 this->y = lump.getInt16 (i + 2);
00131 this->angle = lump.getUInt16 (i + 4);
00132 this->type = lump.getUInt16 (i + 6);
00133 this->flags = lump.getUInt16 (i + 8);
00134 }
00135 catch (std::range_error &e)
00136 {
00137 return false;
00138 }
00139 return true;
00140 }
00141
00142 std::string Thing::toString (void) const throw ()
00143 {
00144 std::ostringstream str;
00145 str << '(' << x << ',' << y << ',' << angle << ',' << type << ',' << flags << ')';
00146 return str.str ();
00147 }
00148
00168 HexenThing::HexenThing (uint16 _id, int16 _x, int16 _y, int16 _height, uint16 _angle, uint16 _type, uint16 _flags, byte _special, byte _arg1, byte _arg2, byte _arg3, byte _arg4, byte _arg5) throw () : id (_id), x (_x), y (_y), height (_height), angle (_angle), type (_type), flags (_flags), special (_special), arg1 (_arg1), arg2 (_arg2), arg3 (_arg3), arg4 (_arg4), arg5 (_arg5)
00169 {
00170 }
00171
00175 HexenThing::~HexenThing (void) throw ()
00176 {
00177 }
00178
00179 size_t HexenThing::getLength (void) const throw ()
00180 {
00181 return LENGTH;
00182 }
00183
00184 bool HexenThing::write (Lump &lump, Lump::size_type i) const throw ()
00185 {
00186 try
00187 {
00188 lump.setUInt16 (this->id, i);
00189 lump.setInt16 (this->x, i + 2);
00190 lump.setInt16 (this->y, i + 4);
00191 lump.setInt16 (this->height, i + 6);
00192 lump.setUInt16 (this->angle, i + 8);
00193 lump.setUInt16 (this->type, i + 10);
00194 lump.setUInt16 (this->flags, i + 12);
00195 lump.setByte (this->special, i + 14);
00196 lump.setByte (this->arg1, i + 15);
00197 lump.setByte (this->arg2, i + 16);
00198 lump.setByte (this->arg3, i + 17);
00199 lump.setByte (this->arg4, i + 18);
00200 lump.setByte (this->arg5, i + 19);
00201 }
00202 catch (std::range_error &e)
00203 {
00204 return false;
00205 }
00206 return true;
00207 }
00208
00209 bool HexenThing::read (const Lump &lump, Lump::size_type i) throw ()
00210 {
00211 try
00212 {
00213 this->id = lump.getUInt16 (i);
00214 this->x = lump.getInt16 (i + 2);
00215 this->y = lump.getInt16 (i + 4);
00216 this->height = lump.getInt16 (i + 6);
00217 this->angle = lump.getUInt16 (i + 8);
00218 this->type = lump.getUInt16 (i + 10);
00219 this->flags = lump.getUInt16 (i + 12);
00220 this->special = lump.getByte (i + 14);
00221 this->arg1 = lump.getByte (i + 15);
00222 this->arg2 = lump.getByte (i + 16);
00223 this->arg3 = lump.getByte (i + 17);
00224 this->arg4 = lump.getByte (i + 18);
00225 this->arg5 = lump.getByte (i + 19);
00226 }
00227 catch (std::range_error &e)
00228 {
00229 return false;
00230 }
00231 return true;
00232 }
00233
00234 std::string HexenThing::toString (void) const throw ()
00235 {
00236 std::ostringstream str;
00237 str << '(' << id << ',' << x << ',' << y << ',' << height << ',' << angle << ','
00238 << type << ',' << flags << ','
00239 << (static_cast<int> (special)) << ',' << (static_cast<int> (arg1)) << ',' << (static_cast<int> (arg2)) << ','
00240 << (static_cast<int> (arg3)) << ',' << (static_cast<int> (arg4)) << ',' << (static_cast<int> (arg5)) << ')';
00241 return str.str ();
00242 }
00243
00247 Things::Things (void) throw ()
00248 {
00249 return;
00250 }
00251
00261 Things::Things (const Lump &lump) throw ()
00262 {
00263 this->setFromLump (lump);
00264 return;
00265 }
00266
00272 Things::~Things (void) throw ()
00273 {
00274 return;
00275 }
00276
00277 bool Things::setFromLump (const Lump &lump) throw ()
00278 {
00279
00280
00281 size_t q = lump.size ();
00282 if (q % Thing::LENGTH != 0) return false;
00283
00284 Thing t;
00285
00286 this->clear ();
00287
00288 for (size_t i = 0; i < q; i += Thing::LENGTH)
00289 {
00290 t.read (lump, i);
00291 this->push_back (t);
00292 }
00293
00294 return true;
00295 }
00296
00297 Lump Things::toLump (void) const throw ()
00298 {
00299 Lump lump (NAME, this->size () * Thing::LENGTH);
00300
00301 size_t i = 0;
00302 const_iterator iter = this->begin ();
00303 for (; iter != this->end (); i += Thing::LENGTH, ++iter)
00304 {
00305 iter->write (lump, i);
00306 }
00307
00308 return lump;
00309 }
00310
00311 std::string Things::toString (void) const throw ()
00312 {
00313 std::ostringstream str;
00314 for (const_iterator iter = this->begin (); iter != this->end (); ++iter)
00315 str << iter->toString () << '\n';
00316 return str.str ();
00317 }
00318
00322 HexenThings::HexenThings (void) throw ()
00323 {
00324 return;
00325 }
00326
00336 HexenThings::HexenThings (const Lump &lump) throw ()
00337 {
00338 this->setFromLump (lump);
00339 return;
00340 }
00341
00347 HexenThings::~HexenThings (void) throw ()
00348 {
00349 return;
00350 }
00351
00352 bool HexenThings::setFromLump (const Lump &lump) throw ()
00353 {
00354 size_t q = lump.size ();
00355 if (q % HexenThing::LENGTH != 0) return false;
00356
00357 HexenThing t;
00358
00359 this->clear ();
00360
00361 for (size_t i = 0; i < q; i += HexenThing::LENGTH)
00362 {
00363 t.read (lump, i);
00364 this->push_back (t);
00365 }
00366
00367 return true;
00368 }
00369
00370 Lump HexenThings::toLump (void) const throw ()
00371 {
00372 Lump lump (NAME, this->size () * HexenThing::LENGTH);
00373
00374 size_t i = 0;
00375 const_iterator iter = this->begin ();
00376 for (; iter != this->end (); i += HexenThing::LENGTH, ++iter)
00377 {
00378 iter->write (lump, i);
00379 }
00380
00381 return lump;
00382 }
00383
00384 std::string HexenThings::toString (void) const throw ()
00385 {
00386 std::ostringstream str;
00387 for (const_iterator iter = this->begin (); iter != this->end (); ++iter)
00388 str << iter->toString () << '\n';
00389 return str.str ();
00390 }