Code:
void CLoadLevel::LoadLevel(std::string filename)
{
/*Temeporay storage vector for reading in character arrays form a binary file*/
std::vector<char>temp(0);
/*Local variables for reading in int data from a binary file*/
char ch;
int namelength;
int strength;
int dexterity;
int intelligence;
int endurance;
int hp;
int maxhp;
int mp;
int maxmp;
int gold;
int xp;
int weaponname;
int mindamage;
int maxdamage;
int accuracy;
int price;
int armorname;
int ap;
std::ifstream in(filename.c_str(), std::ios::binary);
in.read((char*)&enemycount, sizeof(int));
for(int count = 0; count < enemycount; count++)
{
in.read((char*)&namelength, sizeof(int));
for(int x = 0; x < namelength; x++)
{
in.get(ch);
temp.push_back(ch);
}
std::string name(temp.begin(), temp.end());
temp.clear();
in.read((char*)&strength, sizeof(int));
in.read((char*)&dexterity, sizeof(int));
in.read((char*)&intelligence, sizeof(int));
in.read((char*)&endurance, sizeof(int));
in.read((char*)&hp, sizeof(int));
in.read((char*)&maxhp, sizeof(int));
in.read((char*)&mp, sizeof(int));
in.read((char*)&maxmp, sizeof(int));
in.read((char*)&gold, sizeof(int));
in.read((char*)&xp, sizeof(int));
in.read((char*)&namelength, sizeof(int));
for(int x = 0; x < namelength; x++)
{
in.get(ch);
temp.push_back(ch);
}
std::string weaponname(temp.begin(), temp.end());
temp.clear();
in.read((char*)&mindamage, sizeof(int));
in.read((char*)&maxdamage, sizeof(int));
in.read((char*)&accuracy, sizeof(int));
/*Read in the number of characters in armorname*/
in.read((char*)&namelength, sizeof(int));
/*Now read in armorname*/
for(int x = 0; x < namelength; x++)
{
in.get(ch);
temp.push_back(ch);
}
std::string armorname(temp.begin(), temp.end());
temp.clear();
in.read((char*)&ap, sizeof(int));
CEnemy enemylist;
enemylist.CreateEnemy(name, strength, endurance, dexterity, intelligence, hp, maxhp, mp,
maxmp, xp, gold, weaponname, mindamage, maxdamage, accuracy, armorname, ap);
enemy.push_back(enemylist);
}
in.read((char*)&weaponcount, sizeof(int));
for (int count = 0; count < weaponcount; count++)
{
in.read((char*)&namelength, sizeof(int));
for(int x = 0; x < namelength; x++)
{
in.get(ch);
temp.push_back(ch);
}
std::string newname(temp.begin(), temp.end());
temp.clear();
in.read((char*)&mindamage, sizeof(int));
in.read((char*)&maxdamage, sizeof(int));
in.read((char*)&accuracy, sizeof(int));
in.read((char*)&price, sizeof(int));
CWeapon weaponlist;
weaponlist.CreateWeapon(newname, mindamage, maxdamage, accuracy, price);
weapon.push_back(weaponlist);
}
in.close();
};
It now works perfectly...as far as I can tell...unfortunately I will probably be overhauling it agian soon.