/** * serialise saves / restores the state of the object */ void VectorGenerator::serialise( DataSectionPtr pBaseSect, bool load ) { BW_GUARD; DataSectionPtr pSect; if (load) pSect = pBaseSect; else pSect = pBaseSect->newSection( nameID() ); serialiseInternal(pSect, load); }
void SpawnAreaMap::readAreaObject(LuaObject& areaObj) { String name = areaObj.getStringAt(1); float x = areaObj.getFloatAt(2); float y = areaObj.getFloatAt(3); int tier = areaObj.getIntAt(5); int constant = areaObj.getIntAt(6); float radius = 0; float width = 0; float height = 0; float innerRadius = 0; float outerRadius = 0; LuaObject areaShapeObject = areaObj.getObjectAt(4); if (areaShapeObject.isValidTable()) { if (areaShapeObject.getIntAt(1) == 1) { radius = areaShapeObject.getFloatAt(2); } else if (areaShapeObject.getIntAt(1) == 2) { width = areaShapeObject.getFloatAt(2); height = areaShapeObject.getFloatAt(3); } else if (areaShapeObject.getIntAt(1) == 3) { innerRadius = areaShapeObject.getFloatAt(2); outerRadius = areaShapeObject.getFloatAt(3); } areaShapeObject.pop(); } else { areaShapeObject.pop(); radius = areaObj.getFloatAt(4); width = 0; height = 0; } if (radius == 0 && width == 0 && height == 0 && innerRadius == 0 && outerRadius == 0) return; uint32 crc = 0; if (tier & STATICSPAWNAREA) { crc = String("object/static_spawn_area.iff").hashCode(); } else if (tier & DYNAMICSPAWNAREA) { crc = String("object/dynamic_spawn_area.iff").hashCode(); } else if (tier & LAIRSPAWNAREA) { crc = String("object/lair_spawn_area.iff").hashCode(); } else { error("Unknown region tier " + String::valueOf(tier)); crc = String("object/dynamic_spawn_area.iff").hashCode(); } ManagedReference<SpawnArea*> area = dynamic_cast<SpawnArea*>(ObjectManager::instance()->createObject(crc, 0, "spawnareas")); if (area == NULL) return; StringId nameID(zone->getZoneName() + "_region_names", name); area->setObjectName(nameID); if (height > 0 && width > 0) { ManagedReference<RectangularAreaShape*> rectangularAreaShape = new RectangularAreaShape(); rectangularAreaShape->setAreaCenter(x, y); rectangularAreaShape->setDimensions(height, width); area->setAreaShape(rectangularAreaShape); } else if (radius > 0) { ManagedReference<CircularAreaShape*> circularAreaShape = new CircularAreaShape(); circularAreaShape->setAreaCenter(x, y); circularAreaShape->setRadius(radius); area->setAreaShape(circularAreaShape); } else if (innerRadius > 0 && outerRadius > 0) { ManagedReference<RingAreaShape*> ringAreaShape = new RingAreaShape(); ringAreaShape->setAreaCenter(x, y); ringAreaShape->setInnerRadius(innerRadius); ringAreaShape->setOuterRadius(outerRadius); area->setAreaShape(ringAreaShape); } else { ManagedReference<CircularAreaShape*> circularAreaShape = new CircularAreaShape(); circularAreaShape->setAreaCenter(x, y); circularAreaShape->setRadius(zone->getBoundingRadius()); area->setAreaShape(circularAreaShape); } area->setTier(tier); area->setSpawnConstant(constant); for (int j = 7; j <= areaObj.getTableSize(); ++j) area->addTemplate(areaObj.getStringAt(j).hashCode()); if ((radius != -1) && !(tier & (WORLDSPAWNAREA | REBELSPAWNAREA | IMPERIALSPAWNAREA | NEUTRALSPAWNAREA))) { zone->transferObject(area, -1, true); } else { if (tier & NEUTRALSPAWNAREA) { factionalNeutralSpawnAreas.add(area); } else if (tier & REBELSPAWNAREA) { factionalRebelSpawnAreas.add(area); } else if (tier & IMPERIALSPAWNAREA) { factionalImperialSpawnAreas.add(area); } else if (tier & WORLDSPAWNAREA) { worldSpawnAreas.add(area); } area->setZone(zone); } area->updateToDatabase(); put(nameID.getStringID().hashCode(), area); if (tier & NOSPAWNAREA) { noSpawnAreas.add(area); } if (tier & NOBUILDZONEAREA) { area->setNoBuildArea(true); } if (area->isStaticArea() && (tier & STATICSPAWNAREA)) { StaticSpawnArea* staticArea = cast<StaticSpawnArea*>(area.get()); staticArea->spawnCreatures(); } if (area->isDynamicArea() && (tier & DYNAMICSPAWNAREA)) { DynamicSpawnArea* dynamicArea = cast<DynamicSpawnArea*>(area.get()); dynamicArea->addSpawnTask(); } }
void SpawnAreaMap::readAreaObject(LuaObject& areaObj) { String name = areaObj.getStringAt(1); float x = areaObj.getFloatAt(2); float y = areaObj.getFloatAt(3); int tier = areaObj.getIntAt(5); int constant = areaObj.getIntAt(6); if (tier == UNDEFINEDAREA) return; float radius = 0; float width = 0; float height = 0; float innerRadius = 0; float outerRadius = 0; LuaObject areaShapeObject = areaObj.getObjectAt(4); if (areaShapeObject.isValidTable()) { if (areaShapeObject.getIntAt(1) == 1) { radius = areaShapeObject.getFloatAt(2); } else if (areaShapeObject.getIntAt(1) == 2) { width = areaShapeObject.getFloatAt(2); height = areaShapeObject.getFloatAt(3); } else if (areaShapeObject.getIntAt(1) == 3) { innerRadius = areaShapeObject.getFloatAt(2); outerRadius = areaShapeObject.getFloatAt(3); } areaShapeObject.pop(); } else { areaShapeObject.pop(); radius = areaObj.getFloatAt(4); width = 0; height = 0; } if (radius == 0 && width == 0 && height == 0 && innerRadius == 0 && outerRadius == 0) return; static const uint32 crc = STRING_HASHCODE("object/spawn_area.iff"); ManagedReference<SpawnArea*> area = dynamic_cast<SpawnArea*>(ObjectManager::instance()->createObject(crc, 0, "spawnareas")); if (area == NULL) return; Locker objLocker(area); StringId nameID(zone->getZoneName() + "_region_names", name); area->setObjectName(nameID); if (height > 0 && width > 0) { ManagedReference<RectangularAreaShape*> rectangularAreaShape = new RectangularAreaShape(); Locker shapeLocker(rectangularAreaShape); rectangularAreaShape->setAreaCenter(x, y); rectangularAreaShape->setDimensions(height, width); area->setAreaShape(rectangularAreaShape); } else if (radius > 0) { ManagedReference<CircularAreaShape*> circularAreaShape = new CircularAreaShape(); Locker shapeLocker(circularAreaShape); circularAreaShape->setAreaCenter(x, y); circularAreaShape->setRadius(radius); area->setAreaShape(circularAreaShape); } else if (innerRadius > 0 && outerRadius > 0) { ManagedReference<RingAreaShape*> ringAreaShape = new RingAreaShape(); Locker shapeLocker(ringAreaShape); ringAreaShape->setAreaCenter(x, y); ringAreaShape->setInnerRadius(innerRadius); ringAreaShape->setOuterRadius(outerRadius); area->setAreaShape(ringAreaShape); } else { ManagedReference<CircularAreaShape*> circularAreaShape = new CircularAreaShape(); Locker shapeLocker(circularAreaShape); circularAreaShape->setAreaCenter(x, y); circularAreaShape->setRadius(zone->getBoundingRadius()); area->setAreaShape(circularAreaShape); } area->setTier(tier); area->setSpawnConstant(constant); if (tier & SPAWNAREA) { area->setTemplate(areaObj.getStringAt(7).hashCode()); area->setMaxSpawnLimit(areaObj.getIntAt(8)); } if ((radius != -1) && !(tier & WORLDSPAWNAREA)) { zone->transferObject(area, -1, true); } else { if (tier & WORLDSPAWNAREA) { worldSpawnAreas.add(area); } area->setZone(zone); } area->updateToDatabase(); put(nameID.getStringID().hashCode(), area); if (tier & NOSPAWNAREA) { area->setNoSpawnArea(true); noSpawnAreas.add(area); } if (tier & NOBUILDZONEAREA) { area->setNoBuildArea(true); } }