From: Côme Chilliet Date: Sun, 11 Dec 2016 09:21:48 +0000 (+0700) Subject: Stopped using Account pointers, and removed general difficulty setting (difficulty... X-Git-Url: https://git.jsancho.org/?p=lugaru.git;a=commitdiff_plain;h=bdabd9d4a53be2fa9d90f900f7e5949d2f0ef75c Stopped using Account pointers, and removed general difficulty setting (difficulty from account is always used) Was supposed to be two separate commits, sorry I forgot :-/ --- diff --git a/Source/Account.cpp b/Source/Account.cpp index 560592f..6a1d3bb 100644 --- a/Source/Account.cpp +++ b/Source/Account.cpp @@ -29,7 +29,7 @@ using namespace std; extern bool devtools; -vector Account::accounts = vector(); +vector Account::accounts; int Account::i_active = -1; Account::Account(const string& name) : name(name), campaignProgress() @@ -44,6 +44,107 @@ Account::Account(const string& name) : name(name), campaignProgress() setCurrentCampaign("main"); } +Account::Account(FILE* tfile) : Account("") +{ + funpackf(tfile, "Bi", &difficulty); + funpackf(tfile, "Bi", &progress); + int nbCampaigns; + funpackf(tfile, "Bi", &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); + } + funpackf(tfile, "Bf", &(campaignProgress[campaignName].time)); + funpackf(tfile, "Bf", &(campaignProgress[campaignName].score)); + funpackf(tfile, "Bf", &(campaignProgress[campaignName].fasttime)); + funpackf(tfile, "Bf", &(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; + } + campaignProgress[campaignName].choices.push_back(campaignchoice); + } + } + + currentCampaign = ""; + int t; + char c; + funpackf(tfile, "Bi", &t); + for (int i = 0; i < t; i++) { + funpackf(tfile, "Bb", &c); + currentCampaign.append(1, c); + } + + funpackf(tfile, "Bf", &points); + for (int i = 0; i < 50; i++) { + funpackf(tfile, "Bf", &(highscore[i])); + funpackf(tfile, "Bf", &(fasttime[i])); + } + for (int i = 0; i < 60; i++) { + funpackf(tfile, "Bb", &(unlocked[i])); + } + int temp; + char ctemp; + funpackf(tfile, "Bi", &temp); + for (int i = 0; i < temp; i++) { + funpackf(tfile, "Bb", &ctemp); + name.append(1, ctemp); + } + if (name.empty()) { + name = "Lugaru Player"; // no empty player name security. + } +} + +void Account::save(FILE* tfile) +{ + fpackf(tfile, "Bi", difficulty); + fpackf(tfile, "Bi", progress); + fpackf(tfile, "Bi", campaignProgress.size()); + + map::const_iterator it; + for (it = campaignProgress.begin(); it != campaignProgress.end(); ++it) { + fpackf(tfile, "Bi", it->first.size()); + for (unsigned j = 0; j < it->first.size(); j++) { + fpackf(tfile, "Bb", it->first[j]); + } + fpackf(tfile, "Bf", it->second.time); + fpackf(tfile, "Bf", it->second.score); + fpackf(tfile, "Bf", it->second.fasttime); + fpackf(tfile, "Bf", it->second.highscore); + fpackf(tfile, "Bi", it->second.choices.size()); + for (unsigned j = 0; j < it->second.choices.size(); j++) { + fpackf(tfile, "Bi", it->second.choices[j]); + } + } + + fpackf(tfile, "Bi", getCurrentCampaign().size()); + for (unsigned j = 0; j < getCurrentCampaign().size(); j++) { + fpackf(tfile, "Bb", getCurrentCampaign()[j]); + } + + fpackf(tfile, "Bf", points); + for (unsigned j = 0; j < 50; j++) { + fpackf(tfile, "Bf", highscore[j]); + fpackf(tfile, "Bf", fasttime[j]); + } + for (unsigned j = 0; j < 60; j++) { + fpackf(tfile, "Bb", unlocked[j]); + } + fpackf(tfile, "Bi", name.size()); + for (unsigned j = 0; j < name.size(); j++) { + fpackf(tfile, "Bb", name[j]); + } +} + void Account::setCurrentCampaign(const string& name) { currentCampaign = name; @@ -51,11 +152,11 @@ void Account::setCurrentCampaign(const string& name) void Account::add(const string& name) { - accounts.push_back(new Account(name)); + accounts.emplace_back(name); i_active = accounts.size() - 1; } -Account* Account::get(int i) +Account& Account::get(int i) { return accounts.at(i); } @@ -72,7 +173,7 @@ bool Account::hasActive() Account& Account::active() { - return *(accounts.at(i_active)); + return accounts.at(i_active); } void Account::setActive(int i) @@ -139,66 +240,10 @@ void Account::loadFile(string filename) if (tfile) { funpackf(tfile, "Bi", &numaccounts); funpackf(tfile, "Bi", &iactive); - printf("number of accounts %d\n", numaccounts); + printf("Loading %d accounts\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); - - 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); - } - 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); + printf("Loading account %d/%d\n", i, numaccounts); + accounts.emplace_back(tfile); } fclose(tfile); @@ -220,45 +265,8 @@ void Account::saveFile(string filename) fpackf(tfile, "Bi", i_active); for (int i = 0; i < getNbAccounts(); i++) { - Account* a = Account::get(i); - printf("writing account %d/%d (%s)\n", i + 1, getNbAccounts(), a->getName().c_str()); - fpackf(tfile, "Bi", a->difficulty); - fpackf(tfile, "Bi", a->progress); - fpackf(tfile, "Bi", a->campaignProgress.size()); - - map::const_iterator it; - for (it = a->campaignProgress.begin(); it != a->campaignProgress.end(); ++it) { - fpackf(tfile, "Bi", it->first.size()); - for (unsigned j = 0; j < it->first.size(); j++) { - fpackf(tfile, "Bb", it->first[j]); - } - fpackf(tfile, "Bf", it->second.time); - fpackf(tfile, "Bf", it->second.score); - fpackf(tfile, "Bf", it->second.fasttime); - fpackf(tfile, "Bf", it->second.highscore); - fpackf(tfile, "Bi", it->second.choices.size()); - for (unsigned j = 0; j < it->second.choices.size(); j++) { - fpackf(tfile, "Bi", it->second.choices[j]); - } - } - - fpackf(tfile, "Bi", a->getCurrentCampaign().size()); - for (unsigned j = 0; j < a->getCurrentCampaign().size(); j++) { - fpackf(tfile, "Bb", a->getCurrentCampaign()[j]); - } - - fpackf(tfile, "Bf", a->points); - for (unsigned j = 0; j < 50; j++) { - fpackf(tfile, "Bf", a->highscore[j]); - fpackf(tfile, "Bf", a->fasttime[j]); - } - for (unsigned j = 0; j < 60; j++) { - fpackf(tfile, "Bb", a->unlocked[j]); - } - fpackf(tfile, "Bi", a->name.size()); - for (unsigned j = 0; j < a->name.size(); j++) { - fpackf(tfile, "Bb", a->name[j]); - } + printf("writing account %d/%d (%s)\n", i + 1, getNbAccounts(), accounts[i].getName().c_str()); + accounts[i].save(tfile); } fclose(tfile); diff --git a/Source/Account.h b/Source/Account.h index dcaba95..385c6fa 100644 --- a/Source/Account.h +++ b/Source/Account.h @@ -46,7 +46,7 @@ public: static void destroyActive(); static void setActive(int i); static void add(const std::string& name); - static Account* get(int i); + static Account& get(int i); static void loadFile(std::string filename); static void saveFile(std::string filename); static int getNbAccounts(); @@ -54,6 +54,9 @@ public: static bool hasActive(); static Account& active(); + Account(const std::string& name = ""); + Account(FILE* tfile); + void endGame(); void winCampaignLevel(int choice, float score, float time); void winLevel(int level, float score, float time); @@ -110,10 +113,11 @@ public: private: //statics - static std::vector accounts; + static std::vector accounts; static int i_active; - Account(const std::string& name = ""); + void save(FILE* tfile); + int difficulty; int progress; // progress in challenge levels float points; diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index d1f7b9d..c070d29 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -57,7 +57,6 @@ extern float flashamount, flashr, flashg, flashb; extern int flashdelay; extern int whichjointstartarray[26]; extern int whichjointendarray[26]; -extern int difficulty; extern float slomospeed; extern bool gamestarted; diff --git a/Source/Menu.cpp b/Source/Menu.cpp index 14f54aa..f1fb94f 100644 --- a/Source/Menu.cpp +++ b/Source/Menu.cpp @@ -294,9 +294,6 @@ void Menu::updateSettingsMenu() if (bloodtoggle == 0) setText(2, "Blood: Off"); if (bloodtoggle == 1) setText(2, "Blood: On, low detail"); if (bloodtoggle == 2) setText(2, "Blood: On, high detail (slower)"); - if (difficulty == 0) setText(3, "Difficulty: Easier"); - if (difficulty == 1) setText(3, "Difficulty: Difficult"); - if (difficulty == 2) setText(3, "Difficulty: Insane"); setText(4, ismotionblur ? "Blur Effects: Enabled (less compatible)" : "Blur Effects: Disabled (more compatible)"); setText(5, decals ? "Decals: Enabled (slower)" : "Decals: Disabled"); setText(6, musictoggle ? "Music: Enabled" : "Music: Disabled"); @@ -366,7 +363,6 @@ void Menu::Load() addButton(14, "", 10 + 400, 440); addButton( 1, "", 10 + 60, 405); addButton( 2, "", 10 + 70, 370); - addButton( 3, "", 10 + 20 - 1000, 335 - 1000); addButton( 4, "", 10 , 335); addButton( 5, "", 10 + 60, 300); addButton( 6, "", 10 + 70, 265); @@ -447,7 +443,7 @@ void Menu::Load() addLabel(-2, "", 20, 400); addButton(Account::getNbAccounts() + 1, "Back", 10, 10); for (int i = 0; i < Account::getNbAccounts(); i++) { - addButton(i + 1, Account::get(i)->getName(), 10, 340 - 20 * (i + 1)); + addButton(i + 1, Account::get(i).getName(), 10, 340 - 20 * (i + 1)); } break; case 8: @@ -621,11 +617,6 @@ void Menu::Tick() if (bloodtoggle > 2) bloodtoggle = 0; break; - case 3: - difficulty++; - if (difficulty > 2) - difficulty = 0; - break; case 4: ismotionblur = !ismotionblur; break; diff --git a/Source/Person.cpp b/Source/Person.cpp index cada57b..fb3c445 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -1468,14 +1468,15 @@ void Person::Reverse() velocity = 0; victim->velocity = 0; - if (aitype != playercontrolled) + if (aitype != playercontrolled) { feint = 0; - if (aitype != playercontrolled && Random() % 3 == 0 && escapednum < 2 && difficulty == 2) - feint = 1; - if (aitype != playercontrolled && Random() % 5 == 0 && escapednum < 2 && difficulty == 1) - feint = 1; - if (aitype != playercontrolled && Random() % 10 == 0 && escapednum < 2 && difficulty == 0) - feint = 1; + if (escapednum < 2) { + int chances = ((difficulty == 2) ? 3 : ((difficulty == 1) ? 5 : 10)); + if ((Random() % chances) == 0) { + feint = 1; + } + } + } if (victim->id == 0 && Animation::animations[victim->animTarget].attack == reversal) numreversals++; diff --git a/Source/Settings.cpp b/Source/Settings.cpp index e962d0b..eca9efd 100644 --- a/Source/Settings.cpp +++ b/Source/Settings.cpp @@ -42,7 +42,6 @@ void DefaultSettings() musictoggle = 1; trilinear = 1; gamespeed = 1; - difficulty = 1; damageeffects = 0; texttoggle = 1; alwaysblur = 0; @@ -124,8 +123,6 @@ void SaveSettings() if (oldgamespeed == 0) oldgamespeed = 1; opstream << oldgamespeed; - opstream << "\nDifficulty(0,1,2) higher=harder:\n"; - opstream << difficulty; opstream << "\nDamage effects(blackout, doublevision):\n"; opstream << damageeffects; opstream << "\nText:\n"; @@ -239,8 +236,6 @@ bool LoadSettings() gamespeed = 1; oldgamespeed = 1; } - } else if ( !strncmp(setting, "Difficulty", 10) ) { - ipstream >> difficulty; } else if ( !strncmp(setting, "Damage effects", 14) ) { ipstream >> damageeffects; } else if ( !strncmp(setting, "Text", 4) ) { diff --git a/Source/Settings.h b/Source/Settings.h index ac14df3..e5f983a 100644 --- a/Source/Settings.h +++ b/Source/Settings.h @@ -37,7 +37,6 @@ extern bool decals; extern bool invertmouse; extern float gamespeed; extern float oldgamespeed; -extern int difficulty; extern bool damageeffects; extern bool texttoggle; extern bool devtools; diff --git a/Source/Weapons.cpp b/Source/Weapons.cpp index 35f73c2..bc610d7 100644 --- a/Source/Weapons.cpp +++ b/Source/Weapons.cpp @@ -48,7 +48,6 @@ extern float camerashake; extern float woozy; extern float viewdistance; extern float blackout; -extern int difficulty; extern bool freeze; extern int tutoriallevel; extern int numthrowkill; diff --git a/Source/main.cpp b/Source/main.cpp index 7fb4291..09a10cb 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -55,6 +55,8 @@ extern float slomospeed; extern float slomofreq; extern bool visibleloading; +extern int difficulty; + extern SDL_Window *sdlwindow; using namespace std;