MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / CheckUnique

Function CheckUnique

Source/items.cpp:1454–1486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1452}
1453
1454_unique_items CheckUnique(Item &item, int lvl, int uper, bool recreate)
1455{
1456 std::bitset<128> uok = {};
1457
1458 if (GenerateRnd(100) > uper)
1459 return UITEM_INVALID;
1460
1461 int numu = 0;
1462 for (int j = 0; UniqueItems[j].UIItemId != UITYPE_INVALID; j++) {
1463 if (!IsUniqueAvailable(j))
1464 break;
1465 if (UniqueItems[j].UIItemId == AllItemsList[item.IDidx].iItemId
1466 && lvl >= UniqueItems[j].UIMinLvl
1467 && (recreate || !UniqueItemFlags[j] || gbIsMultiplayer)) {
1468 uok[j] = true;
1469 numu++;
1470 }
1471 }
1472
1473 if (numu == 0)
1474 return UITEM_INVALID;
1475
1476 DiscardRandomValues(1);
1477 uint8_t itemData = 0;
1478 while (numu > 0) {
1479 if (uok[itemData])
1480 numu--;
1481 if (numu > 0)
1482 itemData = (itemData + 1) % 128;
1483 }
1484
1485 return (_unique_items)itemData;
1486}
1487
1488void GetUniqueItem(const Player &player, Item &item, _unique_items uid)
1489{

Callers 1

SetupAllItemsFunction · 0.85

Calls 3

GenerateRndFunction · 0.85
IsUniqueAvailableFunction · 0.85
DiscardRandomValuesFunction · 0.85

Tested by

no test coverage detected