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 "linedefs.hpp"
00043 #include "wadentry.hpp"
00044
00045 using namespace Doomwad;
00046
00047 const std::string Linedefs::NAME = "LINEDEFS";
00048 const std::string HexenLinedefs::NAME = "LINEDEFS";
00049
00050
00051 const uint16 Linedef::NOSIDEDEF = 0xFFFF;
00052
00053 const size_t Linedef::LENGTH = 0x0000000E;
00054 const size_t HexenLinedef::LENGTH = 0x00000010;
00055
00056
00057 const uint16 Linedef::IMPASSIBLE = 0x0001;
00058 const uint16 Linedef::BLOCK_MONSTER = 0x0002;
00059 const uint16 Linedef::TWOSIDED = 0x0004;
00060 const uint16 Linedef::UNPEG_UPPER = 0x0008;
00061 const uint16 Linedef::UNPEG_LOWER = 0x0010;
00062 const uint16 Linedef::SECRET = 0x0020;
00063 const uint16 Linedef::BLOCK_SOUND = 0x0040;
00064 const uint16 Linedef::INVISIBLE = 0x0080;
00065 const uint16 Linedef::ALWAYS_MAPPED = 0x0100;
00066 const uint16 Linedef::ACTION_PASSTHROUGH = 0x0200;
00067
00068 const uint16 HexenLinedef::ACTIVE_MULTIPLE = 0x0200;
00069 const uint16 HexenLinedef::ACTIVE_PLAYER = 0x0400;
00070 const uint16 HexenLinedef::ACTIVE_MONSTER = 0x0800;
00071 const uint16 HexenLinedef::ACTIVE_PROJECTILE_HIT = 0x0C00;
00072 const uint16 HexenLinedef::ACTIVE_PLAYER_BUMP = 0x1000;
00073 const uint16 HexenLinedef::ACTIVE_PROJECTILE_PASSTHROUGH = 0x1400;
00074 const uint16 HexenLinedef::ACTIVE_PLAYER_PASSTHROUGH = 0x1000;
00075 const uint16 HexenLinedef::ACTIVE_PLAYER_MONSTERS = 0x2000;
00076 const uint16 HexenLinedef::ZDOOM_UNKNOWN = 0x4000;
00077 const uint16 HexenLinedef::BLOCKS_EVERYTHING = 0x8000;
00078
00092 Linedef::Linedef (uint16 _start, uint16 _end, uint16 _flags, uint16 _tag, uint16 _sidedef1, uint16 _sidedef2, uint16 _type) throw () : start (_start), end (_end), flags (_flags), tag (_tag), sidedef1 (_sidedef1), sidedef2 (_sidedef2), type (_type)
00093 {
00094 }
00095
00101 Linedef::~Linedef (void) throw ()
00102 {
00103 }
00104
00105 size_t Linedef::getLength (void) const throw ()
00106 {
00107 return LENGTH;
00108 }
00109
00110 bool Linedef::write (Lump &lump, Lump::size_type i) const throw ()
00111 {
00112 try
00113 {
00114 lump.setUInt16 (this->start, i);
00115 lump.setUInt16 (this->end, i + 2);
00116 lump.setUInt16 (this->flags, i + 4);
00117 lump.setUInt16 (this->tag, i + 6);
00118 lump.setUInt16 (this->sidedef1, i + 8);
00119 lump.setUInt16 (this->sidedef2, i + 10);
00120 lump.setUInt16 (this->type, i + 12);
00121 }
00122 catch (std::range_error &e)
00123 {
00124 return false;
00125 }
00126 return true;
00127 }
00128
00129 bool Linedef::read (const Lump &lump, Lump::size_type i) throw ()
00130 {
00131 try
00132 {
00133 this->start = lump.getUInt16 (i);
00134 this->end = lump.getUInt16 (i + 2);
00135 this->flags = lump.getUInt16 (i + 4);
00136 this->tag = lump.getUInt16 (i + 6);
00137 this->sidedef1 = lump.getUInt16 (i + 8);
00138 this->sidedef2 = lump.getUInt16 (i + 10);
00139 this->type = lump.getUInt16 (i + 12);
00140 }
00141 catch (std::range_error &e)
00142 {
00143 return false;
00144 }
00145 return true;
00146 }
00147
00148 std::string Linedef::toString (void) const throw ()
00149 {
00150 std::ostringstream str;
00151
00152 str << '(' << start << ',' << end << ',' << flags << ',' << tag << ','
00153 << sidedef1 << ',' << sidedef2 << ',' << type << ')';
00154
00155 return str.str ();
00156 }
00157
00175 HexenLinedef::HexenLinedef (uint16 _start, uint16 _end, uint16 _flags, uint16 _sidedef1, uint16 _sidedef2, uint8 _type, int8 _arg1, int8 _arg2, int8 _arg3, int8 _arg4, int8 _arg5) throw () : start (_start), end (_end), flags (_flags), sidedef1 (_sidedef1), sidedef2 (_sidedef2), type (_type), arg1 (_arg1), arg2 (_arg2), arg3 (_arg3), arg4 (_arg4), arg5 (_arg5)
00176 {
00177 }
00178
00184 HexenLinedef::~HexenLinedef (void) throw ()
00185 {
00186 }
00187
00188 size_t HexenLinedef::getLength (void) const throw ()
00189 {
00190 return LENGTH;
00191 }
00192
00193 bool HexenLinedef::write (Lump &lump, Lump::size_type i) const throw ()
00194 {
00195 try
00196 {
00197 lump.setUInt16 (this->start, i);
00198 lump.setUInt16 (this->end, i + 2);
00199 lump.setUInt16 (this->flags, i + 4);
00200 lump.setUInt16 (this->sidedef1, i + 6);
00201 lump.setUInt16 (this->sidedef2, i + 8);
00202 lump.setUInt8 (this->type, i + 10);
00203 lump.setInt8 (this->arg1, i + 11);
00204 lump.setInt8 (this->arg2, i + 12);
00205 lump.setInt8 (this->arg3, i + 13);
00206 lump.setInt8 (this->arg4, i + 14);
00207 lump.setInt8 (this->arg5, i + 15);
00208 }
00209 catch (std::range_error &e)
00210 {
00211 return false;
00212 }
00213 return true;
00214 }
00215
00216 bool HexenLinedef::read (const Lump &lump, Lump::size_type i) throw ()
00217 {
00218 try
00219 {
00220 this->start = lump.getUInt16 (i);
00221 this->end = lump.getUInt16 (i + 2);
00222 this->flags = lump.getUInt16 (i + 4);
00223 this->sidedef1 = lump.getUInt16 (i + 6);
00224 this->sidedef2 = lump.getUInt16 (i + 8);
00225 this->type = lump.getUInt8 (i + 10);
00226 this->arg1 = lump.getInt8 (i + 11);
00227 this->arg2 = lump.getInt8 (i + 12);
00228 this->arg3 = lump.getInt8 (i + 13);
00229 this->arg4 = lump.getInt8 (i + 14);
00230 this->arg5 = lump.getInt8 (i + 15);
00231 }
00232 catch (std::range_error &e)
00233 {
00234 return false;
00235 }
00236 return true;
00237 }
00238
00239 std::string HexenLinedef::toString (void) const throw ()
00240 {
00241 std::ostringstream str;
00242
00243 str << '(' << start << ',' << end << ',' << flags << ','
00244 << sidedef1 << ',' << sidedef2 << ','
00245 << (static_cast<int> (type)) << ',' << (static_cast<int> (arg1)) << ',' << (static_cast<int> (arg2)) << ','
00246 << (static_cast<int> (arg3)) << ',' << (static_cast<int> (arg4)) << ',' << (static_cast<int> (arg5)) << ')';
00247
00248 return str.str ();
00249 }
00250
00254 Linedefs::Linedefs (void) throw ()
00255 {
00256 return;
00257 }
00258
00268 Linedefs::Linedefs (const Lump &lump) throw ()
00269 {
00270 this->setFromLump (lump);
00271 return;
00272 }
00273
00279 Linedefs::~Linedefs (void) throw ()
00280 {
00281 return;
00282 }
00283
00284 bool Linedefs::setFromLump (const Lump &lump) throw ()
00285 {
00286
00287
00288 size_t q = lump.size ();
00289 if (q % Linedef::LENGTH != 0) return false;
00290
00291 Linedef l;
00292
00293 this->clear ();
00294
00295 for (size_t i = 0; i < q; i += Linedef::LENGTH)
00296 {
00297 l.read (lump, i);
00298 this->push_back (l);
00299 }
00300
00301 return true;
00302 }
00303
00304 Lump Linedefs::toLump (void) const throw ()
00305 {
00306 Lump l (NAME);
00307
00308 l.setSize (this->size () * Linedef::LENGTH);
00309 size_t i = 0;
00310 const_iterator iter = this->begin ();
00311 for (; iter != this->end (); i += 14, ++iter)
00312 {
00313 iter->write (l, i);
00314 }
00315
00316 return l;
00317 }
00318
00319 std::string Linedefs::toString (void) const throw ()
00320 {
00321 std::ostringstream str;
00322 for (const_iterator iter = this->begin (); iter != this->end (); ++iter)
00323 str << iter->toString () << '\n';
00324 return str.str ();
00325 }
00326
00330 HexenLinedefs::HexenLinedefs (void) throw ()
00331 {
00332 return;
00333 }
00334
00344 HexenLinedefs::HexenLinedefs (const Lump &lump) throw ()
00345 {
00346 this->setFromLump (lump);
00347 return;
00348 }
00349
00355 HexenLinedefs::~HexenLinedefs (void) throw ()
00356 {
00357 return;
00358 }
00359
00360 bool HexenLinedefs::setFromLump (const Lump &lump) throw ()
00361 {
00362
00363
00364 size_t q = lump.size ();
00365 if (q % HexenLinedef::LENGTH != 0) return false;
00366
00367 HexenLinedef l;
00368
00369 this->clear ();
00370
00371 for (size_t i = 0; i < q; i += 10)
00372 {
00373 l.read (lump, i);
00374 this->push_back (l);
00375 }
00376
00377 return true;
00378 }
00379
00380 Lump HexenLinedefs::toLump (void) const throw ()
00381 {
00382 Lump l (NAME);
00383
00384 l.setSize (this->size () * 16);
00385 size_t i = 0;
00386 const_iterator iter = this->begin ();
00387 for (; iter != this->end (); i += 14, ++iter)
00388 {
00389 iter->write (l, i);
00390 }
00391
00392 return l;
00393 }
00394
00395 std::string HexenLinedefs::toString (void) const throw ()
00396 {
00397 std::ostringstream str;
00398 for (const_iterator iter = this->begin (); iter != this->end (); ++iter)
00399 str << iter->toString () << '\n';
00400 return str.str ();
00401 }