Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

Structure.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "Structure.h"
  19. #include "resource/Environment.h"
  20. #include "BinReader.h"
  21. #include "Core.h"
  22. #include "ResourceCache.h"
  23. enum EnvCellFlags
  24. {
  25. kSeenOutside = 1,
  26. kHasStaticObjects = 2,
  27. kHasWeenieObjects = 4,
  28. kHasRestrictionObject = 8
  29. };
  30. Structure::Structure(const void* data, size_t size)
  31. {
  32. BinReader reader(data, size);
  33. uint32_t resourceId = reader.readInt();
  34. id_ = LandcellId(resourceId);
  35. uint32_t flags = reader.readInt();
  36. assert(flags <= 0xF);
  37. uint32_t resourceId2 = reader.readInt();
  38. assert(resourceId2 == resourceId);
  39. UNUSED(resourceId2);
  40. uint8_t numSurfaces = reader.readByte();
  41. surfaces_.resize(numSurfaces);
  42. uint8_t numConnected = reader.readByte();
  43. uint16_t numVisible = reader.readShort();
  44. for(ResourcePtr& surface : surfaces_)
  45. {
  46. uint16_t surfaceId = reader.readShort();
  47. surface = Core::get().resourceCache().get(static_cast<uint32_t>(ResourceType::kSurface) | surfaceId);
  48. }
  49. uint16_t environmentId = reader.readShort();
  50. environment_ = Core::get().resourceCache().get(static_cast<uint32_t>(ResourceType::kEnvironment) | environmentId);
  51. partNum_ = reader.readShort();
  52. read(reader, location_);
  53. // AC: CCellPortal
  54. for(uint8_t i = 0; i < numConnected; i++)
  55. {
  56. /*portalSide*/ reader.readShort();
  57. /*portalId*/ reader.readShort();
  58. /*cellId*/ reader.readShort();
  59. /*exactMatch*/ reader.readShort();
  60. }
  61. for(uint16_t i = 0; i < numVisible; i++)
  62. {
  63. /*cellId*/ reader.readShort();
  64. }
  65. if(flags & kHasStaticObjects)
  66. {
  67. uint32_t numStaticObjects = reader.readInt();
  68. staticObjects_.resize(numStaticObjects);
  69. for(StaticObject& staticObject : staticObjects_)
  70. {
  71. read(reader, staticObject);
  72. }
  73. }
  74. if(flags & kHasRestrictionObject)
  75. {
  76. reader.readInt();
  77. }
  78. assert(reader.remaining() == 0);
  79. }
  80. LandcellId Structure::id() const
  81. {
  82. return id_;
  83. }
  84. const Location& Structure::location() const
  85. {
  86. return location_;
  87. }
  88. const vector<ResourcePtr>& Structure::surfaces() const
  89. {
  90. return surfaces_;
  91. }
  92. const Environment& Structure::environment() const
  93. {
  94. return environment_->cast<Environment>();
  95. }
  96. uint16_t Structure::partNum() const
  97. {
  98. return partNum_;
  99. }