mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-31 06:32:39 +00:00
Simplify npc data update and fix data copy when autocal flag changed.
This commit is contained in:
parent
8c39f2b376
commit
78457a8234
@ -1373,70 +1373,33 @@ void CSMWorld::Data::npcDataChanged (const QModelIndex& topLeft, const QModelInd
|
|||||||
static_cast<CSMWorld::IdTree*>(getTableModel(CSMWorld::UniversalId::Type_Referenceable));
|
static_cast<CSMWorld::IdTree*>(getTableModel(CSMWorld::UniversalId::Type_Referenceable));
|
||||||
|
|
||||||
int autoCalcColumn = objectModel->findColumnIndex(CSMWorld::Columns::ColumnId_AutoCalc);
|
int autoCalcColumn = objectModel->findColumnIndex(CSMWorld::Columns::ColumnId_AutoCalc);
|
||||||
int miscColumn = objectModel->findColumnIndex(CSMWorld::Columns::ColumnId_NpcMisc);
|
|
||||||
|
|
||||||
// first check for level
|
// check for autocalc
|
||||||
bool levelChanged = false;
|
if (topLeft.parent().isValid() || bottomRight.parent().isValid()
|
||||||
if (topLeft.parent().isValid() && bottomRight.parent().isValid())
|
|| topLeft.column() > autoCalcColumn || autoCalcColumn > bottomRight.column())
|
||||||
{
|
{
|
||||||
if (topLeft.parent().column() <= miscColumn && miscColumn <= bottomRight.parent().column())
|
return;
|
||||||
{
|
|
||||||
for (int col = topLeft.column(); col <= bottomRight.column(); ++col)
|
|
||||||
{
|
|
||||||
int role = objectModel->nestedHeaderData(topLeft.parent().column(),
|
|
||||||
col, Qt::Horizontal, CSMWorld::ColumnBase::Role_ColumnId).toInt();
|
|
||||||
if (role == CSMWorld::Columns::ColumnId_NpcLevel)
|
|
||||||
{
|
|
||||||
levelChanged = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// next check for autocalc
|
int row = topLeft.row();
|
||||||
bool autoCalcChanged = false;
|
for (; row <= bottomRight.row(); ++row)
|
||||||
if (!topLeft.parent().isValid() && !bottomRight.parent().isValid())
|
|
||||||
{
|
|
||||||
if ((topLeft.column() <= autoCalcColumn && autoCalcColumn <= bottomRight.column())
|
|
||||||
|| (topLeft.column() <= miscColumn && miscColumn <= bottomRight.column()))
|
|
||||||
{
|
|
||||||
autoCalcChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!levelChanged && !autoCalcChanged)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int row = 0;
|
|
||||||
int end = 0;
|
|
||||||
if (topLeft.parent().isValid())
|
|
||||||
row = topLeft.parent().row();
|
|
||||||
else
|
|
||||||
row = topLeft.row();
|
|
||||||
|
|
||||||
if (bottomRight.parent().isValid())
|
|
||||||
end = bottomRight.parent().row();
|
|
||||||
else
|
|
||||||
end = bottomRight.row();
|
|
||||||
|
|
||||||
for (; row <= end; ++row)
|
|
||||||
{
|
{
|
||||||
Record<ESM::NPC> record =
|
Record<ESM::NPC> record =
|
||||||
static_cast<const Record<ESM::NPC>&>(mReferenceables.getRecord(row));
|
static_cast<const Record<ESM::NPC>&>(mReferenceables.getRecord(row));
|
||||||
ESM::NPC &npc = record.get();
|
ESM::NPC &npc = record.get();
|
||||||
|
|
||||||
// If going from autocalc to non-autocalc, save the autocalc values
|
if (npc.mNpdtType != ESM::NPC::NPC_WITH_AUTOCALCULATED_STATS)
|
||||||
if (autoCalcChanged)
|
|
||||||
{
|
{
|
||||||
if (npc.mNpdtType != ESM::NPC::NPC_WITH_AUTOCALCULATED_STATS)
|
// first pretend autocalc to force recalculation
|
||||||
saveAutoCalcValues(npc); // update attributes and skills
|
npc.mNpdtType = ESM::NPC::NPC_WITH_AUTOCALCULATED_STATS;
|
||||||
else
|
saveAutoCalcValues(npc); // update attributes and skills
|
||||||
npc.mNpdt12.mLevel = npc.mNpdt52.mLevel; // for NPC's loaded as non-autocalc
|
npc.mNpdtType = ESM::NPC::NPC_DEFAULT;
|
||||||
|
|
||||||
record.setModified(npc);
|
|
||||||
mReferenceables.replace(row, record);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
npc.mNpdt12.mLevel = npc.mNpdt52.mLevel; // for NPC's loaded as non-autocalc
|
||||||
|
|
||||||
|
record.setModified(npc);
|
||||||
|
mReferenceables.replace(row, record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1469,11 +1432,7 @@ void CSMWorld::Data::gmstDataChanged (const QModelIndex& topLeft, const QModelIn
|
|||||||
// FIXME: how to undo?
|
// FIXME: how to undo?
|
||||||
void CSMWorld::Data::saveAutoCalcValues(ESM::NPC& npc)
|
void CSMWorld::Data::saveAutoCalcValues(ESM::NPC& npc)
|
||||||
{
|
{
|
||||||
CSMWorld::NpcStats * cachedStats = getCachedNpcData (npc.mId);
|
CSMWorld::NpcStats *stats = npcAutoCalculate(npc);
|
||||||
if (!cachedStats)
|
|
||||||
return; // silently fail
|
|
||||||
|
|
||||||
CSMWorld::NpcStats* stats = npcAutoCalculate(npc);
|
|
||||||
|
|
||||||
// update npc
|
// update npc
|
||||||
npc.mNpdt52.mLevel = npc.mNpdt12.mLevel;
|
npc.mNpdt52.mLevel = npc.mNpdt12.mLevel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user