MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / evaluateChallengeProgress

Method evaluateChallengeProgress

src/OpenLoco/src/World/Company.cpp:176–222  ·  view source on GitHub ↗

Split off from updateDailyPlayer

Source from the content-addressed store, hash-verified

174
175 // Split off from updateDailyPlayer
176 void Company::evaluateChallengeProgress()
177 {
178 if (challengeProgress == 100)
179 {
180 challengeFlags |= CompanyFlags::challengeCompleted;
181 if (CompanyManager::getControllingId() == id())
182 {
183 if (CompanyManager::getSecondaryPlayerId() != CompanyId::null)
184 {
185 auto* secondaryPlayer = CompanyManager::get(CompanyManager::getSecondaryPlayerId());
186 secondaryPlayer->challengeFlags |= CompanyFlags::challengeBeatenByOpponent;
187 Ui::WindowManager::invalidate(Ui::WindowType::company, enumValue(secondaryPlayer->id()));
188 }
189 MessageManager::post(MessageType::congratulationsCompleted, id(), enumValue(id()), 0xFFFF);
190 companyEmotionEvent(id(), Emotion::happy);
191 updateOwnerEmotion();
192 Ui::Windows::CompanyWindow::openChallenge(id());
193 Scenario::getObjectiveProgress().completedChallengeInMonths = Scenario::getObjectiveProgress().monthsInChallenge;
194 ScenarioManager::saveNewScore(Scenario::getObjectiveProgress(), id());
195 }
196 else
197 {
198 if (CompanyManager::getControllingId() != CompanyId::null)
199 {
200 auto* secondaryPlayer = CompanyManager::get(CompanyManager::getControllingId());
201 secondaryPlayer->challengeFlags |= CompanyFlags::challengeBeatenByOpponent;
202 Ui::WindowManager::invalidate(Ui::WindowType::company, enumValue(secondaryPlayer->id()));
203 }
204 MessageManager::post(MessageType::haveBeenBeaten, id(), enumValue(id()), 0xFFFF);
205 companyEmotionEvent(id(), Emotion::surprised);
206 updateOwnerEmotion();
207 Ui::Windows::CompanyWindow::openChallenge(id());
208 Scenario::getObjectiveProgress().completedChallengeInMonths = Scenario::getObjectiveProgress().monthsInChallenge;
209 }
210 }
211 else if (challengeProgress == 255)
212 {
213 challengeFlags |= CompanyFlags::challengeFailed;
214 if (CompanyManager::getControllingId() == id())
215 {
216 MessageManager::post(MessageType::failedObjectives, id(), enumValue(id()), 0xFFFF);
217 companyEmotionEvent(id(), Emotion::dejected);
218 updateOwnerEmotion();
219 Ui::Windows::CompanyWindow::openChallenge(id());
220 }
221 }
222 }
223
224 // Converts performance index to rating
225 // 0x00437D60

Callers 1

completeChallengeFunction · 0.80

Calls 10

getControllingIdFunction · 0.85
getSecondaryPlayerIdFunction · 0.85
enumValueFunction · 0.85
postFunction · 0.85
companyEmotionEventFunction · 0.85
openChallengeFunction · 0.85
saveNewScoreFunction · 0.85
getFunction · 0.70
invalidateFunction · 0.50
idMethod · 0.45

Tested by

no test coverage detected