MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / LoadCampaign

Method LoadCampaign

Source/Campaign.cpp:163–234  ·  view source on GitHub ↗

* Load a campaign */

Source from the content-addressed store, hash-verified

161 * Load a campaign
162 */
163bool cCampaign::LoadCampaign(const std::string& pName, bool pCustom, bool pDirectPath) {
164
165 if (!pName.size())
166 return false;
167
168 Clear();
169 mName = pName;
170 mPath = pName;
171 mUseCustomPath = pDirectPath;
172
173 if (mUseCustomPath) {
174 auto Final = pName.find_last_of(gPathSeperator);
175
176 mName = pName.substr(0, Final);
177 }
178
179 std::ifstream MissionSetFile(GetPathToCampaign());
180 if (MissionSetFile.is_open()) {
181 Json MissionSet = Json::parse(MissionSetFile);
182
183 mAuthor = MissionSet["Author"];
184 mName = MissionSet["Name"];
185
186 mIsCustomCampaign = pCustom;
187
188 // Loop through the missions in this set
189 for (auto& Mission : MissionSet["Missions"]) {
190 std::shared_ptr<cMission> newMission = std::make_shared<cMission>();
191 mMissions.push_back(newMission);
192
193 newMission->mName = Mission["Name"];
194
195 // Each Map (Phase)
196 for (auto& Phase : Mission["Phases"]) {
197 std::shared_ptr<cPhase> newPhase = std::make_shared<cPhase>();
198 newMission->mPhases.push_back(newPhase);
199
200 newPhase->mName = Phase["Name"];
201 newPhase->mMapFilename = Phase["MapName"];
202 if (Phase["Aggression"].size()) {
203 newPhase->mAggression.mMin = Phase["Aggression"][0];
204 newPhase->mAggression.mMax = Phase["Aggression"][1];
205 }
206
207 if(Phase["Grenades"].size())
208 newPhase->mGrenades = Phase["Grenades"];
209
210 if(Phase["Rockets"].size())
211 newPhase->mRockets = Phase["Rockets"];
212
213
214 // Each map goal
215 for (std::string ObjectiveName : Phase["Objectives"]) {
216 transform(ObjectiveName.begin(), ObjectiveName.end(), ObjectiveName.begin(), toupper);
217
218 // Check each goal
219 int x = 0;
220 for (const std::string& GoalTitle : mMissionGoal_Titles) {

Callers 3

menu_loopFunction · 0.80
Campaign_LoadMethod · 0.80
quickServiceScreenFunction · 0.80

Calls 5

parseFunction · 0.85
sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected