1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/*
Copyright (C) 2003, 2010 - Wolfire Games
Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
This file is part of Lugaru.
Lugaru is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Lugaru is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Level/Campaign.hpp"
#include "Game.hpp"
#include "Utils/Folders.hpp"
#include <dirent.h>
using namespace Game;
std::vector<CampaignLevel> campaignlevels;
bool campaign = false;
int actuallevel = 0;
std::string campaignEndText[3];
std::vector<std::string> ListCampaigns()
{
errno = 0;
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);
}
std::vector<std::string> campaignNames;
while ((campaign = readdir(campaigns)) != NULL) {
std::string name(campaign->d_name);
if (name.length() < 5) {
continue;
}
if (!name.compare(name.length() - 4, 4, ".txt")) {
campaignNames.push_back(name.substr(0, name.length() - 4));
}
}
closedir(campaigns);
return campaignNames;
}
void LoadCampaign()
{
if (!Account::hasActive()) {
return;
}
std::ifstream ipstream(Folders::getResourcePath("Campaigns/" + Account::active().getCurrentCampaign() + ".txt"));
if (!ipstream.good()) {
if (Account::active().getCurrentCampaign() == "main") {
cerr << "Could not find main campaign!" << endl;
return;
}
cerr << "Could not find campaign \"" << Account::active().getCurrentCampaign() << "\", falling back to main." << endl;
Account::active().setCurrentCampaign("main");
return LoadCampaign();
}
ipstream.ignore(256, ':');
int numlevels;
ipstream >> numlevels;
campaignlevels.clear();
for (int i = 0; i < numlevels; i++) {
CampaignLevel cl;
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"));
if (test.good()) {
Mainmenuitems[7].load("Textures/" + Account::active().getCurrentCampaign() + "/World.png", 0);
} else {
Mainmenuitems[7].load("Textures/World.png", 0);
}
if (Account::active().getCampaignChoicesMade() == 0) {
Account::active().setCampaignScore(0);
Account::active().resetFasttime();
}
}
CampaignLevel::CampaignLevel()
: width(10)
, choosenext(1)
{
location.x = 0;
location.y = 0;
}
int CampaignLevel::getStartX()
{
return 30 + 120 + location.x * 400 / 512;
}
int CampaignLevel::getStartY()
{
return 30 + 30 + (512 - location.y) * 400 / 512;
}
int CampaignLevel::getEndX()
{
return getStartX() + width;
}
int CampaignLevel::getEndY()
{
return getStartY() + width;
}
XYZ CampaignLevel::getCenter()
{
XYZ center;
center.x = getStartX() + width / 2;
center.y = getStartY() + width / 2;
return center;
}
int CampaignLevel::getWidth()
{
return width;
}
istream& CampaignLevel::operator<<(istream& is)
{
is.ignore(256, ':');
is.ignore(256, ':');
is.ignore(256, ' ');
is >> mapname;
is.ignore(256, ':');
is >> description;
for (size_t pos = description.find('_'); pos != string::npos; pos = description.find('_', pos)) {
description.replace(pos, 1, 1, ' ');
}
is.ignore(256, ':');
is >> choosenext;
is.ignore(256, ':');
int numnext, next;
is >> numnext;
for (int j = 0; j < numnext; j++) {
is.ignore(256, ':');
is >> next;
nextlevel.push_back(next - 1);
}
is.ignore(256, ':');
is >> location.x;
is.ignore(256, ':');
is >> location.y;
return is;
}
|