|
|
|
#include "inventorystate.hpp"
|
|
|
|
|
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
|
|
|
#include <components/misc/strings/algorithm.hpp>
|
|
|
|
|
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
|
|
|
|
void InventoryState::load(ESMReader& esm)
|
|
|
|
{
|
|
|
|
// obsolete
|
|
|
|
int index = 0;
|
|
|
|
while (esm.isNextSub("IOBJ"))
|
|
|
|
{
|
|
|
|
int unused; // no longer used
|
|
|
|
esm.getHT(unused);
|
|
|
|
|
|
|
|
ObjectState state;
|
|
|
|
|
|
|
|
// obsolete
|
|
|
|
if (esm.isNextSub("SLOT"))
|
|
|
|
{
|
|
|
|
int slot;
|
|
|
|
esm.getHT(slot);
|
|
|
|
mEquipmentSlots[index] = slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
state.mRef.loadId(esm, true);
|
|
|
|
state.load(esm);
|
|
|
|
|
|
|
|
if (state.mCount == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mItems.push_back(state);
|
|
|
|
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
|
|
|
int itemsCount = 0;
|
|
|
|
esm.getHNOT(itemsCount, "ICNT");
|
|
|
|
for (int i = 0; i < itemsCount; i++)
|
|
|
|
{
|
|
|
|
ObjectState state;
|
|
|
|
|
|
|
|
state.mRef.loadId(esm, true);
|
|
|
|
state.load(esm);
|
|
|
|
|
|
|
|
if (state.mCount == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mItems.push_back(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next item is Levelled item
|
|
|
|
while (esm.isNextSub("LEVM"))
|
|
|
|
{
|
|
|
|
// Get its name
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2 years ago
|
|
|
ESM::RefId id = esm.getRefId();
|
|
|
|
int count;
|
|
|
|
std::string parentGroup;
|
|
|
|
// Then get its count
|
|
|
|
esm.getHNT(count, "COUN");
|
|
|
|
// Old save formats don't have information about parent group; check for that
|
|
|
|
if (esm.isNextSub("LGRP"))
|
|
|
|
// Newest saves contain parent group
|
|
|
|
parentGroup = esm.getHString();
|
|
|
|
mLevelledItemMap[std::make_pair(id, parentGroup)] = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (esm.isNextSub("MAGI"))
|
|
|
|
{
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2 years ago
|
|
|
ESM::RefId id = esm.getRefId();
|
|
|
|
|
|
|
|
std::vector<std::pair<float, float>> params;
|
|
|
|
while (esm.isNextSub("RAND"))
|
|
|
|
{
|
|
|
|
float rand, multiplier;
|
|
|
|
esm.getHT(rand);
|
|
|
|
esm.getHNT(multiplier, "MULT");
|
|
|
|
params.emplace_back(rand, multiplier);
|
|
|
|
}
|
|
|
|
mPermanentMagicEffectMagnitudes[id] = params;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (esm.isNextSub("EQUI"))
|
|
|
|
{
|
|
|
|
esm.getSubHeader();
|
|
|
|
int equipIndex;
|
|
|
|
esm.getT(equipIndex);
|
|
|
|
int slot;
|
|
|
|
esm.getT(slot);
|
|
|
|
mEquipmentSlots[equipIndex] = slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esm.isNextSub("EQIP"))
|
|
|
|
{
|
|
|
|
esm.getSubHeader();
|
|
|
|
int slotsCount = 0;
|
|
|
|
esm.getT(slotsCount);
|
|
|
|
for (int i = 0; i < slotsCount; i++)
|
|
|
|
{
|
|
|
|
int equipIndex;
|
|
|
|
esm.getT(equipIndex);
|
|
|
|
int slot;
|
|
|
|
esm.getT(slot);
|
|
|
|
mEquipmentSlots[equipIndex] = slot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mSelectedEnchantItem = -1;
|
|
|
|
esm.getHNOT(mSelectedEnchantItem, "SELE");
|
|
|
|
|
|
|
|
// Old saves had restocking levelled items in a special map
|
|
|
|
// This turns items from that map into negative quantities
|
|
|
|
for (const auto& entry : mLevelledItemMap)
|
|
|
|
{
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2 years ago
|
|
|
const ESM::RefId& id = entry.first.first;
|
|
|
|
const int count = entry.second;
|
|
|
|
for (auto& item : mItems)
|
|
|
|
{
|
|
|
|
if (item.mCount == count && id == item.mRef.mRefID)
|
|
|
|
item.mCount = -count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InventoryState::save(ESMWriter& esm) const
|
|
|
|
{
|
|
|
|
int itemsCount = static_cast<int>(mItems.size());
|
|
|
|
if (itemsCount > 0)
|
|
|
|
{
|
|
|
|
esm.writeHNT("ICNT", itemsCount);
|
|
|
|
for (const ObjectState& state : mItems)
|
|
|
|
{
|
|
|
|
state.save(esm, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
|
|
|
{
|
|
|
|
esm.writeHNRefId("LEVM", it->first.first);
|
|
|
|
esm.writeHNT("COUN", it->second);
|
|
|
|
esm.writeHNString("LGRP", it->first.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (TEffectMagnitudes::const_iterator it = mPermanentMagicEffectMagnitudes.begin();
|
|
|
|
it != mPermanentMagicEffectMagnitudes.end(); ++it)
|
|
|
|
{
|
|
|
|
esm.writeHNRefId("MAGI", it->first);
|
|
|
|
|
|
|
|
const std::vector<std::pair<float, float>>& params = it->second;
|
|
|
|
for (std::vector<std::pair<float, float>>::const_iterator pIt = params.begin(); pIt != params.end(); ++pIt)
|
|
|
|
{
|
|
|
|
esm.writeHNT("RAND", pIt->first);
|
|
|
|
esm.writeHNT("MULT", pIt->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int slotsCount = static_cast<int>(mEquipmentSlots.size());
|
|
|
|
if (slotsCount > 0)
|
|
|
|
{
|
|
|
|
esm.startSubRecord("EQIP");
|
|
|
|
esm.writeT(slotsCount);
|
|
|
|
for (std::map<int, int>::const_iterator it = mEquipmentSlots.begin(); it != mEquipmentSlots.end(); ++it)
|
|
|
|
{
|
|
|
|
esm.writeT(it->first);
|
|
|
|
esm.writeT(it->second);
|
|
|
|
}
|
|
|
|
esm.endRecord("EQIP");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSelectedEnchantItem != -1)
|
|
|
|
esm.writeHNT("SELE", mSelectedEnchantItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|