2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 #include "Level/Campaign.hpp"
24 #include "Utils/Folders.hpp"
30 std::vector<CampaignLevel> campaignlevels;
32 bool campaign = false;
36 std::vector<std::string> ListCampaigns()
39 DIR* campaigns = opendir(Folders::getResourcePath("Campaigns").c_str());
40 struct dirent* campaign = NULL;
42 perror(("Problem while loading campaigns from " + Folders::getResourcePath("Campaigns")).c_str());
45 std::vector<std::string> campaignNames;
46 while ((campaign = readdir(campaigns)) != NULL) {
47 std::string name(campaign->d_name);
48 if (name.length() < 5) {
51 if (!name.compare(name.length() - 4, 4, ".txt")) {
52 campaignNames.push_back(name.substr(0, name.length() - 4));
61 if (!Account::hasActive()) {
64 std::ifstream ipstream(Folders::getResourcePath("Campaigns/" + Account::active().getCurrentCampaign() + ".txt"));
65 if (!ipstream.good()) {
66 if (Account::active().getCurrentCampaign() == "main") {
67 cerr << "Could not found main campaign!" << endl;
70 cerr << "Could not found campaign \"" << Account::active().getCurrentCampaign() << "\", falling back to main." << endl;
71 Account::active().setCurrentCampaign("main");
72 return LoadCampaign();
74 ipstream.ignore(256, ':');
76 ipstream >> numlevels;
77 campaignlevels.clear();
78 for (int i = 0; i < numlevels; i++) {
81 campaignlevels.push_back(cl);
85 std::ifstream test(Folders::getResourcePath("Textures/" + Account::active().getCurrentCampaign() + "/World.png"));
87 Mainmenuitems[7].load("Textures/" + Account::active().getCurrentCampaign() + "/World.png", 0);
89 Mainmenuitems[7].load("Textures/World.png", 0);
92 if (Account::active().getCampaignChoicesMade() == 0) {
93 Account::active().setCampaignScore(0);
94 Account::active().resetFasttime();
98 CampaignLevel::CampaignLevel()
106 int CampaignLevel::getStartX()
108 return 30 + 120 + location.x * 400 / 512;
111 int CampaignLevel::getStartY()
113 return 30 + 30 + (512 - location.y) * 400 / 512;
116 int CampaignLevel::getEndX()
118 return getStartX() + width;
121 int CampaignLevel::getEndY()
123 return getStartY() + width;
126 XYZ CampaignLevel::getCenter()
129 center.x = getStartX() + width / 2;
130 center.y = getStartY() + width / 2;
134 int CampaignLevel::getWidth()
139 istream& CampaignLevel::operator<<(istream& is)
147 for (size_t pos = description.find('_'); pos != string::npos; pos = description.find('_', pos)) {
148 description.replace(pos, 1, 1, ' ');
155 for (int j = 0; j < numnext; j++) {
158 nextlevel.push_back(next - 1);