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/>.
23 #include "Utils/Folders.h"
28 std::vector<CampaignLevel> campaignlevels;
30 bool campaign = false;
34 std::vector<std::string> ListCampaigns()
37 DIR *campaigns = opendir(Folders::getResourcePath("Campaigns").c_str());
38 struct dirent *campaign = NULL;
40 perror(("Problem while loading campaigns from " + Folders::getResourcePath("Campaigns")).c_str());
43 std::vector<std::string> campaignNames;
44 while ((campaign = readdir(campaigns)) != NULL) {
45 std::string name(campaign->d_name);
46 if (name.length() < 5)
48 if (!name.compare(name.length() - 4, 4, ".txt")) {
49 campaignNames.push_back(name.substr(0, name.length() - 4));
58 if (!Account::hasActive()) {
61 std::ifstream ipstream(Folders::getResourcePath("Campaigns/" + Account::active().getCurrentCampaign() + ".txt"));
62 if (!ipstream.good()) {
63 if (Account::active().getCurrentCampaign() == "main") {
64 cerr << "Could not found main campaign!" << endl;
67 cerr << "Could not found campaign \"" << Account::active().getCurrentCampaign() << "\", falling back to main." << endl;
68 Account::active().setCurrentCampaign("main");
69 return LoadCampaign();
71 ipstream.ignore(256, ':');
73 ipstream >> numlevels;
74 campaignlevels.clear();
75 for (int i = 0; i < numlevels; i++) {
78 campaignlevels.push_back(cl);
82 std::ifstream test(Folders::getResourcePath("Textures/" + Account::active().getCurrentCampaign() + "/World.png"));
84 Mainmenuitems[7].load("Textures/" + Account::active().getCurrentCampaign() + "/World.png", 0);
86 Mainmenuitems[7].load("Textures/World.png", 0);
89 if (Account::active().getCampaignChoicesMade() == 0) {
90 Account::active().setCampaignScore(0);
91 Account::active().resetFasttime();
95 CampaignLevel::CampaignLevel() :
103 int CampaignLevel::getStartX() {
104 return 30 + 120 + location.x * 400 / 512;
107 int CampaignLevel::getStartY() {
108 return 30 + 30 + (512 - location.y) * 400 / 512;
111 int CampaignLevel::getEndX() {
112 return getStartX() + width;
115 int CampaignLevel::getEndY() {
116 return getStartY() + width;
119 XYZ CampaignLevel::getCenter() {
121 center.x = getStartX() + width / 2;
122 center.y = getStartY() + width / 2;
126 int CampaignLevel::getWidth() {
130 istream& CampaignLevel::operator<< (istream& is) {
137 for (size_t pos = description.find('_'); pos != string::npos; pos = description.find('_', pos)) {
138 description.replace(pos, 1, 1, ' ');
145 for (int j = 0; j < numnext; j++) {
148 nextlevel.push_back(next - 1);