I have no idea what the purpose of this code is.
What if all slots are full up.
You call addItem twice. You could probably do something like this:
Writing a comment for every line is often "too much". Certainly saying something like "for-loop to walk through the array" - well, doh!, it's generally what for-loops do. Comments aren't there to explain what the code itself means, but the overall idea of the code.
I would also add teh rest of the braces, even if they aren't strictly needed.
I also wonder if you should ALWAYS add new elements if there is a zero-id, even is element of that ID with a value in it.
You use both addItem and AddItem - I presume there is only one variant of the name.
Here's something like what you do, but with error checking and only ONE line that does AddItemI().
Code:
void GetItem(int A)
{
for( int iii=0; iii != MAX_INV; iii++)
{
int tmpid = charInv[iii];
if( tmpid == 0 || (tmpid == id && charInv[iii].amount < stackSize))
{
break;
}
}
if (iii != MAX_INV)
{
if (charInv[iii] == 0)
{
charInv[iii] = *this;
}
charInv[iii].Additem(A);
}
else
{
// Handle error : no slots free.
}
}
--
Mats