1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
void selectProperties(ITEMS* item, int* propArray, int propStage, int propNum)
{
int availableProp[] = { 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
int numAvailable = sizeof(availableProp) / sizeof(availableProp[0]);
int count = 0;
switch(propStage)
{
case 1:
numAvailable -= 3;
break;
case 2:
numAvailable -= 2;
break;
case 3:
numAvailable -= 1;
break;
case 4:
break;
default: ASSERT(FALSE, "The propStage variable is out of range. Available from 1 to 4. Check the function before!");
}
while (count < propNum)
{
// randomize the properties from the given array and assign to the selectedProp
int randProp = rand() % numAvailable;
int selectedProp = availableProp[randProp];
// add some condition, and if failed skip and continue to try with other properties again.
if ((selectedProp == 10) && (item->category != SHIELD && item->category != JEWELRY))
continue;
else if ((selectedProp == 16) && item->category != JEWELRY)
continue;
else if ((selectedProp == 17) && item->jewel_kind != AMULET)
continue;
else
{
// add prop if it doesn't already exist in the array
if (!inArray(selectedProp, propArray, count))
{
propArray[count] = selectedProp;
count++;
}
}
}
}
|