i am currently developing a 2d rpg and have ran across a problem that i can't identify in my inventory system
its not a compile error as far as i'm aware
i am trying to allocate some memory for an array of a custom class with a pointer pointing to it.
an example of what i'm doing class wise:
class foo{
private:
int m_DynamicNumber;
int *p_CustomClassCount;
CustomClass *p_CustomClass;
public:
class();
}
//in constructor
class::class(){
m_DynamicNumber = 5;
p_CustomClass = new CustomClass[m_DynamicNumber];
p_CustomClassCount = new CustomClassCount[m_DynamicNumber];
}
now that is basically what i'm doing (full source code included at the end)
i think it might be that i'm trying to allocate the memory in the constructor but i dont see the problem with that.
it is compiling and when i run the program it does allocate memory but only for 1 not for the entire array,i've also checked if i can access the other members (as i thought it just might not be showing up in msvc) but i cant.
any help would be appreciated
thank you
(note: the problem i'm talking about is in the Inventory code,the item code is there because it is a header in inventory)
Item.h
#pragma once
#include <windows.h>
#include <string>
#include <gl/gl.h>
#include "TGA.h"
using namespace std;
class Item{
protected:
string m_Name;
string m_ID;
string m_Description;
GLuint m_DropSprite;
GLuint m_InventorySprite;
public:
Item();
Item(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven);
string GetName();
string GetDesc();
string GetID();
GLuint GetDropSprite();
GLuint GetInventorySprite();
void SetName(string Name);
void SetDesc(string Desc);
void SetID(string ID);
void SetDropSprite(TGAImg *DropSprite);
void SetInventorySprite(TGAImg *InvenSprite);
void SetDropSprite(GLuint DropSprite);
void SetInventorySprite(GLuint InvenSprite);
};
class Item_Potion : public Item{
private:
int m_RestoreValue;
public:
Item_Potion();
Item_Potion(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven,int Value);
int GetRestoreValue();
void SetRestoreValue(int Value);
};
class Item_MonsterDrop : public Item{
private:
int m_Level;
public:
Item_MonsterDrop();
Item_MonsterDrop(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven,int Level);
int GetLevel();
void SetLevel(int Level);
};
class Item_Base : public Item{
private:
int m_Type; // 0 for damage 1 for defence 2 for elemental
int m_Level; //level's 1 through 5, 1 being the lowest
public:
Item_Base();
Item_Base(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven,int Type,int Level);
int GetType();
int GetLevel();
void SetType(int Type);
void SetLevel(int Level);
};
class Item_Upgrade : public Item{
private:
int m_Type; // 0 for Damage 1 for Defence 2 for elemental
int m_Level; //level's 1 through 5, 1 being the lowest
int m_Value; //Value of attack,defense or elemental addition
public:
Item_Upgrade();
Item_Upgrade(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven,int Type,int Level);
int GetType();
int GetLevel();
int GetValue();
void SetType(int Type);
void SetLevel(int Level);
void SetValue(int Value);
};
class Item_Weapon : public Item{
private:
int m_Atk;
int m_Element;
int m_Percentage;
TGAImg m_AttackImg;
public:
Item_Weapon();
Item_Weapon(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven,TGAImg AttackImg,int Atk,int Element,int Percentage);
int GetAtk();
int GetElement();
int GetPercentage();
void SetAtk(int Atk);
void SetElement(int Element);
void SetPercentage(int Percentage);
};
class Item_Armour : public Item{
private:
int m_Def;
int m_Element;
int m_Percentage;
public:
Item_Armour();
Item_Armour(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven,int Def,int Element,int Percentage);
int GetDef();
int GetElement();
int GetPercentage();
void SetDef(int Def);
void SetElement(int Element);
void SetPercentage(int Percentage);
};
Item.cpp
#pragma once
#include "Item.h"
//Base Class Functions
Item::Item(){} // default constructor DO NOT USE
Item::Item(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven){
m_Name = Name;
m_Description = Description;
m_ID = ID;
SetDropSprite(&Drop);
SetInventorySprite(&Inven);
}
string Item::GetDesc(){
return m_Description;
}
string Item::GetName(){
return m_Name;
}
string Item::GetID(){
return m_ID;
}
GLuint Item::GetDropSprite(){
return m_DropSprite;
}
GLuint Item::GetInventorySprite(){
return m_InventorySprite;
}
void Item::SetName(string Name){
m_Name = Name;
}
void Item::SetDesc(string Desc){
m_Description = Desc;
}
void Item::SetID(string ID){
m_ID = ID;
}
void Item::SetDropSprite(TGAImg *DropSprite){
glGenTextures(1,&m_DropSprite);
glBindTexture(GL_TEXTURE_2D,m_DropSprite);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, DropSprite->GetWidth(),DropSprite->GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,DropSprite->GetImg());
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
void Item::SetInventorySprite(TGAImg *InvenSprite){
glGenTextures(1,&m_InventorySprite);
glBindTexture(GL_TEXTURE_2D,m_InventorySprite);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, InvenSprite->GetWidth(),InvenSprite->GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,InvenSprite->GetImg());
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
void Item::SetDropSprite(GLuint DropSprite){
m_DropSprite = DropSprite;
}
void Item::SetInventorySprite(GLuint InvenSprite){
m_InventorySprite = InvenSprite;
}
//Potion Specific Functions
Item_Potion::Item_Potion(){} // default constructor DO NOT USE
Item_Potion::Item_Potion(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven,int Value){
m_Name = Name;
m_Description = Description;
m_ID = ID;
SetDropSprite(&Drop);
SetInventorySprite(&Inven);
m_RestoreValue = Value;
}
int Item_Potion::GetRestoreValue(){
return m_RestoreValue;
}
void Item_Potion::SetRestoreValue(int Value){
m_RestoreValue = Value;
}
// Monster Drop Specific functions
Item_MonsterDrop::Item_MonsterDrop(){} // default constructor DO NOT USE
Item_MonsterDrop::Item_MonsterDrop(string Name, string Description, string ID, TGAImg Drop, TGAImg Inven, int Level){
m_Name = Name;
m_Description = Description;
m_ID = ID;
SetDropSprite(&Drop);
SetInventorySprite(&Inven);
m_Level = Level;
}
int Item_MonsterDrop::GetLevel(){
return m_Level;
}
void Item_MonsterDrop::SetLevel(int Level){
m_Level = Level;
}
// Synth Base Specific Functions
Item_Base::Item_Base(){} // default constructor DO NOT USE
Item_Base::Item_Base(string Name, string Description, string ID, TGAImg Drop, TGAImg Inven, int Type, int Level){
m_Name = Name;
m_Description = Description;
m_ID = ID;
SetDropSprite(&Drop);
SetInventorySprite(&Inven);
m_Type = Type;
m_Level = Level;
}
int Item_Base::GetType(){
return m_Type;
}
int Item_Base::GetLevel(){
return m_Level;
}
void Item_Base::SetLevel(int Level){
m_Level = Level;
}
void Item_Base::SetType(int Type){
m_Type = Type;
}
//Upgrade Specific Functions
Item_Upgrade::Item_Upgrade(){} // default constructor DO NOT USE
Item_Upgrade::Item_Upgrade(string Name, string Description, string ID, TGAImg Drop, TGAImg Inven, int Type, int Level){
m_Name = Name;
m_Description = Description;
m_ID = ID;
SetDropSprite(&Drop);
SetInventorySprite(&Inven);
m_Type = Type;
m_Level = Level;
}
int Item_Upgrade::GetType(){
return m_Type;
}
int Item_Upgrade::GetLevel(){
return m_Level;
}
int Item_Upgrade::GetValue(){
return m_Value;
}
void Item_Upgrade::SetLevel(int Level){
m_Level = Level;
}
void Item_Upgrade::SetType(int Type){
m_Type = Type;
}
void Item_Upgrade::SetValue(int Value){
m_Value = Value;
}
// Weapon Specific Functions
Item_Weapon::Item_Weapon(){} // default constructor DO NOT USE
Item_Weapon::Item_Weapon(string Name,string Description,string ID,TGAImg Drop,TGAImg Inven,TGAImg AttackImg,int Atk,int Element,int Percentage){
m_Name = Name;
m_Description = Description;
m_ID = ID;
SetDropSprite(&Drop);
SetInventorySprite(&Inven);
m_AttackImg = AttackImg;
m_Atk = Atk;
m_Element = Element;
m_Percentage = Percentage;
}
int Item_Weapon::GetAtk(){
return m_Atk;
}
int Item_Weapon::GetElement(){
return m_Element;
}
int Item_Weapon::GetPercentage(){
return m_Percentage;
}
void Item_Weapon::SetAtk(int Atk){
m_Atk = Atk;
}
void Item_Weapon::SetElement(int Element){
m_Element = Element;
}
void Item_Weapon::SetPercentage(int Percentage){
m_Percentage = Percentage;
}
//Armour Specific Functions
Item_Armour::Item_Armour(){} // default constructor DO NOT USE
Item_Armour::Item_Armour(string Name, string Description, string ID, TGAImg Drop, TGAImg Inven, int Def, int Element, int Percentage){
m_Name = Name;
m_Description = Description;
m_ID = ID;
SetDropSprite(&Drop);
SetInventorySprite(&Inven);
m_Def = Def;
m_Element = Element;
m_Percentage = Percentage;
}
int Item_Armour::GetDef(){
return m_Def;
}
int Item_Armour::GetElement(){
return m_Element;
}
int Item_Armour::GetPercentage(){
return m_Percentage;
}
void Item_Armour::SetDef(int Def){
m_Def = Def;
}
void Item_Armour::SetElement(int Element){
m_Element = Element;
}
void Item_Armour::SetPercentage(int Percentage){
m_Percentage = Percentage;
}
Inventory.h
#pragma once
#include "Item.h"
class Inventory{
private:
int m_PotionSlots;
int m_DropSlots;
int m_BaseSlots;
int m_UpgradeSlots;
int m_WeaponSlots;
int m_ArmourSlots;
int *m_PotionCount;
int *m_DropCount;
int *m_BaseCount;
int *m_UpgradeCount;
int *m_WeaponCount;
int *m_ArmourCount;
public:
Item_Potion *m_PotionBag;
Item_MonsterDrop *m_DropBag;
Item_Base *m_BaseBag;
Item_Upgrade *m_UpgradeBag;
Item_Weapon *m_WeaponBag;
Item_Armour *m_ArmourBag;
Inventory();
Inventory(int PotionSlots,int DropSlots,int BaseSlots,int UpgradeSlots,int WeaponSlots,int ArmourSlots);
~Inventory();
bool AddToPotion(Item_Potion Item);
bool AddToPotion(Item_Potion Item,int Slot);
bool AddToMonsterDrop(Item_MonsterDrop Item);
bool AddToMonsterDrop(Item_MonsterDrop Item,int Slot);
bool AddToBase(Item_Base Item);
bool AddToBase(Item_Base Item,int Slot);
bool AddToUpgrade(Item_Upgrade Item);
bool AddToUpgrade(Item_Upgrade Item,int Slot);
bool AddToWeapon(Item_Weapon Item);
bool AddToWeapon(Item_Weapon Item,int Slot);
bool AddToArmour(Item_Armour Item);
bool AddToArmour(Item_Armour Item,int Slot);
void DestroyItem(int Slot);
void MoveItem(int RootSlot, int TargetSlot);
};
Inventory.cpp
#include "Inventory.h"
#define POTION_STACK_LIMIT 10
#define DROP_STACK_LIMIT 20
#define BASE_STACK_LIMIT 20
#define UPGRADE_STACK_LIMIT 2
#define WEAPON_STACK_LIMIT 1
#define ARMOUR_STACK_LIMIT 1
Inventory::Inventory(){
m_PotionSlots = 5; // sets up how many slots for each item type
m_DropSlots = 10;
m_BaseSlots = 10;
m_UpgradeSlots = 6;
m_WeaponSlots = 4;
m_ArmourSlots = 4;
m_PotionBag = new Item_Potion[m_PotionSlots]; // assigns an array with amount of slots defined previously
m_PotionCount = new int[m_PotionSlots]; // and also creates an array that holds a counter for each slot
m_DropBag = new Item_MonsterDrop[m_DropSlots]; // so items can stack
m_DropCount = new int[m_DropSlots];
m_BaseBag = new Item_Base[m_BaseSlots];
m_BaseCount = new int[m_BaseSlots];
m_UpgradeBag = new Item_Upgrade[m_UpgradeSlots];
m_UpgradeCount = new int[m_UpgradeSlots];
m_WeaponBag = new Item_Weapon[m_WeaponSlots];
m_WeaponCount = new int[m_WeaponSlots];
m_ArmourBag = new Item_Armour[m_ArmourSlots];
m_ArmourCount = new int[m_ArmourSlots];
for(int i = 0;i<m_PotionSlots;i++){ //Set all counters to 0
m_PotionCount = 0; //could possibly do with memset but not sure
} //if it sets it to 0 or the unsigned char version of 0
for(int i = 0;i<m_DropSlots;i++){
m_DropCount = 0;
}
for(int i = 0;i<m_BaseSlots;i++){
m_BaseCount = 0;
}
for(int i = 0;i<m_UpgradeSlots;i++){
m_UpgradeCount = 0;
}
for(int i = 0;i<m_WeaponSlots;i++){
m_WeaponCount = 0;
}
for(int i = 0;i<m_ArmourSlots;i++){
m_ArmourCount = 0;
}
}
Inventory::Inventory(int PotionSlots,int DropSlots,int BaseSlots,int UpgradeSlots,int WeaponSlots,int ArmourSlots){
m_PotionSlots = PotionSlots;
m_DropSlots = DropSlots;
m_BaseSlots = BaseSlots;
m_UpgradeSlots = UpgradeSlots;
m_WeaponSlots = WeaponSlots;
m_ArmourSlots = ArmourSlots;
m_PotionBag = new Item_Potion[m_PotionSlots]; // assigns an array with amount of slots defined previously
m_PotionCount = new int[m_PotionSlots]; // and also creates an array that holds a counter for each slot
m_DropBag = new Item_MonsterDrop[m_DropSlots]; // so items can stack
m_DropCount = new int[m_DropSlots];
m_BaseBag = new Item_Base[m_BaseSlots];
m_BaseCount = new int[m_BaseSlots];
m_UpgradeBag = new Item_Upgrade[m_UpgradeSlots];
m_UpgradeCount = new int[m_UpgradeSlots];
m_WeaponBag = new Item_Weapon[m_WeaponSlots];
m_WeaponCount = new int[m_WeaponSlots];
m_ArmourBag = new Item_Armour[m_ArmourSlots];
m_ArmourCount = new int[m_ArmourSlots];
for(int i = 0;i<m_PotionSlots;i++){ //Set all counters to 0
m_PotionCount = 0; //could possibly do with memset but not sure
} //if it sets it to 0 or the unsigned char version of 0
for(int i = 0;i<m_DropSlots;i++){
m_DropCount = 0;
}
for(int i = 0;i<m_BaseSlots;i++){
m_BaseCount = 0;
}
for(int i = 0;i<m_UpgradeSlots;i++){
m_UpgradeCount = 0;
}
for(int i = 0;i<m_WeaponSlots;i++){
m_WeaponCount = 0;
}
for(int i = 0;i<m_ArmourSlots;i++){
m_ArmourCount = 0;
}
}
Inventory::~Inventory(){
delete []m_PotionBag;
delete []m_PotionCount;
delete []m_DropBag;
delete []m_DropCount;
delete []m_BaseBag;
delete []m_BaseCount;
delete []m_UpgradeBag;
delete []m_UpgradeCount;
delete []m_WeaponBag;
delete []m_WeaponCount;
delete []m_ArmourBag;
delete []m_ArmourCount;
}
bool Inventory::AddToPotion(Item_Potion Item){
bool Item_Present = false; //if item is already in the bag
bool Item_Fits = false; //if the item is already in the bag and will fit into a stack
bool Empty_Space = false;
int Situation = 4; // a value not in the enumeration(and thus not in the switch-case)
// enum types
// P_SIS the item is present and a is has space in its stack
// NP_ES item is not already present and there is an empty space where it can go
// ALL_FULL there is no space for the item/ if it is present, all stacks are full
//
enum { P_SIS,NP_ES,ALL_FULL};
for(int i = 0;i < m_PotionSlots;i++){ //checks to see if item is already present in the bag
if(m_PotionBag.GetID() == Item.GetID()){
Item_Present = true;
}
}
for(int i = 0;i < m_PotionSlots;i++){ //checks to see if there are any empty spaces
if(m_PotionCount == 0){
Empty_Space = true;
}
}
if(Item_Present){ //if item is present then see if a stack has space
for(int i = 0;i < m_PotionSlots;i++){
if(m_PotionBag.GetID() == Item.GetID() && m_PotionCount < POTION_STACK_LIMIT){ // checks to see if the stacks of the items are full
Item_Fits = true;
}
}
}
if(Item_Present && Item_Fits){ //if there is a space in a stack of the item already
Situation = P_SIS;
}else if(Empty_Space){ //if item is not already there or item is there but full then check for empty spaces
Situation = NP_ES;
}else{ // otherwise item does not fit in bag
Situation = ALL_FULL;
}
switch(Situation){
case P_SIS:
for(int i = 0;i < m_PotionSlots;i++){
if(m_PotionBag.GetID() == Item.GetID()){
m_PotionCount ++;
return true;
break;
}
}
break;
case NP_ES:
for(int i = 0;i< m_PotionSlots;i++){
if(m_PotionCount == 0){ // if the block is empty
m_PotionBag.SetDesc(Item.GetDesc()); //then copy the item into the space
m_PotionBag.SetDropSprite(Item.GetDropSprite());
m_PotionBag.SetID(Item.GetID());
m_PotionBag.SetInventorySprite(Item.GetInventorySprite());
m_PotionBag.SetName(Item.GetName());
m_PotionBag.SetRestoreValue(Item.GetRestoreValue());
m_PotionCount ++; // and add one to the slots counter
return true;
break;
}
}
break;
case ALL_FULL:
// INSERT ERROR MESSAGE HERE
return false;
break;
default:
// INSERT UNEXPECTED ERROR MESSAGE HERE
return false;
break;
}
return false;
}
bool Inventory::AddToPotion(Item_Potion Item,int Slot){
if(m_PotionBag[Slot].GetID() == Item.GetID() && m_PotionCount[Slot] < POTION_STACK_LIMIT){
m_PotionCount[Slot] ++;
return true;
}
else if(m_PotionCount[Slot] == 0){
m_PotionBag[Slot].SetDesc(Item.GetDesc()); //then copy the item into the space
m_PotionBag[Slot].SetDropSprite(Item.GetDropSprite());
m_PotionBag[Slot].SetID(Item.GetID());
m_PotionBag[Slot].SetInventorySprite(Item.GetInventorySprite());
m_PotionBag[Slot].SetName(Item.GetName());
m_PotionBag[Slot].SetRestoreValue(Item.GetRestoreValue());
m_PotionCount[Slot] ++; // and add one to the slots counter
return true;
}
else{
return false;
}
}
bool Inventory::AddToMonsterDrop(Item_MonsterDrop Item){
bool Item_Present = false; //if item is already in the bag
bool Item_Fits = false; //if the item is already in the bag and will fit into a stack
bool Empty_Space = false;
int Situation = 4; // a value not in the enumeration(and thus not in the switch-case)
// enum types
// P_SIS the item is present and a is has space in its stack
// NP_ES item is not already present and there is an empty space where it can go
// ALL_FULL there is no space for the item/ if it is present, all stacks are full
//
enum { P_SIS,NP_ES,ALL_FULL};
for(int i = 0;i < m_DropSlots;i++){ //checks to see if item is already present in the bag
if(m_DropBag.GetID() == Item.GetID()){
Item_Present = true;
}
}
for(int i = 0;i < m_DropSlots;i++){ //checks to see if there are any empty spaces
if(m_DropCount == 0){
Empty_Space = true;
}
}
if(Item_Present){ //if item is present then see if a stack has space
for(int i = 0;i < m_DropSlots;i++){
if(m_DropBag.GetID() == Item.GetID() && m_DropCount< DROP_STACK_LIMIT){ // checks to see if the stacks of the items are full
Item_Fits = true;
}
}
}
if(Item_Present && Item_Fits){ //if there is a space in a stack of the item already
Situation = P_SIS;
}else if(Empty_Space){ //if item is not already there or item is there but full then check for empty spaces
Situation = NP_ES;
}else{ // otherwise item does not fit in bag
Situation = ALL_FULL;
}
switch(Situation){
case P_SIS:
for(int i = 0;i < m_DropSlots;i++){
if(m_DropBag.GetID() == Item.GetID()){
m_DropCount ++;
return true;
break;
}
}
break;
case NP_ES:
for(int i = 0;i< m_DropSlots;i++){
if(m_DropCount == 0){ // if the block is empty
m_DropBag.SetDesc(Item.GetDesc()); //then copy the item into the space
m_DropBag.SetDropSprite(Item.GetDropSprite());
m_DropBag.SetID(Item.GetID());
m_DropBag.SetInventorySprite(Item.GetInventorySprite());
m_DropBag.SetName(Item.GetName());
m_DropBag.SetLevel(Item.GetLevel());
m_DropCount ++; // and add one to the slots counter
return true;
break;
}
}
break;
case ALL_FULL:
// INSERT ERROR MESSAGE HERE
return false;
break;
default:
// INSERT UNEXPECTED ERROR MESSAGE HERE
return false;
break;
}
return false;
}
bool Inventory::AddToMonsterDrop(Item_MonsterDrop Item,int Slot){
if(m_DropBag[Slot].GetID() == Item.GetID() && m_DropCount[Slot] < DROP_STACK_LIMIT){
m_DropCount[Slot] ++;
return true;
}
else if(m_DropCount[Slot] == 0){
m_DropBag[Slot].SetDesc(Item.GetDesc()); //then copy the item into the space
m_DropBag[Slot].SetDropSprite(Item.GetDropSprite());
m_DropBag[Slot].SetID(Item.GetID());
m_DropBag[Slot].SetInventorySprite(Item.GetInventorySprite());
m_DropBag[Slot].SetName(Item.GetName());
m_DropBag[Slot].SetLevel(Item.GetLevel());
m_DropCount[Slot] ++; // and add one to the slots counter
return true;
}
else{
return false;
}
}
bool Inventory::AddToBase(Item_Base Item){
bool Item_Present = false; //if item is already in the bag
bool Item_Fits = false; //if the item is already in the bag and will fit into a stack
bool Empty_Space = false;
int Situation = 4; // a value not in the enumeration(and thus not in the switch-case)
// enum types
// P_SIS the item is present and a is has space in its stack
// NP_ES item is not already present and there is an empty space where it can go
// ALL_FULL there is no space for the item/ if it is present, all stacks are full
//
enum { P_SIS,NP_ES,ALL_FULL};
for(int i = 0;i < m_BaseSlots;i++){ //checks to see if item is already present in the bag
if(m_BaseBag.GetID() == Item.GetID()){
Item_Present = true;
}
}
for(int i = 0;i < m_BaseSlots;i++){ //checks to see if there are any empty spaces
if(m_BaseCount == 0){
Empty_Space = true;
}
}
if(Item_Present){ //if item is present then see if a stack has space
for(int i = 0;i < m_BaseSlots;i++){
if(m_BaseBag.GetID() == Item.GetID() && m_BaseCount< BASE_STACK_LIMIT){ // checks to see if the stacks of the items are full
Item_Fits = true;
}
}
}
if(Item_Present && Item_Fits){ //if there is a space in a stack of the item already
Situation = P_SIS;
}else if(Empty_Space){ //if item is not already there or item is there but full then check for empty spaces
Situation = NP_ES;
}else{ // otherwise item does not fit in bag
Situation = ALL_FULL;
}
switch(Situation){
case P_SIS:
for(int i = 0;i < m_BaseSlots;i++){
if(m_BaseBag.GetID() == Item.GetID()){
m_BaseCount ++;
return true;
break;
}
}
break;
case NP_ES:
for(int i = 0;i< m_BaseSlots;i++){
if(m_BaseCount == 0){ // if the block is empty
m_BaseBag.SetDesc(Item.GetDesc()); //then copy the item into the space
m_BaseBag.SetDropSprite(Item.GetDropSprite());
m_BaseBag.SetID(Item.GetID());
m_BaseBag.SetInventorySprite(Item.GetInventorySprite());
m_BaseBag.SetName(Item.GetName());
m_BaseBag.SetLevel(Item.GetLevel());
m_BaseBag.SetType(Item.GetType());
m_BaseCount ++; // and add one to the slots counter
return true;
break;
}
}
break;
case ALL_FULL:
// INSERT ERROR MESSAGE HERE
return false;
break;
default:
// INSERT UNEXPECTED ERROR MESSAGE HERE
return false;
break;
}
return false;
}
bool Inventory::AddToBase(Item_Base Item,int Slot){
if(m_BaseBag[Slot].GetID() == Item.GetID() && m_BaseCount[Slot] < BASE_STACK_LIMIT){
m_BaseCount[Slot] ++;
return true;
}
else if(m_BaseCount[Slot] == 0){
m_BaseBag[Slot].SetDesc(Item.GetDesc()); //then copy the item into the space
m_BaseBag[Slot].SetDropSprite(Item.GetDropSprite());
m_BaseBag[Slot].SetID(Item.GetID());
m_BaseBag[Slot].SetInventorySprite(Item.GetInventorySprite());
m_BaseBag[Slot].SetName(Item.GetName());
m_BaseBag[Slot].SetLevel(Item.GetLevel());
m_BaseBag[Slot].SetType(Item.GetType());
m_BaseCount[Slot] ++; // and add one to the slots counter
return true;
}
else{
return false;
}
}
bool Inventory::AddToUpgrade(Item_Upgrade Item){
bool Item_Present = false; //if item is already in the bag
bool Item_Fits = false; //if the item is already in the bag and will fit into a stack
bool Empty_Space = false;
int Situation = 4; // a value not in the enumeration(and thus not in the switch-case)
// enum types
// P_SIS the item is present and a is has space in its stack
// NP_ES item is not already present and there is an empty space where it can go
// ALL_FULL there is no space for the item/ if it is present, all stacks are full
//
enum { P_SIS,NP_ES,ALL_FULL};
for(int i = 0;i < m_UpgradeSlots;i++){ //checks to see if item is already present in the bag
if(m_UpgradeBag.GetID() == Item.GetID()){
Item_Present = true;
}
}
for(int i = 0;i < m_UpgradeSlots;i++){ //checks to see if there are any empty spaces
if(m_UpgradeCount == 0){
Empty_Space = true;
}
}
if(Item_Present){ //if item is present then see if a stack has space
for(int i = 0;i < m_UpgradeSlots;i++){
if(m_UpgradeBag.GetID() == Item.GetID() && m_UpgradeCount< UPGRADE_STACK_LIMIT){ // checks to see if the stacks of the items are full
Item_Fits = true;
}
}
}
if(Item_Present && Item_Fits){ //if there is a space in a stack of the item already
Situation = P_SIS;
}else if(Empty_Space){ //if item is not already there or item is there but full then check for empty spaces
Situation = NP_ES;
}else{ // otherwise item does not fit in bag
Situation = ALL_FULL;
}
switch(Situation){
case P_SIS:
for(int i = 0;i < m_UpgradeSlots;i++){
if(m_UpgradeBag.GetID() == Item.GetID()){
m_UpgradeCount ++;
return true;
}
}
break;
case NP_ES:
for(int i = 0;i< m_UpgradeSlots;i++){
if(m_UpgradeCount == 0){ // if the block is empty
m_UpgradeBag.SetDesc(Item.GetDesc()); //then copy the item into the space
m_UpgradeBag.SetDropSprite(Item.GetDropSprite());
m_UpgradeBag.SetID(Item.GetID());
m_UpgradeBag.SetInventorySprite(Item.GetInventorySprite());
m_UpgradeBag.SetName(Item.GetName());
m_UpgradeBag.SetLevel(Item.GetLevel());
m_UpgradeBag.SetType(Item.GetType());
m_UpgradeBag.SetValue(Item.GetValue());
m_UpgradeCount ++; // and add one to the slots counter
return true;
}
}
break;
case ALL_FULL:
// INSERT ERROR MESSAGE HERE
return false;
break;
default:
// INSERT UNEXPECTED ERROR MESSAGE HERE
return false;
break;
}
return false;
}
bool Inventory::AddToUpgrade(Item_Upgrade Item,int Slot){
if(m_UpgradeBag[Slot].GetID() == Item.GetID() && m_UpgradeCount[Slot] < UPGRADE_STACK_LIMIT){
m_UpgradeCount[Slot] ++;
return true;
}
else if(m_UpgradeCount[Slot] == 0){
m_UpgradeBag[Slot].SetDesc(Item.GetDesc()); //then copy the item into the space
m_UpgradeBag[Slot].SetDropSprite(Item.GetDropSprite());
m_UpgradeBag[Slot].SetID(Item.GetID());
m_UpgradeBag[Slot].SetInventorySprite(Item.GetInventorySprite());
m_UpgradeBag[Slot].SetName(Item.GetName());
m_UpgradeBag[Slot].SetLevel(Item.GetLevel());
m_UpgradeBag[Slot].SetType(Item.GetType());
m_UpgradeBag[Slot].SetValue(Item.GetValue());
m_UpgradeCount[Slot] ++; // and add one to the slots counter
return true;
}
else{
return false;
}
}
bool Inventory::AddToWeapon(Item_Weapon Item){
bool Item_Present = false; //if item is already in the bag
bool Item_Fits = false; //if the item is already in the bag and will fit into a stack
bool Empty_Space = false;
int Situation = 4; // a value not in the enumeration(and thus not in the switch-case)
// enum types
// P_SIS the item is present and a is has space in its stack
// NP_ES item is not already present and there is an empty space where it can go
// ALL_FULL there is no space for the item/ if it is present, all stacks are full
//
enum { P_SIS,NP_ES,ALL_FULL};
for(int i = 0;i < m_WeaponSlots;i++){ //checks to see if item is already present in the bag
if(m_WeaponBag.GetID() == Item.GetID()){
Item_Present = true;
}
}
for(int i = 0;i < m_WeaponSlots;i++){ //checks to see if there are any empty spaces
if(m_WeaponCount == 0){
Empty_Space = true;
}
}
if(Item_Present){ //if item is present then see if a stack has space
for(int i = 0;i < m_WeaponSlots;i++){
if(m_WeaponBag.GetID() == Item.GetID() && m_WeaponCount< WEAPON_STACK_LIMIT){ // checks to see if the stacks of the items are full
Item_Fits = true;
}
}
}
if(Item_Present && Item_Fits){ //if there is a space in a stack of the item already
Situation = P_SIS;
}else if(Empty_Space){ //if item is not already there or item is there but full then check for empty spaces
Situation = NP_ES;
}else{ // otherwise item does not fit in bag
Situation = ALL_FULL;
}
switch(Situation){
case P_SIS:
for(int i = 0;i < m_WeaponSlots;i++){
if(m_WeaponBag.GetID() == Item.GetID()){
m_WeaponCount ++;
return true;
break;
}
}
break;
case NP_ES:
for(int i = 0;i< m_WeaponSlots;i++){
if(m_WeaponCount == 0){ // if the block is empty
m_WeaponBag.SetDesc(Item.GetDesc()); //then copy the item into the space
m_WeaponBag.SetDropSprite(Item.GetDropSprite());
m_WeaponBag.SetID(Item.GetID());
m_WeaponBag.SetInventorySprite(Item.GetInventorySprite());
m_WeaponBag.SetName(Item.GetName());
m_WeaponBag.SetAtk(Item.GetAtk());
m_WeaponBag.SetElement(Item.GetElement());
m_WeaponBag.SetPercentage(Item.GetPercentage());
m_WeaponCount ++; // and add one to the slots counter
return true;
break;
}
}
break;
case ALL_FULL:
// INSERT ERROR MESSAGE HERE
return false;
break;
default:
// INSERT UNEXPECTED ERROR MESSAGE HERE
return false;
break;
}
return false;
}
bool Inventory::AddToWeapon(Item_Weapon Item,int Slot){
if(m_WeaponBag[Slot].GetID() == Item.GetID() && m_WeaponCount[Slot] < WEAPON_STACK_LIMIT){
m_WeaponCount[Slot] ++;
return true;
}
else if(m_WeaponCount[Slot] == 0){
m_WeaponBag[Slot].SetDesc(Item.GetDesc()); //then copy the item into the space
m_WeaponBag[Slot].SetDropSprite(Item.GetDropSprite());
m_WeaponBag[Slot].SetID(Item.GetID());
m_WeaponBag[Slot].SetInventorySprite(Item.GetInventorySprite());
m_WeaponBag[Slot].SetName(Item.GetName());
m_WeaponBag[Slot].SetAtk(Item.GetAtk());
m_WeaponBag[Slot].SetElement(Item.GetElement());
m_WeaponBag[Slot].SetPercentage(Item.GetPercentage());
m_WeaponCount[Slot] ++; // and add one to the slots counter
return true;
}
else{
return false;
}
}
bool Inventory::AddToArmour(Item_Armour Item){
bool Item_Present = false; //if item is already in the bag
bool Item_Fits = false; //if the item is already in the bag and will fit into a stack
bool Empty_Space = false;
int Situation = 4; // a value not in the enumeration(and thus not in the switch-case)
// enum types
// P_SIS the item is present and a is has space in its stack
// NP_ES item is not already present and there is an empty space where it can go
// ALL_FULL there is no space for the item/ if it is present, all stacks are full
//
enum { P_SIS,NP_ES,ALL_FULL};
for(int i = 0;i < m_ArmourSlots;i++){ //checks to see if item is already present in the bag
if(m_ArmourBag.GetID() == Item.GetID()){
Item_Present = true;
}
}
for(int i = 0;i < m_ArmourSlots;i++){ //checks to see if there are any empty spaces
if(m_ArmourCount == 0){
Empty_Space = true;
}
}
if(Item_Present){ //if item is present then see if a stack has space
for(int i = 0;i < m_ArmourSlots;i++){
if(m_ArmourBag.GetID() == Item.GetID() && m_ArmourCount< ARMOUR_STACK_LIMIT){ // checks to see if the stacks of the items are full
Item_Fits = true;
}
}
}
if(Item_Present && Item_Fits){ //if there is a space in a stack of the item already
Situation = P_SIS;
}else if(Empty_Space){ //if item is not already there or item is there but full then check for empty spaces
Situation = NP_ES;
}else{ // otherwise item does not fit in bag
Situation = ALL_FULL;
}
switch(Situation){
case P_SIS:
for(int i = 0;i < m_ArmourSlots;i++){
if(m_ArmourBag.GetID() == Item.GetID()){
m_ArmourCount ++;
return true;
break;
}
}
break;
case NP_ES:
for(int i = 0;i< m_ArmourSlots;i++){
if(m_ArmourCount == 0){ // if the block is empty
m_ArmourBag.SetDesc(Item.GetDesc()); //then copy the item into the space
m_ArmourBag.SetDropSprite(Item.GetDropSprite());
m_ArmourBag.SetID(Item.GetID());
m_ArmourBag.SetInventorySprite(Item.GetInventorySprite());
m_ArmourBag.SetName(Item.GetName());
m_ArmourBag.SetDef(Item.GetDef());
m_ArmourBag.SetElement(Item.GetElement());
m_ArmourBag.SetPercentage(Item.GetPercentage());
m_ArmourCount ++; // and add one to the slots counter
return true;
break;
}
}
break;
case ALL_FULL:
// INSERT ERROR MESSAGE HERE
return false;
break;
default:
// INSERT UNEXPECTED ERROR MESSAGE HERE
return false;
break;
}
return false;
}
bool Inventory::AddToArmour(Item_Armour Item,int Slot){
if(m_ArmourBag[Slot].GetID() == Item.GetID() && m_ArmourCount[Slot] < ARMOUR_STACK_LIMIT){
m_ArmourCount[Slot] ++;
return true;
}
else if(m_ArmourCount[Slot] == 0){
m_ArmourBag[Slot].SetDesc(Item.GetDesc()); //then copy the item into the space
m_ArmourBag[Slot].SetDropSprite(Item.GetDropSprite());
m_ArmourBag[Slot].SetID(Item.GetID());
m_ArmourBag[Slot].SetInventorySprite(Item.GetInventorySprite());
m_ArmourBag[Slot].SetName(Item.GetName());
m_ArmourBag[Slot].SetDef(Item.GetDef());
m_ArmourBag[Slot].SetElement(Item.GetElement());
m_ArmourBag[Slot].SetPercentage(Item.GetPercentage());
m_ArmourCount[Slot] ++; // and add one to the slots counter
return true;
}
else{
return false;
}
}
void Inventory::DestroyItem(int Slot){}
void Inventory::MoveItem(int RootSlot, int TargetSlot){}