本文整理汇总了C++中LuaTable类的典型用法代码示例。如果您正苦于以下问题:C++ LuaTable类的具体用法?C++ LuaTable怎么用?C++ LuaTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LuaTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parser
bool SideParser::Load()
{
dataVec.clear();
errorLog.clear();
LuaParser parser("gamedata/sidedata.lua",
SPRING_VFS_MOD_BASE, SPRING_VFS_MOD_BASE);
#if !defined UNITSYNC && !defined DEDICATED
// this should not be included with unitsync:
// 1. avoids linkage with LuaSyncedRead
// 2. ModOptions are not valid during unitsync mod parsing
parser.GetTable("Spring");
parser.AddFunc("GetModOptions", LuaSyncedRead::GetModOptions);
parser.EndTable();
#endif
if (!parser.Execute()) {
errorLog = "Side-Parser: " + parser.GetErrorLog();
return false;
}
std::set<std::string> sideSet;
const LuaTable root = parser.GetRoot();
for (int i = 1; /* no-op */; i++) {
const LuaTable sideTable = root.SubTable(i);
if (!sideTable.IsValid()) {
break;
}
Data data;
data.caseName = sideTable.GetString("name", "");
data.sideName = StringToLower(data.caseName);
data.startUnit = sideTable.GetString("startUnit", "");
data.startUnit = StringToLower(data.startUnit);
if (data.sideName.empty()) {
logOutput.Print("Missing side name: %i", i);
} else if (data.startUnit.empty()) {
logOutput.Print("Missing side start unit: " + data.sideName);
} else if (sideSet.find(data.sideName) != sideSet.end()) {
logOutput.Print("Duplicate side name: " + data.sideName);
} else {
sideSet.insert(data.sideName);
dataVec.push_back(data);
}
}
return true;
}
示例2: _get_bay_ids
// Data format example:
// bay_groups = {
// {0, 500, {1}},
// },
static int _get_bay_ids(lua_State *L, const char *key, SpaceStationType::TBayGroups &outBayGroups, unsigned int &outNumDockingPorts)
{
LUA_DEBUG_START(L);
LuaTable t = LuaTable(L, -1).Sub(key);
if (t.GetLua() == 0) {
luaL_error(L, "The bay group isn't a proper table (%s)", key);
}
if (t.Size() < 1) {
return luaL_error(L, "Station must have at least 1 group of bays in %s", key);
}
LuaTable::VecIter<LuaTable> it_end = t.End<LuaTable>();
for (LuaTable::VecIter<LuaTable> it = t.Begin<LuaTable>(); it != it_end; ++it) {
SpaceStationType::SBayGroup newBay;
newBay.minShipSize = it->Get<int>(1);
newBay.maxShipSize = it->Get<int>(2);
LuaTable group = it->Sub(3);
if (group.GetLua() == 0) {
luaL_error(L, "A group is of the form {int, int, table} (%s)", key);
}
if (group.Size() == 0) {
return luaL_error(L, "Group must have at least 1 bay %s", key);
}
newBay.bayIDs.reserve(group.Size());
LuaTable::VecIter<int> jt_end = group.End<int>();
for (LuaTable::VecIter<int> jt = group.Begin<int>(); jt != jt_end; ++jt) {
if ((*jt) < 1) {
return luaL_error(L, "Valid bay ID ranges start from 1 %s", key);
}
newBay.bayIDs.push_back((*jt)-1);
++outNumDockingPorts;
}
lua_pop(L, 1); // Popping group
outBayGroups.push_back(newBay);
}
lua_pop(L, 1); // Popping t
LUA_DEBUG_END(L, 0);
return 0;
}
示例3: ReadSmf
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);
}
示例4: info_parseInfoItem
static bool info_parseInfoItem(const LuaTable& root, int index, InfoItem& inf,
std::set<string>& infoSet)
{
const LuaTable& infsTbl = root.SubTable(index);
if (!infsTbl.IsValid()) {
LOG_L(L_WARNING, "parseInfoItem: subtable %d invalid", index);
return false;
}
// common info properties
inf.key = infsTbl.GetString("key", "");
if (inf.key.empty()
|| (inf.key.find_first_of(InfoItem_badKeyChars) != string::npos)) {
LOG_L(L_WARNING,
"parseInfoItem: empty key or key contains bad characters");
return false;
}
std::string lowerKey = StringToLower(inf.key);
if (infoSet.find(inf.key) != infoSet.end()) {
LOG_L(L_WARNING, "parseInfoItem: key toLowerCase(%s) exists already",
inf.key.c_str());
return false;
}
// TODO add support for info value types other then string
inf.valueType = INFO_VALUE_TYPE_STRING;
inf.valueTypeString = infsTbl.GetString("value", "");
if (inf.valueTypeString.empty()) {
LOG_L(L_WARNING, "parseInfoItem: %s: empty value", inf.key.c_str());
return false;
}
inf.desc = infsTbl.GetString("desc", "");
infoSet.insert(lowerKey);
return true;
}
示例5: clear
void GameSound::loadSound( const Variant& v )
{
clear();
if (v.type != Variant::kTable) {
return;
}
LuaTable table = v;
table.beginRead();
String name = table.get("sound");
m_minDist = table.get("minDist");
m_maxDist = table.get("maxDist");
m_looping = table.get("looping");
m_interval = table.get("interval");
table.endRead();
if (name.empty())
return;
m_sfx << g_soundSystem->createSfx(name);
}
示例6: main
int main()
{
Lua lua;
LuaTable tbl = lua.CreateTable();
tbl.Set("name", "Chuck Norris");
tbl.Set("age", 1337);
tbl.Set("0", "divide by");
tbl.Set(1337, "leet");
int keys = 3;
tbl.ForAllStringKeys([&](std::string key, LuaType::Value value)
{
keys--;
});
return keys;
}
示例7: content_error
MoveDefHandler::MoveDefHandler(LuaParser* defsParser)
{
const LuaTable rootTable = defsParser->GetRoot().SubTable("MoveDefs");
if (!rootTable.IsValid())
throw content_error("Error loading movement definitions");
CRC crc;
for (int tt = 0; tt < CMapInfo::NUM_TERRAIN_TYPES; ++tt) {
const CMapInfo::TerrainType& terrType = mapInfo->terrainTypes[tt];
crc << terrType.tankSpeed << terrType.kbotSpeed;
crc << terrType.hoverSpeed << terrType.shipSpeed;
}
moveDefs.reserve(rootTable.GetLength());
for (size_t num = 1; /* no test */; num++) {
const LuaTable moveDefTable = rootTable.SubTable(num);
if (!moveDefTable.IsValid()) {
break;
}
moveDefs.emplace_back(moveDefTable, num);
const MoveDef& md = moveDefs.back();
moveDefNames[md.name] = md.pathType;
crc << md.GetCheckSum();
}
CMoveMath::noHoverWaterMove = (mapInfo->water.damage >= MAX_ALLOWED_WATER_DAMAGE_HMM);
CMoveMath::waterDamageCost = (mapInfo->water.damage >= MAX_ALLOWED_WATER_DAMAGE_GMM)?
0.0f: (1.0f / (1.0f + mapInfo->water.damage * 0.1f));
crc << CMoveMath::waterDamageCost;
crc << CMoveMath::noHoverWaterMove;
checksum = crc.GetDigest();
}
示例8: luaParser
/** Load the messages from gamedata/messages.lua into memory. */
void CMessages::Load()
{
LuaParser luaParser("gamedata/messages.lua",
SPRING_VFS_MOD_BASE, SPRING_VFS_MOD_BASE);
if (!luaParser.Execute()) {
// Show parse errors in the infolog.
logOutput.Print(string("ERROR: messages.lua: ") + luaParser.GetErrorLog());
return;
}
const LuaTable root = luaParser.GetRoot();
vector<string> labels;
root.GetKeys(labels);
for (size_t l = 0; l < labels.size(); l++) {
const string label = StringToLower(labels[l]);
const LuaTable msgTable = root.SubTable(label);
if (!msgTable.IsValid()) {
continue;
}
vector<string> msgs;
for (int s = 1; true; s++) {
const string msg = msgTable.GetString(s, "");
if (msg.empty()) {
break;
}
msgs.push_back(msg);
}
if (!msgs.empty()) {
tr[label] = msgs;
}
}
loaded = true;
}
示例9: StringToLower
/*
* 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);
}
}
示例10: p
void CArchiveScanner::ReadCacheData(const std::string& filename)
{
LuaParser p(filename, SPRING_VFS_RAW, SPRING_VFS_BASE);
if (!p.Execute()) {
logOutput.Print("Warning: Failed to read archive cache: " + p.GetErrorLog());
return;
}
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 = CArchiveScanner::ArchiveData(archived);
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");
}
std::string lcname = StringToLower(ai.origName);
archiveInfo[lcname] = ai;
}
const LuaTable brokenArchives = archiveCache.SubTable("brokenArchives");
for (int i = 1; brokenArchives.KeyExists(i); ++i) {
const LuaTable curArchive = brokenArchives.SubTable(i);
BrokenArchive ba;
std::string name = curArchive.GetString("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");
StringToLowerInPlace(name);
this->brokenArchives[name] = ba;
}
isDirty = false;
}
示例11: SetModelRadiusAndHeight
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;
}
示例12: LoadPieceTransformations
void CAssParser::LoadPieceTransformations(
SAssPiece* piece,
const S3DModel* model,
const aiNode* pieceNode,
const LuaTable& pieceTable
) {
aiVector3D aiScaleVec, aiTransVec;
aiQuaternion aiRotateQuat;
// process transforms
pieceNode->mTransformation.Decompose(aiScaleVec, aiRotateQuat, aiTransVec);
// metadata-scaling
piece->scales = pieceTable.GetFloat3("scale", aiVectorToFloat3(aiScaleVec));
piece->scales.x = pieceTable.GetFloat("scalex", piece->scales.x);
piece->scales.y = pieceTable.GetFloat("scaley", piece->scales.y);
piece->scales.z = pieceTable.GetFloat("scalez", piece->scales.z);
if (piece->scales.x != piece->scales.y || piece->scales.y != piece->scales.z) {
// LOG_SL(LOG_SECTION_MODEL, L_WARNING, "Spring doesn't support non-uniform scaling");
piece->scales.y = piece->scales.x;
piece->scales.z = piece->scales.x;
}
// metadata-translation
piece->offset = pieceTable.GetFloat3("offset", aiVectorToFloat3(aiTransVec));
piece->offset.x = pieceTable.GetFloat("offsetx", piece->offset.x);
piece->offset.y = pieceTable.GetFloat("offsety", piece->offset.y);
piece->offset.z = pieceTable.GetFloat("offsetz", piece->offset.z);
// metadata-rotation
// NOTE:
// these rotations are "pre-scripting" but "post-modelling"
// together with the (baked) aiRotateQuad they determine the
// model's pose *before* any animations execute
//
// float3 rotAngles = pieceTable.GetFloat3("rotate", aiQuaternionToRadianAngles(aiRotateQuat) * RADTODEG);
float3 pieceRotAngles = pieceTable.GetFloat3("rotate", ZeroVector);
pieceRotAngles.x = pieceTable.GetFloat("rotatex", pieceRotAngles.x);
pieceRotAngles.y = pieceTable.GetFloat("rotatey", pieceRotAngles.y);
pieceRotAngles.z = pieceTable.GetFloat("rotatez", pieceRotAngles.z);
pieceRotAngles *= DEGTORAD;
LOG_SL(LOG_SECTION_PIECE, L_INFO,
"(%d:%s) Assimp offset (%f,%f,%f), rotate (%f,%f,%f,%f), scale (%f,%f,%f)",
model->numPieces, piece->name.c_str(),
aiTransVec.x, aiTransVec.y, aiTransVec.z,
aiRotateQuat.w, aiRotateQuat.x, aiRotateQuat.y, aiRotateQuat.z,
aiScaleVec.x, aiScaleVec.y, aiScaleVec.z
);
LOG_SL(LOG_SECTION_PIECE, L_INFO,
"(%d:%s) Relative offset (%f,%f,%f), rotate (%f,%f,%f), scale (%f,%f,%f)",
model->numPieces, piece->name.c_str(),
piece->offset.x, piece->offset.y, piece->offset.z,
pieceRotAngles.x, pieceRotAngles.y, pieceRotAngles.z,
piece->scales.x, piece->scales.y, piece->scales.z
);
// NOTE:
// at least collada (.dae) files generated by Blender represent
// a coordinate-system that differs from the "standard" formats
// (3DO, S3O, ...) for which existing tools at least have prior
// knowledge of Spring's expectations --> let the user override
// the ROOT rotational transform and the rotation-axis mapping
// used by animation scripts (but re-modelling/re-exporting is
// always preferred!) even though AssImp should convert models
// to its own system which matches that of Spring
//
// .dae : x=Rgt, y=-Fwd, z= Up, as=(-1, -1, 1), am=AXIS_XZY (if Z_UP)
// .dae : x=Rgt, y=-Fwd, z= Up, as=(-1, -1, 1), am=AXIS_XZY (if Y_UP) [!?]
// .blend: ????
piece->bakedRotMatrix = aiMatrixToMatrix(aiMatrix4x4t<float>(aiRotateQuat.GetMatrix()));
if (piece == model->GetRootPiece()) {
const float3 xaxis = pieceTable.GetFloat3("xaxis", piece->bakedRotMatrix.GetX());
const float3 yaxis = pieceTable.GetFloat3("yaxis", piece->bakedRotMatrix.GetY());
const float3 zaxis = pieceTable.GetFloat3("zaxis", piece->bakedRotMatrix.GetZ());
if (math::fabs(xaxis.SqLength() - yaxis.SqLength()) < 0.01f && math::fabs(yaxis.SqLength() - zaxis.SqLength()) < 0.01f) {
piece->bakedRotMatrix = CMatrix44f(ZeroVector, xaxis, yaxis, zaxis);
}
}
piece->rotAxisSigns = pieceTable.GetFloat3("rotAxisSigns", float3(-OnesVector));
piece->axisMapType = AxisMappingType(pieceTable.GetInt("rotAxisMap", AXIS_MAPPING_XYZ));
// construct 'baked' part of the piece-space matrix
// AssImp order is translate * rotate * scale * v;
// we leave the translation and scale parts out and
// put those in <offset> and <scales> --> transform
// is just R instead of T * R * S
//
// note: for all non-AssImp models this is identity!
//
piece->ComposeRotation(piece->bakedRotMatrix, pieceRotAngles);
piece->SetHasIdentityRotation(piece->bakedRotMatrix.IsIdentity() == 0);
assert(piece->bakedRotMatrix.IsOrthoNormal() == 0);
}
示例13: parser
void CModInfo::Init(const char* modname)
{
filename = modname;
humanName = archiveScanner->ModArchiveToModName(modname);
const CArchiveScanner::ModData md = archiveScanner->ModArchiveToModData(modname);
shortName = md.shortName;
version = md.version;
mutator = md.mutator;
description = md.description;
// initialize the parser
LuaParser parser("gamedata/modrules.lua",
SPRING_VFS_MOD_BASE, SPRING_VFS_ZIP);
// customize the defs environment
parser.GetTable("Spring");
parser.AddFunc("GetModOptions", LuaSyncedRead::GetModOptions);
parser.EndTable();
parser.Execute();
if (!parser.IsValid()) {
logOutput.Print("Error loading modrules, using defaults");
logOutput.Print(parser.GetErrorLog());
}
const LuaTable root = parser.GetRoot();
// determine if bombers are allowed to leave map boundaries
const LuaTable movementTbl = root.SubTable("movement");
allowAirPlanesToLeaveMap = movementTbl.GetBool("allowAirPlanesToLeaveMap", true);
// determine whether the modder allows the user to use team coloured nanospray
const LuaTable nanosprayTbl = root.SubTable("nanospray");
allowTeamColors = nanosprayTbl.GetBool("allow_team_colors", true);
if (allowTeamColors) {
// Load the users preference for team coloured nanospray
gu->teamNanospray = !!configHandler->Get("TeamNanoSpray", 1);
}
// constructions
const LuaTable constructionTbl = root.SubTable("construction");
constructionDecay = constructionTbl.GetBool("constructionDecay", true);
constructionDecayTime = (int)(constructionTbl.GetFloat("constructionDecayTime", 6.66) * 30);
constructionDecaySpeed = constructionTbl.GetFloat("constructionDecaySpeed", 0.03);
// reclaim
const LuaTable reclaimTbl = root.SubTable("reclaim");
multiReclaim = reclaimTbl.GetInt("multiReclaim", 0);
reclaimMethod = reclaimTbl.GetInt("reclaimMethod", 1);
reclaimUnitMethod = reclaimTbl.GetInt("unitMethod", 1);
reclaimUnitEnergyCostFactor = reclaimTbl.GetFloat("unitEnergyCostFactor", 0.0);
reclaimUnitEfficiency = reclaimTbl.GetFloat("unitEfficiency", 1.0);
reclaimFeatureEnergyCostFactor = reclaimTbl.GetFloat("featureEnergyCostFactor", 0.0);
reclaimAllowEnemies = reclaimTbl.GetBool("allowEnemies", true);
reclaimAllowAllies = reclaimTbl.GetBool("allowAllies", true);
// repair
const LuaTable repairTbl = root.SubTable("repair");
repairEnergyCostFactor = repairTbl.GetFloat("energyCostFactor", 0.0);
// resurrect
const LuaTable resurrectTbl = root.SubTable("resurrect");
resurrectEnergyCostFactor = resurrectTbl.GetFloat("energyCostFactor", 0.5);
// capture
const LuaTable captureTbl = root.SubTable("capture");
captureEnergyCostFactor = captureTbl.GetFloat("energyCostFactor", 0.0);
// fire-at-dead-units
const LuaTable fireAtDeadTbl = root.SubTable("fireAtDead");
fireAtKilled = fireAtDeadTbl.GetBool("fireAtKilled", false);
fireAtCrashing = fireAtDeadTbl.GetBool("fireAtCrashing", false);
// transportability
const LuaTable transportTbl = root.SubTable("transportability");
transportAir = transportTbl.GetInt("transportAir", false);
transportShip = transportTbl.GetInt("transportShip", false);
transportHover = transportTbl.GetInt("transportHover", false);
transportGround = transportTbl.GetInt("transportGround", true);
// experience
const LuaTable experienceTbl = root.SubTable("experience");
CUnit::SetExpMultiplier (experienceTbl.GetFloat("experienceMult", 1.0f));
CUnit::SetExpPowerScale (experienceTbl.GetFloat("powerScale", 1.0f));
CUnit::SetExpHealthScale(experienceTbl.GetFloat("healthScale", 0.7f));
CUnit::SetExpReloadScale(experienceTbl.GetFloat("reloadScale", 0.4f));
// flanking bonus
const LuaTable flankingBonusTbl = root.SubTable("flankingBonus");
flankingBonusModeDefault = flankingBonusTbl.GetInt("defaultMode", 1);
// feature visibility
const LuaTable featureLOS = root.SubTable("featureLOS");
featureVisibility = featureLOS.GetInt("featureVisibility", 3);
if (featureVisibility < 0 || featureVisibility > 3)
throw content_error("invalid modinfo: featureVisibility, valid range is 0..3");
// sensors
const LuaTable sensors = root.SubTable("sensors");
requireSonarUnderWater = sensors.GetBool("requireSonarUnderWater", true);
//.........这里部分代码省略.........
示例14: ParseWeaponsTable
void UnitDef::ParseWeaponsTable(const LuaTable& weaponsTable)
{
const WeaponDef* noWeaponDef = weaponDefHandler->GetWeapon("NOWEAPON");
for (int w = 0; w < MAX_WEAPONS_PER_UNIT; 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 (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 {
weapons.push_back(UnitDefWeapon());
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)).SafeNormalize();
const float angleDif = cos(wTable.GetFloat("maxAngleDif", 360.0f) * (PI / 360.0f));
const float fuelUse = wTable.GetFloat("fuelUsage", 0.0f);
UnitDefWeapon weapon(name, wd, slaveTo, mainDir, angleDif, btc, otc, fuelUse);
weapons.push_back(weapon);
maxWeaponRange = std::max(maxWeaponRange, wd->range);
if (wd->interceptor && wd->coverageRange > maxCoverage)
maxCoverage = wd->coverageRange;
if (wd->isShield) {
if (!shieldWeaponDef || // use the biggest shield
(shieldWeaponDef->shieldRadius < wd->shieldRadius)) {
shieldWeaponDef = wd;
}
}
if (wd->stockpile) {
// interceptors have priority
if (wd->interceptor ||
!stockpileWeaponDef ||
!stockpileWeaponDef->interceptor) {
stockpileWeaponDef = wd;
}
}
}
}
示例15: content_error
void CCustomExplosionGenerator::Load(CExplosionGeneratorHandler* h, const string& tag)
{
static std::map<string, CEGData> cachedCEGs;
std::map<string, CEGData>::iterator it = cachedCEGs.find(tag);
if (it == cachedCEGs.end()) {
CEGData cegData;
const LuaTable& root = h->GetTable();
const LuaTable expTable = root.SubTable(tag);
if (!expTable.IsValid()) {
throw content_error("Explosion info for " + tag + " not found.");
}
vector<string> spawns;
expTable.GetKeys(spawns);
for (vector<string>::iterator si = spawns.begin(); si != spawns.end(); ++si) {
ProjectileSpawnInfo psi;
const string& spawnName = *si;
const LuaTable spawnTable = expTable.SubTable(spawnName);
if (!spawnTable.IsValid() || spawnName == "groundflash") {
continue;
}
const string className = spawnTable.GetString("class", spawnName);
unsigned int flags = 0;
if (spawnTable.GetBool("ground", false)) {
flags |= SPW_GROUND;
}
if (spawnTable.GetBool("water", false)) {
flags |= SPW_WATER;
}
if (spawnTable.GetBool("air", false)) {
flags |= SPW_AIR;
}
if (spawnTable.GetBool("underwater", false)) {
flags |= SPW_UNDERWATER;
}
if (spawnTable.GetBool("unit", false)) {
flags |= SPW_UNIT;
}
if (spawnTable.GetBool("nounit", false)) {
flags |= SPW_NO_UNIT;
}
psi.projectileClass = h->projectileClasses.GetClass(className);
psi.flags = flags;
psi.count = spawnTable.GetInt("count", 1);
string code;
map<string, string> props;
map<string, string>::const_iterator propIt;
spawnTable.SubTable("properties").GetMap(props);
for (propIt = props.begin(); propIt != props.end(); ++propIt) {
creg::Class::Member* m = psi.projectileClass->FindMember(propIt->first.c_str());
if (m && (m->flags & creg::CM_Config)) {
ParseExplosionCode(&psi, m->offset, m->type, propIt->second, code);
}
}
code += (char)OP_END;
psi.code.resize(code.size());
copy(code.begin(), code.end(), psi.code.begin());
cegData.projectileSpawn.push_back(psi);
}
const LuaTable gndTable = expTable.SubTable("groundflash");
const int ttl = gndTable.GetInt("ttl", 0);
if (ttl > 0) {
cegData.groundFlash.circleAlpha = gndTable.GetFloat("circleAlpha", 0.0f);
cegData.groundFlash.flashSize = gndTable.GetFloat("flashSize", 0.0f);
cegData.groundFlash.flashAlpha = gndTable.GetFloat("flashAlpha", 0.0f);
cegData.groundFlash.circleGrowth = gndTable.GetFloat("circleGrowth", 0.0f);
cegData.groundFlash.color = gndTable.GetFloat3("color", float3(1.0f, 1.0f, 0.8f));
unsigned int flags = SPW_GROUND;
if (gndTable.GetBool("ground", false)) {
flags |= SPW_GROUND;
}
if (gndTable.GetBool("water", false)) {
flags |= SPW_WATER;
}
if (gndTable.GetBool("air", false)) {
flags |= SPW_AIR;
}
if (gndTable.GetBool("underwater", false)) {
flags |= SPW_UNDERWATER;
}
if (gndTable.GetBool("unit", false)) {
flags |= SPW_UNIT;
}
if (gndTable.GetBool("nounit", false)) {
flags |= SPW_NO_UNIT;
}
//.........这里部分代码省略.........