X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FLevel%2FCampaign.cpp;h=02072d0137d101338dd3f0e8b908156e9c14ae6c;hb=72217fbefd03881048287da8345925e1b89b5b9b;hp=2aa5f176a8af91d8f3f8ab5665d9afa3f785f12d;hpb=b84825978803615f45a9f128232e62431042aec0;p=lugaru.git diff --git a/Source/Level/Campaign.cpp b/Source/Level/Campaign.cpp index 2aa5f17..02072d0 100644 --- a/Source/Level/Campaign.cpp +++ b/Source/Level/Campaign.cpp @@ -18,9 +18,10 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Level/Campaign.h" -#include "Utils/Folders.h" +#include "Level/Campaign.hpp" + +#include "Game.hpp" +#include "Utils/Folders.hpp" #include @@ -31,12 +32,13 @@ std::vector campaignlevels; bool campaign = false; int actuallevel = 0; +std::string campaignEndText[3]; std::vector ListCampaigns() { errno = 0; - DIR *campaigns = opendir(Folders::getResourcePath("Campaigns").c_str()); - struct dirent *campaign = NULL; + DIR* campaigns = opendir(Folders::getResourcePath("Campaigns").c_str()); + struct dirent* campaign = NULL; if (!campaigns) { perror(("Problem while loading campaigns from " + Folders::getResourcePath("Campaigns")).c_str()); exit(EXIT_FAILURE); @@ -44,8 +46,9 @@ std::vector ListCampaigns() std::vector campaignNames; while ((campaign = readdir(campaigns)) != NULL) { std::string name(campaign->d_name); - if (name.length() < 5) + if (name.length() < 5) { continue; + } if (!name.compare(name.length() - 4, 4, ".txt")) { campaignNames.push_back(name.substr(0, name.length() - 4)); } @@ -62,10 +65,10 @@ void LoadCampaign() std::ifstream ipstream(Folders::getResourcePath("Campaigns/" + Account::active().getCurrentCampaign() + ".txt")); if (!ipstream.good()) { if (Account::active().getCurrentCampaign() == "main") { - cerr << "Could not found main campaign!" << endl; + cerr << "Could not find main campaign!" << endl; return; } - cerr << "Could not found campaign \"" << Account::active().getCurrentCampaign() << "\", falling back to main." << endl; + cerr << "Could not find campaign \"" << Account::active().getCurrentCampaign() << "\", falling back to main." << endl; Account::active().setCurrentCampaign("main"); return LoadCampaign(); } @@ -78,6 +81,15 @@ void LoadCampaign() ipstream >> cl; campaignlevels.push_back(cl); } + campaignEndText[0] = "Congratulations!"; + campaignEndText[1] = string("You have completed ") + Account::active().getCurrentCampaign() + " campaign"; + campaignEndText[2] = "and restored peace to the island of Lugaru."; + if (ipstream.good()) { + ipstream.ignore(256, ':'); + getline(ipstream, campaignEndText[0]); + getline(ipstream, campaignEndText[1]); + getline(ipstream, campaignEndText[2]); + } ipstream.close(); std::ifstream test(Folders::getResourcePath("Textures/" + Account::active().getCurrentCampaign() + "/World.png")); @@ -93,42 +105,49 @@ void LoadCampaign() } } -CampaignLevel::CampaignLevel() : - width(10), - choosenext(1) +CampaignLevel::CampaignLevel() + : width(10) + , choosenext(1) { location.x = 0; location.y = 0; } -int CampaignLevel::getStartX() { +int CampaignLevel::getStartX() +{ return 30 + 120 + location.x * 400 / 512; } -int CampaignLevel::getStartY() { +int CampaignLevel::getStartY() +{ return 30 + 30 + (512 - location.y) * 400 / 512; } -int CampaignLevel::getEndX() { +int CampaignLevel::getEndX() +{ return getStartX() + width; } -int CampaignLevel::getEndY() { +int CampaignLevel::getEndY() +{ return getStartY() + width; } -XYZ CampaignLevel::getCenter() { +XYZ CampaignLevel::getCenter() +{ XYZ center; center.x = getStartX() + width / 2; center.y = getStartY() + width / 2; return center; } -int CampaignLevel::getWidth() { +int CampaignLevel::getWidth() +{ return width; } -istream& CampaignLevel::operator<< (istream& is) { +istream& CampaignLevel::operator<<(istream& is) +{ is.ignore(256, ':'); is.ignore(256, ':'); is.ignore(256, ' ');