1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
int load()
{
int loadinv = 0;
int loadwep = 0;
int loadchk = 0;
string invamt;
string goldt;
string str1;
string dex1;
string con1;
string Int1;
string wis1;
string cha1;
string temp;
string health;
string armorclass;
string attk;
int loadarmr = 0;
int loadmisc = 0;
ifstream myfile ("savefile.nae");
if(myfile.is_open())
{
getline(myfile,Cstats.name);
getline(myfile,Cstats.Class);
getline(myfile,Cstats.race);
getline(myfile,str1);
stringstream convert(str1);
convert >> str;
getline(myfile,dex1);
stringstream convert1(dex1);
convert1 >> dex;
getline(myfile,con1);
stringstream convert2(con1);
convert2 >> con;
getline(myfile,Int1);
stringstream convert3(Int1);
convert3 >> Int;
getline(myfile,wis1);
stringstream convert4(wis1);
convert4 >> wis;
getline(myfile,cha1);
stringstream convert5(cha1);
convert5 >> cha;
getline(myfile,armorclass);
stringstream convert7(armorclass);
convert7 >> inventory[0].ArmorClass;
getline(myfile,attk);
stringstream convert8(attk);
convert8 >> Cstats.BaseAttk;
getline(myfile,health);
stringstream convert9(health);
convert9 >> Cstats.Health;
while(loadinv!=1)
{ // Loads weapons
while(loadchk!=1)
{
getline(myfile,temp);
if(temp=="")
{
loadchk = 1;
}
else
{
bool weapon=false;
if(weapon==false)
{
Cstats.currentweapon = temp;
weapon=true;
}
inventory[loadwep].weapon = temp;
getline(myfile,invamt);
stringstream convert(invamt);
convert >> inventory[loadwep].invamt;
getline(myfile,inventory[loadwep].invno);
loadwep++;
}
}
loadchk = 0;
// Loads armor
while(loadchk!=1)
{
getline(myfile,temp);
if(temp=="")
{
loadchk = 1;
}
else
{
inventory[loadarmr].armor = temp;
getline(myfile,invamt);
stringstream convert(invamt);
convert >> inventory[loadarmr].invamt;
getline(myfile,inventory[loadarmr].invno);
loadarmr++;
}
}
loadchk = 0;
// Loads Misc. Items
while(loadchk!=1)
{
getline(myfile,temp);
if(temp=="")
{
loadchk = 1;
}
else
{
inventory[loadmisc].miscitems = temp;
getline(myfile,invamt);
stringstream convert19(invamt);
convert19 >> inventory[loadmisc].invamt;
getline(myfile,inventory[loadmisc].invno);
loadmisc++;
}
}
loadinv = 1;
}
getline(myfile,goldt);
stringstream convert6(goldt);
convert6 >> Cstats.gold;
getline(myfile,Cstats.progress);
getline(myfile,Cstats.currentweapon);
getline(myfile,Cstats.currentarmor);
string slvl;
string sExp;
string sreq;
string smheal;
string smp;
string smmp;
getline(myfile,slvl);
stringstream convert12(slvl);
convert12 >> Cstats.clevel;
getline(myfile,sExp);
stringstream convert13(sExp);
convert13 >> Cstats.Exp;
getline(myfile,sreq);
stringstream convert14(sreq);
convert14 >> reqxp;
getline(myfile,smheal);
stringstream convert15(smheal);
convert15 >> Cstats.MaxHealth;
getline(myfile,smmp);
stringstream convert16(smmp);
convert16 >> Cstats.MaxMp;
getline(myfile,smp);
stringstream convert17(smp);
convert17 >> Cstats.Mp;
myfile.close();
cout << "File loaded successfully." << endl;
gamemenu();
system("pause");
}
else
{
cout << "Error: File either damaged, or does not exist. Returning to main menu." << endl;
Sleep(2000);
system("cls");
main();
}
return 0;
}
|