Browse Source

use unsigned types for item seeds

pull/6084/head
ephphatha 3 years ago committed by Anders Jenbo
parent
commit
3a7ae732cd
  1. 6
      Source/inv.cpp
  2. 6
      Source/inv.h
  3. 12
      Source/items.cpp
  4. 16
      Source/items.h
  5. 4
      Source/loadsave.cpp
  6. 8
      Source/msg.cpp
  7. 6
      Source/msg.h

6
Source/inv.cpp

@ -1669,7 +1669,7 @@ void AutoGetItem(Player &player, Item *itemPointer, int ii)
NetSendCmdPItem(true, CMD_RESPAWNITEM, item.position, item);
}
int FindGetItem(int32_t iseed, _item_indexes idx, uint16_t createInfo)
int FindGetItem(uint32_t iseed, _item_indexes idx, uint16_t createInfo)
{
for (uint8_t i = 0; i < ActiveItemCount; i++) {
auto &item = Items[ActiveItems[i]];
@ -1681,7 +1681,7 @@ int FindGetItem(int32_t iseed, _item_indexes idx, uint16_t createInfo)
return -1;
}
void SyncGetItem(Point position, int32_t iseed, _item_indexes idx, uint16_t ci)
void SyncGetItem(Point position, uint32_t iseed, _item_indexes idx, uint16_t ci)
{
// Check what the local client has at the target position
int ii = dItem[position.x][position.y] - 1;
@ -1801,7 +1801,7 @@ int SyncDropItem(Point position, _item_indexes idx, uint16_t icreateinfo, int is
return ii;
}
int SyncDropEar(Point position, uint16_t icreateinfo, int iseed, uint8_t cursval, string_view heroname)
int SyncDropEar(Point position, uint16_t icreateinfo, uint32_t iseed, uint8_t cursval, string_view heroname)
{
if (ActiveItemCount >= MAXITEMS)
return -1;

6
Source/inv.h

@ -208,8 +208,8 @@ void AutoGetItem(Player &player, Item *itemPointer, int ii);
* @param ci Flags used to describe the specific subtype of the target item
* @return An index into ActiveItems or -1 if no matching item was found
*/
int FindGetItem(int32_t iseed, _item_indexes idx, uint16_t ci);
void SyncGetItem(Point position, int32_t iseed, _item_indexes idx, uint16_t ci);
int FindGetItem(uint32_t iseed, _item_indexes idx, uint16_t ci);
void SyncGetItem(Point position, uint32_t iseed, _item_indexes idx, uint16_t ci);
/**
* @brief Checks if the tile has room for an item
@ -220,7 +220,7 @@ bool CanPut(Point position);
int InvPutItem(const Player &player, Point position, const Item &item);
int SyncDropItem(Point position, _item_indexes idx, uint16_t icreateinfo, int iseed, int id, int dur, int mdur, int ch, int mch, int ivalue, uint32_t ibuff, int toHit, int maxDam, int minStr, int minMag, int minDex, int ac);
int SyncDropEar(Point position, uint16_t icreateinfo, int iseed, uint8_t cursval, string_view heroname);
int SyncDropEar(Point position, uint16_t icreateinfo, uint32_t iseed, uint8_t cursval, string_view heroname);
int8_t CheckInvHLight();
bool CanUseScroll(Player &player, SpellID spell);
void ConsumeStaffCharge(Player &player);

12
Source/items.cpp

@ -1517,7 +1517,7 @@ int GetItemBLevel(int lvl, item_misc_id miscId, bool onlygood, bool uper15)
return iblvl;
}
void SetupAllItems(const Player &player, Item &item, _item_indexes idx, int iseed, int lvl, int uper, bool onlygood, bool recreate, bool pregen)
void SetupAllItems(const Player &player, Item &item, _item_indexes idx, uint32_t iseed, int lvl, int uper, bool onlygood, bool recreate, bool pregen)
{
item._iSeed = iseed;
SetRndSeed(iseed);
@ -3301,7 +3301,7 @@ void CreateTypeItem(Point position, bool onlygood, ItemType itemType, int imisc,
SetupBaseItem(position, idx, onlygood, sendmsg, delta);
}
void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire)
void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, uint32_t iseed, int ivalue, bool isHellfire)
{
bool tmpIsHellfire = gbIsHellfire;
gbIsHellfire = isHellfire;
@ -3353,7 +3353,7 @@ void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t
gbIsHellfire = tmpIsHellfire;
}
void RecreateEar(Item &item, uint16_t ic, int iseed, uint8_t bCursval, string_view heroName)
void RecreateEar(Item &item, uint16_t ic, uint32_t iseed, uint8_t bCursval, string_view heroName)
{
InitializeItem(item, IDI_EAR);
@ -4509,7 +4509,7 @@ void CreateMagicWeapon(Point position, ItemType itemType, int icurs, bool sendms
CreateMagicItem(position, curlv, itemType, imid, icurs, sendmsg, delta);
}
bool GetItemRecord(int nSeed, uint16_t wCI, int nIndex)
bool GetItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex)
{
uint32_t ticks = SDL_GetTicks();
@ -4526,7 +4526,7 @@ bool GetItemRecord(int nSeed, uint16_t wCI, int nIndex)
return true;
}
void SetItemRecord(int nSeed, uint16_t wCI, int nIndex)
void SetItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex)
{
uint32_t ticks = SDL_GetTicks();
@ -4541,7 +4541,7 @@ void SetItemRecord(int nSeed, uint16_t wCI, int nIndex)
gnNumGetRecords++;
}
void PutItemRecord(int nSeed, uint16_t wCI, int nIndex)
void PutItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex)
{
uint32_t ticks = SDL_GetTicks();

16
Source/items.h

@ -177,7 +177,7 @@ struct Player;
struct Item {
/** Randomly generated identifier */
int32_t _iSeed = 0;
uint32_t _iSeed = 0;
uint16_t _iCreateInfo = 0;
ItemType _itype = ItemType::None;
bool _iAnimFlag = false;
@ -416,7 +416,7 @@ struct Item {
[[nodiscard]] bool isUsable() const;
[[nodiscard]] bool keyAttributesMatch(int32_t seed, _item_indexes itemIndex, uint16_t createInfo) const
[[nodiscard]] bool keyAttributesMatch(uint32_t seed, _item_indexes itemIndex, uint16_t createInfo) const
{
return _iSeed == seed && IDidx == itemIndex && _iCreateInfo == createInfo;
}
@ -457,7 +457,7 @@ struct Item {
};
struct ItemGetRecordStruct {
int32_t nSeed;
uint32_t nSeed;
uint16_t wCI;
int nIndex;
uint32_t dwTimestamp;
@ -507,8 +507,8 @@ void SpawnItem(Monster &monster, Point position, bool sendmsg);
void CreateRndItem(Point position, bool onlygood, bool sendmsg, bool delta);
void CreateRndUseful(Point position, bool sendmsg);
void CreateTypeItem(Point position, bool onlygood, ItemType itemType, int imisc, bool sendmsg, bool delta);
void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire);
void RecreateEar(Item &item, uint16_t ic, int iseed, uint8_t bCursval, string_view heroName);
void RecreateItem(const Player &player, Item &item, _item_indexes idx, uint16_t icreateinfo, uint32_t iseed, int ivalue, bool isHellfire);
void RecreateEar(Item &item, uint16_t ic, uint32_t iseed, uint8_t bCursval, string_view heroName);
void CornerstoneSave();
void CornerstoneLoad(Point position);
void SpawnQuestItem(_item_indexes itemid, Point position, int randarea, int selflag, bool sendmsg);
@ -544,9 +544,9 @@ void CreateSpellBook(Point position, SpellID ispell, bool sendmsg, bool delta);
void CreateMagicArmor(Point position, ItemType itemType, int icurs, bool sendmsg, bool delta);
void CreateAmulet(Point position, int lvl, bool sendmsg, bool delta);
void CreateMagicWeapon(Point position, ItemType itemType, int icurs, bool sendmsg, bool delta);
bool GetItemRecord(int nSeed, uint16_t wCI, int nIndex);
void SetItemRecord(int nSeed, uint16_t wCI, int nIndex);
void PutItemRecord(int nSeed, uint16_t wCI, int nIndex);
bool GetItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex);
void SetItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex);
void PutItemRecord(uint32_t nSeed, uint16_t wCI, int nIndex);
/**
* @brief Resets item get records.

4
Source/loadsave.cpp

@ -231,7 +231,7 @@ public:
void LoadItemData(LoadHelper &file, Item &item)
{
item._iSeed = file.NextLE<int32_t>();
item._iSeed = file.NextLE<uint32_t>();
item._iCreateInfo = file.NextLE<uint16_t>();
file.Skip(2); // Alignment
item._itype = static_cast<ItemType>(file.NextLE<uint32_t>());
@ -1000,7 +1000,7 @@ void SaveItem(SaveHelper &file, const Item &item)
iType = ItemType::None;
}
file.WriteLE<int32_t>(item._iSeed);
file.WriteLE<uint32_t>(item._iSeed);
file.WriteLE<int16_t>(item._iCreateInfo);
file.Skip(2); // Alignment
file.WriteLE<int32_t>(static_cast<int32_t>(iType));

8
Source/msg.cpp

@ -1136,7 +1136,7 @@ size_t OnRequestGetItem(const TCmd *pCmd, Player &player)
if (gbBufferMsgs != 1 && IOwnLevel(player) && IsGItemValid(message)) {
const Point position { message.x, message.y };
const int32_t dwSeed = SDL_SwapLE32(message.def.dwSeed);
const uint32_t dwSeed = SDL_SwapLE32(message.def.dwSeed);
const uint16_t wCI = SDL_SwapLE16(message.def.wCI);
const _item_indexes wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx));
if (GetItemRecord(dwSeed, wCI, wIndx)) {
@ -1180,7 +1180,7 @@ size_t OnGetItem(const TCmd *pCmd, size_t pnum)
SendPacket(pnum, &message, sizeof(message));
} else if (IsGItemValid(message)) {
const Point position { message.x, message.y };
const int32_t dwSeed = SDL_SwapLE32(message.def.dwSeed);
const uint32_t dwSeed = SDL_SwapLE32(message.def.dwSeed);
const uint16_t wCI = SDL_SwapLE16(message.def.wCI);
const _item_indexes wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx));
if (DeltaGetItem(message, message.bLevel)) {
@ -1228,7 +1228,7 @@ size_t OnRequestAutoGetItem(const TCmd *pCmd, Player &player)
if (gbBufferMsgs != 1 && IOwnLevel(player) && IsGItemValid(message)) {
const Point position { message.x, message.y };
const int32_t dwSeed = SDL_SwapLE32(message.def.dwSeed);
const uint32_t dwSeed = SDL_SwapLE32(message.def.dwSeed);
const uint16_t wCI = SDL_SwapLE16(message.def.wCI);
const _item_indexes wIndx = static_cast<_item_indexes>(SDL_SwapLE16(message.def.wIndx));
if (GetItemRecord(dwSeed, wCI, wIndx)) {
@ -2577,7 +2577,7 @@ void DeltaAddItem(int ii)
if (item.bCmd != CMD_INVALID
&& static_cast<_item_indexes>(SDL_SwapLE16(item.def.wIndx)) == Items[ii].IDidx
&& SDL_SwapLE16(item.def.wCI) == Items[ii]._iCreateInfo
&& static_cast<int32_t>(SDL_SwapLE32(item.def.dwSeed)) == Items[ii]._iSeed
&& static_cast<uint32_t>(SDL_SwapLE32(item.def.dwSeed)) == Items[ii]._iSeed
&& IsAnyOf(item.bCmd, TCmdPItem::PickedUpItem, TCmdPItem::FloorItem)) {
return;
}

6
Source/msg.h

@ -532,13 +532,13 @@ struct TCmdQuest {
struct TItemDef {
_item_indexes wIndx;
uint16_t wCI;
int32_t dwSeed;
uint32_t dwSeed;
};
struct TItem {
_item_indexes wIndx;
uint16_t wCI;
int32_t dwSeed;
uint32_t dwSeed;
uint8_t bId;
uint8_t bDur;
uint8_t bMDur;
@ -557,7 +557,7 @@ struct TItem {
struct TEar {
_item_indexes wIndx;
uint16_t wCI;
int32_t dwSeed;
uint32_t dwSeed;
uint8_t bCursval;
char heroname[17];
};

Loading…
Cancel
Save