/** Add a creature by template name to the roster list. */ bool Roster::addRosterMemberByTemplate(Common::UString name, Common::UString cTemplate) { // Disallow null strings if (name.size() == 0 || cTemplate.size() == 0) return false; // Don't permit duplicate roster names auto match = std::find_if(_members.begin(), _members.end(), [&](const Member &m) { return m.rosterName == name; }); if (match != _members.end()) return false; // A matching template file must exist if (!ResMan.hasResource(cTemplate, Aurora::kFileTypeUTC)) { // HACK: Check for custom unit test token "[GTEST]" at start if (!cTemplate.beginsWith("[GTEST]")) return false; } // Add roster member to the list Member member; member.rosterName = name; member.cTemplate = cTemplate; _members.push_back(member); // TODO: Template is not stored in ROSTER.rst, so load creature into game for saving, but don't spawn return true; }
UString FilePath::relativize(const UString &basePath, const UString &path) { const Common::UString normPath = normalize(path, false); const Common::UString normBase = normalize(basePath, false); UString relative = ""; if (normPath.beginsWith(normBase)) relative = normPath.substr(normPath.getPosition(normBase.size() + 1), normPath.end()); return relative; }
Common::UString FileTypeManager::getExtension(FileType type) { buildTypeLookup(); Common::UString ext; TypeLookup::const_iterator t = _typeLookup.find(type); if (t != _typeLookup.end()) ext = t->second->extension; if (ext.beginsWith(".")) ext.erase(ext.begin()); return ext; }
void Creature::loadPortrait(const Aurora::GFF3Struct &gff) { uint32 portraitID = gff.getUint("PortraitId"); if (portraitID != 0) { const Aurora::TwoDAFile &twoda = TwoDAReg.get2DA("portraits"); Common::UString portrait = twoda.getRow(portraitID).getString("BaseResRef"); if (!portrait.empty()) { if (portrait.beginsWith("po_")) _portrait = portrait; else _portrait = "po_" + portrait; } } _portrait = gff.getString("Portrait", _portrait); }
void Model_Witcher::load(ParserContext &ctx) { if (ctx.mdb->readByte() != 0) { ctx.mdb->seek(0); Common::UString type = Common::readString(*ctx.mdb, Common::kEncodingASCII); if (type.beginsWith("binarycompositemodel")) throw Common::Exception("TODO: binarycompositemodel"); throw Common::Exception("Not a The Witcher MDB file"); } ctx.mdb->seek(4); ctx.fileVersion = ctx.mdb->readUint32LE() & 0x0FFFFFFF; if ((ctx.fileVersion != 136) && (ctx.fileVersion != 133)) throw Common::Exception("Unknown The Witcher MDB version %d", ctx.fileVersion); uint32 modelCount = ctx.mdb->readUint32LE(); if (modelCount != 1) throw Common::Exception("Unsupported model count %d in The Witcher MDB", modelCount); ctx.mdb->skip(4); ctx.modelDataSize = ctx.mdb->readUint32LE(); ctx.mdb->skip(4); ctx.offModelData = 32; if (ctx.fileVersion == 133) { ctx.offRawData = ctx.mdb->readUint32LE() + ctx.offModelData; ctx.rawDataSize = ctx.mdb->readUint32LE(); ctx.offTexData = ctx.offModelData; ctx.texDatasize = 0; } else { ctx.offRawData = ctx.offModelData; ctx.rawDataSize = 0; ctx.offTexData = ctx.mdb->readUint32LE() + ctx.offModelData; ctx.texDatasize = ctx.mdb->readUint32LE(); } ctx.mdb->skip(8); _name = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64); uint32 offsetRootNode = ctx.mdb->readUint32LE(); ctx.mdb->skip(32); byte type = ctx.mdb->readByte(); ctx.mdb->skip(3); ctx.mdb->skip(48); float firstLOD = ctx.mdb->readIEEEFloatLE(); float lastLOD = ctx.mdb->readIEEEFloatLE(); ctx.mdb->skip(16); Common::UString detailMap = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64); ctx.mdb->skip(4); float modelScale = ctx.mdb->readIEEEFloatLE(); Common::UString superModel = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 64); ctx.mdb->skip(16); newState(ctx); ModelNode_Witcher *rootNode = new ModelNode_Witcher(*this); ctx.nodes.push_back(rootNode); ctx.mdb->seek(ctx.offModelData + offsetRootNode); rootNode->load(ctx); addState(ctx); }
void CharSpells::fixWidgetType(const Common::UString &tag, GUI::WidgetType &type) { if (tag.beginsWith("SpellLevel")) type = kWidgetTypeButton; }
void Model_Witcher::load(ParserContext &ctx) { if (ctx.mdb->readByte() != 0) { ctx.mdb->seek(0); Common::UString type; type.readASCII(*ctx.mdb); if (type.beginsWith("binarycompositemodel")) throw Common::Exception("TODO: binarycompositemodel"); throw Common::Exception("Not a The Witcher MDB file"); } ctx.mdb->seek(4); ctx.fileVersion = ctx.mdb->readUint16LE(); ctx.mdb->skip(10); ctx.modelDataSize = ctx.mdb->readUint32LE(); ctx.mdb->skip(4); ctx.offModelData = 32; if (ctx.fileVersion == 133) { ctx.offRawData = ctx.mdb->readUint32LE() + ctx.offModelData; ctx.rawDataSize = ctx.mdb->readUint32LE(); ctx.offTexData = ctx.offModelData; ctx.texDatasize = 0; } else { ctx.offRawData = ctx.offModelData; ctx.rawDataSize = 0; ctx.offTexData = ctx.mdb->readUint32LE() + ctx.offModelData; ctx.texDatasize = ctx.mdb->readUint32LE(); } ctx.mdb->skip(8); _name.readFixedASCII(*ctx.mdb, 64); uint32 offsetRootNode = ctx.mdb->readUint32LE(); ctx.mdb->skip(32); byte type = ctx.mdb->readByte(); ctx.mdb->skip(3); ctx.mdb->skip(48); float firstLOD = ctx.mdb->readIEEEFloatLE(); float lastLOD = ctx.mdb->readIEEEFloatLE(); ctx.mdb->skip(16); Common::UString detailMap; detailMap.readFixedASCII(*ctx.mdb, 64); ctx.mdb->skip(4); float scale = ctx.mdb->readIEEEFloatLE(); Common::UString superModel; superModel.readFixedASCII(*ctx.mdb, 64); ctx.mdb->skip(16); newState(ctx); ModelNode_Witcher *rootNode = new ModelNode_Witcher(*this); ctx.nodes.push_back(rootNode); ctx.mdb->seek(ctx.offModelData + offsetRootNode); rootNode->load(ctx); addState(ctx); }