123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- /*
- * Bael'Zharon's Respite
- * Copyright (C) 2014 Daniel Skorupski
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
- #include "Structure.h"
- #include "resource/Environment.h"
- #include "BinReader.h"
- #include "Core.h"
- #include "ResourceCache.h"
- enum EnvCellFlags
- {
- kSeenOutside = 1,
- kHasStaticObjects = 2,
- kHasWeenieObjects = 4,
- kHasRestrictionObject = 8
- };
- Structure::Structure(const void* data, size_t size)
- {
- BinReader reader(data, size);
- uint32_t resourceId = reader.readInt();
- id_ = LandcellId(resourceId);
- uint32_t flags = reader.readInt();
- assert(flags <= 0xF);
- uint32_t resourceId2 = reader.readInt();
- assert(resourceId2 == resourceId);
- UNUSED(resourceId2);
- uint8_t numSurfaces = reader.readByte();
- surfaces_.resize(numSurfaces);
- uint8_t numConnected = reader.readByte();
- uint16_t numVisible = reader.readShort();
- for(ResourcePtr& surface : surfaces_)
- {
- uint16_t surfaceId = reader.readShort();
- surface = Core::get().resourceCache().get(static_cast<uint32_t>(ResourceType::kSurface) | surfaceId);
- }
- uint16_t environmentId = reader.readShort();
- environment_ = Core::get().resourceCache().get(static_cast<uint32_t>(ResourceType::kEnvironment) | environmentId);
- partNum_ = reader.readShort();
- read(reader, location_);
- // AC: CCellPortal
- for(uint8_t i = 0; i < numConnected; i++)
- {
- /*portalSide*/ reader.readShort();
- /*portalId*/ reader.readShort();
- /*cellId*/ reader.readShort();
- /*exactMatch*/ reader.readShort();
- }
- for(uint16_t i = 0; i < numVisible; i++)
- {
- /*cellId*/ reader.readShort();
- }
- if(flags & kHasStaticObjects)
- {
- uint32_t numStaticObjects = reader.readInt();
- staticObjects_.resize(numStaticObjects);
- for(StaticObject& staticObject : staticObjects_)
- {
- read(reader, staticObject);
- }
- }
- if(flags & kHasRestrictionObject)
- {
- reader.readInt();
- }
- assert(reader.remaining() == 0);
- }
- LandcellId Structure::id() const
- {
- return id_;
- }
- const Location& Structure::location() const
- {
- return location_;
- }
- const vector<ResourcePtr>& Structure::surfaces() const
- {
- return surfaces_;
- }
- const Environment& Structure::environment() const
- {
- return environment_->cast<Environment>();
- }
- uint16_t Structure::partNum() const
- {
- return partNum_;
- }
|