This is a pretty good tutorial for learning structures:
http://www.cplusplus.com/doc/tutorial/structures/
I fixed my code and am now using it in my own project, here is a sample (it's not done yet):
StatsManager.h
#include "CMI.h"
struct statsManager {
// Character data
char Name[128]; // Character name
int Level; // Character level
int RankID; // Character rank
int RaceID; // For specifying the race of the character
// Character customization data
int Sex;
int HairStyle;
int HairColour;
int EyeColour;
int FaceType;
int BeardStyle;
int BeardColour;
int BodyType;
// Combat stats
int maxHP;
int maxMP;
int maxStam;
float currentHP;
float currentMP;
float currentStam;
int regenHP;
int regenMP;
int regenStam;
float ArmourClass;
float AttackPower;
float Dodge;
float Evade;
float Parry;
float Block;
float Attack;
float AttackDelay;
float SwingSpeed;
float CritChance;
float maxHitDamage;
float minHitDamage;
// Character stats
int Srength;
int Agility;
int Dexterity;
int Endurance;
int Intelligence;
int Wisdom;
// Character item system
int Inventory[INVENTORY_SLOTS]; // Defines the an array for holding inventory items
int BagSlots[BAG_SLOTS]; // Defines the number of slots for holding bags
int UtilitySlots[UTILITY_SLOTS]; // Defines the number of slots for holding utility items
// Character equiped items
int eHead; // Helmets, crowns, masks, etc (head gear)
int eLeftEar; // Earings
int eRightEar; // Earings
int eNeck; // Necklaces
int eShoulders; // Shoulder pads
int eChest; // Breast plates, chain mail armor, robes, etc (armor to protect the torso)
int eUnderChest; // Shirts, tunics, etc (anything under the "chest item")
int eBack; // Capes, cloaks, backpacks, etc (something worn on the back)
int eEnsignia; // Rank badges, trophies, etc
int eLeftArm; // Bracers, shackles, etc
int eRightArm; // Bracers, shackles, etc
int eGloves; // Gloves, mits, etc
int eBelt; // Belts
int eLegs; // Leg armor
int eBoots; // Boots, shoes, etc
int eMainHand; // Main handed weapon or item
int eOffHand; // Offhand weapon or item
int eRanged; // ranged weapon or item
int eTotem; // Quivers for arrows/bolts, totem, flag, etc
};
#if INCL_PLAYER != 0
extern statsManager * player;
#endif
#if INCL_MP != 0
extern statsManager * mPlayer[PLAYER_MP];
#endif
#if INCL_GROUP0 != 0
extern statsManager * group0[GROUP0];
#endif
#if INCL_GROUP1 != 0
extern statsManager * group1[GROUP1];
#endif
#if INCL_GROUP2 != 0
extern statsManager * group2[GROUP2];
#endif
#if INCL_GROUP3 != 0
extern statsManager * group3[GROUP3];
#endif
#if INCL_GROUP4 != 0
extern statsManager * group4[GROUP4];
#endif
#if INCL_GROUP5 != 0
extern statsManager * group5[GROUP5];
#endif
#if INCL_GROUP6 != 0
extern statsManager * group6[GROUP6];
#endif
#if INCL_GROUP7 != 0
extern statsManager * group7[GROUP7];
#endif
#if INCL_GROUP8 != 0
extern statsManager * group8[GROUP8];
#endif
#if INCL_GROUP9 != 0
extern statsManager * group9[GROUP9];
#endif
StatsManager.cpp
#include "StatsManager.h"
#if INCL_PLAYER != 0
statsManager * player;
#endif
#if INCL_MP != 0
statsManager * mPlayer[PLAYER_MP];
#endif
#if INCL_GROUP0 != 0
statsManager * group0[GROUP0];
#endif
#if INCL_GROUP1 != 0
statsManager * group1[GROUP1];
#endif
#if INCL_GROUP2 != 0
statsManager * group2[GROUP2];
#endif
#if INCL_GROUP3 != 0
statsManager * group3[GROUP3];
#endif
#if INCL_GROUP4 != 0
statsManager * group4[GROUP4];
#endif
#if INCL_GROUP5 != 0
statsManager * group5[GROUP5];
#endif
#if INCL_GROUP6 != 0
statsManager * group6[GROUP6];
#endif
#if INCL_GROUP7 != 0
statsManager * group7[GROUP7];
#endif
#if INCL_GROUP8 != 0
statsManager * group8[GROUP8];
#endif
#if INCL_GROUP9 != 0
statsManager * group9[GROUP9];
#endif
CMI.h
/*==== CharacterManager Interface ======================================================*\
| |
| This file contains all definitions needed to customize the CharacterManager. |
| |
\*======================================================================================*/
// Changing the following definitions to false (0) will exclude the entity grouping (useful for saving memory)
#define INCL_PLAYER 1 // The player group is included by default
#define INCL_MPLAYER 0 // The multiplayer group is excluded by default
#define INCL_GROUP0 1
#define INCL_GROUP1 1
#define INCL_GROUP2 1
#define INCL_GROUP3 0
#define INCL_GROUP4 0
#define INCL_GROUP5 0
#define INCL_GROUP6 0
#define INCL_GROUP7 0
#define INCL_GROUP8 0
#define INCL_GROUP9 0
// Defines the maximum number of entities in each catagory. If a group is excluded its size does not matter
#define PLAYER_MP 5 // Number of players in a multi-player environment
#define GROUP0 100
#define GROUP1 100
#define GROUP2 100
#define GROUP3 100
#define GROUP4 100
#define GROUP5 100
#define GROUP6 100
#define GROUP7 100
#define GROUP8 100
#define GROUP9 100
// Parameters defining the size of the inventory system
#define BAG_SLOTS 3 // How many additional slots there are for bags
#define INVENTORY_SLOTS 20 // Defines how man inventory slots are available to a character
#define UTILITY_SLOTS 5 // Defines the number of slots for holding utility items
#define SMALL_BAG_SIZE 5 // Number of slots in a small bag
#define MEDIUM_BAG_SIZE 10 // Number of slots in a medium bag
#define LARGE_BAG_SIZE 15 // Number of slots in a medium bag
My code has a lot of excess definitions that even I am not using in my project, it's just nice to have the capability to use them for later projects.
Include "StatsManager.h" in your main project. You can than modify data like you would a variable, for example:
// This needs to be within a function or your main loop to work
player->maxHP = 100;
group1[20]->Level = 10;
// etc
I would suggest writing a function that can set up your characters and player, etc. I haven't gotten around to doing this yet.
------------------------------------
Currently 1500+ lines of code into an "over-the-shoulder" action RPG with combat based on rag-doll physics.