class Item{
};
class Entity{
public:
std::string name;
int hp;
};
class ItemHolder{
std::vector<Item*> items;
size_t max_items;
};
class MoneyHolder{
int money;
};
class NPC : public Entity, public ItemHolder, public MoneyHolder{
};
class Player : public Entity, public ItemHolder, public MoneyHolder{
};
i'd like to make negotiations between Player and NPCs. i have this up to now:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void trade(Entity& trader, int c_money, int g_money, Item& c_item, Item& g_item){ //coming/going money and items
if (trader.money >= c_money && money >= g_money){
money += c_money - g_money;
items.append(c_item);
items.remove(g_item);
trader.money += g_money - c_money;
trader.items.append(g_item);
trader.items.remove(c_item);
}
else {
/*negotiation can't be done*/
}
}
but i can't find where to put this function and how to make it work.
and before anyone asks, i need the classes to be like this (instead of a big class that holds everything) for learning purposes and because there will be other Entities that will not hold money or items.