So just building an item and inventory/equipping system.
My solution to doing this is to have a base Item class, then subclasses like MeleeWeapon, RangedWeapon etc. that will have more specific values and functions attached to them.
My problem is here:
unsigned int Player::equipItem(Item item)
{
//first, we equip the item
switch (item.subClass) {
case SC::MELEE_WEAPON :
if (item.isOneHanded) {
//unequip mainhand (returns 2! so we can see if something was already there, equip mainhand slot.
//blabla
return 1; // yay!
}
break;
case SC::RANGED_WEAPON :
break;
case SC::SHIELD :
break;
case SC::ARMOR :
break;
}
return 0; //somethings fucked up.
}
so, the error is line 6, and it's because item does not have isOneHanded, but MeleeWeapon does. This would be safe at runtime im 99.9999% sure, but compiler doesn't know. I saw somewhere you can dynamically cast it to a MeleeWeapon manually and I played with that, got even more confusing errors, and on and on.
SC::... is just what i use for identifying what subclass the item is.
As to the kind of solutions I'm looking for:
as simple as possible, and as much explanation as possible. I want to learn not copy paste! Thank you!