本文整理汇总了C++中LuaTable::GetMap方法的典型用法代码示例。如果您正苦于以下问题:C++ LuaTable::GetMap方法的具体用法?C++ LuaTable::GetMap怎么用?C++ LuaTable::GetMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LuaTable
的用法示例。
在下文中一共展示了LuaTable::GetMap方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadSoundDefs
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;
}
示例2: LoadSoundDefs
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;
}
示例3: ParseAtlasTextures
void CProjectileDrawer::ParseAtlasTextures(
const bool blockTextures,
const LuaTable& textureTable,
std::set<std::string>& blockedTextures,
CTextureAtlas* textureAtlas)
{
std::vector<std::string> subTables;
std::map<std::string, std::string> texturesMap;
std::map<std::string, std::string>::iterator texturesMapIt;
textureTable.GetMap(texturesMap);
textureTable.GetKeys(subTables);
for (texturesMapIt = texturesMap.begin(); texturesMapIt != texturesMap.end(); ++texturesMapIt) {
const std::string textureName = StringToLower(texturesMapIt->first);
if (blockTextures) {
// no textures added to this atlas are allowed
// to be overwritten later by other textures of
// the same name
blockedTextures.insert(textureName);
}
if (blockTextures || (blockedTextures.find(textureName) == blockedTextures.end())) {
textureAtlas->AddTexFromFile(texturesMapIt->first, "bitmaps/" + texturesMapIt->second);
}
}
texturesMap.clear();
for (size_t i = 0; i < subTables.size(); i++) {
const LuaTable& textureSubTable = textureTable.SubTable(subTables[i]);
if (textureSubTable.IsValid()) {
textureSubTable.GetMap(texturesMap);
for (texturesMapIt = texturesMap.begin(); texturesMapIt != texturesMap.end(); ++texturesMapIt) {
const std::string textureName = StringToLower(texturesMapIt->first);
if (blockTextures) {
blockedTextures.insert(textureName);
}
if (blockTextures || (blockedTextures.find(textureName) == blockedTextures.end())) {
textureAtlas->AddTexFromFile(texturesMapIt->first, "bitmaps/" + texturesMapIt->second);
}
}
texturesMap.clear();
}
}
}
示例4: Load
void ClassAliasList::Load(const LuaTable& aliasTable)
{
map<string, string> aliasList;
aliasTable.GetMap(aliasList);
aliases.insert(aliasList.begin(), aliasList.end());
}
示例5: LoadSoundDefsImpl
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;
}
示例6: ParseTAWeapon
//.........这里部分代码省略.........
logOutput.Print("warning: targetBorder truncated to 1 (was %f)", wd.targetBorder);
wd.targetBorder = 1.0f;
} else if (wd.targetBorder < -1.0f) {
logOutput.Print("warning: targetBorder truncated to -1 (was %f)", wd.targetBorder);
wd.targetBorder = -1.0f;
}
wd.cylinderTargetting = wdTable.GetFloat("cylinderTargetting", melee ? 1.0f : 0.0f);
wd.range = wdTable.GetFloat("range", 10.0f);
const float accuracy = wdTable.GetFloat("accuracy", 0.0f);
const float sprayangle = wdTable.GetFloat("sprayAngle", 0.0f);
const float movingAccuracy = wdTable.GetFloat("movingAccuracy", accuracy);
// should really be tan but TA seem to cap it somehow
// should also be 7fff or ffff theoretically but neither seems good
wd.accuracy = sin((accuracy) * PI / 0xafff);
wd.sprayangle = sin((sprayangle) * PI / 0xafff);
wd.movingAccuracy = sin((movingAccuracy) * PI / 0xafff);
wd.targetMoveError = wdTable.GetFloat("targetMoveError", 0.0f);
wd.leadLimit = wdTable.GetFloat("leadLimit", -1.0f);
wd.leadBonus = wdTable.GetFloat("leadBonus", 0.0f);
// setup the default damages
const LuaTable dmgTable = wdTable.SubTable("damage");
float defDamage = dmgTable.GetFloat("default", 0.0f);
if (defDamage == 0.0f) {
defDamage = 1.0f; //avoid division by zeroes
}
for (int a = 0; a < damageArrayHandler->GetNumTypes(); ++a) {
wd.damages[a] = defDamage;
}
map<string, float> damages;
dmgTable.GetMap(damages);
map<string, float>::const_iterator di;
for (di = damages.begin(); di != damages.end(); ++di) {
const int type = damageArrayHandler->GetTypeFromName(di->first);
if (type != 0) {
float dmg = di->second;
if (dmg != 0.0f) {
wd.damages[type] = dmg;
} else {
wd.damages[type] = 1.0f;
}
}
}
wd.damages.impulseFactor = wdTable.GetFloat("impulseFactor", 1.0f);
wd.damages.impulseBoost = wdTable.GetFloat("impulseBoost", 0.0f);
wd.damages.craterMult = wdTable.GetFloat("craterMult", wd.damages.impulseFactor);
wd.damages.craterBoost = wdTable.GetFloat("craterBoost", 0.0f);
wd.areaOfEffect = wdTable.GetFloat("areaOfEffect", 8.0f) * 0.5f;
wd.edgeEffectiveness = wdTable.GetFloat("edgeEffectiveness", 0.0f);
// prevent 0/0 division in CGameHelper::Explosion
if (wd.edgeEffectiveness > 0.999f) {
wd.edgeEffectiveness = 0.999f;
}
wd.projectilespeed = wdTable.GetFloat("weaponVelocity", 0.0f) / GAME_SPEED;
wd.startvelocity = max(0.01f, wdTable.GetFloat("startVelocity", 0.0f) / GAME_SPEED);
wd.weaponacceleration = wdTable.GetFloat("weaponAcceleration", 0.0f) / GAME_SPEED / GAME_SPEED;
wd.reload = wdTable.GetFloat("reloadtime", 1.0f);
wd.salvodelay = wdTable.GetFloat("burstrate", 0.1f);
wd.salvosize = wdTable.GetInt("burst", 1);
示例7: name
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;
}
}
}
//.........这里部分代码省略.........
示例8: resourcesParser
CProjectileHandler::CProjectileHandler()
{
PrintLoadMsg("Creating projectile texture");
maxParticles = configHandler->Get("MaxParticles", 4000);
maxNanoParticles = configHandler->Get("MaxNanoParticles", 10000);
currentParticles = 0;
currentNanoParticles = 0;
particleSaturation = 0.0f;
nanoParticleSaturation = 0.0f;
numPerlinProjectiles = 0;
// preload some IDs
// (note that 0 is reserved for unsynced projectiles)
for (int i = 1; i <= 12345; i++) {
freeIDs.push_back(i);
}
maxUsedID = freeIDs.size();
textureAtlas = new CTextureAtlas(2048, 2048);
// used to block resources_map.tdf from loading textures
set<string> blockMapTexNames;
LuaParser resourcesParser("gamedata/resources.lua",
SPRING_VFS_MOD_BASE, SPRING_VFS_ZIP);
if (!resourcesParser.Execute()) {
logOutput.Print(resourcesParser.GetErrorLog());
}
const LuaTable rootTable = resourcesParser.GetRoot();
const LuaTable gfxTable = rootTable.SubTable("graphics");
const LuaTable ptTable = gfxTable.SubTable("projectileTextures");
// add all textures in projectiletextures section
map<string, string> ptex;
ptTable.GetMap(ptex);
for (map<string, string>::iterator pi=ptex.begin(); pi!=ptex.end(); ++pi) {
textureAtlas->AddTexFromFile(pi->first, "bitmaps/" + pi->second);
blockMapTexNames.insert(StringToLower(pi->first));
}
// add all texture from sections within projectiletextures section
vector<string> seclist;
ptTable.GetKeys(seclist);
for (size_t i = 0; i < seclist.size(); i++) {
const LuaTable ptSubTable = ptTable.SubTable(seclist[i]);
if (ptSubTable.IsValid()) {
map<string, string> ptex2;
ptSubTable.GetMap(ptex2);
for (map<string, string>::iterator pi = ptex2.begin(); pi != ptex2.end(); ++pi) {
textureAtlas->AddTexFromFile(pi->first, "bitmaps/" + pi->second);
blockMapTexNames.insert(StringToLower(pi->first));
}
}
}
// get the smoke textures, hold the count in 'smokeCount'
const LuaTable smokeTable = gfxTable.SubTable("smoke");
int smokeCount;
if (smokeTable.IsValid()) {
for (smokeCount = 0; true; smokeCount++) {
const string tex = smokeTable.GetString(smokeCount + 1, "");
if (tex.empty()) {
break;
}
const string texName = "bitmaps/" + tex;
const string smokeName = "ismoke" + IntToString(smokeCount, "%02i");
textureAtlas->AddTexFromFile(smokeName, texName);
blockMapTexNames.insert(StringToLower(smokeName));
}
}
else {
// setup the defaults
for (smokeCount = 0; smokeCount < 12; smokeCount++) {
const string smokeNum = IntToString(smokeCount, "%02i");
const string smokeName = "ismoke" + smokeNum;
const string texName = "bitmaps/smoke/smoke" + smokeNum + ".tga";
textureAtlas->AddTexFromFile(smokeName, texName);
blockMapTexNames.insert(StringToLower(smokeName));
}
}
if (smokeCount <= 0) {
throw content_error("missing smoke textures");
}
char tex[128][128][4];
for (int y = 0; y < 128; y++) { // shield
for (int x = 0; x < 128; x++) {
tex[y][x][0] = 70;
tex[y][x][1] = 70;
tex[y][x][2] = 70;
tex[y][x][3] = 70;
}
}
textureAtlas->AddTexFromMem("perlintex", 128, 128, CTextureAtlas::RGBA32, tex);
blockMapTexNames.insert("perlintex");
blockMapTexNames.insert("flare");
//.........这里部分代码省略.........
示例9: ParseWeapon
void CWeaponDefHandler::ParseWeapon(const LuaTable& wdTable, WeaponDef& wd)
{
bool manualBombSettings; //Allow the user to manually specify the burst and burstrate for his AircraftBomb
int color;
int color2;
wd.tdfId = wdTable.GetInt("id", 0);
wd.description = wdTable.GetString("name", "Weapon");
wd.cegTag = wdTable.GetString("cegTag", "");
wd.avoidFriendly = wdTable.GetBool("avoidFriendly", true);
wd.avoidFeature = wdTable.GetBool("avoidFeature", true);
wd.avoidNeutral = wdTable.GetBool("avoidNeutral", false);
//FIXME may be smarter to merge the collideXYZ tags with avoidXYZ and removing the collisionFlags tag (and move the code into CWeapon)?
wd.collisionFlags = 0;
if (!wdTable.GetBool("collideEnemy", true)) { wd.collisionFlags |= Collision::NOENEMIES; }
if (!wdTable.GetBool("collideFriendly", true)) { wd.collisionFlags |= Collision::NOFRIENDLIES; }
if (!wdTable.GetBool("collideFeature", true)) { wd.collisionFlags |= Collision::NOFEATURES; }
if (!wdTable.GetBool("collideNeutral", true)) { wd.collisionFlags |= Collision::NONEUTRALS; }
if (!wdTable.GetBool("collideGround", true)) { wd.collisionFlags |= Collision::NOGROUND; }
wd.minIntensity = wdTable.GetFloat("minIntensity", 0.0f);
manualBombSettings = wdTable.GetBool("manualBombSettings", false);
wd.turret = wdTable.GetBool("turret", false);
wd.highTrajectory = wdTable.GetInt("highTrajectory", 2);
wd.noSelfDamage = wdTable.GetBool("noSelfDamage", false);
wd.impactOnly = wdTable.GetBool("impactOnly", false);
wd.waterweapon = wdTable.GetBool("waterWeapon", false);
wd.fireSubmersed = wdTable.GetBool("fireSubmersed", wd.waterweapon);
wd.submissile = wdTable.GetBool("submissile", false);
wd.tracks = wdTable.GetBool("tracks", false);
wd.fixedLauncher = wdTable.GetBool("fixedLauncher", false);
wd.noExplode = wdTable.GetBool("noExplode", false);
wd.isShield = wdTable.GetBool("isShield", false);
wd.beamtime = wdTable.GetFloat("beamTime", 1.0f);
wd.beamburst = wdTable.GetBool("beamburst", false);
wd.waterBounce = wdTable.GetBool("waterBounce", false);
wd.groundBounce = wdTable.GetBool("groundBounce", false);
wd.bounceSlip = wdTable.GetFloat("bounceSlip", 1.0f);
wd.bounceRebound = wdTable.GetFloat("bounceRebound", 1.0f);
wd.numBounce = wdTable.GetInt("numBounce", -1);
wd.thickness = wdTable.GetFloat("thickness", 2.0f);
wd.corethickness = wdTable.GetFloat("coreThickness", 0.25f);
wd.laserflaresize = wdTable.GetFloat("laserFlareSize", 15.0f);
wd.intensity = wdTable.GetFloat("intensity", 0.9f);
wd.duration = wdTable.GetFloat("duration", 0.05f);
wd.falloffRate = wdTable.GetFloat("fallOffRate", 0.5f);
wd.lodDistance = wdTable.GetInt("lodDistance", 1000);
wd.visuals.modelName = wdTable.GetString("model", "");
wd.visuals.explosionScar = wdTable.GetBool("explosionScar", true);
wd.visuals.smokeTrail = wdTable.GetBool("smokeTrail", false);
wd.visuals.alwaysVisible = wdTable.GetBool("alwaysVisible", false);
wd.visuals.sizeDecay = wdTable.GetFloat("sizeDecay", 0.0f);
wd.visuals.alphaDecay = wdTable.GetFloat("alphaDecay", 1.0f);
wd.visuals.separation = wdTable.GetFloat("separation", 1.0f);
wd.visuals.noGap = wdTable.GetBool("noGap", true);
wd.visuals.stages = wdTable.GetInt("stages", 5);
wd.gravityAffected = wdTable.GetBool("gravityAffected", false);
wd.type = wdTable.GetString("weaponType", "Cannon");
wd.targetBorder = Clamp(wdTable.GetFloat("targetBorder", (wd.type == "Melee")? 1.0f : 0.0f), -1.0f, 1.0f);
wd.cylinderTargetting = Clamp(wdTable.GetFloat("cylinderTargetting", (wd.type == "Melee")? 1.0f : 0.0f), 0.0f, 128.0f);
wd.range = wdTable.GetFloat("range", 10.0f);
const float accuracy = wdTable.GetFloat("accuracy", 0.0f);
const float sprayAngle = wdTable.GetFloat("sprayAngle", 0.0f);
const float movingAccuracy = wdTable.GetFloat("movingAccuracy", accuracy);
// should really be tan but TA seem to cap it somehow
// should also be 7fff or ffff theoretically but neither seems good
wd.accuracy = sin((accuracy) * PI / 0xafff);
wd.sprayAngle = sin((sprayAngle) * PI / 0xafff);
wd.movingAccuracy = sin((movingAccuracy) * PI / 0xafff);
wd.targetMoveError = wdTable.GetFloat("targetMoveError", 0.0f);
wd.leadLimit = wdTable.GetFloat("leadLimit", -1.0f);
wd.leadBonus = wdTable.GetFloat("leadBonus", 0.0f);
// setup the default damages
const LuaTable dmgTable = wdTable.SubTable("damage");
float defDamage = dmgTable.GetFloat("default", 0.0f);
if (defDamage == 0.0f) {
defDamage = 1.0f; //avoid division by zeroes
}
for (int a = 0; a < damageArrayHandler->GetNumTypes(); ++a) {
wd.damages[a] = defDamage;
}
map<string, float> damages;
dmgTable.GetMap(damages);
//.........这里部分代码省略.........
示例10: resourcesParser
CProjectileDrawer::CProjectileDrawer(): CEventClient("[CProjectileDrawer]", 123456, false) {
eventHandler.AddClient(this);
loadscreen->SetLoadMessage("Creating Projectile Textures");
textureAtlas = new CTextureAtlas(2048, 2048);
// used to block resources_map.tdf from loading textures
std::set<std::string> blockMapTexNames;
LuaParser resourcesParser("gamedata/resources.lua", SPRING_VFS_MOD_BASE, SPRING_VFS_ZIP);
resourcesParser.Execute();
const LuaTable rootTable = resourcesParser.GetRoot();
const LuaTable gfxTable = rootTable.SubTable("graphics");
const LuaTable ptTable = gfxTable.SubTable("projectileTextures");
// add all textures in projectiletextures section
std::map<std::string, std::string> ptex;
ptTable.GetMap(ptex);
for (std::map<std::string, std::string>::iterator pi = ptex.begin(); pi != ptex.end(); ++pi) {
textureAtlas->AddTexFromFile(pi->first, "bitmaps/" + pi->second);
blockMapTexNames.insert(StringToLower(pi->first));
}
ptex.clear();
// add all texture from sections within projectiletextures section
std::vector<std::string> seclist;
ptTable.GetKeys(seclist);
for (size_t i = 0; i < seclist.size(); i++) {
const LuaTable ptSubTable = ptTable.SubTable(seclist[i]);
if (ptSubTable.IsValid()) {
ptSubTable.GetMap(ptex);
for (std::map<std::string, std::string>::iterator pi = ptex.begin(); pi != ptex.end(); ++pi) {
textureAtlas->AddTexFromFile(pi->first, "bitmaps/" + pi->second);
blockMapTexNames.insert(StringToLower(pi->first));
}
ptex.clear();
}
}
// get the smoke textures, hold the count in 'smokeCount'
const LuaTable smokeTable = gfxTable.SubTable("smoke");
int smokeCount;
if (smokeTable.IsValid()) {
for (smokeCount = 0; true; smokeCount++) {
const std::string tex = smokeTable.GetString(smokeCount + 1, "");
if (tex.empty()) {
break;
}
const std::string texName = "bitmaps/" + tex;
const std::string smokeName = "ismoke" + IntToString(smokeCount, "%02i");
textureAtlas->AddTexFromFile(smokeName, texName);
blockMapTexNames.insert(StringToLower(smokeName));
}
} else {
// setup the defaults
for (smokeCount = 0; smokeCount < 12; smokeCount++) {
const std::string smokeNum = IntToString(smokeCount, "%02i");
const std::string smokeName = "ismoke" + smokeNum;
const std::string texName = "bitmaps/smoke/smoke" + smokeNum + ".tga";
textureAtlas->AddTexFromFile(smokeName, texName);
blockMapTexNames.insert(StringToLower(smokeName));
}
}
if (smokeCount <= 0) {
throw content_error("missing smoke textures");
}
char tex[128][128][4];
for (int y = 0; y < 128; y++) { // shield
for (int x = 0; x < 128; x++) {
tex[y][x][0] = 70;
tex[y][x][1] = 70;
tex[y][x][2] = 70;
tex[y][x][3] = 70;
}
}
textureAtlas->AddTexFromMem("perlintex", 128, 128, CTextureAtlas::RGBA32, tex);
blockMapTexNames.insert("perlintex");
blockMapTexNames.insert("flare");
blockMapTexNames.insert("explo");
blockMapTexNames.insert("explofade");
blockMapTexNames.insert("heatcloud");
blockMapTexNames.insert("laserend");
blockMapTexNames.insert("laserfalloff");
blockMapTexNames.insert("randdots");
blockMapTexNames.insert("smoketrail");
blockMapTexNames.insert("wake");
blockMapTexNames.insert("perlintex");
//.........这里部分代码省略.........
示例11: name
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);
}
//.........这里部分代码省略.........