2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "objectives.h"
24 void adjustObjectives()
26 bool needRequired = false;
28 Entity *mia = (Entity*)map.miaList.getHead();
30 while (mia->next != NULL)
32 mia = (Entity*)mia->next;
34 if (gameData.MIARescued(map.name, mia->name))
41 if (map.foundMIAs >= map.requiredMIAs)
43 map.requiredMIAs = map.totalMIAs;
49 map.requiredMIAs = map.totalMIAs;
56 Objective *objective = (Objective*)map.objectiveList.getHead();
58 bool previouslyCleared = gameData.stagePreviouslyCleared(map.name);
60 while (objective->next != NULL)
62 objective = (Objective*)objective->next;
66 objective->required = false;
71 objective->required = true;
76 objective->required = true;
79 if (previouslyCleared)
81 if (gameData.objectiveCompleted(map.name, objective->description))
83 objective->completed = true;
85 debug(("Objective %s has been completed\n", objective->description));
88 gameData.getObjectiveValues(map.name, objective->description, ¤t, &target);
89 objective->currentValue = current;
90 objective->targetValue = target;
92 // Make sure that gameplay adjustments are catered for...
93 if (!objective->completed)
95 Math::limitInt(&objective->currentValue, 0, objective->targetValue);
97 if (objective->currentValue == objective->targetValue)
99 objective->completed = true;
101 debug(("Objective %s has been completed (gameplay adjustment!)\n", objective->description));
108 bool allObjectivesCompleted()
110 if (map.foundMIAs < map.requiredMIAs)
113 Objective *objective = (Objective*)map.objectiveList.getHead();
115 while (objective->next != NULL)
117 objective = (Objective*)objective->next;
119 if ((objective->required) && (!objective->completed))
126 bool perfectlyCompleted()
128 if (map.foundMIAs < map.totalMIAs)
131 Objective *objective = (Objective*)map.objectiveList.getHead();
133 while (objective->next != NULL)
135 objective = (Objective*)objective->next;
137 if (!objective->completed)
144 bool requiredEnemy(const char *name)
146 Objective *objective = (Objective*)map.objectiveList.getHead();
148 while (objective->next != NULL)
150 objective = (Objective*)objective->next;
152 if (strcmp(objective->target, name) == 0)
161 bool requiredObjectivesCompleted()
163 if (map.foundMIAs < map.requiredMIAs)
168 Objective *objective = (Objective*)map.objectiveList.getHead();
170 while (objective->next != NULL)
172 objective = (Objective*)objective->next;
174 if (strcmp(objective->target, "Exit") == 0)
179 if ((objective->required) && (!objective->completed))
189 Used by the skip level cheat
191 void autoCompleteAllObjectives(bool allObjectives)
195 map.requiredMIAs = map.totalMIAs;
196 map.foundMIAs = map.totalMIAs;
200 map.foundMIAs = map.requiredMIAs;
203 map.foundItems = map.totalItems;
205 Objective *objective = (Objective*)map.objectiveList.getHead();
207 while (objective->next != NULL)
209 objective = (Objective*)objective->next;
213 objective->completed = true;
214 objective->currentValue = objective->targetValue;
218 if (objective->required)
220 objective->completed = true;
221 objective->currentValue = objective->targetValue;
226 int required = map.foundMIAs;
228 Entity *mia = (Entity*)map.miaList.getHead();
230 while (mia->next != NULL)
232 mia = (Entity*)mia->next;
241 void checkObjectives(const char *name, bool alwaysInform)
243 Objective *objective = (Objective*)map.objectiveList.getHead();
249 while (objective->next != NULL)
251 objective = (Objective*)objective->next;
253 if (!objective->completed)
255 if (strcmp(objective->target, name) == 0)
257 if (strstr(objective->target, "Combo-"))
259 objective->currentValue = game.currentComboHits;
260 Math::limitInt(&objective->currentValue, 0, objective->targetValue);
264 objective->currentValue++;
267 requiredValue = objective->targetValue - objective->currentValue;
269 if (objective->currentValue == objective->targetValue)
271 if (!map.isBossMission)
273 snprintf(message, sizeof message, _("%s - Objective Completed - Check Point Reached!"), _(objective->description));
274 game.setObjectiveCheckPoint();
278 snprintf(message, sizeof message, _("%s - Objective Completed"), _(objective->description));
281 if (strcmp(objective->description, "Get the Aqua Lung") == 0)
283 snprintf(message, sizeof message, "Got the Aqua Lung! You can now swim forever!");
284 game.hasAquaLung = true;
285 presentPlayerMedal("Aqua_Lung");
288 if (strcmp(objective->description, "Get the Jetpack") == 0)
290 snprintf(message, sizeof message, "Got the Jetpack! Press SPACE to Activate!");
291 game.hasJetPack = true;
292 presentPlayerMedal("Jetpack");
295 engine.setInfoMessage(message, 9, INFO_OBJECTIVE);
296 objective->completed = true;
297 game.totalObjectivesCompleted++;
300 else if (!strstr(objective->target, "Combo-"))
302 if ((requiredValue % 10 == 0) || (requiredValue <= 10) || (alwaysInform))
304 switch (Math::prand() % 3)
307 snprintf(message, sizeof message, _("%s - %d more to go..."), _(objective->description), requiredValue);
310 snprintf(message, sizeof message, _("%s - need %d more"), _(objective->description), requiredValue);
313 snprintf(message, sizeof message, _("%s - %d of %d"), _(objective->description), objective->currentValue, objective->targetValue);
317 engine.setInfoMessage(message, 1, INFO_NORMAL);