void CMapInfo::ReadStartPos() { const float defX = 1000.0f; const float defZ = 1000.0f; const float defXStep = 100.0f; const float defZStep = 100.0f; const LuaTable teamsTable = mapRoot->SubTable("teams"); for (int t = 0; t < MAX_TEAMS; ++t) { float3 pos; pos.x = defX + (defXStep * t); pos.z = defZ + (defZStep * t); pos.y = 0.0f; const LuaTable posTable = teamsTable.SubTable(t).SubTable("startPos"); if (posTable.KeyExists("x") && posTable.KeyExists("z")) { pos.x = posTable.GetFloat("x", pos.x); pos.z = posTable.GetFloat("z", pos.z); havePos.push_back(true); } else { havePos.push_back(false); } startPos.push_back(pos); } }
void CArchiveScanner::ReadCacheData(const std::string& filename) { if (!FileSystem::FileExists(filename)) { LOG_L(L_INFO, "Archive cache doesn't exist: %s", filename.c_str()); return; } LuaParser p(filename, SPRING_VFS_RAW, SPRING_VFS_BASE); if (!p.Execute()) { LOG_L(L_ERROR, "Failed to parse archive cache: %s", p.GetErrorLog().c_str()); return; } const LuaTable archiveCache = p.GetRoot(); // Do not load old version caches const int ver = archiveCache.GetInt("internalVer", (INTERNAL_VER + 1)); if (ver != INTERNAL_VER) { return; } const LuaTable archives = archiveCache.SubTable("archives"); for (int i = 1; archives.KeyExists(i); ++i) { const LuaTable curArchive = archives.SubTable(i); const LuaTable archived = curArchive.SubTable("archivedata"); std::string name = curArchive.GetString("name", ""); ArchiveInfo& ai = archiveInfos[StringToLower(name)]; ai.origName = name; ai.path = curArchive.GetString("path", ""); // do not use LuaTable.GetInt() for 32-bit integers, the Spring lua // library uses 32-bit floats to represent numbers, which can only // represent 2^24 consecutive integers ai.modified = strtoul(curArchive.GetString("modified", "0").c_str(), 0, 10); ai.checksum = strtoul(curArchive.GetString("checksum", "0").c_str(), 0, 10); ai.updated = false; ai.archiveData = CArchiveScanner::ArchiveData(archived, true); if (ai.archiveData.GetModType() == modtype::map) { AddDependency(ai.archiveData.GetDependencies(), "Map Helper v1"); } else if (ai.archiveData.GetModType() == modtype::primary) { AddDependency(ai.archiveData.GetDependencies(), "Spring content v1"); } } const LuaTable brokenArchives = archiveCache.SubTable("brokenArchives"); for (int i = 1; brokenArchives.KeyExists(i); ++i) { const LuaTable curArchive = brokenArchives.SubTable(i); std::string name = curArchive.GetString("name", ""); StringToLowerInPlace(name); BrokenArchive& ba = this->brokenArchives[name]; ba.path = curArchive.GetString("path", ""); ba.modified = strtoul(curArchive.GetString("modified", "0").c_str(), 0, 10); ba.updated = false; ba.problem = curArchive.GetString("problem", "unknown"); } isDirty = false; }
void CMapInfo::ReadSmf() { // SMF specific settings const LuaTable mapResTable = parser->GetRoot().SubTable("resources"); smf.detailTexName = mapResTable.GetString("detailTex", ""); smf.specularTexName = mapResTable.GetString("specularTex", ""); smf.splatDetailTexName = mapResTable.GetString("splatDetailTex", ""); smf.splatDistrTexName = mapResTable.GetString("splatDistrTex", ""); smf.grassBladeTexName = mapResTable.GetString("grassBladeTex", ""); smf.grassShadingTexName = mapResTable.GetString("grassShadingTex", ""); smf.skyReflectModTexName = mapResTable.GetString("skyReflectModTex", ""); smf.detailNormalTexName = mapResTable.GetString("detailNormalTex", ""); smf.lightEmissionTexName = mapResTable.GetString("lightEmissionTex", ""); if (!smf.detailTexName.empty()) { smf.detailTexName = "maps/" + smf.detailTexName; } else { const LuaTable& resGfxMaps = resRoot->SubTable("graphics").SubTable("maps"); smf.detailTexName = resGfxMaps.GetString("detailtex", "detailtex2.bmp"); smf.detailTexName = "bitmaps/" + smf.detailTexName; } if (!smf.specularTexName.empty()) { smf.specularTexName = "maps/" + smf.specularTexName; } if (!smf.splatDetailTexName.empty()) { smf.splatDetailTexName = "maps/" + smf.splatDetailTexName; } if (!smf.splatDistrTexName.empty()) { smf.splatDistrTexName = "maps/" + smf.splatDistrTexName; } if (!smf.grassBladeTexName.empty()) { smf.grassBladeTexName = "maps/" + smf.grassBladeTexName; } if (!smf.grassShadingTexName.empty()) { smf.grassShadingTexName = "maps/" + smf.grassShadingTexName; } if (!smf.skyReflectModTexName.empty()) { smf.skyReflectModTexName = "maps/" + smf.skyReflectModTexName; } if (!smf.detailNormalTexName.empty()) { smf.detailNormalTexName = "maps/" + smf.detailNormalTexName; } if (!smf.lightEmissionTexName.empty()) { smf.lightEmissionTexName = "maps/" + smf.lightEmissionTexName; } // height overrides const LuaTable smfTable = parser->GetRoot().SubTable("smf"); smf.minHeightOverride = smfTable.KeyExists("minHeight"); smf.maxHeightOverride = smfTable.KeyExists("maxHeight"); smf.minHeight = smfTable.GetFloat("minHeight", 0.0f); smf.maxHeight = smfTable.GetFloat("maxHeight", 0.0f); std::stringstream ss; for (int i = 0; /* no test */; i++) { ss.str(""); ss << "smtFileName" << i; if (smfTable.KeyExists(ss.str())) { smf.smtFileNames.push_back(smfTable.GetString(ss.str(), ".smt")); } else { break; } } }
void CAssParser::SetPieceParentName( SAssPiece* piece, const S3DModel* model, const aiNode* pieceNode, const LuaTable& pieceTable, ParentNameMap& parentMap ) { // Get parent name from metadata or model if (pieceTable.KeyExists("parent")) { parentMap[piece] = pieceTable.GetString("parent", ""); return; } if (pieceNode->mParent == nullptr) return; if (pieceNode->mParent->mParent != nullptr) { // parent is not the root parentMap[piece] = std::string(pieceNode->mParent->mName.data); } else { // parent is the root (which must already exist) assert(model->GetRootPiece() != nullptr); parentMap[piece] = (model->GetRootPiece())->name; } }
void option_parseMapOptions( std::vector<Option>& options, const std::string& fileName, const std::string& mapName, const std::string& fileModes, const std::string& accessModes, std::set<std::string>* optionsSet) { LuaParser luaParser(fileName, fileModes, accessModes); const string mapFile = archiveScanner->MapNameToMapFile(mapName); const string configName = MapParser::GetMapConfigName(mapFile); if (mapName.empty()) throw "Missing map name!"; if (configName.empty()) throw "Could not determine config-file name from the map name '" + mapName + "'!"; luaParser.GetTable("Map"); luaParser.AddString("name", mapName); luaParser.AddString("fileName", FileSystem::GetFilename(mapFile)); luaParser.AddString("fullName", mapFile); luaParser.AddString("configFile", configName); luaParser.EndTable(); if (!luaParser.Execute()) { throw content_error("luaParser.Execute() failed: " + luaParser.GetErrorLog()); } const LuaTable root = luaParser.GetRoot(); if (!root.IsValid()) { throw content_error("root table invalid"); } std::set<std::string>* myOptionsSet = NULL; if (optionsSet == NULL) { myOptionsSet = new std::set<std::string>(); } else { myOptionsSet = optionsSet; } for (int index = 1; root.KeyExists(index); index++) { Option opt; try { option_parseOption(root, index, opt, *myOptionsSet); options.push_back(opt); } catch (const content_error& err) { LOG_L(L_WARNING, "Failed parsing map-option %d from %s for map %s: %s", index, fileName.c_str(), mapName.c_str(), err.what()); } } if (optionsSet == NULL) { delete myOptionsSet; myOptionsSet = NULL; } }
void parseMapOptions( std::vector<Option>& options, const std::string& fileName, const std::string& mapName, const std::string& fileModes, const std::string& accessModes, std::set<std::string>* optionsSet, CLogSubsystem* logSubsystem) { if (!logSubsystem) { assert(logSubsystem); } LuaParser luaParser(fileName, fileModes, accessModes); const string configName = MapParser::GetMapConfigName(mapName); const string mapFile = archiveScanner->MapNameToMapFile(mapName); if (mapName.empty()) throw "Missing map name!"; if (configName.empty()) throw "Couldn't determine config filename from the map name '" + mapName + "'!"; luaParser.GetTable("Map"); luaParser.AddString("name", mapName); luaParser.AddString("fileName", filesystem.GetFilename(mapFile)); luaParser.AddString("fullName", mapFile); luaParser.AddString("configFile", configName); luaParser.EndTable(); if (!luaParser.Execute()) { throw content_error("luaParser.Execute() failed: " + luaParser.GetErrorLog()); } const LuaTable root = luaParser.GetRoot(); if (!root.IsValid()) { throw content_error("root table invalid"); } std::set<std::string>* myOptionsSet = NULL; if (optionsSet == NULL) { myOptionsSet = new std::set<std::string>(); } else { myOptionsSet = optionsSet; } for (int index = 1; root.KeyExists(index); index++) { Option opt; if (parseOption(root, index, opt, *myOptionsSet, *logSubsystem)) { options.push_back(opt); } } if (optionsSet == NULL) { delete myOptionsSet; myOptionsSet = NULL; } }
bool CSound::LoadSoundDefs(const std::string& filename) { //! can be called from LuaUnsyncedCtrl too boost::mutex::scoped_lock lck(soundMutex); LuaParser parser(filename, SPRING_VFS_MOD, SPRING_VFS_ZIP); parser.SetLowerKeys(false); parser.SetLowerCppKeys(false); parser.Execute(); if (!parser.IsValid()) { LogObject(LOG_SOUND) << "Could not load " << filename << ": " << parser.GetErrorLog(); return false; } else { const LuaTable soundRoot = parser.GetRoot(); const LuaTable soundItemTable = soundRoot.SubTable("SoundItems"); if (!soundItemTable.IsValid()) { LogObject(LOG_SOUND) << "CSound(): could not parse SoundItems table in " << filename; return false; } else { std::vector<std::string> keys; soundItemTable.GetKeys(keys); for (std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it) { const std::string name(*it); soundItemDef bufmap; const LuaTable buf(soundItemTable.SubTable(*it)); buf.GetMap(bufmap); bufmap["name"] = name; soundItemDefMap::const_iterator sit = soundItemDefs.find(name); if (sit != soundItemDefs.end()) LogObject(LOG_SOUND) << "CSound(): two SoundItems have the same name: " << name; soundItemDef::const_iterator inspec = bufmap.find("file"); if (inspec == bufmap.end()) // no file, drop LogObject(LOG_SOUND) << "CSound(): SoundItem has no file tag: " << name; else soundItemDefs[name] = bufmap; if (buf.KeyExists("preload")) { LogObject(LOG_SOUND) << "CSound(): preloading " << name; const size_t newid = sounds.size(); sounds.push_back(new SoundItem(GetWaveBuffer(bufmap["file"], true), bufmap)); soundMap[name] = newid; } } LogObject(LOG_SOUND) << "CSound(): Sucessfully parsed " << keys.size() << " SoundItems from " << filename; } } return true; }
CArchiveScanner::ArchiveData CArchiveScanner::GetArchiveData(const LuaTable& archiveTable) { ArchiveData md; if (!archiveTable.IsValid()) { return md; } md.name = archiveTable.GetString("name", ""); md.shortName = archiveTable.GetString("shortName", ""); md.version = archiveTable.GetString("version", ""); md.mutator = archiveTable.GetString("mutator", ""); md.game = archiveTable.GetString("game", ""); md.shortGame = archiveTable.GetString("shortGame", ""); md.description = archiveTable.GetString("description", ""); md.modType = archiveTable.GetInt("modType", 0); md.mapfile = archiveTable.GetString("mapfile", ""); const LuaTable dependencies = archiveTable.SubTable("depend"); for (int dep = 1; dependencies.KeyExists(dep); ++dep) { const std::string depend = dependencies.GetString(dep, ""); md.dependencies.push_back(depend); } const LuaTable replaces = archiveTable.SubTable("replace"); for (int rep = 1; replaces.KeyExists(rep); ++rep) { md.replaces.push_back(replaces.GetString(rep, "")); } // HACK needed until lobbies, lobbyserver and unitsync are sorted out // so they can uniquely identify different versions of the same mod. // (at time of this writing they use name only) // NOTE when changing this, this function is used both by the code that // reads ArchiveCache.lua and the code that reads modinfo.lua from the mod. // so make sure it doesn't keep adding stuff to the name everytime // Spring/unitsync is loaded. if (md.name.find(md.version) == std::string::npos && !md.version.empty()) { md.name += " " + md.version; } return md; }
bool CSound::LoadSoundDefs(const std::string& fileName) { //! can be called from LuaUnsyncedCtrl too boost::recursive_mutex::scoped_lock lck(soundMutex); LuaParser parser(fileName, SPRING_VFS_MOD, SPRING_VFS_ZIP); parser.SetLowerKeys(false); parser.SetLowerCppKeys(false); parser.Execute(); if (!parser.IsValid()) { LOG_L(L_WARNING, "Could not load %s: %s", fileName.c_str(), parser.GetErrorLog().c_str()); return false; } else { const LuaTable soundRoot = parser.GetRoot(); const LuaTable soundItemTable = soundRoot.SubTable("SoundItems"); if (!soundItemTable.IsValid()) { LOG_L(L_WARNING, "CSound(): could not parse SoundItems table in %s", fileName.c_str()); return false; } else { std::vector<std::string> keys; soundItemTable.GetKeys(keys); for (std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it) { const std::string name(*it); soundItemDef bufmap; const LuaTable buf(soundItemTable.SubTable(*it)); buf.GetMap(bufmap); bufmap["name"] = name; soundItemDefMap::const_iterator sit = soundItemDefs.find(name); if (sit != soundItemDefs.end()) LOG_L(L_WARNING, "Sound %s gets overwritten by %s", name.c_str(), fileName.c_str()); soundItemDef::const_iterator inspec = bufmap.find("file"); if (inspec == bufmap.end()) { // no file, drop LOG_L(L_WARNING, "Sound %s is missing file tag (ignoring)", name.c_str()); } else { soundItemDefs[name] = bufmap; } if (buf.KeyExists("preload")) { MakeItemFromDef(bufmap); } } LOG(" parsed %i sounds from %s", (int)keys.size(), fileName.c_str()); } } return true; }
void parseOptions( std::vector<Option>& options, const std::string& fileName, const std::string& fileModes, const std::string& accessModes, const std::string& mapName, std::set<std::string>* optionsSet, CLogSubsystem* logSubsystem) { if (!logSubsystem) { assert(logSubsystem); } LuaParser luaParser(fileName, fileModes, accessModes); const string configName = MapParser::GetMapConfigName(mapName); if (!mapName.empty() && !configName.empty()) { luaParser.GetTable("Map"); luaParser.AddString("fileName", mapName); luaParser.AddString("fullName", "maps/" + mapName); luaParser.AddString("configFile", configName); luaParser.EndTable(); } if (!luaParser.Execute()) { throw content_error("luaParser.Execute() failed: " + luaParser.GetErrorLog()); } const LuaTable root = luaParser.GetRoot(); if (!root.IsValid()) { throw content_error("root table invalid"); } std::set<std::string>* myOptionsSet = NULL; if (optionsSet == NULL) { myOptionsSet = new std::set<std::string>(); } else { myOptionsSet = optionsSet; } for (int index = 1; root.KeyExists(index); index++) { Option opt; if (parseOption(root, index, opt, *myOptionsSet, *logSubsystem)) { options.push_back(opt); } } if (optionsSet == NULL) { delete myOptionsSet; myOptionsSet = NULL; } }
void parseOptions( std::vector<Option>& options, const std::string& fileName, const std::string& fileModes, const std::string& accessModes, std::set<std::string>* optionsSet, CLogSubsystem* logSubsystem) { if (!logSubsystem) { assert(logSubsystem); } LuaParser luaParser(fileName, fileModes, accessModes); if (!luaParser.Execute()) { throw content_error("luaParser.Execute() failed: " + luaParser.GetErrorLog()); } const LuaTable root = luaParser.GetRoot(); if (!root.IsValid()) { throw content_error("root table invalid"); } std::set<std::string>* myOptionsSet = NULL; if (optionsSet == NULL) { myOptionsSet = new std::set<std::string>(); } else { myOptionsSet = optionsSet; } for (int index = 1; root.KeyExists(index); index++) { Option opt; try { parseOption(root, index, opt, *myOptionsSet); options.push_back(opt); } catch (content_error& err) { logOutput.Print(*logSubsystem, "Failed parsing option %d from %s: %s", index, fileName.c_str(), err.what()); } } if (optionsSet == NULL) { delete myOptionsSet; myOptionsSet = NULL; } }
void CArchiveScanner::ReadCacheData(const string& filename) { LuaParser p(filename, SPRING_VFS_RAW, SPRING_VFS_BASE); if (!p.Execute()) { logOutput.Print("ERROR in " + filename + ": " + p.GetErrorLog()); } const LuaTable archiveCache = p.GetRoot(); const LuaTable archives = archiveCache.SubTable("archives"); // Do not load old version caches const int ver = archiveCache.GetInt("internalVer", (INTERNAL_VER + 1)); if (ver != INTERNAL_VER) { return; } for (int i = 1; archives.KeyExists(i); ++i) { const LuaTable curArchive = archives.SubTable(i); const LuaTable archived = curArchive.SubTable("archivedata"); ArchiveInfo ai; ai.origName = curArchive.GetString("name", ""); ai.path = curArchive.GetString("path", ""); // do not use LuaTable.GetInt() for 32-bit integers, the Spring lua // library uses 32-bit floats to represent numbers, which can only // represent 2^24 consecutive integers ai.modified = strtoul(curArchive.GetString("modified", "0").c_str(), 0, 10); ai.checksum = strtoul(curArchive.GetString("checksum", "0").c_str(), 0, 10); ai.updated = false; ai.archiveData = GetArchiveData(archived); if (ai.archiveData.modType == modtype::map) AddDependency(ai.archiveData.dependencies, "maphelper.sdz"); else if (ai.archiveData.modType == modtype::primary) AddDependency(ai.archiveData.dependencies, "Spring content v1"); string lcname = StringToLower(ai.origName); archiveInfo[lcname] = ai; } isDirty = false; }
void CAssParser::SetPieceParentName( SAssPiece* piece, const S3DModel* model, const aiNode* pieceNode, const LuaTable& pieceTable ) { // Get parent name from metadata or model if (pieceTable.KeyExists("parent")) { piece->parentName = pieceTable.GetString("parent", ""); } else if (pieceNode->mParent != NULL) { if (pieceNode->mParent->mParent != NULL) { piece->parentName = std::string(pieceNode->mParent->mName.data); } else { // my parent is the root (which must already exist) assert(model->GetRootPiece() != NULL); piece->parentName = model->GetRootPiece()->name; } } }
void CMapInfo::ReadSmf() { // SMF specific settings const LuaTable mapResTable = mapRoot->SubTable("resources"); smf.detailTexName = mapResTable.GetString("detailTex", ""); if (!smf.detailTexName.empty()) { smf.detailTexName = "maps/" + smf.detailTexName; } else { const LuaTable resGfxMaps = resRoot->SubTable("graphics").SubTable("maps"); smf.detailTexName = resGfxMaps.GetString("detailtex", "detailtex2.bmp"); smf.detailTexName = "bitmaps/" + smf.detailTexName; } // height overrides const LuaTable smfTable = mapRoot->SubTable("smf"); smf.minHeightOverride = smfTable.KeyExists("minHeight"); smf.maxHeightOverride = smfTable.KeyExists("maxHeight"); smf.minHeight = smfTable.GetFloat("minHeight", 0.0f); smf.maxHeight = smfTable.GetFloat("maxHeight", 0.0f); }
static void option_parseOptionsInternal( std::vector<Option>& options, LuaParser& luaParser, const std::string& luaSourceDesc, std::set<std::string>* optionsSet) { if (!luaParser.Execute()) { throw content_error("luaParser.Execute() failed: " + luaParser.GetErrorLog()); } const LuaTable root = luaParser.GetRoot(); if (!root.IsValid()) { throw content_error("root table invalid"); } std::set<std::string>* myOptionsSet = NULL; if (optionsSet == NULL) { myOptionsSet = new std::set<std::string>(); } else { myOptionsSet = optionsSet; } for (int index = 1; root.KeyExists(index); index++) { Option opt; try { option_parseOption(root, index, opt, *myOptionsSet); options.push_back(opt); } catch (const content_error& err) { LOG_L(L_WARNING, "Failed parsing option %d from %s: %s", index, luaSourceDesc.c_str(), err.what()); } } if (optionsSet == NULL) { delete myOptionsSet; myOptionsSet = NULL; } }
void info_parseInfo( std::vector<InfoItem>& info, const std::string& fileName, const std::string& fileModes, const std::string& accessModes, std::set<std::string>* infoSet) { LuaParser luaParser(fileName, fileModes, accessModes); if (!luaParser.Execute()) { throw content_error("luaParser.Execute() failed: " + luaParser.GetErrorLog()); } const LuaTable root = luaParser.GetRoot(); if (!root.IsValid()) { throw content_error("root table invalid"); } std::set<std::string>* myInfoSet = NULL; if (infoSet == NULL) { myInfoSet = new std::set<std::string>(); } else { myInfoSet = infoSet; } for (int index = 1; root.KeyExists(index); index++) { InfoItem inf; if (info_parseInfoItem(root, index, inf, *myInfoSet)) { info.push_back(inf); } } if (infoSet == NULL) { delete myInfoSet; myInfoSet = NULL; } }
bool CAssParser::SetModelRadiusAndHeight( S3DModel* model, const SAssPiece* piece, const aiNode* pieceNode, const LuaTable& pieceTable ) { // check if this piece is "special" (ie, used to set Spring model properties) // if so, extract them and then remove the piece from the hierarchy entirely // if (piece->name == "SpringHeight") { // set the model height to this node's Y-value (FIXME: 'y' is Assimp/Blender-specific) if (!pieceTable.KeyExists("height")) { model->height = piece->offset.y; LOG_SL(LOG_SECTION_MODEL, L_INFO, "Model height of %f set by special node 'SpringHeight'", model->height); } --model->numPieces; delete piece; return true; } if (piece->name == "SpringRadius") { if (!pieceTable.KeyExists("midpos")) { CMatrix44f scaleRotMat; piece->ComposeTransform(scaleRotMat, ZeroVector, ZeroVector, piece->scales); // NOTE: // this makes little sense because the "SpringRadius" // piece can be placed anywhere within the hierarchy model->relMidPos = scaleRotMat.Mul(piece->offset); LOG_SL(LOG_SECTION_MODEL, L_INFO, "Model midpos of (%f,%f,%f) set by special node 'SpringRadius'", model->relMidPos.x, model->relMidPos.y, model->relMidPos.z); } if (!pieceTable.KeyExists("radius")) { if (true || piece->maxs.x <= 0.00001f) { // scales have been set at this point // the Blender import script only sets the scale property [?] // // model->radius = piece->scales.Length(); model->radius = piece->scales.x; } else { // FIXME: // geometry bounds are calculated by LoadPieceGeometry // which is called after SetModelRadiusAndHeight -> can // not take this branch yet // use the transformed mesh extents (FIXME: the bounds are NOT // actually transformed but derived from raw vertex positions!) // // model->radius = ((piece->maxs - piece->mins) * 0.5f).Length(); model->radius = piece->maxs.x; } LOG_SL(LOG_SECTION_MODEL, L_INFO, "Model radius of %f set by special node 'SpringRadius'", model->radius); } --model->numPieces; delete piece; return true; } return false; }
void CMapInfo::ReadWater() { const LuaTable wt = mapRoot->SubTable("water"); water.repeatX = wt.GetFloat("repeatX", 0.0f); water.repeatY = wt.GetFloat("repeatY", 0.0f); water.damage = wt.GetFloat("damage", 0.0f) * (16.0f / 30.0f); water.absorb = wt.GetFloat3("absorb", float3(0.0f, 0.0f, 0.0f)); water.baseColor = wt.GetFloat3("baseColor", float3(0.0f, 0.0f, 0.0f)); water.minColor = wt.GetFloat3("minColor", float3(0.0f, 0.0f, 0.0f)); water.surfaceColor = wt.GetFloat3("surfaceColor", float3(0.75f, 0.8f, 0.85f)); water.surfaceAlpha = wt.GetFloat("surfaceAlpha", 0.55f); water.planeColor = wt.GetFloat3("planeColor", float3(0.0f, 0.4f, 0.0f)); hasWaterPlane = wt.KeyExists("planeColor"); water.specularColor = wt.GetFloat3("specularColor", light.groundSunColor); water.specularFactor = wt.GetFloat("specularFactor", 20.0f); water.fresnelMin = wt.GetFloat("fresnelMin", 0.2f); water.fresnelMax = wt.GetFloat("fresnelMax", 0.3f); water.fresnelPower = wt.GetFloat("fresnelPower", 4.0f); water.texture = wt.GetString("texture", ""); water.foamTexture = wt.GetString("foamTexture", ""); water.normalTexture = wt.GetString("normalTexture", ""); // use 'resources.lua' for missing fields (our the engine defaults) const LuaTable resGfxMaps = resRoot->SubTable("graphics").SubTable("maps"); if (!water.texture.empty()) { water.texture = "maps/" + water.texture; } else { water.texture = "bitmaps/" + resGfxMaps.GetString("watertex", "ocean.jpg"); } if (!water.foamTexture.empty()) { water.foamTexture = "maps/" + water.foamTexture; } else { water.foamTexture = "bitmaps/" + resGfxMaps.GetString("waterfoamtex", "foam.jpg"); } if (!water.normalTexture.empty()) { water.normalTexture = "maps/" + water.normalTexture; } else { water.normalTexture = "bitmaps/" + resGfxMaps.GetString("waternormaltex", "waterbump.png"); } // water caustic textures LuaTable caustics = wt.SubTable("caustics"); string causticPrefix = "maps/"; if (!caustics.IsValid()) { caustics = resRoot->SubTable("graphics").SubTable("caustics"); causticPrefix = "bitmaps/"; } if (caustics.IsValid()) { for (int i = 1; true; i++) { const string texName = caustics.GetString(i, ""); if (texName.empty()) { break; } water.causticTextures.push_back(causticPrefix + texName); } } else { // load the default 32 textures for (int i = 0; i < 32; i++) { char defTex[256]; sprintf(defTex, "bitmaps/caustics/caustic%02i.jpg", i); water.causticTextures.push_back(defTex); } } }
void CMapInfo::ReadWater() { const LuaTable wt = mapRoot->SubTable("water"); water.repeatX = wt.GetFloat("repeatX", 0.0f); water.repeatY = wt.GetFloat("repeatY", 0.0f); water.damage = wt.GetFloat("damage", 0.0f) * (16.0f / 30.0f); water.absorb = wt.GetFloat3("absorb", float3(0.0f, 0.0f, 0.0f)); water.baseColor = wt.GetFloat3("baseColor", float3(0.0f, 0.0f, 0.0f)); water.minColor = wt.GetFloat3("minColor", float3(0.0f, 0.0f, 0.0f)); water.ambientFactor = wt.GetFloat("ambientFactor", 1.0f); water.diffuseFactor = wt.GetFloat("diffuseFactor", 1.0f); water.specularFactor= wt.GetFloat("specularFactor",1.0f); water.specularPower = wt.GetFloat("specularPower", 20.0f); water.planeColor = wt.GetFloat3("planeColor", float3(0.0f, 0.4f, 0.0f)); water.hasWaterPlane = wt.KeyExists("planeColor"); water.surfaceColor = wt.GetFloat3("surfaceColor", float3(0.75f, 0.8f, 0.85f)); water.surfaceAlpha = wt.GetFloat("surfaceAlpha", 0.55f); water.diffuseColor = wt.GetFloat3("diffuseColor", float3(1.0f, 1.0f, 1.0f)); water.specularColor = wt.GetFloat3("specularColor", light.groundSunColor); water.fresnelMin = wt.GetFloat("fresnelMin", 0.2f); water.fresnelMax = wt.GetFloat("fresnelMax", 0.8f); water.fresnelPower = wt.GetFloat("fresnelPower", 4.0f); water.reflDistortion = wt.GetFloat("reflectionDistortion", 1.0f); water.blurBase = wt.GetFloat("blurBase", 2.0f); water.blurExponent = wt.GetFloat("blurExponent", 1.5f); water.perlinStartFreq = wt.GetFloat("perlinStartFreq", 8.0f); water.perlinLacunarity = wt.GetFloat("perlinLacunarity", 3.0f); water.perlinAmplitude = wt.GetFloat("perlinAmplitude", 0.9f); water.windSpeed = wt.GetFloat("windSpeed", 1.0f); water.texture = wt.GetString("texture", ""); water.foamTexture = wt.GetString("foamTexture", ""); water.normalTexture = wt.GetString("normalTexture", ""); water.shoreWaves = wt.GetBool("shoreWaves", true); water.forceRendering = wt.GetBool("forceRendering", false); // use 'resources.lua' for missing fields (our the engine defaults) const LuaTable resGfxMaps = resRoot->SubTable("graphics").SubTable("maps"); if (!water.texture.empty()) { water.texture = "maps/" + water.texture; } else { water.texture = "bitmaps/" + resGfxMaps.GetString("watertex", "ocean.jpg"); } if (!water.foamTexture.empty()) { water.foamTexture = "maps/" + water.foamTexture; } else { water.foamTexture = "bitmaps/" + resGfxMaps.GetString("waterfoamtex", "foam.jpg"); } if (!water.normalTexture.empty()) { water.normalTexture = "maps/" + water.normalTexture; water.numTiles = std::min(16,std::max(1,wt.GetInt("numTiles",1))); } else { water.normalTexture = "bitmaps/" + resGfxMaps.GetString("waternormaltex", "waterbump.png"); if (resGfxMaps.KeyExists("waternormaltex")) { water.numTiles = std::min(16,std::max(1,resGfxMaps.GetInt("numTiles",1))); }else{ // default texture is a TileSet of 3x3 // user-defined textures are expected to be 1x1 (no DynWaves possible) water.numTiles = 3; } } // water caustic textures LuaTable caustics = wt.SubTable("caustics"); string causticPrefix = "maps/"; if (!caustics.IsValid()) { caustics = resRoot->SubTable("graphics").SubTable("caustics"); causticPrefix = "bitmaps/"; } if (caustics.IsValid()) { for (int i = 1; true; i++) { const string texName = caustics.GetString(i, ""); if (texName.empty()) { break; } water.causticTextures.push_back(causticPrefix + texName); } } else { // load the default 32 textures for (int i = 0; i < 32; i++) { char defTex[256]; sprintf(defTex, "bitmaps/caustics/caustic%02i.jpg", i); water.causticTextures.push_back(defTex); } } }
WeaponDef::WeaponDef(const LuaTable& wdTable, const std::string& name_, int id_) : name(name_) , ptrailExplosionGeneratorID(CExplosionGeneratorHandler::EXPGEN_ID_INVALID) , impactExplosionGeneratorID(CExplosionGeneratorHandler::EXPGEN_ID_STANDARD) , bounceExplosionGeneratorID(CExplosionGeneratorHandler::EXPGEN_ID_INVALID) , id(id_) , projectileType(WEAPON_BASE_PROJECTILE) , collisionFlags(0) { WeaponDefs.Load(this, wdTable); if (wdTable.KeyExists("cylinderTargetting")) LOG_L(L_WARNING, "WeaponDef (%s) cylinderTargetting is deprecated and will be removed in the next release (use cylinderTargeting).", name.c_str()); if (wdTable.KeyExists("color1") || wdTable.KeyExists("color2")) LOG_L(L_WARNING, "WeaponDef (%s) color1 & color2 (= hue & sat) are removed. Use rgbColor instead!", name.c_str()); if (wdTable.KeyExists("isShield")) LOG_L(L_WARNING, "WeaponDef (%s) The \"isShield\" tag has been removed. Use the weaponType=\"Shield\" tag instead!", name.c_str()); shieldRechargeDelay = int(wdTable.GetFloat("rechargeDelay", 0) * GAME_SPEED); shieldArmorType = damageArrayHandler->GetTypeFromName(shieldArmorTypeName); flighttime = int(wdTable.GetFloat("flighttime", 0.0f) * 32); maxFireAngle = math::cos(wdTable.GetFloat("firetolerance", 3640.0f) * TAANG2RAD); //FIXME may be smarter to merge the collideXYZ tags with avoidXYZ and removing the collisionFlags tag (and move the code into CWeapon)? collisionFlags = 0; if (!wdTable.GetBool("collideEnemy", true)) { collisionFlags |= Collision::NOENEMIES; } if (!wdTable.GetBool("collideFriendly", true)) { collisionFlags |= Collision::NOFRIENDLIES; } if (!wdTable.GetBool("collideFeature", true)) { collisionFlags |= Collision::NOFEATURES; } if (!wdTable.GetBool("collideNeutral", true)) { collisionFlags |= Collision::NONEUTRALS; } if (!wdTable.GetBool("collideGround", true)) { collisionFlags |= Collision::NOGROUND; } //FIXME defaults depend on other tags { if (paralyzer) cameraShake = wdTable.GetFloat("cameraShake", 0.0f); if (selfExplode) predictBoost = wdTable.GetFloat("predictBoost", 0.5f); if (type == "Melee") { targetBorder = Clamp(wdTable.GetFloat("targetBorder", 1.0f), -1.0f, 1.0f); cylinderTargeting = Clamp(wdTable.GetFloat("cylinderTargeting", wdTable.GetFloat("cylinderTargetting", 1.0f)), 0.0f, 128.0f); } if (type == "Flame") { //FIXME move to lua (for all other weapons this tag is named `duration` and has a different default) duration = wdTable.GetFloat("flameGfxTime", 1.2f); } if (type == "Cannon") { heightmod = wdTable.GetFloat("heightMod", 0.8f); } else if (type == "BeamLaser" || type == "LightningCannon") { heightmod = wdTable.GetFloat("heightMod", 1.0f); } if (type == "LaserCannon") { // for lasers we want this to be true by default: it sets // projectile ttl values to the minimum required to hit a // target which prevents them overshooting (lasers travel // many elmos per frame and ttl's are rounded) at maximum // range selfExplode = wdTable.GetBool("burnblow", true); } } // setup the default damages { const LuaTable dmgTable = wdTable.SubTable("damage"); float defDamage = dmgTable.GetFloat("default", 1.0f); // avoid division by zeros if (defDamage == 0.0f) defDamage = 1.0f; damages.SetDefaultDamage(defDamage); if (!paralyzer) damages.paralyzeDamageTime = 0; std::map<string, float> dmgs; std::map<string, float>::const_iterator di; dmgTable.GetMap(dmgs); for (di = dmgs.begin(); di != dmgs.end(); ++di) { const int type = damageArrayHandler->GetTypeFromName(di->first); if (type != 0) { float dmg = di->second; if (dmg != 0.0f) { damages[type] = dmg; } else { damages[type] = 1.0f; } } } const float tempsize = 2.0f + std::min(defDamage * 0.0025f, damageAreaOfEffect * 0.1f); const float gd = std::max(30.0f, defDamage / 20.0f); const float defExpSpeed = (8.0f + (gd * 2.5f)) / (9.0f + (math::sqrt(gd) * 0.7f)) * 0.5f; size = wdTable.GetFloat("size", tempsize); explosionSpeed = wdTable.GetFloat("explosionSpeed", defExpSpeed); } { // 0.78.2.1 backwards compatibility: non-burst beamlasers play one // sample per shot, not for each individual beam making up the shot const bool singleSampleShot = (type == "BeamLaser" && !beamburst); const bool singleShotWeapon = (type == "Melee" || type == "Rifle"); soundTrigger = wdTable.GetBool("soundTrigger", singleSampleShot || singleShotWeapon); } // get some weapon specific defaults int defInterceptType = 0; if (type == "Cannon") { // CExplosiveProjectile defInterceptType = 1; projectileType = WEAPON_EXPLOSIVE_PROJECTILE; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.9f); intensity = wdTable.GetFloat("intensity", 0.2f); } else if (type == "Rifle") { // no projectile or intercept type defInterceptType = 128; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.9f); } else if (type == "Melee") { // no projectile or intercept type defInterceptType = 256; } else if (type == "Flame") { // CFlameProjectile projectileType = WEAPON_FLAME_PROJECTILE; defInterceptType = 16; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.2f); collisionSize = wdTable.GetFloat("collisionSize", 0.5f); } else if (type == "MissileLauncher") { // CMissileProjectile projectileType = WEAPON_MISSILE_PROJECTILE; defInterceptType = 4; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.5f); } else if (type == "LaserCannon") { // CLaserProjectile projectileType = WEAPON_LASER_PROJECTILE; defInterceptType = 2; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.7f); collisionSize = wdTable.GetFloat("collisionSize", 0.5f); } else if (type == "BeamLaser") { projectileType = largeBeamLaser? WEAPON_LARGEBEAMLASER_PROJECTILE: WEAPON_BEAMLASER_PROJECTILE; defInterceptType = 2; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.7f); } else if (type == "LightningCannon") { projectileType = WEAPON_LIGHTNING_PROJECTILE; defInterceptType = 64; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.5f); } else if (type == "EmgCannon") { // CEmgProjectile projectileType = WEAPON_EMG_PROJECTILE; defInterceptType = 1; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.5f); size = wdTable.GetFloat("size", 3.0f); } else if (type == "TorpedoLauncher") { // WeaponLoader will create either BombDropper with dropTorpedoes = true // (owner->unitDef->canfly && !weaponDef->submissile) or TorpedoLauncher // (both types of weapons will spawn TorpedoProjectile's) // projectileType = WEAPON_TORPEDO_PROJECTILE; defInterceptType = 32; waterweapon = true; } else if (type == "DGun") { // CFireBallProjectile projectileType = WEAPON_FIREBALL_PROJECTILE; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.5f); collisionSize = wdTable.GetFloat("collisionSize", 10.0f); } else if (type == "StarburstLauncher") { // CStarburstProjectile projectileType = WEAPON_STARBURST_PROJECTILE; defInterceptType = 4; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.7f); } else if (type == "AircraftBomb") { // WeaponLoader will create BombDropper with dropTorpedoes = false // BombDropper with dropTorpedoes=false spawns ExplosiveProjectile's // projectileType = WEAPON_EXPLOSIVE_PROJECTILE; defInterceptType = 8; ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.9f); } else { ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.0f); } interceptedByShieldType = wdTable.GetInt("interceptedByShieldType", defInterceptType); const std::string& colormap = wdTable.GetString("colormap", ""); if (!colormap.empty()) { visuals.colorMap = CColorMap::LoadFromDefString(colormap); } else { visuals.colorMap = NULL; } ParseWeaponSounds(wdTable); // custom parameters table wdTable.SubTable("customParams").GetMap(customParams); // internal only isShield = (type == "Shield"); noAutoTarget = (manualfire || interceptor || isShield); onlyForward = !turret && (type != "StarburstLauncher"); }
/* * CArchiveScanner::ArchiveData */ CArchiveScanner::ArchiveData::ArchiveData(const LuaTable& archiveTable) { if (!archiveTable.IsValid()) { return; } std::vector<std::string> keys; if (!archiveTable.GetKeys(keys)) { return; } std::vector<std::string>::const_iterator key; for (key = keys.begin(); key != keys.end(); ++key) { const std::string& keyLower = StringToLower(*key); if (!ArchiveData::IsReservedKey(keyLower)) { if (keyLower == "modtype") { SetInfoItemValueInteger(*key, archiveTable.GetInt(*key, 0)); continue; } const int luaType = archiveTable.GetType(*key); switch (luaType) { case LuaTable::STRING: { SetInfoItemValueString(*key, archiveTable.GetString(*key, "")); } break; case LuaTable::NUMBER: { SetInfoItemValueFloat(*key, archiveTable.GetFloat(*key, 0.0f)); } break; case LuaTable::BOOLEAN: { SetInfoItemValueBool(*key, archiveTable.GetBool(*key, false)); } break; default: { // just ignore unsupported types (most likely to be lua-tables) //throw content_error("Lua-type " + IntToString(luaType) + " not supported in archive-info, but it is used on key \"" + *key + "\""); } break; } } } const LuaTable _dependencies = archiveTable.SubTable("depend"); for (int dep = 1; _dependencies.KeyExists(dep); ++dep) { dependencies.push_back(_dependencies.GetString(dep, "")); } const LuaTable _replaces = archiveTable.SubTable("replace"); for (int rep = 1; _replaces.KeyExists(rep); ++rep) { replaces.push_back(_replaces.GetString(rep, "")); } //! FIXME //! XXX HACK needed until lobbies, lobbyserver and unitsync are sorted out //! so they can uniquely identify different versions of the same mod. //! (at time of this writing they use name only) //! NOTE when changing this, this function is used both by the code that //! reads ArchiveCache.lua and the code that reads modinfo.lua from the mod. //! so make sure it doesn't keep adding stuff to the name everytime //! Spring/unitsync is loaded. const std::string& name = GetName(); const std::string& version = GetVersion(); if ((name.find(version) == std::string::npos) && !version.empty()) { SetInfoItemValueString("name", name + " " + version); } }
bool CSound::LoadSoundDefsImpl(const std::string& fileName) { //! can be called from LuaUnsyncedCtrl too boost::recursive_mutex::scoped_lock lck(soundMutex); LuaParser parser(fileName, SPRING_VFS_MOD, SPRING_VFS_ZIP); parser.Execute(); if (!parser.IsValid()) { LOG_L(L_WARNING, "Could not load %s: %s", fileName.c_str(), parser.GetErrorLog().c_str()); return false; } else { const LuaTable soundRoot = parser.GetRoot(); const LuaTable soundItemTable = soundRoot.SubTable("SoundItems"); if (!soundItemTable.IsValid()) { LOG_L(L_WARNING, "CSound(): could not parse SoundItems table in %s", fileName.c_str()); return false; } else { std::vector<std::string> keys; soundItemTable.GetKeys(keys); for (std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it) { std::string name(*it); soundItemDef bufmap; const LuaTable buf(soundItemTable.SubTable(name)); buf.GetMap(bufmap); bufmap["name"] = name; soundItemDefMap::const_iterator sit = soundItemDefs.find(name); if (name == "default") { defaultItem = bufmap; defaultItem.erase("name"); //must be empty for default item defaultItem.erase("file"); continue; } if (sit != soundItemDefs.end()) LOG_L(L_WARNING, "Sound %s gets overwritten by %s", name.c_str(), fileName.c_str()); if (!buf.KeyExists("file")) { // no file, drop LOG_L(L_WARNING, "Sound %s is missing file tag (ignoring)", name.c_str()); continue; } else { soundItemDefs[name] = bufmap; } if (buf.KeyExists("preload")) { MakeItemFromDef(bufmap); } } LOG(" parsed %i sounds from %s", (int)keys.size(), fileName.c_str()); } } //FIXME why do sounds w/o an own soundItemDef create (!=pointer) a new one from the defaultItem? for (soundItemDefMap::iterator it = soundItemDefs.begin(); it != soundItemDefs.end(); ++it) { soundItemDef& snddef = it->second; if (snddef.find("name") == snddef.end()) { // uses defaultItem! update it! const std::string file = snddef["file"]; snddef = defaultItem; snddef["file"] = file; } } return true; }
void CUnitDefHandler::ParseUnitDefTable(const LuaTable& udTable, const string& unitName, int id) { UnitDef& ud = unitDefs[id]; // allocate and fill ud->unitImage ud.buildPicName = udTable.GetString("buildPic", ""); ud.humanName = udTable.GetString("name", ""); if (ud.humanName.empty()) { const string errmsg = "missing 'name' parameter for the " + unitName + " unitdef"; throw content_error(errmsg); } ud.filename = udTable.GetString("filename", ""); if (ud.filename.empty()) { const string errmsg = "missing 'filename' parameter for the" + unitName + " unitdef"; throw content_error(errmsg); } ud.tooltip = udTable.GetString("description", ud.name); const string decoy = udTable.GetString("decoyFor", ""); if (!decoy.empty()) { decoyNameMap[ud.name] = StringToLower(decoy); } ud.gaia = udTable.GetString("gaia", ""); ud.isCommander = udTable.GetBool("commander", false); if (ud.isCommander && gameSetup) { ud.metalStorage = udTable.GetFloat("metalStorage", gameSetup->startMetal); ud.energyStorage = udTable.GetFloat("energyStorage", gameSetup->startEnergy); } else { ud.metalStorage = udTable.GetFloat("metalStorage", 0.0f); ud.energyStorage = udTable.GetFloat("energyStorage", 0.0f); } ud.extractsMetal = udTable.GetFloat("extractsMetal", 0.0f); ud.windGenerator = udTable.GetFloat("windGenerator", 0.0f); ud.tidalGenerator = udTable.GetFloat("tidalGenerator", 0.0f); ud.metalUpkeep = udTable.GetFloat("metalUse", 0.0f); ud.energyUpkeep = udTable.GetFloat("energyUse", 0.0f); ud.metalMake = udTable.GetFloat("metalMake", 0.0f); ud.makesMetal = udTable.GetFloat("makesMetal", 0.0f); ud.energyMake = udTable.GetFloat("energyMake", 0.0f); ud.health = udTable.GetFloat("maxDamage", 0.0f); ud.autoHeal = udTable.GetFloat("autoHeal", 0.0f) * (16.0f / GAME_SPEED); ud.idleAutoHeal = udTable.GetFloat("idleAutoHeal", 10.0f) * (16.0f / GAME_SPEED); ud.idleTime = udTable.GetInt("idleTime", 600); ud.buildangle = udTable.GetInt("buildAngle", 0); ud.isMetalMaker = (ud.makesMetal >= 1 && ud.energyUpkeep > ud.makesMetal * 40); ud.controlRadius = 32; ud.losHeight = 20; ud.metalCost = udTable.GetFloat("buildCostMetal", 0.0f); if (ud.metalCost < 1.0f) { ud.metalCost = 1.0f; //avoid some nasty divide by 0 etc } ud.mass = udTable.GetFloat("mass", 0.0f); if (ud.mass <= 0.0f) { ud.mass=ud.metalCost; } ud.energyCost = udTable.GetFloat("buildCostEnergy", 0.0f); ud.buildTime = udTable.GetFloat("buildTime", 0.0f); if (ud.buildTime < 1.0f) { ud.buildTime = 1.0f; //avoid some nasty divide by 0 etc } ud.aihint = id; // FIXME? (as noted in SelectedUnits.cpp, aihint is ignored) ud.cobID = udTable.GetInt("cobID", -1); ud.losRadius = udTable.GetFloat("sightDistance", 0.0f) * modInfo.losMul / (SQUARE_SIZE * (1 << modInfo.losMipLevel)); ud.airLosRadius = udTable.GetFloat("airSightDistance", -1.0f); if (ud.airLosRadius == -1.0f) { ud.airLosRadius=udTable.GetFloat("sightDistance", 0.0f) * modInfo.airLosMul * 1.5f / (SQUARE_SIZE * (1 << modInfo.airMipLevel)); } else { ud.airLosRadius = ud.airLosRadius * modInfo.airLosMul / (SQUARE_SIZE * (1 << modInfo.airMipLevel)); } ud.canSubmerge = udTable.GetBool("canSubmerge", false); ud.canfly = udTable.GetBool("canFly", false); ud.canmove = udTable.GetBool("canMove", false); ud.reclaimable = udTable.GetBool("reclaimable", true); ud.capturable = udTable.GetBool("capturable", true); ud.repairable = udTable.GetBool("repairable", true); ud.canAttack = udTable.GetBool("canAttack", true); ud.canFight = udTable.GetBool("canFight", true); ud.canPatrol = udTable.GetBool("canPatrol", true); ud.canGuard = udTable.GetBool("canGuard", true); ud.canRepeat = udTable.GetBool("canRepeat", true); ud.builder = udTable.GetBool("builder", true); ud.canRestore = udTable.GetBool("canRestore", ud.builder); ud.canRepair = udTable.GetBool("canRepair", ud.builder); ud.canReclaim = udTable.GetBool("canReclaim", ud.builder); ud.canAssist = udTable.GetBool("canAssist", ud.builder); ud.canBeAssisted = udTable.GetBool("canBeAssisted", true); ud.canSelfRepair = udTable.GetBool("canSelfRepair", false); ud.fullHealthFactory = udTable.GetBool("fullHealthFactory", false); ud.factoryHeadingTakeoff = udTable.GetBool("factoryHeadingTakeoff", true); ud.upright = udTable.GetBool("upright", false); ud.collide = udTable.GetBool("collide", true); ud.onoffable = udTable.GetBool("onoffable", false); ud.maxSlope = udTable.GetFloat("maxSlope", 0.0f); ud.maxHeightDif = 40 * tan(ud.maxSlope * (PI / 180)); ud.maxSlope = cos(ud.maxSlope * (PI / 180)); ud.minWaterDepth = udTable.GetFloat("minWaterDepth", -10e6f); ud.maxWaterDepth = udTable.GetFloat("maxWaterDepth", +10e6f); ud.minCollisionSpeed = udTable.GetFloat("minCollisionSpeed", 1.0f); ud.slideTolerance = udTable.GetFloat("slideTolerance", 0.0f); // disabled ud.pushResistant = udTable.GetBool("pushResistant", false); ud.waterline = udTable.GetFloat("waterline", 0.0f); if ((ud.waterline >= 5.0f) && ud.canmove) { // make subs travel at somewhat larger depths // to reduce vulnerability to surface weapons ud.waterline += 10.0f; } ud.canSelfD = udTable.GetBool("canSelfDestruct", true); ud.selfDCountdown = udTable.GetInt("selfDestructCountdown", 5); ud.speed = udTable.GetFloat("maxVelocity", 0.0f) * GAME_SPEED; ud.rSpeed = udTable.GetFloat("maxReverseVelocity", 0.0f) * GAME_SPEED; ud.speed = fabs(ud.speed); ud.rSpeed = fabs(ud.rSpeed); ud.maxAcc = fabs(udTable.GetFloat("acceleration", 0.5f)); // no negative values ud.maxDec = fabs(udTable.GetFloat("brakeRate", 3.0f * ud.maxAcc)) * (ud.canfly? 0.1f: 1.0f); // no negative values ud.turnRate = udTable.GetFloat("turnRate", 0.0f); ud.turnInPlace = udTable.GetBool( "turnInPlace", true); ud.turnInPlaceDistance = udTable.GetFloat("turnInPlaceDistance", 350.f); ud.turnInPlaceSpeedLimit = udTable.GetFloat("turnInPlaceSpeedLimit", 15.f); const bool noAutoFire = udTable.GetBool("noAutoFire", false); ud.canFireControl = udTable.GetBool("canFireControl", !noAutoFire); ud.fireState = udTable.GetInt("fireState", ud.canFireControl ? -1 : 2); ud.fireState = std::min(ud.fireState,2); ud.moveState = udTable.GetInt("moveState", (ud.canmove && ud.speed>0.0f) ? -1 : 1); ud.moveState = std::min(ud.moveState,2); ud.buildRange3D = udTable.GetBool("buildRange3D", false); ud.buildDistance = udTable.GetFloat("buildDistance", 128.0f); ud.buildDistance = std::max(128.0f, ud.buildDistance); ud.buildSpeed = udTable.GetFloat("workerTime", 0.0f); ud.repairSpeed = udTable.GetFloat("repairSpeed", ud.buildSpeed); ud.maxRepairSpeed = udTable.GetFloat("maxRepairSpeed", 1e20f); ud.reclaimSpeed = udTable.GetFloat("reclaimSpeed", ud.buildSpeed); ud.resurrectSpeed = udTable.GetFloat("resurrectSpeed", ud.buildSpeed); ud.captureSpeed = udTable.GetFloat("captureSpeed", ud.buildSpeed); ud.terraformSpeed = udTable.GetFloat("terraformSpeed", ud.buildSpeed); ud.flankingBonusMode = udTable.GetInt("flankingBonusMode", modInfo.flankingBonusModeDefault); ud.flankingBonusMax = udTable.GetFloat("flankingBonusMax", 1.9f); ud.flankingBonusMin = udTable.GetFloat("flankingBonusMin", 0.9); ud.flankingBonusDir = udTable.GetFloat3("flankingBonusDir", float3(0.0f, 0.0f, 1.0f)); ud.flankingBonusMobilityAdd = udTable.GetFloat("flankingBonusMobilityAdd", 0.01f); ud.armoredMultiple = udTable.GetFloat("damageModifier", 1.0f); ud.armorType = damageArrayHandler->GetTypeFromName(ud.name); ud.radarRadius = udTable.GetInt("radarDistance", 0); ud.sonarRadius = udTable.GetInt("sonarDistance", 0); ud.jammerRadius = udTable.GetInt("radarDistanceJam", 0); ud.sonarJamRadius = udTable.GetInt("sonarDistanceJam", 0); ud.stealth = udTable.GetBool("stealth", false); ud.sonarStealth = udTable.GetBool("sonarStealth", false); ud.targfac = udTable.GetBool("isTargetingUpgrade", false); ud.isFeature = udTable.GetBool("isFeature", false); ud.canResurrect = udTable.GetBool("canResurrect", false); ud.canCapture = udTable.GetBool("canCapture", false); ud.hideDamage = udTable.GetBool("hideDamage", false); ud.showPlayerName = udTable.GetBool("showPlayerName", false); ud.cloakCost = udTable.GetFloat("cloakCost", -1.0f); ud.cloakCostMoving = udTable.GetFloat("cloakCostMoving", -1.0f); if (ud.cloakCostMoving < 0) { ud.cloakCostMoving = ud.cloakCost; } ud.canCloak = (ud.cloakCost >= 0); ud.startCloaked = udTable.GetBool("initCloaked", false); ud.decloakDistance = udTable.GetFloat("minCloakDistance", 0.0f); ud.decloakSpherical = udTable.GetBool("decloakSpherical", true); ud.decloakOnFire = udTable.GetBool("decloakOnFire", true); ud.highTrajectoryType = udTable.GetInt("highTrajectory", 0); ud.canKamikaze = udTable.GetBool("kamikaze", false); ud.kamikazeDist = udTable.GetFloat("kamikazeDistance", -25.0f) + 25.0f; //we count 3d distance while ta count 2d distance so increase slightly ud.showNanoFrame = udTable.GetBool("showNanoFrame", true); ud.showNanoSpray = udTable.GetBool("showNanoSpray", true); ud.nanoColor = udTable.GetFloat3("nanoColor", float3(0.2f,0.7f,0.2f)); ud.canhover = udTable.GetBool("canHover", false); ud.floater = udTable.GetBool("floater", udTable.KeyExists("WaterLine")); ud.builder = udTable.GetBool("builder", false); if (ud.builder && !ud.buildSpeed) { // core anti is flagged as builder for some reason ud.builder = false; } ud.airStrafe = udTable.GetBool("airStrafe", true); ud.hoverAttack = udTable.GetBool("hoverAttack", false); ud.wantedHeight = udTable.GetFloat("cruiseAlt", 0.0f); ud.dlHoverFactor = udTable.GetFloat("airHoverFactor", -1.0f); ud.bankingAllowed = udTable.GetBool("bankingAllowed", true); ud.transportSize = udTable.GetInt("transportSize", 0); ud.minTransportSize = udTable.GetInt("minTransportSize", 0); ud.transportCapacity = udTable.GetInt("transportCapacity", 0); ud.isFirePlatform = udTable.GetBool("isFirePlatform", false); ud.isAirBase = udTable.GetBool("isAirBase", false); ud.loadingRadius = udTable.GetFloat("loadingRadius", 220.0f); ud.unloadSpread = udTable.GetFloat("unloadSpread", 1.0f); ud.transportMass = udTable.GetFloat("transportMass", 100000.0f); ud.minTransportMass = udTable.GetFloat("minTransportMass", 0.0f); ud.holdSteady = udTable.GetBool("holdSteady", true); ud.releaseHeld = udTable.GetBool("releaseHeld", false); ud.cantBeTransported = udTable.GetBool("cantBeTransported", false); ud.transportByEnemy = udTable.GetBool("transportByEnemy", true); ud.fallSpeed = udTable.GetFloat("fallSpeed", 0.2); ud.unitFallSpeed = udTable.GetFloat("unitFallSpeed", 0); ud.transportUnloadMethod = udTable.GetInt("transportUnloadMethod" , 0); // modrules transport settings if ((!modInfo.transportAir && ud.canfly) || (!modInfo.transportShip && ud.floater) || (!modInfo.transportHover && ud.canhover) || (!modInfo.transportGround && !ud.canhover && !ud.floater && !ud.canfly)) { ud.cantBeTransported = true; } ud.wingDrag = udTable.GetFloat("wingDrag", 0.07f); // drag caused by wings ud.wingDrag = std::min(1.0f, std::max(0.0f, ud.wingDrag)); ud.wingAngle = udTable.GetFloat("wingAngle", 0.08f); // angle between front and the wing plane ud.frontToSpeed = udTable.GetFloat("frontToSpeed", 0.1f); // fudge factor for lining up speed and front of plane ud.speedToFront = udTable.GetFloat("speedToFront", 0.07f); // fudge factor for lining up speed and front of plane ud.myGravity = udTable.GetFloat("myGravity", 0.4f); // planes are slower than real airplanes so lower gravity to compensate ud.crashDrag = udTable.GetFloat("crashDrag",0.005f); // drag used when crashing ud.crashDrag = std::min(1.0f, std::max(0.0f, ud.crashDrag)); ud.maxBank = udTable.GetFloat("maxBank", 0.8f); // max roll ud.maxPitch = udTable.GetFloat("maxPitch", 0.45f); // max pitch this plane tries to keep ud.turnRadius = udTable.GetFloat("turnRadius", 500.0f); // hint to the ai about how large turn radius this plane needs ud.verticalSpeed = udTable.GetFloat("verticalSpeed", 3.0f); // speed of takeoff and landing, at least for gunships ud.maxAileron = udTable.GetFloat("maxAileron", 0.015f); // turn speed around roll axis ud.maxElevator = udTable.GetFloat("maxElevator", 0.01f); // turn speed around pitch axis ud.maxRudder = udTable.GetFloat("maxRudder", 0.004f); // turn speed around yaw axis ud.maxFuel = udTable.GetFloat("maxFuel", 0.0f); //max flight time in seconds before aircraft must return to base ud.refuelTime = udTable.GetFloat("refuelTime", 5.0f); ud.minAirBasePower = udTable.GetFloat("minAirBasePower", 0.0f); ud.maxThisUnit = udTable.GetInt("unitRestricted", MAX_UNITS); string lname = StringToLower(ud.name); if (gameSetup->restrictedUnits.find(lname) != gameSetup->restrictedUnits.end()) { ud.maxThisUnit = std::min(ud.maxThisUnit, gameSetup->restrictedUnits.find(lname)->second); } ud.categoryString = udTable.GetString("category", ""); ud.category = CCategoryHandler::Instance()->GetCategories(udTable.GetString("category", "")); ud.noChaseCategory = CCategoryHandler::Instance()->GetCategories(udTable.GetString("noChaseCategory", "")); // logOutput.Print("Unit %s has cat %i",ud.humanName.c_str(),ud.category); const string iconName = udTable.GetString("iconType", "default"); ud.iconType = iconHandler->GetIcon(iconName); ud.shieldWeaponDef = NULL; ud.stockpileWeaponDef = NULL; ud.maxWeaponRange = 0.0f; ud.maxCoverage = 0.0f; const WeaponDef* noWeaponDef = weaponDefHandler->GetWeapon("NOWEAPON"); LuaTable weaponsTable = udTable.SubTable("weapons"); for (int w = 0; w < COB_MaxWeapons; w++) { LuaTable wTable; string name = weaponsTable.GetString(w + 1, ""); if (name.empty()) { wTable = weaponsTable.SubTable(w + 1); name = wTable.GetString("name", ""); } const WeaponDef* wd = NULL; if (!name.empty()) { wd = weaponDefHandler->GetWeapon(name); } if (wd == NULL) { if (w <= 3) { continue; // allow empty weapons among the first 3 } else { break; } } while (ud.weapons.size() < w) { if (!noWeaponDef) { logOutput.Print("Error: Spring requires a NOWEAPON weapon type " "to be present as a placeholder for missing weapons"); break; } else { ud.weapons.push_back(UnitDef::UnitDefWeapon()); ud.weapons.back().def = noWeaponDef; } } const string badTarget = wTable.GetString("badTargetCategory", ""); unsigned int btc = CCategoryHandler::Instance()->GetCategories(badTarget); const string onlyTarget = wTable.GetString("onlyTargetCategory", ""); unsigned int otc; if (onlyTarget.empty()) { otc = 0xffffffff; } else { otc = CCategoryHandler::Instance()->GetCategories(onlyTarget); } const unsigned int slaveTo = wTable.GetInt("slaveTo", 0); float3 mainDir = wTable.GetFloat3("mainDir", float3(1.0f, 0.0f, 0.0f)); mainDir.SafeNormalize(); const float angleDif = cos(wTable.GetFloat("maxAngleDif", 360.0f) * (PI / 360.0f)); const float fuelUse = wTable.GetFloat("fuelUsage", 0.0f); ud.weapons.push_back(UnitDef::UnitDefWeapon(name, wd, slaveTo, mainDir, angleDif, btc, otc, fuelUse)); if (wd->range > ud.maxWeaponRange) { ud.maxWeaponRange = wd->range; } if (wd->interceptor && wd->coverageRange > ud.maxCoverage) { ud.maxCoverage = wd->coverageRange; } if (wd->isShield) { if (!ud.shieldWeaponDef || // use the biggest shield (ud.shieldWeaponDef->shieldRadius < wd->shieldRadius)) { ud.shieldWeaponDef = wd; } } if (wd->stockpile) { // interceptors have priority if (wd->interceptor || !ud.stockpileWeaponDef || !ud.stockpileWeaponDef->interceptor) { ud.stockpileWeaponDef = wd; } } } ud.canDGun = udTable.GetBool("canDGun", false); string TEDClass = udTable.GetString("TEDClass", "0"); ud.TEDClassString = TEDClass; ud.extractRange = 0.0f; ud.extractSquare = udTable.GetBool("extractSquare", false); if (ud.extractsMetal) { ud.extractRange = mapInfo->map.extractorRadius; ud.type = "MetalExtractor"; } else if (ud.transportCapacity) { ud.type = "Transport"; } else if (ud.builder) { if (TEDClass != "PLANT") { ud.type = "Builder"; } else { ud.type = "Factory"; } } else if (ud.canfly && !ud.hoverAttack) { if (!ud.weapons.empty() && (ud.weapons[0].def != 0) && (ud.weapons[0].def->type=="AircraftBomb" || ud.weapons[0].def->type=="TorpedoLauncher")) { ud.type = "Bomber"; if (ud.turnRadius == 500) { // only reset it if user hasnt set it explicitly ud.turnRadius = 1000; // hint to the ai about how large turn radius this plane needs } } else { ud.type = "Fighter"; } ud.maxAcc = udTable.GetFloat("maxAcc", 0.065f); // engine power } else if (ud.canmove) { ud.type = "GroundUnit"; } else { ud.type = "Building"; } ud.movedata = 0; if (ud.canmove && !ud.canfly && (ud.type != "Factory")) { string moveclass = StringToLower(udTable.GetString("movementClass", "")); ud.movedata = moveinfo->GetMoveDataFromName(moveclass); if (!ud.movedata) { const string errmsg = "WARNING: Couldn't find a MoveClass named " + moveclass + " (used in UnitDef: " + unitName + ")"; logOutput.Print(errmsg); // remove the UnitDef throw content_error(errmsg); } if ((ud.movedata->moveType == MoveData::Hover_Move) || (ud.movedata->moveType == MoveData::Ship_Move)) { ud.upright = true; } if (ud.canhover) { if (ud.movedata->moveType != MoveData::Hover_Move) { logOutput.Print("Inconsistent movedata %i for %s (moveclass %s): canhover, but not a hovercraft movetype", ud.movedata->pathType, ud.name.c_str(), moveclass.c_str()); } } else if (ud.floater) { if (ud.movedata->moveType != MoveData::Ship_Move) { logOutput.Print("Inconsistent movedata %i for %s (moveclass %s): floater, but not a ship movetype", ud.movedata->pathType, ud.name.c_str(), moveclass.c_str()); } } else { if (ud.movedata->moveType != MoveData::Ground_Move) { logOutput.Print("Inconsistent movedata %i for %s (moveclass %s): neither canhover nor floater, but not a ground movetype", ud.movedata->pathType, ud.name.c_str(), moveclass.c_str()); } } } if ((ud.maxAcc != 0) && (ud.speed != 0)) { //meant to set the drag such that the maxspeed becomes what it should be ud.drag = 1.0f / (ud.speed/GAME_SPEED * 1.1f / ud.maxAcc) - (ud.wingAngle * ud.wingAngle * ud.wingDrag); ud.drag = std::min(1.0f, std::max(0.0f, ud.drag)); } else { //shouldn't be needed since drag is only used in CAirMoveType anyway, //and aircraft without acceleration or speed aren't common :) //initializing it anyway just for safety ud.drag = 0.005f; } std::string objectname = udTable.GetString("objectName", ""); if (objectname.find(".") == std::string::npos) { objectname += ".3do"; } ud.modelDef.modelpath = "objects3d/" + objectname; ud.modelDef.modelname = objectname; ud.scriptName = udTable.GetString("script", unitName + ".cob"); ud.scriptPath = "scripts/" + ud.scriptName; ud.wreckName = udTable.GetString("corpse", ""); ud.deathExplosion = udTable.GetString("explodeAs", ""); ud.selfDExplosion = udTable.GetString("selfDestructAs", ""); ud.power = udTable.GetFloat("power", (ud.metalCost + (ud.energyCost / 60.0f))); // Prevent a division by zero in experience calculations. if (ud.power < 1.0e-3f) { logOutput.Print("Unit %s is really cheap? %f", ud.humanName.c_str(), ud.power); logOutput.Print("This can cause a division by zero in experience calculations."); ud.power = 1.0e-3f; } ud.activateWhenBuilt = udTable.GetBool("activateWhenBuilt", false); // TA has only half our res so multiply size with 2 ud.xsize = udTable.GetInt("footprintX", 1) * 2; ud.zsize = udTable.GetInt("footprintZ", 1) * 2; ud.needGeo = false; if ((ud.type == "Building") || (ud.type == "Factory")) { CreateYardMap(&ud, udTable.GetString("yardMap", "c")); } else { for (int u = 0; u < 4; u++) { ud.yardmaps[u] = 0; } } ud.leaveTracks = udTable.GetBool("leaveTracks", false); ud.trackWidth = udTable.GetFloat("trackWidth", 32.0f); ud.trackOffset = udTable.GetFloat("trackOffset", 0.0f); ud.trackStrength = udTable.GetFloat("trackStrength", 0.0f); ud.trackStretch = udTable.GetFloat("trackStretch", 1.0f); if (ud.leaveTracks && groundDecals) { ud.trackType = groundDecals->GetTrackType(udTable.GetString("trackType", "StdTank")); } ud.useBuildingGroundDecal = udTable.GetBool("useBuildingGroundDecal", false); ud.buildingDecalSizeX = udTable.GetInt("buildingGroundDecalSizeX", 4); ud.buildingDecalSizeY = udTable.GetInt("buildingGroundDecalSizeY", 4); ud.buildingDecalDecaySpeed = udTable.GetFloat("buildingGroundDecalDecaySpeed", 0.1f); if (ud.useBuildingGroundDecal && groundDecals) { ud.buildingDecalType = groundDecals->GetBuildingDecalType(udTable.GetString("buildingGroundDecalType", "")); } ud.canDropFlare = udTable.GetBool("canDropFlare", false); ud.flareReloadTime = udTable.GetFloat("flareReload", 5.0f); ud.flareDelay = udTable.GetFloat("flareDelay", 0.3f); ud.flareEfficiency = udTable.GetFloat("flareEfficiency", 0.5f); ud.flareDropVector = udTable.GetFloat3("flareDropVector", ZeroVector); ud.flareTime = udTable.GetInt("flareTime", 3) * GAME_SPEED; ud.flareSalvoSize = udTable.GetInt("flareSalvoSize", 4); ud.flareSalvoDelay = udTable.GetInt("flareSalvoDelay", 0) * GAME_SPEED; ud.smoothAnim = udTable.GetBool("smoothAnim", false); ud.canLoopbackAttack = udTable.GetBool("canLoopbackAttack", false); ud.canCrash = udTable.GetBool("canCrash", true); ud.levelGround = udTable.GetBool("levelGround", true); ud.strafeToAttack = udTable.GetBool("strafeToAttack", false); ud.modelCenterOffset = udTable.GetFloat3("modelCenterOffset", ZeroVector); ud.collisionVolumeTypeStr = udTable.GetString("collisionVolumeType", ""); ud.collisionVolumeScales = udTable.GetFloat3("collisionVolumeScales", ZeroVector); ud.collisionVolumeOffsets = udTable.GetFloat3("collisionVolumeOffsets", ZeroVector); ud.collisionVolumeTest = udTable.GetInt("collisionVolumeTest", COLVOL_TEST_DISC); ud.usePieceCollisionVolumes = udTable.GetBool("usePieceCollisionVolumes", false); // initialize the (per-unitdef) collision-volume // all CUnit instances hold a copy of this object ud.collisionVolume = new CollisionVolume( ud.collisionVolumeTypeStr, ud.collisionVolumeScales, ud.collisionVolumeOffsets, ud.collisionVolumeTest ); if (ud.usePieceCollisionVolumes) { ud.collisionVolume->Disable(); } ud.seismicRadius = udTable.GetInt("seismicDistance", 0); ud.seismicSignature = udTable.GetFloat("seismicSignature", -1.0f); if (ud.seismicSignature == -1.0f) { if (!ud.floater && !ud.canhover && !ud.canfly) { ud.seismicSignature = sqrt(ud.mass / 100.0f); } else { ud.seismicSignature = 0.0f; } } LuaTable buildsTable = udTable.SubTable("buildOptions"); if (buildsTable.IsValid()) { for (int bo = 1; true; bo++) { const string order = buildsTable.GetString(bo, ""); if (order.empty()) { break; } ud.buildOptions[bo] = order; } } LuaTable sfxTable = udTable.SubTable("SFXTypes"); LuaTable expTable = sfxTable.SubTable("explosionGenerators"); for (int expNum = 1; expNum <= 1024; expNum++) { string expsfx = expTable.GetString(expNum, ""); if (expsfx == "") { break; } else { ud.sfxExplGens.push_back(explGenHandler->LoadGenerator(expsfx)); } } // we use range in a modulo operation, so it needs to be >= 1 ud.pieceTrailCEGTag = udTable.GetString("pieceTrailCEGTag", ""); ud.pieceTrailCEGRange = udTable.GetInt("pieceTrailCEGRange", 1); ud.pieceTrailCEGRange = std::max(ud.pieceTrailCEGRange, 1); LuaTable soundsTable = udTable.SubTable("sounds"); LoadSounds(soundsTable, ud.sounds.ok, "ok"); // eg. "ok1", "ok2", ... LoadSounds(soundsTable, ud.sounds.select, "select"); // eg. "select1", "select2", ... LoadSounds(soundsTable, ud.sounds.arrived, "arrived"); // eg. "arrived1", "arrived2", ... LoadSounds(soundsTable, ud.sounds.build, "build"); LoadSounds(soundsTable, ud.sounds.activate, "activate"); LoadSounds(soundsTable, ud.sounds.deactivate, "deactivate"); LoadSounds(soundsTable, ud.sounds.cant, "cant"); LoadSounds(soundsTable, ud.sounds.underattack, "underattack"); // custom parameters table udTable.SubTable("customParams").GetMap(ud.customParams); }
UnitDef::UnitDef(const LuaTable& udTable, const std::string& unitName, int id) : name(unitName) , id(id) , collisionVolume(NULL) , decoyDef(NULL) , techLevel(-1) , buildPic(NULL) , buildangle(0) { humanName = udTable.GetString("name", ""); if (humanName.empty()) { const string errmsg = "missing 'name' parameter for the " + unitName + " unitdef"; throw content_error(errmsg); } filename = udTable.GetString("filename", ""); if (filename.empty()) { const string errmsg = "missing 'filename' parameter for the" + unitName + " unitdef"; throw content_error(errmsg); } tooltip = udTable.GetString("description", name); buildPicName = udTable.GetString("buildPic", ""); decoyName = udTable.GetString("decoyFor", ""); gaia = udTable.GetString("gaia", ""); isCommander = udTable.GetBool("commander", false); metalStorage = udTable.GetFloat("metalStorage", 0.0f); energyStorage = udTable.GetFloat("energyStorage", 0.0f); extractsMetal = udTable.GetFloat("extractsMetal", 0.0f); windGenerator = udTable.GetFloat("windGenerator", 0.0f); tidalGenerator = udTable.GetFloat("tidalGenerator", 0.0f); metalUpkeep = udTable.GetFloat("metalUse", 0.0f); energyUpkeep = udTable.GetFloat("energyUse", 0.0f); metalMake = udTable.GetFloat("metalMake", 0.0f); makesMetal = udTable.GetFloat("makesMetal", 0.0f); energyMake = udTable.GetFloat("energyMake", 0.0f); health = udTable.GetFloat("maxDamage", 0.0f); autoHeal = udTable.GetFloat("autoHeal", 0.0f) * (16.0f / GAME_SPEED); idleAutoHeal = udTable.GetFloat("idleAutoHeal", 10.0f) * (16.0f / GAME_SPEED); idleTime = udTable.GetInt("idleTime", 600); buildangle = udTable.GetInt("buildAngle", 0); losHeight = 20; metalCost = udTable.GetFloat("buildCostMetal", 0.0f); if (metalCost < 1.0f) { metalCost = 1.0f; //avoid some nasty divide by 0 etc } mass = udTable.GetFloat("mass", 0.0f); if (mass <= 0.0f) { mass = metalCost; } energyCost = udTable.GetFloat("buildCostEnergy", 0.0f); buildTime = udTable.GetFloat("buildTime", 0.0f); if (buildTime < 1.0f) { buildTime = 1.0f; //avoid some nasty divide by 0 etc } aihint = id; // FIXME? (as noted in SelectedUnits.cpp, aihint is ignored) cobID = udTable.GetInt("cobID", -1); losRadius = udTable.GetFloat("sightDistance", 0.0f) * modInfo.losMul / (SQUARE_SIZE * (1 << modInfo.losMipLevel)); airLosRadius = udTable.GetFloat("airSightDistance", -1.0f); if (airLosRadius == -1.0f) { airLosRadius = udTable.GetFloat("sightDistance", 0.0f) * modInfo.airLosMul * 1.5f / (SQUARE_SIZE * (1 << modInfo.airMipLevel)); } else { airLosRadius = airLosRadius * modInfo.airLosMul / (SQUARE_SIZE * (1 << modInfo.airMipLevel)); } canSubmerge = udTable.GetBool("canSubmerge", false); canfly = udTable.GetBool("canFly", false); canmove = udTable.GetBool("canMove", false); reclaimable = udTable.GetBool("reclaimable", true); capturable = udTable.GetBool("capturable", true); repairable = udTable.GetBool("repairable", true); canAttack = udTable.GetBool("canAttack", true); canFight = udTable.GetBool("canFight", true); canPatrol = udTable.GetBool("canPatrol", true); canGuard = udTable.GetBool("canGuard", true); canRepeat = udTable.GetBool("canRepeat", true); builder = udTable.GetBool("builder", false); canRestore = udTable.GetBool("canRestore", builder); canRepair = udTable.GetBool("canRepair", builder); canReclaim = udTable.GetBool("canReclaim", builder); canAssist = udTable.GetBool("canAssist", builder); canBeAssisted = udTable.GetBool("canBeAssisted", true); canSelfRepair = udTable.GetBool("canSelfRepair", false); fullHealthFactory = udTable.GetBool("fullHealthFactory", false); factoryHeadingTakeoff = udTable.GetBool("factoryHeadingTakeoff", true); upright = udTable.GetBool("upright", false); collide = udTable.GetBool("collide", true); onoffable = udTable.GetBool("onoffable", false); maxSlope = Clamp(udTable.GetFloat("maxSlope", 0.0f), 0.0f, 89.0f); maxHeightDif = 40 * tan(maxSlope * (PI / 180)); maxSlope = cos(maxSlope * (PI / 180)); minWaterDepth = udTable.GetFloat("minWaterDepth", -10e6f); maxWaterDepth = udTable.GetFloat("maxWaterDepth", +10e6f); minCollisionSpeed = udTable.GetFloat("minCollisionSpeed", 1.0f); slideTolerance = udTable.GetFloat("slideTolerance", 0.0f); // disabled pushResistant = udTable.GetBool("pushResistant", false); waterline = udTable.GetFloat("waterline", 0.0f); if ((waterline >= 5.0f) && canmove) { // make subs travel at somewhat larger depths // to reduce vulnerability to surface weapons waterline += 10.0f; } canSelfD = udTable.GetBool("canSelfDestruct", true); selfDCountdown = udTable.GetInt("selfDestructCountdown", 5); speed = udTable.GetFloat("maxVelocity", 0.0f) * GAME_SPEED; rSpeed = udTable.GetFloat("maxReverseVelocity", 0.0f) * GAME_SPEED; speed = fabs(speed); rSpeed = fabs(rSpeed); maxAcc = fabs(udTable.GetFloat("acceleration", 0.5f)); // no negative values maxDec = fabs(udTable.GetFloat("brakeRate", 3.0f * maxAcc)) * (canfly? 0.1f: 1.0f); // no negative values turnRate = udTable.GetFloat("turnRate", 0.0f); turnInPlace = udTable.GetBool( "turnInPlace", true); turnInPlaceDistance = udTable.GetFloat("turnInPlaceDistance", 350.f); turnInPlaceSpeedLimit = udTable.GetFloat("turnInPlaceSpeedLimit", (speed / GAME_SPEED) * 0.2f); const bool noAutoFire = udTable.GetBool("noAutoFire", false); canFireControl = udTable.GetBool("canFireControl", !noAutoFire); fireState = udTable.GetInt("fireState", canFireControl ? -1 : 2); fireState = std::min(fireState,2); moveState = udTable.GetInt("moveState", (canmove && speed>0.0f) ? -1 : 1); moveState = std::min(moveState,2); buildRange3D = udTable.GetBool("buildRange3D", false); buildDistance = udTable.GetFloat("buildDistance", 128.0f); buildDistance = std::max(128.0f, buildDistance); buildSpeed = udTable.GetFloat("workerTime", 0.0f); repairSpeed = udTable.GetFloat("repairSpeed", buildSpeed); maxRepairSpeed = udTable.GetFloat("maxRepairSpeed", 1e20f); reclaimSpeed = udTable.GetFloat("reclaimSpeed", buildSpeed); resurrectSpeed = udTable.GetFloat("resurrectSpeed", buildSpeed); captureSpeed = udTable.GetFloat("captureSpeed", buildSpeed); terraformSpeed = udTable.GetFloat("terraformSpeed", buildSpeed); flankingBonusMode = udTable.GetInt("flankingBonusMode", modInfo.flankingBonusModeDefault); flankingBonusMax = udTable.GetFloat("flankingBonusMax", 1.9f); flankingBonusMin = udTable.GetFloat("flankingBonusMin", 0.9); flankingBonusDir = udTable.GetFloat3("flankingBonusDir", float3(0.0f, 0.0f, 1.0f)); flankingBonusMobilityAdd = udTable.GetFloat("flankingBonusMobilityAdd", 0.01f); armoredMultiple = udTable.GetFloat("damageModifier", 1.0f); armorType = damageArrayHandler->GetTypeFromName(name); radarRadius = udTable.GetInt("radarDistance", 0); sonarRadius = udTable.GetInt("sonarDistance", 0); jammerRadius = udTable.GetInt("radarDistanceJam", 0); sonarJamRadius = udTable.GetInt("sonarDistanceJam", 0); stealth = udTable.GetBool("stealth", false); sonarStealth = udTable.GetBool("sonarStealth", false); targfac = udTable.GetBool("isTargetingUpgrade", false); isFeature = udTable.GetBool("isFeature", false); canResurrect = udTable.GetBool("canResurrect", false); canCapture = udTable.GetBool("canCapture", false); hideDamage = udTable.GetBool("hideDamage", false); showPlayerName = udTable.GetBool("showPlayerName", false); cloakCost = udTable.GetFloat("cloakCost", -1.0f); cloakCostMoving = udTable.GetFloat("cloakCostMoving", -1.0f); if (cloakCostMoving < 0) { cloakCostMoving = cloakCost; } canCloak = (cloakCost >= 0); startCloaked = udTable.GetBool("initCloaked", false); decloakDistance = udTable.GetFloat("minCloakDistance", 0.0f); decloakSpherical = udTable.GetBool("decloakSpherical", true); decloakOnFire = udTable.GetBool("decloakOnFire", true); cloakTimeout = udTable.GetInt("cloakTimeout", 128); highTrajectoryType = udTable.GetInt("highTrajectory", 0); canKamikaze = udTable.GetBool("kamikaze", false); kamikazeDist = udTable.GetFloat("kamikazeDistance", -25.0f) + 25.0f; //we count 3d distance while ta count 2d distance so increase slightly kamikazeUseLOS = udTable.GetBool("kamikazeUseLOS", false); showNanoFrame = udTable.GetBool("showNanoFrame", true); showNanoSpray = udTable.GetBool("showNanoSpray", true); nanoColor = udTable.GetFloat3("nanoColor", float3(0.2f,0.7f,0.2f)); canhover = udTable.GetBool("canHover", false); floater = udTable.GetBool("floater", udTable.KeyExists("WaterLine")); if (builder && !buildSpeed) { // core anti is flagged as builder for some reason builder = false; } airStrafe = udTable.GetBool("airStrafe", true); hoverAttack = udTable.GetBool("hoverAttack", false); wantedHeight = udTable.GetFloat("cruiseAlt", 0.0f); dlHoverFactor = udTable.GetFloat("airHoverFactor", -1.0f); bankingAllowed = udTable.GetBool("bankingAllowed", true); useSmoothMesh = udTable.GetBool("useSmoothMesh", true); transportSize = udTable.GetInt("transportSize", 0); minTransportSize = udTable.GetInt("minTransportSize", 0); transportCapacity = udTable.GetInt("transportCapacity", 0); isFirePlatform = udTable.GetBool("isFirePlatform", false); isAirBase = udTable.GetBool("isAirBase", false); loadingRadius = udTable.GetFloat("loadingRadius", 220.0f); unloadSpread = udTable.GetFloat("unloadSpread", 1.0f); transportMass = udTable.GetFloat("transportMass", 100000.0f); minTransportMass = udTable.GetFloat("minTransportMass", 0.0f); holdSteady = udTable.GetBool("holdSteady", false); releaseHeld = udTable.GetBool("releaseHeld", false); cantBeTransported = udTable.GetBool("cantBeTransported", false); transportByEnemy = udTable.GetBool("transportByEnemy", true); fallSpeed = udTable.GetFloat("fallSpeed", 0.2); unitFallSpeed = udTable.GetFloat("unitFallSpeed", 0); transportUnloadMethod = udTable.GetInt("transportUnloadMethod" , 0); // modrules transport settings if ((!modInfo.transportAir && canfly) || (!modInfo.transportShip && floater) || (!modInfo.transportHover && canhover) || (!modInfo.transportGround && !canhover && !floater && !canfly)) { cantBeTransported = true; } wingDrag = udTable.GetFloat("wingDrag", 0.07f); // drag caused by wings wingDrag = Clamp(wingDrag, 0.0f, 1.0f); wingAngle = udTable.GetFloat("wingAngle", 0.08f); // angle between front and the wing plane frontToSpeed = udTable.GetFloat("frontToSpeed", 0.1f); // fudge factor for lining up speed and front of plane speedToFront = udTable.GetFloat("speedToFront", 0.07f); // fudge factor for lining up speed and front of plane myGravity = udTable.GetFloat("myGravity", 0.4f); // planes are slower than real airplanes so lower gravity to compensate crashDrag = udTable.GetFloat("crashDrag", 0.005f); // drag used when crashing crashDrag = Clamp(crashDrag, 0.0f, 1.0f); maxBank = udTable.GetFloat("maxBank", 0.8f); // max roll maxPitch = udTable.GetFloat("maxPitch", 0.45f); // max pitch this plane tries to keep turnRadius = udTable.GetFloat("turnRadius", 500.0f); // hint to the ai about how large turn radius this plane needs verticalSpeed = udTable.GetFloat("verticalSpeed", 3.0f); // speed of takeoff and landing, at least for gunships maxAileron = udTable.GetFloat("maxAileron", 0.015f); // turn speed around roll axis maxElevator = udTable.GetFloat("maxElevator", 0.01f); // turn speed around pitch axis maxRudder = udTable.GetFloat("maxRudder", 0.004f); // turn speed around yaw axis maxFuel = udTable.GetFloat("maxFuel", 0.0f); //max flight time in seconds before aircraft must return to base refuelTime = udTable.GetFloat("refuelTime", 5.0f); minAirBasePower = udTable.GetFloat("minAirBasePower", 0.0f); maxThisUnit = udTable.GetInt("unitRestricted", MAX_UNITS); transportableBuilding = udTable.GetBool("transportableBuilding", false); const string lname = StringToLower(name); if (gameSetup->restrictedUnits.find(lname) != gameSetup->restrictedUnits.end()) { maxThisUnit = std::min(maxThisUnit, gameSetup->restrictedUnits.find(lname)->second); } categoryString = udTable.GetString("category", ""); category = CCategoryHandler::Instance()->GetCategories(udTable.GetString("category", "")); noChaseCategory = CCategoryHandler::Instance()->GetCategories(udTable.GetString("noChaseCategory", "")); const string iconName = udTable.GetString("iconType", "default"); iconType = iconHandler->GetIcon(iconName); shieldWeaponDef = NULL; stockpileWeaponDef = NULL; maxWeaponRange = 0.0f; maxCoverage = 0.0f; LuaTable weaponsTable = udTable.SubTable("weapons"); ParseWeaponsTable(weaponsTable); canDGun = udTable.GetBool("canDGun", false); extractRange = 0.0f; extractSquare = udTable.GetBool("extractSquare", false); if (extractsMetal) { extractRange = mapInfo->map.extractorRadius; type = "MetalExtractor"; } else if (transportCapacity) { type = "Transport"; } else if (builder) { if ((speed > 0.0f) || canfly || udTable.GetString("yardMap", "").empty()) { // hubs and nano-towers need to be builders (for now) type = "Builder"; } else { type = "Factory"; } } else if (canfly && !hoverAttack) { if (!weapons.empty() && (weapons[0].def != 0) && (weapons[0].def->type == "AircraftBomb" || weapons[0].def->type == "TorpedoLauncher")) { type = "Bomber"; if (turnRadius == 500) { // only reset it if user hasnt set it explicitly turnRadius *= 2; // hint to the ai about how large turn radius this plane needs } } else { type = "Fighter"; } maxAcc = udTable.GetFloat("maxAcc", 0.065f); // engine power } else if (canmove) { type = "GroundUnit"; } else { type = "Building"; } movedata = NULL; if (canmove && !canfly && (type != "Factory")) { string moveclass = StringToLower(udTable.GetString("movementClass", "")); movedata = moveinfo->GetMoveDataFromName(moveclass); if (!movedata) { const string errmsg = "WARNING: Couldn't find a MoveClass named " + moveclass + " (used in UnitDef: " + unitName + ")"; throw content_error(errmsg); //! invalidate unitDef (this gets catched in ParseUnitDef!) } if ((movedata->moveType == MoveData::Hover_Move) || (movedata->moveType == MoveData::Ship_Move)) { upright = true; } if (canhover) { if (movedata->moveType != MoveData::Hover_Move) { logOutput.Print("Inconsistent movedata %i for %s (moveclass %s): canhover, but not a hovercraft movetype", movedata->pathType, name.c_str(), moveclass.c_str()); } } else if (floater) { if (movedata->moveType != MoveData::Ship_Move) { logOutput.Print("Inconsistent movedata %i for %s (moveclass %s): floater, but not a ship movetype", movedata->pathType, name.c_str(), moveclass.c_str()); } } else { if (movedata->moveType != MoveData::Ground_Move) { logOutput.Print("Inconsistent movedata %i for %s (moveclass %s): neither canhover nor floater, but not a ground movetype", movedata->pathType, name.c_str(), moveclass.c_str()); } } } if ((maxAcc != 0) && (speed != 0)) { //meant to set the drag such that the maxspeed becomes what it should be drag = 1.0f / (speed/GAME_SPEED * 1.1f / maxAcc) - (wingAngle * wingAngle * wingDrag); drag = Clamp(drag, 0.0f, 1.0f); } else { //shouldn't be needed since drag is only used in CAirMoveType anyway, //and aircraft without acceleration or speed aren't common :) //initializing it anyway just for safety drag = 0.005f; } objectName = udTable.GetString("objectName", ""); if (objectName.find(".") == std::string::npos) { objectName += ".3do"; // NOTE: get rid of this? } modelDef.modelPath = "objects3d/" + objectName; modelDef.modelName = objectName; scriptName = udTable.GetString("script", unitName + ".cob"); scriptPath = "scripts/" + scriptName; wreckName = udTable.GetString("corpse", ""); deathExplosion = udTable.GetString("explodeAs", ""); selfDExplosion = udTable.GetString("selfDestructAs", ""); power = udTable.GetFloat("power", (metalCost + (energyCost / 60.0f))); // Prevent a division by zero in experience calculations. if (power < 1.0e-3f) { logOutput.Print("Unit %s is really cheap? %f", humanName.c_str(), power); logOutput.Print("This can cause a division by zero in experience calculations."); power = 1.0e-3f; } activateWhenBuilt = udTable.GetBool("activateWhenBuilt", false); // TA has only half our res so multiply size with 2 xsize = udTable.GetInt("footprintX", 1) * 2; zsize = udTable.GetInt("footprintZ", 1) * 2; needGeo = false; if (speed <= 0.0f) { CreateYardMap(udTable.GetString("yardMap", "")); } leaveTracks = udTable.GetBool("leaveTracks", false); trackTypeName = udTable.GetString("trackType", "StdTank"); trackWidth = udTable.GetFloat("trackWidth", 32.0f); trackOffset = udTable.GetFloat("trackOffset", 0.0f); trackStrength = udTable.GetFloat("trackStrength", 0.0f); trackStretch = udTable.GetFloat("trackStretch", 1.0f); useBuildingGroundDecal = udTable.GetBool("useBuildingGroundDecal", false); buildingDecalTypeName = udTable.GetString("buildingGroundDecalType", ""); buildingDecalSizeX = udTable.GetInt("buildingGroundDecalSizeX", 4); buildingDecalSizeY = udTable.GetInt("buildingGroundDecalSizeY", 4); buildingDecalDecaySpeed = udTable.GetFloat("buildingGroundDecalDecaySpeed", 0.1f); canDropFlare = udTable.GetBool("canDropFlare", false); flareReloadTime = udTable.GetFloat("flareReload", 5.0f); flareDelay = udTable.GetFloat("flareDelay", 0.3f); flareEfficiency = udTable.GetFloat("flareEfficiency", 0.5f); flareDropVector = udTable.GetFloat3("flareDropVector", ZeroVector); flareTime = udTable.GetInt("flareTime", 3) * GAME_SPEED; flareSalvoSize = udTable.GetInt("flareSalvoSize", 4); flareSalvoDelay = udTable.GetInt("flareSalvoDelay", 0) * GAME_SPEED; smoothAnim = udTable.GetBool("smoothAnim", false); canLoopbackAttack = udTable.GetBool("canLoopbackAttack", false); canCrash = udTable.GetBool("canCrash", true); levelGround = udTable.GetBool("levelGround", true); strafeToAttack = udTable.GetBool("strafeToAttack", false); modelCenterOffset = udTable.GetFloat3("modelCenterOffset", ZeroVector); usePieceCollisionVolumes = udTable.GetBool("usePieceCollisionVolumes", false); // initialize the (per-unitdef) collision-volume // all CUnit instances hold a copy of this object collisionVolume = new CollisionVolume( udTable.GetString("collisionVolumeType", ""), udTable.GetFloat3("collisionVolumeScales", ZeroVector), udTable.GetFloat3("collisionVolumeOffsets", ZeroVector), udTable.GetInt("collisionVolumeTest", CollisionVolume::COLVOL_HITTEST_DISC) ); if (usePieceCollisionVolumes) { collisionVolume->Disable(); } seismicRadius = udTable.GetInt("seismicDistance", 0); seismicSignature = udTable.GetFloat("seismicSignature", -1.0f); if (seismicSignature == -1.0f) { if (!floater && !canhover && !canfly) { seismicSignature = sqrt(mass / 100.0f); } else { seismicSignature = 0.0f; } } LuaTable buildsTable = udTable.SubTable("buildOptions"); if (buildsTable.IsValid()) { for (int bo = 1; true; bo++) { const string order = buildsTable.GetString(bo, ""); if (order.empty()) { break; } buildOptions[bo] = order; } } LuaTable sfxTable = udTable.SubTable("SFXTypes"); LuaTable expTable = sfxTable.SubTable("explosionGenerators"); for (int expNum = 1; expNum <= 1024; expNum++) { std::string expsfx = expTable.GetString(expNum, ""); if (expsfx == "") { break; } else { sfxExplGenNames.push_back(expsfx); } } // we use range in a modulo operation, so it needs to be >= 1 pieceTrailCEGTag = udTable.GetString("pieceTrailCEGTag", ""); pieceTrailCEGRange = udTable.GetInt("pieceTrailCEGRange", 1); pieceTrailCEGRange = std::max(pieceTrailCEGRange, 1); // custom parameters table udTable.SubTable("customParams").GetMap(customParams); }
WeaponDef::WeaponDef(const LuaTable& wdTable, const std::string& name_, int id_) : name(name_) , id(id_) , isShield(false) , collisionFlags(0) , explosionGenerator(NULL) , bounceExplosionGenerator(NULL) { WeaponDefs.Load(this, wdTable); if (wdTable.KeyExists("cylinderTargetting")) LOG_L(L_WARNING, "WeaponDef (%s) cylinderTargetting is deprecated and will be removed in the next release (use cylinderTargeting).", name.c_str()); if (wdTable.KeyExists("color1") || wdTable.KeyExists("color2")) LOG_L(L_WARNING, "WeaponDef (%s) color1 & color2 (= hue & sat) are removed. Use rgbColor instead!", name.c_str()); if (wdTable.KeyExists("isShield")) LOG_L(L_WARNING, "WeaponDef (%s) isShield is removed. Use weaponType=\"Shield\" instead!", name.c_str()); shieldRechargeDelay = int(wdTable.GetFloat("rechargeDelay", 0) * GAME_SPEED); flighttime = int(wdTable.GetFloat("flighttime", 0.0f) * 32); //FIXME may be smarter to merge the collideXYZ tags with avoidXYZ and removing the collisionFlags tag (and move the code into CWeapon)? collisionFlags = 0; if (!wdTable.GetBool("collideEnemy", true)) { collisionFlags |= Collision::NOENEMIES; } if (!wdTable.GetBool("collideFriendly", true)) { collisionFlags |= Collision::NOFRIENDLIES; } if (!wdTable.GetBool("collideFeature", true)) { collisionFlags |= Collision::NOFEATURES; } if (!wdTable.GetBool("collideNeutral", true)) { collisionFlags |= Collision::NONEUTRALS; } if (!wdTable.GetBool("collideGround", true)) { collisionFlags |= Collision::NOGROUND; } //FIXME defaults depend on other tags { if (paralyzer) cameraShake = wdTable.GetFloat("cameraShake", 0.0f); if (selfExplode) predictBoost = wdTable.GetFloat("predictBoost", 0.5f); if (type == "Melee") { targetBorder = Clamp(wdTable.GetFloat("targetBorder", 1.0f), -1.0f, 1.0f); cylinderTargeting = Clamp(wdTable.GetFloat("cylinderTargeting", wdTable.GetFloat("cylinderTargetting", 1.0f)), 0.0f, 128.0f); } if (type == "Flame") { //FIXME move to lua (for all other weapons this tag is named `duration` and has a different default) duration = wdTable.GetFloat("flameGfxTime", 1.2f); } if (type == "Cannon") { heightmod = wdTable.GetFloat("heightMod", 0.8f); } else if (type == "BeamLaser" || type == "LightningCannon") { heightmod = wdTable.GetFloat("heightMod", 1.0f); } } // setup the default damages { const LuaTable dmgTable = wdTable.SubTable("damage"); float defDamage = dmgTable.GetFloat("default", 1.0f); if (defDamage == 0.0f) { defDamage = 1.0f; //avoid division by zeros } damages.SetDefaultDamage(defDamage); if (!paralyzer) damages.paralyzeDamageTime = 0; std::map<string, float> dmgs; dmgTable.GetMap(dmgs); std::map<string, float>::const_iterator di; for (di = dmgs.begin(); di != dmgs.end(); ++di) { const int type = damageArrayHandler->GetTypeFromName(di->first); if (type != 0) { float dmg = di->second; if (dmg != 0.0f) { damages[type] = dmg; } else { damages[type] = 1.0f; } } } const float tempsize = 2.0f + std::min(defDamage * 0.0025f, damageAreaOfEffect * 0.1f); size = wdTable.GetFloat("size", tempsize); const float gd = std::max(30.0f, defDamage / 20.0f); const float defExpSpeed = (8.0f + (gd * 2.5f)) / (9.0f + (math::sqrt(gd) * 0.7f)) * 0.5f; explosionSpeed = wdTable.GetFloat("explosionSpeed", defExpSpeed); } { // 0.78.2.1 backwards compatibility: non-burst beamlasers play one // sample per shot, not for each individual beam making up the shot const bool singleSampleShot = (type == "BeamLaser" && !beamburst); const bool singleShotWeapon = (type == "Melee" || type == "Rifle"); soundTrigger = wdTable.GetBool("soundTrigger", singleSampleShot || singleShotWeapon); } // get some weapon specific defaults int defInterceptType = 0; if ((type == "Cannon") || (type == "EmgCannon")) { defInterceptType = 1; } else if ((type == "LaserCannon") || (type == "BeamLaser")) { defInterceptType = 2; } else if ((type == "StarburstLauncher") || (type == "MissileLauncher")) { defInterceptType = 4; } else if (type == "AircraftBomb") { defInterceptType = 8; } else if (type == "Flame") { defInterceptType = 16; } else if (type == "TorpedoLauncher") { defInterceptType = 32; } else if (type == "LightningCannon") { defInterceptType = 64; } else if (type == "Rifle") { defInterceptType = 128; } else if (type == "Melee") { defInterceptType = 256; } interceptedByShieldType = wdTable.GetInt("interceptedByShieldType", defInterceptType); if (type == "Cannon") { // CExplosiveProjectile ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.9f); intensity = wdTable.GetFloat("intensity", 0.2f); } else if (type == "Rifle") { ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.9f); } else if (type == "Melee") { // ... } else if (type == "Flame") { // CFlameProjectile ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.2f); collisionSize = wdTable.GetFloat("collisionSize", 0.5f); } else if (type == "MissileLauncher") { // CMissileProjectile ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.5f); } else if (type == "LaserCannon") { // CLaserProjectile ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.7f); collisionSize = wdTable.GetFloat("collisionSize", 0.5f); } else if (type == "BeamLaser") { ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.7f); } else if (type == "LightningCannon") { ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.5f); } else if (type == "EmgCannon") { // CEmgProjectile ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.5f); size = wdTable.GetFloat("size", 3.0f); } else if (type == "TorpedoLauncher") { assert(waterweapon); waterweapon = true; } else if (type == "DGun") { // CFireBallProjectile ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.5f); collisionSize = wdTable.GetFloat("collisionSize", 10.0f); } else if (type == "StarburstLauncher") { // CStarburstProjectile ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.7f); } else { ownerExpAccWeight = wdTable.GetFloat("ownerExpAccWeight", 0.0f); } const std::string& colormap = wdTable.GetString("colormap", ""); visuals.colorMap = NULL; if (!colormap.empty()) { visuals.colorMap = CColorMap::LoadFromDefString(colormap); } ParseWeaponSounds(wdTable); // custom parameters table wdTable.SubTable("customParams").GetMap(customParams); // internal only isShield = (type == "Shield"); noAutoTarget = (manualfire || interceptor || isShield); onlyForward = !turret && (type != "StarburstLauncher"); }