-Account* Account::loadFile(string filename) {
- FILE *tfile;
- int numaccounts;
- int accountactive;
-
- tfile=fopen(ConvertFileName(filename.c_str()), "rb" );
-
- if(tfile)
- {
- funpackf(tfile, "Bi", &numaccounts);
- funpackf(tfile, "Bi", &accountactive);
- printf("number of accounts %d\n",numaccounts);
- for(int i=0;i<numaccounts;i++)
- {
- printf("loading account %d/%d\n",i,numaccounts);
- Account* acc = new Account();
- funpackf(tfile, "Bi", &(acc->difficulty));
- funpackf(tfile, "Bi", &(acc->progress));
- int nbCampaigns;
- funpackf(tfile, "Bi", &nbCampaigns);
- printf("loading %d campaign progress info\n",nbCampaigns);
-
- for(int k=0;k<nbCampaigns;++k) {
- string campaignName = "";
- int t;
- char c;
- funpackf(tfile, "Bi", &t);
- for(int j=0;j<t;j++)
- {
- funpackf(tfile, "Bb", &c);
- campaignName.append(1,c);
- }
- printf("loading %s campaign progress info\n",campaignName.c_str());
- funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].time));
- funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].score));
- funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].fasttime));
- funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].highscore));
- int campaignchoicesmade,campaignchoice;
- funpackf(tfile, "Bi", &campaignchoicesmade);
- for(int j=0;j<campaignchoicesmade;j++)
- {
- funpackf(tfile, "Bi", &campaignchoice);
- if (campaignchoice >= 10) // what is that for?
- {
- campaignchoice = 0;
- }
- acc->campaignProgress[campaignName].choices.push_back(campaignchoice);
- }
- }
-
- acc->currentCampaign = "";
- int t;
- char c;
- funpackf(tfile, "Bi", &t);
- for(int i=0;i<t;i++)
- {
- funpackf(tfile, "Bb", &c);
- acc->currentCampaign.append(1,c);
- }
-
- funpackf(tfile, "Bf", &(acc->points));
- for(int i=0;i<50;i++)
- {
- funpackf(tfile, "Bf", &(acc->highscore[i]));
- funpackf(tfile, "Bf", &(acc->fasttime[i]));
- }
- for(int i=0;i<60;i++)
- {
- funpackf(tfile, "Bb", &(acc->unlocked[i]));
- }
- int temp;
- char ctemp;
- funpackf(tfile, "Bi", &temp);
- for(int i=0;i<temp;i++)
- {
- funpackf(tfile, "Bb", &ctemp);
- acc->name.append(1,ctemp);
- }
- if(!strcmp(acc->name.c_str(),""))
- acc->name="Lugaru Player"; // no empty player name security.
- accounts.push_back(acc);
- }
-
- fclose(tfile);
- return get(accountactive);
- } else {
- printf("filenotfound\n");
- return NULL;
- }
+Account* Account::loadFile(string filename)
+{
+ FILE *tfile;
+ int numaccounts;
+ int accountactive;
+
+ tfile = fopen(ConvertFileName(filename.c_str()), "rb" );
+
+ if (tfile) {
+ funpackf(tfile, "Bi", &numaccounts);
+ funpackf(tfile, "Bi", &accountactive);
+ printf("number of accounts %d\n", numaccounts);
+ for (int i = 0; i < numaccounts; i++) {
+ printf("loading account %d/%d\n", i, numaccounts);
+ Account* acc = new Account();
+ funpackf(tfile, "Bi", &(acc->difficulty));
+ funpackf(tfile, "Bi", &(acc->progress));
+ int nbCampaigns;
+ funpackf(tfile, "Bi", &nbCampaigns);
+ //~ printf("loading %d campaign progress info\n",nbCampaigns);
+
+ for (int k = 0; k < nbCampaigns; ++k) {
+ string campaignName = "";
+ int t;
+ char c;
+ funpackf(tfile, "Bi", &t);
+ for (int j = 0; j < t; j++) {
+ funpackf(tfile, "Bb", &c);
+ campaignName.append(1, c);
+ }
+ //~ printf("loading %s campaign progress info\n",campaignName.c_str());
+ funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].time));
+ funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].score));
+ funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].fasttime));
+ funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].highscore));
+ int campaignchoicesmade, campaignchoice;
+ funpackf(tfile, "Bi", &campaignchoicesmade);
+ for (int j = 0; j < campaignchoicesmade; j++) {
+ funpackf(tfile, "Bi", &campaignchoice);
+ if (campaignchoice >= 10) { // what is that for?
+ campaignchoice = 0;
+ }
+ acc->campaignProgress[campaignName].choices.push_back(campaignchoice);
+ }
+ }
+
+ acc->currentCampaign = "";
+ int t;
+ char c;
+ funpackf(tfile, "Bi", &t);
+ for (int i = 0; i < t; i++) {
+ funpackf(tfile, "Bb", &c);
+ acc->currentCampaign.append(1, c);
+ }
+
+ funpackf(tfile, "Bf", &(acc->points));
+ for (int i = 0; i < 50; i++) {
+ funpackf(tfile, "Bf", &(acc->highscore[i]));
+ funpackf(tfile, "Bf", &(acc->fasttime[i]));
+ }
+ for (int i = 0; i < 60; i++) {
+ funpackf(tfile, "Bb", &(acc->unlocked[i]));
+ }
+ int temp;
+ char ctemp;
+ funpackf(tfile, "Bi", &temp);
+ for (int i = 0; i < temp; i++) {
+ funpackf(tfile, "Bb", &ctemp);
+ acc->name.append(1, ctemp);
+ }
+ if (!strcmp(acc->name.c_str(), ""))
+ acc->name = "Lugaru Player"; // no empty player name security.
+ accounts.push_back(acc);
+ }
+
+ fclose(tfile);
+ return get(accountactive);
+ } else {
+ printf("filenotfound\n");
+ return NULL;
+ }