|
|
|
#include "inventorystate.hpp"
|
|
|
|
|
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
|
|
|
#include <components/misc/strings/algorithm.hpp>
|
|
|
|
|
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
constexpr uint32_t sInvalidSlot = static_cast<uint32_t>(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InventoryState::load(ESMReader& esm)
|
|
|
|
{
|
|
|
|
// obsolete
|
|
|
|
while (esm.isNextSub("IOBJ"))
|
|
|
|
{
|
|
|
|
esm.skipHT<int32_t>();
|
|
|
|
|
|
|
|
ObjectState state;
|
|
|
|
|
|
|
|
state.mRef.loadId(esm, true);
|
|
|
|
state.load(esm);
|
|
|
|
|
|
|
|
if (state.mRef.mCount == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mItems.push_back(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t itemsCount = 0;
|
|
|
|
esm.getHNOT(itemsCount, "ICNT");
|
|
|
|
for (; itemsCount > 0; --itemsCount)
|
|
|
|
{
|
|
|
|
ObjectState state;
|
|
|
|
|
|
|
|
state.mRef.loadId(esm, true);
|
|
|
|
state.load(esm);
|
|
|
|
|
|
|
|
// Update content file index if load order was changed.
|
|
|
|
if (!esm.applyContentFileMapping(state.mRef.mRefNum))
|
|
|
|
state.mRef.mRefNum = FormId(); // content file removed; unset refnum, but keep object.
|
|
|
|
|
|
|
|
if (state.mRef.mCount == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mItems.push_back(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::pair<ESM::RefId, std::string>, int32_t> levelledItemMap;
|
|
|
|
// 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();
|
|
|
|
int32_t count;
|
|
|
|
// Then get its count
|
|
|
|
esm.getHNT(count, "COUN");
|
|
|
|
std::string parentGroup = esm.getHNString("LGRP");
|
|
|
|
levelledItemMap[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] = std::move(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (esm.isNextSub("EQUI"))
|
|
|
|
{
|
|
|
|
esm.getSubHeader();
|
|
|
|
int32_t equipIndex;
|
|
|
|
esm.getT(equipIndex);
|
|
|
|
int32_t slot;
|
|
|
|
esm.getT(slot);
|
|
|
|
mEquipmentSlots[equipIndex] = slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esm.isNextSub("EQIP"))
|
|
|
|
{
|
|
|
|
esm.getSubHeader();
|
|
|
|
uint32_t slotsCount = 0;
|
|
|
|
esm.getT(slotsCount);
|
|
|
|
for (; slotsCount > 0; --slotsCount)
|
|
|
|
{
|
|
|
|
int32_t equipIndex;
|
|
|
|
esm.getT(equipIndex);
|
|
|
|
int32_t slot;
|
|
|
|
esm.getT(slot);
|
|
|
|
mEquipmentSlots[equipIndex] = slot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t selectedEnchantItem = sInvalidSlot;
|
|
|
|
esm.getHNOT(selectedEnchantItem, "SELE");
|
|
|
|
if (selectedEnchantItem == sInvalidSlot)
|
|
|
|
mSelectedEnchantItem.reset();
|
|
|
|
else
|
|
|
|
mSelectedEnchantItem = selectedEnchantItem;
|
|
|
|
|
|
|
|
// Old saves had restocking levelled items in a special map
|
|
|
|
// This turns items from that map into negative quantities
|
|
|
|
for (const auto& entry : levelledItemMap)
|
|
|
|
{
|
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.mRef.mCount == count && id == item.mRef.mRefID)
|
|
|
|
item.mRef.mCount = -count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InventoryState::save(ESMWriter& esm) const
|
|
|
|
{
|
|
|
|
uint32_t itemsCount = static_cast<uint32_t>(mItems.size());
|
|
|
|
if (itemsCount > 0)
|
|
|
|
{
|
|
|
|
esm.writeHNT("ICNT", itemsCount);
|
|
|
|
for (const ObjectState& state : mItems)
|
|
|
|
{
|
|
|
|
state.save(esm, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& [id, params] : mPermanentMagicEffectMagnitudes)
|
|
|
|
{
|
|
|
|
esm.writeHNRefId("MAGI", id);
|
|
|
|
|
|
|
|
for (const auto& [rand, mult] : params)
|
|
|
|
{
|
|
|
|
esm.writeHNT("RAND", rand);
|
|
|
|
esm.writeHNT("MULT", mult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t slotsCount = static_cast<uint32_t>(mEquipmentSlots.size());
|
|
|
|
if (slotsCount > 0)
|
|
|
|
{
|
|
|
|
esm.startSubRecord("EQIP");
|
|
|
|
esm.writeT(slotsCount);
|
|
|
|
for (const auto& [index, slot] : mEquipmentSlots)
|
|
|
|
{
|
|
|
|
esm.writeT(index);
|
|
|
|
esm.writeT(slot);
|
|
|
|
}
|
|
|
|
esm.endRecord("EQIP");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSelectedEnchantItem)
|
|
|
|
esm.writeHNT("SELE", *mSelectedEnchantItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|