1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 22:15:32 +00:00

Convert AI package type and AI wander repeat columns in the nested tables to use enum delegate

This commit is contained in:
cc9cii 2015-04-18 09:37:19 +10:00
parent e241fb0104
commit f88be67556
7 changed files with 48 additions and 58 deletions

View file

@ -79,6 +79,8 @@ bool CSMWorld::ColumnBase::isId (Display display)
Display_EffectRange, Display_EffectRange,
Display_EffectId, Display_EffectId,
Display_PartRefType, Display_PartRefType,
Display_AiPackageType,
Display_YesNo,
Display_None Display_None
}; };

View file

@ -113,6 +113,8 @@ namespace CSMWorld
Display_EffectRange, Display_EffectRange,
Display_EffectId, Display_EffectId,
Display_PartRefType, Display_PartRefType,
Display_AiPackageType,
Display_YesNo,
//top level columns that nest other columns //top level columns that nest other columns
Display_NestedHeader Display_NestedHeader

View file

@ -248,7 +248,7 @@ namespace CSMWorld
{ ColumnId_EffectArea, "Area" }, { ColumnId_EffectArea, "Area" },
{ ColumnId_AiPackageList, "Ai Packages" }, { ColumnId_AiPackageList, "Ai Packages" },
{ ColumnId_AiPackage, "Package" }, { ColumnId_AiPackageType, "Package" },
{ ColumnId_AiWanderDist, "Wander Dist" }, { ColumnId_AiWanderDist, "Wander Dist" },
{ ColumnId_AiDuration, "Duration" }, { ColumnId_AiDuration, "Duration" },
{ ColumnId_AiWanderToD, "Wander ToD" }, { ColumnId_AiWanderToD, "Wander ToD" },
@ -487,6 +487,17 @@ namespace
"Weapon", "Tail", 0 "Weapon", "Tail", 0
}; };
// see the enums in <component/esm/aipackage.hpp>
static const char *sAiPackageType[] =
{
"AI Wander", "AI Travel", "AI Follow", "AI Escort", "AI Activate", 0
};
static const char *sAiWanderRepeat[] =
{
"No", "Yes", 0
};
const char **getEnumNames (CSMWorld::Columns::ColumnId column) const char **getEnumNames (CSMWorld::Columns::ColumnId column)
{ {
switch (column) switch (column)
@ -513,6 +524,8 @@ namespace
case CSMWorld::Columns::ColumnId_EffectRange: return sEffectRange; case CSMWorld::Columns::ColumnId_EffectRange: return sEffectRange;
case CSMWorld::Columns::ColumnId_EffectId: return sEffectId; case CSMWorld::Columns::ColumnId_EffectId: return sEffectId;
case CSMWorld::Columns::ColumnId_PartRefType: return sPartRefType; case CSMWorld::Columns::ColumnId_PartRefType: return sPartRefType;
case CSMWorld::Columns::ColumnId_AiPackageType: return sAiPackageType;
case CSMWorld::Columns::ColumnId_AiWanderRepeat: return sAiWanderRepeat;
default: return 0; default: return 0;
} }

View file

@ -237,7 +237,7 @@ namespace CSMWorld
ColumnId_EffectArea = 218, ColumnId_EffectArea = 218,
ColumnId_AiPackageList = 219, ColumnId_AiPackageList = 219,
ColumnId_AiPackage = 220, ColumnId_AiPackageType = 220,
ColumnId_AiWanderDist = 221, ColumnId_AiWanderDist = 221,
ColumnId_AiDuration = 222, ColumnId_AiDuration = 222,
ColumnId_AiWanderToD = 223, ColumnId_AiWanderToD = 223,

View file

@ -1318,34 +1318,13 @@ namespace CSMWorld
switch(subColIndex) switch(subColIndex)
{ {
case 0: case 0: list.at(subRowIndex).mCellName = std::string(value.toString().toUtf8().constData()); break;
list.at(subRowIndex).mCellName = std::string(value.toString().toUtf8().constData()); case 1: list.at(subRowIndex).mPos.pos[0] = value.toFloat(); break;
break; case 2: list.at(subRowIndex).mPos.pos[1] = value.toFloat(); break;
case 3: list.at(subRowIndex).mPos.pos[2] = value.toFloat(); break;
case 1: case 4: list.at(subRowIndex).mPos.rot[0] = value.toFloat(); break;
list.at(subRowIndex).mPos.pos[0] = value.toFloat(); case 5: list.at(subRowIndex).mPos.rot[1] = value.toFloat(); break;
break; case 6: list.at(subRowIndex).mPos.rot[2] = value.toFloat(); break;
case 2:
list.at(subRowIndex).mPos.pos[1] = value.toFloat();
break;
case 3:
list.at(subRowIndex).mPos.pos[2] = value.toFloat();
break;
case 4:
list.at(subRowIndex).mPos.rot[0] = value.toFloat();
break;
case 5:
list.at(subRowIndex).mPos.rot[1] = value.toFloat();
break;
case 6:
list.at(subRowIndex).mPos.rot[2] = value.toFloat();
break;
default: default:
throw std::runtime_error("Trying to access non-existing column in the nested table!"); throw std::runtime_error("Trying to access non-existing column in the nested table!");
} }
@ -1461,13 +1440,13 @@ namespace CSMWorld
case 0: case 0:
switch (content.mType) switch (content.mType)
{ {
case ESM::AI_Wander: return QString("AI Wander"); case ESM::AI_Wander: return 0;
case ESM::AI_Travel: return QString("AI Travel"); case ESM::AI_Travel: return 1;
case ESM::AI_Follow: return QString("AI Follow"); case ESM::AI_Follow: return 2;
case ESM::AI_Escort: return QString("AI Escort"); case ESM::AI_Escort: return 3;
case ESM::AI_Activate: return QString("AI Activate"); case ESM::AI_Activate: return 4;
case ESM::AI_CNDT: case ESM::AI_CNDT:
default: return QString("None"); default: return QVariant();
} }
case 1: // wander dist case 1: // wander dist
if (content.mType == ESM::AI_Wander) if (content.mType == ESM::AI_Wander)
@ -1494,7 +1473,7 @@ namespace CSMWorld
return QVariant(); return QVariant();
case 5: // wander repeat case 5: // wander repeat
if (content.mType == ESM::AI_Wander) if (content.mType == ESM::AI_Wander)
return QString(content.mWander.mShouldRepeat ? "Yes" : "No"); return content.mWander.mShouldRepeat;
else else
return QVariant(); return QVariant();
case 6: // activate name case 6: // activate name
@ -1554,18 +1533,14 @@ namespace CSMWorld
switch(subColIndex) switch(subColIndex)
{ {
case 0: // ai package type case 0: // ai package type
if ("AI Wander" == value.toString().toStdString()) switch (value.toInt())
content.mType = ESM::AI_Wander; {
else if ("AI Travel" == value.toString().toStdString()) case 0: content.mType = ESM::AI_Wander;
content.mType = ESM::AI_Travel; case 1: content.mType = ESM::AI_Travel;
else if ("AI Follow" == value.toString().toStdString()) case 2: content.mType = ESM::AI_Follow;
content.mType = ESM::AI_Follow; case 3: content.mType = ESM::AI_Escort;
else if ("AI Escort" == value.toString().toStdString()) case 4: content.mType = ESM::AI_Activate;
content.mType = ESM::AI_Escort; }
else if ("AI Activate" == value.toString().toStdString())
content.mType = ESM::AI_Activate;
else
content.mType = ESM::AI_CNDT;
break; // always save break; // always save
case 1: case 1:
@ -1592,12 +1567,8 @@ namespace CSMWorld
case 5: case 5:
if (content.mType == ESM::AI_Wander) if (content.mType == ESM::AI_Wander)
{ {
if ("Yes" == value.toString().toStdString()) content.mWander.mShouldRepeat = static_cast<unsigned char>(value.toInt());
content.mWander.mShouldRepeat = 1; break;
if ("No" == value.toString().toStdString())
content.mWander.mShouldRepeat = 0;
else
return; // return without saving
} }
case 6: // NAME32 case 6: // NAME32
if (content.mType == ESM::AI_Activate) if (content.mType == ESM::AI_Activate)

View file

@ -188,7 +188,7 @@ CSMWorld::RefIdCollection::RefIdCollection()
new ActorAiRefIdAdapter<ESM::Creature> (UniversalId::Type_Creature))); new ActorAiRefIdAdapter<ESM::Creature> (UniversalId::Type_Creature)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), aiMap)); mNestedAdapters.push_back (std::make_pair(&mColumns.back(), aiMap));
mColumns.back().addColumn( mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiPackage, CSMWorld::ColumnBase::Display_String)); new RefIdColumn (Columns::ColumnId_AiPackageType, CSMWorld::ColumnBase::Display_AiPackageType));
mColumns.back().addColumn( mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiWanderDist, CSMWorld::ColumnBase::Display_Integer)); new RefIdColumn (Columns::ColumnId_AiWanderDist, CSMWorld::ColumnBase::Display_Integer));
mColumns.back().addColumn( mColumns.back().addColumn(
@ -198,7 +198,7 @@ CSMWorld::RefIdCollection::RefIdCollection()
mColumns.back().addColumn( mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiWanderIdle, CSMWorld::ColumnBase::Display_Integer)); new RefIdColumn (Columns::ColumnId_AiWanderIdle, CSMWorld::ColumnBase::Display_Integer));
mColumns.back().addColumn( mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiWanderRepeat, CSMWorld::ColumnBase::Display_String)); new RefIdColumn (Columns::ColumnId_AiWanderRepeat, CSMWorld::ColumnBase::Display_YesNo));
mColumns.back().addColumn( mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiActivateName, CSMWorld::ColumnBase::Display_String)); new RefIdColumn (Columns::ColumnId_AiActivateName, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn( mColumns.back().addColumn(

View file

@ -88,7 +88,9 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
{ CSMWorld::ColumnBase::Display_SkillImpact, CSMWorld::Columns::ColumnId_SkillImpact, true }, { CSMWorld::ColumnBase::Display_SkillImpact, CSMWorld::Columns::ColumnId_SkillImpact, true },
{ CSMWorld::ColumnBase::Display_EffectRange, CSMWorld::Columns::ColumnId_EffectRange, false }, { CSMWorld::ColumnBase::Display_EffectRange, CSMWorld::Columns::ColumnId_EffectRange, false },
{ CSMWorld::ColumnBase::Display_EffectId, CSMWorld::Columns::ColumnId_EffectId, false }, { CSMWorld::ColumnBase::Display_EffectId, CSMWorld::Columns::ColumnId_EffectId, false },
{ CSMWorld::ColumnBase::Display_PartRefType, CSMWorld::Columns::ColumnId_PartRefType, false } { CSMWorld::ColumnBase::Display_PartRefType, CSMWorld::Columns::ColumnId_PartRefType, false },
{ CSMWorld::ColumnBase::Display_AiPackageType, CSMWorld::Columns::ColumnId_AiPackageType, false },
{ CSMWorld::ColumnBase::Display_YesNo, CSMWorld::Columns::ColumnId_AiWanderRepeat, false }
}; };
for (std::size_t i=0; i<sizeof (sMapping)/sizeof (Mapping); ++i) for (std::size_t i=0; i<sizeof (sMapping)/sizeof (Mapping); ++i)