Skip to content

Commit

Permalink
Support more than 127 armor segments
Browse files Browse the repository at this point in the history
  • Loading branch information
gmoromisato committed Feb 13, 2021
1 parent c34e7fd commit 0bb3308
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 58 deletions.
40 changes: 26 additions & 14 deletions Mammoth/Include/TSEItems.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ class CItem

CItem (void);
CItem (const CItem &Copy);
CItem (CItemType &ItemType, int iCount);
CItem (CItemType *pItemType, int iCount);

~CItem (void);
CItem &operator= (const CItem &Copy);

Expand Down Expand Up @@ -319,11 +321,11 @@ class CItem
TSharedPtr<CItemEnhancementStack> GetEnhancementStack (void) const;
inline const CObjectImageArray &GetImage (void) const;
int GetInstallCost (void) const;
int GetInstalled (void) const { return (int)(char)m_dwInstalled; }
const CInstalledArmor *GetInstalledArmor (void) const { if (m_pExtra && m_pExtra->m_iInstalled == installedArmor) return (const CInstalledArmor *)m_pExtra->m_pInstalled; else return NULL; }
CInstalledArmor *GetInstalledArmor (void) { if (m_pExtra && m_pExtra->m_iInstalled == installedArmor) return (CInstalledArmor *)m_pExtra->m_pInstalled; else return NULL; }
const CInstalledDevice *GetInstalledDevice (void) const { if (m_pExtra && m_pExtra->m_iInstalled == installedDevice) return (const CInstalledDevice *)m_pExtra->m_pInstalled; else return NULL; }
CInstalledDevice *GetInstalledDevice (void) { if (m_pExtra && m_pExtra->m_iInstalled == installedDevice) return (CInstalledDevice *)m_pExtra->m_pInstalled; else return NULL; }
int GetInstalled (void) const { return (m_pExtra ? m_pExtra->m_iInstalledIndex : -1); }
const CInstalledArmor *GetInstalledArmor (void) const { if (m_pExtra && m_pExtra->m_iInstalled == EInstalled::Armor) return (const CInstalledArmor *)m_pExtra->m_pInstalled; else return NULL; }
CInstalledArmor *GetInstalledArmor (void) { if (m_pExtra && m_pExtra->m_iInstalled == EInstalled::Armor) return (CInstalledArmor *)m_pExtra->m_pInstalled; else return NULL; }
const CInstalledDevice *GetInstalledDevice (void) const { if (m_pExtra && m_pExtra->m_iInstalled == EInstalled::Device) return (const CInstalledDevice *)m_pExtra->m_pInstalled; else return NULL; }
CInstalledDevice *GetInstalledDevice (void) { if (m_pExtra && m_pExtra->m_iInstalled == EInstalled::Device) return (CInstalledDevice *)m_pExtra->m_pInstalled; else return NULL; }
ICCItem *GetItemProperty (CCodeChainCtx &CCCtx, CItemCtx &Ctx, const CString &sProperty, bool bOnType) const;
Metric GetItemPropertyDouble (CCodeChainCtx &CCCtx, CItemCtx &Ctx, const CString &sProperty) const;
int GetItemPropertyInteger (CCodeChainCtx &CCCtx, CItemCtx &Ctx, const CString &sProperty) const;
Expand Down Expand Up @@ -362,7 +364,16 @@ class CItem
bool IsEnhanced (void) const { return (m_dwFlags & flagEnhanced ? true : false); }
bool IsEnhancementEffective (const CItemEnhancement &Enhancement) const;
bool IsExtraEmpty (DWORD dwFlags = 0);
bool IsInstalled (void) const { return (m_dwInstalled != 0xff); }

// NOTE: We use installed index instead of m_iInstalled because during
// load the index is set up, but the enum has not yet been initialized
// (because that happens later). In the future we could initialized
// m_iInstalled at load time based on m_iInstalledIndex to some value
// that means "in the process of being fixed up". Note that we also
// might want to use a similar technique for SetPreprareUninstalled.

bool IsInstalled (void) const { return (m_pExtra && m_pExtra->m_iInstalledIndex != -1); }

bool IsKnown (int *retiUnknownIndex = NULL) const;
bool IsMarkedForDelete (void) { return (m_dwCount == 0xffff); }
bool IsVirtual (void) const;
Expand Down Expand Up @@ -441,12 +452,12 @@ class CItem
ICCItem *WriteToCCItem (void) const;

private:
enum EInstallTypes
enum class EInstalled
{
installedNone,
None,

installedArmor,
installedDevice,
Armor,
Device,
};

static constexpr DWORD UNKNOWN_INDEX_LOWER_MASK = (flagUnknownBit0 | flagUnknownBit1 | flagUnknownBit2);
Expand All @@ -456,8 +467,9 @@ class CItem

struct SExtra
{
EInstallTypes m_iInstalled = installedNone;
EInstalled m_iInstalled = EInstalled::None;
void *m_pInstalled = NULL; // Pointer to either CInstalledArmor or CInstalledDevice
int m_iInstalledIndex = -1; // Install location

DWORD m_dwCharges = 0; // Charges for items
DWORD m_dwLevel = 0; // For scalable items, this stores the level
Expand Down Expand Up @@ -485,9 +497,9 @@ class CItem

CItemType *m_pItemType = NULL;

DWORD m_dwCount:16; // Number of items
DWORD m_dwFlags:8; // Miscellaneous flags
DWORD m_dwInstalled:8; // Location where item is installed
DWORD m_dwCount:16 = 0; // Number of items
DWORD m_dwFlags:8 = 0; // Miscellaneous flags
DWORD m_dwUnused:8 = 0; // Spare

SExtra *m_pExtra = NULL; // Extra data (may be NULL)

Expand Down
5 changes: 4 additions & 1 deletion Mammoth/Include/TSEVersions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

constexpr DWORD API_VERSION = 51;
constexpr DWORD UNIVERSE_SAVE_VERSION = 38;
constexpr DWORD SYSTEM_SAVE_VERSION = 200;
constexpr DWORD SYSTEM_SAVE_VERSION = 201;

// Uncomment out the following define when building a stable release

Expand Down Expand Up @@ -723,3 +723,6 @@ constexpr DWORD SYSTEM_SAVE_VERSION = 200;
//
// 200: 1.9 Beta 4
// Changed CIntegralRotationDesc::ROTATION_FRACTION
//
// 201: 1.9 Beta 4
// Added m_iInstalledIndex to CItem::SExtra
19 changes: 17 additions & 2 deletions Mammoth/TSE/CInstalledDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,13 +756,28 @@ void CInstalledDevice::ReadFromStream (CSpaceObject &Source, SLoadCtx &Ctx)
if (m_pClass != NULL && m_iDeviceSlot != -1)
{
CItemListManipulator ItemList(Source.GetItemList());
Source.SetCursorAtDevice(ItemList, this);
if (ItemList.IsCursorValid())
if (Source.SetCursorAtDevice(ItemList, this))
{
m_pSource = &Source;
m_pItem = ItemList.GetItemPointerAtCursor();
m_pItem->SetInstalled(*this);
}
else
{
// If we can't find the item, then the save file is corrupt,
// because it must be there at save time. But we try to fix it up
// anyway.

if (Source.GetUniverse().InDebugMode())
throw CException(ERR_FAIL);
else
{
ItemList.AddItem(CItem(*m_pClass->GetItemType(), 1));
ItemList.SetInstalledAtCursor(*this);
m_pSource = &Source;
m_pItem = ItemList.GetItemPointerAtCursor();
}
}

// In previous versions we automatically offset weapon positions.
// In later versions we explicitly set the position, so we have
Expand Down
Loading

0 comments on commit 0bb3308

Please sign in to comment.