MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / FIND_FREE_INDEX

Function FIND_FREE_INDEX

scripts/Merc7.cpp:1365–1385  ·  view source on GitHub ↗

this function will return a random free index in a max (bit must be 0) if there are none, then return a random index??

Source from the content-addressed store, hash-verified

1363// this function will return a random free index in a max (bit must be 0)
1364// if there are none, then return a random index??
1365inline int FIND_FREE_INDEX(unsigned mask, unsigned max_items, bool allow_duplicates) {
1366 int i;
1367 int8_t indices[32];
1368 int8_t nindices = 0;
1369
1370 for (i = 0; i < max_items; i++) {
1371 if ((mask & (1 << i)) == 0) {
1372 indices[nindices++] = i;
1373 }
1374 }
1375
1376 if (nindices == 0) {
1377 if (allow_duplicates) {
1378 return (rand() % max_items);
1379 } else {
1380 return -1;
1381 }
1382 } else {
1383 return (int)(indices[rand() % nindices]);
1384 }
1385}
1386
1387/*
1388$$ACTION

Callers 3

cDroidManagerCreateNewFunction · 0.85
cSendDroidObjToExitFunction · 0.85
cSendDroidObjToTermFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected