2 Copyright (C) 2004-2011 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "objectives.h"
23 void adjustObjectives()
25 bool needRequired = false;
27 Entity *mia = (Entity*)map.miaList.getHead();
29 while (mia->next != NULL)
31 mia = (Entity*)mia->next;
33 if (gameData.MIARescued(map.name, mia->name))
40 if (map.foundMIAs >= map.requiredMIAs)
42 map.requiredMIAs = map.totalMIAs;
48 map.requiredMIAs = map.totalMIAs;
55 Objective *objective = (Objective*)map.objectiveList.getHead();
57 bool previouslyCleared = gameData.stagePreviouslyCleared(map.name);
59 while (objective->next != NULL)
61 objective = (Objective*)objective->next;
65 objective->required = false;
70 objective->required = true;
75 objective->required = true;
78 if (previouslyCleared)
80 if (gameData.objectiveCompleted(map.name, objective->description))
82 objective->completed = true;
84 debug(("Objective %s has been completed\n", objective->description));
87 gameData.getObjectiveValues(map.name, objective->description, ¤t, &target);
88 objective->currentValue = current;
89 objective->targetValue = target;
91 // Make sure that gameplay adjustments are catered for...
92 if (!objective->completed)
94 Math::limitInt(&objective->currentValue, 0, objective->targetValue);
96 if (objective->currentValue == objective->targetValue)
98 objective->completed = true;
100 debug(("Objective %s has been completed (gameplay adjustment!)\n", objective->description));
107 bool allObjectivesCompleted()
109 if (map.foundMIAs < map.requiredMIAs)
112 Objective *objective = (Objective*)map.objectiveList.getHead();
114 while (objective->next != NULL)
116 objective = (Objective*)objective->next;
118 if ((objective->required) && (!objective->completed))
125 bool perfectlyCompleted()
127 if (map.foundMIAs < map.totalMIAs)
130 Objective *objective = (Objective*)map.objectiveList.getHead();
132 while (objective->next != NULL)
134 objective = (Objective*)objective->next;
136 if (!objective->completed)
143 bool requiredEnemy(const char *name)
145 Objective *objective = (Objective*)map.objectiveList.getHead();
147 while (objective->next != NULL)
149 objective = (Objective*)objective->next;
151 if (strcmp(objective->target, name) == 0)
160 bool requiredObjectivesCompleted()
162 if (map.foundMIAs < map.requiredMIAs)
167 Objective *objective = (Objective*)map.objectiveList.getHead();
169 while (objective->next != NULL)
171 objective = (Objective*)objective->next;
173 if (strcmp(objective->target, "Exit") == 0)
178 if ((objective->required) && (!objective->completed))
188 Used by the skip level cheat
190 void autoCompleteAllObjectives(bool allObjectives)
194 map.requiredMIAs = map.totalMIAs;
195 map.foundMIAs = map.totalMIAs;
199 map.foundMIAs = map.requiredMIAs;
202 map.foundItems = map.totalItems;
204 Objective *objective = (Objective*)map.objectiveList.getHead();
206 while (objective->next != NULL)
208 objective = (Objective*)objective->next;
212 objective->completed = true;
213 objective->currentValue = objective->targetValue;
217 if (objective->required)
219 objective->completed = true;
220 objective->currentValue = objective->targetValue;
225 int required = map.foundMIAs;
227 Entity *mia = (Entity*)map.miaList.getHead();
229 while (mia->next != NULL)
231 mia = (Entity*)mia->next;
240 void checkObjectives(const char *name, bool alwaysInform)
242 Objective *objective = (Objective*)map.objectiveList.getHead();
248 while (objective->next != NULL)
250 objective = (Objective*)objective->next;
252 if (!objective->completed)
254 if (strcmp(objective->target, name) == 0)
256 if (strstr(objective->target, "Combo-"))
258 objective->currentValue = game.currentComboHits;
259 Math::limitInt(&objective->currentValue, 0, objective->targetValue);
263 objective->currentValue++;
266 requiredValue = objective->targetValue - objective->currentValue;
268 if (objective->currentValue == objective->targetValue)
270 if (!map.isBossMission)
272 snprintf(message, sizeof message, _("%s - Objective Completed - Check Point Reached!"), _(objective->description));
273 game.setObjectiveCheckPoint();
277 snprintf(message, sizeof message, _("%s - Objective Completed"), _(objective->description));
280 if (strcmp(objective->description, "Get the Aqua Lung") == 0)
282 snprintf(message, sizeof message, "Got the Aqua Lung! You can now swim forever!");
283 game.hasAquaLung = true;
284 presentPlayerMedal("Aqua_Lung");
287 if (strcmp(objective->description, "Get the Jetpack") == 0)
289 snprintf(message, sizeof message, "Got the Jetpack! Press SPACE to Activate!");
290 game.hasJetPack = true;
291 presentPlayerMedal("Jetpack");
294 engine.setInfoMessage(message, 9, INFO_OBJECTIVE);
295 objective->completed = true;
296 game.totalObjectivesCompleted++;
299 else if (!strstr(objective->target, "Combo-"))
301 if ((requiredValue % 10 == 0) || (requiredValue <= 10) || (alwaysInform))
303 switch (Math::prand() % 3)
306 snprintf(message, sizeof message, _("%s - %d more to go..."), _(objective->description), requiredValue);
309 snprintf(message, sizeof message, _("%s - need %d more"), _(objective->description), requiredValue);
312 snprintf(message, sizeof message, _("%s - %d of %d"), _(objective->description), objective->currentValue, objective->targetValue);
316 engine.setInfoMessage(message, 1, INFO_NORMAL);