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));
60 std::ifstream ipstream(Folders::getResourcePath("Campaigns/" + accountactive->getCurrentCampaign() + ".txt"));
61 if (!ipstream.good()) {
62 if (accountactive->getCurrentCampaign() == "main") {
63 cerr << "Could not found main campaign!" << endl;
66 cerr << "Could not found campaign \"" << accountactive->getCurrentCampaign() << "\", falling back to main." << endl;
67 accountactive->setCurrentCampaign("main");
68 return LoadCampaign();
70 ipstream.ignore(256, ':');
72 ipstream >> numlevels;
73 campaignlevels.clear();
74 for (int i = 0; i < numlevels; i++) {
77 campaignlevels.push_back(cl);
81 std::ifstream test(Folders::getResourcePath("Textures/" + accountactive->getCurrentCampaign() + "/World.png"));
83 Mainmenuitems[7].load("Textures/" + accountactive->getCurrentCampaign() + "/World.png", 0);
85 Mainmenuitems[7].load("Textures/World.png", 0);
88 if (accountactive->getCampaignChoicesMade() == 0) {
89 accountactive->setCampaignScore(0);
90 accountactive->resetFasttime();
94 CampaignLevel::CampaignLevel() :
102 int CampaignLevel::getStartX() {
103 return 30 + 120 + location.x * 400 / 512;
106 int CampaignLevel::getStartY() {
107 return 30 + 30 + (512 - location.y) * 400 / 512;
110 int CampaignLevel::getEndX() {
111 return getStartX() + width;
114 int CampaignLevel::getEndY() {
115 return getStartY() + width;
118 XYZ CampaignLevel::getCenter() {
120 center.x = getStartX() + width / 2;
121 center.y = getStartY() + width / 2;
125 int CampaignLevel::getWidth() {
129 istream& CampaignLevel::operator<< (istream& is) {
136 for (size_t pos = description.find('_'); pos != string::npos; pos = description.find('_', pos)) {
137 description.replace(pos, 1, 1, ' ');
144 for (int j = 0; j < numnext; j++) {
147 nextlevel.push_back(next - 1);